4

问候,所以。

我有一些代码尝试使用 gcc 进行编译,但我的尝试遭到了挫败。任何更精通的人可以帮助我解决这个问题,也许我缺少一些东西。

我正在 Linux Kitchen 2.6.28-15-generic #49-Ubuntu SMP Tue Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linux 上编译此代码。

int
main(void)
{
    __asm__(
            "xorq %rdx,%rdx"
            "movq $0x68732f6e69622fff, %rdx"
            "shr $0x8, %rbx"
            "push %rbx"
            "movq %rsp,%rdi"
            "xorq %rax,%rax"
            "pushq %rax"
            "pushq %rdi"
            "movq %rsp,%rsi"
            "mov $0x3b, %al"
            "syscall"
            "pushq $0x1"
            "pop %rdi"
            "pushq $0x3c"
            "pop %rax"
            "syscall"
    );

    return 0;
}

返回的错误是:

$ gcc -o shellcode shellcode.c
shellcode.c: Assembler messages:
shellcode.c:4: Error: bad register name `%rdxmovq $0x68732f6e69622fff'

谢谢大家。

4

1 回答 1

9

您需要将换行符 ( \n) 放入引用的内联程序集中。否则,它认为

xorq %rdx,%rdx
movq $0x68732f6e69622fff, %rdx

是真的

xorq %rdx,%rdxmovq $0x68732f6e69622fff, %rdx

所以前两行(等等)应该更像这样:

"xorq %rdx,%rdx\n"
"movq $0x68732f6e69622fff, %rdx\n"
于 2009-08-31T23:43:34.237 回答