0

我正在研究一个旧的 CTF 问题,我认为我已经通过覆盖__free_hook地址system/bin/sh作为参数传递来解决该问题。但是当我尝试执行时,system(/bin/sh)我从/bin/sh. __libc_start_main过去的经验表明我缺少与 libc 版本或 ELF 解释器相关的内容,但我不确定是什么。

下面是一个最小的可重现示例:


我没有 CTF 问题的来源,所以我编写了一个简短的程序来完成分配和释放内存的重要部分。

例子.c

#include <stdlib.h>
#include <stdio.h>

int main(void) {
    void *chunk = malloc(16);
    free(chunk);
    puts("completed");
}

这个 gdbscript 模拟了漏洞利用的效果

脚本

# Set the required environment variables
set exec-wrapper env 'LD_PRELOAD=./libc.so.6'
# When system forks, follow the child
set follow-fork-mode child

tbreak free
run

# Mimic the results of the exploit
set {void *}&__free_hook=&system
set {char [8]}$rdi="/bin/sh"
continue

编译和段错误:

# The problem was distributed with its own libc, and I copied the correct interpreter
# into the same directory
[user@host tmp]$ ls
example.c  gdbscript  ld-2.27.so  libc.so.6
[user@host tmp]$ ./libc.so.6
GNU C Library (Ubuntu GLIBC 2.27-3ubuntu1) stable release version 2.27. # matches the interpreter
# <output snipped>
[user@host tmp]$ gcc -Xlinker -I./ld-2.27.so example.c -o example
[user@host tmp]$ gdb -x gdbscript ./example # segfaults
4

0 回答 0