WHY does this assembly code issue segmentation fault warning?

杀马特。学长 韩版系。学妹 提交于 2019-12-01 11:29:18

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!