Before we can overwrite a library function or leak one to beat ASLR, we need to understand how a program reaches a library function in the first place. That path runs through two tables the linker builds into every dynamically-linked binary: the PLT and the GOT. This page is the reference for both; later challenges (GOT overwrites and ret2plt) assume you have read it.
There are two ways a binary can be linked to the libraries it uses. Static linking compiles the library functions directly into the binary. Dynamic linking leaves the library out and uses the functions from a separate file (like libc) at runtime.
Dynamic linking is by far the most common. It keeps the binary small for distribution and avoids shipping a copy of libc with every program — every system already has one. The catch is that the binary no longer knows where its library functions live: libc is a separate file, loaded wherever the loader decides to put it. The binary needs a way to find system, printf, and friends at runtime. That is the job of the PLT and the GOT.
Consider the most basic program: Hello World. It calls printf, which is declared in the header stdio.h but defined in libc. At compile time the linker is happy to accept the call because the header exists, but the real address of printf is unknown until the program runs and libc is loaded.
Two tables bridge that gap:
printf@plt.libc function once it has been resolved. The GOT is a run-time construct — it gets filled in as the program executes.The GOT uses lazy binding: a function's real address is only resolved the first time it is called. Before that first call, the GOT entry points back into the PLT, at the resolver stub. On the first call the resolver runs, looks up the function's true address in libc, writes it into the GOT entry, and jumps there. Every call afterward reads the now-filled GOT entry and jumps straight to libc.
In GDB you can read the GOT directly with the got command. Before a function's first call, its GOT entry points back into the PLT (the resolver); after the first call it points into libc.
Two properties of these tables make them a recurring target:
printf actually jumps to win. That is a GOT overwrite.libc. Each resolved entry is a live libc address. If you can leak one, you can subtract its known offset and recover the libc base — the key to beating ASLR. Because the GOT lives in the binary (constant offset when PIE is off or defeated), you always know where to read.The only protection specific to the GOT is RELRO (RELocation Read-Only). It comes in three levels:
checksec reports which level a binary uses. Partial RELRO — the common case — is exactly what makes GOT overwrites possible, as we'll see next.