Skip to content
Tutorials Center
My learning

Topics

Lesson 23 of 37 ยท Packers and Obfuscation

Packers and Protectors: Why Samples Hide Their Code

Learn what packers, crypters and protectors do, the clues they leave in imports, sections and strings, and see a harmless packing model demonstrated in Python.

When you run strings on a sample and see almost nothing, or a disassembler shows a tiny function followed by a huge block of unreadable bytes, you have probably met a packer. A packer compresses or encrypts the real program and wraps it with a small stub that restores it in memory at run time. Legitimate software uses packers too, to shrink downloads or to discourage casual copying, but malware authors use them for a different reason: to defeat signatures, hide strings and imports, and slow analysis.

This lesson explains how packing works and how to recognise it. The code is a harmless model: it "packs" a plain text message with standard compression and shows what that does to what static tools can see. There are no real packers, no real malware and no instructions for building evasive samples.

What a packed file contains

Stub Small code that unpacks.
Payload The real program, hidden.
Few imports Only what the stub needs.

The real code appears only in memory.

1 / 2

How packing works

The life cycle of a packed program is the same in nearly every family:

  1. At build time the original executable is transformed (compressed, encrypted, or both) and stored as data inside a new executable.
  2. The new file's entry point is the stub, not the original code.
  3. When started, the stub allocates memory, decodes the payload there, fixes up imports and relocations, and then jumps to the original entry point (OEP).
  4. From that jump on, the original program runs as if it had never been packed.

The jump from stub to payload is called the tail jump. It is the moment analysts try to catch with a debugger, because at that instant the full program sits decoded in memory. The next lessons, entropy and sections and the chapter on dynamic analysis, build on that idea.

Terms overlap in everyday use:

  • A packer mainly reduces size; well-known commercial and open-source examples exist and are used legitimately.
  • A crypter mainly hides content from antivirus by encrypting the payload, often with a key held in the stub.
  • A protector adds anti-debugging, virtualisation of code, integrity checks and licence logic.
  • A loader or dropper is a different idea: a program whose job is to deliver another one, whether or not it is packed.

Clues that a file is packed

None of these alone proves anything, but together they are persuasive:

Clue What you see
Few imports Only LoadLibrary, GetProcAddress, VirtualAlloc, VirtualProtect or similar
Odd section names UPX0, .aspack, random names, or one section holding almost the whole file
Sections that are both writable and executable The stub writes code and then runs it
Raw size 0, virtual size large A section that is empty on disk but large in memory is where the payload will be written
High entropy Compressed or encrypted data looks random; see the next lesson
Few readable strings Most text is inside the encoded payload
Entry point in the last section The stub was appended or the payload stored first

Common loader behaviour such as VirtualAlloc followed by VirtualProtect to make memory executable is also worth noting; the behavioural lesson puts such API sequences together.

A harmless packing model

The stand-in below does the compression part of packing on a plain text message, and then compares what a simple string scanner and a byte counter can learn from the original and from the packed form. It uses Python's zlib and a one-byte XOR "key" for a toy encryption layer. This is a teaching model of the idea only.

Python What packing does to strings

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 input()), it gets the next line from this box.

The packed blob is much smaller, contains no meaningful strings and no recognisable URL, and still decodes back to the exact original. That is why a signature or a string search written for the unpacked program finds nothing in the packed one. It is also why unpacking, not clever searching, is the real answer to packing.

Spotting the stub's shape

Analysts also read the structure of the file. The second stand-in applies a few heuristics to made-up section records, the kind of table a PE viewer prints, and scores how "packed" the file looks. The numbers and names are invented.

Python Score packing clues in section headers

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 input()), it gets the next line from this box.

A score is a triage aid, not a verdict. Some legitimate installers, game protections and .NET obfuscators also trip these rules, and some careful malware avoids them. Treat the result as a reason to look harder.

Only unpack and run samples inside the isolated lab described in the safe lab chapter. Unpacking executes attacker code, so a mistake in the tail-jump step can run the real payload on your machine.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the tail jump in a packed program?

    After the stub decodes the payload in memory, a jump transfers control to the original entry point.
  2. 2. Which clue suggests packing?

    Space that is empty on disk but large in memory, and both writable and executable, is where a stub writes the payload.
  3. 3. Why does strings often show almost nothing for a packed sample?

    The readable text is part of the encoded payload and only appears after unpacking.
  4. 4. Which statement is correct?

    Legitimate software is packed and protected too, and packing can be defeated by unpacking.

Summary

  • A packer compresses or encrypts the program; a stub restores it in memory and jumps to the original entry point.
  • Crypters focus on hiding from antivirus; protectors add anti-analysis tricks; droppers deliver other programs.
  • Clues: few imports, odd or RWX sections, raw size 0 with large virtual size, high entropy, few strings.
  • Static signatures written for the unpacked program miss the packed one.
  • Packing hints are triage, not proof; legitimate software uses them too.
  • The Python code here is a harmless model of packing for teaching.

Next: Entropy and Section Analysis