【发布时间】:2014-06-18 00:02:56
【问题描述】:
我正在用汇编语言编写一个简单的程序,它应该调用setreuid(0,0),然后调用exit()。这是我的代码:
section .text ; start code section of assembly
global _start
_start:
xor eax, eax ; setruid call
mov al, 0x46 ; get ready for setreuid system call
xor ebx, ebx ; arg 1 (0)
xor ecx, ecx ; arg 2 (0)
int 0x80 ; interrupt for setreuid
mov al, 0x01 ; prepare for exit call
int 0x80 ; interrupt for exit <---- 0x0804806c
当我通过gdb 运行它时,它会到达0x0804806c,然后它会崩溃并显示以下消息:
0x0804806e 在?? ()
执行不在已知函数内
我是组装新手,如果是菜鸟错误,请见谅。
更新
我已将我在此处发布的内容复制并粘贴到exit.asm。然后我使用以下命令编译了exit.asm:
nasm -f elf exit.asm # elf file format for 32-bit linux
ld -o exit exit.o # link
这会产生程序exit。运行它时,我得到以下信息:
****@debian:~/shellcode$ ./exit
Segmentation fault
****@debian:~/shellcode$
【问题讨论】:
-
您应该在第二个系统调用之前将
eax重新归零。第一个系统调用的返回值在那里,如果它设置了mov al, 0x01不重置的任何位,您最终将调用其他调用。 -
为什么不只是
mov eax, 0x46和0x01? -
@AndrewMedico 好主意,我试过了,但它仍然崩溃。
-
@WilliamAndrewMontgomery 我试过了,但仍然出现分段错误。
-
那么你做错了什么,例如没有运行你的程序的当前版本。