[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74N36VBJ644EPNRP7Z76EG7":3,"skill-same:01M74N36VBJ644EPNRP7Z76EG7":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":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":36,"commitSha":37,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M74N36VBJ644EPNRP7Z76EG7","analyzing-packed-malware-with-upx-unpacker",null,"Identifies and unpacks UPX-packed and other packed malware samples to expose the original executable code for static analysis. Covers both standard UPX unpacking and handling modified UPX headers that prevent automated decompression. Activates for requests involving malware unpacking, UPX decompression, packer removal, or preparing packed samples for analysis.","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: analyzing-packed-malware-with-upx-unpacker\ndescription: >\n  Identifies and unpacks UPX-packed and other packed malware samples to expose the original\n  executable code for static analysis. Covers both standard UPX unpacking and handling\n  modified UPX headers that prevent automated decompression. Activates for requests involving\n  malware unpacking, UPX decompression, packer removal, or preparing packed samples for analysis.\ndomain: cybersecurity\nsubdomain: malware-analysis\ntags: [malware, unpacking, UPX, packing, static-analysis]\nversion: 1.0.0\nauthor: mahipal\nlicense: Apache-2.0\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":25,"author":31,"domain":32,"license":15,"version":33,"subdomain":34,"description":35},[26,27,28,29,30],"malware","unpacking","UPX","packing","static-analysis","mahipal","cybersecurity","1.0.0","malware-analysis","Identifies and unpacks UPX-packed and other packed malware samples to expose the original executable code for static analysis. Covers both standard UPX unpacking and handling modified UPX headers that prevent automated decompression. Activates for requests involving malware unpacking, UPX decompression, packer removal, or preparing packed samples for analysis.\n","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill analyzing-packed-malware-with-upx-unpacker",{"tool":48,"command":49},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill analyzing-packed-malware-with-upx-unpacker",{"tool":51,"command":52},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill analyzing-packed-malware-with-upx-unpacker","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fanalyzing-packed-malware-with-upx-unpacker\u002FSKILL.md",true,[56,60,66],{"path":57,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":61,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":64,"sourceHtmlUrl":65},"references\u002Fapi-reference.md","REFERENCE","参考文档",3143,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fanalyzing-packed-malware-with-upx-unpacker\u002Freferences\u002Fapi-reference.md",{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"scripts\u002Fagent.py","SCRIPT","脚本",8699,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fanalyzing-packed-malware-with-upx-unpacker\u002Fscripts\u002Fagent.py",[73,82,89,96,103,110],{"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},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],"2026-11-12 13:55:43",{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":81},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":81},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"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":77,"licenseFileUrl":6,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":81},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":107,"categories":108,"keywords":109,"publishedAt":81},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":111,"name":112,"nameZh":6,"description":113,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":114,"categories":115,"keywords":116,"publishedAt":81},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]