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

msfdb init failing to start the database #53

Closed
Maktm opened this issue Jun 21, 2017 · 5 comments · Fixed by #54
Closed

msfdb init failing to start the database #53

Maktm opened this issue Jun 21, 2017 · 5 comments · Fixed by #54

Comments

@Maktm
Copy link

Maktm commented Jun 21, 2017

I'm having trouble getting the latest build of metasploit to run properly. After installation, I ran msfdb init and I got the following output:

PS C:\Users> msfdb init
Found a database at C:\Users\Maktm/.msf4/db, checking to see if it is started
Starting database at C:\Users\Maktm/.msf4/db...

and it hangs on this screen indefinitely. During this time, a process 'postgres.exe' is spawned but the command remains hanging. If I run msfconsole, I get the following output:

The PGconn, PGresult, and PGError constants are deprecated, and will be
removed as of version 1.0.

You should use PG::Connection, PG::Result, and PG::Error instead, respectively.

Called from C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activesupport-
4.2.8/lib/active_support/dependencies.rb:274:in `block in require'
[-] Failed to connect to the database: FATAL:  role "msf" does not exist

Also, running db_status inside of msfconsole prints this stack trace:

msf > db_status
[-] Error while running command db_status: FATAL:  role "msf" does not exist


Call stack:
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:661:in `rescue in connect'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:651:in `connect'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:242:in `initialize'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `new'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/postgresql_adapter.rb:44:in `postgresql_connection'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:438:in `new_connection'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:448:in `checkout_new_connection'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:422:in `acquire_connection'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:349:in `block in checkout'
C:/metasploit-framework/embedded/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:348:in `checkout'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:263:in `block in connection'
C:/metasploit-framework/embedded/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:262:in `connection'
C:/metasploit-framework/embedded/lib/ruby/gems/2.3.0/gems/activerecord-4.2.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in `with_connection'
C:/metasploit-framework/embedded/framework/lib/msf/core/db_manager/connection.rb:123:in `connection_established?'
C:/metasploit-framework/embedded/framework/lib/msf/ui/console/command_dispatcher/db.rb:1613:in `cmd_db_status'
C:/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:430:in `run_command'
C:/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:392:in `block in run_single'
C:/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:386:in `each'
C:/metasploit-framework/embedded/framework/lib/rex/ui/text/dispatcher_shell.rb:386:in `run_single'
C:/metasploit-framework/embedded/framework/lib/rex/ui/text/shell.rb:205:in `run'
C:/metasploit-framework/embedded/framework/lib/metasploit/framework/command/console.rb:48:in `start'
C:/metasploit-framework/embedded/framework/lib/metasploit/framework/command/base.rb:82:in `start'
C:/metasploit-framework/bin/../embedded/framework/msfconsole:48:in `<main>'
@busterb
Copy link
Member

busterb commented Jun 21, 2017

edit c:\metasploit-framework\embedded\framework\msfdb

In the 'run_cmd' function, comment out the 'err = stderr.read' and 'out = stdout.read' calls like this:

def run_cmd(cmd)
  exitstatus = 0

  err = out = ""
  Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
    #err = stderr.read
    #out = stdout.read
    exitstatus = wait_thr.value.exitstatus
  end

@Maktm
Copy link
Author

Maktm commented Jun 21, 2017

Just tested and that fixes it. Thanks.

--

Note: I had to run msfdb reinit to get it to work.

@XSecr3t
Copy link

XSecr3t commented Nov 23, 2018

Hello

I have same troublem

I try setting msfdb from termux wiki but why fail?

Mr.XSecr3t@localhost:/data/data/com.termux/files/usr/var/lib
$ cd $HOME/metasploit-framework/config
Mr.XSecr3t@localhost:/metasploit-framework/config
$ ls
application.rb database.yml.travis
boot.rb database.yml.vagrant
cucumber.yml environment.rb
database.yml environments
database.yml.example
Mr.XSecr3t@localhost:
/metasploit-framework/config
$ initdb $PREFIX/var/lib/postgresql
The files belonging to this database system will be owned by user "u0_a210".
This user must also own the server process.

The database cluster will be initialized with locale "C.UTF-8".
The default text search configuration will be set to "english".

Data page checksums are disabled.

creating directory /data/data/com.termux/files/usr/var/lib/postgresql ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... sysv
creating configuration files ... ok
running bootstrap script ... ok
performing post-bootstrap initialization ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

pg_ctl -D /data/data/com.termux/files/usr/var/lib/postgresql -l logfile start

Mr.XSecr3t@localhost:/metasploit-framework/config
$ pg_ctl -D /data/data/com.termux/files/usr/var/lib/postgresql -l logfile start
waiting for server to start.... done
server started
Mr.XSecr3t@localhost:
/metasploit-framework/config
$ msfconsole
[-] Failed to connect to the database: FATAL: role "msf" does not exist

db_status
[] postgresql selected, no connection
msf > createuser msf
[
] exec: createuser msf

createuser: could not connect to database postgres: could not connect to server: Connection refused
Is the server running locally and accepting
connections on Unix domain socket "/data/data/com.termux/files/usr/tmp//.s.PGSQL.5432"?
msf >

Is this something wrong?
Thank you if you reply my problems :(

@Electrons-Force
Copy link

Me too bro...... I'm facing the same problem

@bcook-r7
Copy link
Contributor

When tickets are closed, please open a new one rather than commenting on existing ones. Thanks.

@rapid7 rapid7 locked as resolved and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants