[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6ADRE06RZQVHA9C25B5KJM7":3,"skill-same:01M6ADRE06RZQVHA9C25B5KJM7":95},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":23,"publishedAt":36,"linkOnly":37,"markdownContent":38,"markdownBody":39,"frontMatter":40,"refName":54,"commitSha":55,"skillDirectory":56,"forksCount":57,"repositoryHtmlUrl":58,"repositoryHomepageUrl":59,"ownerHtmlUrl":60,"ownerBlogUrl":61,"ownerDescription":62,"updatedAt":63,"install":64,"resources":77},"01M6ADRE06RZQVHA9C25B5KJM7","analyzing-packed-malware-with-upx-unpacker",null,"Identifies and unpacks UPX-packed malware samples, including binaries with modified UPX magic bytes or headers that block automated decompression, to recover the original executable for static analysis. Use when a sample shows high entropy, minimal imports, or only LoadLibrary\u002FGetProcAddress in its import table, or when preparing a packed binary for disassembly in Ghidra or IDA.","mukul975\u002FAnthropic-Cybersecurity-Skills","mukul975","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F42860185?v=4","01M6ADEQR8T5M4EEG6C67BQCWF","Mahipal","01M6ADJPMYWG1E5GM1FWBE3128",36078,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",[18],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发","SCENARIO","使用场景",[24,25,26,27,28,29,30,31,32,33,34,35],"malware","analyzing","analyzing packed malware with upx unpacker","static analysis","cybersecurity","static-analysis","malware-analysis","ghidra","disassembly","unpacking","UPX","packing","2026-11-10 10:12:30",false,"---\nname: analyzing-packed-malware-with-upx-unpacker\ndescription: 'Identifies and unpacks UPX-packed malware samples, including binaries with modified UPX magic bytes or headers that block automated decompression, to recover the original executable for static analysis. Use when a sample shows high entropy, minimal imports, or only LoadLibrary\u002FGetProcAddress in its import table, or when preparing a packed binary for disassembly in Ghidra or IDA.\n\n  '\ndomain: cybersecurity\nsubdomain: malware-analysis\ntags:\n- malware\n- unpacking\n- UPX\n- packing\n- static-analysis\nversion: 1.0.0\nauthor: mahipal\nlicense: Apache-2.0\nnist_csf:\n- DE.AE-02\n- RS.AN-03\n- ID.RA-01\n- DE.CM-01\nmitre_attack:\n- T1027.002\n- T1140\n- T1620\n---\n\n# Analyzing Packed Malware with UPX Unpacker\n\n## When to Use\n\n- Static analysis reveals high entropy sections and minimal imports indicating the binary is packed\n- PEiD, Detect It Easy, or PEStudio identifies UPX or another known packer\n- The import table contains only LoadLibrary and GetProcAddress (runtime import resolution typical of packed binaries)\n- You need to recover the original binary for proper disassembly and decompilation in Ghidra or IDA\n- Automated UPX decompression fails because the malware author modified UPX magic bytes or headers\n\n**Do not use** when dealing with custom packers, VM-based protectors (Themida, VMProtect), or samples where dynamic unpacking via debugging is more appropriate.\n\n## Prerequisites\n\n- UPX (Ultimate Packer for eXecutables) installed (`apt install upx-ucl` or download from https:\u002F\u002Fupx.github.io\u002F)\n- Detect It Easy (DIE) for packer identification\n- Python 3.8+ with `pefile` library for manual header repair\n- x64dbg or x32dbg for manual unpacking when automated tools fail\n- PE-bear or CFF Explorer for PE header inspection and repair\n- Isolated analysis VM without network connectivity\n\n## Workflow\n\n### Step 1: Identify the Packer\n\nDetermine if the sample is packed and identify the packer:\n\n```bash\n# Check with Detect It Easy\ndiec suspect.exe\n\n# Check with UPX (test without unpacking)\nupx -t suspect.exe\n\n# Python-based entropy and packer detection\npython3 \u003C\u003C 'PYEOF'\nimport pefile\nimport math\n\npe = pefile.PE(\"suspect.exe\")\n\nprint(\"Section Analysis:\")\nfor section in pe.sections:\n    name = section.Name.decode().rstrip('\\x00')\n    entropy = section.get_entropy()\n    raw = section.SizeOfRawData\n    virtual = section.Misc_VirtualSize\n    print(f\"  {name:8s} Entropy: {entropy:.2f}  Raw: {raw:>8}  Virtual: {virtual:>8}\")\n\n# Check for UPX section names\nsection_names = [s.Name.decode().rstrip('\\x00') for s in pe.sections]\nif 'UPX0' in section_names or 'UPX1' in section_names:\n    print(\"\\n[!] UPX section names detected\")\nelif '.upx' in [s.lower() for s in section_names]:\n    print(\"\\n[!] UPX variant section names detected\")\n\n# Check import count (packed binaries have very few)\nif hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n    total_imports = sum(len(e.imports) for e in pe.DIRECTORY_ENTRY_IMPORT)\n    print(f\"\\nTotal imports: {total_imports}\")\n    if total_imports \u003C 10:\n        print(\"[!] Very few imports - likely packed\")\nelse:\n    print(\"\\n[!] No import directory - heavily packed\")\nPYEOF\n```\n\n### Step 2: Attempt Standard UPX Decompression\n\nTry the built-in UPX decompression:\n\n```bash\n# Standard UPX decompress\nupx -d suspect.exe -o unpacked.exe\n\n# If UPX fails with \"not packed by UPX\" error, the headers may be modified\n# Verbose output for debugging\nupx -d suspect.exe -o unpacked.exe -v 2>&1\n\n# Verify the unpacked file\nfile unpacked.exe\ndiec unpacked.exe\n```\n\n### Step 3: Repair Modified UPX Headers\n\nIf standard decompression fails, repair tampered magic bytes:\n\n```python\n# Repair modified UPX headers\nimport struct\n\nwith open(\"suspect.exe\", \"rb\") as f:\n    data = bytearray(f.read())\n\n# UPX magic bytes: \"UPX!\" (0x55505821)\n# Malware authors commonly modify these to prevent automatic unpacking\n\n# Search for modified UPX signatures\nupx_magic = b\"UPX!\"\nmodified_patterns = [b\"UPX0\", b\"UPX\\x00\", b\"\\x00PX!\", b\"UPx!\"]\n\n# Find and restore section names\npe_offset = struct.unpack_from(\"\u003CI\", data, 0x3C)[0]\nnum_sections = struct.unpack_from(\"\u003CH\", data, pe_offset + 6)[0]\nsection_table_offset = pe_offset + 0x18 + struct.unpack_from(\"\u003CH\", data, pe_offset + 0x14)[0]\n\nprint(f\"PE offset: 0x{pe_offset:X}\")\nprint(f\"Number of sections: {num_sections}\")\nprint(f\"Section table offset: 0x{section_table_offset:X}\")\n\nfor i in range(num_sections):\n    offset = section_table_offset + (i * 40)\n    name = data[offset:offset+8]\n    print(f\"Section {i}: {name}\")\n\n# Restore UPX magic bytes in the binary\n# Search for the UPX header signature location (typically near the end of packed data)\nfor i in range(len(data) - 4):\n    if data[i:i+3] == b\"UPX\" and data[i+3] != ord(\"!\"):\n        print(f\"Found modified UPX magic at offset 0x{i:X}: {data[i:i+4]}\")\n        data[i:i+4] = b\"UPX!\"\n        print(f\"Restored to: UPX!\")\n\n# Also restore section names if modified\nfor i in range(num_sections):\n    offset = section_table_offset + (i * 40)\n    name = data[offset:offset+8].rstrip(b'\\x00')\n    if name in [b\"UPX0\", b\"UPX1\", b\"UPX2\"]:\n        continue  # Already correct\n    # Check for common modifications\n    if name.startswith(b\"UP\") or name.startswith(b\"ux\"):\n        original = f\"UPX{i}\".encode().ljust(8, b'\\x00')\n        data[offset:offset+8] = original\n        print(f\"Restored section name at 0x{offset:X} to {original}\")\n\nwith open(\"suspect_fixed.exe\", \"wb\") as f:\n    f.write(data)\n\nprint(\"\\nFixed file written. Retry: upx -d suspect_fixed.exe -o unpacked.exe\")\n```\n\n### Step 4: Manual Unpacking with Debugger\n\nWhen automated unpacking fails entirely, use dynamic unpacking:\n\n```\nManual UPX Unpacking with x64dbg:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n1. Load packed sample in x64dbg\n2. Run to the entry point (system breakpoint then F9)\n3. UPX unpacking stub pattern:\n   a. PUSHAD (saves all registers)\n   b. Decompression loop (processes packed sections)\n   c. Resolves imports (LoadLibrary\u002FGetProcAddress calls)\n   d. POPAD (restores registers)\n   e. JMP to OEP (original entry point)\n4. Set hardware breakpoint on ESP after PUSHAD:\n   - After PUSHAD, right-click ESP in registers -> Follow in Dump\n   - Set hardware breakpoint on access at [ESP] address\n   - Run (F9) - breaks at POPAD before JMP to OEP\n5. Step forward (F7\u002FF8) until you reach the JMP to OEP\n6. At OEP: Use Scylla plugin to dump and fix imports:\n   - Plugins -> Scylla -> OEP = current EIP\n   - Click \"IAT Autosearch\" -> \"Get Imports\"\n   - Click \"Dump\" to save unpacked binary\n   - Click \"Fix Dump\" to repair import table\n```\n\n### Step 5: Validate Unpacked Binary\n\nVerify the unpacked sample is valid and complete:\n\n```bash\n# Verify unpacked PE is valid\npython3 \u003C\u003C 'PYEOF'\nimport pefile\n\npe = pefile.PE(\"unpacked.exe\")\n\n# Check sections are normal\nprint(\"Unpacked Section Analysis:\")\nfor section in pe.sections:\n    name = section.Name.decode().rstrip('\\x00')\n    entropy = section.get_entropy()\n    print(f\"  {name:8s} Entropy: {entropy:.2f}\")\n\n# Verify imports are resolved\nprint(f\"\\nImport count:\")\nif hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n    for entry in pe.DIRECTORY_ENTRY_IMPORT:\n        dll = entry.dll.decode()\n        count = len(entry.imports)\n        print(f\"  {dll}: {count} functions\")\n    total = sum(len(e.imports) for e in pe.DIRECTORY_ENTRY_IMPORT)\n    print(f\"  Total: {total} imports\")\n\n# Compare file sizes\nimport os\npacked_size = os.path.getsize(\"suspect.exe\")\nunpacked_size = os.path.getsize(\"unpacked.exe\")\nprint(f\"\\nPacked:   {packed_size:>10} bytes\")\nprint(f\"Unpacked: {unpacked_size:>10} bytes\")\nprint(f\"Ratio:    {unpacked_size\u002Fpacked_size:.1f}x\")\nPYEOF\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| **Packing** | Compressing or encrypting executable code to reduce file size and hinder static analysis; the binary contains an unpacking stub that restores code at runtime |\n| **UPX** | Ultimate Packer for eXecutables; open-source executable packer commonly abused by malware authors because it is free and effective |\n| **Original Entry Point (OEP)** | The real starting address of the malware code before packing; the unpacking stub decompresses code then jumps to the OEP |\n| **Import Reconstruction** | Process of rebuilding the import address table after dumping an unpacked process from memory using tools like Scylla or ImpRec |\n| **PUSHAD\u002FPOPAD** | x86 instructions that save\u002Frestore all general-purpose registers; UPX uses this pattern to preserve register state during unpacking |\n| **Section Entropy** | Randomness measure of PE section data; packed sections show entropy > 7.0 while normal code sections average 5.0-6.5 |\n| **Magic Bytes** | Signature bytes within a file identifying its format; UPX uses \"UPX!\" which malware authors modify to prevent automated decompression |\n\n## Tools & Systems\n\n- **UPX**: Open-source executable packer with built-in decompression capability for properly packed files\n- **Detect It Easy (DIE)**: Packer, compiler, and linker detection tool that identifies protection on PE, ELF, and Mach-O files\n- **x64dbg\u002Fx32dbg**: Open-source Windows debugger used for manual unpacking through dynamic execution and breakpoint-based OEP finding\n- **Scylla**: Import reconstruction tool integrated with x64dbg for rebuilding IAT after memory dumping\n- **PE-bear**: PE file viewer and editor for inspecting and repairing PE headers after unpacking\n\n## Common Scenarios\n\n### Scenario: Unpacking Malware with Modified UPX Headers\n\n**Context**: A malware sample is identified as UPX-packed by section names (UPX0, UPX1) but `upx -d` fails with \"CantUnpackException: header corrupted\". The malware author modified the UPX magic bytes to prevent automated decompression.\n\n**Approach**:\n1. Open the binary in a hex editor and search for the UPX header area (typically at the end of packed data)\n2. Identify the modified magic bytes (e.g., \"UPX!\" changed to \"UPX\\x00\" or completely zeroed)\n3. Use the Python repair script to restore \"UPX!\" magic and correct section names\n4. Retry `upx -d` on the repaired binary\n5. If repair fails, fall back to manual unpacking with x64dbg (PUSHAD -> hardware BP on ESP -> POPAD -> JMP OEP)\n6. Validate the unpacked binary has proper imports and reasonable entropy values\n7. Import into Ghidra or IDA for full static analysis\n\n**Pitfalls**:\n- Assuming UPX is the only packer; the binary may be double-packed (UPX + custom layer)\n- Modifying the original packed sample instead of working on a copy\n- Not reconstructing imports after manual memory dump (the dumped binary will crash without IAT fix)\n- Forgetting to check for overlay data appended after the UPX-packed PE sections\n\n## Output Format\n\n```\nUNPACKING ANALYSIS REPORT\n===========================\nSample:           suspect.exe\nSHA-256:          e3b0c44298fc1c149afbf4c8996fb924...\nPacker:           UPX 3.96 (modified headers)\n\nPACKED BINARY\nSections:         UPX0 (entropy: 0.00) UPX1 (entropy: 7.89) .rsrc (entropy: 3.45)\nImports:          2 (kernel32.dll: LoadLibraryA, GetProcAddress)\nFile Size:        98,304 bytes\n\nUNPACKING METHOD\nMethod:           Header repair + UPX -d\nHeader Fix:       Restored UPX! magic at offset 0x1F000\nCommand:          upx -d suspect_fixed.exe -o unpacked.exe\nResult:           SUCCESS\n\nUNPACKED BINARY\nSections:         .text (entropy: 6.21) .rdata (entropy: 4.56) .data (entropy: 3.12) .rsrc (entropy: 3.45)\nImports:          147 (kernel32, user32, advapi32, wininet, ws2_32)\nFile Size:        245,760 bytes (2.5x expansion)\nOEP:              0x00401000\n\nVALIDATION\nPE Valid:         Yes\nImports Resolved: Yes (147 functions across 8 DLLs)\nExecutable:       Yes (runs without crash in sandbox)\n\nNEXT STEPS\n- Import unpacked.exe into Ghidra for full disassembly\n- Run YARA rules against unpacked binary\n- Submit unpacked binary to VirusTotal for improved detection\n```\n","# Analyzing Packed Malware with UPX Unpacker\n\n## When to Use\n\n- Static analysis reveals high entropy sections and minimal imports indicating the binary is packed\n- PEiD, Detect It Easy, or PEStudio identifies UPX or another known packer\n- The import table contains only LoadLibrary and GetProcAddress (runtime import resolution typical of packed binaries)\n- You need to recover the original binary for proper disassembly and decompilation in Ghidra or IDA\n- Automated UPX decompression fails because the malware author modified UPX magic bytes or headers\n\n**Do not use** when dealing with custom packers, VM-based protectors (Themida, VMProtect), or samples where dynamic unpacking via debugging is more appropriate.\n\n## Prerequisites\n\n- UPX (Ultimate Packer for eXecutables) installed (`apt install upx-ucl` or download from https:\u002F\u002Fupx.github.io\u002F)\n- Detect It Easy (DIE) for packer identification\n- Python 3.8+ with `pefile` library for manual header repair\n- x64dbg or x32dbg for manual unpacking when automated tools fail\n- PE-bear or CFF Explorer for PE header inspection and repair\n- Isolated analysis VM without network connectivity\n\n## Workflow\n\n### Step 1: Identify the Packer\n\nDetermine if the sample is packed and identify the packer:\n\n```bash\n# Check with Detect It Easy\ndiec suspect.exe\n\n# Check with UPX (test without unpacking)\nupx -t suspect.exe\n\n# Python-based entropy and packer detection\npython3 \u003C\u003C 'PYEOF'\nimport pefile\nimport math\n\npe = pefile.PE(\"suspect.exe\")\n\nprint(\"Section Analysis:\")\nfor section in pe.sections:\n    name = section.Name.decode().rstrip('\\x00')\n    entropy = section.get_entropy()\n    raw = section.SizeOfRawData\n    virtual = section.Misc_VirtualSize\n    print(f\"  {name:8s} Entropy: {entropy:.2f}  Raw: {raw:>8}  Virtual: {virtual:>8}\")\n\n# Check for UPX section names\nsection_names = [s.Name.decode().rstrip('\\x00') for s in pe.sections]\nif 'UPX0' in section_names or 'UPX1' in section_names:\n    print(\"\\n[!] UPX section names detected\")\nelif '.upx' in [s.lower() for s in section_names]:\n    print(\"\\n[!] UPX variant section names detected\")\n\n# Check import count (packed binaries have very few)\nif hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n    total_imports = sum(len(e.imports) for e in pe.DIRECTORY_ENTRY_IMPORT)\n    print(f\"\\nTotal imports: {total_imports}\")\n    if total_imports \u003C 10:\n        print(\"[!] Very few imports - likely packed\")\nelse:\n    print(\"\\n[!] No import directory - heavily packed\")\nPYEOF\n```\n\n### Step 2: Attempt Standard UPX Decompression\n\nTry the built-in UPX decompression:\n\n```bash\n# Standard UPX decompress\nupx -d suspect.exe -o unpacked.exe\n\n# If UPX fails with \"not packed by UPX\" error, the headers may be modified\n# Verbose output for debugging\nupx -d suspect.exe -o unpacked.exe -v 2>&1\n\n# Verify the unpacked file\nfile unpacked.exe\ndiec unpacked.exe\n```\n\n### Step 3: Repair Modified UPX Headers\n\nIf standard decompression fails, repair tampered magic bytes:\n\n```python\n# Repair modified UPX headers\nimport struct\n\nwith open(\"suspect.exe\", \"rb\") as f:\n    data = bytearray(f.read())\n\n# UPX magic bytes: \"UPX!\" (0x55505821)\n# Malware authors commonly modify these to prevent automatic unpacking\n\n# Search for modified UPX signatures\nupx_magic = b\"UPX!\"\nmodified_patterns = [b\"UPX0\", b\"UPX\\x00\", b\"\\x00PX!\", b\"UPx!\"]\n\n# Find and restore section names\npe_offset = struct.unpack_from(\"\u003CI\", data, 0x3C)[0]\nnum_sections = struct.unpack_from(\"\u003CH\", data, pe_offset + 6)[0]\nsection_table_offset = pe_offset + 0x18 + struct.unpack_from(\"\u003CH\", data, pe_offset + 0x14)[0]\n\nprint(f\"PE offset: 0x{pe_offset:X}\")\nprint(f\"Number of sections: {num_sections}\")\nprint(f\"Section table offset: 0x{section_table_offset:X}\")\n\nfor i in range(num_sections):\n    offset = section_table_offset + (i * 40)\n    name = data[offset:offset+8]\n    print(f\"Section {i}: {name}\")\n\n# Restore UPX magic bytes in the binary\n# Search for the UPX header signature location (typically near the end of packed data)\nfor i in range(len(data) - 4):\n    if data[i:i+3] == b\"UPX\" and data[i+3] != ord(\"!\"):\n        print(f\"Found modified UPX magic at offset 0x{i:X}: {data[i:i+4]}\")\n        data[i:i+4] = b\"UPX!\"\n        print(f\"Restored to: UPX!\")\n\n# Also restore section names if modified\nfor i in range(num_sections):\n    offset = section_table_offset + (i * 40)\n    name = data[offset:offset+8].rstrip(b'\\x00')\n    if name in [b\"UPX0\", b\"UPX1\", b\"UPX2\"]:\n        continue  # Already correct\n    # Check for common modifications\n    if name.startswith(b\"UP\") or name.startswith(b\"ux\"):\n        original = f\"UPX{i}\".encode().ljust(8, b'\\x00')\n        data[offset:offset+8] = original\n        print(f\"Restored section name at 0x{offset:X} to {original}\")\n\nwith open(\"suspect_fixed.exe\", \"wb\") as f:\n    f.write(data)\n\nprint(\"\\nFixed file written. Retry: upx -d suspect_fixed.exe -o unpacked.exe\")\n```\n\n### Step 4: Manual Unpacking with Debugger\n\nWhen automated unpacking fails entirely, use dynamic unpacking:\n\n```\nManual UPX Unpacking with x64dbg:\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n1. Load packed sample in x64dbg\n2. Run to the entry point (system breakpoint then F9)\n3. UPX unpacking stub pattern:\n   a. PUSHAD (saves all registers)\n   b. Decompression loop (processes packed sections)\n   c. Resolves imports (LoadLibrary\u002FGetProcAddress calls)\n   d. POPAD (restores registers)\n   e. JMP to OEP (original entry point)\n4. Set hardware breakpoint on ESP after PUSHAD:\n   - After PUSHAD, right-click ESP in registers -> Follow in Dump\n   - Set hardware breakpoint on access at [ESP] address\n   - Run (F9) - breaks at POPAD before JMP to OEP\n5. Step forward (F7\u002FF8) until you reach the JMP to OEP\n6. At OEP: Use Scylla plugin to dump and fix imports:\n   - Plugins -> Scylla -> OEP = current EIP\n   - Click \"IAT Autosearch\" -> \"Get Imports\"\n   - Click \"Dump\" to save unpacked binary\n   - Click \"Fix Dump\" to repair import table\n```\n\n### Step 5: Validate Unpacked Binary\n\nVerify the unpacked sample is valid and complete:\n\n```bash\n# Verify unpacked PE is valid\npython3 \u003C\u003C 'PYEOF'\nimport pefile\n\npe = pefile.PE(\"unpacked.exe\")\n\n# Check sections are normal\nprint(\"Unpacked Section Analysis:\")\nfor section in pe.sections:\n    name = section.Name.decode().rstrip('\\x00')\n    entropy = section.get_entropy()\n    print(f\"  {name:8s} Entropy: {entropy:.2f}\")\n\n# Verify imports are resolved\nprint(f\"\\nImport count:\")\nif hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):\n    for entry in pe.DIRECTORY_ENTRY_IMPORT:\n        dll = entry.dll.decode()\n        count = len(entry.imports)\n        print(f\"  {dll}: {count} functions\")\n    total = sum(len(e.imports) for e in pe.DIRECTORY_ENTRY_IMPORT)\n    print(f\"  Total: {total} imports\")\n\n# Compare file sizes\nimport os\npacked_size = os.path.getsize(\"suspect.exe\")\nunpacked_size = os.path.getsize(\"unpacked.exe\")\nprint(f\"\\nPacked:   {packed_size:>10} bytes\")\nprint(f\"Unpacked: {unpacked_size:>10} bytes\")\nprint(f\"Ratio:    {unpacked_size\u002Fpacked_size:.1f}x\")\nPYEOF\n```\n\n## Key Concepts\n\n| Term | Definition |\n|------|------------|\n| **Packing** | Compressing or encrypting executable code to reduce file size and hinder static analysis; the binary contains an unpacking stub that restores code at runtime |\n| **UPX** | Ultimate Packer for eXecutables; open-source executable packer commonly abused by malware authors because it is free and effective |\n| **Original Entry Point (OEP)** | The real starting address of the malware code before packing; the unpacking stub decompresses code then jumps to the OEP |\n| **Import Reconstruction** | Process of rebuilding the import address table after dumping an unpacked process from memory using tools like Scylla or ImpRec |\n| **PUSHAD\u002FPOPAD** | x86 instructions that save\u002Frestore all general-purpose registers; UPX uses this pattern to preserve register state during unpacking |\n| **Section Entropy** | Randomness measure of PE section data; packed sections show entropy > 7.0 while normal code sections average 5.0-6.5 |\n| **Magic Bytes** | Signature bytes within a file identifying its format; UPX uses \"UPX!\" which malware authors modify to prevent automated decompression |\n\n## Tools & Systems\n\n- **UPX**: Open-source executable packer with built-in decompression capability for properly packed files\n- **Detect It Easy (DIE)**: Packer, compiler, and linker detection tool that identifies protection on PE, ELF, and Mach-O files\n- **x64dbg\u002Fx32dbg**: Open-source Windows debugger used for manual unpacking through dynamic execution and breakpoint-based OEP finding\n- **Scylla**: Import reconstruction tool integrated with x64dbg for rebuilding IAT after memory dumping\n- **PE-bear**: PE file viewer and editor for inspecting and repairing PE headers after unpacking\n\n## Common Scenarios\n\n### Scenario: Unpacking Malware with Modified UPX Headers\n\n**Context**: A malware sample is identified as UPX-packed by section names (UPX0, UPX1) but `upx -d` fails with \"CantUnpackException: header corrupted\". The malware author modified the UPX magic bytes to prevent automated decompression.\n\n**Approach**:\n1. Open the binary in a hex editor and search for the UPX header area (typically at the end of packed data)\n2. Identify the modified magic bytes (e.g., \"UPX!\" changed to \"UPX\\x00\" or completely zeroed)\n3. Use the Python repair script to restore \"UPX!\" magic and correct section names\n4. Retry `upx -d` on the repaired binary\n5. If repair fails, fall back to manual unpacking with x64dbg (PUSHAD -> hardware BP on ESP -> POPAD -> JMP OEP)\n6. Validate the unpacked binary has proper imports and reasonable entropy values\n7. Import into Ghidra or IDA for full static analysis\n\n**Pitfalls**:\n- Assuming UPX is the only packer; the binary may be double-packed (UPX + custom layer)\n- Modifying the original packed sample instead of working on a copy\n- Not reconstructing imports after manual memory dump (the dumped binary will crash without IAT fix)\n- Forgetting to check for overlay data appended after the UPX-packed PE sections\n\n## Output Format\n\n```\nUNPACKING ANALYSIS REPORT\n===========================\nSample:           suspect.exe\nSHA-256:          e3b0c44298fc1c149afbf4c8996fb924...\nPacker:           UPX 3.96 (modified headers)\n\nPACKED BINARY\nSections:         UPX0 (entropy: 0.00) UPX1 (entropy: 7.89) .rsrc (entropy: 3.45)\nImports:          2 (kernel32.dll: LoadLibraryA, GetProcAddress)\nFile Size:        98,304 bytes\n\nUNPACKING METHOD\nMethod:           Header repair + UPX -d\nHeader Fix:       Restored UPX! magic at offset 0x1F000\nCommand:          upx -d suspect_fixed.exe -o unpacked.exe\nResult:           SUCCESS\n\nUNPACKED BINARY\nSections:         .text (entropy: 6.21) .rdata (entropy: 4.56) .data (entropy: 3.12) .rsrc (entropy: 3.45)\nImports:          147 (kernel32, user32, advapi32, wininet, ws2_32)\nFile Size:        245,760 bytes (2.5x expansion)\nOEP:              0x00401000\n\nVALIDATION\nPE Valid:         Yes\nImports Resolved: Yes (147 functions across 8 DLLs)\nExecutable:       Yes (runs without crash in sandbox)\n\nNEXT STEPS\n- Import unpacked.exe into Ghidra for full disassembly\n- Run YARA rules against unpacked binary\n- Submit unpacked binary to VirusTotal for improved detection\n```\n",{"name":5,"tags":41,"author":42,"domain":28,"license":15,"version":43,"nist_csf":44,"subdomain":30,"description":49,"mitre_attack":50},[24,33,34,35,29],"mahipal","1.0.0",[45,46,47,48],"DE.AE-02","RS.AN-03","ID.RA-01","DE.CM-01","Identifies and unpacks UPX-packed malware samples, including binaries with modified UPX magic bytes or headers that block automated decompression, to recover the original executable for static analysis. Use when a sample shows high entropy, minimal imports, or only LoadLibrary\u002FGetProcAddress in its import table, or when preparing a packed binary for disassembly in Ghidra or IDA.\n",[51,52,53],"T1027.002","T1140","T1620","main","54a798831d2266a3ca61ce68a7acb80b81160d57","skills\u002Fanalyzing-packed-malware-with-upx-unpacker",4414,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills","https:\u002F\u002Fmahipal.engineer\u002FAnthropic-Cybersecurity-Skills\u002F","https:\u002F\u002Fgithub.com\u002Fmukul975","Mahipal.engineer","🔐 Cybersecurity | 💻 Dev | 📷 Street Photographer\r\n🎓 MSc | 📚 Research & AI Security","2026-08-31 12:32:44",{"source":8,"skillName":5,"commands":65,"prompt":75,"zipAvailable":76},[66,69,72],{"tool":67,"command":68},"npx","npx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill analyzing-packed-malware-with-upx-unpacker",{"tool":70,"command":71},"bunx","bunx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill analyzing-packed-malware-with-upx-unpacker",{"tool":73,"command":74},"pnpm","pnpm dlx skills add mukul975\u002FAnthropic-Cybersecurity-Skills --skill analyzing-packed-malware-with-upx-unpacker","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",true,[78,83,89],{"path":79,"resourceType":79,"resourceTypeDesc":80,"sizeBytes":81,"sourceHtmlUrl":82},"LICENSE","许可证",11255,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FLICENSE",{"path":84,"resourceType":85,"resourceTypeDesc":86,"sizeBytes":87,"sourceHtmlUrl":88},"references\u002Fapi-reference.md","REFERENCE","参考文档",3143,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fanalyzing-packed-malware-with-upx-unpacker\u002Freferences\u002Fapi-reference.md",{"path":90,"resourceType":91,"resourceTypeDesc":92,"sizeBytes":93,"sourceHtmlUrl":94},"scripts\u002Fagent.py","SCRIPT","脚本",8699,"https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fanalyzing-packed-malware-with-upx-unpacker\u002Fscripts\u002Fagent.py",[96,123,147,175,201,228],{"skillNo":97,"name":98,"nameZh":6,"description":99,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":103,"publishedAt":36},"01M6AGDM3HJXTKXX15ZZ0ZVCJ3","verifying-build-provenance-with-slsa-sigstore","Verifies artifact signatures and SLSA provenance using Sigstore's cosign (verify, verify-attestation, verify-blob-attestation) and slsa-verifier (verify-artifact), enforcing keyless OIDC builder identity and source repo against SLSA Build levels. Use in CI\u002FCD before deploying artifacts, when consuming third-party attestations, establishing a SLSA Build L3 pipeline, or confirming provenance during incident response or admission control.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fverifying-build-provenance-with-slsa-sigstore\u002FSKILL.md",[102],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[104,105,106,107,108,28,109,110,111,112,113,114,115,116,117,118,119,120,121,122],"sigstore","provenance","slsa","verifying build provenance with slsa sigstore","security","incident response","identity","pr","code","artifacts","ci","supply-chain","pipeline","supply-chain-security","t1195","attestation","code-signing","cosign","keyless",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":130,"publishedAt":36},"01M6AGDGBPWYVZ2F11GFKJ4HZ9","validating-tpm-measured-boot-attestation","Verifies TPM 2.0 measured-boot integrity and remote attestation with tpm2-tools -- reading PCRs (tpm2_pcrread), replaying the boot event log, generating and checking signed quotes (tpm2_quote\u002Ftpm2_checkquote), and sealing secrets to a PCR policy. Use to confirm a system booted trusted firmware\u002Fkernel for Zero Trust device posture, detect boot-chain tampering via PCR drift, or build a golden-value baseline for fleet attestation.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fvalidating-tpm-measured-boot-attestation\u002FSKILL.md",[129],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[131,119,132,133,108,134,28,111,135,136,137,138,139,140,141,142,143,144,145,146],"boot","TPM","validating tpm measured boot attestation","policy","verification","ZeRO","firmware","Tools","measured-boot","PCR","integrity","secrets","remote-attestation","tpm2-tools","integrity-verification","trusted-computing",{"skillNo":148,"name":149,"nameZh":6,"description":150,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":151,"categories":152,"keywords":157,"publishedAt":36},"01M6AGDCW0Y4FXZ3362GT1941M","validating-backup-integrity-for-recovery","Validates backup integrity through cryptographic hash verification, automated restore testing, corruption detection, and recoverability checks to confirm backups are reliable for disaster recovery and ransomware response. Use before relying on backups for recovery, when building post-backup validation pipelines, auditing backup infrastructure for compliance, or checking immutable\u002Fair-gapped backups for silent corruption or tampering.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Fvalidating-backup-integrity-for-recovery\u002FSKILL.md",[153,156],{"categoryNo":154,"categoryName":155,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[141,158,159,160,161,28,162,163,135,164,165,166,167,168,169,170,171,172,173,174],"backup","recovery","validating backup integrity for recovery","testing","infrastructure","validation","compliance","hash-verification","incident-response","ransomware","cryptocurrency","detection","t1078","t1490","immutable","disaster-recovery","restore-testing",{"skillNo":176,"name":177,"nameZh":6,"description":178,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":179,"categories":180,"keywords":182,"publishedAt":36},"01M6AGD9GBG2KZ336AE763J3WH","triaging-windows-with-kape","Runs KAPE (Kroll Artifact Parser and Extractor) to collect targeted forensic artifacts (registry hives, $MFT, event logs, prefetch, browser data) via Targets and parse them with Modules wrapping Eric Zimmerman's EZ Tools (PECmd, MFTECmd, RECmd). Use during early incident containment\u002Ftriage when full disk imaging is impractical but a defensible, parseable Windows artifact set is needed quickly, including at-scale remote collection.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-windows-with-kape\u002FSKILL.md",[181],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[183,184,185,28,186,187,188,189,190,191,192,193,194,195,196,197,138,198,199,200],"windows","kape","triaging windows with kape","registry","browser","logs","windows-forensics","dfir","mft","mftecmd","data","prefetch","eric-zimmerman","digital-forensics","SET","collection","pecmd","artifact-collection",{"skillNo":202,"name":203,"nameZh":6,"description":204,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":205,"categories":206,"keywords":208,"publishedAt":36},"01M6AGD5PW5J4EVZM958WD74ZQ","triaging-vulnerabilities-with-ssvc-framework","Triages and prioritizes vulnerabilities with CISA's Stakeholder-Specific Vulnerability Categorization (SSVC) decision tree, weighing exploitation status (via the CISA KEV catalog and FIRST EPSS API), technical impact, automatability, and mission prevalence to output Track\u002FTrack*\u002FAttend\u002FAct decisions. Use when prioritizing vulnerability scan results (OpenVAS, Nessus, Qualys) for remediation planning beyond raw CVSS scores.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-vulnerabilities-with-ssvc-framework\u002FSKILL.md",[207],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[209,210,211,28,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227],"vulnerabilities","framework","triaging vulnerabilities with ssvc framework","status","planning","CISA","vulnerability-management","risk-management","nessus","qualys","openvas","cvss","remediation","risk","vulnerability","api","prioritization","ssvc","decision-tree",{"skillNo":229,"name":230,"nameZh":6,"description":231,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":232,"categories":233,"keywords":235,"publishedAt":36},"01M6AGD24TTQQM4CXG69E3B9TJ","triaging-security-incident","Performs initial triage of security incidents using the NIST SP 800-61r3 and SANS PICERL frameworks, classifying incident type, assigning priority by business impact, and routing to the appropriate response team. Use when a SIEM\u002FEDR alert needs human classification, concurrent alerts must be prioritized, or a user report or threat-intel IOC match requires initial incident categorization.","https:\u002F\u002Fgithub.com\u002Fmukul975\u002FAnthropic-Cybersecurity-Skills\u002Fblob\u002Fmain\u002Fskills\u002Ftriaging-security-incident\u002FSKILL.md",[234],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},[108,236,28,237,238,239,240,241,242,243,244,170,245,171,246,247,248,249,250,251],"triaging security incident","siem","file","ioc","soc","NIST-800-61","NIST","severity","edr","execution","analysis","classification","severity-classification","incident-triage","SANS-PICERL","SOC-operations"]