【问题标题】:Invalid character '\' in mnemonic助记符中的无效字符“\”
【发布时间】:2020-06-09 04:08:20
【问题描述】:

我是 asm/shellcode 新手,在编译 ParrotOS 中作为模板包含的示例 shellcode 时遇到问题。

我浏览了以下主题,但无法解决我的问题:

Assembly error: invalid character '$' in mnemonic

Invalid character (0xe2) in mnemonic

我尝试使用as 命令而不是gcc,但是我得到了同样的错误。

char code[] = 

    "\xe9\x1e\x00\x00\x00"  //          jmp    8048083 <MESSAGE>
    "\xb8\x04\x00\x00\x00"  //          mov    $0x4,%eax
    "\xbb\x01\x00\x00\x00"  //          mov    $0x1,%ebx
    "\x59"                  //          pop    %ecx
    "\xba\x0f\x00\x00\x00"  //          mov    $0xf,%edx
    "\xcd\x80"              //          int    $0x80
    "\xb8\x01\x00\x00\x00"  //          mov    $0x1,%eax
    "\xbb\x00\x00\x00\x00"  //          mov    $0x0,%ebx
    "\xcd\x80"              //          int    $0x80
    "\xe8\xdd\xff\xff\xff"  //          call   8048065 <GOBACK>
    "give me a bottle of rum!\r\n";     // OR       "\x48\x65\x6c\x6c\x6f\x2c\x20\x57"
                            //          "\x6f\x72\x6c\x64\x21\x0d\x0a"


int main(int argc, char **argv)
{
    (*(void(*)())code)();

    return 0;
}
gcc shellcode.s

shellcode.s: Assembler messages:
shellcode.s:1: Error: no such instruction: `char code[]='
shellcode.s:3: Error: invalid character '\' in mnemonic
shellcode.s:4: Error: invalid character '\' in mnemonic
shellcode.s:5: Error: invalid character '\' in mnemonic
shellcode.s:6: Error: invalid character '\' in mnemonic
shellcode.s:7: Error: invalid character '\' in mnemonic
shellcode.s:8: Error: invalid character '\' in mnemonic
shellcode.s:9: Error: invalid character '\' in mnemonic
shellcode.s:10: Error: invalid character '\' in mnemonic
shellcode.s:11: Error: invalid character '\' in mnemonic
shellcode.s:12: Error: invalid character '\' in mnemonic
shellcode.s:13: Error: no such instruction: `give me a bottle of rum!\r\n"'
shellcode.s:17: Error: junk `(int argc,char **argv)' after expression
shellcode.s:17: Error: operand size mismatch for `int'
shellcode.s:18: Error: no such instruction: `{'
shellcode.s:19: Error: junk at end of line, first unrecognized character is `('
shellcode.s:21: Error: no such instruction: `return 0'
shellcode.s:22: Error: junk at end of line, first unrecognized character is `}'

【问题讨论】:

    标签: c linux gcc assembly shellcode


    【解决方案1】:

    这是 C 代码,但它有一个 .s 扩展名,表示汇编。将您的文件重命名为shellcode.c

    【讨论】:

    • 谢谢,调试起来有点棘手。我没想到 gcc 会识别扩展,因为在 C/C++ 编程期间我从未有过这种感觉。我目前遇到分段错误,但我会尝试自己解决。
    【解决方案2】:

    默认情况下,gcc会根据文件的扩展名来决定编译文件的语言。

    根据文件内容正确重命名文件是正确的做法 (as already suggested)

    如果由于某种原因您无法重命名文件,您还可以使用-x 选项强制gcc 以给定(支持)语言编译具有任何扩展名的文件:

    gcc -x c shellcode.s
    

    此开关设置语言但不设置默认链接选项。尝试在 C++ 文件上使用 gcc 创建可执行文件失败,因为默认情况下 gcc 链接驱动程序不会添加 C++ 库。

    【讨论】:

    • "默认情况下,gcc 会根据扩展名决定编译文件的语言。" - 这是否意味着有人可以使用 gcc 编译 .cpp 文件g++gcc -o foo bar.cpp 一样没有问题?
    • 实际上它会编译,但链接会失败,除非您明确添加 C++ 库(或使用 g++ 链接)
    • 对,但我可以使用gcc 编译和g++ 链接?
    • gcc -c foo.cpp 然后g++ -o foo foo.o
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-20
    • 2021-09-02
    • 1970-01-01
    • 2017-02-02
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多