socmalwareanalysis
MDstable
NoteSnippetChecklistPlaybook
Analyse de malware — Triage rapide
Analyse statique et dynamique de malware, sandbox, IOC extraction
snippetadvanced 2025-05-13 6 min read
socmalwareanalysissandboxIOCstaticdynamicreverse
Workflow d'analyse — Vue d'ensemble
Fichier suspect reu1 Hashing VirusTotal lookupMalveillant confirm Oui Passer IOC extractionNon/Inconnu2 Analyse statiqueStrings PE headers imports3 Sandbox dynamiqueComportement rseau FS registry4 IOC extraction partage TIP5 YARA rule creation
Analyse statique
Identification du fichier
bash
# Type de fichier réel (ignorer l'extension)file suspiciousexefile suspiciouspdf# Entropie — haute entropie = packed/chiffrépython3 -cimport sys mathdata open'suspicious.exe' 'rb'readfreqfor b in datafreqb freqgetb 0 1entropy -sum((c/len(data)) mathlog2c/lendata for c in freqvaluesprintf'Entropy: {entropy:.2f} bits/byte (> 7.0 = likely packed)'# Hashes — collecte complètemd5sum suspiciousexesha256sum suspiciousexesha1sum suspiciousexe# Ou PowerShellGet-FileHash suspiciousexe -Algorithm MD5 SHA1 SHA256 | Format-List
VirusTotal & MalwareBazaar
bash
Variables
{{VT_API_KEY}}
# VirusTotal via APIVT_API"{{VT_API_KEY}}"SHA256sha256sum suspiciousexe | cut -d' -f1)curl -s "https://www.virustotal.com/api/v3/files/$SHA256"-H "x-apikey: $VT_API" | jqname dataattributesmeaningful_namemalicious dataattributeslast_analysis_statsmaliciousundetected dataattributeslast_analysis_statsundetectedfirst_seen dataattributesfirst_submission_datefamily dataattributespopular_threat_classificationsuggested_threat_label# MalwareBazaar lookup (pas de clé requise pour query)curl -s -X POST "https://mb-api.abuse.ch/api/v1/"-d "query=get_info&hash=$SHA256" | jq data0 |file_name file_type signature tags reporter
Strings — Extraction et analyse
bash
# Strings basiquesstrings suspiciousexe | grep -iE "(http|ftp|\\\\|cmd|power|shell|download|upload)"# Strings Unicodestrings -el suspiciousexe | head -100# Strings avec offset (pour corrélation avec dissassembly)strings -t x suspiciousexe | grep -iE "(CreateRemoteThread|VirtualAlloc|WriteProcessMemory)"# Strings suspects — fonctions d'injection mémoireSUSPECT_FUNCS"VirtualAlloc" "VirtualAllocEx" "WriteProcessMemory""CreateRemoteThread" "NtCreateThreadEx" "RtlCreateUserThread""ShellExecute" "WinExec" "CreateProcess""RegSetValue" "RegCreateKey""InternetOpen" "InternetConnect" "HttpSendRequest""WSAStartup" "connect" "send" "recv"for func in "${SUSPECT_FUNCS[@]}"; docountstrings suspiciousexe | grep -c "$func" 2>/dev/null"$count" -gt 0 && echo "FOUND [$count]: $func"done
PE Headers — pestudio / pefile
python
# Python — analyse PE avec pefileimport pefileimport syspe = pefile.PE("suspicious.exe")print("=== PE INFO ===")print(f"Machine: {hex(pe.FILE_HEADER.Machine)}")print(f"Timestamp: {pe.FILE_HEADER.dump_dict()['TimeDateStamp']['Value']}")print(f"Subsystem: {pe.OPTIONAL_HEADER.Subsystem}")print(f"Entry Point: {hex(pe.OPTIONAL_HEADER.AddressOfEntryPoint)}")print("\n=== SECTIONS ===")for s in pe.sections:entropy = s.get_entropy()print(f" {s.Name.decode().strip()} | VSize={s.Misc_VirtualSize} | Entropy={entropy:.2f}")if entropy > 7.0:print(f" ^^^ HIGH ENTROPY — possible packed/encrypted section")print("\n=== IMPORTS ===")if hasattr(pe, 'DIRECTORY_ENTRY_IMPORT'):for lib in pe.DIRECTORY_ENTRY_IMPORT:print(f" {lib.dll.decode()}")for imp in lib.imports:if imp.name:func = imp.name.decode()if any(s in func for s in ["VirtualAlloc", "CreateRemoteThread", "WriteProcess","LoadLibrary", "GetProcAddress", "ShellExec"]):print(f" *** SUSPICIOUS: {func}")print("\n=== EXPORTS ===")if hasattr(pe, 'DIRECTORY_ENTRY_EXPORT'):for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols:if exp.name:print(f" {exp.name.decode()}")
Analyse dynamique — Sandbox
Plateformes recommandées
| Plateforme | URL | Avantages | |---|---|---| | ANY.RUN | app.any.run | Interactif, temps réel, MITRE mapping | | Hybrid Analysis | hybrid-analysis.com | Gratuit, rapport détaillé | | Joe Sandbox | joesandbox.com | Deep analysis, déobfuscation | | Triage (Hatching) | tria.ge | API-first, rapide | | Cuckoo | Auto-hébergé | Privé, personnalisable |
Cuckoo — Analyse locale
bash
Variables
{{MALICIOUS_URL}}
{{TASK_ID}}
# Soumettre un fichier à Cuckoocuckoo submit --timeout 120 suspiciousexe# Soumettre une URLcuckoo submit --url "http://{{MALICIOUS_URL}}"# Vérifier le résultatcuckoo api # Port 8090 par défautcurl http//localhost8090/tasks/report/{{TASK_ID}}/json | jq '.signatures[].name'# Extraire les IOCs du rapportcurl http//localhost8090/tasks/report/{{TASK_ID}}/json | jqdomains networkdomainsdomainips networkhostsmutexes behaviorsummarymutexesfiles behaviorsummaryfilesregistry behaviorsummarykeys
Checklist IOC Extraction
Checklist0/13
YARA — Bases et exemple
Structure d'une règle YARA
yara
Variables
{{ANALYST_NAME}}
{{MALWARE_FAMILY}}
{{SHA256_HASH}}
{{REPORT_URL}}
{{C2_DOMAIN}}
rule Malware_FamilyName_Variant {meta:author = "{{ANALYST_NAME}}"date = "2025-05-13"description = "Détecte {{MALWARE_FAMILY}} variant X"hash = "{{SHA256_HASH}}"reference = "https://{{REPORT_URL}}"mitre = "T1059.001, T1071.001"strings:// Strings ASCII/Wide$s1 = "CreateRemoteThread" ascii$s2 = "VirtualAlloc" ascii$s3 = "{{C2_DOMAIN}}" wide ascii nocase// Pattern hexadécimal (shellcode signature)$hex1 = { 60 89 E5 31 D2 64 8B 52 30 }// Regex$re1 = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/ // GUID mutexcondition:uint16(0) == 0x5A4D // MZ header (PE file)and filesize < 5MBand ((2 of ($s*)) or$hex1 or($re1 and 1 of ($s*)))}
Tests YARA
bash
# Tester sur un fichieryara ruleyar suspiciousexe -s# Tester sur un répertoireyara -r ruleyar /malware_samples/# Tester depuis un dossier de règles (SigmaHQ style)yara rules target_fileexe --no-warnings# Vérifier les faux positifs sur binaires légitimesyara ruleyar /Windows/System32/ 2>/dev/null | head -20
IOCs réseau — Analyse PCAP
bash
# Wireshark / tshark — filtres pour trafic malware# Connexions HTTP suspectestshark -r capturepcap -Y "http.request"-T fields -e ipsrc -e ipdst -e httphost -e httprequesturi -e httpuser_agent# DNS — domaines résolustshark -r capturepcap -Y "dns.flags.response == 0"-T fields -e ipsrc -e dnsqryname -e dnsqrytype# Certificats TLS — extraction CN et SANstshark -r capturepcap -Y "ssl.handshake.type == 11"-T fields -e x509satuTF8String -e ipdst# Extraction automatique de fichiers HTTP (payloads)tshark -r capturepcap --export-objects http/tmp/http_objects/# Suricata sur PCAP existantsuricata -r capturepcap -l /tmp/suricata_output/ -c /etc/suricata/suricata.yamljq '.alert.signature' /tmp/suricata_output/eve.json | sort | uniq -c | sort -rn
Techniques d'évasion — VM detection
bash
# Avant de détonner en sandbox : rechercher des marqueurs d'évasion dans les stringsstrings suspiciousexe | grep -iE "(vmware|virtualbox|sandbox|wine|cuckoo|vbox|qemu)"strings suspiciousexe | grep -iE "(SbieDll|sbiedrvr|snxhk|avghookx)"# Marqueurs courants de VM detection# - CPUID checks (hypervisor bit)# - Registry keys : HKLM\SOFTWARE\VMware Inc.# - Fichiers : C:\windows\system32\drivers\vmmouse.sys# - Process : vmtoolsd.exe, vboxservice.exe# - MAC prefix : 00:0C:29 (VMware), 08:00:27 (VirtualBox)# - Timing attacks : RDTSC delta anormal
💡 Tip — Toujours détonner dans un réseau isolé (VLAN dédié, pas de routage vers Internet sauf proxy contrôlé) et vérifier les techniques de VM detection AVANT l'exécution — un malware qui détecte un sandbox peut adopter un comportement bénin. Utiliser des profils de sandbox qui imitent de vrais hôtes (nom réaliste, user actif, documents Office présents) pour contourner les évasions basiques.
OPS·BRAIN v1.075 notes · Securitylocal