2012-04-08

Mallory MiTM Proxy as a Wireless Access Point (Part 2 of 2)

In Part 1 we got an Virtual Machine partially running as a wireless access point using Virtual Box, Ubuntu, hostapd, and an Alfa wifi card. In this Post we will fully configure the AP and install/configure Mallory to MiTM anything that connects to the virtual Wireless Access Point.


Create An AccessPoint Startup Script

We have one more prerequisite before we can continue. We need to create a network bridge so the access point can connect to the NAT'ed ethernet adaptor. If its not already installed go ahead and install bridge-utils.

> sudo apt-get install bridge-utils


In your home folder create a file named startAP.sh and enter the following text.


   #!/bin/bash
   # stop the network manager
   stop network-manager
   #create the bridge and add eth0 
   brctl addbr br0
   brctl addif br0 eth0
   #Start the Access Point
   hostapd -B ./rtl_hostapd.conf > /var/log/hostapd.log
   # wait for AP to come online before adding it to the bridge   
   sleep 5
   #Add the wireless AP to the bridge
   brctl addif br0 wlan0
   dhclient br0


Run your script.


> chmod 755 ./startAP
> sudo ./startAP





*NOTE: ensure the birdge=br0 is somewhere in your hostapd config file. 


You should now have a fully configured Wireless access point. Try to get you mobile device or other computer to connect to the internet through this access point. In some instances you will have to manually add your IP address on the device. Usually setting something like the following will work: 


IP Address: 10.0.2.17 
SubnetMask: 255.255.255.0
Router: 10.0.2.2
DNS: 8.8.8.8


Mallory Installation Steps

In the virtual machine that was created in Part 1 you must drop to a terminal and first install mercurial before anything else.

> sudo apt-get install mercurial


Now determine a directory where you want to install and run Mallory. I like having it in my home Dir so thats where the rest of this tutorial will make reference to it.


> cd ~
> hg clone https://bitbucket.org/IntrepidusGroup/mallory
> cd mallory
> sudo ./mallory_install.sh
> sudo ./mallory_install.sh


The first time you run the installation script it will ask you to verify you have an internet connection. Once you verify you just run the same script again and it will download and install all of the dependencies.


Lets MiTM some traffic!!!

Finally the fun happens! We need to start the Mallory core process and then the Mallory GUI while the AP is running.


> cd  ~/mallory/current/src
> sudo python ./mallory.py
Open another terminal and type:
> sudo python ./launchgui.py


Once the GUI comes up Select the Interfaces Tab and ensure that br0 is checked for  "Perform MiTM" and eth0 is checked for "Outbound Interface" and Click Apply.


Select the Protocols tab and uncomment the line starting with ssl_2 and Click Apply.


Click the Rules tab and ensure that Debug All is the current rule if not create it by copying the setting in the following ScreenShot.







Now Click on Streams and click "Intercept" and "AutoSend". After this you can navigate to some site on your phones browser and you should see the streams populating to the screen.






Additional Set Up

Strip Encoding


There are a few things your going to want to do here to really MiTM some traffic. First your going to want to create a rule that strips encoding on web pages since mallory does not automatically decode these like Burp Suite does. 
  1. Select the Rules tab.
  2. Set the Name to "Strip Encoding".
  3. Direction C2S (Client to Server)
  4. The Type is Muck
  5. Enter Accept-Encoding: gzip.*/Header: fake/1 into the Muck textbox.
  6. Passthu = yes
  7. Move "Strip Encoding" to the top.

Now Mallory will send "Header: fake" instead of "Accept-Encoding: gzip,deflate" on all HTTP requests which prevents the server from sending a compressed response (i.e. you can read the responses it in Mallory's Streams tab now).


Install the CA Cert on a mobile device

The next thing you will want to do is add Mallory's CA cert to your device. This is how you can intercept SSL traffic without the mobile device giving you SSL warnings or some apps will not connect at all if the certs are not signed by a trusted CA. 

The Mallory CA is located in ~/mallory/current/src/ca/ca.cer. If your intercepting traffic on IOS you can just email this cert to yourself, open the attachment with the IOS mail client, and select install. Now you can intercept SSL traffic with IOS apps that do certificate checks (and almost all do). On Android devices you need to install this certificate into /etc/security/cacerts.bks. You will need to jailbreak the device to do this and you will need the android SDK. There are already alot of articles on this so i'm not going to go into detail here. Maybe in another post.


Thats it. Good Luck! :)



2012-04-07

Mallory MiTM Proxy as a Wireless Access Point (Part 1 of 2)

Mallory MiTM Proxy is great tool if you need to intercept and modify non HTTP connections. I generally use this tool while doing mobile assessments to get an idea of all the connections the device is performing in the background. It allows you to intercept most types of tcp and udp connections and has special translators for HTTP protocols. I still prefer using BurpSuite for HTTP protocols but since Mallory understands protocols  that BurpSuite does not it reamins a great tool to have on your side.

There are a ton of ways to setup and configure Mallory. The easiest is as a VPN but I feel the wireless access point is more robust and easier to get your devices proxing through it once you have it set up.

Create a Virtual Machine Wireless Access Point

I created a new Ubuntu Virtual Machine to act as my MiTM Wireless Access Point with VirtualBox as the host. I like the virtual machine approach because I can save the state and start anew with each new assessment and I can run it on my laptop which makes my mobile environment more portable. This requires a wireless card that is USB, runs in Ubuntu, and can be put into Monitor mode. The Alfa cards work great for this, they are high power (mine is 2000mW), and fairly inexpensive.







Once your Ubuntu is installed and have a wireless card that works you need to install hostapd. It's the software that will make your VM act like an access point. You also need to create one NAT'ed Network adaptor in the VirtualBox config. I could not get this to work correctly unless it was NAT'ed. The Alfa drivers come with its own custom version of hostap. If you are using the Alfa then proceed to the next section. If not you should be able to get away with just running sudo apt-get install hostapd.

Installing the Alfa Drivers (Skip this section if not using the Alfa )

If your using the wireless card mentioned above then you also need to install the drivers from the Alfa website. The divers can be downloaded here. Once downloaded and unziped you will need to build the driver.
> cd [ALFA ROOT]/driver
Unzip and untar the driver and cd into the created directory structure and run the following commands.
>make
>sudo make install


Your driver should be installed and to test reboot the machine and see if the Alfa can connect to the internet. In virtual box i had to create a USB filter so that the VM can see the device. This is pretty simple and the Alpha shows up in the list when you click Add USB in the USB Virtual Box config.


Install HostAp for Alfa

The downloaded drivers have a custom hostap that needs to be built to use this card. You need to 
> cd [ALFA ROOT] /wpa_supplicant_hostapd/
> unzip wpa_supplicant_hostapd-0.8_rtw_20110524.zip
> cd wpa_supplicant_hostapd-0.8
> cd hostap
> make
> sudo make install
cd [ALFA ROOT] /wpa_supplicant_hostapd/
> cp rtl_hostapd.conf ~/
> cd ~




Configure HostAp

Now your ready to start your AP. You can configure your access point inside rtl_hostapd.conf or /etc/hostap/hostapd.conf if your not using the Alfa Drivers. In this file ensure that the interface is correct, change the ssid, and change the password. Below is an example of the only things I needed to configure.


interface=wlan0
ctrl_interface=/var/run/hostapd
ssid=MALLORY_VM
wpa_passphrase=thisisatest
channel=6
wpa=2
bridge=br0


Run your access point by typing:
> sudo hostapd ./rtl_hostapd.conf


You should be able to see your wireless access point show up on your mobile devices. In Part 2 we will discuss the installation of Mallory and getting it to MiTM any device that connects to the wireless AP.