-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCodeFlow.sh
executable file
·471 lines (413 loc) · 15 KB
/
CodeFlow.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
#!/bin/bash
#Parent Folder of Scripts
home_dir=`eval echo ~$USER`
scripts_path=$home_dir"/Scripts/CausalAnalysis/"
logFile="log.txt"
pcap_parent=$home_dir"/Datasets_PCAPs/"
csv_parent=$home_dir"/Datasets_CSVs/"
allDays="allDays/"
separator="/"
underscore="_"
#specific scripts sub folder
aps_clients="APs-Clients/"
number_of_frames="FindNumberofFrames/"
frame_details="FindAllTrafficDetails/"
airtime_utilization="ATU/"
useless_pt="UselessProbeTraffic/"
causal_analysis="CausalAnalysis-Datasets/"
causal_analysis_dfa="CausalAnalysis-DFA/"
preq_pres="1PReq_NPRes/"
convert_pcap_csv="ConvertPCAPtoCSV/"
association_patterns="AssociationPatterns/"
###########################################################
######Initial Choices######################################
###########################################################
echo -n "Name of dataset to be processed....."
read dataset
echo -n "EDCA Enabled(1) or Disabled(0)?..Enter 1 or 0..."
read edcaEnabled
echo -n "Header - Radiotap(1) or Prism(2)..Enter 1 or 2....."
read denominator
echo "What do you want to process?..Enter Y or N..."
echo
echo -n ".....Convert PCAP to CSV required?....."
read convert
echo -n ".....APs and Clients?....."
read findAPsClients
echo -n ".....Filter Traffic?....."
read filterTraffic
echo -n ".....Frame Details?....."
read frameDetails
echo -n ".....Airtime Utilization?....."
read atu
if echo "$atu" | grep y
then
echo -n "..........Enter Slot Size (seconds) for Calculating Airtime Utilization....."
read slotSize
fi
echo -n ".....Useless Probe Traffic?....."
read upt
echo -n ".....Automatic Causal Detection?....."
read acd
#if echo "$upt" | grep y
#then
#fi
echo -n ".....Quantify Causes?....."
read quantifyCauses
echo -n ".....Find 1 Probe Request = X Probe Responses?....."
read preqNpres
echo -n ".....Association Patterns?....."
read ap
echo -n "........Do you want to calculate Jaccard Index? [Warning: Works only if Association Patterns Executed Before]...."
read calculateJaccardIndex
######################################################
#####################End##############################
######################################################
echo "Scripts Path...." $scripts_path
#PCAP Folder Structure: /home/dherytaj/Datasets_PCAPs/Name_of_dataset/DayNo/<PCAP_Files>
pcap_path=$pcap_parent$dataset
#CSV Folder Structure: ~/Datasets_CSVs/Name_of_dataset/DayNo_Merged.csv
csv_path=$csv_parent$dataset
#Convert PCAPs to CSVs, Merge CSVs to Merged.csv
mkdir -p $csv_path
if echo "$convert" | grep y
then
i=1
echo "PCAP PATH:" $pcap_path
for date in `ls -v $pcap_path/`; do
echo "Processing Date:" $date
process_folder=$pcap_path$separator$date$separator
#Convert PCAP to CSV will create two folders PCAP_CSV and Merged in Date Folder, we need to move Merged/Merged.csv to CSV Folder Structure given below
execute_path=$scripts_path$convert_pcap_csv
script_name="/ConvertPCAPtoCSV.sh"
echo "Processing Folder: " $process_folder
$execute_path$script_name $process_folder
merged="Merged.csv"
filename=Day$i$underscore$merged
mv $process_folder/Merge/Merge.csv $csv_path$separator$filename
i=`expr $i + 1`
done
echo "Conversion Complete"
fi
#number_of_days=`ls -l| wc -l`
#number_of_days=`expr $number_of_days - 1` #These many folders will be created
echo "Creating Folder Structure"
#Output Folder Structure: ~/DataAnalysis/Name_of_dataset/Day#/ScriptName/
output_parent="/home/dherytaj/DataAnalysis/"
output_path=$output_parent$dataset$separator
#Create Folder Structure
if [ ! -d $output_path ]; then
mkdir $output_path
fi
for csv in `ls -v $csv_path`; do #One folder per day of data
#Format Day#_Merged.csv
day=`echo $csv|tr '_' ','|awk -F, '{print $1}'`
echo "Creating folders for:" $csv " and " $day
datanalysis_path=$output_path$separator$day$separator
echo "Data Analysis Path:" $datanalysis_path
#For every script create one folder
if [ ! -d $datanalysis_path ]; then
mkdir $datanalysis_path
fi
mkdir -p $datanalysis_path$aps_clients
mkdir -p $datanalysis_path$number_of_frames
mkdir -p $datanalysis_path$frame_details
mkdir -p $datanalysis_path$airtime_utilization
mkdir -p $datanalysis_path$useless_pt
mkdir -p $datanalysis_path$causal_analysis
mkdir -p $datanalysis_path$causal_analysis_dfa
mkdir -p $datanalysis_path$preq_pres
mkdir -p $datanalysis_path$association_patterns
done
if echo "$ap" | grep y
then
out_path=$output_path$day$separator$association_patterns$separator
out_path_allDays=$output_path$separator$allDays$separator$association_patterns$separator
if [ ! -d $output_path$separator$allDays ]; then
mkdir $output_path$separator$allDays
fi
if [ ! -d $output_path$separator$allDays$separator$association_patterns$separator ]; then
mkdir $output_path$separator$allDays$separator$association_patterns$separator
else
echo -n "....Shall I empty the Old Association Patterns?...."
read empty
if echo "$empty" | grep y
then
rm $output_path$separator$allDays$separator$association_patterns$separator/*
fi
fi
fi
echo "Folder Structure Created"
if echo "$upt" | grep y
then
echo "....Find useless probe traffic--Started"
out_path=$output_path$day$separator$useless_pt$separator
execute_path=$scripts_path$useless_pt
script_name="/FindUPT.sh"
if [ -z "$askUPT_Everytime" -o "$askUPT_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
echo -n "........Enter allowed SSIDs (CSV)----"
read SSIDs
ssidFile="/tmp/SSIDs.txt"
if [ -f $ssidFile ]; then
rm $ssidFile
fi
echo $SSIDs >> $ssidFile
fi
if [ -z "$askUPT_Everytime" ]; then
echo -n "......Do you want to enter clients and ssids next time? (y-yes, n-no)......"
read askUPT_Everytime
fi
$execute_path$script_name $csv_path$separator$csv $out_path $ssidFile $clientFile
echo "....Find useless probe traffic--Ended"
fi
askCausal_Everytime=
askUPT_Everytime=
askAP_Everytime=
askCalculateJaccardIndex=
echo "Processing Started"
#For every Merged.csv of every dataset
for csv in `ls $csv_path/`; do
day=`echo $csv|tr '_' ','|awk -F, '{print $1}'`
echo "..Processing day: $day"
#echo -n "############Continue............(Y/N)"
#read cont
#if echo "$cont" | grep y
#then
if echo "$findAPsClients" | grep y
then
echo "....Find APs and Clients--Started"
out_path=$output_path$day$separator$aps_clients$separator
execute_path=$scripts_path$aps_clients
script_name="/FindAPs-Clients.sh"
$execute_path$script_name $csv_path$separator$csv $out_path
echo "......***Please manually remove spurious entries from SSIDs.txt***...."
echo "....Find APs and Clients--Ended"
fi
if echo "$filterTraffic" | grep y
then
echo "....Find number of total, data, management, and control frames--Started"
out_path=$output_path$day$separator$number_of_frames$separator
execute_path=$scripts_path$number_of_frames
script_name="/FilterTraffic.sh "
$execute_path$script_name $csv_path$separator$csv $out_path
echo "....Find number of total, data, management, and control frames--Ended"
fi
if echo "$frameDetails" | grep y
then
echo "....Find CDF size, rate, IFAT of probe requests, probe response, probe traffic, data and ack--Started"
out_path=$output_path$day$separator$frame_details$separator
execute_path=$scripts_path$frame_details
script_name="/ConsolidatedFrameDetails.sh "
$execute_path$script_name $csv_path$separator$csv $out_path $denominator
echo "....Find CDF size, rate, IFAT of probe requests, probe response, probe traffic, data and ack--Ended"
fi
if echo "$atu" | grep y
then
echo "....Find airtime utilization of probe requests, probe responses, and ACKs--Started"
out_path=$output_path$day$separator$airtime_utilization$separator
execute_path=$scripts_path$airtime_utilization
script_name="/ProcessPCAPsForATU.sh "
$execute_path$script_name $csv_path$separator$csv $out_path $edcaEnabled $denominator $slotSize
echo "....Find airtime utilization of probe requests, probe responses, and ACKs--Ended"
fi
if echo "$upt" | grep y
then
echo "....Find useless probe traffic--Started"
out_path=$output_path$day$separator$useless_pt$separator
execute_path=$scripts_path$useless_pt
script_name="/FindUPT.sh"
if [ -z "$askUPT_Everytime" -o "$askUPT_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
echo -n "........Enter allowed SSIDs (CSV)----"
read SSIDs
ssidFile="/tmp/SSIDs.txt"
if [ -f $ssidFile ]; then
rm $ssidFile
fi
echo $SSIDs >> $ssidFile
fi
if [ -z "$askUPT_Everytime" ]; then
echo -n "......Do you want to enter clients and ssids next time? (y-yes, n-no)......"
read askUPT_Everytime
fi
$execute_path$script_name $csv_path$separator$csv $out_path $ssidFile $clientFile
echo "....Find useless probe traffic--Ended"
fi
if echo "$quantifyCauses" | grep y
then
echo "....Find the quantification of causal model--Started"
out_path=$output_path$day$separator$causal_analysis$separator
execute_path=$scripts_path$causal_analysis
script_name="/Quantify-Causes.sh"
if [ -z "$askCausal_Everytime" -o "$askCausal_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
fi
if [ -z "$askCausal_Everytime" ]; then
echo -n "......Do you want to enter clients next time? (y-yes, n-no)......"
read askCausal_Everytime
fi
ssidFile=$output_path$day$separator$aps_clients/SSIDs.txt
if [ -f $ssidFile ]; then
$execute_path$script_name $csv_path$separator$csv $out_path $clientFile $ssidFile
echo "....Find the quantification of causal model--Ended"
else
echo "....Find the quantification of causal model--Failed - Create SSID File"
fi
fi
if echo "$acd" | grep y
then
echo -n "....Pre-processing Required...."
read preprocess
echo -n "....CMAS Required...."
read cmas
if echo "$preprocess" | grep y
then
echo "....Automatic Causal Detection--Started"
out_path=$output_path$day$separator$causal_analysis_dfa$separator
execute_path=$scripts_path$causal_analysis_dfa
script_name="/Prepare_Data_F_Signatures.sh"
echo -n "....Enter AP MAC...."
read ap_mac
echo -n "....Enter AP SSID...."
read ap_ssid
$execute_path$script_name $csv_path$separator$csv $out_path $ap_mac $ap_ssid
echo "....Automatic Causal Detection--Ended"
fi
if echo "$cmas" | grep y
then
echo "....CMAS Process--Started"
out_path=$output_path$day$separator$causal_analysis_dfa$separator
execute_path=$scripts_path$causal_analysis_dfa
script_name="/Prepare_Data_F_DFA.sh"
$execute_path$script_name $out_path $execute_path
echo "....CMAS Process--Ended"
fi
fi
if echo "$preqNpres" | grep y
then
echo "....Find 1 probe request is responded by how many probe responses--Started"
out_path=$output_path$day$separator$preq_pres$separator
execute_path=$scripts_path$preq_pres
script_name="/Find1PreqNPres.sh"
$execute_path$script_name $csv_path$separator$csv $out_path
echo "....Find 1 probe request is responded by how many probe responses--Ended"
fi
if echo "$ap" | grep y
then
echo "....Find association patterns--Started"
out_path=$output_path$day$separator$association_patterns$separator
out_path_allDays=$output_path$separator$allDays$separator$association_patterns$separator
execute_path=$scripts_path$association_patterns
script_name="/FindAP.sh"
if [ -z "$askAP_Everytime" -o "$askAP_Everytime" = "y" ]; then
echo -n "........Do you want to provide path of clients file (1) or enter client MAC addresses (2)?"
read clientChoice
if [ $clientChoice -eq 1 ]; then
echo -n "........Enter the file name----"
read clientFile
fi
if [ $clientChoice -eq 2 ]; then
enterMore=
until [ "$enterMore" = "n" ]; do
echo -n ".........Client's MAC Address----"
read clientMAC
clientFile="/tmp/Clients.txt"
if [ -f $clientFile ]; then
rm $clientFile
fi
echo $clientMAC >> $clientFile
echo -n "..........Enter More (y/n)?"
read enterMore
done
fi
fi
if [ -z "$askAP_Everytime" ]; then
echo -n "......Do you want to enter clients next time? (y-yes, n-no)......"
read askAP_Everytime
fi
$execute_path$script_name $csv_path$separator$csv $out_path $out_path_allDays $clientFile
echo "....Find association patterns--Ended"
fi
#fi
done
if [ "$calculateJaccardIndex" = "y" ]; then
flag=0
if [ ! -d $output_path$separator$allDays$separator$association_patterns$separator ]; then
flag=1
else
files=`ls $output_path$separator$allDays$separator$association_patterns$separator|wc -l`
if [ -z $files -o $files -eq 0 ]; then
flag=1
fi
fi
if [ $flag -eq 0 ]; then
echo "....Calculate Jaccard Index--Started"
out_path=$output_path$day$separator$association_patterns$separator
out_path_allDays=$output_path$separator$allDays$separator$association_patterns$separator
execute_path=$scripts_path$association_patterns
script_name="/CalculateJaccard.sh"
$execute_path$script_name $out_path_allDays
echo "....Calculate Jaccard Index--Ended"
else
echo "....!!!!Jaccard Index cannot be calculated....Association Patterns Not Present"
fi
fi
echo "Processing Completed"