dVN*_*VNE 5 assembly openbsd bsd freebsd netbsd
我编写了这个程序,应该以 exitcode 44 退出:
// prog.S
#include <sys/syscall.h>
.text
.globl _start
_start:
subl $8, %esp
pushl $44
pushl $0
movl $SYS_exit, %eax
int $0x80
Run Code Online (Sandbox Code Playgroud)
我编译了
$ cc prog.S -nostdlib -o a.out
Run Code Online (Sandbox Code Playgroud)
并运行
$./a.out
Run Code Online (Sandbox Code Playgroud)
在 FreeBSD 13.0-RELEASE i386 (clang 11.0.1) 上这样做效果很好。事实上,可执行文件运行并且程序的退出代码应该是 44。
但是,在 OpenBSD 7.0 GENERIC.MP#5 i386(clang 版本 11.1.0)和 NetBSD 9.2 i386(gcc 7.5.0)上执行相同操作时,内核拒绝执行代码,并将其传递给 shell,其中课程失败:
openbsd$ ./a.out
./a.out[1]: syntax error: `(' unexpected
Run Code Online (Sandbox Code Playgroud)
奇怪的是,该文件说它是一个 ELF 二进制文件,因此通常应该由内核执行
openbsd$ file a.out
a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped
Run Code Online (Sandbox Code Playgroud)
甚至 objdump 也会打印预期打印的内容
openbsd$ objdump -d a.out
a.out: file format elf32-i386
Disassembly of section .text:
00001184 <_start>:
1184: 83 ec 08 sub $0x8,%esp
1187: 6a 2c push $0x2c
1189: b8 01 00 00 00 mov $0x1,%eax
118e: 6a 00 push $0x0
1190: cd 80 int $0x80
Run Code Online (Sandbox Code Playgroud)
知道我做错了什么吗?
PS:使用 main 更改 _start 并在不使用 -nostdlib 的情况下进行编译在 OpenBSD 和 NetBSD 上都可以正常工作
我发现 OpenBSD 检查 .section“.note.openbsd.ident”、“a”。如果它不存在,则不会执行该文件。如果我用 main 替换 _start 并在没有 -nostdlib 的情况下链接,则可以在 libc 中找到 .note.openbsd.ident。对于 NetBSD 来说也是如此。
要了解更多信息,请访问https://www.exploit-db.com/papers/13219
归档时间: |
|
查看次数: |
300 次 |
最近记录: |