Making Spike Proxy module

From OWASP Live CD 2008

Jump to: navigation, search

Contents

Get the source for Spike Proxy

Spike Proxy is hosted here and includes direct links to the releases for various platforms. You'd be tempted to grab the latest tgz for Linux and start there. That's what I did. That was not a happy decision. Spike Proxy is from ~2004 and is written for Python 2.2. Python is currently at 2.6 or 3.0 depending on how brave you are. I had tons of issues with running it on my regular Linux box, let alone the OWASP Live CD. There were issues with the characters set (more here) - in particular line 91 in ./ntlm/md4.py and line 22 in./ntlm/des_c.py. I then realized that Spike Proxy was in the Debian/Ubuntu repos - and it worked fine. This told me that someone had already gone through the pain of patching Spike Proxy. (And I don't have to). So I grabbed the .deb from here. We'll use that to build the lzm.

Create the necessary files in the fakeroot directory

First lets create a .lzm from the .deb on a system running Ubuntu/Debian since it required dpkg:

 $ cp temp/spikeproxy_1.4.8-4_all.deb ./
 $ ./deb2lzm spikeproxy_1.4.8-4_all.deb spikeproxy-1.4.8-4.lzm

Now lets get that .lzm over to a running OWASP Live CD and see what we've got:

 # scp mtesauro@mybox.example.com:/home/mtesauro/projects/spikeproxy-1.4.8-4.lzm ./
 # mkdir fakeroot
 # lzm2dir spikeproxy-1.4.8-4.lzm fakeroot
 # find fakeroot/ | less

First some cleanup of Ubuntu/Debian specific stuff we don't need:

 # rm -rf fakeroot/var/lib
 # vi fakeroot/usr/bin/spikeproxy
     [minor edit to change DATADIR]
 # cat fakeroot/usr/bin/spikeproxy
#!/bin/sh

DATADIR=/opt/owasp/spikeproxy/         
if [ ! -d "$DATADIR" ] ; then
        echo "ERR: Cannot find $DATADIR, is spikeproxy properly installed?"
        exit 1
fi

cd $DATADIR
./spkproxy.py -p 8068 "$@" | tee /root/tools/spikeproxy/spikeproxy.log

 # mkdir -p fakeroot/opt/owasp
 # vi fakeroot/usr/share/python-support/spikeproxy.dirs
     [minor edit to change a path]
 # cat fakeroot/usr/share/python-support/spikeproxy.dirs
/opt/owasp/spikeproxy
 # chmod 775 fakeroot/usr/bin/spikeproxy

Ubuntu had Spike Proxy in /usr/share/spikeproxy. That's nice and all but I want it somewhere else. Mainly /opt/owasp

 # mkdir fakeroot/opt/owasp
 # mv fakeroot/usr/share/spikeproxy fakeroot/opt/owasp

Here's where the fun starts. Spike Proxy is still barfing. After a bit of digging and fixing, I got is working with the following modifications:

  • line 91 in ./ntlm/md4.py
  • line 22 in./ntlm/des_c.py
  • line 96 & 485 in ./spikeProxyUI.py

I created a patch to handle this now and in future. Here's the process for making the patch & applying the patch:

  • create a duplicate of the current fakeroot. I called the one copy 'original' and one copy 'new'
  • edit the necessary files
  • take a diff of the two directories like:
 # diff -crB original/ new/ > spikeproxy-owasplivecd.patch
  • test the patch and if successful, patch the original directory. Diff of them now should show no difference.
 # cd original
 # patch --dry-run -p1 -i ../spikeproxy-owasplivecd.patch
patching file opt/owasp/spikeproxy/ntlm/des_c.py
patching file opt/owasp/spikeproxy/ntlm/md4.py
patching file opt/owasp/spikeproxy/spikeProxyUI.py
     [ notice that the patch appears to cleanly apply and only changes the necessary files ]
 # patch -p1 -i ../spikeproxy-owasplivecd.patch
 # cd ../
 # diff -crB original/ new/
 # 

OK. We've got a patch that works as advertised. We're good to proceed. BTW, you can get the patch here

We'll need a script to make spikeproxy available in our path, so lets do that next. This is a modified version of what we got from the Ubuntu package:

 # mkdir -p fakeroot/usr/bin
 # vi fakeroot/usr/bin/spikeproxy
   [create script]
 # cat fakeroot/usr/bin/spikeproxy
#!/bin/sh

DATADIR=/opt/owasp/spikeproxy/
if [ ! -d "$DATADIR" ] ; then
	echo "ERR: Cannot find $DATADIR, is spikeproxy properly installed?"
	exit 1
fi

cd $DATADIR
./spkproxy.py -p 8068 "$@" 2>&1 > /root/tools/spikeproxy/spikeproxy-`date +%B-%d-%Y_%R`.log &

# Open the launch page in Firefox
firefox file:///opt/owasp/spikeproxy/spikeproxy-launch-page/start-spike-proxy.html

 # chmod 775 fakeroot/usr/bin/spikeproxy

Careful observers will notice that I have Firefox opening some static html page. Because Spike Proxy isn't like the other proxies on the OWASP Live CD, we're going to create a page to open in the browser. Thing is that not only does it proxy http/https, but the GUI is a web application. The launch page currently doesn't exist, so lets make that.

 # mkdir -p /fakeroot/opt/owasp/spikeproxy/spikeproxy-launch-page
 # vi /fakeroot/opt/owasp/spikeproxy/spikeproxy-launch-page/start-spike-proxy.html
     [create a nice web page with the necessary info]

There's more to this web page than I feel like typing so I've tarballed it and put it here.

Now a menu item:

 $ mkdir fakeroot/usr/share/applications
 $ vi fakeroot/usr/share/applications/spikeproxy.desktop
   [create the file]
 $ cat fakeroot/usr/share/applications/spikeproxy.desktop 
[Desktop Entry]
Categories=Application;Network;
Comment=
Encoding=UTF-8
Exec[$e]=spikeproxy
GenericName=Spike Proxy
Icon=/usr/share/pixmaps/spikeproxy-icon.png
MimeType=text/html
Name=Local Proxy
Path[$e]=
StartupNotify=false
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 an image of a spike mace 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/spikeproxy-icon.png fakeroot/usr/share/pixmaps/

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/ spikeproxy-1.4.8-4.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. I fired up Spike Proxy to make sure everything went as expected.

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

This assumes your Spike Proxy 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/spikeproxy
 $ mv spikeproxy-1.4.8-4.lzm ./completed_modules/spikeproxy/
 $ mv temp/spikeproxy_1.4.8-4_all.deb ./completed_modules/spikeproxy/
 $ rm -rf ./temp/*