Port and fix MongoDB scanner modules (version/login/schemadump/hashdump) - #3
Merged
Merged
Conversation
Ports and fixes the MongoDB auxiliary modules from rapid7#21785 (h00die): mongodb_version (new), mongodb_login (updated for SCRAM-SHA-1 / MongoDB 3.0+), and the new mongodb_schemadump and mongodb_hashdump modules. Fixes applied relative to the original PR: - 'Reliability' => [UNKNOWN_RELIABILITY] double-nested the constant (UNKNOWN_RELIABILITY is itself ['unknown-reliability']), which crashed the `info` command with "no implicit conversion of Array into String" in dump_traits. Changed to 'Reliability' => UNKNOWN_RELIABILITY in all four modules. - mongodb_version.rb defined a `parse_doc` helper that was never called; get_version duplicated the same BSON-parsing logic inline. - ~250 lines of identical build_cmd_packet/parse_doc/parse_docs/ parse_scram_payload/have_auth_error? code were copy-pasted across mongodb_login.rb and mongodb_hashdump.rb (with subsets duplicated in mongodb_version.rb and mongodb_schemadump.rb too). Extracted the wire-protocol primitives into a new Msf::Exploit::Remote::Mongodb mixin (lib/msf/core/exploit/remote/mongodb.rb); each module keeps its own auth-flow/reporting logic on top of it, since those differ enough (SCRAM step counts, whether creds get reported, return value semantics) that unifying them risked changing tested behavior. - Typo: "Sccuessfully tested" -> "Successfully tested" in mongodb_schemadump.rb's description. - mongodb_hashdump.rb stores credentials with jtr_format 'mongodb-scram-sha1'/'mongodb-scram-sha256', but neither format is registered in cracker.rb's jtr_format_to_hashcat_format table or crack_databases.rb's format list, so Metasploit's own analyze modules won't select them for cracking despite the hashes being correctly formatted for external hashcat use. Documented this limitation directly in the module description rather than attempting an unverified extension of the cracking pipeline. - Missing trailing newline in 3 of 4 documentation markdown files, which fails tools/dev/msftidy_docs.rb. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CkE73M69GgryoXCXW9sTg7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for contributing to Metasploit Framework!
Description
Ports and fixes the MongoDB auxiliary modules originally proposed in rapid7/metasploit-framework#21785 (h00die):
mongodb_version(new),mongodb_login(updated for SCRAM-SHA-1 / MongoDB 3.0+, falling back to legacy MONGODB-CR), and the newmongodb_schemadumpandmongodb_hashdumpmodules.I don't have push access to that upstream PR's branch, so rather than leave the review findings unactioned, this recreates the same functionality in this fork with the issues found during review fixed:
'Reliability' => [UNKNOWN_RELIABILITY].UNKNOWN_RELIABILITYis already['unknown-reliability'], so the double-nesting crashed theinfocommand withno implicit conversion of Array into Stringindump_traits. Reproduced live inmsfconsolebefore fixing to'Reliability' => UNKNOWN_RELIABILITY.mongodb_version.rbdefined aparse_dochelper that was never called;get_versionduplicated the same BSON-parsing logic inline instead.build_cmd_packet/parse_doc/parse_docs/parse_scram_payload/have_auth_error?were copy-pasted near-verbatim acrossmongodb_login.rbandmongodb_hashdump.rb(with subsets duplicated inmongodb_version.rbandmongodb_schemadump.rbtoo). Extracted the wire-protocol primitives into a newMsf::Exploit::Remote::Mongodbmixin (lib/msf/core/exploit/remote/mongodb.rb). Each module keeps its own auth-flow/reporting logic on top of it, since those differ enough (SCRAM step counts, whether creds get reported, return value semantics) that unifying them risked changing tested behavior.mongodb_schemadump.rb's description.mongodb_hashdump.rbstores credentials withjtr_format'mongodb-scram-sha1'/'mongodb-scram-sha256', but neither format is registered incracker.rb'sjtr_format_to_hashcat_formattable orcrack_databases.rb's format list, so Metasploit's ownanalyzemodules won't select them for cracking despite the hashes being correctly formatted for external hashcat use (modes 24100/24200). Documented this limitation directly in the module description rather than attempting an unverified extension of the cracking pipeline.tools/dev/msftidy_docs.rb.Breaking Changes
None.
Reviewer Notes
Start with
lib/msf/core/exploit/remote/mongodb.rb— the shared mixin all four modules include. Then each module file mainly differs in its higher-level flow (dump_system_users/dump_app_usersfor hashdump, schema sampling for schemadump, brute-force login for login, single version lookup for version).Verification Steps
bundle exec rubocop lib/msf/core/exploit/remote/mongodb.rb modules/auxiliary/scanner/mongodb/mongodb_{version,login,schemadump,hashdump}.rb— expect no offenses.ruby tools/dev/msftidy.rb modules/auxiliary/scanner/mongodb/mongodb_{version,login,schemadump,hashdump}.rb— expect no offenses.ruby tools/dev/msftidy_docs.rb documentation/modules/auxiliary/scanner/mongodb/mongodb_{version,login,schemadump,hashdump}.md— expect no offenses.msfconsole:use auxiliary/scanner/mongodb/mongodb_version(repeat forlogin,schemadump,hashdump) theninfo— expect no load errors and correct rendering of Module reliability/stability/side effects (this is the regression check for the Reliability crash).mongodb_versionreports the version;mongodb_loginbrute-forces/reports no-auth or valid creds;mongodb_schemadumpdumps inferred schema to loot;mongodb_hashdumpdumpssystem.usershashes and stores them asnonreplayable_hashcredentials.Test Evidence
Verified the new mixin's wire-protocol logic directly (packet header construction, single/multi BSON document parsing, SCRAM payload parsing, auth-error detection) with round-trip unit checks against synthetic MongoDB wire-protocol byte sequences — all passed.
Reproduced the Reliability crash before the fix:
Confirmed clean after the fix — all four modules load and
inforenders correctly:Environment
AI Usage Disclosure
This PR was authored by Claude (Anthropic) working in Claude Code: reviewing the original upstream PR's diff, identifying the crashing bug and duplication, extracting the shared mixin, porting all four modules, and writing/running the verification above. A human directed and reviewed the work. The original module logic (wire protocol construction, SCRAM-SHA-1/MONGODB-CR auth flows) originates from h00die's upstream PR rapid7#21785, which itself disclosed AI assistance (Gemini for schemadump/login updates, GLM-4.7 for version/hashdump) with human verification.
Pre-Submission Checklist
documentation/modulesfor each module