From 4e4bd171253fa8be7488f2e11defe32fa1726f86 Mon Sep 17 00:00:00 2001 From: Akshat Date: Wed, 21 Oct 2026 15:05:18 +0530 Subject: [PATCH] Add MemProcFS with a reproducible raw-image check Run the MemProcFS check from the issue #6 conditional backlog: a self-built x64 page table in a raw image is opened through the Python API with a user-supplied DTB, and physical reads, virtual reads, virt2phys, and /memory.pmem match the planted markers. The check runs on Linux x86-64 only, where the pinned wheels need leechcorepyc and libusb-1.0; other hosts record it as skipped. The prerequisite tests cover the platform-limited pins and the missing-libusb diagnostic. --- .github/workflows/resource-examples.yml | 2 + README.md | 1 + docs/priority-candidates.json | 32 ++++++++++++ docs/priority-candidates.md | 3 +- examples/resource-intake/README.md | 11 ++-- examples/resource-intake/memprocfs_probe.py | 18 +++++++ examples/resource-intake/requirements.txt | 2 + examples/resource-intake/verified.json | 32 +++++++++--- examples/resource-intake/verify.py | 58 +++++++++++++++++++-- tests/test_resource_prerequisites.py | 24 ++++++++- 10 files changed, 165 insertions(+), 18 deletions(-) create mode 100644 examples/resource-intake/memprocfs_probe.py diff --git a/.github/workflows/resource-examples.yml b/.github/workflows/resource-examples.yml index c97e2e7..497a67b 100644 --- a/.github/workflows/resource-examples.yml +++ b/.github/workflows/resource-examples.yml @@ -41,6 +41,8 @@ jobs: node-version: '22' - name: Check prerequisite diagnostics run: python -m unittest discover -s tests -p test_resource_prerequisites.py -v + - name: Install MemProcFS runtime library + run: sudo apt-get install -y --no-install-recommends libusb-1.0-0 - name: Install pinned example dependencies run: python -m pip install -r examples/resource-intake/requirements.txt - name: Reproduce the bounded examples diff --git a/README.md b/README.md index 341f648..792b3f2 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,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. +- [MemProcFS](https://github.com/ufrisk/MemProcFS) - Exposes memory dumps and live memory as a virtual file system and Python, C, and Rust APIs, with process and forensic views for Windows targets; mounting requires Dokany, FUSE, or macFUSE. - [mwemu](https://github.com/mwemuorg/mwemu) - Emulates x86/x64 and AArch64 code for PE, ELF, and Mach-O investigations, with Windows API models and kernel-driver memory-lifetime checks; Windows-focused, with growing Linux/macOS support and Rust 1.95+ required to build the reviewed source. - [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. diff --git a/docs/priority-candidates.json b/docs/priority-candidates.json index af03a97..43a4641 100644 --- a/docs/priority-candidates.json +++ b/docs/priority-candidates.json @@ -811,6 +811,38 @@ "source_browser_urls": [ "https://github.com/CERT-Polska/malduck/blob/0425e0209ec30b656e75ff94071e01c34c4cffa5/README.md" ] + }, + { + "name": "MemProcFS", + "url": "https://github.com/ufrisk/MemProcFS", + "section": "Malware analysis", + "description": "Exposes memory dumps and live memory as a virtual file system and Python, C, and Rust APIs, with process and forensic views for Windows targets; mounting requires Dokany, FUSE, or macFUSE.", + "research_priority": "B", + "decision": "added", + "checked_at": "2026-10-19", + "next_review": "2026-11-19", + "evidence_type": "reproduced (CI)", + "task": "Memory dumps as files/APIs", + "constraints": "Runs on Linux x86-64 only in this check; raw images without a recognizable OS need -dtb; Windows process, registry, and forensic views were not exercised; the Linux pip wheel needs leechcorepyc and libusb-1.0.", + "sources": [ + "https://raw.githubusercontent.com/ufrisk/MemProcFS/a81e7960d6f17a4adfc77c080f94e631d74b2fb9/README.md" + ], + "source_commit": "a81e7960d6f17a4adfc77c080f94e631d74b2fb9", + "license_api": "AGPL-3.0", + "license_api_is_complete_audit": false, + "canonical_repo": "ufrisk/MemProcFS", + "archived": false, + "default_branch_commit_at": "2026-10-05T18:10:04Z", + "github_release": { + "tag_name": "v5.19", + "published_at": "2026-10-05T17:38:01Z", + "html_url": "https://github.com/ufrisk/MemProcFS/releases/tag/v5.19" + }, + "reproduction": "examples/resource-intake/README.md", + "reproduced_scope": "Self-authored raw image: physical read, user-supplied DTB fallback process, virtual read, virt2phys, /memory.pmem; no Windows OS analysis", + "source_browser_urls": [ + "https://github.com/ufrisk/MemProcFS/blob/a81e7960d6f17a4adfc77c080f94e631d74b2fb9/README.md" + ] } ] } diff --git a/docs/priority-candidates.md b/docs/priority-candidates.md index afaa1b4..248f203 100644 --- a/docs/priority-candidates.md +++ b/docs/priority-candidates.md @@ -67,9 +67,10 @@ For subsequent reviews, confirm the exact host, target, board/backend, distribut ## Additional conditional candidates (2026-10-19) -Checked on **2026-10-19 UTC**; recheck by **2026-11-19**. These address the Malduck extractor and newer Hermes-bytecode items in issue #6. Fixtures, commands and dated results are in [the examples](../examples/resource-intake/README.md); **reproduced (CI)** means the bounded checks run in the resource-example workflow. +Checked on **2026-10-19 UTC**; recheck by **2026-11-19**. These address the Malduck extractor, newer Hermes-bytecode, and MemProcFS dump-API items in issue #6. Fixtures, commands and dated results are in [the examples](../examples/resource-intake/README.md); **reproduced (CI)** means the bounded checks run 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. | | hermes-dec: [README](https://raw.githubusercontent.com/P1sec/hermes-dec/2e796663e1fedb93dca51060797ebf3327b3fedb/README.md) | **Reproduced (CI), added to Language runtimes and packagers.** HBC 98 and 99 fixtures from pinned `hermes-compiler` builds parse, disassemble, and decompile with function names, strings, and branches intact, but with an unsupported-version warning. With `-g1` debug info, `hbc-file-parser` raises a `TypeError` after printing the header. The pseudo-code does not preserve JavaScript behavior: executing it prints `21` where the original prints `25`, because registers are shared across functions. Release 0.1.8 (2026-10-15) is newer than the 2026-10-13 research snapshot. AGPL-3.0-or-later. | +| MemProcFS: [README](https://raw.githubusercontent.com/ufrisk/MemProcFS/a81e7960d6f17a4adfc77c080f94e631d74b2fb9/README.md) | **Reproduced (CI) on Linux x86-64, bounded; added to Malware analysis beside Volatility 3.** With a user-supplied DTB, a self-built x64 page table in a raw image produced a single `unknown_process`, correct physical and virtual reads, `virt2phys`, and `/memory.pmem` file reads. Without a recognizable OS, initialization fails. No Windows dump was available, so process, registry, and forensic views remain **documented**. The pip wheels are Linux x86-64 and Windows x64 only; on Linux they need `leechcorepyc` (for `leechcore.so`) and `libusb-1.0`. Release v5.19 (2026-10-05). AGPL-3.0. | diff --git a/examples/resource-intake/README.md b/examples/resource-intake/README.md index 2443f02..05dfbd3 100644 --- a/examples/resource-intake/README.md +++ b/examples/resource-intake/README.md @@ -1,6 +1,6 @@ -# Five bounded resource examples +# Seven bounded resource examples -These self-authored fixtures demonstrate Construct, Scapy, YARA-X, Vineflower, Malduck, and hermes-dec. 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, Malduck, hermes-dec, and MemProcFS. 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, Node.js, and an Internet connection for the pinned packages, JAR, and Hermes compilers. From the repository root: @@ -15,6 +15,8 @@ The runner downloads [Vineflower 1.12.0](https://github.com/Vineflower/vineflowe The Hermes fixture additionally needs Node.js (CI uses Node.js 22). Its pinned compilers provide Linux x86-64, universal macOS, and Windows x86-64 binaries; native Windows/macOS execution is not part of this repository's verification. +MemProcFS runs only on Linux x86-64, where it also needs the system `libusb-1.0` library (`sudo apt-get install libusb-1.0-0` on Debian/Ubuntu). Its pinned wheels are installed only on that host, and on other hosts the runner records MemProcFS as `skipped`. + On Windows, use this PowerShell block with Python 3.11 and JDK 17 or newer (`java` and `javac` on `PATH`). The verifier checks both Java versions before running the fixtures. Use `python` in place of `py -3.11` if that is your Python 3.11 launcher. ```powershell @@ -34,6 +36,7 @@ $resourcePython = Join-Path $resourceExamplesDir "venv\Scripts\python.exe" | 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 | | hermes-dec 0.1.8 | [`hbc_fixture.js`](hbc_fixture.js) compiled by `hermes-compiler` 250829098.0.19 (HBC 98) and 260318099.0.4 (HBC 99) at `-g0` and `-g1`; header version, disassembly, and pseudo-code landmarks (function names, strings, ``, constant `7`) | See the limits below | +| MemProcFS 5.19.0 | A 16 MiB raw image with a self-built x64 page table; with `-dtb 0x10000` the [probe](memprocfs_probe.py) shows one `unknown_process`, reads `MPFS-PHYS-MARK-1` at physical `0x1000` and through `/memory.pmem`, and translates `0x140001678` to physical `0x345678` where it reads `MPFS-VIRT-MARK-2` | Physical-memory, page-table, and virtual-file-system API on Linux x86-64 only; no Windows OS analysis | The branch oracle for `Probe.java` is: @@ -51,6 +54,8 @@ The hermes-dec check also records three limits: - With `-g1` location info, `hbc-file-parser` prints the header and then raises a `TypeError` in `debug_info_parser.py`; `-g0` files parse cleanly. The disassembler and decompiler succeed at both levels. - The original fixture prints `even:negative:25` under Node.js; executing the pseudo-code prints `even:negative:21`, because register variables are shared across functions instead of being local to each call. -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, Java 17, and Node.js 22; it makes no Windows, macOS, hardware, or other-version claim. +Without `-dtb`, MemProcFS rejects a raw image that contains no identifiable operating system (`Unable to locate valid DTB`). The Linux `memprocfs` wheel does not include `leechcore.so`; the runner uses the one from `leechcorepyc` by starting the probe with `LD_LIBRARY_PATH` pointing at its directory. + +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 x86-64, Python 3.11, Java 17, Node.js 22, and `libusb-1.0`; 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/memprocfs_probe.py b/examples/resource-intake/memprocfs_probe.py new file mode 100644 index 0000000..37e0273 --- /dev/null +++ b/examples/resource-intake/memprocfs_probe.py @@ -0,0 +1,18 @@ +"""Read a self-authored raw image through the MemProcFS Python API and print the observations as JSON.""" +import json +import sys + +import memprocfs + +image, dtb, va = sys.argv[1], int(sys.argv[2], 0), int(sys.argv[3], 0) +vmm = memprocfs.Vmm(["-device", image, "-dtb", hex(dtb), "-disable-python", "-disable-symbolserver"]) +process = vmm.process_list()[0] +print(json.dumps({ + "physical": vmm.memory.read(0x1000, 16).hex(), + "processes": [[p.pid, p.name, p.dtb] for p in vmm.process_list()], + "virtual": process.memory.read(va, 16).hex(), + "virt2phys": process.memory.virt2phys(va), + "pmem_file": vmm.vfs.read("/memory.pmem", 16, 0x1000).hex(), + "root": sorted(vmm.vfs.list("/")), +})) +vmm.close() diff --git a/examples/resource-intake/requirements.txt b/examples/resource-intake/requirements.txt index fdcafeb..c6f44be 100644 --- a/examples/resource-intake/requirements.txt +++ b/examples/resource-intake/requirements.txt @@ -3,3 +3,5 @@ scapy==2.8.0 yara-x==1.21.0 hermes-dec==0.1.8 malduck==4.4.1 +memprocfs==5.19.0; sys_platform == "linux" and platform_machine == "x86_64" +leechcorepyc==2.23.3; sys_platform == "linux" and platform_machine == "x86_64" diff --git a/examples/resource-intake/verified.json b/examples/resource-intake/verified.json index b54fa16..8ab63dd 100644 --- a/examples/resource-intake/verified.json +++ b/examples/resource-intake/verified.json @@ -1,10 +1,10 @@ { - "checked_at": "2026-10-20T14:20:47.418756+00:00", + "checked_at": "2026-10-21T09:33:32.652177+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", - "node": "v24.21.0" + "node": "v22.23.3" }, "results": [ { @@ -42,6 +42,12 @@ "version": "0.1.8", "result": "passed", "scope": "HBC 98/99 at -g0/-g1: header, disassembly and pseudo-code landmarks; -g1 debug-info parsing raises TypeError; executing the pseudo-code prints 21, not 25" + }, + { + "name": "MemProcFS", + "version": "5.19.0", + "result": "passed", + "scope": "Self-authored raw image: physical read, user-supplied DTB fallback process, virtual read, virt2phys, /memory.pmem; no Windows OS analysis" } ], "inputs": [ @@ -65,13 +71,17 @@ "path": "malduck_modules/duckcfg/duckcfg.yar", "sha256": "7b36aaf95fad7f8544eb87962b61277d383ce616d43fd880c3ee4f74a9001581" }, + { + "path": "memprocfs_probe.py", + "sha256": "28371a05c81ddf4af7515350adf3868b40e6584880abc490bc7b0f393f7804fb" + }, { "path": "verify.py", - "sha256": "1d06631607af8e9cfd8c0f85e55792dd1e672b2c00f75cbaaf772511e50d9b09" + "sha256": "05071536e95b054bc81aa1494476b4759aa301745707542a86649fd69adcf287" }, { "path": "requirements.txt", - "sha256": "e82f3a0ec8e0920c97b12fc63d92cfe34c898c2999ac70c6dba931ea21ac8d05" + "sha256": "d55a1c0b3c8657ac2955f8d99a8ddc9639cb4b021fc9e7228cbc6d430f010681" } ], "golden_hex": "534d4b310500017472616365", @@ -113,14 +123,20 @@ "hbc_sha256": { "98": { "g0": "d1ceacc1f40097b798abf4eeaf8f2f0a663afa9ed8d8fdd5f2b2d99ee2e422a8", - "g1": "607bacb57bde59047aacfc9831c2d4a0d2a39812b77e4e99c7b1d2f296c423ad" + "g1": "d5f33936891fdc73684e9440c6898ba9a346813b4d95d3a89a484df3b1aae668" }, "99": { "g0": "f51e55203c85ab6fd016ab83862f81aa61cc2f441087c10ef712c2148bf7b57d", - "g1": "1435f40bec256fc1c62fd79135400157449ed18ef804cedd1f2437c04916174e" + "g1": "1aee0a677f150b400ad20900e3782a084c2e2177ef68a6bb8360e735d65629c3" } }, "original_output": "even:negative:25", "pseudocode_output": "even:negative:21" + }, + "memprocfs": { + "image_sha256": "8e785901820f4614a5c74d2c9b156ec561e6c77aab19e78f755421f0b42f2d3d", + "dtb": "0x10000", + "virtual_address": "0x140001678", + "physical_address": "0x345678" } } diff --git a/examples/resource-intake/verify.py b/examples/resource-intake/verify.py index de4fada..8faf55b 100644 --- a/examples/resource-intake/verify.py +++ b/examples/resource-intake/verify.py @@ -1,10 +1,12 @@ -"""Reproduce six narrow resource examples with independent expected outputs.""" +"""Reproduce seven narrow resource examples with independent expected outputs.""" import argparse +import ctypes.util from datetime import datetime, timezone import hashlib from importlib.metadata import PackageNotFoundError, version import io import json +import os from pathlib import Path import platform import re @@ -34,6 +36,9 @@ HBC_PSEUDOCODE_OUTPUT = "even:negative:21" 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} +MEMPROCFS_PACKAGES = {"memprocfs": "5.19.0", "leechcorepyc": "2.23.3"} +PML4, PDPT, PD, PT, PAGE = 0x10000, 0x11000, 0x12000, 0x13000, 0x345000 +FIXTURE_VA = 0x140001678 def sha256(path): return hashlib.sha256(path.read_bytes()).hexdigest() @@ -49,8 +54,8 @@ def checksum(data): return (~total) & 0xFFFF -def run(*args): - completed = subprocess.run(args, text=True, capture_output=True, check=True) +def run(*args, env=None): + completed = subprocess.run(args, text=True, capture_output=True, check=True, env=env) return completed.stdout.strip() @@ -157,8 +162,44 @@ def verify_malduck(work): assert results["wrong-key"] == (None, []) and results["no-marker"] == (None, []) return sha256(work / "duckcfg-good.bin") +def memprocfs_host(): + # The pinned wheels are Linux x86-64 and Windows x64; only Linux x86-64 is exercised here. + return platform.system() == "Linux" and platform.machine() == "x86_64" + + +def memprocfs_image(path): + image = bytearray(16 * 1024 * 1024) + indexes = [(FIXTURE_VA >> shift) & 0x1FF for shift in (39, 30, 21, 12)] + for table, entry, index in zip((PML4, PDPT, PD, PT), (PDPT, PD, PT, PAGE), indexes): + image[table + index * 8:table + index * 8 + 8] = struct.pack("