Making the Netcats module

Get the source for Netcat

For as ubiquitous as Netcat is, you'd think finding the source would be easier. Not so. The original was created by Hobbit of Lopht and At Stake fame. That version hasn't changed in many years. Since Hobbit's original, there have been new versions - a GNU re-write as well as an OpenBSD version, a IP v6 version, etc. I picked two to make modules of and time will tell if I'll add more variants. (Join the mail list and let me know what you think...)

The best place to find the source of the original (since At Stake is long gone), is to grab it from a distro's source package. For Debian-based distros, a pristine source tarball will be called package-version.orig.tar.gz. You can find Netcat's from Debian or Ubuntu for example. Other distros should have the source as well. One reason these are handy is that there are a bunch of patches to the original source to work on more recent Linuxes. With Debian variant packages, you're also guaranteed a man page as well. (Thanks Debian Standards!)

The GNU re-write can be found on SourceForge. You can get the source, MD5sums and a signature file on the main page Get the latest version of:

  • the GNU netcat source (netcat-0.7.1.tar.gz)
  • its signature file (netcat-0.7.1.tar.gz.asc)
  • its md5sums file (md5sums.txt)

Say no to bad downloads and check both the MD5 sums and digital signatures as explained in Checking sources. [PAGE NOT MADE]

The traditional Netcat

Getting what we need for a module is amazingly easy for the traditional netcat. Grab the .deb package and convert it to a .lzm before you move it over to a running OWASP Live CD. This step will need to happen on a Debian/Ubuntu/Debian-variant since it requires the dpkg command:

 $ ./deb2lzm netcat-traditional_1.10-38_i386.deb

This will create a .lzm which we'll move over to a running OWASP Live CD so we can combine that with the GNU version. We'll also modify the contents a bit to remove some Debian-specific bits we don't need

 # scp mtesauro@matt-box.example.com:/home/mtesauro/projects/netcat-traditional.lzm ./
# mkdir fakeroot
# lzm2dir netcat-traditional.lzm fakeroot/
# rm -rf fakeroot/var
# mv fakeroot/bin/nc.traditional fakeroot/bin/nc
# mv fakeroot/usr/share/man/man1/nc_traditional.1.gz fakeroot/usr/share/man/man1/nc.1.gz
# mkdir fakeroot/usr/bin
# mv fakeroot/bin/nc fakeroot/usr/bin/
# rm -rf fakeroot/bin/

OK. We've got what we need for the traditional Netcat. Next is the GNU re-write

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/netcat-0.7.1.tar.gz ./
# tar -xzvf netcat-0.7.1.tar.gz
# cd netcat-0.7.1

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:

 # ./configure
[bunch of output - hopefully ending on a happy note]
# make
# find / > ../pre-netcat
# make install
# find / > ../post-netcat
# cd ../
# diff pre-netcat post-netcat > netcat-diff
# cat netcat-diff | grep changes | grep -v build > netcat-install
# vi netcat-install
[remove any cruft and modify to copy the installed files to /root/fakeroot]
# cat netcat-install
mkdir -p /root/fakeroot/usr/local/share/
cp -a /usr/local/share/locale /root/fakeroot/usr/local/share/

cp -a /usr/local/man/man1/netcat.1 /root/fakeroot/usr/share/man/man1/netcat.1

cp -a /usr/local/bin/netcat /root/fakeroot/usr/bin/netcat
# chmod u+x netcat-install
# ./netcat-install

Create support files in the fakeroot directory

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

 $ vi fakeroot/usr/bin/startup-netcat
[create script]
$ cat fakeroot/usr/bin/startup-netcat
#/bin/sh

echo " /\_/\ "
echo " / 0 0 \ "
echo " ====v===="
echo " \ W /"
echo " | | _ Netcat - The TCP/IP swiss army knife"
echo " / ___ \ / (part of the OWASP Live CD)"
echo " / / \ \ |"
echo "(((-----)))-' There are two netcats included:"
echo " / (1) Hobbit's original - nc"
echo "( ___ (2) A GNU re-write of netcat - netcat"
echo " \__.=|___E"
echo " /"
echo " "
echo " Type 'nc -h' or 'netcat -h for help"
echo " Basic usage:"
echo " connect to somewhere: nc [-options] hostname port[s] [ports] ..."
echo " listen for inbound: nc -l -p port [-options] [hostname] [port]"
echo " - OR -"
echo " connect to somewhere: netcat [options] hostname port [port] ..."
echo " listen for inbound: netcat -l -p port [options] [hostname] [port] ..."
echo " tunnel to somewhere: netcat -L hostname:port -p port [options]"
echo " "
echo " If unsure, go with 'nc' its a great old tool"

Now a menu item:

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

For the icon, I wasn't quite sure what to do. I grabbed a Swiss Army logo (like on the knives) and used a little Gimp-foo to come up with the icon. Then, I moved that into fakeroot.

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

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/ netcats.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 [PAGE NOT MADE] 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 netcat works as expected.

# nc -l -p 20

Then use the following to connect from a remote port

nc [IP of Live CD] 20

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 netcats.lzm ../contents/slax/base/
$ chmod 775 ../contents/slax/base/netcats.lzm

This assumes your netcats module was moved into your working directory.  See Creating the base Live CD from SLAX (Create a Working Directory section)

Clean up and archive

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

 $ $ mkdir ./completed_modules/netcats
$ mv netcats.lzm ./completed_modules/netcats/
$ mv temp/netcat ./completed_modules/netcats/
$ rm -rf ./temp/*