The code that I am struggling with is shown below:
section .text
global _start
_start:
xor eax, eax
push eax
push 0x68732f2f ;This is equivalent to push '//sh'
push 0x6e68622f ;This is equivalent to push '/bin'
mov ebx, esp
push eax
push ebx
mov ecx, esp
xor edx, edx
mov al, 0x0b
int 0x80
mov eax, 0x01
xor ebx, ebx
int 0x80
Basically, what this code supposedly does is that it slips some null-terminated string "/bin/sh" into the memory (specifically, the top of the stack), along with a char *[2], which holds the address of the aforementioned string and a null character, then it invokes system call execve() to spawn a shell.
The problem I am facing is that after I compiled and linked it by typing "nasm -f elf code.asm" and "ld -m elf_i386 -o code code.o", it did not seem to work properly.
In case it matters, the linux distribution I am running is 64-bit Ubuntu version 14.04.
Hope that you guys could help me out here. Sincere thanks in advance!
来源:https://stackoverflow.com/questions/33998397/why-does-this-assembly-code-issue-segmentation-fault-warning