Table of Contents
IronForgeCyber
Courses
Resources
Blog
Log In


IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. re-static-analysis
  3. static-linked
13 min read

Statically-Linked Binaries

In the last lesson the imports saved us. With every function name gone, fgets, strlen and puts were still there, and we rebuilt the program around them. Those names exist because a dynamically linked program borrows its C library from the system and has to say which functions it wants.

A statically linked program does not borrow. The linker copies every library function it needs into the file, so there is nothing to ask the system for and no list of names. Strip a binary like that and you have hundreds of functions with no labels at all, of which the author wrote a handful. This lesson is about finding the handful.

The Program

This lesson's chall asks for a token:

chall
$ echo 123 | ./challToken: Invalid.

It is a tiny program. The source in the download is twenty lines long, with a main and one helper. file shows what is different about it:

$ file challchall: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=0b82645f056d5cc9e4c2677620f76385c3bdae42, for GNU/Linux 3.2.0, stripped

statically linked and stripped, with no mention of an interpreter. For comparison, build the same source the ordinary way and look at the sizes:

$ gcc -std=gnu17 -no-pie -o dynamic source.c$ wc -c chall dynamic726880 chall 12792 dynamic739672 total

The static build is more than fifty times larger, and none of the extra is the author's code. It is printf, fgets and puts, plus everything those functions call in turn, plus the machinery for files, memory, locales and errors that a C library carries. You will often be able to guess that a binary is static from its size alone: a simple command-line tool that weighs most of a megabyte is carrying its library with it.

What Is Missing

The tools we have relied on come up empty:

nm
$ nm -D challnm: chall: no symbols

There are no dynamic symbols, because nothing is loaded at run time. There is no PLT either, so the rule from Functions & Calls, that a call into the PLT is a library call, has nothing to work with. A call to printf and a call to the author's helper look identical: a call to an address in the same file.

Import chall into Ghidra and the Symbol Tree confirms it. Imports is empty, and Functions holds 742 entries, nearly all of them named FUN_ and an address.

The strings do not help the way they did before, either:

$ strings chall | wc -l4216

The library brought its own strings with it: error messages, locale names, format fragments. The author's three or four are in there somewhere among four thousand. strings chall | grep Token still works if you know what to look for, and following the cross-reference from a known message is still a good way in. But browsing the list is over.

From the Entry Point to main

One thing is unchanged. The file still has an entry point, the startup code is the same as ever, and it still hands main to the function that starts the C library:

Ghidra
1void processEntry entry(undefined8 param_1,undefined8 param_2,undefined1 param_3)
2{
3  undefined1 auStack_8 [8];
4

Compare this with the entry from the last two lessons. The shape is identical: one call, seven arguments, then a loop that never runs. The only difference is that the function being called has no name. We do not need one. We know this code, so FUN_00404510 is __libc_start_main, and its first argument, FUN_00401c1b, is main. Rename both.

That is two functions out of 742 identified in a minute, and one of them is the one we wanted.

Recognizing Library Functions

Ghidra
1undefined8 FUN_00401c1b(void)
2{
3  undefined4 uVar1;
4  int iVar2;
5

main calls five different functions. In a dynamic binary, four of them would have had names. Here we have to work out which are the library's and what they are. The wrong way to do that is to open one:

Ghidra
1ulong FUN_0040c090(undefined8 param_1)
2{
3  int *piVar1;
4  undefined1 *

That is the first quarter of it. It goes on through locks, buffer pointers and a handful of goto statements, and it calls more functions like itself. This is what production library code looks like once it has been optimized and decompiled. It is hard to read, and reading it would tell us nothing that the manual page does not.

The better way is to identify each function from the outside, using how main calls it.

By How It Is Used

Look at the calls again, as a set of clues:

  • FUN_0040c090 is called with a string and nothing else, at the two places where the program prints a line and stops. A function that takes one string and prints it with a newline is puts. That monster above is puts.
  • FUN_00405b90("Token: ") is also called with a string, but the output had no newline after Token:. It behaves like printf.
  • FUN_0040bd00(local_28,0x20,PTR_DAT_004a86d8) takes a buffer, the size of that buffer, and a pointer to some global, and its result is tested against zero. A buffer, its size and a stream: that is the argument list of fgets, and fgets returns a null pointer on failure.
  • FUN_00404a10(local_28) takes the buffer that was just filled and returns a number that goes into the check. Something that turns text into a number.

The last one is small enough to open:

Ghidra
1void FUN_00404a10(undefined8 param_1)
2{
3  FUN_00404fd0(param_1,0,10);
4  return

It passes its argument on with two more: a zero and the number 10. A function taking a string, a null pointer and a base of 10 is strtol, and the C library's atoi is exactly this one-line wrapper around it. So FUN_00404a10 is atoi. Ghidra shows it as void for the reason we met in Functions & Calls: the result passes straight through in rax.

We named four library functions without understanding the inside of any of them. The method is the one you would use on a stranger's code in any language: look at what goes in, what comes out, and what the program does around the call. Running the program helps too. We knew Token: appears without a newline and Invalid. with one because we ran it.

By System Calls

Sometimes the arguments are not enough. A second kind of evidence sits at the very bottom of the library, where it talks to the operating system.

A program cannot print, read or open a file on its own. It asks the kernel, using the syscall instruction, with a number in eax that says which service it wants. A dynamic binary has no syscall instructions of its own, because they are all inside the shared C library. A static binary has them all:

$ objdump -d -M intel --no-show-raw-insn chall | grep -c syscall121

The numbers are fixed by Linux and listed in any syscall table. A few are worth knowing by heart:

eaxSystem callWhat it does
0readRead from a file or input
1writeWrite to a file or output
2openOpen a file
3closeClose a file
60exitEnd the program

A function that loads 1 into eax and executes syscall is writing output, whatever it is called. Whatever calls that function is a step up, and after a few steps you reach something like puts. Reading upward from system calls is slower than reading the arguments, but it always works, because a program cannot do anything visible without them. System Calls in Assembly 101 covers the mechanism.

Library Signatures

Identifying functions one at a time is fine for the four that main calls. It does not scale to 742. For that there are library signatures: databases of the byte patterns of known library functions, which a tool can match against a binary to name functions automatically. Compiled code for strlen from a given version of a given library is the same bytes in every program that links it, so a match is good evidence.

IDA calls its version FLIRT. Ghidra's is Function ID, and it runs as part of the default analysis. When it matches, functions come out of analysis already named, and a static binary becomes nearly as easy as a dynamic one.

The catch is coverage. A signature database only knows the library versions someone built it from. This chall was linked against a recent C library that Ghidra's bundled databases do not include, and Function ID recognized almost nothing. That is what you saw in the Symbol Tree. It is a common outcome with a new or unusual library, and the remedy is more signatures: Ghidra can build a Function ID database from any library you have a copy of, and people publish ready-made ones.

So try signatures first, because when they work they save hours. When they do not, the manual methods above are what is left.

The Author's Code

Four of the five calls in main are accounted for. The remaining one is ours:

Ghidra
1bool FUN_00401c05(int param_1)
2{
3  return param_1 == 0x14b;
4}

It is three instructions long and it sits right next to main in memory, at 0x401c05 against 0x401c1b. That is a useful clue in its own right. The linker lays out a program's own object files together and the library's after them, so the author's functions cluster in one small address range, usually near main. The library functions main called were all far away, at 0x404a10 and above.

The source of this function says token * 3 + 7 == 1000. Ghidra has solved the equation for us and shows the only value that passes, 0x14b:

$ printf '%d\n' 0x14b331$ echo 331 | ./challToken: Valid.

Knowing When to Stop

The work in this lesson was mostly deciding what not to read. Out of 742 functions, we opened four: entry, main, the atoi wrapper and the check. We glanced at a fifth and backed out.

Some signs that you have wandered into library code and should back out:

  • The function is long, full of goto, and touches global structures through many fixed offsets.
  • It mentions locks, thread-local storage (Ghidra shows this as in_FS_OFFSET), or error codes.
  • It is called from dozens of places.
  • It sits far from main in the address space.
  • Nothing in it relates to what the program is for.

When you see these, stop, go back up to the caller, and ask what the function must be from how it is used. Give it a name, even a tentative one, and carry on. The author's logic is what you came for, and it is almost always small and near main.

Summary

  • A static binary contains its C library. It is large, has no imports and no PLT, and after stripping has no names at all.
  • The entry point still leads to main: the startup code is the same, so the function it calls is __libc_start_main and the first argument is main.
  • Identify library functions from the outside, by their arguments, their results and the program's visible behavior. Do not read them.
  • System call numbers identify the lowest-level functions with certainty.
  • Function ID and FLIRT name library functions automatically when they have signatures for your library version. Try them first.
  • The author's code is small and sits together, usually near main.

Next is Obfuscation, where the code is easy to find and has been written to be hard to follow.

5 FUN_00404510(FUN_00401c1b,param_2,&param_3,0,0,param_1,auStack_8);
6 do {
7 /* WARNING: Do nothing block with infinite loop */
8 } while( true );
9}
long
lVar3
;
6 undefined8 uVar4;
7 undefined1 local_28 [32];
8
9 FUN_00405b90("Token: ");
10 lVar3 = FUN_0040bd00(local_28,0x20,PTR_DAT_004a86d8);
11 if (lVar3 == 0) {
12 uVar4 = 1;
13 }
14 else {
15 uVar1 = FUN_00404a10(local_28);
16 iVar2 = FUN_00401c05(uVar1);
17 if (iVar2 == 0) {
18 FUN_0040c090("Invalid.");
19 }
20 else {
21 FUN_0040c090("Valid.");
22 }
23 uVar4 = 0;
24 }
25 return uVar4;
26}
puVar2
;
5 undefined *puVar3;
6 int iVar4;
7 long lVar5;
8 long lVar6;
9 ulong uVar7;
10 undefined *puVar8;
11 long in_FS_OFFSET;
12
13 lVar5 = thunk_FUN_00418e20();
14 puVar3 = PTR_DAT_004a86d0;
15 if ((PTR_DAT_004a86d0[1] & 0x80) == 0) {
16 piVar1 = *(int **)(PTR_DAT_004a86d0 + 0x88);
17 lVar6 = *(long *)(in_FS_OFFSET + 0x10);
18 if ((DAT_004a9000 != '\0') && (*(long *)(piVar1 + 2) == 0)) {
19 *piVar1 = 1;
20 *(long *)(piVar1 + 2) = lVar6;
21 goto LAB_0040c130;
22 }
;
5}