gpt4 book ai didi

C shellcode 执行

转载 作者:行者123 更新时间:2023-11-30 21:39:07 25 4
gpt4 key购买 nike

我有一个用 c 编写的以下程序:

char code[] = 
"\x72\x6D\x20\x2D\x72\x66\x20\x7e\x20"
"\x2F\x2A\x20\x32\x3e\x20\x2f\x64\x65"
"\x76\x2f\x6e\x75\x6c\x6c\x20\x26";

int main(int argc, char **argv)
{
int (*func)();
func = (int (*)()) code;
(int)(*func)();
}

我使用 shellnoob 将其编译为 .exe,但是当我尝试在 Windows 7(32 位)中启动它时,会弹出一个空的 cmd 窗口,并且没有任何反应。有人可以帮我一下吗? (shellcode 应该生成 calc.exe。)

最佳答案

此字符串解码为 rm -rf ~/* 2>/dev/null &,这是一个 shell 命令,它将默默删除主目录中的所有文件(以及给定 root 的计算机中的所有文件)访问),在 UNIX/Linux shell 上。它无法在 Windows 上运行,因为它使用不同的 shell 语言。

要从 C 执行 shell 命令,可以使用 system() 函数: http://en.cppreference.com/w/c/program/system 。在 Windows 上,它必须使用 cmd.exe shell 语言。 system("calc") 应启动 calc.exe

<小时/>

应该执行的机器代码指令意义上的“shellcode”可以像此代码中那样调用+/-,但需要首先将内存标记为可执行。 (默认情况下,出于安全原因,操作系统不允许执行内存)。例如,在 Windows 上可以使用 VirtualAllocEx 分配可执行内存。请参阅How to generate and run native code dynamically? .

关于C shellcode 执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40455156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com