Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 53 ยท Systems and Post-Exploitation Concepts

Static Malware Analysis

Learn how analysts examine a suspicious file without running it: file type, hashes, strings, entropy and packing, PE headers and common tools, using safe harmless samples in a lab.

When a suspicious file arrives (an email attachment, a download flagged by an antivirus, a file found on a compromised server), an analyst has two broad ways to learn what it does. Static analysis examines the file without running it. Dynamic analysis runs it in a controlled environment and watches (the subject of the next lesson, Dynamic Analysis and Malware Lab Setup). Static analysis is safer, faster and always the first step: in a few minutes it can tell you what kind of file you have, whether it has been seen before and whether it is hiding something.

Never open or run a suspicious file on your normal computer. Handle samples only inside an isolated analysis VM with no shared folders and no network, and only if you are authorized to hold them. This lesson uses harmless text and an invented byte sequence, not real malware, so every example is safe to run.

For background on what malware does, read Malware and Social Engineering.

The static workflow

flowchart LR
  A["Receive sample<br/>(isolated VM)"] --> B["Identify file type"]
  B --> C["Hash it and look it up"]
  C --> D["Extract strings"]
  D --> E["Check entropy and packing"]
  E --> F["Inspect headers, imports"]
  F --> G["Form hypotheses<br/>and decide on next step"]

Each step narrows the question. None of them runs the file.

1. File type

Do not trust the extension. A file named invoice.pdf may be an executable. Analysts identify the real type from the magic bytes, the first few bytes of a file that mark its format: MZ (4D 5A) for Windows executables, %PDF for PDFs, PK for ZIP-based files including Office documents, 7F 45 4C 46 (\x7fELF) for Linux executables. Tools such as file perform this check.

2. Hashes

A cryptographic hash (SHA-256 is the standard choice) is a fingerprint of the exact file contents. Hashing lets you identify a known sample by searching reputation services and threat-intelligence databases, share an indicator with colleagues without sharing the file and verify that the file did not change. Changing one byte changes the hash completely, so a hash match proves "the same file"; a miss does not prove the file is new. See Cryptography for Hackers for hashing basics.

3. Strings

Many programs contain readable text: URLs, file paths, registry keys, error messages, commands and function names. Extracting all printable runs of characters ("strings") often reveals a command-and-control address, a mutex name or a ransom note. Analysts look for both ASCII and UTF-16 strings (Windows uses wide characters a lot). Malware authors try to hide strings by encoding or encrypting them, so a file with almost no readable strings is itself a clue.

4. Entropy and packing

Entropy measures randomness on a scale from 0 (all identical) to 8 bits per byte (perfectly random). Normal code and text have moderate entropy; compressed or encrypted data is close to 8. Packers compress or encrypt the real program and attach a small stub to unpack it at run time, to evade signature scanning and slow analysis. A section with entropy above about 7 suggests packing or encryption. Packing is not proof of malice (legitimate software uses it too), but it is a reason to look closer.

5. Headers and imports

Windows executables use the PE (Portable Executable) format. Its headers describe sections (.text for code, .data, .rsrc), the compile timestamp, the entry point and, importantly, the import table, the list of operating system functions the program calls. An import list tells you capabilities: networking functions suggest communication, registry and service functions suggest persistence, process-memory functions suggest injection. A very short import table with only functions to load other functions suggests a packed or dynamically resolved program. Linux binaries have the analogous ELF format.

Tools you will meet

  • file, strings, sha256sum on Linux, and similar built-in utilities.
  • Hex editors to view raw bytes.
  • PE inspection tools such as PE-bear, pestudio and CFF Explorer, or libraries that parse headers.
  • Online reputation lookups by hash (never upload sensitive or private files to public services).
  • YARA, a pattern-matching language for describing and detecting malware families.
  • Disassemblers and decompilers for deeper work, introduced in Reverse Engineering Basics.

A static analysis toolkit in miniature

The invented "sample" below is a small byte buffer made of harmless text. The code identifies the type from magic bytes, computes entropy and extracts strings. It runs in Node and touches no real file.

Node.js Magic bytes, entropy and strings on a harmless buffer

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The first buffer is readable text that happens to begin with MZ, a reminder that magic bytes show claimed format, not safety. The second has high entropy and no useful strings, which is the profile of compressed or encrypted content.

Reading a (simplified) PE header

Real PE headers are specific and long, so the second stand-in parses an invented, much simpler structure with the same idea: fixed offsets, a section table and a check on how suspicious each section looks. Treat it as a model for reading structure, not a real parser.

Node.js Parse a simplified header and flag oddities

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

A section that is both writable and executable and has very high entropy is a classic packed-code signature. In a real analysis this evidence is added to what the strings and imports say before any conclusions.

Limits and good practice

  • Static analysis can be defeated by packing, encryption and obfuscation; then dynamic analysis or unpacking is needed.
  • A clean static result does not mean the file is safe.
  • Keep notes: hashes, timestamps, indicators found, tools and versions. They feed incident response and your report.
  • Defang indicators (for example hxxp:// and example[.]test) when sharing them so nobody clicks by accident.
  • Never upload files containing confidential data to public scanning services.

Resources and anomalies inside executables

A Windows executable (PE file) carries more than code. Its resource section holds icons, images and cursors, dialog boxes and menus, version information and sometimes legal or copyright strings. These help an analyst: a program that claims to be a document viewer but has a stolen vendor icon, wrong company name or no version data deserves suspicion; embedded dialogs may reveal what the program asks users for; and extra resources can hide a second executable.

Check for inconsistencies: a compile timestamp far in the past or future (it can be forged), a timestamp that contradicts the signing date, section names or sizes that do not match the real content, odd entry points, or a PE header that disagrees with the file (all signs of packing or tampering). Typical Windows tools are Exeinfo PE (identifies packers and compilers), PEview (shows header structure) and Sigcheck from Sysinternals (verifies signatures and can submit hashes for lookup). Always handle samples in an isolated lab. See lab setup for malware analysis.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A file named report.pdf begins with the bytes 4D 5A. What is it most likely?

    MZ marks the PE executable format. Extensions are easy to fake, so analysts check magic bytes.
  2. 2. What does very high entropy in a file section usually suggest?

    Compressed or encrypted bytes look random and approach 8 bits of entropy per byte.
  3. 3. What is the main reason to hash a sample?

    A hash is a fingerprint. It identifies the exact file and can be searched in threat intelligence.
  4. 4. Why is static analysis done first?

    Static analysis gives fast context without running the file, but obfuscation can limit what it reveals.

Summary

  • Static analysis studies a file without running it: type, hash, strings, entropy, headers and imports.
  • Magic bytes identify the real file type; hashes identify and share samples.
  • Strings reveal indicators, and a lack of strings suggests obfuscation.
  • High entropy and odd sections hint at packing; PE import tables show capabilities.
  • Work in an isolated VM, defang indicators and remember that a clean result proves little.

Next: Dynamic Analysis and Malware Lab Setup