c - X Window 系统中的一个老缺陷。它是如何工作的?

标签 c security unix static-analysis

我今天正在阅读一篇文章,其中提到了以下内容:

"We've found many errors over the years. One of the absolute best was the following in the X Window System:

     if(getuid() != 0 && geteuid == 0) {
       ErrorF("Only root");
       exit(1);
     }

It allowed any local user to get root access. (The tautological check geteuid == 0 was intended to be geteuid() == 0. In its current form, it compress the address of geteuid to 0; given that the function exists, its address is never 0)."

文章解释了代码有什么问题,但我想知道说“它允许任何本地用户获得 root 访问权限” 是什么意思。我不是 C 语言的专家,但有人可以给我一个确切的上下文,让我可以利用这个漏洞吗?具体来说,我的意思是,假设我是本地用户,如果我们假设这段代码存在于某处,我将如何获得 root 访问权限?

对于任何有兴趣阅读全文的人,这里是链接:

A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in Real World

最佳答案

文章的意思是,if 之后的代码,本应仅在验证用户为 root 时才执行,实际上任何人都可以执行。要利用它,您需要在代码中查找用于检查用户身份的分支(该文章负责任地没有提供:您需要做一些工作),然后将其安排为执行。

“allowed to get root access”是一个省略号,用于描述原始代码中if 之后发生的情况。它与测试没有特别的关系,因为它描述了测试之后发生的事情。

换句话说,测试本身并不能让你root。它之后的代码让你 Root 。另外,请记住,X 服务器通常必须与 root 所有者和 setuid bit set 一起安装。 ,这就是为什么其代码中有缺陷的逻辑很危险的原因。

这不是关于 C 的问题。这是关于 Unix 安全模型的问题,它是非常二进制的(尤其是在旧的实现中):你必须是 root 才能做任何事情,所以很多程序都有 root 所有者和setuid 位(有点讽刺)。

关于c - X Window 系统中的一个老缺陷。它是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2717653/

相关文章:

C-X11 API : Custom Control Redraw Issue

c - NaN 作为特殊参数

security - 如何在 BlueZ 上启动 BLE 配对

linux - 脚本创建父目录的 tar,该目录将具有其子目录的单独 tar

linux - 脚本持续运行数小时

c - 返回指向指针数组的指针

c - 交换字符位并在交换后将其替换为新创建的字符

cocoa-touch - 如何防止 iOS 应用程序中的数据与 iTunes 同步

database - 银行系统NoSQL数据库

python - 在 python 中禁用从\r\n 到\n 的自动更改