内联汇编错误,阻止 gcc 编译尝试

发布于 2024-08-03 00:55:51 字数 896 浏览 0 评论 0原文

你好,所以。

我尝试使用 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'

谢谢大家。

Greetings, SO.

I have some code which I've made attempts at compiling using gcc, but my attempts have been thwarted. Could anyone more versed assist me with the subject, perhaps there's something I'm missing.

I'm compiling this code on 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;
}

The error that is returned is:

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

Thanks, everyone.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑忘罢 2024-08-10 00:55:51

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

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

确实是

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

所以前两行(依此类推)应该更像这样:

"xorq %rdx,%rdx\n"
"movq $0x68732f6e69622fff, %rdx\n"

You need to put newlines (\n) into your quoted inline assembly. Otherwise, it thinks that

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

is really

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

So the first two lines (and so on) should be more like this:

"xorq %rdx,%rdx\n"
"movq $0x68732f6e69622fff, %rdx\n"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文