Skip to content

hypnguyen1209/offensive-claude / skills/malware-analysis

malware-analysis

Unverified

Use when reverse-engineering or detecting malware — static triage + capa/YARA-X, emulation/DBI/.NET unpacking, dynamic/fileless/Volatility 3 memory analysis, C2 config extraction (Cobalt Strike/CAPE), C2 traffic detection (JA4+, beaconing)

scripts/frida_unpack.js

View on GitHub
/*
 * frida_unpack.js - Dynamic unpacking via API hooks (DBI approach).
 *
 * Hooks the memory-write + execute-transition APIs every runtime packer must use,
 * and dumps each RWX/executable region the moment it is filled. Complements the
 * static emulator (auto_unpack.py): use this when emulation fails (VM-protected,
 * API-heavy, or .NET loaders) but you can detonate in an isolated VM.
 *
 * USAGE (isolated, snapshotted analysis VM, no real network):
 *   frida -f C:\sample.exe -l frida_unpack.js --no-pause
 *   # dumps land in the sample's working dir as dump_<addr>_<size>.bin
 *
 * Captures:
 *   - VirtualAlloc / VirtualAllocEx returns (tracks RWX allocations)
 *   - VirtualProtect transitions to PAGE_EXECUTE_* (unpack stub flips perms)
 *   - WriteProcessMemory (self/remote injection target)
 *   - LdrLoadDll  (manual-mapped / reflective DLL loads)
 *   - .NET: System.Reflection.Assembly.Load(byte[])  via CLR (if managed)
 *
 * DEPENDENCIES: frida-tools (pip install frida-tools). Tested on Frida 16/17.
 * OPSEC: this DETONATES the sample. Use a throwaway VM + INetSim/FakeNet, snapshot
 * first, no internet routing.
 */
'use strict';

const PAGE_EXEC = 0x10 | 0x20 | 0x40 | 0x80; // EXECUTE | EXECUTE_READ | EXECUTE_READWRITE | EXECUTE_WRITECOPY
const tracked = {};          // base -> size
const dumped = new Set();

function isPE(ptr) {
    try {
        if (ptr.readU16() !== 0x5A4D) return false;            // 'MZ'
        const lfanew = ptr.add(0x3C).readU32();
        if (lfanew <= 0 || lfanew > 0x1000) return false;
        return ptr.add(lfanew).readU32() === 0x00004550;        // 'PE\0\0'
    } catch (e) { return false; }
}

function dumpRegion(base, size, tag) {
    const key = base.toString();
    if (dumped.has(key)) return;
    try {
        const rng = Process.findRangeByAddress(base);
        const len = size && size > 0 ? size : (rng ? rng.size : 0x10000);
        const fname = 'dump_' + tag + '_' + base + '_' + len + '.bin';
        const f = new File(fname, 'wb');
        f.write(base.readByteArray(len));
        f.close();
        dumped.add(key);
        console.log('[+] dumped ' + tag + ' region ' + base + ' (' + len + ' bytes) -> ' + fname);
    } catch (e) {
        console.log('[-] dump failed @ ' + base + ': ' + e);
    }
}

function hook(modExport, name, onLeave) {
    const addr = Module.findExportByName(null, name);
    if (!addr) { return; }
    Interceptor.attach(addr, onLeave);
    console.log('[*] hooked ' + name);
}

// VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect)
hook(null, 'VirtualAlloc', {
    onEnter(args) { this.size = args[1].toInt32(); this.prot = args[3].toInt32(); },
    onLeave(ret) {
        if (!ret.isNull() && (this.prot & PAGE_EXEC)) {
            tracked[ret.toString()] = this.size;
            console.log('[*] VirtualAlloc RWX ' + ret + ' size=' + this.size);
        }
    }
});

// VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect)
hook(null, 'VirtualProtect', {
    onEnter(args) { this.addr = args[0]; this.size = args[1].toInt32(); this.prot = args[2].toInt32(); },
    onLeave(ret) {
        if (this.prot & PAGE_EXEC) {
            // perms flipped to executable -> unpack stub just finished writing code
            const tag = isPE(this.addr) ? 'pe' : 'code';
            dumpRegion(this.addr, this.size, tag);
        }
    }
});

// WriteProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, *written)
hook(null, 'WriteProcessMemory', {
    onEnter(args) {
        this.dst = args[1]; this.src = args[2]; this.n = args[3].toInt32();
        if (this.n > 256) {
            const tag = isPE(this.src) ? 'wpm_pe' : 'wpm';
            dumpRegion(this.src, this.n, tag);   // dump the buffer we were about to inject
        }
    }
});

// LdrLoadDll - catches reflective / manual map fallbacks routed through loader
hook(null, 'LdrLoadDll', {
    onLeave() { /* presence logging only; range enumerated on demand below */ }
});

// On each new executable module load, check for in-memory-only PEs
const intervalId = setInterval(function () {
    for (const base in tracked) {
        const p = ptr(base);
        if (isPE(p)) dumpRegion(p, tracked[base], 'rwx_pe');
    }
}, 2000);

// .NET Assembly.Load(byte[]) hook (only if CLR loaded). Lazy attach.
setTimeout(function () {
    const clr = Process.findModuleByName('clr.dll') || Process.findModuleByName('coreclr.dll');
    if (clr) {
        console.log('[*] managed process detected (' + clr.name + ') - attach dnSpyEx / ExtremeDumper for the Assembly.Load buffer');
    }
}, 1500);

console.log('[*] frida_unpack armed - waiting for unpack/inject transitions');
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall