【问题标题】:GCC assembly language compiler errorsGCC 汇编语言编译器错误
【发布时间】:2015-10-12 08:50:34
【问题描述】:
void main()
{
    __asm__
        (
         "jmp   0x2a    
         popl   %esi
         movl   %esi, 0x8(%esi)
         movb   $0x0, 0x7(%esi)
         movl   $0x0, 0xc(%esi)
         movl   $0xb, %eax
         movl   %esi, %ebx
         leal   0x8(%esi), %ecx
         leal   0xc(%esi), %edx
         int    $0x80
         movl   $0x1, %eax
         movl   $0x0, %ebx
         int    $0x80
         call   -0x2f 
         .string \"/bin/sh\"
         ");
}

我遵循了shellcode 教程,但是当我使用gcc shellcodeasm.c 编译它时,我收到以下错误:

shellcodeasm.c: In function ‘main’:
shellcodeasm.c:5:4: warning: missing terminating " character [enabled by default]
    "jmp 0x2a  
    ^
shellcodeasm.c:5:4: error: missing terminating " character
shellcodeasm.c:6:4: error: expected string literal before ‘popl’
    popl %esi
    ^
shellcodeasm.c:19:4: error: stray ‘\’ in program
    .string \"/bin/sh\"
    ^
shellcodeasm.c:19:13: warning: missing terminating " character [enabled by default]
    .string \"/bin/sh\"
             ^
shellcodeasm.c:19:4: error: missing terminating " character
    .string \"/bin/sh\"
    ^
shellcodeasm.c:20:4: warning: missing terminating " character [enabled by default]
    ");
    ^
shellcodeasm.c:20:4: error: missing terminating " character

我是这方面的新手。

【问题讨论】:

标签: linux gcc compiler-errors x86 inline-assembly


【解决方案1】:

虽然我已将其识别为另一个问题的重复,但您可以通过在每行内联汇编的开头和结尾放置引号并在每个字符串的末尾嵌入换行符来解决此问题:

void main()
{
    __asm__
        (
         "jmp   0x2a\n"
         "popl   %esi\n"
         "movl   %esi, 0x8(%esi)\n"
         "movb   $0x0, 0x7(%esi)\n"
         "movl   $0x0, 0xc(%esi)\n"
         "movl   $0xb, %eax\n"
         "movl   %esi, %ebx\n"
         "leal   0x8(%esi), %ecx\n"
         "leal   0xc(%esi), %edx\n"
         "int    $0x80\n"
         "movl   $0x1, %eax\n"
         "movl   $0x0, %ebx\n"
         "int    $0x80\n"
         "call   -0x2f\n"
         ".string \"/bin/sh\"\n"
         );
}

【讨论】:

  • 谢谢哥们。这些错误消失了,但我收到了一个新错误shellcodeasm.c:4: Error: invalid instruction suffix for 'pop'。感谢您的宝贵时间。
  • @HuangJie 很可能是因为当您看起来正在编写 32 位代码时,您正在使用 64 位编译器编译代码。尝试将 -m32 选项传递给您的 gcc 命令。
猜你喜欢
  • 1970-01-01
  • 2010-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多