msfconsole error after updating Metasploit Framework in Kali Linux [Solved]

Updated on September 1, 2017

Updating Metasploit is quite easy – you just need to run msfupdate command. Later, you might have to be prepared for series of errors while invoking msfconsole. For instance, I had to switch between various commands like bundle install, gem install, apt-get install etc…to fix each error. Well, if you are facing similar issue, then here’s how I solved msfconsole error while launching.

It all started here.

# msfupdate
::::Complete::::

I didn’t get any error while updating Metasploit, but the below error was thrown when I executed msfconsole.

# msfconsole
 Could not find nokogiri-1.6.8 in any of the sources
 Run `bundle install` to install missing gems.

msfconsole error

How to solve msfconsole error after updating Metasploit?

Below are the series of errors and solutions.

Error: Could not find nokogiri-1.6.8 in any of the sources

According to the error message, I understand that there few gems that needs to be installed. So I ran the command suggested along with the error message.

$ sudo bundle install
 extconf failed, exit code 1
 Gem files will remain installed in /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/nokogiri-1.6.8 for inspection.
 Results logged to /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0/nokogiri-1.6.8/gem_make.out
 An error occurred while installing nokogiri (1.6.8), and Bundler cannot
 continue.
 Make sure that `gem install nokogiri -v '1.6.8'` succeeds before bundling.

Error: An error occurred while installing nokogiri (1.6.8), and Bundler cannot continue.

As suggested in the error message, I tried installing nokigiri as shown below.

$ sudo gem install nokogiri -v '1.6 .8'
 Fetching: pkg-config-1.1.7.gem (100%)
 Successfully installed pkg-config-1.1.7
 Fetching: mini_portile2-2.1.0.gem (100%)
 Successfully installed mini_portile2-2.1.0
 Fetching: nokogiri-1.6.8.gem (100%)
 Building native extensions. This could take a while...
 ERROR: Error installing nokogiri:
 ERROR: Failed to build gem native extension.
 /usr/bin/ruby2.2 -r ./siteconf20160920-3175-1au4x8d.rb extconf.rb
 Using pkg-config version 1.1.7
 checking if the C compiler accepts ... yes
 Building nokogiri using packaged libraries.
 Using mini_portile version 2.1.0
 checking for gzdopen() in -lz... no
 zlib is missing; necessary for building libxml2
 *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of necessary
 libraries and/or headers. Check the mkmf.log file for more details. You may
 need configuration options.
 extconf failed, exit code 1
 Gem files will remain installed in /var/lib/gems/2.2.0/gems/nokogiri-1.6.8 for inspection.
 Results logged to /var/lib/gems/2.2.0/extensions/x86_64-linux/2.2.0/nokogiri-1.6.8/gem_make.out

Error: zlib is missing; necessary for building libxml2

Solution: So, I need to install the dependent package zlib before installing nokogiri.

$ sudo apt-get install zlib1g-dev

Now, go back and install nokogiri.

$ sudo gem install nokogiri -v '1.6 .8'

The above command should install nokogiri without much issue. Once nokogiri is installed successfully, get back to bundle install

$sudo bundle install

But again resulted in another error suggesting gem install pg -v ‘0.18.4’

So let us now install pg using gem:

$ sudo gem install pg -v '0.18.4'
 Fetching: pg-0.18.4.gem (100%)
 Building native extensions.  This could take a while...
 ERROR:  Error installing pg:
 ERROR: Failed to build gem native extension.
 /usr/bin/ruby2.2 -r ./siteconf20160920-3810-1fzgcgb.rb extconf.rb
 checking for pg_config... yes
 Using config values from /usr/bin/pg_config
 You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
 You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
 checking for libpq-fe.h... no
 Can't find the 'libpq-fe.h header
 *** extconf.rb failed ***
 Could not create Makefile due to some reason, probably lack of necessary
 libraries and/or headers.  Check the mkmf.log file for more details.  You may
 need configuration options.

Error: Can’t find the ‘libpq-fe.h header

Install libpg-dev package.

$ sudo apt-get install libpq-dev
$ sudo gem install pg -v '0.18.4'
 Building native extensions.  This could take a while...
 Successfully installed pg-0.18.4
 Parsing documentation for pg-0.18.4
 Installing ri documentation for pg-0.18.4
 Done installing documentation for pg after 2 seconds
 1 gem installed

Again bundle install:

$ sudo bundle install
 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
 /usr/bin/ruby2.2 -r ./siteconf20160920-8348-1a1iahe.rb extconf.rb
 [*] Running checks for pcaprub_c code...
 platform is x86_64-linux-gnu
 checking for ruby/thread.h... yes
 checking for rb_thread_blocking_region()... no
 checking for rb_thread_call_without_gvl()... yes
 checking for pcap_open_live() in -lpcap... no
 checking for pcap_setnonblock() in -lpcap... no
 creating Makefile
 make "DESTDIR=" clean
 make "DESTDIR="
 compiling pcaprub.c
 pcaprub.c:11:18: fatal error: pcap.h: No such file or directory
 compilation terminated.
 Makefile:238: recipe for target 'pcaprub.o' failed
 make: *** [pcaprub.o] Error 1
 An error occurred while installing pcaprub (0.12.4), and Bundler cannot continue. Make sure that `gem install pcaprub -v '0.12.4'` succeeds before bundling.

Install pcaprub to solve the above error:

$ sudo gem install pcaprub -v '0.12.4'
 Fetching: pcaprub-0.12.4.gem (100%)
 Building native extensions.  This could take a while...
 ERROR:  Error installing pcaprub:
 ERROR: Failed to build gem native extension.
 /usr/bin/ruby2.2 -r ./siteconf20160920-8986-1sm8qak.rb extconf.rb
 [*] Running checks for pcaprub_c code...
 platform is x86_64-linux-gnu
 checking for ruby/thread.h... yes
 checking for rb_thread_blocking_region()... no
 checking for rb_thread_call_without_gvl()... yes
 checking for pcap_open_live() in -lpcap... no
 checking for pcap_setnonblock() in -lpcap... no
 creating Makefile
 make "DESTDIR=" clean
 make "DESTDIR="
 compiling pcaprub.c
 pcaprub.c:11:18: fatal error: pcap.h: No such file or directory
 compilation terminated.
 Makefile:238: recipe for target 'pcaprub.o' failed
 make: *** [pcaprub.o] Error 1
 make failed, exit code 2
 Gem files will remain installed in /var/lib/gems/2.2.0/gems/pcaprub-0.12.4 for inspection.
 Results logged to /var/lib/gems/2.2.0/extensions/x86_64-linux/2.2.0/pcaprub-0.12.4/gem_make.out

Error : fatal error: pcap.h: No such file or directory

To solve this error, install libpcap-dev package.

$ sudo apt-get install libpcap-dev

Again, gem install pcaprub as shown below:

$ sudo gem install pcaprub -v '0.12.4'
 Building native extensions.  This could take a while...
 Successfully installed pcaprub-0.12.4
 Parsing documentation for pcaprub-0.12.4
 Installing ri documentation for pcaprub-0.12.4
 Done installing documentation for pcaprub after 0 seconds
 1 gem installed

Now, bundle install:

$ sudo bundle install
 Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
 /usr/bin/ruby2.2 -r ./siteconf20160920-13049-rpgoai.rb extconf.rb
 checking for sqlite3.h... no
 sqlite3.h is missing. Try 'port install sqlite3 +universal',
 'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
 and check your shared library search path (the
 location where your sqlite3 shared library is located).
 *** extconf.rb failed ***
 Gem files will remain installed in /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/sqlite3-1.3.11 for inspection.
 Results logged to /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/extensions/x86_64-linux/2.2.0/sqlite3-1.3.11/gem_make.out
 An error occurred while installing sqlite3 (1.3.11), and Bundler cannot continue.
 Make sure that `gem install sqlite3 -v '1.3.11'` succeeds before bundling.

Error: sqlite3.h is missing. Try ‘port install sqlite3 +universal

$ sudo apt-get install libsqlite3-dev

Once libsqlite3-dev is installed successfully, as suggested in the error message gem install sqlite3 -v ‘1.3.11

$ sudo gem install sqlite3 -v '1.3.11'
 Building native extensions.  This could take a while...
 Successfully installed sqlite3-1.3.11
 Parsing documentation for sqlite3-1.3.11
 Installing ri documentation for sqlite3-1.3.11
 Done installing documentation for sqlite3 after 0 seconds
 1 gem installed

So the gem install of sqlite3 is done, executing bundle install again.

$sudo bundle install
 Installing sqlite3 1.3.11 with native extensions
 Installing sshkey 1.8.0
 Installing tzinfo-data 1.2016.6
 Installing windows_error 0.0.2
 Using metasploit-framework 4.12.26 from source at .
 Installing simplecov-html 0.10.0
 Installing simplecov 0.12.0
 Using bundler 1.10.6
 Bundle complete! 14 Gemfile dependencies, 86 gems now installed.
 Gems in the groups development and test were not installed.
 Bundled gems are installed into ./vendor/bundle.

Finally, the bundle install has successfully bundled all gems. Once this is done, I tried executing msfconsole to only end up with another error.

$ msfconsole
 /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require': cannot load such file -- robots (LoadError)
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `block in require'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:240:in `load_dependency'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/dependencies.rb:274:in `require'
 from /usr/share/metasploit-framework/lib/metasploit/framework.rb:18:in `<top (required)>'
 from /usr/share/metasploit-framework/lib/metasploit/framework/database.rb:1:in `require'
 from /usr/share/metasploit-framework/lib/metasploit/framework/database.rb:1:in `<top (required)>'
 from /usr/share/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `require'
 from /usr/share/metasploit-framework/lib/metasploit/framework/parsed_options/base.rb:17:in `<top (required)>'
 from /usr/share/metasploit-framework/lib/metasploit/framework/parsed_options/console.rb:2:in `<top (required)>'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:263:in `const_get'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:263:in `block in constantize'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `each'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `inject'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/inflector/methods.rb:259:in `constantize'
 from /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.7.1/lib/active_support/core_ext/string/inflections.rb:66:in `constantize'
 from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:73:in `parsed_options_class'
 from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:69:in `parsed_options'
 from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:47:in `require_environment!'
 from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:81:in `start'
 from /usr/bin/msfconsole:48:in `<main>'

Solution: Fortunately, there’s a bug reported on this link which says, one of the gems that framework depends has a bug and it was mainly due to permission issue. That message hinted me to execute msfconsole as root user and it worked. But the same command failed for the local user with the above mentioned error.

To fix that, you need to allow the local user to read robots.rb files as shown below:

So I quickly tried to list all robots.rb files available in my system:

# find / -name robots.rb
 /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/robots-0.10.1/lib/robots.rb
 /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/robots-0.10.1/lib/robots.rb
 /var/lib/gems/2.2.0/gems/robots-0.10.1/lib/robots.rb

I’m really not sure to which file the permission should be changed. So I did for all three files listed by the find command.

# chmod o+r /var/lib/gems/2.2.0/gems/robots-0.10.1/lib/robots.rb
 # chmod o+r /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/robots-0.10.1/lib/robots.rb
 #chmod o+r /usr/share/metasploit-framework/vendor/bundle/ruby/2.2.0/gems/robots-0.10.1/lib/robots.rb

Well, I got that info from this page.

That’s it! msfconsole command now works for both the privileged and non-privileged user accounts.

Was this article helpful?

Related Articles

Comments Leave a Comment

Leave a Comment