Knowledge / Computer Science (Cyber Security) / Malware analysis and reverse engineering

Malware analysis and reverse engineering

Computer Science (Cyber Security) (B.E./B.Tech) · Offensive and defensive security · free study notes for exams, placements and interviews

In short

Malware analysis is the systematic examination of malicious software to determine what it does, how it does it, how to detect it and how to remove it; reverse engineering is the technique of recovering a program's design and logic from its binary when no source code is available. It combines file-format knowledge (PE/ELF), x86/x64 assembly, debugging, sandboxing and signature writing (YARA), and feeds detection rules and indicators of compromise back to defenders. Indian employers hiring for this include antivirus and product companies (Quick Heal/Seqrite, K7 Computing, Trend Micro, Palo Alto Networks, CrowdStrike, Zscaler India R&D), CERT-In and NCIIPC, the big SOC/MSSP practices (TCS, Infosys, Wipro, HCLTech, Accenture, LTIMindtree) and DFIR teams in banks under RBI cyber-security directions. It appears in AICTE/CBCS "Malware Analysis", "Cyber Forensics" and "Information Security" papers, in M.Tech cyber-security entrance interviews, and in certification syllabi (GREM, CEH, OSCP-adjacent).

Explained

Malware types and classification

Analysis lab and safety

Static analysis (without executing)

  1. Identify the file: file, magic bytes (MZ for PE, 0x7F "ELF", PK for APK/JAR), hashes MD5/SHA-1/SHA-256 for lookup; ssdeep/TLSH fuzzy hashes to find near-identical variants; imphash (hash of the import table) to cluster same-compiler/same-family builds.
  2. Strings: strings (ASCII and UTF-16) reveals URLs, IPs, registry keys, mutex names, ransom-note text, PDB paths, embedded commands. Few meaningful strings usually means packing or encryption.
  3. PE structure: DOS header → NT headers (IMAGE_FILE_HEADER, IMAGE_OPTIONAL_HEADER) → section table. Useful fields: AddressOfEntryPoint, ImageBase, Subsystem, TimeDateStamp (can be forged), sections .text .data .rdata .rsrc .reloc.
  4. Imports/exports: suspicious imports tell the story - CreateRemoteThread, WriteProcessMemory, VirtualAllocEx (injection); SetWindowsHookEx, GetAsyncKeyState (keylogging); CryptEncrypt/BCryptGenRandom (ransomware); InternetOpenUrl/WinHttpSendRequest (C2); LoadLibrary+GetProcAddress only = dynamic resolution to hide intent.
  5. Resources and overlays: .rsrc often hides a second-stage PE, a decoy PDF or a configuration blob; data appended after the last section (overlay) is a common payload store.
  6. Digital signature: check Authenticode - a valid signature from a stolen certificate is a strong IOC; an invalid/absent signature on something claiming to be from a known vendor is suspicious.
  7. Disassembly/decompilation: IDA Pro, Ghidra (free, NSA), Binary Ninja, radare2/rizin, objdump; Ghidra's decompiler gives readable C-like pseudocode for quick triage. For .NET use dnSpy/ILSpy (IL is nearly source); for Java jadx; for Python-compiled EXEs pyinstxtractor + uncompyle/decompyle3.
  8. Advantages: safe, complete code coverage including branches never taken at runtime, no network exposure. Limits: defeated by packing and obfuscation, cannot see runtime-decrypted configuration, slow and skill-intensive.

Dynamic and behavioural analysis

Obfuscation, packing and anti-analysis

Code injection, persistence and the ATT&CK view

Detection artefacts: IOCs, YARA and reporting

Key points

Formulas and examples

Shannon entropy H = − Σ pᵢ log₂ pᵢ, where pᵢ is the frequency of byte value i; H is in bits per byte, range 0 to 8 for byte data. H > ≈7.2 for a code section suggests packing/encryption.
PE header offset: e_lfanew is the 4-byte little-endian value at file offset 0x3C; the PE signature 50 45 00 00 sits at that offset.
Section raw/virtual mismatch (packing hint): ratio = VirtualSize / SizeOfRawData; ratio ≫ 1 (or SizeOfRawData = 0) indicates code written at runtime.
Imphash = MD5 of the string "library.function, library.function, ..." built from the import table in order, lower-cased.
Detection-rate / confusion metrics: TPR = TP/(TP+FN), FPR = FP/(FP+TN), Precision = TP/(TP+FP), Accuracy = (TP+TN)/Total. Dimensionless, usually shown as %.
ssdeep similarity = integer 0-100 (100 = near-identical content); it is a similarity score, not a probability.
Ransomware encryption time ≈ Data size / Throughput, with throughput in MB/s; key-space size = 2n for an n-bit symmetric key.

Example 1 - Entropy of a packed section. A .text section of 64 KB has, after counting, 256 distinct byte values each occurring with almost equal frequency (pᵢ ≈ 1/256).

Example 2 - Two-symbol entropy check (hand calculation). A 1,000-byte blob contains only two byte values, 0x00 (750 times) and 0xFF (250 times).

Example 3 - Reading a PE header by hand. First bytes of a sample: 4D 5A 90 00 ..., and the 4 bytes at offset 0x3C are E0 00 00 00.

Example 4 - Ransomware impact estimate for an Indian hospital. 1.8 TB of records on one file server; the sample encrypts at a measured 90 MB/s in the lab, and the bill for downtime is ₹4.5 lakh per hour.

Example 5 - Evaluating a classifier. An ML-based static detector is tested on 10,000 files: 2,000 malicious, 8,000 benign. It flags 1,860 of the malicious and 120 of the benign.

AspectStatic analysisDynamic analysis
Sample executedNoYes
Code coverageAll branches present in the fileOnly the path actually taken
Defeated byPacking, obfuscation, encryptionAnti-VM, anti-debug, trigger conditions, long sleeps
Reveals C2 and configOnly if unencryptedYes, after runtime decryption
Risk to analystLowHigh - needs isolation and snapshots
Typical toolsGhidra, IDA, PEStudio, strings, YARACuckoo/CAPE, Procmon, Wireshark, x64dbg, Volatility
Speed for triageSlower (manual)Minutes (automated sandbox)
ToolPurposeNotes
GhidraDisassembler + decompilerFree, scriptable (Java/Python), good C pseudocode
IDA Pro / Binary NinjaDisassembler + decompilerCommercial; IDA is the industry reference
x64dbg / OllyDbgUser-mode debuggerUnpacking, patching, breakpoints on APIs
WinDbgKernel debuggerRootkits, drivers, crash dumps
CAPE / CuckooAutomated sandboxBehaviour report, PCAP, config extraction
Volatility 3Memory forensicsFileless and injected-code detection
PEStudio / pefilePE inspectionImports, entropy, signature, resources
YARASignature matchingScales analysis into detection
dnSpy / jadx.NET and Android decompilersNear-source recovery

Where it is used

Interview questions

Common mistakes

Related topics

Digital forensics · Incident response and threat hunting · Threat intelligence and MITRE ATT&CK · Security operations: SOC and SIEM · Operating systems and memory management · Assembly language and computer architecture

Open in the Knowledge reader →Find jobs →