Making the Metasploit 3 moduleSubmitted by mtesauro on Fri, 04/24/2009 - 23:53 |
Get the Source for Metasploit Framework 3
While you can go to the Metasploit Framework website and which has a link to the latest tarball, I didn't do that. Instead, I used subversion to pull the latest version directly from the project's Subversion trunk. Not only will you get the latest, greatest Metasploit has to offer, but you'll also be able to easily update the software again.
Go ahead and pull down the trunk into the temporary directory
$ cd temp/
$ svn co http://metasploit.com/svn/framework3/trunk/
$ cd ../
Create the needed directories in fakeroot
Eventually, we'll use dir2lzm to make the module, so lets get the directories created that we need:
$ mkdir -p ./fakeroot/opt/owasp/
$ mkdir -p ./fakeroot/usr/bin
$ mkdir -p ./fakeroot/usr/share/aplications
$ mkdir -p ./fakeroot/usr/share/pixmaps
Create and put the module's files into the fakeroot directory
Since we are getting Ruby source, lets get the application files where they needs to go.
$ mv temp/trunk fakeroot/opt/owasp/
$ mv fakeroot/opt/owasp/trunk fakeroot/opt/owasp/metasploit3
Next, well need some scripts to start the various bits of Metasploit 3 in fakeroot/usr/bin. The first two are pretty easy:
$ vi fakeroot/usr/bin/msfcli
[create script]
$ cat fakeroot/usr/bin/msfcli
#!/bin/sh
/opt/owasp/metasploit3/msfcli "$@"
$ vi fakeroot/usr/bin/msfconsole
[create script]
$ cat fakeroot/usr/bin/msfconsole
#!/bin/sh
/opt/owasp/metasploit3/msfconsole "$@"
$ vi fakeroot/usr/bin/msfweb
[create script]
$ cat fakeroot/usr/bin/msfweb
#!/bin/sh
case "$1" in
start)
screen -d -m /opt/owasp/metasploit3/msfweb
pidof SCREEN > /tmp/msfweb.pid
echo "Starting MSFWeb on port 55555" | \
osd_cat -p top -A center --font=-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1 --delay=3
sleep 3
firefox http://127.0.0.1:55555 &
sleep 4
echo "Remember to be nice to others ; )" | \
osd_cat -p middle -A center --font=-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1 --delay=3
;;
stop)
echo "Stopping MSFWeb" | \
osd_cat -p top -A center --font=-adobe-helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1 --delay=5
kill -9 `cat /tmp/msfweb.pid | cut -f 2 -d " "`
rm -f /tmp/msfweb.pid
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
$ chmod 775 fakeroot/usr/bin/msf*
Because parts of Metasploit 3 are command line tools, we're going to create two startup scripts to be used by the menu items for msfcli
$ vi fakeroot/usr/bin/startup-msfcli
[create script]
$ cat fakeroot/usr/bin/startup-msfcli
#/bin/sh
echo " "
echo " "
echo " Metasploit Framework 3 - An Equil Opportunity Exploiter"
echo " msfcli - command line interface"
echo " (part of the OWASP Live CD 2008)"
echo " "
echo "Usage: msfcli <exploit_name> <option=value> [mode]"
echo "========================================================================="
echo " "
echo " Mode Description"
echo " ---- -----------"
echo " (H)elp You're looking at it baby!"
echo " (S)ummary Show information about this module"
echo " (O)ptions Show available options for this module"
echo " (A)dvanced Show available advanced options for this module"
echo " (I)DS Evasion Show available ids evasion options for this module"
echo " (P)ayloads Show available payloads for this module"
echo " (T)argets Show available targets for this exploit module"
echo " (AC)tions Show available actions for this auxiliary module"
echo " (C)heck Run the check routine of the selected module"
echo " (E)xecute Execute the selected module"
echo " "
and msfconsole.
$ vi fakeroot/usr/bin/startup-msfconsole
[create script]
$ cat fakeroot/usr/bin/startup-msfconsole
#/bin/sh
echo " "
echo " "
echo " Metasploit Framework 3 - An Equil Opportunity Exploiter"
echo " msfconsole - Interactive Metasploit Console"
echo " (part of the OWASP Live CD 2008)"
echo " "
echo " ## ### ## ##"
echo " ## ## #### ###### #### ##### ##### ## #### ######"
echo " ####### ## ## ## ## ## ## ## ## ## ## ### ##"
echo " ####### ###### ## ##### #### ## ## ## ## ## ## ##"
echo " ## # ## ## ## ## ## ## ##### ## ## ## ## ##"
echo " ## ## #### ### ##### ##### ## #### #### #### ###"
echo " ##"
echo " "
echo " Type 'msfconsole --help' to get help "
echo " or get started with 'msfconsole"
echo " "
Creating Metasploit's four menu item is a bit more complex since two of them open in a terminal. Use a text editor and create the files:
msfcli.desktop
$ vi fakeroot/usr/share/applications/msfcli.desktop
[create the file]
$ cat fakeroot/usr/share/applications/msfcli.desktop
[Desktop Entry]
Categories=Application;Network;
Comment=
Encoding=UTF-8
Exec[$e]=startup-msfcli; bash
GenericName=msfcli
Icon=/usr/share/pixmaps/metasploit-icon.png
MimeType=text/html
Name=Metasploit Command Line Interface
Path[$e]=
StartupNotify=false
Terminal=1
TerminalOptions=-T "Metasploit 3 - Command Line Interface"
Type=Application
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
and msfconsole.desktop
$ vi fakeroot/usr/share/applications/msfconsole.desktop
[create the file]
$ cat fakeroot/usr/share/applications/msfconsole.desktop
[Desktop Entry]
Categories=Application;Network;
Comment=
Encoding=UTF-8
Exec[$e]=startup-msfconsole; bash
GenericName=msfconsole
Icon=/usr/share/pixmaps/metasploit-icon.png
MimeType=text/html
Name=Metasploit Interactive Console
Path[$e]=
StartupNotify=false
Terminal=1
TerminalOptions=-T "Metasploit 3 - Interactive Console"
Type=Application
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
and msfweb-start.desktop
$ vi fakeroot/usr/share/applications/msfweb-start.desktop
[create the file]
$ cat fakeroot/usr/share/applications/msfweb-start.desktop
[Desktop Entry]
Encoding=UTF-8
Exec=msfweb start
Icon=/usr/share/pixmaps/metasploit-icon.png
Type=Application
Categories=Application;Network;
Name=Metasploit Web Interface
Name[cs]=Metasploit Web Interface
GenericName=Start msfweb
GenericName[cs]=Start msfweb
MimeType=text/html
X-KDE-StartupNotify=true
and msfweb-stop.desktop
$ vi fakeroot/usr/share/applications/msfweb-stop.desktop
[create the file]
$ cat fakeroot/usr/share/applications/msfweb-stop.desktop
[Desktop Entry]
Encoding=UTF-8
Exec=msfweb stop
Icon=/usr/share/pixmaps/metasploit-icon.png
Type=Application
Categories=Application;Network;
Name=Metasploit Web Interface
Name[cs]=Metasploit Web Interface
GenericName=Stop msfweb
GenericName[cs]=Stop msfweb
MimeType=text/html
X-KDE-StartupNotify=true
For the icon, I wasn't quite sure what to sue. I tried to make something of the Metasploit ICBM logo but by the time you got it down to icon size, it was a mess. I settled on the "M" from the Metasploit which displays as the default theme for msfweb. Did a little Gimp-foo and then moved that into fakeroot.
$ cp temp/metasploit-icon.png fakeroot/usr/share/pixmaps/metasploit-icon.png
Metasploit 3 requires Ruby. I also wanted Subversion so you could update the framework. Finally, this module is best with xosd (xosd-2.2.12.lzm) and Firefox (firefox3.lzm) as I use both in the msfweb startup script. All those modules exist already. You can read about Making the Subversion client module [PAGE NOT MADE] and Making the Ruby module [PAGE NOT MADE] if your curious.
As an added bonus, lets create an easy way to update your Metasploit Framework. First a script to actually do that:
$ vi fakeroot/usr/bin/update-msf
[create script]
$ cat fakeroot/usr/bin/update-msf
#!/bin/sh
cd /opt/owasp/metasploit3/
svn update
and a script to all from the menu:
vi fakeroot/usr/bin/startup-update-msf
[create script]
$ cat fakeroot/usr/bin/startup-update-msf
#/bin/sh
echo " "
echo " "
echo " Metasploit Framework 3 - An Equil Opportunity Exploiter"
echo " Update the Metasploit Framework 3"
echo " (part of the OWASP Live CD 2008)"
echo " "
echo " "
echo " Subversion + Metasploit = Always hot exploits. Always "
echo " Get started with 'update-msf"
echo " "
echo " A message like 'At revision XXXX' means you are up to date"
echo " "
and a menu item too:
$ vi fakeroot/usr/share/applications/update-msf.desktop
[create the file]
$ cat fakeroot/usr/share/applications/update-msf.desktop
[Desktop Entry]
Categories=Application;Network;
Comment=
Encoding=UTF-8
Exec[$e]=startup-update-msf; bash
GenericName=update-msf
Icon=/usr/share/pixmaps/metasploit-icon.png
MimeType=text/html
Name=Update Metasploit Framework 3
Path[$e]=
StartupNotify=false
Terminal=1
TerminalOptions=-T "Metasploit 3 - Updating the goodness"
Type=Application
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=
Everything is in place to create the module, a quick final check:
find fakeroot
fakeroot/
fakeroot/opt
fakeroot/opt/owasp
fakeroot/opt/owasp/metasploit3
fakeroot/opt/owasp/metasploit3/plugins
fakeroot/opt/owasp/metasploit3/plugins/msfd.rb
...
Generate the .lzm module
This is the easy part.
$ ./dir2lzm ./fakeroot metasploit3-svn-2008-09-06.lzm
Add the modules to the ISO build directory
Also cake
$ cp -i metasploit3-svn-2008-09-06.lzm ../contents/slax/base/
$ chmod 775 ../contents/slax/base/metasploit3-svn-2008-09-06.lzm
Test the new module
I like scp'ing the new modules into a running Live CD and using the Module Manager to Add modules to a running system. [PAGE NOT MADE] I typically have the Live CD running in a VM while I create modules so its already up and ready.
You can also gen a new ISO and run it in a VM of your choice.
$ cd ../contents/slax/
$ ./make_iso.sh /home/mtesauro/isos/new-owasp.iso
If anything doesn't work as expected, make the changes needed to ./fakeroot and try again.
Clean up and archive
Once you've got a working module, lets clean up a bit.
$ $ mkdir ./completed_modules/metasploit3
$ mv metasploit3-svn-2008-09-06.lzm ./completed_modules/metasploit3/
$ rm -rf ./temp/*
I usually delete anything under ./fakeroot also.
$ rm -rf ./fakeroot/*
