ASLR (Address Space Layout Randomization) is a popular security feature that randomizes the location of the library file. ASLR is a kernel protection feature, meaning that it is turned on or off for the entire system.
This is the equivalent of PIE for libc. This means you cannot hard-code libc addresses into your exploit (such as system or binsh).
echo 2 | sudo tee /proc/sys/kernel/randomize_va_spaceASLR can be turned off using:
echo 0 | sudo tee /proc/sys/kernel/randomize_va_spaceThis is useful for debugging. However, just be mindful that you're not hardcoding addresses in your exploit until the libc base address is leaked.
The exploit for this challenge is slightly different than that of the PIE exploit. Using a format string vulnerability isn't as simple as you'd think for two main reasons:
libc versions: Different systems run different libc versions, and unless the specific libc version is provided, the offsets for the return pointers can vary.libc address, you might leak an old address used by a function that has already returned.Instead, we look to the GOT (Global Offset Table). The GOT is a table of addresses that are used by the binary. GOT addresses are valid for the entire execution and don't become invalid when a function returns. It is the most reliable way to determine the address of a libc function.
If you can read an address from the GOT, you can get the actual address of where that function resides in memory, which provides the libc base address.
While ASLR will cause the libc base address to change between different program executions, the offset from the libc base to a particular function remains consistent for a given libc version. So, if you can leak one libc function address from the GOT, you can reliably calculate the address of other functions or gadgets in libc.
Recall from The PLT and GOT that every dynamically-linked function is called through its GOT entry, and that once resolved, each GOT entry holds the function's real address inside libc.
That is exactly what we need. The GOT lives inside the binary, so it sits at a constant offset from the binary's base — and if PIE is disabled (or already beaten), we know its absolute address. Reading a single resolved GOT entry hands us a live libc address; subtracting that function's known offset gives us the libc base, and from the base we can reach system, /bin/sh, or any gadget we need. That is how a GOT leak beats ASLR.
The most common exploit built on this is the ret2plt, covered at the end of this section.
libc base addresses are also multiples of 0x1000, for the same reason as PIE. This means that you can check the base address of libc and see if it's a multiple of 0x1000. If it's not, you most likely leaked the address incorrectly.