Static Analysis On Linux
Static analysis involves examining malware without executing it. It helps identify malware properties, such as file type, strings, hashes, embedded elements, and packer information, serving as a foundation for deeper analysis.
Key Static Analysis Components
File Type: Identifying actual file types prevents reliance on potentially misleading file extensions.
File Hashes: Unique identifiers for tracking malware samples.
Strings: Extracted ASCII and Unicode strings provide insights into potential malware functionality.
Embedded Elements: Identifiable elements (like domains or file paths).
Packer Information: Detects if malware is packed or compressed, which may obscure analysis.
Imports/Exports: Identifies imported and exported functions.
Assembly Code: Provides low-level insights.
File Type Identification
To identify the actual file type:
file /path/to/malware.exeExample result:
PE32 executable (GUI) Intel 80386, for MS WindowsAlternatively, inspect the file header:
hexdump -C /path/to/malware.exe | moreLook for the "MZ" (4D 5A) magic number to confirm it's a Windows executable.
Malware Fingerprinting
File Hashes
Generate MD5 or SHA256 hashes to uniquely identify malware samples:
md5sum /path/to/malware.exe
sha256sum /path/to/malware.exeUse these hashes to cross-reference with online databases like VirusTotal.
Import Hash (IMPHASH)
IMPHASH identifies similar malware by hashing imports in alphabetical order. Example Python code:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
imphash = pe.get_imphash()
print(imphash)Run the script:
python3 imphash_calc.py /path/to/malware.exeFuzzy Hashing (SSDEEP)
Calculate SSDEEP for similarity matching:
ssdeep /path/to/malware.exeSection Hashing (Hashing PE Sections)
Hashing individual PE sections helps detect small changes in malware. Example Python code:
import sys
import pefile
pe_file = sys.argv[1]
pe = pefile.PE(pe_file)
for section in pe.sections:
print(section.Name, "MD5 hash:", section.get_hash_md5())
print(section.Name, "SHA256 hash:", section.get_hash_sha256())Run the script:
python3 section_hashing.py /path/to/malware.exeString Analysis
Strings help reveal filenames, IPs, registry paths, API functions, etc. Extract strings:
strings -n 15 /path/to/malware.exeTo analyze obfuscated strings, use FLOSS:
floss /path/to/malware.exeUnpacking UPX-Packed Malware
Packed malware obfuscates or compresses code. Detect UPX-packed malware by looking for UPX in the strings output.
Unpack with UPX:
upx -d -o /path/to/unpacked_malware.exe /path/to/malware.exeAfter unpacking, rerun strings to see unobfuscated data:
strings /path/to/unpacked_malware.exeLast updated