jwilk / python-afl

American Fuzzy Lop fork server and instrumentation for pure-Python code
https://jwilk.net/software/python-afl
MIT License
350 stars 33 forks source link

Python fails to import afl.so when using py-afl #5

Closed FynnMazurkiewicz closed 7 years ago

FynnMazurkiewicz commented 7 years ago

Hi there.

First of, thank you for providing the missing link between Python and AFL.

I've recently taken a deep dive into AFL and am now stuck at fuzzing one of my targets. Even thought I am almost certain it's an error on my side, I thought I would open this issue.

Here's the code in question:

import sys
import os

f = open("log.txt","w")

#Redacted: Here I import some custom modules.

f.write("Imported custom modules.\n")
try:
    import afl
except:
    import traceback
    f.write(traceback.format_exc())
    f.close()
    exit(1)
f.write("Imported AFL.\n")
afl.init()
f.close()
os._exit(0)

Expected Output (as found in log.txt):

Imported some custom modules.
Imported AFL.

Output (run with /usr/bin/python file.py):

Imported some custom modules.
Imported AFL.

Output (run with py-afl-fuzz -i input -o output -- /usr/bin/python file.py):

Imported custom modules.Traceback (most recent call last):
  File "test.py", line 16, in <module>
    import afl
ImportError: /home/redacted/.local/lib/python2.7/site-packages/afl.so: failed to map segment from shared object

I don't know which I find more confusing: The fact that I get the error, or the fact that I only get it when using py-afl. Either way, it's another one of those moments, that shows me just how much of a beginner I am.

Right now, I am absolutely clueless. I've been googling my eyes out and spent half of my New Years Eve being really mad at my computer. No good times.

Any ideas? Happy new year by the way!

jwilk commented 7 years ago

ImportError: /home/redacted/.local/lib/python2.7/site-packages/afl.so: failed to map segment from shared object

Sounds like perhaps there's not enough virtual memory to mmap this shlib? afl-fuzz sets up quite a tight memory limit, so maybe that's it. Could you try again with a higher limit (say, -m 100) and see if it helps?

FynnMazurkiewicz commented 7 years ago

Wow. Actually had some issues with this before and even tried -m, but that must have been with a different run config. Thank you lots!

I knew it was me. Stupid me.

Cheers!