如何从终端编译这个简单的 shellcode C 程序?

问题描述 投票:0回答:3

我正在尝试使用 Ubuntu 12.04(精确穿山甲)上的终端进行编译:

#include <stdio.h>
#include <stdlib.h>

main()
{
    /* Declare argument array */
    char *args[2];

    args[0] = “/bin/bash”;
    args[1] = NULL;

    execve(args[0], args, NULL);

    exit(0);
}

我在 Buffer Overflow Primer Part 4 (Disassembly Execve) 上找到了这个例子,它也恰好是 Aleph One 在“粉碎堆栈以获得乐趣和利润”中使用的那个。我知道自那时以来发生了很大变化。在我使用的更简单的示例中:

gcc -ggdb -mpreferred-stack-boundary=2 -fno-stack-protector filename filename.c

其他时候我可能会包含静态实用程序。它一直在工作,直到我尝试编译上面的 C 代码。我从终端收到的消息是:

gcc -static -mpreferred-stack-boundary=2 -fno-stack-protector -o shell shell.c

输出:

shell.c: In function ‘main’:
shell.c:9:2: error: stray ‘\342’ in program
shell.c:9:2: error: stray ‘\200’ in program
shell.c:9:2: error: stray ‘\234’ in program
shell.c:9:15: error: expected expression before ‘/’ token
shell.c:9:15: error: stray ‘\342’ in program
shell.c:9:15: error: stray ‘\200’ in program
shell.c:9:15: error: stray ‘\235’ in program

我知道这是一个非常简单的例子,这个错误可能是由 Linux 中当前的标准安全措施引起的,但我想绕过它们来练习这个例子,并在未来进行更多练习。我该如何解决这个问题?

c security buffer-overflow shellcode execve
3个回答
4
投票

你的字符串文字周围有“智能”引号,

“/bin/bash”;

尝试使用普通引号

"
.


2
投票

我认为这与安全无关,而是以下行:

args[0] = “/bin/bash”;

您用来分隔字符串的引号字符不是标准的 ASCII 引号字符;相反,它们是引号的漂亮 Unicode 字符。

尝试将其重写为

args[0] = "/bin/bash";

通过用新的双引号替换引号字符。

顺便说一句——编译器不可能检测到所有可能启动 shellcode 的程序。如果任何标准编译器会做任何事情来阻止程序因安全漏洞而编译,我会感到震惊。

希望这有帮助!


0
投票

感谢大家的快速回复。我学到了一些东西:

1)复制和粘贴是愚蠢的

2) 不要复制粘贴

3)无论如何都要检查我的引号

答案是引号。我删除并再次输入它们。 *叹息

干杯

我是新人-我是第一个承认的。

© www.soinside.com 2019 - 2024. All rights reserved.