Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 37 ยท Static Analysis

Extracting Strings

Learn to extract ASCII and UTF-16 strings from binaries, filter them into URLs, IP addresses, paths and registry keys, and judge what strings do and do not prove.

Programs are full of text: error messages, file paths, URLs, command lines, registry keys, library names. Extracting the printable strings from a sample is one of the quickest ways to guess what it does, and it needs nothing more than reading bytes. A single string such as a web address or a ransom message can tell you more in a minute than an hour of staring at a hex dump.

The tools are simple (strings on Linux, Sysinternals Strings on Windows, and FLOSS, which also decodes some obfuscated strings), and we can write the core of one ourselves.

ASCII and Unicode strings

Windows programs use two common encodings:

  • ASCII (one byte per character): h t t p is stored as 68 74 74 70.
  • UTF-16 little-endian ("wide" or "Unicode" strings): each character takes two bytes, so http is 68 00 74 00 74 00 70 00.

A naive tool that looks only for ASCII misses all the wide strings, which Windows API calls favour. Always search for both. A minimum length (usually 4 or 5 characters) keeps random binary noise from filling the output.

Python Write a strings extractor

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 UTF-16 path would have been invisible to a plain ASCII search. Notice also that real output contains lots of junk strings: part of the skill is skimming past them.

Sorting strings into indicators

A long strings list is overwhelming, so analysts filter it with patterns. Useful categories:

Category Example Why it matters
URL / domain http://update.example.test/gate.php Network indicator, possible C2
IP address 203.0.113.7 Network indicator
File path C:\Users\Public\upd.exe Drop location
Registry key ...\CurrentVersion\Run Persistence
Commands cmd.exe /c, powershell -enc Execution method
API names VirtualAlloc, CreateRemoteThread Capabilities (see Imports)
Mutex / pipe names Global\q7x... Single-instance check, family marker
User-agent text Mozilla/5.0 ... Fixed values make detection rules
Messages "Your files are encrypted" Purpose
Debug paths C:\dev\proj\Release\x.pdb Author clues
Python Classify strings into indicator types

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.

In a real case you would send the url, ip, registry, path and mutex groups to your notes as candidate indicators, then check them with dynamic analysis.

Obfuscated strings

If a sample shows almost no readable strings, that is itself a finding. Authors hide strings so tools cannot read them:

  • XOR or custom encoding: each byte is combined with a key and decoded at run time.
  • Stack strings: the text is built one character at a time by code, so it never appears contiguously in the file.
  • Base64 or hex text: readable but meaningless until decoded.
  • Packing: the whole program is compressed or encrypted (Packers and Obfuscation comes later).

Here is a simple demonstration of why XOR hides strings, and how a defender recovers them when the key is a single byte. This is an analysis technique, applied here to a harmless sentence.

Python Recover a single-byte XOR string

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 brute-force guess works only for trivial schemes, but it is a classic first attempt, and FLOSS automates similar tricks.

What strings cannot tell you

  • A string in a file does not prove the code uses it. Programs may carry unused text.
  • Attackers plant decoy strings (fake error messages, other families' names) to mislead.
  • Missing strings do not prove innocence: they may be encrypted.
  • Strings give hypotheses; confirm them with behaviour or code.

Practical tips

  • Run both ASCII and UTF-16 extraction, with a minimum length of 5 or 6 for big files.
  • Keep the offset of interesting strings so you can find the code that references them later.
  • Compare strings between several samples; shared odd strings reveal a family.
  • Defang any URL before pasting it into a note.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why should a strings tool search for UTF-16 as well as ASCII?

    Many Windows API strings are wide characters, which a plain ASCII scan misses.
  2. 2. A sample has almost no readable strings. What is a reasonable conclusion?

    Few strings is a meaningful finding: authors hide text with encoding, encryption or packing.
  3. 3. Which string is the most likely persistence indicator?

    The Run key is a common autostart location in the Windows registry.
  4. 4. What can strings NOT prove?

    Unused or decoy strings exist, so you must confirm behaviour another way.

Summary

  • Extract both ASCII and UTF-16 strings with a sensible minimum length.
  • Classify strings into URLs, IPs, paths, registry keys, commands, APIs, mutexes and messages.
  • Few strings suggests obfuscation or packing; simple XOR can be brute-forced.
  • Strings are hints, not proof: decoys and unused text exist.
  • Keep offsets and defang indicators.

Next: The PE File Format