forked from SYWorks/wireless-ids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wids.py
4518 lines (4100 loc) · 194 KB
/
wids.py
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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/python
#
# This was written for educational purpose only. Use it at your own risk.
# Author will be not responsible for any damage!
# Written By SY Chua, [email protected]
#
appver="1.0, R.9"
apptitle="WIDS"
appDesc="- The Wireless Intrusion Detection System"
appcreated="07 Jan 2014"
appupdated="26 Feb 2014"
appnote="by SY Chua, " + appcreated + ", Updated " + appupdated
import sys,os
import subprocess
import random
import curses
from subprocess import call
import termios
import tty
import time
import signal
import select
import datetime
import ssl
import os.path
import binascii, re
import commands
from subprocess import Popen, PIPE
import threading
##################################
# Global Variables Declaration #
##################################
global RTY
RTY=""
def CheckAdmin():
is_admin = os.getuid() == 0
if is_admin==False:
printc ("!!!","Application required admin rights in-order to work properly !","")
exit(1)
class fcolor:
CReset='\033[0m'
CBold='\033[1m'
CDim='\033[2m'
CUnderline='\033[4m'
CBlink='\033[5m'
CInvert='\033[7m'
CHidden='\033[8m'
CDebugB='\033[1;90m'
CDebug='\033[0;90m'
Black='\033[30m'
Red='\033[31m'
Green='\033[32m'
Yellow='\033[33m'
Blue='\033[34m'
Pink='\033[35m'
Cyan='\033[36m'
White='\033[37m'
SBlack='\033[0;30m'
SRed='\033[0;31m'
SGreen='\033[0;32m'
SYellow='\033[0;33m'
SBlue='\033[0;34m'
SPink='\033[0;35m'
SCyan='\033[0;36m'
SWhite='\033[0;37m'
BBlack='\033[1;30m'
BRed='\033[1;31m'
BBlue='\033[1;34m'
BYellow='\033[1;33m'
BGreen='\033[1;32m'
BPink='\033[1;35m'
BCyan='\033[1;36m'
BWhite='\033[1;37m'
UBlack='\033[4;30m'
URed='\033[4;31m'
UGreen='\033[4;32m'
UYellow='\033[4;33m'
UBlue='\033[4;34m'
UPink='\033[4;35m'
UCyan='\033[4;36m'
UWhite='\033[4;37m'
BUBlack=CBold + '\033[4;30m'
BURed=CBold + '\033[4;31m'
BUGreen=CBold + '\033[4;32m'
BUYellow=CBold + '\033[4;33m'
BUBlue=CBold + '\033[4;34m'
BUPink=CBold + '\033[4;35m'
BUCyan=CBold + '\033[4;36m'
BUWhite=CBold + '\033[4;37m'
IGray='\033[0;90m'
IRed='\033[0;91m'
IGreen='\033[0;92m'
IYellow='\033[0;93m'
IBlue='\033[0;94m'
IPink='\033[0;95m'
ICyan='\033[0;96m'
IWhite='\033[0;97m'
BIGray='\033[1;90m'
BIRed='\033[1;91m'
BIGreen='\033[1;92m'
BIYellow='\033[1;93m'
BIBlue='\033[1;94m'
BIPink='\033[1;95m'
BICyan='\033[1;96m'
BIWhite='\033[1;97m'
BGBlack='\033[40m'
BGRed='\033[41m'
BGGreen='\033[42m'
BGYellow='\033[43m'
BGBlue='\033[44m'
BGPink='\033[45m'
BGCyan='\033[46m'
BGWhite='\033[47m'
BGIBlack='\033[100m'
BGIRed='\033[101m'
BGIGreen='\033[102m'
BGIYellow='\033[103m'
BGIBlue='\033[104m'
BGIPink='\033[105m'
BGICyan='\033[106m'
BGIWhite='\033[107m'
def read_a_key():
stdinFileDesc = sys.stdin.fileno()
oldStdinTtyAttr = termios.tcgetattr(stdinFileDesc)
try:
tty.setraw(stdinFileDesc)
sys.stdin.read(1)
finally:
termios.tcsetattr(stdinFileDesc, termios.TCSADRAIN, oldStdinTtyAttr)
def printc(ptype, ptext,ptext2):
"""
Function : Displaying text with pre-defined icon and color
Usage of printc:
ptype - Type of Icon to display
ptext - First sentence to display
ptext2 - Second sentence, "?" as reply text, "@"/"@^" as time in seconds
Examples : Lookup DemoOnPrintC() for examples
"""
ScriptName=os.path.basename(__file__)
printd("PType - " + str(ptype) + "\n " + "PText = " + str(ptext) + "\n " + "PText2 = " + str(ptext2))
ReturnOut=""
bcolor=fcolor.SWhite
pcolor=fcolor.BGreen
tcolor=fcolor.SGreen
if ptype=="i":
pcolor=fcolor.BBlue
tcolor=fcolor.BWhite
if ptype=="H":
pcolor=fcolor.BBlue
tcolor=fcolor.BWhite
hcolor=fcolor.BUBlue
if ptype=="!":
pcolor=fcolor.BRed
tcolor=fcolor.BYellow
if ptype=="!!":
ptype="!"
pcolor=fcolor.BRed
tcolor=fcolor.SRed
if ptype=="!!!":
ptype="!"
pcolor=fcolor.BRed
tcolor=fcolor.BRed
if ptype==".":
pcolor=fcolor.BGreen
tcolor=fcolor.SGreen
if ptype=="-":
pcolor=fcolor.SWhite
tcolor=fcolor.SWhite
if ptype=="--":
ptype="-"
pcolor=fcolor.BWhite
tcolor=fcolor.BWhite
if ptype=="..":
ptype="."
pcolor=fcolor.BGreen
tcolor=fcolor.BGreen
if ptype==">" or ptype=="+":
pcolor=fcolor.BCyan
tcolor=fcolor.BCyan
if ptype==" ":
pcolor=fcolor.BYellow
tcolor=fcolor.Green
if ptype==" ":
pcolor=fcolor.BYellow
tcolor=fcolor.BGreen
if ptype=="?":
pcolor=fcolor.BYellow
tcolor=fcolor.BGreen
if ptype=="x":
pcolor=fcolor.BRed
tcolor=fcolor.BBlue
if ptype=="*":
pcolor=fcolor.BYellow
tcolor=fcolor.BPink
if ptype=="@" or ptype=="@^":
pcolor=fcolor.BRed
tcolor=fcolor.White
firstsixa=""
if ptext!="":
tscolor=fcolor.Blue
ts = time.time()
DateTimeStamp=datetime.datetime.fromtimestamp(ts).strftime('%d/%m/%Y %H:%M:%S')
TimeStamp=datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
DateStamp=datetime.datetime.fromtimestamp(ts).strftime('%d/%m/%Y')
ptext=ptext.replace("%dt -",tscolor + DateTimeStamp + " -" + tcolor)
ptext=ptext.replace("%dt",tscolor + DateTimeStamp + tcolor)
ptext=ptext.replace("%t -",tscolor + TimeStamp + " -" + tcolor)
ptext=ptext.replace("%t",tscolor + TimeStamp + tcolor)
ptext=ptext.replace("%d -",tscolor + DateStamp + " -" + tcolor)
ptext=ptext.replace("%d",tscolor + DateStamp + tcolor)
ptext=ptext.replace("%an",tscolor + ScriptName + tcolor)
if "%cs" in ptext:
ptext=ptext.replace("%cs",tscolor + ptext2 + tcolor)
ptext2=""
lptext=len(ptext)
if lptext>6:
firstsix=ptext[:6].lower()
firstsixa=firstsix
if firstsix=="<$rs$>":
ReturnOut="1"
lptext=lptext-6
ptext=ptext[-lptext:]
if PrintToFile=="1" and ptype!="@" and ptype!="x" and ptype!="@^" and firstsixa!="<$rs$>":
ptypep=ptype
if ptypep==" " or ptypep==" ":
ptypep=" "
else:
ptypep="[" + ptype + "] "
open(LogFile,"a+b").write(RemoveColor(ptypep) + RemoveColor(str(ptext.lstrip().rstrip())) + "\n")
if ptype=="x":
if ptext=="":
ptext="Press Any Key To Continue..."
c1=bcolor + "[" + pcolor + ptype + bcolor + "] " + tcolor + ptext
print c1,
sys.stdout.flush()
read_a_key()
print ""
return
if ptype=="H":
c1=bcolor + "[" + pcolor + "i" + bcolor + "] " + hcolor + ptext + fcolor.CReset
if ReturnOut!="1":
print c1
return c1
else:
return c1
if ptype=="@" or ptype=="@^":
if ptext2=="":
ptext2=5
t=int(ptext2)
while t!=0:
s=bcolor + "[" + pcolor + str(t) + bcolor + "] " + tcolor + ptext + "\r"
s=s.replace("%s",pcolor+str(ptext2)+tcolor)
sl=len(s)
print s,
sys.stdout.flush()
time.sleep(1)
s=""
ss="\r"
print "" + s.ljust(sl+2) + ss,
sys.stdout.flush()
if ptype=="@^":
t=t-1
while sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
line = sys.stdin.readline()
if line:
print bcolor + "[" + fcolor.BRed + "!" + bcolor + "] " + fcolor.Red + "Interupted by User.." + fcolor.Green
return
else:
t=t-1
c1=bcolor + "[" + pcolor + "-" + bcolor + "] " + tcolor + ptext + "\r"
c1=c1.replace("%s",pcolor+str(ptext2)+tcolor)
print c1,
sys.stdout.flush()
return
if ptype=="?":
if ptext2!="":
usr_resp=raw_input(bcolor + "[" + pcolor + ptype + bcolor + "] " + tcolor + ptext + " ( " + pcolor + ptext2 + tcolor + " ) : " + fcolor.BWhite)
return usr_resp;
else:
usr_resp=raw_input(bcolor + "[" + pcolor + ptype + bcolor + "] " + tcolor + ptext + " : " + fcolor.BWhite)
return usr_resp;
if ptype==" " or ptype==" ":
if ReturnOut!="1":
print bcolor + " " + tcolor + ptext + ptext2
else:
return bcolor + " " + tcolor + ptext + ptext2
else:
if ReturnOut!="1":
print bcolor + "[" + pcolor + ptype + bcolor + "] " + tcolor + ptext + ptext2
else:
return bcolor + "[" + pcolor + ptype + bcolor + "] " + tcolor + ptext + ptext2
def AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply):
"""
Function : Question for user input. Quite similar to printc("?") function
Usage of AskQuestion:
QuestionText - Question Text to ask
ReplyText - The reply text. Ex : "Y/n")
Examples : Lookup DemoOnPrintC() for examples
"""
if DisplayReply=="":
DisplayReply=1
bcolor=fcolor.SWhite
pcolor=fcolor.BYellow
tcolor=fcolor.BGreen
if ReplyText!="":
usr_resp=raw_input(bcolor + "[" + pcolor + "?" + bcolor + "] " + tcolor + QuestionText + " ( " + pcolor + ReplyText + tcolor + " ) : " + fcolor.BWhite)
else:
usr_resp=raw_input(bcolor + "[" + pcolor + "?" + bcolor + "] " + tcolor + QuestionText + " : " + fcolor.BWhite)
if DefaultReply!="":
if usr_resp=="":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Default Selected ==> " + fcolor.BYellow + str(DefaultReply),"")
return DefaultReply
else:
if ReplyType=="U":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp.upper()),"")
return usr_resp.upper()
if ReplyType=="FN":
if os.path.isfile(usr_resp)==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Filename ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
else:
printc ("!!","Filename [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="FP":
if os.path.exists(usr_resp)==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Path ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
else:
printc ("!!","Filename/Pathname [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="PN":
if os.path.isdir(usr_resp)==True:
if usr_resp[-1:]!="/":
usr_resp=usr_resp + "/"
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Path ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
else:
printc ("!!","Path [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="L":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp.lower()),"")
return usr_resp.lower()
if ReplyType=="N":
if usr_resp.isdigit()==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp;
else:
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if DefaultReply=="":
if usr_resp=="":
if ReplyText!="":
usr_resp=raw_input(bcolor + "[" + pcolor + "?" + bcolor + "] " + tcolor + QuestionText + " ( " + pcolor + ReplyText + tcolor + " ) : " + fcolor.BWhite)
return usr_resp;
else:
if ReplyType=="MA" or ReplyType=="FN" or ReplyType=="PN" or ReplyType=="FP":
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
else:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str("Nothing"),"")
return usr_resp;
else:
if ReplyType=="MN":
if usr_resp.isdigit()==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp;
else:
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="FN":
if os.path.isfile(usr_resp)==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Filename ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
else:
printc ("!!","Filename [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="PN":
if os.path.isdir(usr_resp)==True:
if usr_resp[-1:]!="/":
usr_resp=usr_resp + "/"
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Path ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
else:
printc ("!!","Path [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="FP":
if os.path.exists(usr_resp)==True:
if os.path.isfile(usr_resp)==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Filename ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
if os.path.isdir(usr_resp)==True:
if usr_resp[-1:]!="/":
usr_resp=usr_resp + "/"
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Path ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp
return usr_resp
else:
printc ("!!","Filename/Pathname [" + fcolor.SYellow + usr_resp + fcolor.SRed + "] does not exist !.","")
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if ReplyType=="U":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp.upper()),"")
return usr_resp.upper()
if ReplyType=="L":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp.lower()),"")
return usr_resp.lower()
if ReplyType=="N":
if usr_resp.isdigit()==True:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp;
else:
usr_resp=AskQuestion(QuestionText, ReplyText,ReplyType,DefaultReply,DisplayReply)
return usr_resp;
if usr_resp=="":
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str("Nothing"),"")
return usr_resp;
else:
if DisplayReply=="1":
printc (" ",fcolor.SWhite + "Selected ==> " + fcolor.BYellow + str(usr_resp),"")
return usr_resp;
def printl (DisplayText,ContinueBack,PrevIconCount):
"""
Function : Displaying text on the same line
Usage of printl:
DisplayText - Text to Display
ContinueBack = "0" - Start DisplayText on beginning of line.
ContinueBack = "1" - Start from the back of the previous DisplayText
ContinueBack = "2" - Start DisplayText on beginning of line with Icon,PrevIconCount need to contain value
PrevIconCount - Value of last icon count
Examples : Lookup DemoOnPrintl() for examples
"""
icolor=fcolor.BGreen
bcolor=fcolor.SWhite
IconDisplay=""
if ContinueBack=="":
ContinueBack="0"
if PrevIconCount=="":
PrevIconCount="0"
else:
PrevIconCount=int(PrevIconCount)+1
if PrevIconCount>=8:
PrevIconCount=0
PrevIconCount=str(PrevIconCount)
if PrevIconCount=="0":
IconDisplay="|"
if PrevIconCount=="1":
IconDisplay="/"
if PrevIconCount=="2":
IconDisplay="-"
if PrevIconCount=="3":
IconDisplay="\\"
if PrevIconCount=="4":
IconDisplay="|"
if PrevIconCount=="5":
IconDisplay="/"
if PrevIconCount=="6":
IconDisplay="-"
if PrevIconCount=="7":
IconDisplay="\\"
if ContinueBack=="0":
curses.setupterm()
TWidth=curses.tigetnum('cols')
TWidth=TWidth-1
sys.stdout.write("\r")
sys.stdout.flush()
sys.stdout.write (" " * TWidth + "\r")
sys.stdout.flush()
sys.stdout.write(DisplayText)
sys.stdout.flush()
if ContinueBack=="1":
sys.stdout.write(DisplayText)
sys.stdout.flush()
if ContinueBack=="2":
curses.setupterm()
TWidth=curses.tigetnum('cols')
TWidth=TWidth-1
sys.stdout.write("\r")
sys.stdout.flush()
sys.stdout.write (" " * TWidth + "\r")
sys.stdout.flush()
sys.stdout.write(bcolor + "[" + icolor + str(IconDisplay) + bcolor + "] " + DisplayText)
sys.stdout.flush()
return str(PrevIconCount);
def DrawLine(LineChr,LineColor,LineCount):
"""
Function : Drawing of Line with various character type, color and count
Usage of DrawLine:
LineChr - Character to use as line
LineColor - Color of the line
LineCount - Number of character to print. "" is print from one end to another
Examples : Lookup DemoDrawLine for examples
"""
printd(fcolor.CDebugB + "DrawLine Function\n" + fcolor.CDebug + " LineChr - " + str(LineChr) + "\n " + "LineColor = " + str(LineColor) + "\n " + "LineCount = " + str(LineCount))
if LineColor=="":
LineColor=fcolor.SBlack
if LineChr=="":
LineChr="_"
if LineCount=="":
curses.setupterm()
TWidth=curses.tigetnum('cols')
TWidth=TWidth-1
else:
TWidth=LineCount
print LineColor + LineChr * TWidth
def MoveInstallationFiles(srcPath,dstPath):
import shutil
listOfFiles = os.listdir(srcPath)
listOfFiles.sort()
for f in listOfFiles:
if f!=".git" and f!=".gitignore":
srcfile = srcPath + f
dstfile = dstPath + f
if f==ScriptName:
shutil.copy2(srcfile, "/usr/sbin/" + str(ScriptName))
printd("Copy to " + "/usr/sbin/" + str(ScriptName))
result=os.system("chmod +x /usr/sbin/" + ScriptName + " > /dev/null 2>&1")
printd("chmod +x " + "/usr/sbin/" + str(ScriptName))
if os.path.exists(dstfile):
os.remove(dstfile)
shutil.move(srcfile, dstfile)
print fcolor.SGreen + " Moving " + fcolor.CUnderline + f + fcolor.CReset + fcolor.SGreen + " to " + dstfile
if f==ScriptName:
result=os.system("chmod +x " + dstfile + " > /dev/null 2>&1")
printd("chmod +x " + str(dstfile))
def GetScriptVersion(cmdScriptName):
if cmdScriptName=="":
cmdScriptName=str(os.path.realpath(os.path.dirname(sys.argv[0]))) + "/" + str(os.path.basename(__file__))
VerStr=""
findstr="appver=\""
printd ("Get Version : " + cmdScriptName)
if os.path.exists(cmdScriptName)==True:
ps=subprocess.Popen("cat " + cmdScriptName + " | grep '" + findstr + "' | sed -n '1p'" , shell=True, stdout=subprocess.PIPE)
VerStr=ps.stdout.read()
VerStr=VerStr.replace("appver=\"","")
VerStr=VerStr.replace("\"","")
VerStr=VerStr.replace("\n","")
return VerStr;
def GetUpdate(ExitMode):
if ExitMode=="":
ExitMode="1"
github="https://github.com/SYWorks/wireless-ids.git"
Updatetmpdir="/tmp/git-update/"
DownloadedScriptLocation=Updatetmpdir + ScriptName
dstPath=os.getcwd() + "/"
dstPath=appdir
dstScript=dstPath + ScriptName
CurVersion=GetScriptVersion(dstScript)
printc (".","Retrieving update details ....","")
result=RemoveTree(Updatetmpdir,"")
result=os.system("git clone " + github + " " + Updatetmpdir + " > /dev/null 2>&1")
if result==0:
printc (" ",fcolor.SGreen + "Package downloaded..","")
NewVersion=GetScriptVersion(DownloadedScriptLocation)
if CurVersion!=NewVersion:
printc ("i","Current Version\t: " + fcolor.BRed + str(CurVersion),"")
printc (" ",fcolor.BWhite + "New Version\t: " + fcolor.BRed + str(NewVersion),"")
Ask=AskQuestion ("Do you want to update ?","Y/n","","Y","")
if Ask=="y" or Ask=="Y" or Ask=="":
srcPath=Updatetmpdir
result=MoveInstallationFiles(srcPath,dstPath)
result=os.system("chmod +x " + dstScript + " > /dev/null 2>&1")
result=RemoveTree(Updatetmpdir,"")
print ""
printc ("i",fcolor.BGreen + "Application updated !!","")
printc (" ",fcolor.SGreen + "Re-run the updated application on [ " + fcolor.BYellow + dstScript + fcolor.SGreen + " ]..","")
if ExitMode=="1":
exit(0)
else:
return
else:
printc ("i",fcolor.BWhite + "Update aborted..","")
result=RemoveTree(Updatetmpdir,"")
else:
printc ("i","Your already have the latest version [ " + fcolor.BRed + str(CurVersion) + fcolor.BWhite + " ].","")
printc (" ",fcolor.BWhite + "Update aborted..","")
result=RemoveTree(Updatetmpdir,"")
if ExitMode=="1":
exit(0)
else:
return
else:
printd ("Unknown Error : " + str(result))
printc ("!!!","Unable to retrieve update !!","")
if ExitMode=="1":
exit(1)
else:
return
def GetDir(LookupPath):
"""
Function : Return the varius paths such as application path, current path and Temporary path
Example :
"""
import os
import tempfile
pathname, scriptname = os.path.split(sys.argv[0])
if LookupPath=="":
LookupPath="appdir"
LookupPath=LookupPath.lower()
if LookupPath=="curdir":
result=os.getcwd()
if LookupPath=="appdir":
result=os.path.realpath(os.path.dirname(sys.argv[0]))
if LookupPath=="exedir":
result=os.path.dirname(sys.executable)
if LookupPath=="relativedir":
result=pathname
if LookupPath=="scriptdir":
result=os.path.abspath(pathname)
if LookupPath=="sysdir":
result=sys.path[0]
if LookupPath=="pypath":
result=sys.path[1]
if LookupPath=="homedir":
result=os.environ['HOME']
if LookupPath=="tmpdir":
result=tempfile.gettempdir()
if LookupPath=="userset":
result=appdir
result=result + "/"
if result[-2:]=="//":
result=result[:len(str(result))-1]
return result;
def CheckLinux():
"""
Function : Check for Current OS. Exit if not using Linux
"""
from subprocess import call
from platform import system
os = system()
printd ("Operating System : " + os)
if os != 'Linux':
printc ("!!!","This application only works on Linux.","")
exit(1)
def CheckPyVersion(MinPyVersion):
"""
Function : Check for current Python Version.
Exit if current version is less than MinPyVersion
"""
import platform
PyVersion = platform.python_version()
printd ("Python Version : " + PyVersion)
if MinPyVersion!="":
if MinPyVersion >= PyVersion:
printc ("!!!",fcolor.BGreen + "Your Python version " + fcolor.BRed + str(PyVersion) + fcolor.BGreen + " may be outdated.","")
printc (" ",fcolor.BWhite + "Minimum version required for this application is " + fcolor.BRed + str(MinPyVersion) + fcolor.BWhite + ".","")
exit(0)
def GetAppName():
"""
Function : Get Current Script Name
Return : ScriptName = Actual script name
DScriptName = For Display
"""
global ScriptName
global FullScriptName
global DScriptName
ScriptName=os.path.basename(__file__)
DScriptName="./" + ScriptName
appdir=os.path.realpath(os.path.dirname(sys.argv[0]))
FullScriptName=str(appdir) + "/" + str(ScriptName)
printd("FullScriptName : " + FullScriptName)
printd("ScriptName : " + str(ScriptName))
def DisplayAppDetail():
print fcolor.SBlue + " $$$$$ $ $$ $ $$ $$$$$ $$$$$ $$ $ $$$$$" + fcolor.SYellow + " / \\"
print fcolor.SBlue + " $ $ $$ $ $ $$ $ $$ $ $$ $$ $$ $ " + fcolor.SYellow + " ( R )"
print fcolor.SBlue + " $$$$ $$$$ $ $$ $ $ $$ $$$$$ $$$$ $$$$" + fcolor.SYellow + " \\_/"
print fcolor.SBlue + " $ $$ $ $ $ $$ $ $$ $ $$ $ $$ $$"
print fcolor.SBlue + " $ $$ $ $ $$$ $$ $$ $ $$ $ $$ $"
print fcolor.SBlue + " $$$$$ $$ $$ $$ $$$$$ $ $$ $ $$ $$$$$ "
print ""
print fcolor.BGreen + apptitle + " " + appver + fcolor.SGreen + " " + appDesc
print fcolor.CReset + fcolor.White + appnote
print ""
def DisplayDisclaimer():
printc ("!!!","Legal Disclaimer :- " + fcolor.Red + "FOR EDUCATIONAL PURPOSES ONLY !!","")
print fcolor.SWhite + " Usage of this application for attacking target without prior mutual consent is illegal. It is the"
print fcolor.SWhite + " end user's responsibility to obey all applicable local, state and federal laws. Author assume no"
print fcolor.SWhite + " liability and are not responsible for any misuse or damage caused by this application."
print ""
def DisplayFullDescription():
print fcolor.BRed + " Description : "
print fcolor.SGreen + " This a a beta release and reliablity of the information might not be totally accurate.."
print fcolor.SWhite + " This application sniff the surrounding wireless network for any suspicious packets detected such as high amount of"
print fcolor.SWhite + " association/authentication packets, suspicious data sent via broadcast address, unreasonable high amount of deauth"
print fcolor.SWhite + " packets or EAP association packets which in the other way indicated possible way indicated possible WEP/WPA/WPS"
print fcolor.SWhite + " attacks found.."
print fcolor.BWhite + " New !! " + fcolor.SWhite + "Detecting connected client for possible Rogue AP"
print ""
def DisplayDescription():
print fcolor.BRed + "Description : "
print fcolor.SWhite + " This application sniff your surrounding wireless traffic and analyse for suspicious packets such as"
print fcolor.SWhite + " WEP/WPA/WPS attacks, wireless client switched to another access point, detection of possible Rogue AP,"
print fcolor.SWhite + " displaying AP with the same name and much more.. "
print ""
def DisplayDetailHelp():
print fcolor.BGreen + "Usage : " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " [options] " + fcolor.BBlue + "<args>"
print fcolor.CReset + fcolor.Black + " Running application without parameter will fire up the interactive mode."
print ""
print fcolor.BIPink + "Options:" + fcolor.CReset
print fcolor.BWhite + " -h --help\t\t" + fcolor.CReset + fcolor.White + "- Show basic help message and exit"
print fcolor.BWhite + " -hh \t\t" + fcolor.CReset + fcolor.White + "- Show advanced help message and exit"
print fcolor.BWhite + " --update\t" + fcolor.CReset + fcolor.White + "- Check for updates"
print fcolor.BWhite + " --remove\t" + fcolor.CReset + fcolor.White + "- Uninstall application"
print ""
print fcolor.BWhite + " -l --loop" + fcolor.BBlue + " <arg>\t" + fcolor.CReset + fcolor.White + "- Run the number of loop before exiting"
print fcolor.BWhite + " -i --iface" + fcolor.BBlue + " <arg>\t" + fcolor.CReset + fcolor.White + "- Set Interface to use"
print fcolor.BWhite + " -t --timeout" + fcolor.BBlue + " <arg>\t" + fcolor.CReset + fcolor.White + "- Duration to capture before analysing the captured data"
print fcolor.BWhite + " -hp --hidepropbe" + fcolor.BBlue + "\t" + fcolor.CReset + fcolor.White + "- Hide displaying of Probing devices."
print fcolor.BWhite + " -la --log-a" + fcolor.BBlue + " \t" + fcolor.CReset + fcolor.White + "- Append to current scanning log detail"
print fcolor.BWhite + " -lo --log-o" + fcolor.BBlue + " \t" + fcolor.CReset + fcolor.White + "- Overwrite existing scanning logs"
print fcolor.BWhite + " --log" + fcolor.BBlue + "\t\t" + fcolor.CReset + fcolor.White + "- Similar to --log-o"
print ""
print fcolor.BGreen + "Examples: " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " --update"
print fcolor.BGreen + " " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " -i " + fcolor.BBlue + "wlan0" + fcolor.BWhite + " -t " + fcolor.BBlue + "120"+ fcolor.BWhite
print fcolor.BGreen + " " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " --loop " + fcolor.BBlue + "10" + fcolor.BWhite + " --timeout " + fcolor.BBlue + "30"+ fcolor.BWhite
print fcolor.BGreen + " " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " --iface " + fcolor.BBlue + "wlan1" + fcolor.BWhite + " --timeout " + fcolor.BBlue + "20"+ fcolor.BWhite
print ""
DrawLine("-",fcolor.CReset + fcolor.Black,"")
print ""
def DisplayHelp():
print fcolor.BGreen + "Usage : " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " [options] " + fcolor.BBlue + "<args>"
print fcolor.CReset + fcolor.Black + " Running application without parameter will fire up the interactive mode."
print ""
print fcolor.BIPink + "Options:" + fcolor.CReset
print fcolor.BWhite + " -h --help\t\t" + fcolor.CReset + fcolor.White + "- Show basic help message and exit"
print fcolor.BWhite + " -hh \t\t" + fcolor.CReset + fcolor.White + "- Show advanced help message and exit"
print ""
print fcolor.BWhite + " -i --iface" + fcolor.BBlue + " <arg>\t" + fcolor.CReset + fcolor.White + "- Set Interface to use"
print fcolor.BWhite + " -t --timeout" + fcolor.BBlue + " <arg>\t" + fcolor.CReset + fcolor.White + "- Duration to capture before analysing the captured data"
print fcolor.BWhite + " -hp --hidepropbe" + fcolor.BBlue + "\t" + fcolor.CReset + fcolor.White + "- Hide displaying of Probing devices."
print ""
print fcolor.BGreen + "Examples: " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " --update"
print fcolor.BGreen + " " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " -i " + fcolor.BBlue + "wlan0" + fcolor.BWhite + " -t " + fcolor.BBlue + "120"+ fcolor.BWhite
print fcolor.BGreen + " " + fcolor.BYellow + "" + DScriptName + fcolor.BWhite + " --iface " + fcolor.BBlue + "wlan1" + fcolor.BWhite + " --timeout " + fcolor.BBlue + "20"+ fcolor.BWhite
print ""
DrawLine("-",fcolor.CReset + fcolor.Black,"")
print ""
def GetParameter(cmdDisplay):
"""
cmdDisplay = "0" : Does not display help if not specified
"1" : Display help even not specified
"2" : Display Help, exit if error
"""
global DebugMode
global AllArguments
global SELECTED_IFACE
global PRINTTOFILE
global ReadPacketOnly
global LoopCount
global TEMP_HIDEPROBE
TEMP_HIDEPROBE="0"
ReadPacketOnly=""
LoopCount=99999999
SELECTED_IFACE=""
global SELECTED_MON
SELECTED_MON=""
PRINTTOFILE=""
global TIMEOUT
TIMEOUT=20
global ASSIGNED_MAC
ASSIGNED_MAC=""
global SPOOF_MAC
SPOOF_MAC=""
AllArguments=""
import sys, getopt
if cmdDisplay=="":
cmdDisplay="0"
Err=0
totalarg=len(sys.argv)
printd ("Argument Len : " + str(totalarg))
printd ("Argument String : " + str(sys.argv))
if totalarg>1:
i=1
while i < totalarg:
Err=""
if i>0:
i2=i+1
if i2 >= len(sys.argv):
i2=i
i2str=""
else:
i2str=str(sys.argv[i2])
argstr=("Argument %d : %s" % (i, str(sys.argv[i])))
printd (argstr)
arg=str(sys.argv[i])
if arg=="-h" or arg=="--help":
DisplayHelp()
Err=0
exit()
break;
elif arg=="-hh":
DisplayDetailHelp()
Err=0
exit()
elif arg=="-ro":
Err=0
ReadPacketOnly="1"
elif arg=="--update":
Err=0
GetUpdate("1")
exit()
elif arg=="--remove":
Err=0
UninstallApplication()
exit()
elif arg=="--spoof":
AllArguments=AllArguments + fcolor.BWhite + "Spoof MAC\t\t: " + fcolor.BRed + "Enabled\n"
SPOOF_MAC="1"
Err=0
elif arg=="-m" or arg=="--mac":
i=i2
if i2str=="":
printc("!!!","Invalid MAC Address set !","")
Err=1
else:
Err=0
if i2str[:1]!="-":
if len(i2str)==17:
Result=CheckMAC(i2str)
if Result!="":
ASSIGNED_MAC=i2str
AllArguments=AllArguments + fcolor.BWhite + "Selected MAC\t\t: " + fcolor.BRed + i2str + "\n"
SPOOF_MAC="1"
else:
printc("!!!","Invalid MAC Address set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
else:
printc("!!!","Invalid MAC Address set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
else:
printc("!!!","Invalid MAC Address set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
elif arg=="-t" or arg=="--timeout":
i=i2
if i2str=="":
printc("!!!","Invalid timeout variable set !","")
Err=1
else:
Err=0
if i2str[:1]!="-":
if i2str.isdigit():
TIMEOUT=i2str
AllArguments=AllArguments + fcolor.BWhite + "Timeout (Seconds)\t: " + fcolor.BRed + str(TIMEOUT) + "\n"
if float(TIMEOUT)<20:
AllArguments=AllArguments + fcolor.SWhite + "\t\t\t: Timeout second set may be to low for detection.\n"
else:
printc("!!!","Invalid timeout variable set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
else:
printc("!!!","Invalid timeout variable set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
elif arg=="-l" or arg=="--loop":
i=i2
if i2str=="":
printc("!!!","Invalid loopcount variable set !","")
Err=1
else:
Err=0
if i2str[:1]!="-":
if i2str.isdigit():
LoopCount=i2str
if float(LoopCount)<1:
AllArguments=AllArguments + fcolor.SWhite + "\t\t\t: Minimum loop count is 1.\n"
LoopCount=1
AllArguments=AllArguments + fcolor.BWhite + "Loop Count\t\t: " + fcolor.BRed + str(LoopCount) + "\n"
else:
printc("!!!","Invalid loop count variable set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
else:
printc("!!!","Invalid loop count variable set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
elif arg=="-i" or arg=="--iface":
i=i2
if i2str=="":
printc("!!!","Invalid Interface variable set !","")
Err=1
else:
Err=0
if i2str[:1]!="-":
SELECTED_IFACE=i2str
AllArguments=AllArguments + fcolor.BWhite + "Selected interface\t: " + fcolor.BRed + i2str + "\n"
else:
printc("!!!","Invalid Interface variable set [ " + fcolor.BWhite + i2str + fcolor.BRed + " ] !","")
Err=1
elif arg=="--hideprobe" or arg=="-hp":
TEMP_HIDEPROBE="1"
AllArguments=AllArguments + fcolor.BWhite + "Probing Devices\t\t: " + fcolor.BRed + "Hide\n"
Err=0
elif arg=="--log-a" or arg=="-la":
PRINTTOFILE="1"
AllArguments=AllArguments + fcolor.BWhite + "Result Logging\t\t: " + fcolor.BRed + "Append\n"
Err=0
elif arg=="--log-o" or arg=="-lo" or arg=="--log":
PRINTTOFILE="1"
AllArguments=AllArguments + fcolor.BWhite + "Result Logging\t\t: " + fcolor.BRed + "Overwrite\n"
open(LogFile,"wb").write("")
Err=0
elif Err=="":
DisplayHelp()
printc("!!!","Invalid option set ! [ " + fcolor.BGreen + arg + fcolor.BRed + " ]","")
Err=1
exit(0)
if Err==1:
if cmdDisplay=="2":
print ""
DisplayHelp()
exit(0)
i=i+1
if AllArguments!="":
print fcolor.BYellow + "Parameter set:"
print AllArguments
else:
print ""
DisplayHelp()
print ""
printc ("i", fcolor.BCyan + "Entering Semi-Interactive Mode..","")
result=DisplayTimeStamp("start","")
print ""
else:
if cmdDisplay=="1":
DisplayHelp()