How to analyze shellcode without running it
Shellcode is position-independent machine code with no file format around it: no headers, no import table, nothing that says where it starts or which CPU it is for. That makes it awkward to study. You can’t double-click it, and a disassembler on its own often shows only the first few instructions: most shellcode decodes itself, or finds the Windows functions it needs at run time, so the interesting part isn’t in the bytes you have.
There are three ways to look inside.
Read it: disassembly
A disassembler such as Capstone, Ghidra or IDA turns the bytes into instructions. It is safe and complete in one sense: every byte is shown. But it can’t follow a decoder, so an encoded payload stays encoded, and data mixed into the code throws a linear disassembly off track.
Run it: a debugger and a loader
On a Windows machine you can load the bytes into executable memory with a small loader and step through them in a debugger. You see exactly what happens on that machine, including the real responses from the network. It is also the riskiest option: the code really runs, so it belongs on an isolated analysis machine with no route to anything you care about.
Emulate it
An emulator runs the instructions on a software CPU and answers the Windows API calls itself. Speakeasy, from Mandiant’s FLARE team, is built for exactly this: it emulates the CPU with Unicorn, lays out a Windows process around the shellcode, and records every API call with its decoded arguments. Nothing runs on a real CPU or a real Windows, file writes go to an emulated file system, and the network is simulated.
Emulation gets you most of what running it would, without the risk:
- the API calls, in order, with their arguments, so a resolved
LoadLibraryAorInternetOpenUrlAshows up by name even when the code only ever had a hash of it; - the hosts, URLs, files, registry keys and commands it uses;
- code it decodes and runs, as a separate stage you can disassemble;
- which instructions ran, so a disassembly can tell code from data.
Reading the report
Shellcode Emulator runs Speakeasy on what you paste and shows the result.
- The verdict says whether the code returned or stopped, and where. A stop isn’t a failure of the analysis: shellcode often ends in a crash once it has done its work, or when it waits for something the emulator doesn’t provide.
- The byte map shows each input byte. Amber bytes ran. Cyan bytes were rewritten by the code itself, which is what an in-place decoder does. Click a byte to see its instruction.
- Summary lists what matters first: network, processes, files, registry and loaded libraries.
- Calls is the full timeline of API calls.
- Code is the disassembly, marked with what ran, plus each stage the code wrote and ran.
- Memory holds the stages and other memory the code filled, as hex, to download for a closer look.
When emulation stops early
- It stopped on the first instruction or two: the architecture or the start offset is probably wrong. Try x86 and x64 (Auto does both), or start where the code begins if the bytes have something in front of it.
- It read or jumped to an address that isn’t mapped: the code expected something from its environment, such as a register value set by the loader that normally runs it, or a structure the emulator doesn’t model.
- It called an API the emulator doesn’t implement: the report names it. Everything before it is still valid.
- It ran until the time limit: a long decoding loop, a sleep loop, or code waiting for a reply that never comes.
- Interrupt 0x80: the code makes Linux system calls. This emulator runs Windows shellcode.
What emulation can’t tell you
The emulator answers DNS and HTTP requests with made-up addresses and placeholder content. A stager that downloads its next stage gets that placeholder instead of the real payload, so the report shows where it would have connected, not what it would have received. Code that checks its environment closely enough can also tell it isn’t on a real machine and behave differently. When the stakes are high, treat the emulator’s report as the map and confirm the details on an isolated analysis machine.