about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDominik Maier <domenukk@gmail.com>2020-02-03 10:55:15 +0100
committerDominik Maier <domenukk@gmail.com>2020-02-03 10:55:15 +0100
commitb4d9d56af4a6c4a4583a2443e1c2de7ea6fede8e (patch)
tree4f3e2475a818dd6ed86049f2eaf16f337eb92d12
parentc7167190a6abe9884787b0aae9e0728848971163 (diff)
downloadafl++-b4d9d56af4a6c4a4583a2443e1c2de7ea6fede8e.tar.gz
broader python support
-rw-r--r--Makefile58
-rw-r--r--docs/python_mutators.txt19
-rw-r--r--src/afl-fuzz.c2
3 files changed, 28 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index 459cae5f..dd6c19aa 100644
--- a/Makefile
+++ b/Makefile
@@ -63,42 +63,20 @@ CFLAGS     += -Wall -g -Wno-pointer-sign -I include/ \
 
 AFL_FUZZ_FILES = $(wildcard src/afl-fuzz*.c)
 
-ifneq "$(filter %3.7m, $(shell python3.7m-config --includes 2>/dev/null))" ""
-  PYTHON_INCLUDE  ?= $(shell python3.7m-config --includes)
-  PYTHON_LIB      ?= $(shell python3.7m-config --ldflags)
-  PYTHON_VERSION   = 3.7m
-else
-  ifneq "$(filter %3.7, $(shell python3.7-config --includes 2>/dev/null))" ""
-    PYTHON_INCLUDE  ?= $(shell python3.7-config --includes)
-    PYTHON_LIB      ?= $(shell python3.7-config --ldflags)
-    PYTHON_VERSION   = 3.7
-  else
-    ifneq "$(filter %2.7, $(shell python2.7-config --includes 2>/dev/null))" ""
-      PYTHON_INCLUDE  ?= $(shell python2.7-config --includes)
-      PYTHON_LIB      ?= $(shell python2.7-config --ldflags)
-      PYTHON_VERSION   = 2.7
-    endif
+ifneq "$(shell which python3)" ""
+  ifneq "$(shell which python3-config)" ""
+    PYTHON_INCLUDE  ?= $(shell python3-config --includes)
+    PYTHON_LIB      ?= $(shell python3-config --ldflags)
+    PYTHON_VERSION  ?= $(strip $(shell python3 --version 2>&1))
   endif
 endif
 
-PYTHON_INCLUDE	?= $(shell test -e /usr/include/python3.7m && echo /usr/include/python3.7m)
-PYTHON_INCLUDE	?= $(shell test -e /usr/include/python3.7 && echo /usr/include/python3.7)
-PYTHON_INCLUDE	?= $(shell test -e /usr/include/python2.7 && echo /usr/include/python2.7)
-
-ifneq "$(filter %3.7m, $(PYTHON_INCLUDE))" ""
-    PYTHON_VERSION ?= 3.7m
-    PYTHON_LIB  ?= -lpython3.7m
-else
-    ifneq "$(filter %3.7, $(PYTHON_INCLUDE))" ""
-        PYTHON_VERSION ?= 3.7
-    else
-        ifneq "$(filter %2.7, $(PYTHON_INCLUDE))" ""
-            PYTHON_VERSION ?= 2.7
-            PYTHON_LIB     ?= -lpython2.7
-        else
-            PYTHON_VERSION ?= none
-        endif
-    endif
+ifneq "$(shell which python)" ""
+  ifneq "$(shell which python-config)" ""
+    PYTHON_INCLUDE  ?= $(shell python-config --includes)
+    PYTHON_LIB      ?= $(shell python-config --ldflags)
+    PYTHON_VERSION  ?= $(strip $(shell python --version 2>&1))
+  endif
 endif
 
 ifdef SOURCE_DATE_EPOCH
@@ -128,9 +106,9 @@ endif
 COMM_HDR    = include/alloc-inl.h include/config.h include/debug.h include/types.h
 
 
-ifeq "$(shell echo '\#include <Python.h>@int main() {return 0; }' | tr @ '\n' | $(CC) -x c - -o .test -I$(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
+ifeq "$(shell echo '\#include <Python.h>@int main() {return 0; }' | tr @ '\n' | $(CC) -x c - -o .test $(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) 2>/dev/null && echo 1 || echo 0 ; rm -f .test )" "1"
 	PYTHON_OK=1
-	PYFLAGS=-DUSE_PYTHON -I$(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) -DPYTHON_VERSION=\"$(PYTHON_VERSION)\"
+	PYFLAGS=-DUSE_PYTHON $(PYTHON_INCLUDE) $(LDFLAGS) $(PYTHON_LIB) -DPYTHON_VERSION="\"$(PYTHON_VERSION)\""
 else
 	PYTHON_OK=0
 	PYFLAGS=
@@ -161,7 +139,7 @@ ifeq "$(TEST_MMAP)" "1"
 endif
 
 
-all:	test_x86 test_shm test_python27 ready $(PROGS) afl-as test_build all_done
+all:	test_x86 test_shm test_python ready $(PROGS) afl-as test_build all_done
 
 man:    $(MANPAGES) 
 	-$(MAKE) -C llvm_mode
@@ -229,14 +207,14 @@ endif
 
 ifeq "$(PYTHON_OK)" "1"
 
-test_python27:
+test_python:
 	@rm -f .test 2> /dev/null
-	@echo "[+] Python $(PYTHON_VERSION) support seems to be working."
+	@echo "[+] $(PYTHON_VERSION) support seems to be working."
 
 else
 
-test_python27:
-	@echo "[-] You seem to need to install the package python3.7-dev or python2.7-dev (and perhaps python[23]-apt), but it is optional so we continue"
+test_python:
+	@echo "[-] You seem to need to install the package python3-dev or python2-dev (and perhaps python[23]-apt), but it is optional so we continue"
 
 endif
 
diff --git a/docs/python_mutators.txt b/docs/python_mutators.txt
index 0caa2161..7fd54547 100644
--- a/docs/python_mutators.txt
+++ b/docs/python_mutators.txt
@@ -9,9 +9,10 @@ Adding custom mutators to AFL using Python modules
 
   Implemented by Christian Holler (:decoder) <choller@mozilla.com>.
 
-  NOTE: Python 3.7 and 2.7 are supported so far (3.8 upcomming).
-  Depending on with which version afl-fuzz was compiled, you must use
+  NOTE: Only cPython 2.7, 3.7 and above are supported, although others may work.
+  Depending on with which version afl-fuzz was compiled against, you must use
   python2 or python3 syntax in your scripts!
+  After a major version upgrade (e.g. 3.7 -> 3.8), a recompilation of afl-fuzz may be needed.
 
   For an example and a template see ../python_mutators/
 
@@ -57,23 +58,21 @@ further information about this feature.
 3) How to compile AFLFuzz with Python support
 ---------------------------------------------
 
-You must install the python 3.7 or 2.7 development package of your Linux
+You must install the python 3 or 2 development package of your Linux
 distribution before this will work. On Debian/Ubuntu/Kali this can be done
 with either:
-  apt install python3.7-dev
+  apt install python3-dev
 or
-  apt install python2.7-dev
+  apt install python-dev
 Note that for some distributions you might also need the package python[23]-apt
 
 A prerequisite for using this mode is to compile AFLFuzz with Python support.
 
-The afl Makefile performs some magic and detects Python 3.7 and 2.7 if it is
-in the default path and compiles afl-fuzz with the feature if available (which
-is /usr/include/python2.7 for the Python.h include and
-/usr/lib/x86_64-linux-gnu for the libpython2.7.a library)
+The AFL++ Makefile detects Python 3 and 2 through `python-config` if is is in the PATH
+and compiles afl-fuzz with the feature if available.
 
 In case your setup is different set the necessary variables like this:
-PYTHON_INCLUDE=/path/to/python2.7/include LDFLAGS=-L/path/to/python2.7/lib make
+PYTHON_INCLUDE=/path/to/python/include LDFLAGS=-L/path/to/python/lib make
 
 
 4) How to run AFLFuzz with your custom module
diff --git a/src/afl-fuzz.c b/src/afl-fuzz.c
index 39e737c2..eae4ba1f 100644
--- a/src/afl-fuzz.c
+++ b/src/afl-fuzz.c
@@ -145,7 +145,7 @@ static void usage(u8* argv0) {
       argv0, EXEC_TIMEOUT, MEM_LIMIT);
 
 #ifdef USE_PYTHON
-  SAYF("Compiled with Python %s module support, see docs/python_mutators.txt\n",
+  SAYF("Compiled with %s module support, see docs/python_mutators.txt\n",
        (char*)PYTHON_VERSION);
 #endif