Frelatage is a coverage-based Python fuzzing library which can be used to fuzz python code. The development of Frelatage was inspired by various other fuzzers, including AFL/AFL++, Atheris and PythonFuzz. The main purpose of the project is to take advantage of the best features of these fuzzers and gather them together into a new tool in order to efficiently fuzz python applications.
Python 3
pip3 install frelatage
Recommended for developers. It automatically clones the main branch from the frelatage repo, and installs from source.
Automatically clone the Frelatage repository and install Frelatage from source
bash <(wget -q https://raw.githubusercontent.com/Rog3rSm1th/Frelatage/main/scripts/autoinstall.sh -O -)
The idea behind the design of Frelatage is the usage of a genetic algorithm to generate mutations that will cover as much code as possible. The functioning of a fuzzing cycle can be roughly summarized with this diagram :
Frelatage allows to fuzz a function by passing a file as input.
import frelatage
import my_vulnerable_library
def MyFunctionFuzz(data):
my_vulnerable_library.parse(data)
input = frelatage.Input(value=”initial_value”)
f = frelatage.Fuzzer(MyFunctionFuzz, [[input]])
f.fuzz()
Frelatage gives you the possibility to fuzz file type input parameters. To initialize the value of these files, you must create files in the input folder (./in
by default).
If we want to initialize the value of a file used to fuzz, we can do it like this:
echo “initial value” > ./in/input.txt
And then run the fuzzer:
import frelatage
import my_vulnerable_library
def MyFunctionFuzz(data):
my_vulnerable_library.load_file(data)
input = frelatage.Input(file=True, value=”input.txt”)
f = frelatage.Fuzzer(MyFunctionFuzz, [[input]])
f.fuzz()
If you need to load several files into a corpus at once (useful if you use a large corpus) You can use the built-in function of Frelatage load_corpus
. This function returns a list of inputs.
load_corpus(directory: str, file_extensions: list) -> list[Input]
./
, ./images
["jpeg", "gif"]
, ["pdf"]
import frelatage
import my_vulnerable_library
def MyFunctionFuzz(data):
my_vulnerable_library.load_file(data)
my_vulnerable_library.load_file(data2)
Load every every file in the ./in directory
corpus_1 = frelatage.load_corpus(directory=”./”)
Load every .gif/.jpeg file in the ./in/images subdirectory
corpus_2 = frelatage.load_corpus(directory=”./images”, file_extension=[“gif”, “jpeg”])
f = frelatage.Fuzzer(MyFunctionFuzz, [corpus_1, corpus_2])
f.fuzz()
You can copy one or more dictionaries located here in the directory dedicated to dictionaries (./dict
by default).
Differental fuzzing is a popular software testing technique that attempts to detect bugs by providing the same input to multiple libraries/programs and observing differences in their behaviors. You will find an example here of a use of differential fuzzing with Frelatage with the json
and ujson
libraries.
You can find more examples of fuzzers and corpus in the examples directory.
Each crash is saved in the output folder (./out
by default), in a folder named : id:<crash ID>,err:<error
type>,err_pos:<error>,err_file:<error file>
.
The report directory is in the following form:
├── out
│ ├── id:,err:,err_file:,err_pos:
│ ├── input
│ ├── 0
│ ├──
│ ├── …
│ ├── …
Inputs passed to a function are serialized using the pickle module before being saved in the <report_folder>/input file
. It is therefore necessary to deserialize it to be able to read the contents of the file. This action can be performed with this script.
./read_report.py input
There are two ways to set up Frelatage:
ENV Variable | Description | Possible Values | Default Value |
---|---|---|---|
FRELATAGE_DICTIONARY_ENABLE | Enable the use of mutations based on dictionary elements | 1 to enable, 0 otherwise | 1 |
FRELATAGE_TIMEOUT_DELAY | Delay in seconds after which a function will return a TimeoutError | 1 – infinity | 2 |
FRELATAGE_INPUT_FILE_TMP_DIR | Temporary folder where input files are stored | absolute path to a folder, e.g. /tmp/custom_dir | /tmp/frelatage |
FRELATAGE_INPUT_MAX_LEN | Maximum size of an input variable in bytes | 4 – infinity | 4094 |
FRELATAGE_MAX_THREADS | Maximum number of simultaneous threads | 8 – infinity | 8 |
FRELATAGE_MAX_CYCLES_WITHOUT_NEW_PATHS | Number of cycles without new paths found after which we go to the next stage | 10 – infinity | 5000 |
FRELATAGE_INPUT_DIR | Directory containing the initial input files. It needs to be a relative path (to the path of the fuzzing file) | relative path to a folder, e.g. ./in | ./in |
FRELATAGE_DICTIONARY_DIR | Default directory for dictionaries. It needs to be a relative path (to the path of the fuzzing file) | relative path to a folder, e.g. ./dict | ./dict |
FRELATAGE_DEBUG_MODE | Enable the debug mode (show the error when Frelatage crash) | 1 to enable, 0 otherwise | 1 |
A configuration example :
export FRELATAGE_DICTIONARY_ENABLE=1 &&
export FRELATAGE_TIMEOUT_DELAY=2 &&
export FRELATAGE_INPUT_FILE_TMP_DIR=”/tmp/frelatage” &&
export FRELATAGE_INPUT_MAX_LEN=4096 &&
export FRELATAGE_MAX_THREADS=8 &&
export FRELATAGE_MAX_CYCLES_WITHOUT_NEW_PATHS=5000 &&
export FRELATAGE_INPUT_DIR=”./in” &&
export FRELATAGE_DICTIONARY_DIR=”./dict” &&
python3 fuzzer.py
Passing arguments to the fuzzer
def myfunction(input1_string, input2_int):
pass
input1 = frelatage.Input(value=”initial_value”)
input2 = frelatage.Input(value=2)
f = frelatage.Fuzzer(
# The method you want to fuzz
method=myfunction,
# Corpus
corpus=[[input1], [input2]],
# Number of threads
threads_count=8,
# Exceptions that will be taken into account
exceptions_whitelist=(OSError),
# Exceptions that will not be taken into account
exceptions_blacklist=(),
# Directory where the error reports will be stored
output_directory=”./out”,
# Enable or disable silent mode
silent=False,
# Enable or disable infinite fuzzing
infinite_fuzz=False
)
f.fuzz()
shadow-rs is a Windows kernel rootkit written in Rust, demonstrating advanced techniques for kernel manipulation…
Extract and execute a PE embedded within a PNG file using an LNK file. The…
Embark on the journey of becoming a certified Red Team professional with our definitive guide.…
This repository contains proof of concept exploits for CVE-2024-5836 and CVE-2024-6778, which are vulnerabilities within…
This took me like 4 days (+2 days for an update), but I got it…
MaLDAPtive is a framework for LDAP SearchFilter parsing, obfuscation, deobfuscation and detection. Its foundation is…