ম্যালওয়্যার অ্যানালাইসিস
স্ট্যাটিক ও ডাইনামিক অ্যানালাইসিস, স্যান্ডবক্স এক্সিকিউশন, YARA rules, ডিঅবফাসকেশন, আর ম্যালিশিয়াস কোড রিভার্স ইঞ্জিনিয়ারিং।
গল্পে বুঝি
ফাতিমা আল-ফিহরি একজন বোম্ব ডিসপোজাল এক্সপার্ট। শহরের এক কোণে একটা সন্দেহজনক ডিভাইস পাওয়া গেছে — তারের জট, একটা টাইমার, ভেতরে কী আছে কেউ জানে না। ফাতিমা কিন্তু ব্যস্ত রাস্তার মাঝখানে বসে এটা খুলতে বসেন না। ডিভাইসটা প্রথমে তুলে নিয়ে যাওয়া হয় একটা সিল করা, ব্লাস্ট-প্রুফ কনটেইনমেন্ট রুমে — মোটা দেয়াল, বাইরের কারও কোনো ক্ষতি হবে না। ওখানে বসেই তিনি কাজ শুরু করেন।
প্রথম ধাপে ফাতিমা ডিভাইসটাকে ট্রিগার না করেই বাইরে থেকে খুঁটিয়ে দেখেন — কী ধরনের তার, কোন সার্কিট কোথায় যুক্ত, গঠনটা কেমন। কিছুই চালু করেন না, শুধু কাঠামো পড়েন। এরপর দ্বিতীয় ধাপে, একই সিল করা ঘরের নিরাপত্তায়, তিনি ডিভাইসটাকে নিয়ন্ত্রিতভাবে একটু কাজ করতে দেন — ঠিক কী করার চেষ্টা করে সেটা নিজের চোখে দেখেন। সব ইনফরমেশন লিখে রাখেন, যাতে পরেরবার একই ধরনের ডিভাইস দেখলেই বোম্ব স্কোয়াড চিনে ফেলে আর সহজে ডিফিউজ করতে পারে। বাইরে খোলা রাস্তায় ঝুঁকি নেওয়ার প্রশ্নই আসে না।
malware analysis ঠিক এই জিনিসটাই। ব্লাস্ট-প্রুফ কনটেইনমেন্ট রুম হলো isolated sandbox — একটা আলাদা করা এনভায়রনমেন্ট যেখানে ম্যালিশিয়াস প্রোগ্রাম বাইরের সিস্টেমের কোনো ক্ষতি করতে পারে না। ট্রিগার না করেই বাইরে থেকে দেখা মানে static analysis — ফাইল রান না করেই তার গঠন, strings, ইম্পোর্ট পড়া। আর নিয়ন্ত্রিতভাবে কাজ করতে দিয়ে আচরণ দেখা মানে dynamic analysis — sandbox-এর ভেতরে চালিয়ে ঠিক কী করে সেটা অবজার্ভ করা। এসব থেকে যা শেখা যায় তা দিয়ে detection বানানো হয় — YARA rules বা signature — যাতে পরের নমুনা এলেই চেনা যায়। আর সবচেয়ে গুরুত্বপূর্ণ নিয়ম: বোম্ব যেমন ব্যস্ত রাস্তায় খোলা হয় না, ম্যালওয়্যারও কখনো নিজের আসল মেশিনে চালানো হয় না — সবসময় isolated VM বা sandbox-এই। বাস্তবে এভাবেই SOC টিম, threat intelligence রিসার্চার আর অ্যান্টিভাইরাস ভেন্ডররা নতুন ম্যালওয়্যার ফ্যামিলি ডিফেন্সিভলি স্টাডি করে।
বাস্তব জীবনের উপমা
একজন বোম্ব ডিসপোজাল টেকনিশিয়ান কখনো অনুমানের ভিত্তিতে ডিভাইস ডিফিউজ করেন না — প্রথমে মেকানিজম স্টাডি করেন: কী ধরনের ট্রিগার, কী সার্কিট, অপারেশনের অর্ডার কী। ম্যালওয়্যার অ্যানালাইসিসও একই রকম: হাত দেওয়ার আগে বুঝে নিতে হবে এটা আসলে কী করে।
ল্যাব সেটআপ (আগে সেফটি)
# NEVER analyze malware on your main machine
# Use an isolated VM with:
# - No host-only adapters that malware could pivot to host
# - Snapshot before analysis (restore after)
# - Flare-VM (Windows) or REMnux (Linux) — pre-configured analysis distros
# Install Flare-VM (Windows analysis)
# https://github.com/mandiant/flare-vm
# Install REMnux (Linux analysis)
# https://remnux.org/
# Network isolation options:
# - NAT but with FakeNet-NG (intercepts network calls, doesn't let them out)
# - Host-only adapter (can reach host but not internet)
# - No network (for most static analysis) স্ট্যাটিক অ্যানালাইসিস — এক্সিকিউশন ছাড়াই
ফাইল রান না করেই সেটা পরীক্ষা করা।
ফাইল আইডেন্টিফিকেশন
# Identify the file type (don't trust the extension)
file malware.exe
file malware.pdf # might actually be an EXE
# Check hashes — search VirusTotal
md5sum malware.exe
sha256sum malware.exe
# Search: virustotal.com (68 AV engines check it)
# Quick automated check
curl -s --request POST \
--url 'https://www.virustotal.com/vtapi/v2/file/scan' \
--form apikey='YOUR_KEY' \
--form file=@malware.exe | jq '.permalink' Strings এক্সট্র্যাকশন
# Basic strings
strings malware.exe
strings -n 8 malware.exe # minimum 8 chars (reduce noise)
strings -e l malware.exe # Unicode strings (Windows malware often uses Unicode)
# Look for:
# - URLs and IPs (C2 servers)
# - Registry keys (persistence)
# - File paths (what does it create/modify)
# - Function names (API calls reveal behavior)
# - Error messages (reveal programming language/compiler)
# - Encoded strings (base64, hex — sign of obfuscation)
strings malware.exe | grep -iE "(http|https|ftp)://"
strings malware.exe | grep -iE "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
strings malware.exe | grep -i "HKEY_\|SOFTWARE\\\|Run" PE হেডার অ্যানালাইসিস (Windows)
# PE files = Windows executables
# PEiD, Detect-It-Easy — identify packer/compiler
die malware.exe # Detect-It-Easy CLI
# Output: "PE64, Microsoft Visual C++ 2019"
# Or: "Packed: UPX 3.96" → needs unpacking
# PEview — examine PE structure
peview malware.exe
# Python: pefile
pip install pefile
python3 << EOF
import pefile
pe = pefile.PE('malware.exe')
# Compilation timestamp
print("Compile time:", pe.FILE_HEADER.TimeDateStamp)
# Imports — what Windows APIs does it call?
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print(f"\nDLL: {entry.dll.decode()}")
for imp in entry.imports:
if imp.name:
print(f" {imp.name.decode()}")
EOF সন্দেহজনক Windows API imports:
CreateRemoteThread → process injection
VirtualAllocEx → allocating memory in other processes
WriteProcessMemory → writing to other processes
SetWindowsHookEx → keylogging
CreateService → persistence as service
RegSetValueEx → registry persistence
WinExec / ShellExecute → executing commands
InternetOpenUrl → network communication
CryptEncrypt → encrypting data (ransomware?)
FindFirstFile/FindNextFile → file enumeration (ransomware?) আনপ্যাকিং
প্যাক করা ম্যালওয়্যার আসল কোড কমপ্রেস/এনক্রিপ্ট করে রাখে। ডাইনামিক অ্যানালাইসিস প্রায়ই জোর করে আনপ্যাক করিয়ে দেয়।
# UPX (most common)
upx -d malware.exe # decompress
upx -d -o unpacked.exe malware.exe
# Generic unpacking:
# 1. Run in debugger
# 2. Wait for OEP (original entry point) — where real code starts
# 3. Dump memory at that point
# Tools: x64dbg + ScyllaHide plugin (PE Rebuilder) ডাইনামিক অ্যানালাইসিস — নিয়ন্ত্রিত এক্সিকিউশন
স্যাম্পল রান করে দেখা এটা আসলে কী করে।
Process Monitor (Procmon)
Procmon — records all file, registry, and network activity
Filters to set:
Process Name is malware.exe
Watch for:
- CreateFile → what files does it create/read?
- WriteFile → what does it write?
- RegSetValue → what registry keys does it set?
- Process Create → does it spawn child processes? নেটওয়ার্ক ট্রাফিক অ্যানালাইসিস
# Wireshark — capture while malware runs
wireshark &
# Start capture, run malware (in VM!), stop capture
# FakeNet-NG — intercepts network calls, simulates internet services
# Prevents real C2 connection, captures what the malware tries to do
fakenet --config-dir configs/
# Inetsim — simulate DNS, HTTP, FTP, SMTP servers
inetsim
# All DNS queries return FakeNet IP, HTTP connections are served generic pages
# Malware makes real network calls → captured by Inetsim স্যান্ডবক্স অ্যানালাইসিস (অটোমেটেড)
# Any.run — interactive sandbox (free tier)
# https://app.any.run — upload file, see live behavior
# Cuckoo Sandbox — self-hosted
pip install cuckoo
cuckoo init
cuckoo -d # start in debug mode
curl -F "file=@malware.exe" http://localhost:8090/tasks/create/file
# VirusTotal sandbox
# Upload → Behavior tab → see API calls, network, files
# Joe Sandbox
# Hybrid Analysis (https://hybrid-analysis.com) — free tier ডিসঅ্যাসেম্বলি ও ডিকম্পাইলেশন
# Ghidra — NSA's free decompiler (best free option)
# https://ghidra-sre.org
# Open project → Import file → Analyze → CodeBrowser
# Decompiler view: C-like pseudocode from assembly
# Radare2 — open source, CLI-based
r2 malware.exe
# Commands:
# aaa → analyze all
# afl → list functions
# pdf @main → print disassembly of main
# VV → visual graph mode
# ? → help
# x64dbg — Windows debugger for dynamic analysis
# Open malware.exe → set breakpoints → step through execution
# F7: step into F8: step over F9: run F2: breakpoint
# IDA Pro (commercial, industry standard)
# Community version available for non-commercial use কমন অবফাসকেশন টেকনিক
# XOR encoding — simple but common
key = 0x41
encoded = bytes([b ^ key for b in encoded_shellcode])
# Base64 PowerShell (common in phishing)
# Decode:
import base64
cmd = "cG93ZXJzaGVsbCAtZW5jb2RlZA=="
print(base64.b64decode(cmd).decode('utf-16'))
# String reversal
reversed_url = "moc.live/nettekcer.www//:sptth"[::-1]
# ROT13
import codecs
codecs.decode("GERIRY", "rot13") # TREVER
# CyberChef handles all of these automatically YARA Rules — ম্যালওয়্যার ডিটেকশন
YARA হলো ম্যালওয়্যার ফ্যামিলি ক্লাসিফাই করার জন্য একটা প্যাটার্ন-ম্যাচিং টুল।
# Write a YARA rule
rule Ransomware_WannaCry {
meta:
author = "Analyst"
description = "WannaCry Ransomware"
hash = "db349b97c37d22f5ea1d1841e3c89eb4"
strings:
$s1 = "tasksche.exe" ascii
$s2 = "WanaCrypt0r" ascii wide
$s3 = "WANNACRY" ascii nocase
$pdb = "C:\\projects\\wannacry" ascii
$ransom_note = {
57 61 6E 6E 61 43 72 79 70 74 // WannaCrypt in hex
}
condition:
uint16(0) == 0x5A4D // MZ header (PE file)
and filesize < 10MB
and (2 of ($s*) or $ransom_note or $pdb)
} # Scan with YARA
yara rule.yar malware.exe
yara rule.yar /suspicious/directory/ -r # recursive
# YARA rule sources:
# - Signature-Base by Florian Roth (github.com/Neo23x0/signature-base)
# - Awesome YARA rules collection
# - VirusTotal Intelligence (paid)
# Compile rules for performance
yarac rules.yar rules.yrc
yara rules.yrc malware.exe বিহেভিয়ারাল অ্যানালাইসিস টেকনিক
# Regshot — take registry snapshot before and after malware runs
# Diff shows exactly what registry keys were added/modified/deleted
# Process Hacker — real-time process, memory, and network monitoring
# More powerful than Task Manager for malware analysis
# API Monitor — hook API calls, see exact parameters
# Reveals: file paths, registry keys, URLs, crypto operations
# Detect command and control (C2) communication patterns
# - Periodic beaconing (every N seconds) → likely C2 heartbeat
# - DNS queries for random-looking domains → DGA (Domain Generation Algorithm)
# - Large outbound data → exfiltration
# - HTTPS to single IP (not a CDN) → encrypted C2
# DGA detection — compute Alexa-based score
python3 dga_detector.py suspicious_domain.com রিয়েল প্রজেক্ট: WannaCry অ্যানালাইজ করা
# Get the WannaCry sample (from theZoo malware repository - controlled environment only)
# sha256: 24d004a104d4d54034dbcffc2a4b19a11f39008a575aa614ea04703480b1022c
# In isolated VM:
# 1. Strings analysis
strings wannacry.exe | grep -iE "(http|https|\.onion|bitcoin)"
# 2. PE imports — look for crypto APIs
python3 -c "
import pefile
pe = pefile.PE('wannacry.exe')
for entry in pe.DIRECTORY_ENTRY_IMPORT:
print(entry.dll.decode())
for imp in entry.imports:
if imp.name and b'Crypt' in imp.name:
print(' ', imp.name.decode())
"
# 3. Open in Ghidra — find the encryption routine
# Search for CryptEncrypt, CryptImportKey, CryptGenRandom
# 4. Find the killswitch domain:
strings wannacry.exe | grep -i "www\."
# Found: www.iuqerfsodp9ifjaposdfjhgosurijfaewrwergwea.com
# 5. Run in Cuckoo sandbox — see complete behavior report