如何解决如何解决在 CTF 问题中调用 system(/bin/sh) 后发生的段错误?
我正在解决一个旧的 CTF 问题,我认为我已经通过用 __free_hook
的地址覆盖 system
并将 /bin/sh
作为参数传递来解决了这个问题。但是当我尝试执行 system(/bin/sh)
时,在 /bin/sh
中启动 __libc_start_main
时出现段错误。过去的经验表明,我缺少与 libc 版本或 ELF 解释器相关的内容,但我不确定是什么。
下面是一个可重现的最小示例:
我没有 CTF 问题的来源,所以我写了一个简短的程序来完成分配和释放内存的重要部分。
example.c
#include <stdlib.h>
#include <stdio.h>
int main(void) {
void *chunk = malloc(16);
free(chunk);
puts("completed");
}
这个 gdbscript 模拟了漏洞利用的效果
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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。