【问题标题】:NASM Not Running Correctly in CNASM 在 C 中未正确运行
【发布时间】:2014-02-03 06:26:15
【问题描述】:

我用 x64 写了一个 NASM 文件:

section .text
        global _start
_start:
        jmp j
r:
        pop rsi
        mov al, 1d
        mov dil, 1d
        mov dl, 13d
        syscall

        xor eax, eax
        mov al, 60d
        syscall

j:      call r
        db "Hello World!",10

编译:

nasm -f elf64 -o TEMP.o file.asm
ld -s -o exec TEMP.o

外壳代码:

\xeb\x10\x5e\xb0\x01\x40\xb7\x01\xb2\x0d\x0f\x05\x31\xc0\xb0\x3c\x0f\x05\xe8\xeb\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x0a

当我执行./exec 时,它会按原样打印“Hello World”。但是,当我把它放在下面的 C 文件中时,它给了我一个分段错误。

另外,当我改变时:

unsigned char shellcode[] = ...

unsigned char * shellcode = ...

我没有任何输出。

C 来源:

#include <stdio.h>
#include <string.h>

unsigned char shellcode[] = "\xeb\x10\x5e\xb0\x01\x40\xb7\x01\xb2\x0d\x0f\x05\x31\xc0\xb0\x3c\x0f\x05\xe8\xeb\xff\xff\xff\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x21\x0a";

int main(){
        printf("Shellcode Length (Bytes): %d\n", strlen(shellcode));
        ((void(*)(void))shellcode)();
        return 0;
}

【问题讨论】:

    标签: c assembly segmentation-fault nasm


    【解决方案1】:

    我相信我已经弄明白了。直到最近我才搬到 Crunchbang。我现在必须指定-z execstack 才能使其工作。感谢任何真正试图给我答案的人!

    【讨论】:

      猜你喜欢
      • 2015-06-01
      • 1970-01-01
      • 2012-05-20
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 2015-05-26
      • 2015-10-03
      • 1970-01-01
      相关资源
      最近更新 更多