Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Fixed a bug in afl-sync that caused some directories to not be pulled
Browse files Browse the repository at this point in the history
from the remote location when a session name was specified.

Added afl's .cur_input to the rsync exclude list in afl-sync.
  • Loading branch information
rc0r committed Jul 29, 2016
1 parent 5136465 commit dc4d6ac
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
15 changes: 13 additions & 2 deletions afl_utils/afl_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def __init__(self, server_config, fuzzer_config):


class AflRsync(AflBaseSync):
def __init__(self, server_config, fuzzer_config):
# default excludes
self.__excludes = ['*.cur_input']
super(AflRsync, self).__init__(server_config, fuzzer_config)

def __prepare_rsync_commandline(self, local_path, remote_path, rsync_options=list(_rsync_default_options),
rsync_excludes=list([]), rsync_get=False):
cmd = ['rsync']
Expand Down Expand Up @@ -76,7 +81,7 @@ def push(self):
if self.fuzzer_config['session'] is not None:
fuzzers = (fuzzer for fuzzer in fuzzers if fuzzer.startswith(self.fuzzer_config['session']))

excludes = []
excludes = self.__excludes

if self.fuzzer_config['exclude_crashes']:
excludes += ['crashes*/']
Expand All @@ -97,7 +102,7 @@ def pull(self):
remote_path = self.server_config['remote_path']

options = list(_rsync_default_options)
excludes = []
excludes = self.__excludes

# exclude our previously pushed fuzzer states from being pulled again
# and avoid to overwrite our local fuzz data
Expand All @@ -106,7 +111,13 @@ def pull(self):

# restrict to certain session, if requested
if self.fuzzer_config['session'] is not None:
# make sure defaults are excluded from explicitly included locations
for exclude_rule in self.__excludes:
options += ['--exclude=\"/{}*/{}\"'.format(self.fuzzer_config['session'], exclude_rule)]
# recursively include everything that does match the session name
options += ['--include=\"/{}*/\"'.format(self.fuzzer_config['session'])]
options += ['--include=\"/{}*/*\"'.format(self.fuzzer_config['session'])]
# exclude everything else
excludes += ['*']

print_ok('Pulling {}/* <- {}/'.format(local_path, remote_path))
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Version 1.30a
- Parsing of slightly different modified 'fuzzer_stats' file fixed
in afl-stats.
- Delayed startup added to afl-multicore.
- Fixed a bug in afl-sync that caused some directories to not be pulled
from the remote location when a session name was specified.
- Added afl's .cur_input to the rsync exclude list in afl-sync.

Version 1.29a

Expand Down
15 changes: 15 additions & 0 deletions tests/test_afl_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def setUp(self):
os.makedirs('testdata/rsync_tmp_store', exist_ok=True)
os.makedirs('testdata/sync/fuzz000/crashes', exist_ok=True)
os.makedirs('testdata/sync/fuzz000/hangs', exist_ok=True)
os.makedirs('testdata/sync/fuzz000/.cur_input', exist_ok=True)
os.makedirs('testdata/sync/fuzz001/.cur_input', exist_ok=True)
os.makedirs('testdata/sync/fuzz002.sync', exist_ok=True)
os.makedirs('testdata/sync/invalid_fuzz000', exist_ok=True)
os.makedirs('testdata/sync/invalid_fuzz001', exist_ok=True)
Expand All @@ -22,7 +24,10 @@ def setUp(self):
os.makedirs('testdata/rsync_output_pull/fuzz000.sync', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/fuzz001.sync', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_fuzz000.sync', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_fuzz000.sync/.cur_input', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_fuzz000.sync/crashes', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_fuzz001.sync', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_fuzz001.sync/.cur_input', exist_ok=True)
os.makedirs('testdata/rsync_output_pull/other_invalid_fuzz000.sync', exist_ok=True)
# sync
os.makedirs('testdata/rsync_output_sync/other_fuzz000.sync', exist_ok=True)
Expand All @@ -34,6 +39,8 @@ def tearDown(self):
self.clean_remove_dir('testdata/rsync_tmp_store')
self.clean_remove_dir('testdata/sync/fuzz000/crashes')
self.clean_remove_dir('testdata/sync/fuzz000/hangs')
self.clean_remove_dir('testdata/sync/fuzz000/.cur_input')
self.clean_remove_dir('testdata/sync/fuzz001/.cur_input')
self.clean_remove_dir('testdata/sync/fuzz002.sync')
self.clean_remove_dir('testdata/sync/invalid_fuzz000')
self.clean_remove_dir('testdata/sync/invalid_fuzz001')
Expand Down Expand Up @@ -134,6 +141,7 @@ def test_afl_rsync_put(self):
afl_rsync = AflRsync(None, None)
self.assertTrue(afl_rsync.rsync_put(local_path, remote_path, rsync_excludes=excludes))
self.assertTrue(os.path.exists(remote_path + '.sync/fuzzer_stats'))
self.assertTrue(os.path.exists(remote_path + '.sync/.cur_input'))
self.assertFalse(os.path.exists(remote_path + '.sync/crashes'))
self.assertFalse(os.path.exists(remote_path + '.sync/hangs'))

Expand Down Expand Up @@ -163,7 +171,9 @@ def test_afl_rsync_push(self):
afl_rsync = AflRsync(server_config, fuzzer_config)
self.assertIsNone(afl_rsync.push())
self.assertTrue(os.path.exists('testdata/rsync_output_push/fuzz000.sync'))
self.assertFalse(os.path.exists('testdata/rsync_output_push/fuzz000.sync/.cur_input'))
self.assertTrue(os.path.exists('testdata/rsync_output_push/fuzz001.sync'))
self.assertFalse(os.path.exists('testdata/rsync_output_push/fuzz000.sync/.cur_input'))
self.assertFalse(os.path.exists('testdata/rsync_output_push/fuzz002.sync'))
self.assertFalse(os.path.exists('testdata/rsync_output_push/fuzz002.sync.sync'))
self.assertFalse(os.path.exists('testdata/rsync_output_push/invalid_fuzz000.sync'))
Expand All @@ -184,7 +194,10 @@ def test_afl_rsync_pull_session(self):
afl_rsync = AflRsync(server_config, fuzzer_config)
self.assertIsNone(afl_rsync.pull())
self.assertTrue(os.path.exists('testdata/sync/other_fuzz000.sync'))
self.assertTrue(os.path.exists('testdata/sync/other_fuzz000.sync/crashes'))
self.assertFalse(os.path.exists('testdata/sync/other_fuzz000.sync/.cur_input'))
self.assertTrue(os.path.exists('testdata/sync/other_fuzz001.sync'))
self.assertFalse(os.path.exists('testdata/sync/other_fuzz001.sync/.cur_input'))
self.assertFalse(os.path.exists('testdata/sync/other_invalid_fuzz000.sync'))
self.assertFalse(os.path.exists('testdata/sync/fuzz000.sync'))
self.assertFalse(os.path.exists('testdata/sync/fuzz001.sync'))
Expand All @@ -205,6 +218,8 @@ def test_afl_rsync_pull_all(self):
self.assertIsNone(afl_rsync.pull())
self.assertTrue(os.path.exists('testdata/sync/other_fuzz000.sync'))
self.assertTrue(os.path.exists('testdata/sync/other_fuzz001.sync'))
self.assertFalse(os.path.exists('testdata/sync/other_fuzz000.sync/.cur_input'))
self.assertFalse(os.path.exists('testdata/sync/other_fuzz001.sync/.cur_input'))
self.assertTrue(os.path.exists('testdata/sync/other_invalid_fuzz000.sync'))
self.assertFalse(os.path.exists('testdata/sync/fuzz000.sync'))
self.assertFalse(os.path.exists('testdata/sync/fuzz001.sync'))
Expand Down

0 comments on commit dc4d6ac

Please sign in to comment.