Code Monkey home page Code Monkey logo

afl_ghidra_emu's Introduction

afl_ghidra_emu

License

afl_ghidra_emu allows to fuzz exotic architecture using AFL++ and Ghidra emulation with code coverage functionality.

For more information, read this article.

How it works?

First, AFL++ listens on TCP socket (Ex: 22222/tcp) to get notified about sample’s code execution path.

Then AFL++ runs a trampoline script (afl_bridge_external.py) which is in charge of forwarding samples and maintaining the AFL++ configuration to Ghidra emulation via a TCP socket (Ex: 127.0.0.1:6674/tcp)

Finally, a python script in Ghidra (fuzz_xtensa_check_serial.py) is responsible of emulating code execution. It listens on a TCP socket (127.0.0.1:6674/tcp) and waits for input data coming from trampoline script. As soon as the script receives input data, the emulation will be started. During the execution, the executed path addresses are sent to AFL++ using its socket (127.0.0.1:22222).

The emulation engine reports the final execution status (Ex: got crash or not) to the trampoline script (afl_bridge_external.py). If state crash is reported, the trampoline script exits with segfault signal that AFL++ caches.

Installation

Clone AFLplusplus-socket-mode directory.

git clone https://github.com/airbus-cyber/AFLplusplus-socket-mode

Compile AFLplusplus (read AFLplusplus-socket-mode/README.md for more options)

cd AFLplusplus-socket-mode
make

Get AFL Ghidra emulator scripts and library

cd AFLplusplus-socket-mode/utils/socket_mode
sh get_afl_ghidra_emulator.sh

Copy afl_ghidra_emu files to your ghidra script directory

cp –r afl_ghidra_emu/* $USER_HOME/ghidra_scripts/

Example: Fuzzing Xtensa binary code keygenme_xtensa.elf

./examples/xtensa/bin/keygenme_xtensa.elf is a keygenMe compiled for Xtensa (ex: esp32) architecture. Xtensa is not officially supported in Ghidra yet. So, you need first to install it by following these instruction

Load in Ghidra

  • Create a new project in Ghidra;
  • Import file ./bin/keygenme_xtensa.elf (arch: Xtensa:LE:32);
  • Open it in CodeBrowser and execute auto-analyze;
  • Open Script Manager in "Window" submenu;
  • Run script fuzz_xtensa_check_serial.py;

Start Fuzz

Make AFL workspace directories

mkdir input output

Add first sample

echo -n "BBBBBBBB" > input/sample1.bin

Start AFL++ with trampoline script.

afl-fuzz -p explore -D -Y 22222 -i input -o output -t 90000 /usr/bin/python2 afl_bridge_external.py -H 127.0.0.1 -P 6674 -a 127.0.0.1 -p 22222 -i @@

Stop Ghidra emulation

./afl_bridge_external.py -H 127.0.0.1 -P 6674 -s

Example: Fuzzing PPC binary code keygenme_ppc.elf

./examples/ppc/bin/keygenme_ppc.elf is also a keygenMe compiled for PowerPC architecture.

Follow the same steps above with PowerPC:BE:32:default architecture in Ghidra and run the script fuzz_ppc_check_serial.py.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.