-
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
Use upstream ruby-mysql in Remote::MYSQL #18296
Use upstream ruby-mysql in Remote::MYSQL #18296
Conversation
Thanks for championing this! 💯
I also tried verifying this module using a prebuilt vulnerable 5.5.23 image from https://github.com/vulhub/vulhub - specifically the versions from dockerhub https://hub.docker.com/r/vulhub/mysql/tags and saw similar output as yourself Another community member was recently hitting issues with this module which made probe a bit deeper - and I've had to create a PR to patch both the module and MySQL library code a bit - #18297 It looks like we might want to send a feature request/pull request to add socket-reuse to the RbMysql library, as well as fixing the nil charset exception when the server immediately responds with an error - rather than initially attempting to negotiate a charset. I can attempt to contribute those code changes plus extra tests as a contribution upstream, or I'm happy for you to try and contribute a patch upstream/raise an issue Let me know whatever works best for yourself 👍 |
Ha! TIL about vulhub, thank you! I haven't fully grokked #18297 but happy to take a stab at converting that into a PR on upstream. |
@@ -72,7 +72,7 @@ def query(q) | |||
res.each_hash do |row| | |||
rows << row | |||
end | |||
rescue RbMysql::ParseError | |||
rescue Mysql::ParseError |
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.
rescue Mysql::ParseError | |
rescue ::Mysql::ParseError |
@@ -104,7 +104,7 @@ def exploit | |||
print_status("Attempting to login as '#{datastore['USERNAME']}:#{datastore['PASSWORD']}'") | |||
begin | |||
m = mysql_login(datastore['USERNAME'], datastore['PASSWORD']) | |||
rescue RbMysql::AccessDeniedError | |||
rescue Mysql::AccessDeniedError |
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.
rescue Mysql::AccessDeniedError | |
rescue ::Mysql::AccessDeniedError |
@@ -116,7 +116,7 @@ def exploit | |||
|
|||
begin | |||
drive = get_drive_letter | |||
rescue RbMysql::ParseError | |||
rescue Mysql::ParseError |
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.
rescue Mysql::ParseError | |
rescue ::Mysql::ParseError |
@@ -129,7 +129,7 @@ def exploit | |||
print_status("Uploading to '#{dest}'") | |||
begin | |||
upload_file(exe, dest) | |||
rescue RbMysql::AccessDeniedError | |||
rescue Mysql::AccessDeniedError |
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.
rescue Mysql::AccessDeniedError | |
rescue ::Mysql::AccessDeniedError |
@adfoster-r7 Apologies for the slow response on this, my week took an unexpected turn to the left. If it is ok with you, I am happy to keep this open until I have gotten the RbMySQL changes merged upstream and we can continue to replace the use of RbMYSQL. I am hoping to get some work done on branch for upstream over the weekend (unfortunately, I am primarily restricted to after-hours and weekends for this stuff). |
No worries! Feel free to ping me if you need anything 👍 |
@adfoster-r7 Upstream As a result, I think this PR is ready to be resuscitated. The one catch is that I am not sure when an updated version of the gem will be released. Would you have any objections to the gem being sourced from the project's gitlab repo rather than from rubygems? |
Thanks for handling those PRs! (https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/4 + https://gitlab.com/tmtms/ruby-mysql/-/merge_requests/2) If you're good with rebasing, pointing to the latest Github SHA on GitLab, we could start testing this on our side. If everything's well, we can see if there's new version available on RubyGems https://rubygems.org/gems/ruby-mysql by then and decide what to do next 😄 I'd definitely preference the source code being available in RubyGems as it has the benefit of being cacheable by artifactory / nexus in CI envs, and I know it wouldn't impact downstream build systems like Kali/Arch etc; but happy to re-evaluate after testing things! 👍 |
Makes sense - let me rebase and re-test based on the Gitlab HEAD and then we can always park this until an updated version of the gem is released. |
37b8f00
to
0b6e60f
Compare
@@ -37,21 +37,21 @@ def mysql_login(user='root', pass='', db=nil) | |||
connect | |||
|
|||
begin | |||
@mysql_handle = ::RbMysql.connect(rhost, user, pass, db, rport, sock) | |||
@mysql_handle = ::Mysql.connect(rhost, user, pass, db, rport, io: sock) |
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.
🎉
@adfoster-r7 I have manually tested this per the examples at the top of this PR. All seems fine - I have tried recreating the 'blocked because of many connection errors' issue (to confirm that the gem and my manual change of earlier have produced the same result) but I have been unable to. At any rate, some googling and a cursory inspection of the docs around |
Thanks for the awesome work! Will keep an eye on the release page for the gem to be available 🤞 |
@adfoster-r7 I see that version 4.1.0 of |
* ... and dependents
0b6e60f
to
1b17276
Compare
@adfoster-r7 I think this is ready to go - I see there is one check failing, but I can't see why. |
@msjenkins-r7 retest this please |
Thanks! I'll try and run through things today 🎉 |
Updated the steps to include the happy path of #18297 now too, and everything looks good - thanks! 👍 |
Release NotesUpdates multiple MySQL modules to support authenticating with newer versions of MySQL. |
Added a call out for the updated support in the Metasploit release notes, thanks! 👍 https://www.rapid7.com/blog/post/2023/10/13/metasploit-weekly-wrap-up-31/ |
I am hoping to get rid of the last few RbMysql remnants this week. |
Continuation of #18278
Relates to #18297
This is the next iteration of replacing the local
RbMysql
with the upstreamruby-mysql
gem. It replacesRbMysql
inMsf::Exploit::Remote::MYSQL
.There are two manual tests to confirm that this functionality works:
modules/auxiliary/scanner/mysql/mysql_file_enum.rb
(it seems to use most of the core functionality provided byMsf::Exploit::Remote::MYSQL
)modules/auxiliary/scanner/mysql/mysql_authbypass_hashdump.rb
(it not only usesMsf::Exploit::Remote::MYSQL
but it also usesRbMysql
independently. ~~I cannot fully test this as I could not find a mysql container that is old enough to have the vulnerability, so it is a very high-level test, but enough to confirm that the code can connect to the MySQL instance (hopefully). ~~ Resolved by: Fix broken mysql_authbypass_hashdump module #18297Verification
Part 1 (
mysql_file_enum.rb
)docker run --name some-mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=foo123 -d mysql:5.7.42 --secure-file-priv=/etc
echo '/etc/my.cnf' > test.txt
msfconsole
use auxiliary/scanner/mysql/mysql_file_enum
set RHOSTS 127.0.0.1
set USERNAME root
set PASSWORD foo123
set FILE_LIST test.txt
run
You should see output as per the below:
Part 2 (mysql_authbypass_hashdump)
msfconsole
use auxiliary/scanner/mysql/mysql_authbypass_hashdump
set RHOSTS 127.0.0.1
You should see output as per the below:
part 3 - mysql_authbypass_hashdump - vulnerable
Expected results from #18297 :