
Rust binary deobfuscation with rust-deobf
strings sees nothing. FLOSS sees nothing. rust-deobf sees the C2.
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
strings sees nothing. FLOSS sees nothing. rust-deobf sees the C2.
rust-deobf recovers what obfuscated Rust binaries hide — C2 addresses, file paths, mutexes, registry keys, config — without ever running the sample.
Demo · Use it from an AI agent · Quick start · Results · Real malware · Limitations
A stripped Rust program built the way malware ships (opt-level="z", fat LTO, panic=abort), with its eight indicators encrypted by obfstr — the strings sit in a struct, match arms, comparisons, and a branch that never runs. None is ever printed.
Rendered from the captured output of a real run (Linux x86-64, rustc 1.97): the text is verbatim, the colours and typing animation are added, the ~8 s emulation wait is sped up, and the output is trimmed to the decoded strings. The plain-text output below is the same run.
$ B=build/scatter_obfstr__elf__size-lto__strip $ strings $B | grep -ciE 'northwind|10.66|NW-5c1e9a|skip-update' 0
What rust-deobf recovers (static + Unicorn emulation; the binary is never executed):
$ python3 scripts/recover.py $B binary: scatter_obfstr__elf__size-lto__strip format=ELF arch=x86_64 static x86-64 (recover_callsite): 0 strings decoders=9 seconds=0.2 emulation (recover_emulate): 8 strings functions=416/416 timed_out=False workers=1 seconds=6.8
== decoded strings == 10.66.12.7:8443 [ip] function 0xf20c (emulation) C:\ProgramData\NorthwindSvc\state.db [path] function 0xf20c (emulation) Mozilla/5.0 (Windows NT 10.0; Win64; x64) NorthwindAgent/2.1 function 0xf20c (emulation) --skip-update-check function 0xf443 (emulation) Software\Northwind\Agent\Settings [registry] function 0xf51b (emulation) Global\NW-5c1e9a [mutex] function 0xf5a8 (emulation) https://telemetry.northwind.example/api/v3/beacon [url] function 0xfd58 (emulation) nw-agent::stage=collect function 0xfd58 (emulation)
8/8 in under 10 seconds, each string tagged and traced to the function that builds it. Reproduce it with ONLY=scatter_obfstr PROFILES=size-lto FORMATS=elf bash scripts/build_all.sh (output trimmed to the decoded strings). (The input is a benign benchmark program; every planted string is listed in bench_src/manifest.json.)
Rust malware is rising, and its deobfuscation tooling is effectively absent. FLOSS — the standard open-source string deobfuscator — recovers nothing from the common Rust obfuscation crates:
Canary benchmark, release builds, ELF and PE x86-64 and AArch64, stripped and not. Full table, including the one case that needs dynamic recovery (cryptify with a custom key), under Results.
On real samples: EDDIESTEALER (PE) — 32 obfuscated strings including its hidden C2 domain and URL path, where static tools and FLOSS recover 0. AmnesiaStealer (macOS Mach-O) — C2 exfil URL, crypto-clipper config, staging paths. More below.
String deobfuscation — static call-site recovery (seconds) + a Unicorn emulation engine with a real loader, a C runtime, path exploration and global-constructor replay. Recovers strings built only in one match arm or on a branch that never runs.
One-screen SOC triage — soc_triage.py: format/arch, Rust toolchain, crate capability fingerprint (networking / crypto / recon / persistence / staging), indicators grouped by type, and a calibrated LOW / MEDIUM / HIGH signal with its evidence. --json for a SIEM, --fail-on HIGH for scripted gating. --fast (metadata + literal indicators, no decoding) scales with binary size: under a second on a small sample, ~20 s on a 20 MB binary.
Multi-arch, multi-format — x86-64, ARM64 and 32-bit x86 across ELF, PE and Mach-O.
Fits your workflow — FLOSS-compatible export (--floss-json), headless Ghidra annotation (plate comments, bookmarks, renames), library-function identification by byte signature (lib_<name> in stripped binaries), batch mode over a directory (--jsonl).
Beyond strings — config/C2 extraction, hash-obfuscated API-import resolution, unpacked stage-2 carving, control-flow-flattening detection and reconstruction (x86-64 and AArch64, validated on goldberg, OLLVM -fla and a real LLVM-18 flattening pass), MBA / opaque-predicate simplification with Z3, Rust trait-object vtable recovery (recover_types.py), and optimization-reversal (jump-table un-switching, unrolled-loop detection — premium/opt_reverse.py).
Code virtualization — detect_vm.py flags VMProtect/Themida/Tigress-style bytecode VMs; the premium devirtualizer lifts them back. From a VM with randomized opcodes and encrypted operands, it reconstructs:
return (((a0 > 1000) & (((((a0 * 31) + a1) ^ (a0 >> 3)) % 97) == 0)) ? (a1 + a0) : 0xffffffff);
— the function's exact source.
Safe by design — static + emulation by default: emulation runs functions of the binary under Unicorn, never the binary itself. Dynamic (Frida) recovery is opt-in and for isolated VMs only.
Rust metadata that survives strip — rustc version, third-party crates with exact versions, and panic sites, rebuilt from the source paths the compiler leaves in every Rust binary (no cargo-auditable needed).
A decompiler's string view, strings, FLOSS — anything that reads strings from the file — can only show bytes that are in the file. An obfuscation crate makes sure the plaintext never is, so an AI agent reading a decompiler sees the same nothing you do. rust-deobf gives it the facts instead.
It is a CLI with JSON output, so any agent that can run shell commands (Claude Code, Codex, Cursor, …) can call it next to whatever decompiler tooling it already drives:
python3 scripts/soc_triage.py sample.bin --json # one-screen facts: toolchain, crates, IOCs, signal python3 scripts/recover.py sample.bin --json # every decoded string + the function that builds it scripts/ghidra_run.sh sample.bin # write them into the Ghidra decompiler as plate comments python3 scripts/mcp_server.py # or serve recover/triage/metadata/detect as MCP tools
Prefer typed tools over CLI parsing? scripts/mcp_server.py exposes detect / metadata / triage / recover as MCP tools over stdio (no third-party package needed), so an agent calls them with a JSON schema and gets structured JSON back. And scripts/export_rules.py turns the recovered facts into capa rules and YARA rules (the Mandiant detection formats), for the obfuscation crates and from the recovered decoder idioms / hash-obfuscated imports — --static-only emits the crate family ruleset for any corpus.
"Run python3 scripts/soc_triage.py sample.bin --json and python3 scripts/recover.py sample.bin --json from rust-deobf, then decompile the functions those strings came from and explain what they do. Treat rust-deobf's decoded strings as ground truth; label anything you infer as a hypothesis."
Want the LLM step built in? scripts/llm_triage.py hands only the recovered facts (never the raw binary) to a local model (Ollama / vLLM via RUST_DEOBF_LLM_BASE — malware data stays on your host), the Anthropic or OpenAI API, or prints the grounded prompt for offline use.
git clone https://github.com/VAHPEM/rust-deobf.git cd rust-deobf python3 -m pip install -r requirements.txt # lief, capstone, unicorn, z3-solver
python3 scripts/recover.py path/to/binary # static + emulation (default), never runs it python3 scripts/soc_triage.py path/to/binary # one-screen triage card python3 scripts/recover.py path/to/binary --json # machine-readable, for agents and pipelines
All options python3 scripts/recover.py path/to/binary --floss-json out.json # FLOSS results document python3 scripts/recover.py path/to/binary --emulate never # static passes only, seconds python3 scripts/recover.py path/to/binary --time-budget 600 # big binaries: emulate longer python3 scripts/recover.py path/to/binary --max-ram 2G # cap memory (fewer processes) python3 scripts/recover.py path/to/binary --libfuncs # also name Rust std/crate functions python3 scripts/recover.py samples/ --jsonl triage.jsonl # a whole directory
name library functions in a stripped binary (needs a signature DB for its toolchain):
python3 scripts/recover_libfuncs.py --gen build/releasenostrip # build the DB once per toolchain python3 scripts/recover_libfuncs.py path/to/binary # identify; --json for records python3 scripts/recover_libfuncs.py path/to/binary --propagate # + call-graph thunks & drop-glue
recover Rust trait-object vtables (dyn Trait dispatch) as Ghidra data types:
python3 scripts/recover_types.py path/to/binary # --json for records
push strings + library names + vtables into Ghidra (headless, PyGhidra):
scripts/ghidra_run.sh path/to/binary
AI-assisted read over the recovered facts only (local model, API, or --offline):
python3 scripts/llm_triage.py path/to/binary
runtime-only decoders, inside an isolated analysis VM ONLY (pip install frida frida-tools)
it EXECUTES the sample, so it refuses to start without the explicit opt-in flag
python3 scripts/recover_dynamic.py path/to/binary --i-understand-this-executes [--argv arg1 arg2 ...]
Exit codes (recover.py, soc_triage.py, llm_triage.py): 0 the analysis ran, 2 usage error, 3 unsupported or unparseable input (not an ELF/PE/Mach-O LIEF can read — e.g. a text file), 4 analysis error (an engine raised; the other engines still ran and their output is printed; in directory mode, at least one file failed — the table's error column says which). soc_triage.py --fail-on MEDIUM|HIGH exits 1 when the signal reaches that level. Directory mode analyses every binary single-file mode supports (32-bit x86 included), and counts the files it skipped.
Emulation runs by default and is bounded by --time-budget (120 s): functions are tried in decoder-score order, and the output says how many were emulated (functions=412/1671) and whether the budget ran out. Memory is the other knob: a large binary is split across worker processes (RUST_DEOBF_WORKERS, default min(4, CPUs)), each holding its own loaded image and Unicorn instance — roughly 250 MB plus 45 MB per MB of .text, so ≈0.5 GB for gdb and ≈1.1 GB for cargo. --max-ram 2G (or RUST_DEOBF_MAX_RAM_MB) caps the process count to fit that budget, trading speed for memory; a budget below one process's footprint runs serially, slower, and the output reports both the process count and the reduction.
Every number here is a test or a script in this repo, and the benchmark publishes the cases where the tool does not work too.
python scripts/eval_scatter.py — the default recover.py pipeline, exact matches out of 8; (+n) = extra strings reported (false positives). plaintext is the same program with plain literals: everything it reports is a false positive.
360/360 exact strings and 0 extra across all 54 binaries (stripped builds); the code an external review tested got 79/360. Every cell is a test in tests/test_scatter.py.
Release builds, ELF and PE x86-64 and AArch64, stripped and not; size-lto/speed-lto builds of every crate are tested too. Static = reads the decoder's key and the call sites without running anything; emulation = Unicorn, never runs the sample natively; dynamic = Frida in an isolated VM.
¹ cryptify reads CRYPTIFY_KEY again at run time: with a custom key the sample only decrypts when run with that variable set, and the key is not in the binary. recover_cryptify detects the crate and says so.
The benchmark's own programs rebuilt with release settings the benchmark never uses, stripped (CARGO_PROFILE_RELEASE_* overrides). Exact strings; +n = junk strings reported.
Each set was built after the fixes for the previous one, measured once ("first measured": the honest held-out number, 98–99 % exact with a few junk strings), and then used to find and fix its failures — so the "now" column is no longer held-out. The next independent review will say how the current code does on what nobody has seen.
scripts/measure_fp.py --pipeline --corpus (static + emulation, 120 s budget): every decoded string reported is a false positive. The corpus mixes C/C++, Go and Rust binaries, because the six binaries the filters were developed against (bash, tar, xz, git, curl, ripgrep: 0) overstated precision — Xvfb and a Go bina
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。