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

Extract SMB, PostgreSQL, MySQL and MSSQL optional sessions into their own mixins #18770

Merged

Conversation

dwelch-r7
Copy link
Contributor

@dwelch-r7 dwelch-r7 commented Jan 30, 2024

Spotted an issue where having any of the new SMB/MySQL/PostgreSQL/MSSQL session type features enabled would end up enabling the new feature for each which was unintended, also fixes an issue where if the postgres session feature is enabled it starts registering postgres specific datastore options in the included other session type modules, this PR resolves both of these issues by splitting the Msf::OptionalSession out into individual mixins for each session type.

The Msf::OptionalSession mixin is left quite bare at the minute, but it will fill up in the near future with stuff common to all sessions (like the SESSION datastore option as an example) once the sessions are no longer behind individual feature flags

Verification steps

  • with features set smb_session_type false and features set postgresql_session_type false
    • check that the SESSION datastore option is not available in the smb/postgres modules
    • check that the smb modules do not have the DATABASE datastore option registered
    • Run a few modules to make sure they still work as expected
  • with features set smb_session_type true and features set postgresql_session_type false
    • check that the SESSION datastore option is not available in the postgres modules
    • check that the SESSION datastore option is available in the SMB modules
    • check that the smb modules do not have the DATABASE datastore option registered
    • Run a few SMB modules with a session to make sure they still work as expected
  • with features set smb_session_type false and features set postgresql_session_type true
    • check that the SESSION datastore option is not available in the SMB modules
    • check that the SESSION datastore option is available in the postgres modules
    • check that the smb modules do not have the DATABASE datastore option registered
    • Run the postgres schema dump module with a session to make sure it still works as expected
  • with features set smb_session_type true and features set postgresql_session_type true
    • check that the SESSION datastore option is available in the postgres/SMB modules
    • check that the smb modules do not have the DATABASE datastore option registered
    • Run a few modules to make sure they still work as expected

Continue the above steps for each new session type

@zgoldman-r7 zgoldman-r7 self-requested a review January 30, 2024 18:36
Copy link
Contributor

@zgoldman-r7 zgoldman-r7 left a comment

Choose a reason for hiding this comment

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

This all works for and looks good to me and - seems to be an issue in #18763 as well, I'll add a commit to that following this pattern

@dwelch-r7 dwelch-r7 mentioned this pull request Jan 31, 2024
7 tasks
@adfoster-r7
Copy link
Contributor

@dwelch-r7 I think this needs a rebase 👀

@dwelch-r7 dwelch-r7 force-pushed the individual-optional-session-mixins branch from 4addfab to 5b10b92 Compare February 13, 2024 11:02
@cgranleese-r7 cgranleese-r7 self-assigned this Feb 13, 2024
@dwelch-r7 dwelch-r7 force-pushed the individual-optional-session-mixins branch from 5b10b92 to 1e76bbc Compare February 13, 2024 11:09
@cgranleese-r7 cgranleese-r7 changed the title Extract SMB and PostgreSQL optional sessions into their own mixins Extract SMB, PostgreSQL, MySQL and MSSQL optional sessions into their own mixins Feb 13, 2024
@cgranleese-r7 cgranleese-r7 added the rn-fix release notes fix label Feb 13, 2024
@cgranleese-r7
Copy link
Contributor

Tested the steps outlined in the verification steps above and repeated those for the MySQL scenarios as well and everything appears to be working as expected 👍

Assuming we wont want to land this until we have the MSSQL modules in and tested against this as well?

Copy link
Contributor

@cgranleese-r7 cgranleese-r7 left a comment

Choose a reason for hiding this comment

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

Everything worked when tested but noticed a few things that may need updated due to lots of overlapping PRs and things needing updated since this was opened.

[
Msf::OptInt.new('SESSION', [ false, 'The session to run this module on' ]),
Msf::Opt::RHOST(nil, false),
Msf::Opt::RPORT(nil, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Context: I think some final changes were made after this PR was put up.

Suggested change
Msf::Opt::RPORT(nil, false)
Msf::Opt::RPORT(3306, false)

super(
update_info(
info,
'SessionTypes' => %w[MySQL]
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this added to address this comment?
Also, I have a PR that updates these session types to be aligned with the rest of framework to use lowercase. Makes sense to align it here as well to avoid a race condition on which PR lands first:

Suggested change
'SessionTypes' => %w[MySQL]
'SessionTypes' => %w[mysql]

super(
update_info(
info,
'SessionTypes' => %w[PostgreSQL]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Suggested change
'SessionTypes' => %w[PostgreSQL]
'SessionTypes' => %w[postgresql]

Msf::OptString.new('DATABASE', [ false, 'The database to authenticate against', 'postgres']),
Msf::OptString.new('USERNAME', [ false, 'The username to authenticate as', 'postgres']),
Msf::Opt::RHOST(nil, false),
Msf::Opt::RPORT(nil, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as MySQL port

Suggested change
Msf::Opt::RPORT(nil, false)
Msf::Opt::RPORT(5432, false)

lib/msf/core/optional_session/mssql.rb Show resolved Hide resolved
super(
update_info(
info,
'SessionTypes' => %w[SMB]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'SessionTypes' => %w[SMB]
'SessionTypes' => %w[smb]

[
Msf::OptInt.new('SESSION', [ false, 'The session to run this module on' ]),
Msf::Opt::RHOST(nil, false),
Msf::Opt::RPORT(nil, false)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, the other session types needed the RPORT value defaulted, is there a reason as to why the SMB session type doesn't require a default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea not sure what happened, I added it elsewhere in the default options values part of the info hash but it's not there now and I'm not sure what happened but makes sense to add it in here

@@ -18,7 +18,6 @@ def initialize
),
'Author' => ['theLightCosine'],
'License' => MSF_LICENSE,
'SessionTypes' => %w[PostgreSQL]
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this was done here, but lots of other modules didn't have this removed. If we're going ahead with initialising the session type within the mixin, I'm assuming we want all of these removed?

Looks like it's mostly the MySQL and PostgreSQL modules were this was the case, so I assume you just forgot to remove them after updating the mxin 🤷

Example:
https://github.com/rapid7/metasploit-framework/pull/18770/files#diff-eeaec8f2c44f2baca8313b0d7849a46daf67c71d0d2ac8eef3a7a92692280468R23

Copy link
Contributor

Choose a reason for hiding this comment

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

Thinking more about this, do we really want the session type not being on the module? As a user I'd expect to be able to view that kinda of module info within the module.

Just thinking removing the existing module information could cause confusion, whereas the call in the module is just more information for the user to work with. Not super strongly opinionated on this just thought I'd call it out 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it still appears when you do info -d though right? I think that's how a majority of users would see it rather than looking at the module code itself

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose that's true. Maybe I'm looking at it too much from a developer perspective were I'd be working with the module and just get my information there. Whereas you say, users would probably get it from console.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dean's current pattern looks good to me 👍

@adfoster-r7
Copy link
Contributor

This branch has conflicts that must be resolved

Needs a rebase, and probably some changes back-ported to the recently changed mssql modules 👍

@dwelch-r7 dwelch-r7 force-pushed the individual-optional-session-mixins branch from 1e76bbc to d258c52 Compare February 14, 2024 12:16
@dwelch-r7 dwelch-r7 force-pushed the individual-optional-session-mixins branch from 9b9a175 to d73293d Compare February 14, 2024 15:37
@dwelch-r7 dwelch-r7 force-pushed the individual-optional-session-mixins branch from d73293d to fa5c4c0 Compare February 14, 2024 15:45
@adfoster-r7 adfoster-r7 merged commit e49c6a7 into rapid7:master Feb 15, 2024
49 checks passed
@adfoster-r7
Copy link
Contributor

Release Notes

Fixes a bug when multiple new session types (SMB, PostgreSQL, MSSQL, MySQL) were enabled with the features set postgresql_session_type true command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-fix release notes fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants