pwn加載題目給定的so
阿新 • • 發佈:2018-06-09
return bug TP head gre one PE 是否 lur
pwn加載題目給定的so
from pwn import *
import sys, os
def change_ld(binary, ld):
"""
Force to use assigned new ld.so by changing the binary
"""
if not os.access(ld, os.R_OK):
log.failure("Invalid path {} to ld".format(ld))
return None
if not isinstance(binary, ELF):
if not os.access(binary, os.R_OK):
log.failure("Invalid path {} to binary".format(binary))
return None
binary = ELF(binary)
for segment in binary.segments:
if segment.header[‘p_type‘] == ‘PT_INTERP‘:
size = segment.header[‘p_memsz‘]
addr = segment.header[‘p_paddr‘]
data = segment.data()
if size <= len(ld):
log.failure("Failed to change PT_INTERP from {} to {}".format(data, ld))
return None
binary.write(addr, ld.ljust(size, ‘\0‘))
if not os.access(‘/tmp/pwn‘ , os.F_OK): os.mkdir(‘/tmp/pwn‘)
path = ‘/tmp/pwn/{}_debug‘.format(os.path.basename(binary.path))
if os.access(path, os.F_OK):
os.remove(path)
info("Removing exist file {}".format(path))
binary.save(path)
os.chmod(path, 0b111000000) #rwx------
success("PT_INTERP has changed from {} to {}. Using temp file {}".format(data, ld, path))
return ELF(path)
#example
elf = change_ld(‘./echo2‘, ‘./ld.so‘)
p = elf.process(env={‘LD_PRELOAD‘:‘./libc.so.6‘})
#後續步驟接著寫
先用strings libc.so.6 | grep GLIBC 查看自己的glibc是否兼容題目給的libc庫
(libc.so.6 是我將題目給的改名的)
註意ld.so 是從安裝的glibc 例如按照我的blog(編譯glibc)的目錄是/usr/glibc223/lib裏的ld2.23.so拷貝出來的並且改了下名 libc.so.6 則是題目給的libc庫改名的
此腳本需要pwn題 ld.so libc.so.6在一個文件夾
寫的好像不太清楚,有問題就問 這破事煩了我兩天才給搞好,真是為難新手
參考
https://bbs.pediy.com/thread-225849.htm
pwn加載題目給定的so