简体   繁体   English

在C错误中编译ShellCode程序

[英]Compiling ShellCode Program in C error

I am currently reading through a book about shellcoding and I am running into some issues during one of the examples. 我目前正在阅读一本有关shellcoding的书,在其中一个示例中遇到了一些问题。 I am trying to compile the code below but I keep getting an error about stray "\\". 我正在尝试编译下面的代码,但始终收到关于流浪“ \\”的错误。 Is there a certain way I have to input the characters because of the "\\"? 是否由于“ \\”而必须输入某些字符?

// shellcode.c

char shellcode[] =
“\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46”
“\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1”
“\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68”;

int main(){

    int *ret;
    ret = (int *)&ret + 2;
    (*ret) = (int)shellcode;
}

\\x indicates a hexadecimal character escape. \\ x表示十六进制字符转义。 From C99 6.4.4.4.: 从C99 6.4.4.4 .:

The hexadecimal digits that follow the backslash and the letter x in a hexadecimal escape sequence are taken to be part of the construction of a single character for an integer character constant or of a single wide character for a wide character constant. 在十六进制转义序列中,反斜杠后面的十六进制数字和字母x被视为构成整数字符常量的单个字符或构成宽字符常量的单个宽字符的一部分。

EXAMPLE 3 Even if eight bits are used for objects that have type char, the construction '\\x123' specifies an integer character constant containing only one character, since a hexadecimal escape sequence is terminated only by a non-hexadecimal character. 示例3即使对于具有char类型的对象使用了八位,构造'\\ x123'也会指定仅包含一个字符的整数字符常量,因为十六进制转义序列仅以非十六进制字符结尾。 To specify an integer character constant containing the two characters whose values are '\\x12' and '3', the construction '\\0223' may be used, since an octal escape sequence is terminated after three octal digits. 要指定包含两个值为'\\ x12'和'3'的字符的整数字符常量,可以使用结构'\\ 0223',因为八进制转义序列在三个八进制数字后终止。 (The value of this two-character integer character constant is implementation-defined.) (此两个字符的整数字符常量的值是实现定义的。)

I think the problem is caused by the typographic quotes: . 我认为问题是由印刷引号引起的:

In C, strings must be enclosed by regular double quotes: " 在C语言中,字符串必须以普通双引号括起来: "

The \\x notation for hex characters only works inside strings (double quotes) and character constants (single qoutes). 十六进制字符的\\x表示法仅在字符串(双引号)和字符常量(单个qoutes)内部起作用。 Becuse of the typographic qoutes the compiler doesn't recognize the code as a string. 由于存在印刷字体,编译器无法将代码识别为字符串。

So try changing the declaration like this: 因此,尝试像这样更改声明:

char shellcode[] =
"\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46"
"\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1"
"\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";

As indicated before, your quotes are an issue here. 如前所述,您的报价在这里是一个问题。 Pasting them on vi produces ?~@~\\\\xeb.. which may explain the complain about the backslash. 将它们粘贴到vi上会生成?~@~\\\\xeb..这可能解释了有关反斜杠的抱怨。

Also, I would consider this cast for shellcode, which is more straightforward. 另外,我会考虑对shellcode进行强制转换,这更简单。

char shellcode[] =
"\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46"
"\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1"
"\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";

int main(){
        (*(void(*)()) shellcode)();
    return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM