forked from morrownr/8821au-20210708
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-mon.sh
executable file
·369 lines (343 loc) · 12.9 KB
/
test-mon.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#!/bin/bash
SCRIPT_NAME="test-mon.sh"
SCRIPT_VERSION="20211218"
# Check that sudo was used to start the script
if [[ $EUID -ne 0 ]]
then
clear
echo "You must run this script with superuser (root) privileges."
echo "Try: \"sudo ./${SCRIPT_NAME}\""
exit 1
fi
# Set color definitions (https://en.wikipedia.org/wiki/ANSI_escape_code)
# Black 0;30 Dark Gray 1;30
# Red 0;31 Light Red 1;31
# Green 0;32 Light Green 1;32
# Brown/Orange 0;33 Yellow 1;33
# Blue 0;34 Light Blue 1;34
# Purple 0;35 Light Purple 1;35
# Cyan 0;36 Light Cyan 1;36
# Light Gray 0;37 White 1;37
RED='\033[1;31m'
YELLOW='\033[0;33;1m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NoColor='\033[0m'
# Display docs
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo
echo ' Purpose: Test monitor mode on the provided wlan interface'
echo
echo ' Usage: $ sudo ./test-mon.sh [interface:wlan0]'
echo
echo ' Please feel free to help make this script better.'
echo
echo ' Some parts of this script require the installation of:'
echo
echo ' aircrack-ng'
echo ' wireshark'
echo
echo ' Note: To exit this script and install the above: Ctrl + c'
echo
echo ' Note: For installation on Debian based systems:'
echo
echo ' $ sudo apt install -y aircrack-ng wireshark'
echo
echo ' --------------------------------'
echo -e "${NoColor}"
# Interfering processes must be disabled prior to running this script:
#
#```
# $ sudo airmon-ng check kill
#```
# Assign default monitor mode interface name
iface0mon='wlan0mon'
# Assign default channel
chan=6
# Activate option to set automatic or manual interface mode
#
# Option 1: if you only have one wlan interface (automatic detection)
#iface0=`iw dev | grep 'Interface' | sed 's/Interface //'`
#
# Option 2: if you have more than one wlan interface (default wlan0)
iface0=${1:-wlan0}
# Set iface0 down
ip link set dev $iface0 down
# Check if iface0 exists and continue if true
if [ $? -eq 0 ]
then
# Disabled interfering processes
# clear
echo
read -p " Do you want to use airmon-ng to disable interfering processes? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
airmon-ng check kill
read -p " Press any key to continue. " -n 1 -r
fi
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0 info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0 info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0 | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0 info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo -e "${NoColor}"
# Set addr (has to be done before renaming the interface)
iface_addr_orig=$iface_addr
read -p " Do you want to set a new addr? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p " What addr do you want? ( 12:34:56:78:90:ab ) " iface_addr
ip link set dev $iface0 address $iface_addr
fi
# iface_addr=$(iw dev $iface0 info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
# echo ' addr - ' $iface_addr
# exit 1
# Set monitor mode
# iw dev <devname> set monitor <flag>
# Valid monitor flags are:
# none: no special flags
# fcsfail: show frames with FCS errors
# control: show control frames
# otherbss: show frames from other BSSes
# cook: use cooked mode
# active: use active mode (ACK incoming unicast packets)
# mumimo-groupid <GROUP_ID>: use MUMIMO according to a group id
# mumimo-follow-mac <MAC_ADDRESS>: use MUMIMO according to a MAC address
iw dev $iface0 set monitor control
# Rename interface
ip link set dev $iface0 name $iface0mon
# Bring the interface up
ip link set dev $iface0mon up
# Run airodump-ng
# airodump-ng will display a list of detected access points and clients
# https://www.aircrack-ng.org/doku.php?id=airodump-ng
# https://en.wikipedia.org/wiki/Regular_expression
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo -e "${NoColor}"
echo -e " airodump-ng can receive and interpret key strokes while running..."
echo
echo -e " a - select active area"
echo -e " i - invert sorting order"
echo -e " s - change sort column"
echo -e " q - quit"
echo ' ----------------------------'
echo
read -p " Do you want to run airodump-ng to display a list of detected access points and clients? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# usage: airodump-ng <options> <interface>[,<interface>,...]
#
# -c <channels> : Capture on specific channels
# -a : Filter unassociated clients
# --ignore-negative-one : Removes the message that says fixed channel <interface>: -1
# --essid-regex <regex> : Filter APs by ESSID using a regular expression
#
# Select option
#
# 1) shows hidden ESSIDs
# airodump-ng -c 1-165 -a --ignore-negative-one $iface0mon
#
# 2) does not show hidden ESSIDs
#
airodump-ng -c 1-165 -a --ignore-negative-one --essid-regex '^(?=.)^(?!.*CoxWiFi)' $iface0mon
fi
# Set channel
read -p " Do you want to set the channel? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p " What channel do you want to set? " chan
# ip link set dev $iface0mon down
iw dev $iface0mon set channel $chan
# ip link set dev $iface0mon up
fi
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
iface_chan=$(iw dev $iface0mon info | grep 'channel' | sed 's/channel //' | sed -e 's/^[ \t]*//')
echo ' chan - ' $chan
iface_txpw=$(iw dev $iface0mon info | grep 'txpower' | sed 's/txpower //' | sed -e 's/^[ \t]*//')
echo ' txpw - ' $iface_txpw
echo ' --------------------------------'
echo -e "${NoColor}"
# Set txpw
read -p " Do you want to set the txpower? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p " What txpw setting do you want? ( 2300 = 23 dBm ) " iface_txpw
# ip link set dev $iface0mon down
iw dev $iface0mon set txpower fixed $iface_txpw
# ip link set dev $iface0mon up
fi
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
iface_chan=$(iw dev $iface0mon info | grep 'channel' | sed 's/channel //' | sed -e 's/^[ \t]*//')
echo ' chan - ' $chan
iface_txpw=$(iw dev $iface0mon info | grep 'txpower' | sed 's/txpower //' | sed -e 's/^[ \t]*//')
echo ' txpw - ' $iface_txpw
echo ' --------------------------------'
echo -e "${NoColor}"
# Test injection capability with aireplay-ng
read -p " Do you want to test injection capability? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# ip link set dev $iface0mon up
aireplay-ng --test $iface0mon
fi
# Start wireshark
read -p " Do you want to start Wireshark? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
# ip link set dev $iface0mon up
wireshark --interface wlan0mon
# test filter: wlan.fc.type_subtype == 29
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
iface_chan=$(iw dev $iface0mon info | grep 'channel' | sed 's/channel //' | sed -e 's/^[ \t]*//')
echo ' chan - ' $chan
# iface_txpw=$(iw dev $iface0mon info | grep 'txpower' | sed 's/txpower //' | sed -e 's/^[ \t]*//')
# echo ' txpw - ' $iface_txpw
echo ' --------------------------------'
echo -e "${NoColor}"
fi
# Return the adapter to original settings
read -p " Do you want to return the adapter to original settings? [Y/n] " -n 1 -r
if [[ $REPLY =~ ^[Nn]$ ]]
then
# ip link set dev $iface0mon up
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0mon info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0mon info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0mon | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0mon info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo -e "${NoColor}"
else
ip link set dev $iface0mon down
ip link set dev $iface0mon address $iface_addr_orig
iw $iface0mon set type managed
ip link set dev $iface0mon name $iface0
ip link set dev $iface0 up
# Display interface settings
clear
echo -e "${GREEN}"
echo ' --------------------------------'
echo -e " ${SCRIPT_NAME} ${SCRIPT_VERSION}"
echo ' --------------------------------'
echo ' WiFi Interface:'
echo ' '$iface0
echo ' --------------------------------'
iface_name=$(iw dev $iface0 info | grep 'Interface' | sed 's/Interface //' | sed -e 's/^[ \t]*//')
echo ' name - ' $iface_name
iface_type=$(iw dev $iface0 info | grep 'type' | sed 's/type //' | sed -e 's/^[ \t]*//')
echo ' type - ' $iface_type
iface_state=$(ip addr show $iface0 | grep 'state' | sed 's/.*state \([^ ]*\)[ ]*.*/\1/')
echo ' state - ' $iface_state
iface_addr=$(iw dev $iface0 info | grep 'addr' | sed 's/addr //' | sed -e 's/^[ \t]*//')
echo ' addr - ' $iface_addr
echo ' --------------------------------'
echo -e "${NoColor}"
fi
exit 0
else
echo -e "${YELLOW}ERROR: Please provide an existing interface as parameter! ${NoColor}"
echo -e "${NoColor}Usage: $ ${CYAN}sudo ./$SCRIPT_NAME [interface:wlan0] ${NoColor}"
echo -e "${NoColor}Tip: $ ${CYAN}iw dev ${NoColor}(displays available interfaces)"
exit 1
fi