From 7d3341643416f2cae3d97fc230d3eb69c0201792 Mon Sep 17 00:00:00 2001 From: Akshat Date: Tue, 20 Oct 2026 03:22:49 +0530 Subject: [PATCH] Add Malduck with a reproducible config-extraction check Run the Malduck check from the issue #6 conditional backlog: a self-authored YARA-triggered extractor recovers an RC4-encrypted config from a self-built sample, and wrong-key and no-marker samples yield no config. The check runs in the resource-example workflow beside the four existing examples. --- .gitignore | 1 + README.md | 1 + docs/priority-candidates.json | 34 +++++++++++++ docs/priority-candidates.md | 10 ++++ examples/resource-intake/README.md | 7 +-- .../malduck_modules/duckcfg/__init__.py | 25 ++++++++++ .../malduck_modules/duckcfg/duckcfg.yar | 7 +++ examples/resource-intake/requirements.txt | 1 + examples/resource-intake/verified.json | 38 +++++++++++--- examples/resource-intake/verify.py | 49 +++++++++++++++++-- 10 files changed, 161 insertions(+), 12 deletions(-) create mode 100644 examples/resource-intake/malduck_modules/duckcfg/__init__.py create mode 100644 examples/resource-intake/malduck_modules/duckcfg/duckcfg.yar diff --git a/.gitignore b/.gitignore index 693b9d2..62a0505 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .DS_Store .lycheecache lychee/ +__pycache__/ diff --git a/README.md b/README.md index 0338c46..ec4fd62 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,7 @@ Run samples only in isolated, disposable environments, and follow your organizat - [CAPE Sandbox](https://github.com/kevoreilly/CAPEv2) - Automated sandbox derived from Cuckoo that runs samples in virtual machines and records behavior, unpacked payloads, and malware configurations. - [FLARE-VM](https://github.com/mandiant/flare-vm) - Installation scripts that turn a Windows virtual machine into a malware-analysis and reverse-engineering workstation. +- [Malduck](https://github.com/CERT-Polska/malduck) - Python library of cryptography, compression, and memory-model helpers with a YARA-driven framework for writing your own malware configuration extractors; it does not ship family extractors. - [oletools](https://github.com/decalage2/oletools) - Python tools for inspecting Office, OLE, and RTF files and extracting macros, embedded objects, and other document artifacts. - [PE-sieve](https://github.com/hasherezade/pe-sieve) - Scans a running process for injected or modified code, such as hollowed modules, hooks, and shellcode, and dumps what it finds. - [REMnux](https://remnux.org/) - Linux toolkit for analyzing malicious executables, documents, scripts, and network traffic, available as a virtual machine, container, or installer. diff --git a/docs/priority-candidates.json b/docs/priority-candidates.json index c9a8c39..bf06d32 100644 --- a/docs/priority-candidates.json +++ b/docs/priority-candidates.json @@ -746,5 +746,39 @@ "automated_result": "HTTP 403", "evidence": "Official page content retrieved during review; exact URL excluded from lychee, not the whole domain." } + ], + "conditional_checks": [ + { + "name": "Malduck", + "url": "https://github.com/CERT-Polska/malduck", + "section": "Malware analysis", + "description": "Python library of cryptography, compression, and memory-model helpers with a YARA-driven framework for writing your own malware configuration extractors; it does not ship family extractors.", + "research_priority": "B", + "decision": "added", + "checked_at": "2026-10-19", + "next_review": "2026-11-19", + "evidence_type": "reproduced (CI)", + "task": "Configuration extraction primitives", + "constraints": "Extractors and YARA rules are user-supplied; useful beside FLOSS/capa, not universal family recovery.", + "sources": [ + "https://raw.githubusercontent.com/CERT-Polska/malduck/0425e0209ec30b656e75ff94071e01c34c4cffa5/README.md" + ], + "source_commit": "0425e0209ec30b656e75ff94071e01c34c4cffa5", + "license_api": "GPL-3.0", + "license_api_is_complete_audit": false, + "canonical_repo": "CERT-Polska/malduck", + "archived": false, + "default_branch_commit_at": "2025-06-22T15:04:14Z", + "github_release": { + "tag_name": "v4.4.1", + "published_at": "2024-05-10T13:20:36Z", + "html_url": "https://github.com/CERT-Polska/malduck/releases/tag/v4.4.1" + }, + "reproduction": "examples/resource-intake/README.md", + "reproduced_scope": "Self-authored YARA-triggered extractor and RC4 config; wrong-key and no-marker samples yield no config", + "source_browser_urls": [ + "https://github.com/CERT-Polska/malduck/blob/0425e0209ec30b656e75ff94071e01c34c4cffa5/README.md" + ] + } ] } diff --git a/docs/priority-candidates.md b/docs/priority-candidates.md index 641e940..cf55746 100644 --- a/docs/priority-candidates.md +++ b/docs/priority-candidates.md @@ -64,3 +64,13 @@ Reviewed on **2026-10-13 UTC**; recheck by **2026-11-13**, or earlier if an upst | WinDbg MCP: [setup](https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/set-up-windbg-mcp) · [overview](https://learn.microsoft.com/en-us/windows-hardware/drivers/debuggercmds/windbg-mcp-overview) | Built into WinDbg 1.2610.1001.0+. Official clients are VS Code with GitHub Copilot and GitHub Copilot CLI; other clients use best-effort custom configuration. Only one active MCP client can connect to each WinDbg session. Protected operations require permitted MCP sampling for cross-prompt injection checks. No Windows target or client was tested here. | For subsequent reviews, confirm the exact host, target, board/backend, distribution channel, and license/edition before widening claims. An archived repository or old reference can remain useful; deprecation and unsupported installation routes require a human decision rather than automatic deletion. + +## Conditional-candidate checks + +Checked on **2026-10-19 UTC**; recheck by **2026-11-19**. Issue #6 lists Malduck among the conditional candidates that need a self-authored extractor and a known encrypted configuration. The fixture, commands, and dated report are in [the examples](../examples/resource-intake/README.md); **reproduced (CI)** means the check runs in the resource-example workflow. + +| Candidate / primary evidence | Result and decision | +| --- | --- | +| Malduck: [README](https://raw.githubusercontent.com/CERT-Polska/malduck/0425e0209ec30b656e75ff94071e01c34c4cffa5/README.md) | **Reproduced (CI), added to Malware analysis.** A self-authored YARA-triggered extractor recovered an RC4-encrypted config built by an independent RC4 implementation; wrong-key and no-marker samples yielded nothing. Malduck supplies primitives and the extraction framework, not family extractors. Latest release v4.4.1 (2024-05-10); default branch last changed 2025-06-22. GPL-3.0. | + +The machine-readable record is under `conditional_checks` in [the JSON snapshot](priority-candidates.json). The other conditional candidates remain in issue #6. diff --git a/examples/resource-intake/README.md b/examples/resource-intake/README.md index 6515e7f..576ab49 100644 --- a/examples/resource-intake/README.md +++ b/examples/resource-intake/README.md @@ -1,6 +1,6 @@ -# Four bounded resource examples +# Five bounded resource examples -These self-authored fixtures demonstrate Construct, Scapy, YARA-X, and Vineflower. They are small selection examples, not upstream test suites or evidence of full platform/version support. +These self-authored fixtures demonstrate Construct, Scapy, YARA-X, Vineflower, and Malduck. They are small selection examples, not upstream test suites or evidence of full platform/version support. Use Python 3.11 with `venv`/`pip` support, JDK 17, and an Internet connection for the pinned packages and JAR. From the repository root: @@ -19,6 +19,7 @@ The runner downloads [Vineflower 1.12.0](https://github.com/Vineflower/vineflowe | Scapy 2.8.0 | Known Ethernet/IP/UDP fields and `trace` payload; independent IP/UDP checksum checks; PCAP write/read | Offline packets only, no transmission or live capture | | YARA-X 1.21.0 | Self-authored rule matches the golden bytes and not `negative sample`; unescaped `{` in a regex produces `CompileError` | Python API and this documented regex difference, not all YARA rules/modules | | Vineflower 1.12.0 | Java 17 record and switch expression; compile → decompile → rebuild; main prints `25`, five branch vectors match explicit expected values | This fixture only, no obfuscation or other Java target versions | +| Malduck 4.4.1 | A [self-authored extractor](malduck_modules/duckcfg/__init__.py) and [YARA rule](malduck_modules/duckcfg/duckcfg.yar); a sample with marker `DKCFG1`, an 8-byte key, and a config encrypted by an independent RC4 implementation yields two C2 URLs, campaign `trace-7`, and sleep `300`; wrong-key and no-marker samples yield no config | Extractor framework, procmem reads, and RC4 only; no real malware family | The branch oracle for `Probe.java` is: @@ -30,6 +31,6 @@ The branch oracle for `Probe.java` is: 9:-1 ``` -The [dated local result](verified.json) records host/tool versions, input hashes, artifact digest, and the tested scope. CI repeats the examples and uploads current results through the [resource-example workflow](../../.github/workflows/resource-examples.yml). The current job uses Linux, Python 3.11, and Java 17; it makes no Windows, macOS, hardware, or other-version claim. +The [dated local result](verified.json) records host/tool versions, input hashes, artifact digests, and the tested scope; it was produced in a Linux x86_64 container. CI repeats the examples and uploads current results through the [resource-example workflow](../../.github/workflows/resource-examples.yml). The current job uses Linux, Python 3.11, and Java 17; it makes no Windows, macOS, hardware, or other-version claim. See the [candidate review](../../docs/priority-candidates.md) for primary sources, documented requirements, and the nineteen entries without execution verification. diff --git a/examples/resource-intake/malduck_modules/duckcfg/__init__.py b/examples/resource-intake/malduck_modules/duckcfg/__init__.py new file mode 100644 index 0000000..cf28cb6 --- /dev/null +++ b/examples/resource-intake/malduck_modules/duckcfg/__init__.py @@ -0,0 +1,25 @@ +"""Self-authored Malduck extractor for the DKCFG1 fixture: marker, 8-byte RC4 key, uint16 length, ciphertext.""" +from malduck import Extractor, rc4 + + +class DuckCfg(Extractor): + family = "duckcfg" + yara_rules = ("duckcfg",) + + @Extractor.string("cfg") + def config_block(self, p, addr, match): + key = p.readv(addr + 6, 8) + size = p.uint16v(addr + 14) + plain = rc4(key, p.readv(addr + 16, size)) + if not plain.startswith(b"c2="): + return None + config = {"family": self.family, "urls": []} + for field in plain.decode("ascii").split(";"): + name, value = field.split("=", 1) + if name == "c2": + config["urls"].append(value) + elif name == "campaign": + config["campaign"] = value + elif name == "sleep": + config["sleep"] = int(value) + return config diff --git a/examples/resource-intake/malduck_modules/duckcfg/duckcfg.yar b/examples/resource-intake/malduck_modules/duckcfg/duckcfg.yar new file mode 100644 index 0000000..dc4fa1d --- /dev/null +++ b/examples/resource-intake/malduck_modules/duckcfg/duckcfg.yar @@ -0,0 +1,7 @@ +rule duckcfg +{ + strings: + $cfg = "DKCFG1" + condition: + $cfg +} diff --git a/examples/resource-intake/requirements.txt b/examples/resource-intake/requirements.txt index 0c5393c..e71d83b 100644 --- a/examples/resource-intake/requirements.txt +++ b/examples/resource-intake/requirements.txt @@ -1,3 +1,4 @@ construct==2.10.70 scapy==2.8.0 yara-x==1.21.0 +malduck==4.4.1 diff --git a/examples/resource-intake/verified.json b/examples/resource-intake/verified.json index 83b6471..a3f7abb 100644 --- a/examples/resource-intake/verified.json +++ b/examples/resource-intake/verified.json @@ -1,8 +1,8 @@ { - "checked_at": "2026-10-13T02:59:07.191970+00:00", + "checked_at": "2026-10-19T21:51:28.521712+00:00", "host": { - "platform": "Linux-6.1.0-53-cloud-amd64-x86_64-with-glibc2.36", - "python": "3.11.2", + "platform": "Linux-6.8.0-117-generic-x86_64-with-glibc2.36", + "python": "3.11.17", "javac": "javac 17.0.20.1" }, "results": [ @@ -29,6 +29,12 @@ "version": "1.12.0", "result": "passed", "scope": "Java 17 record/switch expression, rebuild, main output and five branch vectors" + }, + { + "name": "Malduck", + "version": "4.4.1", + "result": "passed", + "scope": "Self-authored YARA-triggered extractor and RC4 config; wrong-key and no-marker samples yield no config" } ], "inputs": [ @@ -40,13 +46,21 @@ "path": "Probe.java", "sha256": "efecf11dc98b876125987476835805989b2fa2f6b52b722b695d7711169fe67a" }, + { + "path": "malduck_modules/duckcfg/__init__.py", + "sha256": "21ec275a54f2a24121648e37f6a75c69d528a3498c34179e0ef2f6634b50fb8a" + }, + { + "path": "malduck_modules/duckcfg/duckcfg.yar", + "sha256": "7b36aaf95fad7f8544eb87962b61277d383ce616d43fd880c3ee4f74a9001581" + }, { "path": "verify.py", - "sha256": "a25cf9c230b8e0d2016d225ff2b8abbf461883f1102df3b9ab5cdcd4e9f3f93e" + "sha256": "fcd9e83f2d18fc595296f193acd3fcdd23b104727361411d16a63c0ffdad6990" }, { "path": "requirements.txt", - "sha256": "db6df24e77cc6098c67850a1589720247932a58694261684b9351d0a6bc8ede3" + "sha256": "59e3114feda99afa36dfc0ca42d9f31660e5ddb6b6bddb2c1fb8ed0c821d85b0" } ], "golden_hex": "534d4b310500017472616365", @@ -61,5 +75,17 @@ "1:22", "2:22", "9:-1" - ] + ], + "malduck": { + "sample_sha256": "23366aee6b6831f13d37926ab773ef0319f6fb36be3295ca778d5858da3af2e3", + "expected_config": { + "family": "duckcfg", + "urls": [ + "http://192.0.2.10/gate", + "http://198.51.100.7/gate" + ], + "campaign": "trace-7", + "sleep": 300 + } + } } diff --git a/examples/resource-intake/verify.py b/examples/resource-intake/verify.py index e7c2c98..a9b3c44 100644 --- a/examples/resource-intake/verify.py +++ b/examples/resource-intake/verify.py @@ -1,4 +1,4 @@ -"""Reproduce four narrow resource examples with independent expected outputs.""" +"""Reproduce five narrow resource examples with independent expected outputs.""" import argparse from datetime import datetime, timezone import hashlib @@ -14,12 +14,16 @@ from urllib.request import urlopen from construct import Byte, Bytes, Const, ConstructError, Int16ul, Struct, Terminated from scapy.all import Ether, IP, Raw, UDP, rdpcap, wrpcap import yara_x +from malduck.extractor import ExtractManager, ExtractorModules SOURCE = Path(__file__).resolve().parent JAR_URL = "https://github.com/Vineflower/vineflower/releases/download/1.12.0/vineflower-1.12.0.jar" JAR_SHA256 = "1dfcfe974395734fa467ce620661c7623d05ba83670de0529b1fbd63ff548b9d" GOLDEN = bytes.fromhex("534d4b310500017472616365") EXPECTED_BRANCHES = "-1:-1\n0:11\n1:22\n2:22\n9:-1" +DUCK_KEY = b"duck-key" +DUCK_PLAIN = b"c2=http://192.0.2.10/gate;c2=http://198.51.100.7/gate;campaign=trace-7;sleep=300" +DUCK_CONFIG = {"family": "duckcfg", "urls": ["http://192.0.2.10/gate", "http://198.51.100.7/gate"], "campaign": "trace-7", "sleep": 300} def sha256(path): @@ -41,8 +45,41 @@ def run(*args): return completed.stdout.strip() +def rc4(key, data): + """Independent RC4 used only to build the Malduck fixture.""" + state, j = list(range(256)), 0 + for i in range(256): + j = (j + state[i] + key[i % len(key)]) & 0xFF + state[i], state[j] = state[j], state[i] + i = j = 0 + out = bytearray() + for byte in data: + i = (i + 1) & 0xFF + j = (j + state[i]) & 0xFF + state[i], state[j] = state[j], state[i] + out.append(byte ^ state[(state[i] + state[j]) & 0xFF]) + return bytes(out) + + +def duck_sample(key=DUCK_KEY, marker=b"DKCFG1"): + return b"\x00" * 64 + marker + DUCK_KEY + struct.pack("