-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbursts_functions.sh
481 lines (307 loc) · 11.7 KB
/
bursts_functions.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
472
473
474
475
476
477
478
479
480
481
#!/bin/bash
#0 = unprocessed
#1 = no burst found by mac address
#2 = no burst found by sequence number
#3 = no burst found by vht
ssid_2bursts-wlan_sa () {
#set -x
echo ssid_2bursts-wlan_sa start $(date +"%H:%M:%S.%3N")
#pull unproccessed SSID and break into array
es=0
#es exit status and until loop to iterate through all unprocessed lines
until [[ $es -ne 0 ]]; do
#select unprocessed row
row=$(mysql -N probeprint <<< "select ssid_hex,wlan_sa,time from ssid where is_processed=0 order by time limit 1;")
es=$?
arr=($row)
if [[ -z ${arr} ]]
then echo No rows found for wlan_sa
echo finishing ssid_2bursts-wlan_sa $(date)
sleep 5
return
#exit 0
fi
ssid_hex=${arr[0]}
wlan_sa=${arr[1]}
time=${arr[2]}
#echo $ssid_hex $wlan_sa $time
#sleep 1
###analyze probes in the next 1 second
end_time=$(echo "scale=7; $time + 1" | bc)
#echo $end_time
#sleep 2
endtime=$end_time
begintime=$( echo "scale=7; $time - .000001" | bc)
#echo $begintime
#sleep 3
burst=()
#burst+=("$ssid_hex")
### future probe loop
while read line;
do
#sleep 1
#IFS=\|
arr2=($line)
ssid_hex2=${arr2[0]}
wlan_sa2=${arr2[1]}
time2=${arr2[2]}
#append ssid of matching mac address to burst
#unset IFS
burst+=("$ssid_hex2")
#mark child probes as processed, if considered a burst
if [[ "$time" != "$time2" ]]; then
mysql -N probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
#else
#sqlite3 new.db "update ssid set is_processed=1 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
fi
final_time=$time2
#query for 1 second in the future and iterate through probes to find match ## sqlite3 reverses < and > because numbers are negatives, treats them as positive
done <<<$(mysql -N probeprint <<< "SELECT ssid_hex,wlan_sa,time from ssid where time < \"$endtime\" and time > \"$begintime\" and wlan_sa=\"$wlan_sa\" order by time;")
#mark partent probe as processed
mysql probeprint <<< "update ssid set is_processed=1 where wlan_sa = \"$wlan_sa\" and time = \"$time\";"
bcount=${#burst[@]}
#mark parent is_processed 100 where burst is found
if [[ $bcount -gt "1" ]]
then
mysql probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa\" and time =\"$time\";"
newburst=`echo ${burst[*]} | tr \ \:`
bdur=`echo "scale=7; $final_time - $time" | bc`
#sqlite3 bursts.db "insert into bursts(ssids,time,burst_size,burst_duration,bmethod) values (\"$newburst\",\"$time\",\"${#burst[@]}\",\"$bdur\", \"wlan_sa\") on conflict(ssids) do update set time=\"$final_time\";"
echo $newburst >> /tmp/ssids.log
mysql probeprint <<< "insert into bursts(ssids,time,burst_size,burst_duration,bmethod) values (\"$newburst\",\"$time\",\"${#burst[@]}\",\"$bdur\", \"wlan_sa\");"
fi
done
echo ssid_2bursts-wlan_sa done $(date +"%H:%M:%S.%3N")
}
ssid2bursts-seq () {
#needs to include rssi
echo ssid_2bursts-seq start $(date +"%H:%M:%S.%3N")
#pull unproccessed SSID and break into array
es=0
until [[ $es -ne 0 ]]; do
row=$(mysql -N probeprint <<< "select ssid_hex,wlan_sa,time,seq,rssi from ssid where is_processed=1 and seq!=null order by time limit 1;")
es=$?
arr=($row)
if [[ -z ${arr} ]]
then echo ending no seq_row
echo ssid_2bursts-seq stop $(date +"%H:%M:%S.%3N")
sleep 5
return
#exit 0
fi
ssid_hex=${arr[0]}
wlan_sa=${arr[1]}
time=${arr[2]}
seq=${arr[3]}
rssi=$(echo ${arr[4]} | cut -d, -f1)
rssi_max=$(echo $rssi +2 |bc)
rssi_min=$(echo $rssi -2 | bc)
end_time=$(echo "scale=7; $time + 1" | bc)
endtime=$end_time
begintime=$( echo "scale=7; $time - .000001" | bc)
seq_end=$(($seq +60))
burst=()
while read line;
do
#echo child PR with rssi_min max $line
#sleep 1
arr2=($line)
ssid_hex2=${arr2[0]}
wlan_sa2=${arr2[1]}
time2=${arr2[2]}
#proc2=${arr2[4]}
#append ssid of matching mac address to burst
#unset IFS
burst+=("$ssid_hex2")
#ensure child probe is not the same as parent probe
if [[ "$time" != "$time2" ]]; then
#mark child probes as processed, if considered a burst
#echo will run update ssid set is_processed=100 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\"
mysql probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
else
#selected parent probe as child probe, marking as no burst found
#echo will run update ssid set is_processed=2 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\"
mysql probeprint <<< "update ssid set is_processed=2 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
fi
#updating final_time
final_time=$time2
#mark partent probe as processed
#echo will run "update ssid set is_processed=2 where wlan_sa = \"$wlan_sa\" and time = \"$time\";"
mysql probeprint <<< "update ssid set is_processed=2 where wlan_sa = \"$wlan_sa\" and time = \"$time\";"
done <<<$(mysql -N probeprint <<< "SELECT ssid_hex,wlan_sa,time from ssid where time < \"$endtime\" and time > \"$begintime\" and seq >= \"$seq\" and seq <= \"$seq_end\" and rssi <= \"$rssi_max\" and rssi >= \"$rssi_min\" order by time;")
bcount=${#burst[@]}
if [[ $bcount -gt "1" ]]
then
#mark parent probe as part of burst if burst is found
mysql probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa\" and time=\"$time\";"
fi
newburst=`echo ${burst[*]} | tr \ \:`
bdur=$(echo "scale=7; $final_time - $time" | bc)
#echo $bdur
#only insert bursts with burst count greater than 1 because otherwise it's not a burst
if [[ "${#burst[@]}" -gt 1 ]]; then
mysql probeprint <<< "insert into bursts(ssids,time,burst_size,burst_duration,bmethod) values (\"$newburst\",\"$time\",\"${#burst[@]}\",\"$bdur\", \"seq\");"
fi
done
echo ssid_2bursts-seq stop $(date +"%H:%M:%S.%3N")
}
ssid2bursts-vht () {
echo ssid_2bursts-vht start $(date +"%H:%M:%S.%3N")
#pull unproccessed SSID and break into array
es=0
until [[ $es -ne 0 ]]; do
row=$(mysql -N probeprint <<< "select ssid_hex,wlan_sa,time,vht,rssi from ssid where is_processed=2 order by time limit 1;")
es=$?
arr=($row)
if [[ -z ${arr} ]]
then echo ending no vht_row
echo ssid_2bursts-vht stop $(date +"%H:%M:%S.%3N")
sleep 50
return
#exit 0
fi
ssid_hex=${arr[0]}
wlan_sa=${arr[1]}
time=${arr[2]}
vht=${arr[3]}
rssi=$(echo ${arr[4]} | cut -d, -f1)
rssi_max=$(echo $rssi +2 |bc)
rssi_min=$(echo $rssi -2 | bc)
end_time=$(echo "scale=7; $time + 1" | bc)
endtime=$end_time
begintime=$( echo "scale=7; $time - .000001" | bc)
burst=()
while read line;
do
#echo child PR with rssi_min max $line
#sleep 1
arr2=($line)
ssid_hex2=${arr2[0]}
wlan_sa2=${arr2[1]}
time2=${arr2[2]}
#append ssid of matching mac address to burst
#unset IFS
burst+=("$ssid_hex2")
#ensure child probe is not the same as parent probe
if [[ "$time" != "$time2" ]]; then
#mark child probes as processed, if considered a burst
#echo will run update ssid set is_processed=100 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\"
mysql probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
else
#selected parent probe as child probe, marking as no burst found
#echo will run update ssid set is_processed=2 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\"
mysql probeprint <<< "update ssid set is_processed=3 where wlan_sa = \"$wlan_sa2\" and time =\"$time2\";"
fi
#updating final_time
final_time=$time2
#mark partent probe as processed
#echo will run "update ssid set is_processed=2 where wlan_sa = \"$wlan_sa\" and time = \"$time\";"
mysql probeprint <<< "update ssid set is_processed=3 where wlan_sa = \"$wlan_sa\" and time = \"$time\";"
done <<<$(mysql -N probeprint <<< "SELECT ssid_hex,wlan_sa,time from ssid where time < \"$endtime\" and time > \"$begintime\" and vht = \"$vht\" and rssi <= \"$rssi_max\" and rssi >= \"$rssi_min\" order by time;")
bcount=${#burst[@]}
if [[ $bcount -gt "1" ]]
then
#mark parent probe as part of burst if burst is found
mysql probeprint <<< "update ssid set is_processed=100 where wlan_sa = \"$wlan_sa\" and time=\"$time\";"
fi
newburst=`echo ${burst[*]} | tr \ \:`
bdur=$(echo "scale=7; $final_time - $time" | bc)
#echo $bdur
#only insert bursts with burst count greater than 1 because otherwise it's not a burst
if [[ "${#burst[@]}" -gt 1 ]]; then
mysql probeprint <<< "insert into bursts(ssids,time,burst_size,burst_duration,bmethod) values (\"$newburst\",\"$time\",\"${#burst[@]}\",\"$bdur\", \"vht\");"
fi
done
echo ssid_2bursts-vht stop $(date +"%H:%M:%S.%3N")
}
is_uniq () {
echo is_uniq start $(date +"%H:%M:%S.%3N")
#set -x
ssids=.
until [ -z $ssids ]; do
ssids=$(mysql -N probeprint <<< "select ssids from bursts where is_uniq is null limit 1")
uniq=0
uniq=$(echo ${ssids[*]} | tr \: \\n | sort | uniq | wc -l)
if [[ $uniq -lt 2 ]]; then
mysql probeprint <<< "update bursts set is_uniq=0 where ssids=\"$ssids\";"
else
mysql probeprint <<< "update bursts set is_uniq=1 where ssids=\"$ssids\";"
fi
done
echo is_uniq stop $(date +"%H:%M:%S.%3N")
}
find_relatedbursts () {
echo starting find_relatedbursts $(date +"%H:%M:%S.%3N")
while true; do
IFS=:;
###
###set related_burst to ignore for bursts of non-unique common ssids
###
#select unprocessed rowid and break into array
ssids=($(mysql -N probeprint <<< "select time,ssids from bursts where burst_duration != 0 and burst_size > 1 and related_burst = 0 and is_uniq=1 limit 1;"));
echo ${ssids[*]}
#check for value
if [[ -z ${ssids} ]]
then echo nothing to do, no ssids
echo find_relatedbursts stop $(date +"%H:%M:%S.%3N")
sleep 10
break
fi
#set a count of all the ssids
ssidn="${#ssids[@]}"
# number of ssid to examine, ssid[0] = time
ssidi=1
echo working on ${ssids[$ssidi]}
#find bursts of uniq ssids only ; could be taken care of by is_uniq
uniq=0
uniq=$(echo ${ssids[*]} | tr \ \\n | sort | uniq | wc -l)
((uniq--))
#echo $uniq
if [[ $uniq -lt 2 ]]
then
echo only 1 unique ssid in burst
echo doing ignore check
ignore_check=$(mysql -N probeprint <<< "select ssid_hex from ssid_intel where (is_common=1 or is_airport IS NOT NULL) and ssid_hex=\"${ssids[1]}\";")
if [ -n $ignore_check ];
then
echo ssid ${ssids[1]} is on ignore list, setting related burst to self
mysql probeprint <<< "update bursts set related_burst=\"${ssids[0]}\" where time=\"${ssids[0]}\";"
echo exit was here
#exit 1
fi
#continue process for ssids not on ignore list
echo finding similar bursts for time = ${ssids[0]}
mysql probeprint <<< "update bursts set related_burst=\"${ssids[0]}\" where (ssids like \"%:${ssids[1]}:%\" or ssids like \"%:${ssids[1]}\" or ssids like \"${ssids[1]}:%\") AND related_burst != \"IGNORE\";"
#mark parent burst as complete
mysql probeprint <<< "update bursts set related_burst=\"${ssids[0]}\" where time=\"${ssids[0]}\";"
fi
#done processing bursts with only 1 ssid
#for non uniq ssids
#check for ignored ssids. super common ssid, like name of current location wifi
#ignored is wrong answer, need to iterate to next in array
until [[ "$ssidi" == "$ssidn" ]]
do
#echo $ssidi
#echo ${ssids[$ssidi]}
echo doing ignore check
ignore_check=$(mysql -N probeprint <<< "select ssid_hex from ssid_intel where (is_common=1 or is_airport IS NOT NULL) and ssid_hex=\"${ssids[$ssidi]}\";")
if [ -z $ignore_check ];
then
#No value so not on the ignore list
mysql probeprint <<< "update bursts set related_burst=\"${ssids[0]}\" where (ssids like \"%:${ssids[$ssidi]}:%\" or ssids like \"${ssids[$ssidi]}:%\" or ssids like \"%${ssids[$ssidi]}\" or ssids=\"{ssids[$ssidi]}\") AND related_burst != \"IGNORE\";"
echo updated ssids like ${ssids[$ssidi]} with time ${ssids[0]}
#end extra action
else echo ${ssids[$ssdi]} is on ignore list
fi
#move to next ssid for both ignore and not ignore
((ssidi++))
echo will be working on ${ssids[$ssidi]}
done
#done for until
#set parenent burst related burst
mysql probeprint <<< "update bursts set related_burst=\"${ssids[0]}\" where time=\"${ssids[0]}\";"
echo exit 0 was here
#exit 0
done
echo find_relatedbursts stop $(date +"%H:%M:%S.%3N")
}