Making nmap module

From OWASP Live CD 2008

Jump to: navigation, search

Contents

Get the source for nmap

Go to Fyodor's nmap download page and grab the latest bzip2 (tar.bz2) file which at the time of this writing is nmap-4.76.tar.bz2. There are also digest files and signature files to download with the source. Those are (in this case) nmap-4.76.tar.bz2.digest.txt and nmap-4.76.tar.bz2.gpg.txt. There's a handy page on verifying your downloads here and the download directory is here.

Say no to bad downloads and check both the digests and digital signatures demonstrated below and explained in Checking sources.

 $ cd temp/
 $ sha1sum nmap-4.76.tar.bz2 >> nmap-4.76.tar.bz2.digest.txt 
 $ vi nmap-4.76.tar.bz2.digest.txt 
     [look at the appended digest and compare to those from the site]
 $ gpg --verify nmap-4.76.tar.bz2.gpg.txt nmap-4.76.tar.bz2
gpg: Signature made Fri 12 Sep 2008 04:03:59 AM CDT using DSA key ID 6B9355D0
gpg: Good signature from "Nmap Project Signing Key (http://www.insecure.org/)"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 436D 66AB 9A79 8425 FDA0  E3F8 01AF 9F03 6B93 55D0

The above indicates a valid download - the warning tells me that I've not marked the nmap key as trusted. However, me trusting (or not) that key has nothing to do with the validity of the download. So now that we know the source hasn't been diddled with...

Compile the source and complete the package

Since we're doing this from source, its best to download the source into a running version of the Live CD. We can then do the compilation there to make sure the Live CD has all the necessary dependencies.

First get the source into the Live CD. Since you've verified the signatures, scp them over from your primary box and then extract both files in the same directory

 # mkdir build
 # cd build
 # scp matt@matt-box.example.com:/home/matt/download/nmap-4.76.tar.bz2 ./
 # tar -xzvf nmap-4.76.tar.bz2
 # cd nmap-4.76

So far so good. Now to get this guy install, all we really need to do is the 3 step Linux install dance - with a special variation I've come to prefer - two finds and a diff. We'll also specify some configure directives to get the architecture-dependent files into /opt/owasp/nmap.

 # ./configure --exec-prefix=/opt/owasp/nmap --sysconfdir=/opt/owasp/nmap/etc --sharedstatedir=/opt/owasp/nmap/com --localstatedir=/opt/owasp/nmap/var 
     [bunch of output - hopefully ending on a happy note]
 # make
 # find / > ../pre-nmap
 # make install
 # find / > ../post-nmap
 # cd ../
 # diff pre-nmap post-nmap > nmap-diff
 # cat nmap-diff | grep changes | grep -v build > nmap-install
 # vi nmap-install
    [remove any cruft and modify to copy the installed files to /root/fakeroot]
 # head -n 7 nmap-install

mkdir -p /root/fakeroot/opt/owasp
cp -a /opt/owasp/nmap /root/fakeroot/opt/owasp

cp -a /usr/local/bin/uninstall_zenmap /root/fakeroot/opt/owasp/bin
cp -a /usr/local/bin/zenmap /root/fakeroot/opt/owasp/bin

 # chmod u+x nmap-install
 # ./nmap-install

Create support files in the fakeroot directory

Because nmap is a command line tool, we're going to create two startup scripts to be used by the menu item:

 # mkdir -p fakeroot/usr/bin
 # vi fakeroot/usr/bin/startup-nmap
   [create script]
 # cat fakeroot/usr/bin/startup-nmap 
#/bin/sh

echo "    __  "
echo "   (  )   /\   _                 (     "
echo "     \ |  (  \ ( \.(               )                      _____ "
echo "   \  \ \  \`  \`   ) \             (  ___                 / _   \ "
echo "  (_\`    \+   . x  ( .\            \/   \____-----------/ (o)   \_ "
echo " - .-               \+  ;          (  O                           \____ "
echo "                           )        \_____________  \`              \  / "
echo " (__                +- .( -'.- <. - _  VVVVVVV VV V\                 \/ "
echo " (_____            ._._: <_ - <- _  (--  _AAAAAAA__A_/                | "
echo "   .    /./.+-  . .- /  +--  - .     \______________//_              \_______ "
echo "   (__ ' /x  / x _/ (                                  \___'          \     / "
echo "  , x / ( '  . / .  /                                      |           \   / "
echo "     /  /  _/ /    +                                      /              \/ "
echo "    '  (__/                                             /                  \ "
echo "              NMAP IS A POWERFUL TOOL -- USE CAREFULLY AND RESPONSIBLY "
echo " "
echo "      nmap - Utility for network exploration or security auditing"
echo "               (part of the OWASP Live CD 2008)"
echo " "
echo "      Nmap 4.76 ( http://nmap.org )"
echo "      Usage: nmap [Scan Type(s)] [Options] {target specification}"
echo " "
echo "  Type 'nmap -h' for brief help or 'man nmap' for more info"
echo ""

 # chmod 775 fakeroot/usr/bin/startup-nmap

Now a menu item:

 $ mkdir fakeroot/usr/share/applications
 $ vi fakeroot/usr/share/applications/nmap.desktop
   [create the file]
 $ cat fakeroot/usr/share/applications/nmap.desktop 
[Desktop Entry]
Categories=Application;Network;
Comment=
Encoding=UTF-8
Exec[$e]=startup-nmap; bash
GenericName=nmap
Icon=/usr/share/pixmaps/nmap-icon.png
MimeType=text/html
Name=Network Mapper
Path[$e]=
StartupNotify=false
Terminal=1
TerminalOptions=-T "nmap - THE network mapper"
Type=Application
X-KDE-StartupNotify=true
X-KDE-SubstituteUID=false
X-KDE-Username=

Lets get nmap in the path with this script:

 # vi fakeroot/usr/bin/nmap
 # cat fakeroot/usr/bin/nmap
#!/bin/sh

cd /opt/owasp/nmap/bin
./nmap "$@"

For the icon, The make install included the eyeball image off the nmap site so we'll just use that. I moved that into fakeroot.

  mkdir fakeroot/usr/share/pixmaps
 $ cp temp/nnmap-icon.png fakeroot/usr/share/pixmaps/nmap-icon.png

OK. That's got nmap done but what about Zenmap?

First we've got to modify a line of the Zenmap config file (zenmap.conf) to make sure it can find our relocated nmap binary. Look for the line with only [paths] in it. That was line 70 in my case. Change the line which follows to reflect the new location:

 # vi fakeroot/usr/local/share/zenmap/zenmap/config/zenmap.config
     [find the "nmap_command_path =" bit and make sure it points correctly]
 # cat fakeroot/usr/local/share/zenmap/zenmap/config/zenmap.config | grep nmap_command_path
nmap_command_path = /opt/owasp/nmap/bin/nmap
 # 

We don't need to make a menu item from scratch since the make, make install gave us one. But, we'll move the .desktop file to the usual place and tweak it a bit:

 # mv fakeroot/usr/local/share/applications/zenmap.desktop fakeroot/usr/share/applications/zenmap.desktop
 # rm -rf fakeroot/usr/local/share/applications
 # vi fakeroot/usr/share/applications/zenmap.desktop
     [make a few changes]
 # cat fakeroot/usr/share/applications/zenmap.desktop
[Desktop Entry]
Encoding=UTF-8
Name=GUI Port Scanner
GenericName=Zenmap
TryExec=zenmap
Exec=zenmap %F
Terminal=false
Icon=/usr/share/pixmaps/zenmap-icon.png        
Type=Application
Categories=Application;Network;
Comment=A cross-platform GUI for the Nmap Security Scanner.

The icon we get with the source is just the eye and I wanted a slightly different icon for Zenmap. So, I took the eye, did some gimp-foo and moved the resulting .png into fakeroot:

 # mv temp/zenmap-icon.png fakeroot/usr/share/pixmaps/

We also need to get zenmap into our path. Let do that quick:

 # vi fakeroot/usr/bin/zenmap
 # cat fakeroot/usr/bin/zenmap
#!/bin/sh

cd /opt/owasp/nmap/bin
./zenmap "$@"

Note: I'm not bothering to put uninstal_zenmap into the path since that isn't likely to be used.

We should now have everything we need in fakeroot. Give it a final sanity check, then create a new module based on what's in fakeroot:

 # find fakeroot/ | less
 # dir2lzm fakeroot/ nmap_Zenmap-4.76.lzm

Test the new modules

SLAX will allow you to add modules to a running system. Before going on, you should install the module and make sure it works like expected. Check out the page Add modules to a running system to see how to do this. Since I had to do a make install before I created the module, I used a freshly booted Live CD to test the module. Verify that nmap works as expected.

# nmap -v -sS -F [IP Address to scan]

If everything goes as expected, you'll need to add this module to the ISO image. Since we've created the module in the Live CD, you'll need to move it off to a "real" computer. You can use a USB drive, scp or whatever to get the files off the Live CD.

Add the modules to the ISO build directory

Also cake

 $ cp -i nmap_Zenmap-4.76.lzm ../contents/slax/base/
 $ chmod 775 ../contents/slax/base/nmap_Zenmap-4.76.lzm

This assumes your nmap module was moved into your working directory. See How I created the live CD#Create_a_Working_Directory

Clean up and archive

Once you've got a working module, lets clean up a bit.

 $ $ mkdir ./completed_modules/nmap
 $ mv nmap_Zenmap-4.76.lzm ./completed_modules/nmas/
 $ mv temp/nmap-4.76.tar.bz2* completed_modules/nmap/
 $ mv temp/install-nmap completed_modules/nmap/
 $ rm -rf ./temp/*
Personal tools