0
我在程序集中編寫了一個簡單程序,該程序應該調用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偉大的想法,我試過了,但它仍然崩潰。 – John