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

Fix DB initialization when missing database YAML file #9860

Merged
merged 1 commit into from
Apr 11, 2018

Conversation

mkienow-r7
Copy link
Contributor

@mkienow-r7 mkienow-r7 commented Apr 10, 2018

Fixes DB initialization when the database YAML file is missing. The message "WARNING: No database support: NilClass" reported during msfconsole startup is the first indicator of the issue. Subsequent DB operations fail to work as expected due to the framework not loading CommandDispatcher::Db. Fixes #9811

This also cleans up some things that were not caught in the early Goliath changes.

Verification

  • Temporarily move database.yml file: mv ~/.msf4/database.yml ~/.msf4/database.yml.disable
  • Start msfconsole
  • Run command: db_status
  • Verify Command ran successfully and it reports postgresql selected, no connection
  • Connect to DB: db_connect -y ~/.msf4/database.yml.disable
  • Verify Command ran successfully and db_status reports it is connected to the specified database (postgresql connected to ...)
  • Verify ability to connect to a remote data store (Goliath)
    • Start remote data service on a server or VM: msfdb_ws
    • Connect to remote data service: data_services --add <host>
  • Restore database.yml file: mv ~/.msf4/database.yml.disable ~/.msf4/database.yml

@mkienow-r7 mkienow-r7 changed the title Fix DB initialization Fix DB initialization when missing database YAML file Apr 11, 2018
@mkienow-r7 mkienow-r7 force-pushed the fix_goliath_db_initialization branch from c1e089d to e639fda Compare April 11, 2018 13:16
@wvu
Copy link
Contributor

wvu commented Apr 11, 2018

👏

@jbarnett-r7 jbarnett-r7 self-assigned this Apr 11, 2018
@@ -153,9 +157,6 @@ def check
#
def initialize_database_support
begin
# Database drivers can reset our KCODE, do not let them
$KCODE = 'NONE' if RUBY_VERSION =~ /^1\.8\./
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 just removed because we no longer support Ruby 1.8?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's unfortunate KCODE doesn't mean Konami Code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wvu-r7 ⬆️⬆️⬇️⬇️⬅️➡️⬅️➡️🅱️🅰️

@@ -1653,8 +1653,8 @@ def cmd_db_nmap_tabs(str, words)
# Database management
#
def db_check_driver
if(not framework.db.driver)
print_error("No database driver installed. Try 'gem install pg'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was the suggestion to install the pg gem removed here?

Copy link
Contributor Author

@mkienow-r7 mkienow-r7 Apr 11, 2018

Choose a reason for hiding this comment

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

I believe the suggestion to gem install pg is not relevant given we now use bundler. Is this correct @busterb?

@@ -1909,6 +1909,12 @@ def each_host_range_chunk(host_ranges, &block)
#######

def add_data_service(*args)
# database is required to use Mdm objects
unless framework.db.active
print_error("Database not connected; connect to an existing database with db_connect before using data_services")
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like longer term we should move everything under a single command (either db_connect or data_services). Agree/disagree?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree

@jbarnett-r7 jbarnett-r7 merged commit e639fda into rapid7:master Apr 11, 2018
jbarnett-r7 added a commit that referenced this pull request Apr 11, 2018
This PR fixes a bug introduced with goliath that caused incorrect error messages
and other error messages when no database.yml was present. It also improves the
messaging around that use case and loads CommandDispatcher::Db correctly.
@mkienow-r7
Copy link
Contributor Author

mkienow-r7 commented Apr 17, 2018

Release Notes

Fixes issues introduced with Goliath #9717 that caused confusing error messages and subsequent DB operations to fail to work as expected due to the framework not loading CommandDispatcher::Db when the database YAML file (database.yml) is missing.

@mkienow-r7 mkienow-r7 deleted the fix_goliath_db_initialization branch April 17, 2018 18:38
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants