[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7EBJ8RM3FM4YQ9P3PFZRA7A":3,"skill-same:01M7EBJ8RM3FM4YQ9P3PFZRA7A":72},{"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":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":47,"repositoryHtmlUrl":48,"repositoryHomepageUrl":6,"ownerHtmlUrl":49,"ownerBlogUrl":6,"ownerDescription":50,"updatedAt":51,"install":52,"resources":65},"01M7EBJ8RM3FM4YQ9P3PFZRA7A","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.","lza6\u002FArmor-piercing-system-prompts","lza6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F128880206?v=4","01M7EB3K7WPX5T28EJ2NVHE6EG","Chinese-tingfeng","01M7EB3K97E1KQ16QWKJMFNGX8",11,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F03-逆向工程\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",[],[],"2026-11-15 14:19:17",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":24,"author":30,"domain":31,"license":15,"version":32,"nist_csf":33,"subdomain":38,"description":39,"mitre_attack":40},[25,26,27,28,29],"malware","unpacking","UPX","packing","static-analysis","mahipal","cybersecurity","1.0.0",[34,35,36,37],"DE.AE-02","RS.AN-03","ID.RA-01","DE.CM-01","malware-analysis","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",[41,42,43],"T1027.002","T1140","T1620","main","d69096e239f2a89aabc2cd078c47664a9d3b1e11","03-逆向工程\u002Fanalyzing-packed-malware-with-upx-unpacker",3,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts","https:\u002F\u002Fgithub.com\u002Flza6","个人vx：Tf00798\r\n个人✈：@TFGY999","2026-10-08 14:29:22",{"source":8,"skillName":5,"commands":53,"prompt":63,"zipAvailable":64},[54,57,60],{"tool":55,"command":56},"npx","npx skills add lza6\u002FArmor-piercing-system-prompts --skill analyzing-packed-malware-with-upx-unpacker",{"tool":58,"command":59},"bunx","bunx skills add lza6\u002FArmor-piercing-system-prompts --skill analyzing-packed-malware-with-upx-unpacker",{"tool":61,"command":62},"pnpm","pnpm dlx skills add lza6\u002FArmor-piercing-system-prompts --skill analyzing-packed-malware-with-upx-unpacker","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F03-逆向工程\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",true,[66],{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"references\u002Fapi-reference.md","REFERENCE","参考文档",3143,"https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F03-逆向工程\u002Fanalyzing-packed-malware-with-upx-unpacker\u002Freferences\u002Fapi-reference.md",[73,82,87,94,101,108],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":81},"01M7FFG485KY83TD6HSC4YPCMC","obsidian-clipper-template-creator","Guide for creating templates for the Obsidian Web Clipper. Use when you want to create a new clipping template, understand available variables, or format clipped content.","MIT","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator\u002FSKILL.md",[],[],"2026-11-16 10:05:34",{"skillNo":83,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":81},"01M7FFG0T6AZ0STEJPSB3CX84K","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobsidian-clipper-template-creator-antigravity-awesome-skills-main\u002FSKILL.md",[],[],{"skillNo":88,"name":89,"nameZh":6,"description":90,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":81},"01M7FFFY0QEM14SKWPDYGMXM2P","python-api","Programmatic Object-Detection-Metrics API guidance for BoundingBox, BoundingBoxes, Evaluator, enums, coordinate conversion, AP\u002FmAP semantics, and source-style import diagnostics.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Fpython-api\u002FSKILL.md",[],[],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":81},"01M7FFFVZQZ2GJ0C0TGP7JHD20","file-evaluation","Folder-based PASCAL VOC AP\u002FmAP evaluation from ground-truth and detection text files.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002Fsub-skills\u002Ffile-evaluation\u002FSKILL.md",[],[],{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":81},"01M7FFFSFNYSE77SJ6PE1CK2DA","object-detection-metrics","Guides legacy Object-Detection-Metrics PASCAL VOC AP\u002FmAP evaluation from detection text folders and direct Python API classes.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fobject-detection-metrics\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":81},"01M7FFFP0GCK1RVXBCPQ8APBMT","nx-workspace-patterns","Configure and optimize Nx monorepo workspaces. Use when setting up Nx, configuring project boundaries, optimizing build caching, or implementing affected commands.","https:\u002F\u002Fgithub.com\u002Flza6\u002FArmor-piercing-system-prompts\u002Fblob\u002Fmain\u002F07-后端与架构\u002Fnx-workspace-patterns\u002FSKILL.md",[],[]]