Read about it here!
cbexec scans PE images for callback-execution sites: functions that perform an
indirect call/jmp through a pointer they were handed as an argument.
This can be used for call-stack spoofing, to make a thread's stack originate from a legitimate module and can also help defenders by issuing a list of callback functions to hook or pay attention to when found in stacks.
For educational and blue team, defensive research purposes only. Use only on systems you own or are authorised to test. No warranty are offered.
pip install -r requirements.txt
Requires python3 with pefile and capstone.
python3 find_cb_exec.py <dll-or-dir>... [-r] [-j N] [-o DIR]
-r recurses into directories, -j sets parallel workers (0 = auto), and
-o sets the output directory (default out/). Writes
cbexec.jsonl, cbexec_hits.tsv, cbexec_summary.tsv and
cbexec_report.md.
$ python3 find_cb_exec.py /path/to/dlls -r -j 8 -o /tmp/out/cbexec
[1/112] acmigration.dll funcs=1273 icalls=351 hits=146
...
[112/112] wpx.dll funcs=1552 icalls=6529 hits=2403
CBEXEC_DONE files=112 funcs=114672 icalls=123647 cfg=122389 hits=69735 out=/tmp/out/cbexec
One hit as it appears in cbexec.jsonl:
{
"call": "0x1800011b9", "kind": "call", "form": "reg",
"tier": "derived", "args": [6], "insn": "call 0x180064010 ; cfg -> rax",
"bytes": "e8522e0600", "via": "cfg",
"func": "0x180001150", "fname": "sub_180001150", "fsize": 116,
"offset": 105, "is_named": false
}Each hit records the transfer address and the function that contains it, plus two fields for direct use:
| field | meaning |
|---|---|
offset |
byte distance from the containing function's entry to the call/jmp. Jump here to skip the prologue |
is_named |
true when the containing function is an export with a real symbol name, false for a sub_<va> label |
tier is direct when the argument value itself is the transfer target, and
derived when the target is loaded or computed through the argument
(struct/vtable dispatch). Sites whose instruction text ends in ; cfg -> reg
are /guard:cf dispatches, flagged via=cfg in the jsonl. The report lists
direct-tier sites first, then named functions, then the lowest argument index.
python3 tests/verify.py
Scans tests/fixture.dll (a committed 64-bit build of tests/fixture.c, one
named direct-tier site and one unnamed derived-tier site) and compares every
hit against tests/expected.json, plus asserts the offset and is_named
invariants. sh tests/build.sh rebuilds the fixture and its expectation, and
needs x86_64-w64-mingw32-gcc.
See LICENSE.