Expand description
Welcome to LibAFL_bolts
§LibAFL_bolts: OS and Fuzzer Dev’s Libary Collection.
The libafl_bolts
crate exposes a lot of low-level features of LibAFL for projects that are unrelated to fuzzing, or just fuzzers completely different to LibAFL.
Some cross-platform things in bolts include (but are not limited to):
- SerdeAnyMap: a map that stores and retrieves elements by type and is serializable and deserializable
- ShMem: A cross-platform (Windows, Linux, Android, MacOS) shared memory implementation
- LLMP: A fast, lock-free IPC mechanism via SharedMap
- Core_affinity: A maintained version of
core_affinity
that can be used to get core information and bind processes to cores - Rands: Fast random number generators for fuzzing (like RomuRand)
- MiniBSOD: get and print information about the current process state including important registers.
- Tuples: Haskel-like compile-time tuple lists
- Os: OS specific stuff like signal handling, windows exception handling, pipes, and helpers for
fork
LibAFL_bolts is written and maintained by
- Andrea Fioraldi andrea@aflplus.plus
- Dominik Maier dominik@aflplus.plus
- s1341 github@shmarya.net
- Dongjia Zhang toka@aflplus.plus
- Addison Crump me@addisoncrump.info
§Contributing
For bugs, feel free to open issues or contact us directly. Thank you for your support. <3
Even though we will gladly assist you in finishing up your PR, try to
- keep all the crates compiling with stable rust (hide the eventual non-stable code under
cfg
s) - run
cargo nightly fmt
on your code before pushing - check the output of
cargo clippy --all
or./clippy.sh
- run
cargo build --no-default-features
to check forno_std
compatibility (and possibly add#[cfg(feature = "std")]
) to hide parts of your code.
Some of the parts in this list may be hard, don’t be afraid to open a PR if you cannot fix them by yourself, so we can help.
§License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Dependencies under more restrictive licenses, such as GPL or AGPL, can be enabled using the respective feature in each crate when it is present, such as the 'agpl' feature of the libafl crate.
§Feature Flags
§General Features
std
(enabled by default) — Enables features that need rust’sstd
lib to work, like print, env, … supportalloc
(enabled by default) — Enables all features that allocate inno_std
derive
(enabled by default) — Provide the#[derive(SerdeAny)]
macro.rand_trait
(enabled by default) — If set, libafl_bolt’srand
implementations will implementrand::Rng
python
— Will build thepyo3
bindingsprelude
— Exposelibafl::prelude
for direct access to all types without additionaluse
directivescli
— Exposelibafl_bolts::cli
for easy commandline parsing of common fuzzer settingsqemu_cli
— Enables extra commandline flags for qemu-based fuzzers incli
frida_cli
— Enables extra commandline flags for frida-based fuzzers incli
errors_backtrace
— Stores the backtraces of all generatedError
s. Good for debugging, but may come with a slight performance hit.gzip
(enabled by default) — Enables gzip compression in certain parts of the libxxh3
(enabled by default) — Replacesahash
with the potentially fasterxxh3
in some parts of the lib. This yields a stable and fast hash, but may increase the resulting binary size slightly This also enables certain hashing and rand features inno_std
no-alloc.
§SerdeAny features
stable_anymap
— With this feature, the AnyMap usestype_name
instead ofTypeId::of
for deserialization. With this feature, stored state remains deserializable across multiple compilations of LibAFL. The rust doc specifically states that “multiple types may map to the same type name”, so it could potentially lead to bugs. However, we make sure that no two types with the same name ever exist.serdeany_autoreg
(enabled by default) — Automatically register all#[derive(SerdeAny)]
types at startup.
§LLMP features
llmp_bind_public
— If set, llmp will bind to 0.0.0.0, allowing cross-device communication. Binds to localhost by default.llmp_compression
(enabled by default) — Enables llmp compression using GZipllmp_debug
— Enables debug output for LLMP (also needs alogger
installed)llmp_small_maps
(enabled by default) — Reduces the initial map size for llmp
Modules§
- anymap
- Poor-rust-man’s downcasts to have
AnyMap
- bolts_
prelude - The purpose of this module is to alleviate imports of the bolts by adding a glob import.
- build_
id - Based on https://github.com/alecmocatta/build_id (C) Alec Mocatta alec@mocatta.net under license MIT or Apache 2
- cli
- A one-size-fits-most approach to defining runtime behavior of
LibAFL
fuzzers - compress
- Compression of events passed between a broker and clients. Currently we use the gzip compression algorithm for its fast decompression performance.
- core_
affinity - This crate manages CPU affinities.
- cpu
- Fast implementations for specific CPU architectures.
- fs
LibAFL
functionality for filesystem interaction- llmp
- A library for low level message passing
- math
- Math-related functions that we commonly (or at least sometimes) need
- minibsod
- Implements a mini-bsod generator. It dumps all important registers and prints a stacktrace.
- os
- Operating System specific abstractions
- ownedref
- Wrappers that abstracts references (or pointers) and owned data accesses.
- prelude
- The purpose of this module is to alleviate imports of many components by adding a glob import.
- pybind
- rands
- The random number generators of
LibAFL
- serdeany
- Poor-rust-man’s downcasts for stuff we send over the wire (or shared maps)
- shmem
- A generic shared memory region to be used by any functions (queues or feedbacks too.)
- staterestore
- Stores and restores state when a client needs to relaunch.
Uses a
ShMem
up to a threshold, then write to disk. - subrange
- Subrange of things. Convenient wrappers to handle sub-slices efficiently.
- tuples
- Compiletime lists/tuples used throughout the
LibAFL
universe
Macros§
- create_
manual_ register - Manually register a
SerdeAny
type in theRegistryBuilder
- create_
register - Register a
SerdeAny
type in theRegistryBuilder
- impl_
serde_ pyobjectwrapper - impl_
serdeany - Implement a
SerdeAny
, registering it in theRegistryBuilder
when on std - map_
tuple_ list_ type - Maps the types of a mapping with a
MappingFunctor
- merge_
tuple_ list_ type - Merges the types of two merged
tuple_list!
s - nonnull_
raw_ mut - Get a
core::ptr::NonNull
to a global static mut (or similar). - nonzero
- Zero-cost way to construct
core::num::NonZeroUsize
at compile-time. - tuple_
for_ each - Iterate over a tuple, executing the given
expr
for each element. - tuple_
for_ each_ mut - Iterate over a tuple, executing the given
expr
for each element, granting mut access. - unwrap_
me_ body - unwrap_
me_ mut_ body
Structs§
- Client
Id - The client ID == the sender id.
- Simple
FdLogger - A simple logger struct that logs to a
RawFd
when used withlog::set_logger
. - Simple
Stderr Logger - A simple logger struct that logs to stderr when used with
log::set_logger
. - Simple
Stdout Logger - A simple logger struct that logs to stdout when used with
log::set_logger
.
Enums§
- Error
- Main error struct for
LibAFL
Constants§
- IP_
LOCALHOST - Localhost addr, this is used, for example, for LLMP Client, which connects to this address
Statics§
- LIBAFL_
STDERR_ LOGGER - Stderr logger
- LIBAFL_
STDOUT_ LOGGER - Stdout logger
Traits§
- AsIter
- Create an
Iterator
from a reference - AsIter
Mut - Create an
Iterator
from a mutable reference - AsSized
Slice - Can be converted to a slice
- AsSized
Slice Mut - Can be converted to a mutable slice
- AsSlice
- Can be converted to a slice
- AsSlice
Mut - Can be converted to a mutable slice
- HasLen
- Has a length field
- HasRef
Cnt - Has a ref count
- Into
Owned - Trait to convert into an Owned type
- Named
- We need fixed names for many parts of this lib.
- Truncate
- Trait to truncate slices and maps to a new size
Functions§
- current_
milliseconds - Gets current milliseconds since
UNIX_EPOCH
- current_
nanos - Gets current nanoseconds since
UNIX_EPOCH
- current_
time - Current time
- dup_
and_ ⚠mute_ outputs - Closes
stdout
andstderr
and returns a newstdout
andstderr
to be used in the fuzzer for further logging. - format_
duration_ hms - Format a
Duration
into a HMS string - generic_
hash_ std - Hashes the input with a given hash
- hash_
64_ fast - Fast hash function for 64 bits integers minimizing collisions. Adapted from https://xorshift.di.unimi.it/splitmix64.c
- hash_
std - Hashes the input with a given hash
- hasher_
std - Returns the standard input
Hasher
- set_
error_ ⚠print_ panic_ hook - Set up an error print hook that will
- vec_
init ⚠ - Create a
Vec
of the given type withnb_elts
elements, initialized in place. The closure must initializeVec
(of sizenb_elts
*sizeo_of::<T>()
).
Type Aliases§
- Error
Backtrace - Error Backtrace type when
errors_backtrace
feature is enabled (==backtrace::Backtrace
)
Derive Macros§
- Serde
Any - Derive macro to implement
SerdeAny
, to use a type in aSerdeAnyMap