unix - SUID exploit and patch
问题描述
I am working on a SUID root binary 'app' that runs a system("ls -la /dir") command and managed to exploit it by writing a malicious ls to get root and changing my user's environment path to set it to higher priority than the kernel's one.
I noticed that executing it as user returns me root shell while executing it with sudo "./example" uses root's path and simply lists the files in dir. As far as i know setuid inherits owner's (in this case root) privileges to user and sudo executes as root.
What are such vulnerabilities called ? How would an app developer patch it? I there any way i can force user's to use sudo ./app to execute a program?
解决方案
我建议您更改应用程序以对其运行的命令使用绝对路径。例如:
system("/bin/ls -la /dir");
即使用户使用 sudo 命令执行它,他们也可以使用 sudo 参数 (--preserve-env) 来保留自己的 PATH。
如果您希望用户使用 sudo 运行应用程序,那么二进制文件不需要是 SUID root。
推荐阅读
- ruby-on-rails - 在 Rails 中渲染两个 JSON 项
- python - 如何从 func1 中获取 var1 并在 func2 中使用它而不在 func1 中运行两次
- c - 使用 mmap 读取/写入文件时如何解析 ENODEV
- python - ',' 在这个切片操作中做了什么 - [:,::-1]
- c# - 在可视化树中添加和删除用户控件会引发 Unloaded 事件,但不会引发 Loaded 事件
- swift - 是否有更可定制的方式来创建嵌入式超链接?
- sql - 个人和团体帐户的数据库模式(如 Facebook 用户和页面)
- javascript - window.move 在负方向问题
- c++ - 如何降低高分辨率(10 微秒)精确计时器的 CPU 使用率?
- python - 向量化 Numpy 3D 和 2D 数组操作