Skip to content

Commit c0da127

Browse files
committed
add support for stdin
1 parent 71ce66c commit c0da127

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
afl-cov-0.6.4 (2020-05-23):
2+
- afl-cov now supports stdin targets (just omit @@/AFL_FILE)
3+
- enhance scripts
4+
15
afl-cov-0.6.3 (2020-05-13):
26
- Allow @@ additionally to AFL_FILE
37
- added three helper scripts

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# afl-cov - AFL Fuzzing Code Coverage
22

3-
Version: 0.6.3
3+
Version: 0.6.4
44

55
- [Preface](#preface)
66
- [Introduction](#introduction)
@@ -18,8 +18,9 @@ Version: 0.6.3
1818
This is a modified afl-cov fork because the original author's account is
1919
inactive :-(
2020

21-
It has three changes:
22-
* afl-cov now accepts "@@" like AFL++ in the command line
21+
It has four changes:
22+
* afl-cov now accepts "@@" like AFL++ in the target command parameters
23+
* afl-cov now can send to targets that read on stdin (just omit @@)
2324
* afl-cov.sh makes using afl-cov easier (just needs two parameters)
2425
* afl-cov-build.sh makes builing a target for coverage easier
2526
* afl-stat.sh shows the statistics of a run (in progress or completed)

afl-cov

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
#
33
# File: afl-cov
44
#
5-
# Version: 0.6.3
5+
# Version: 0.6.4
66
#
77
# Purpose: Perform lcov coverage diff's against each AFL queue file to see
88
# new functions and line coverage evolve from an AFL fuzzing cycle.
99
#
1010
# Copyright (C) 2015-2016 Michael Rash ([email protected])
11+
# Copyright (C) 2018-2020 Marc "vanHauser" Heuse ([email protected])
1112
#
1213
# License (GNU General Public License version 2 or any later version):
1314
#
@@ -44,7 +45,7 @@ try:
4445
except ImportError:
4546
import subprocess
4647

47-
__version__ = '0.6.3'
48+
__version__ = '0.6.4'
4849

4950
NO_OUTPUT = 0
5051
WANT_OUTPUT = 1
@@ -185,10 +186,10 @@ def process_afl_test_cases(cargs):
185186
### for the current AFL test case file
186187
if run_once:
187188
run_cmd(cargs.coverage_cmd.replace('AFL_FILE', f),
188-
cov_paths['log_file'], cargs, NO_OUTPUT)
189+
cov_paths['log_file'], cargs, NO_OUTPUT, True, f)
189190
else:
190191
out_lines = run_cmd(cargs.coverage_cmd.replace('AFL_FILE', f),
191-
cov_paths['log_file'], cargs, WANT_OUTPUT)[1]
192+
cov_paths['log_file'], cargs, WANT_OUTPUT, True, f)[1]
192193
run_once = True
193194

194195
if cargs.afl_queue_id_limit \
@@ -584,29 +585,29 @@ def lcov_gen_coverage(cov_paths, cargs):
584585
+ " --no-checksum --capture --directory " \
585586
+ cargs.code_dir + " --output-file " \
586587
+ cov_paths['lcov_info'], \
587-
cov_paths['log_file'], cargs, LOG_ERRORS)
588+
cov_paths['log_file'], cargs, LOG_ERRORS, False, "")
588589

589590
if (cargs.disable_lcov_exclude_pattern):
590591
out_lines = run_cmd(cargs.lcov_path \
591592
+ lcov_opts
592593
+ " --no-checksum -a " + cov_paths['lcov_base'] \
593594
+ " -a " + cov_paths['lcov_info'] \
594595
+ " --output-file " + cov_paths['lcov_info_final'], \
595-
cov_paths['log_file'], cargs, WANT_OUTPUT)[1]
596+
cov_paths['log_file'], cargs, WANT_OUTPUT, False, "")[1]
596597
else:
597598
tmp_file = NamedTemporaryFile(delete=False)
598599
run_cmd(cargs.lcov_path \
599600
+ lcov_opts
600601
+ " --no-checksum -a " + cov_paths['lcov_base'] \
601602
+ " -a " + cov_paths['lcov_info'] \
602603
+ " --output-file " + tmp_file.name, \
603-
cov_paths['log_file'], cargs, LOG_ERRORS)
604+
cov_paths['log_file'], cargs, LOG_ERRORS, False, "")
604605
out_lines = run_cmd(cargs.lcov_path \
605606
+ lcov_opts
606607
+ " --no-checksum -r " + tmp_file.name \
607608
+ " " + cargs.lcov_exclude_pattern + " --output-file " \
608609
+ cov_paths['lcov_info_final'],
609-
cov_paths['log_file'], cargs, WANT_OUTPUT)[1]
610+
cov_paths['log_file'], cargs, WANT_OUTPUT, False, "")[1]
610611
if os.path.exists(tmp_file.name):
611612
os.unlink(tmp_file.name)
612613

@@ -643,7 +644,7 @@ def gen_web_cov_report(fuzz_dir, cov_paths, cargs):
643644
+ " --output-directory " \
644645
+ cov_paths['web_dir'] + " " \
645646
+ cov_paths['lcov_info_final'], \
646-
cov_paths['log_file'], cargs, LOG_ERRORS)
647+
cov_paths['log_file'], cargs, LOG_ERRORS, False, "")
647648

648649
logr("[+] Final lcov web report: %s/%s" % \
649650
(cov_paths['web_dir'], 'index.html'), cov_paths['log_file'], cargs)
@@ -691,23 +692,26 @@ def get_running_pid(stats_file, pid_re):
691692
break
692693
return pid
693694

694-
def run_cmd(cmd, log_file, cargs, collect):
695+
def run_cmd(cmd, log_file, cargs, collect, aflrun, fn):
695696

696697
out = []
697698

698-
if cargs.verbose:
699-
if log_file:
700-
logr(" CMD: %s" % cmd, log_file, cargs)
701-
else:
702-
print " CMD: %s" % cmd
703-
704699
fh = None
705700
if cargs.disable_cmd_redirection or collect == WANT_OUTPUT \
706701
or collect == LOG_ERRORS:
707702
fh = NamedTemporaryFile(delete=False)
708703
else:
709704
fh = open(os.devnull, 'w')
710705

706+
if aflrun == True and len(fn) > 0:
707+
cmd = 'cat ' + fn + ' | ' + cmd
708+
709+
if cargs.verbose:
710+
if log_file:
711+
logr(" CMD: %s" % cmd, log_file, cargs)
712+
else:
713+
print " CMD: %s" % cmd
714+
711715
es = subprocess.call(cmd, stdin=None,
712716
stdout=fh, stderr=subprocess.STDOUT, shell=True)
713717

@@ -809,15 +813,15 @@ def init_tracking(cov_paths, cargs):
809813
run_cmd(cargs.lcov_path \
810814
+ lcov_opts \
811815
+ " --no-checksum --zerocounters --directory " \
812-
+ cargs.code_dir, cov_paths['log_file'], cargs, LOG_ERRORS)
816+
+ cargs.code_dir, cov_paths['log_file'], cargs, LOG_ERRORS, False, "")
813817

814818
run_cmd(cargs.lcov_path \
815819
+ lcov_opts
816820
+ " --no-checksum --capture --initial" \
817821
+ " --directory " + cargs.code_dir \
818822
+ " --output-file " \
819823
+ cov_paths['lcov_base'], \
820-
cov_paths['log_file'], cargs, LOG_ERRORS)
824+
cov_paths['log_file'], cargs, LOG_ERRORS, False, "")
821825

822826
return True
823827

@@ -832,7 +836,7 @@ def is_bin_gcov_enabled(binary, cargs):
832836

833837
### run readelf against the binary to see if it contains gcov support
834838
for line in run_cmd("%s -a %s" % (cargs.readelf_path, binary),
835-
False, cargs, WANT_OUTPUT)[1]:
839+
False, cargs, WANT_OUTPUT, False, "")[1]:
836840
if ' __gcov' in line:
837841
if cargs.validate_args or cargs.gcov_check or cargs.gcov_check_bin:
838842
print "[+] Binary '%s' is compiled with code coverage support via gcc." % binary
@@ -897,12 +901,9 @@ def is_gcov_enabled(cargs):
897901
return False
898902

899903
if cargs.coverage_cmd:
900-
if 'AFL_FILE' not in cargs.coverage_cmd:
901-
print "[*] --coverage-cmd must contain AFL_FILE"
902-
return False
903-
904904
### make sure at least one component of the command is an
905905
### executable and is compiled with code coverage support
906+
906907
found_exec = False
907908
found_code_cov_binary = False
908909

0 commit comments

Comments
 (0)