analyzing-packed-malware-with-upx-unpacker
Fungsinya
Alat ini membantu membuka (unpack) program yang telah 'di-pack' menggunakan alat bernama UPX. Ini berguna ketika perangkat lunak berbahaya (virus) disamarkan dan Anda perlu melihat kode aslinya untuk dianalisis.
Kapan dipakai
- ✓Ketika sebuah program terlihat mencurigakan dan hanya memiliki sedikit informasi yang terlihat.
- ✓Ketika alat lain menunjukkan bahwa program tersebut 'di-pack' dengan UPX.
- ✓Ketika Anda perlu menganalisis kode asli sebuah program untuk keperluan keamanan.
Link skill
https://github.com/mukul975/Anthropic-Cybersecurity-Skills/blob/main/skills/analyzing-packed-malware-with-upx-unpacker/SKILL.mdSalin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.
Cara pakai
Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.
Pesan siap tempel
Untuk Claude Code, Codex, atau Cursor: jalankan di folder proyek, lalu skill langsung terpasang.
Unduh SKILL.md lalu taruh di folder skill agen Anda.
Contoh permintaan ke AI
“Buka (unpack) file mencurigakan ini supaya saya bisa menganalisisnya.”
5 skill baru setiap minggu. 1 menit baca.
Cara kerjanya
Alat ini mencoba membuka file menggunakan UPX. Jika gagal karena 'packer'-nya telah dimodifikasi, alat akan memperbaiki bagian yang diubah terlebih dahulu, lalu mencoba membukanya kembali.
Konten teknis (SKILL.md asli)
Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.
Analyzing Packed Malware with UPX Unpacker
When to Use
- Static analysis reveals high entropy sections and minimal imports indicating the binary is packed
- PEiD, Detect It Easy, or PEStudio identifies UPX or another known packer
- The import table contains only LoadLibrary and GetProcAddress (runtime import resolution typical of packed binaries)
- You need to recover the original binary for proper disassembly and decompilation in Ghidra or IDA
- Automated UPX decompression fails because the malware author modified UPX magic bytes or headers
Do not use when dealing with custom packers, VM-based protectors (Themida, VMProtect), or samples where dynamic unpacking via debugging is more appropriate.
Prerequisites
- UPX (Ultimate Packer for eXecutables) installed (
apt install upx-uclor download from https://upx.github.io/) - Detect It Easy (DIE) for packer identification
- Python 3.8+ with
pefilelibrary for manual header repair - x64dbg or x32dbg for manual unpacking when automated tools fail
- PE-bear or CFF Explorer for PE header inspection and repair
- Isolated analysis VM without network connectivity
Workflow
Step 1: Identify the Packer
Determine if the sample is packed and identify the packer:
# Check with Detect It Easy
diec suspect.exe
# Check with UPX (test without unpacking)
upx -t suspect.exe
# Python-based entropy and packer detection
python3 << 'PYEOF'
import pefile
import math
pe = pefile.PE("suspect.exe")
print("Section Analysis:")
for section in pe.sections:
name = section.Name.decode().rstrip('\x00')
entropy = section.get_entropy()
raw = section.SizeOfRawData
virtual = section.Misc_VirtualSize
print(f" {name:8s} Entropy: {entropy:.2f} Raw: {raw:>8} Virtual: {virtual:>8}")
# Check for UPX section names
section_names = [s.Name.decode().rstrip('\x00') for s in pe.sections]
if 'UPX0' in section_names or 'UPX1' in section_names:
print("\n[!] UPX section names detected")
elif '.upx' in [s.lower() for s in section_names]:
print("\n[!] UPX variant section names detected")
# Check import count (packed binaries have very few)
if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):
total_imports = sum(len(e.imports) for e in pe.DIRECTORY_ENTRY_IMPORT)
print(f"\nTotal imports: {total_imports}")
if total_imports < 10:
print("[!] Very few imports - likely packed")
else:
print("\n[!] No import directory - heavily packed")
PYEOF
Step 2: Attempt Standard UPX Decompression
Try the built-in UPX decompression:
# Standard UPX decompress
upx -d suspect.exe -o unpacked.exe
# If UPX fails with "not packed by UPX" error, the headers may be modified
# Verbose output for debugging
upx -d suspect.exe -o unpacked.exe -v 2>&1
# Verify the unpacked file
file unpacked.exe
diec unpacked.exe
Step 3: Repair Modified UPX Headers
If standard decompression fails, repair tampered magic bytes:
# Repair modified UPX headers
import struct
with open("suspect.exe", "rb") as f:
data = bytearray(f.read())
# UPX magic bytes: "UPX!" (0x55505821)
# Malware authors commonly modify these to prevent automatic unpacking
# Search for modified UPX signatures
upx_magic = b"UPX!"
modified_patterns = [b"UPX0", b"UPX\x00", b"\x00PX!", b"UPx!"]
# Find and restore section names
pe_offset = struct.unpack_from("<I", data, 0x3C)[0]
num_sections = struct.unpack_from("<H", data, pe_offset + 6)[0]
section_table_offset = pe_offset + 0x18 + struct.unpack_from("<H", data, pe_offset + 0x14)[0]
print(f"PE offset: 0x{pe_offset:X}")
print(f"Number of sections: {num_sections}")
print(f"Section table offset: 0x{section_table_offset:X}")
for i in range(num_sections):
offset = section_table_offset + (i * 40)
name = data[offset:offset+8]
print(f"Section {i}: {name}")
# Restore UPX magic bytes in the binary
# Search for the UPX header signature location (typically near the end of packed data)
for i in range(len(data) - 4):
if data[i:i+3] == b"UPX" and data[i+3] != ord("!"):
print(f"Found modified UPX magic at offset 0x{i:X}: {data[i:i+4]}")
data[i:i+4] = b"UPX!"
print(f"Restored to: UPX!")
# Also restore section names if modified
for i in range(num_sections):
offset = section_table_offset + (i * 40)
name = data[offset:offset+8].rstrip(b'\x00')
if name in [b"UPX0", b"UPX1", b"UPX2"]:
continue # Already correct
# Check for common modifications
…
Pertanyaan umum
Apa artinya 'pack' pada sebuah program?
Ibaratnya seperti memasukkan program ke dalam kotak khusus agar ukurannya lebih kecil atau lebih sulit dipahami. UPX adalah alat umum yang digunakan untuk ini.
Mengapa perangkat lunak berbahaya perlu dibuka?
Supaya para ahli keamanan bisa melihat kode aslinya dan memahami cara kerjanya, kerusakan apa yang bisa ditimbulkan, dan bagaimana cara melawannya.
Apa itu 'magic bytes' yang dimodifikasi?
Ini adalah kode khusus di awal sebuah file yang menunjukkan jenis 'packer' yang digunakan. Jika kode ini diubah, alat biasa mungkin tidak mengenali file tersebut sebagai file yang di-pack dengan UPX.
Detail
Deskripsi asli dari pembuat
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/GetProcAddress in its import table, or when preparing a packed binary for disassembly in Ghidra or IDA. '
Popularitas
- Bintang GitHub
- 35k
- Peringkat
- #7642
- Lisensi
- Apache-2.0
- Diperbarui
- 31/8/2026
Komentar
- …
Skill lain dari repositori ini
abusing-dpapi-for-credential-access
35kMemberi agent AI Anda instruksi siap pakai untuk tugas tertentu, sehingga hasilnya lebih baik dan pengerjaannya lebih cepat.
abusing-shadow-credentials-for-privesc
35kMengajarkan agent AI Anda menulis teks yang jelas dan terstruktur dengan baik.
achieving-cmmc-level-2-compliance
35kMembantu agent Anda menyiapkan lingkungan untuk kepatuhan CMMC Level 2. Skill ini menerapkan persyaratan keamanan dan mengelola dokumentasi yang diperlukan.
acquiring-disk-image-with-dd-and-dcfldd
35kMembantu agent Anda membuat salinan persis dari hard drive. Berguna untuk memastikan tidak ada informasi yang hilang atau berubah selama investigasi.
Skill serupa
gitcrawl
394kMemungkinkan agent Anda mencari arsip issue dan pull request GitHub yang tersimpan, mengelompokkan yang duplikat, dan memeriksa status terkininya di GitHub.
slacrawl
394kMemungkinkan agent Anda mencari dan menghitung pesan di arsip Slack lokal, memeriksa seberapa baru arsip itu, dan menyegarkannya bila diperlukan.
goplaces
394kMembantu agent Anda mencari tempat, mendapatkan detail dan ulasannya, serta menentukan nama tempat memakai Google Places, dengan keluaran JSON untuk skrip.