Fixing MySQL Gem Errors in BT4

8 01 2011

Armitage is a new GUI for Metasploit, which is very interactive and makes hacking or like white-hats call it pen-testing real easy.

To install Armitage, all you have to do is download it and run it on Linux using the following command:
./armitage.sh

The reason I’m writing this blog is that while trying to run it with Metasploit and MySQL, I came across two errors and it took me a while to find the answers.

I was trying to install Armitage on Backtrack4, not 4r2 version for which the instructions are available here.

So the first error i was getting was when installing the gem mysql. The gem is required if you want to use MySQL database. When I tried installing the gem in Metasploit itself or in shell I was getting the following error:

ERROR: could not find gem mysql locally or in a repository

So I need to update the gem repository and I tried:
gem update --system

This returned an error:
ERROR: While executing gem ... (RuntimeError)
gem update --system is disabled on Debian. RubyGems can be updated using the
official Debian repositories by aptitude or apt-get.

Wandered on the Interwebs for a while and found no solution. So I tried updating the ruby gems by doing:

apt-get install rubygems

And this updated the package and the following command now worked:

gem install mysql

But wait, I’m still not able to connect to the MySQL database in Metasploit or Armitage, when I run the following command:

msf > db_connect root:toor@127.0.0.1/msf3

The error I get is:


[-] Error while running command db_connect: Failed to connect to the database: uninitialized constant MysqlCompat::MysqlRes

Call stack:
/opt/metasploit3/msf3/lib/msf/ui/console/command_dispatcher/db.rb:1702:in `db_connect_mysql'
/opt/metasploit3/msf3/lib/msf/ui/console/command_dispatcher/db.rb:1548:in `cmd_db_connect'
/opt/metasploit3/msf3/lib/rex/ui/text/dispatcher_shell.rb:246:in `run_command'
/opt/metasploit3/msf3/lib/rex/ui/text/dispatcher_shell.rb:208:in `block in run_single'
/opt/metasploit3/msf3/lib/rex/ui/text/dispatcher_shell.rb:202:in `each'
/opt/metasploit3/msf3/lib/rex/ui/text/dispatcher_shell.rb:202:in `run_single'
/opt/metasploit3/msf3/lib/rex/ui/text/shell.rb:143:in `run'
/opt/metasploit3/msf3/msfconsole:128:in `'

WTF…
Searched for the error on Google and found an article on how to resolve this error on Mac OS X. Unix Linux same shit. Knew it will work. So ran the following command:

sudo gem install --no-rdoc --no-ri -v=2.7 mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/bin/mysql_config

It worked and Armitage now successfully connected to the Metaploit db in MySQL.

Happy Hacking!


Actions

Information

5 responses

8 01 2011
Armitage Hacker

Good post. I get questions about database connectivity all the time. Sadly, there isn’t much I can do to smooth out the process more. I’ve added your link to my FAQ page.

12 01 2011
Matthias

Hey, just read this post and tried to fix my “[-] Invalid driver specified” problem at armitage. The normal msfconsole has no problem connecting to mysql after executing “gem install mysql”.
But Armitage doesn’t work because of this “[-] Invalid driver specified” problem. I can’t load the mysql driver with db_driver in armitage and can’t before that install mysql with “gem install mysql”. So how do I geht the driver?
Thanks for help!

13 01 2011
baber

Do you have sun jre or jdk installed? If yes then try this in bash on BT4:
sudo gem install –no-rdoc –no-ri -v=2.7 mysql — –with-mysql-dir=/usr/local/mysql –with-mysql-config=/usr/bin/mysql_config

It worked for me.

22 03 2011
JC

This is great!

I experienced the same errors and everything you got but unfortunately at the very end I still had an issue. After I ran the command:

sudo gem install –no-rdoc –no-ri -v=2.7 mysql — –with-mysql-dir=/usr/local/mysql –with-mysql-config=/usr/bin/mysql_config

I was able to connect to the db with this command:

msf > db_connect root:toor@127.0.0.1/msf3

but when I go to run armitage:

root@bt:/# pentest/exploits/framework3/armitage

And choose “start msf” I will still get the [-] Invalid driver specified error.

I stopped and started mysql and am able to successfully add the mysql driver but still no go.

So to recap I am able to connect to the database via msfconsole but when it comes to connecting via Armitage, I get a driver error and no db connection. I feel like I am close but just missing something.

Any ideas? I will continue to troubleshoot.

Thanks again!

JC

22 03 2011
JC

Same thing Matthias is having. Would help if I read the previous post more carefully – Sorry about that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.