利用 C 中的 system() 调用
Exploit system() call in C
我在名为 vulnerable.c 的文件中有以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
gid_t egid = getegid();
setregid(egid, egid);
system("echo testing");
return 0;
}
以下是易受攻击的可执行文件的权限:
-rwxr-sr-x 1 test cool 8192 2016 年 9 月 28 日易受攻击
在我的主目录中,我创建了一个名为"echotest" 的新目录并放入了一个echo.c 文件并进行了编译。 echo.c 文件只是打印出 "Exploited!!"。我还更改了我的 PATH 环境变量以包含 $HOME/echotest.
现在,当我 运行 易受攻击时,它应该打印出 "Exploited!" 但事实并非如此。我在这里错过了什么?
我用 "cat" 做了一个类似的测试,它起作用了,但没有回声。
任何帮助将不胜感激。
谢谢
问题是 echo
通常是 shell 内置的。如果您希望它可以被利用,您可以将易受攻击的代码更改为:
int main() {
gid_t egid = getegid();
setregid(egid, egid);
system("env echo testing");
return 0;
}
有关此的更多信息,请参阅:
我在名为 vulnerable.c 的文件中有以下代码:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main() {
gid_t egid = getegid();
setregid(egid, egid);
system("echo testing");
return 0;
}
以下是易受攻击的可执行文件的权限:
-rwxr-sr-x 1 test cool 8192 2016 年 9 月 28 日易受攻击
在我的主目录中,我创建了一个名为"echotest" 的新目录并放入了一个echo.c 文件并进行了编译。 echo.c 文件只是打印出 "Exploited!!"。我还更改了我的 PATH 环境变量以包含 $HOME/echotest.
现在,当我 运行 易受攻击时,它应该打印出 "Exploited!" 但事实并非如此。我在这里错过了什么?
我用 "cat" 做了一个类似的测试,它起作用了,但没有回声。 任何帮助将不胜感激。
谢谢
问题是 echo
通常是 shell 内置的。如果您希望它可以被利用,您可以将易受攻击的代码更改为:
int main() {
gid_t egid = getegid();
setregid(egid, egid);
system("env echo testing");
return 0;
}
有关此的更多信息,请参阅: