/
escan
executable file
·1007 lines (953 loc) · 26.3 KB
/
escan
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
#!/bin/bash
# Eternal Scanner 2.3 by peterpt
# https://gitlab.com/peterpt/eternal_scanner
#
# Eternal Scanner scans a network looking for vulnerable windows machines to the exploit CVE-2017-0144
# https://www.cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0144
#
#-------------Variables---------------------------
path=$(pwd)
#setup colors
cyan='\e[0;36m'
green='\033[92m'
red='\e[1;31m'
yellow='\e[0;33m'
orange='\e[38;5;166m'
rt="500"
#Current Version
vers="2.3"
# Set Default Data directory
defdir="/usr/local/share/Eternal_Scanner"
# Set default Scanner Speed
rt="500"
# Set Default Port
port="445"
# Files copied in instalation
fls="0"
# Variables for Data files & temp files
vuln="vuln.txt"
vulnos="vuln_OS.txt"
vulndp="vuln_DP.txt"
vulntmp="vulntmp.txt"
vulner="vulner.txt"
vulnertmp="vulner_tmp.txt"
vulndptmp="vulndptmp.txt"
msflog="msflog.log"
temp1="temp1.txt"
vuln1="vuln1.txt"
vulnch="vulnch.txt"
vulnostmp="vulnostmp.txt"
temp="temp.txt"
eromance="python3 $defdir/check"
ip=""
vm="0"
massd="0"
var2="0"
# ------------------------------------------------------------------
# CTRL+C Interrupt for scanner
trap ctrl_c INT
function ctrl_c() {
if [ "$stat" == "1" ]
then
pkill -f masscan* >/dev/null 2>&1
fi
}
chknet () {
echo -e "GET http://google.com HTTP/1.0\n\n" | nc google.com 80 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e "$yellow" "Opps , not connected to Internet"
exit 1
fi
}
#Check install
if [ ! -d "$defdir" ]
then
mkdir "$defdir" >/dev/null 2>&1
if [ -f "$path/$vuln" ]
then
mv "$path/$vuln" "$defdir/" >/dev/null 2>&1
fls="1"
fi
if [ -f "$path/$vulndp" ]
then
mv "$path/$vulndp" "$defdir/" >/dev/null 2>&1
fi
if [ -f "$path/$vulnos" ]
then
mv "$path/$vulnos" "$defdir/" >/dev/null 2>&1
fi
fi
if [ ! -f "$defdir/mysmb.py" ]
then
if [ -f "$path/mysmb.py" ]
then
cp "$path/mysmb.py" "$defdir/mysmb.py" >/dev/null 2>&1
chmod +x $defdir/mysmb.py >/dev/null 2>&1
fi
fi
if [ ! -f "$defdir/mysmb.pyc" ]
then
if [ -f "$path/mysmb.pyc" ]
then
cp "$path/mysmb.pyc" "$defdir/mysmb.pyc" >/dev/null 2>&1
chmod +x $defdir/mysmb.pyc >/dev/null 2>&1
fi
fi
if [ ! -f "$defdir/check" ]
then
if [ -f "$path/check" ]
then
cp "$path/check" "$defdir/check" >/dev/null 2>&1
chmod +x $defdir/check >/dev/null 2>&1
fi
echo -e "$orange" "Updated : Eternal Scanner $vers"
echo ""
if [ $fls == "1" ]
then
echo -e "$green" "Your Eternal Scanner Data Files were moved to :"
echo -e "$yellow""$defdir"
echo -e ""
echo -e "$yellow" "Press ENTER key To Continue"
read -r cont
echo ""
cp escan /usr/local/sbin/ >/dev/null 2>&1
cp elog /usr/local/sbin/ >/dev/null 2>&1
echo ""
echo -e "$green" "Eternal Scanner was installed in your system"
echo ""
echo -e "$orange" "Write (escan) or (escan -h) anywhere to run it."
echo ""
echo -e "$yellow" "Press ENTER key To Continue"
read -r cont
else
cp escan /usr/local/sbin/ >/dev/null 2>&1
cp elog /usr/local/sbin/ >/dev/null 2>&1
echo ""
echo -e "$green" "Eternal Scanner was installed in your system"
echo ""
echo -e "$orange" "Write (escan) or (escan -h) anywhere to run it."
echo ""
echo -e "$yellow" "Press ENTER key To Continue"
read -r cont
fi
fi
warn() {
if [[ $i -gt $wrn ]]
then
wrn=$((wrn+20))
else
if [[ $i == "$wrn" ]]
then
echo ""
echo -e "$red""Press CTRL+Z To Stop The IP Check"
echo ""
fi
fi
}
chker() {
rm -rf $defdir/$temp1
$eromance $var > $defdir/$temp1 2>&1
# ip file to be created in current path with vulnerable ips
ipl=$defdir/$vulner
# Check from output if connection to ip had a timeout
gtdata=$(cat $defdir/$temp1 | grep "timeout")
if [[ ! -z $gtdata ]]
then
echo -e "$yellow Time Out / Offline"
else
gtdata=$(cat $defdir/$temp1 | grep "not patched")
# timeout was not recieved , so check if ip is vulnerable
if [[ ! -z $gtdata ]]
then
gos=$(cat $defdir/$temp1 | grep "Windows" | awk '{$1=$2=""; print $0}')
echo -e "$green Vulnerable"
if [[ -f $defdir/$vulner ]]
then
echo "$var | $gos" >> $ipl
else
echo "Vulnerable Ips to Eternal Romance Exploit (SMB V1)(MS17-010) - Scanned by Eternal Scanner" > $ipl
echo "-----------------------------------------------------------------------------------------" >> $ipl
echo "$var | $gos" >> $ipl
fi
else
echo -e "$yellow Not Vulnerable"
fi
fi
warn
}
etr() {
wrn="0"
f1="$defdir/check"
f2="$defdir/mysmb.py"
f3="$defdir/mysmb.pyc"
if [ ! -f "$f1" ]
then
echo -e "$yellow""An Important dependency is missing ($cyan check$yellow file)"
echo -e "$green""Write (escan -u) to update Eternal Scanner"
exit 1
fi
if [ ! -f "$f2" ]
then
echo -e "$yellow""An Important dependency is missing ($cyan mysmb.py$yellow file)"
echo -e "$green""Write (escan -u) to update Eternal Scanner"
exit 1
fi
if [ ! -f "$f3" ]
then
echo -e "$yellow""An Important dependency is missing ($cyan mysmb.pyc$yellow file)"
echo -e "$green""Write (escan -u) to update Eternal Scanner"
exit 1
fi
if [ -f "$defdir/$vuln" ]
then
delf
tempf=$(tail -n+3 $defdir/$vuln | sed -e "s/:445//g")
echo "$tempf" > "$defdir/$vulnertmp"
tr " " "\n" <$defdir/$vulnertmp >$defdir/$vulner
rm -f "$defdir/$vulnertmp" >/dev/null 2>&1
mv $defdir/$vulner $defdir/$vulnertmp >/dev/null 2>&1
lm=$(wc -l < $defdir/$vulnertmp)
$eromance > $defdir/$temp1 2>&1
chker=$(grep "ImportError" < $defdir/$temp1 | awk '{print$5}')
if [[ ! -z "$chker" ]]
then
echo -e "$yellow" "Dependency Missing : $chker"
echo ""
echo -e "$green" "Try : apt-get install python-crypto python-impacket python-pyasn1-modules"
exit 1
else
echo -e "$green" "Eternal Romance (SMB V1) IP List Check"
echo -e "$cyan" "Checking :$yellow $defdir/$vuln"
echo -e "$orange""*****************************************************"
echo -e "$cyan""Output file:$green $defdir/$vulner"
echo -e "$orange""*****************************************************"
echo ""
echo -e "$red""Press CTRL+Z To Stop The IP Check"
echo ""
for i in $(seq "$lm")
do
lg=$defdir/erlog.txt
rm $lg >/dev/null 2>&1
var=$(awk -v nb=$i 'NR==nb' < $defdir/$vulnertmp)
echo -ne "$cyan""IP$yellow $i$cyan from$yellow $lm$cyan :$green $var$cyan --> "
chker
done
fi
else
echo -e "$yellow" "Vulnerable Ip file was not yet created"
exit 1
fi
}
# Database search function
schos(){
clear
if [[ ! -f "$defdir/$vulnos" ]]
then
logo
echo ""
echo -e "$yellow" "Database was not yet build. Use escan"
exit 1
else
logo
echo ""
echo -e "$cyan" "Some search tips"
echo ""
echo -e "$orange""Windows 5.0 =$green Windows 2000"
echo -e "$orange""Windows 5.1 =$green Windows XP 32bit"
echo -e "$orange""Windows 5.2 =$green Windows XP 64bit"
echo -e "$orange""Windows 6.0 =$green Windows Vista"
echo -e "$orange""Windows 6.1 =$green Windows 7"
echo -e "$orange""Windows 7 =$green Windows 7"
echo -e "$orange""Embedded =$green Windows 7 Embedded"
echo -e ""
echo -e "$cyan""Write (exit) or press CTRL+Z to exit"
echo -e "$green"""
echo -ne "Search Database : "
read srch
if [[ -z "$srch" ]]
then
echo ""
echo -e "$yellow" "No input detected , write (exit) or press CTRL+Z to exit"
echo -e "$green" ""
read -p "Press [Enter] to Return"
schos
fi
if [[ "$srch" == "exit" ]]
then
exit 1
else
echo ""
echo -e "$yellow""Search results for : $green $srch"
echo -e "$orange""*****************************************************$green"
echo -e "$orange""***************$cyan Eternal Blue Results$orange ****************"
echo -e "$orange""*****************************************************$green"
var=$(grep "$srch" < "$defdir/$vulnos" | sed -e "s/:445//g")
lc=$(grep "$srch" < "$defdir/$vulnos" | sed -e "s/:445//g" | wc -l)
if [[ -f "$defdir/$vulner" ]]
then
var1=$(grep "$srch" < "$defdir/$vulner")
lc1=$(grep "$srch" < "$defdir/$vulner" | wc -l)
fi
if [[ -z "$var" ]]
then
echo -e "$yellow" "No results found with search term : $srch"
else
grep "$srch" < "$defdir/$vulnos" | sed -e "s/:445//g"
echo -e "$orange""*****************************************************"
echo -e "$cyan" "Found :$yellow $lc$cyan Eternal Blue Results"
echo -e "$green"""
fi
if [[ ! -z $var1 ]]
then
echo -e "$orange""*****************************************************"
echo -e "$orange""*************$cyan Eternal Romance Results$orange ***************"
echo -e "$orange""*****************************************************$green"
grep "$srch" < "$defdir/$vulner"
echo -e "$orange""*****************************************************"
echo -e "$cyan" "Found :$yellow $lc1$cyan Eternal Romance Results"
echo -e "$green" ""
fi
read -p "Press [Enter] key to Return"
schos
fi
fi
}
# Delete temporary files
delf() {
rm -rf "$defdir/temp1.txt" >/dev/null 2>&1
rm -rf "$defdir/temp.txt" >/dev/null 2>&1
rm -f "$defdir/masscan" >/dev/null 2>&1
rm -f "$defdir/msfip" >/dev/null 2>&1
rm -f "$defdir/msf.rc" >/dev/null 2>&1
rm -f "$defdir/msflog.log" >/dev/null 2>&1
rm -f "$path/paused.conf" >/dev/null 2>&1
rm -f "$defdir/pid.tmp" >/dev/null 2>&1
rm -f "$defdir/x$i" >/dev/null 2>&1
rm -f "$defdir/$vulnertmp" >/dev/null 2>&1
rm -f "$defdir/stat" >/dev/null 2>&1
}
# Eternal Scanner Logo
logo() {
echo -e "$orange" "*****************************************"
echo -e "$orange" "*$green ▄▄▄ .▄▄▄▄▄▄▄▄ .▄▄▄ ▐ ▄ ▄▄▄· ▄▄▌ $orange*"
echo -e "$orange" "*$green ▀▄.▀·•██ ▀▄.▀·▀▄ █·•█▌▐█▐█ ▀█ ██• $orange*"
echo -e "$orange" "*$green ▐▀▀▪▄ ▐█.▪▐▀▀▪▄▐▀▀▄ ▐█▐▐▌▄█▀▀█ ██▪ $orange*"
echo -e "$orange" "*$green ▐█▄▄▌ ▐█▌·▐█▄▄▌▐█•█▌██▐█▌▐█ ▪▐▌▐█▌▐▌ $orange*"
echo -e "$orange" "*$green ▀▀▀ ▀▀▀ ▀▀▀ .▀ ▀▀▀ █▪ ▀ ▀ .▀▀▀ $orange*"
echo -e "$orange" "*$green .▄▄ · ▄▄· ▄▄▄· ▐ ▄ ▐ ▄ ▄▄▄ .▄▄▄ $orange*"
echo -e "$orange" "*$green ▐█ ▀. ▐█ ▌▪▐█ ▀█ •█▌▐█•█▌▐█▀▄.▀·▀▄ █· $orange*"
echo -e "$orange" "*$green ▄▀▀▀█▄██ ▄▄▄█▀▀█ ▐█▐▐▌▐█▐▐▌▐▀▀▪▄▐▀▀▄ $orange*"
echo -e "$orange" "*$green ▐█▄▪▐█▐███▌▐█ ▪▐▌██▐█▌██▐█▌▐█▄▄▌▐█•█▌ $orange*"
echo -e "$orange" "*$green ▀▀▀▀ ·▀▀▀ ▀ ▀ ▀▀ █▪▀▀ █▪ ▀▀▀ .▀ ▀ $orange*"
echo -e "$orange" "*****************************************"
echo -e "$orange" "*$green Current Version :$yellow $vers $orange*"
echo -e "$orange" "*****************************************"
}
# Check Eternal Scanner dependencies
chkdep() {
which msfconsole > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Metasploit Framework Missing"
echo ""
echo -e "$yellow" "Try : apt-get install metasploit-framework"
exit 1
fi
which nc > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Netcat Missing"
echo ""
echo -e "$yellow" "Try : apt-get install netcat"
exit 1
fi
which masscan > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Masscan Missing"
echo ""
echo -e "$yellow" "Try : apt-get install masscan"
exit 1
fi
which wget > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Wget Missing"
echo ""
echo -e "$yellow" "Try : apt-get install wget"
exit 1
fi
# Python checks for Eternal Romance Vulnerability check to be implemented
which python3 > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Python3 Missing"
echo ""
echo -e "$yellow" "Try : apt-get install python3"
exit 1
fi
which pip > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
echo -e "$red" "Pip Missing"
echo ""
echo -e "$yellow" "Try : apt-get install python3-pip"
exit 1
fi
}
# Function to extract data from metasploit results
getdata(){
vuln0=$(grep "MS17-010" < $defdir/$msflog | awk '{print$2}')
vuln1=$(grep "MS17-010" < $defdir/$msflog | awk '{print$2}' | sed -n 1p)
vuln2=$(grep "MS17-010" < $defdir/$msflog | awk '{$1=$3=$4=$5=$6=$7=$8=$9=""; print $0}')
vuln3=$(grep "Arch" < $defdir/$msflog | awk '{$1=$3=$4=$5=$6=$7=$8=$9=$10=$11=$13=$14=$15=$16=""; print $0}')
vtmp="$defdir/$vulndptmp"
if [[ -z "$vuln1" ]]
then
echo ""
echo -e "$red" "No vulnerable targets were detected from the list "
delf
else
if [[ ! -z "$vuln3" ]]
then
if [[ ! -f "$defdir/$vulndp" ]]
then
echo "Vulnerable Ips to Eternal Blue exploit (MS17-010) - Scanned by Eternal Scanner" > $defdir/$vulndp
echo "------------------------------------------------------------------------------" >> $defdir/$vulndp
echo " Doublepulsar Implanted Hosts & Architectures " >> $defdir/$vulndp
echo "+----------------------------------------------------------------------------+" >> $defdir/$vulndp
echo "$vuln3" >> "$defdir/$vulndptmp"
awk '!a[$0]++' $defdir/$vulndptmp > $defdir/$vulndp 2>&1
rm -f $defdir/$vulndptmp >/dev/null 2>&1
else
echo "$vuln3" > "$defdir/$vulndptmp"
awk '!a[$0]++' $defdir/$vulndptmp >> $defdir/$vulndp 2>&1
rm -f $defdir/$vulndptmp >/dev/null 2>&1
fi
fi
if [[ ! -f "$defdir/$vulnos" ]]
then
echo "Vulnerable Ips to Eternal Blue exploit (MS17-010) - Scanned by Eternal Scanner" > $defdir/$vulnos
echo "------------------------------------------------------------------------------" >> $defdir/$vulnos
echo " Detailed Vulnerable IP & Operating System File " >> $defdir/$vulnos
echo "+----------------------------------------------------------------------------+" >> $defdir/$vulnos
echo "$vuln2" >> "$defdir/$vulnostmp"
awk '!a[$0]++' $defdir/$vulnostmp > $defdir/$vulnos 2>&1
rm -f $defdir/$vulnostmp >/dev/null 2>&1
else
echo "$vuln2" > "$defdir/$vulnostmp"
awk '!a[$0]++' $defdir/$vulnostmp >> $defdir/$vulnos 2>&1
rm -f $defdir/$vulnostmp >/dev/null 2>&1
fi
if [[ -f "$defdir/$vuln" ]]
then
echo "$vuln0" > $defdir/$vulntmp
# Open the temporary file and filter all ips to one on each line
tr " " "\n" <$defdir/$vulntmp >$defdir/temp1.txt
#Write new detections to last line in vuln.txt
tr " " "\n" <$defdir/temp1.txt >>$defdir/$vuln
rm -f "$defdir/$vulntmp" >/dev/null 2>&1
# Remove duplicates
awk '!a[$0]++' $defdir/$vuln > $defdir/$vulntmp 2>&1
# Remove old vuln.txt file and write the new one without duplicates
rm -f $defdir/$vuln && mv $defdir/$vulntmp $defdir/$vuln >/dev/null 2>&1
# count number of lines in file
lm=$(wc -l < $defdir/temp1.txt)
echo ""
echo -e "$green" "$lm Vulnerable ips found"
echo "---------------------------------------"
# Display the positive results
sed -e "s/:445//g" < "$defdir/temp1.txt"
echo "---------------------------------------"
echo -e "$yellow" "Eternal Scanner saved the vulnerable ips to $defdir/$vuln"
else
echo "$vuln0" > "$defdir/$vulntmp"
rm -f "$defdir/$msflog" >/dev/null 2>&1
tr " " "\n" <$defdir/$vulntmp >$defdir/temp1.txt
#no vuln. file exists , create a new one
echo "Vulnerable Ips to Eternal Blue exploit (MS17-010) - Scanned by Eternal Scanner" > $defdir/$vuln
echo "------------------------------------------------------------------------------" >> $defdir/$vuln
tr " " "\n" <$defdir/temp1.txt >>$defdir/$vuln
rm -f $defdir/$vulntmp >/dev/null 2>&1
# count number of lines in file
lm=$(wc -l < $defdir/temp1.txt)
echo ""
echo -e "$green" "$lm Vulnerable ips found"
echo "---------------------------------------"
# Display the positive results
sed -e "s/:445//g" < "$defdir/temp1.txt"
echo "---------------------------------------"
echo -e "$yellow" "Eternal Scanner saved the vulnerable ips to $defdir/$vuln"
sleep 3
fi
fi
delf
}
#Function for Metasploit multiple files scan (bigger that 500 ips)
msfm(){
for i in $(seq "$tms")
do
rm $defdir/msf.rc >/dev/null 2>&1
echo "spool $defdir/msflog.log" > $defdir/msf.rc
echo "use auxiliary/scanner/smb/smb_ms17_010" >> $defdir/msf.rc
paste -sd, "$defdir/x$i" \
|sed 's/^/set rhosts /; s/,/, /g' \
>>$defdir/msf.rc
echo "set rport $port" >> $defdir/msf.rc
echo "set threads 10" >> $defdir/msf.rc
echo "exploit" >> $defdir/msf.rc
echo "quit -y" >> $defdir/msf.rc
echo ""
#count number of lines in 1st splitted ip list
lc=$(wc -l < "$defdir/x$i" )
echo -e "$green" "Checking ip list $i of $tms"
echo -e "$yellow" "----------------------------"
cat "$defdir/x$i"
echo -e "$yellow" "----------------------------"
echo ""
echo -e "$green" "Press CTRL+C (1X ONLY) to stop vulnerability check on task $i"
echo -e "$green" "(aborting this process now will not verify all ips in task $i of $tms)"
echo ""
echo -e "\033[33;7mPlease Wait , checking $lc ips from task $i of $tms may take a while\033[0m"
stat="2"
# Execute msfconsole script , get PID from msfconsole and start elog
rm -rf "$defdir/stat" >/dev/null 2>&1
echo "2" > $defdir/stat
msfconsole -r $defdir/msf.rc >/dev/null 2>&1 & echo $! > $defdir/pid.tmp & elog
sleep 2
getdata
sleep 4
done
}
#Function for metasploit single or less than 500 ips to be scanned
msfn(){
lc=$(wc -l < "$defdir/msfip" )
if [ "$lc" -gt "100" ]
then
thr="10"
fi
echo "spool $defdir/$msflog" > "$defdir/msf.rc"
echo "use auxiliary/scanner/smb/smb_ms17_010" >> "$defdir/msf.rc"
paste -sd, "$defdir/msfip" \
|sed 's/^/set rhosts /; s/,/, /g' \
>>"$defdir/msf.rc"
echo "set rport $port" >> "$defdir/msf.rc"
echo "set threads $thr" >> "$defdir/msf.rc"
echo "exploit" >> "$defdir/msf.rc"
echo "quit -y" >> "$defdir/msf.rc"
echo ""
echo -e "$green" "Press CTRL+C (1X ONLY) to stop ips vulnerability check"
echo -e "$green" "(aborting this process will not verify all ips)"
echo ""
echo -e "\033[33;7mPlease Wait , checking $lc ips may take a while\033[0m"
stat="2"
rm -rf "$defdir/stat" >/dev/null 2>&1
echo "2" > $defdir/stat
msfconsole -r $defdir/msf.rc >/dev/null 2>&1 & echo $! > $defdir/pid.tmp & elog
sleep 2
getdata
}
# Function to split ip list file bigger than 500 ips
splitip(){
split -d -l 500 $defdir/msfip $defdir/x
tms=$(find $defdir/ -name "x*" | wc -l)
for i in $(seq 0 "$tms")
do
tm=$((i+1))
if [ "$tm" == "11" ]
then
mv "$defdir/x$i" "$defdir/x$tm" >/dev/null 2>&1
else
mv "$defdir/x0$i" "$defdir/x$tm" >/dev/null 2>&1
fi
done
msfm
}
# Function for masscan ip scanner
mass(){
echo ""
echo -e "$orange" "For switches write (escan -h)"
echo -e "$cyan" "Config Port:$yellow $port$cyan | Rate Speed:$yellow $rt$cyan pkt/s"
delf
mass="$defdir/masscan"
echo ""
if [[ -z "$ip" ]]
then
echo -e "$orange" "Enter IP or IP range ."
echo -e "$orange" "Example 1 :$cyan 192.168.1.32"
echo -e "$orange" "Example 2 :$cyan 192.168.1.1/24"
echo ""
echo -ne "$green" "IP/IP Range : ";tput sgr0
read -r ip
fi
echo ""
echo -e "$cyan" "User IP Input :$yellow $ip"
echo ""
#check if user input is empty
if [[ -z "$ip" ]]
then
echo ""
echo -e "$yellow" "Invalid IP/IP Range"
exit 1
fi
#check if user input have any letters
inv=$(echo "$ip" | grep [a-zA-Z] )
if [[ ! -z "$inv" ]]
then
echo ""
echo -e "$yellow" "Invalid IP/IP Range"
exit 1
fi
echo ""
val0="0.0.0.0"
if [ "$ip" == "$val0" ]
then
echo -e "$red" "$ip is not valid"
exit 1
fi
val="0.0.0.0/0"
if [ "$ip" == "$val" ]
then
echo -e "$cyan" "Scanning all internet will take hours !"
echo ""
echo -ne "$green" "Do you still want to continue ? (y/N) : ";tput sgr0
read -r opt
echo ""
case "$opt" in
y|Y|yes|YES|Yes)
echo -e "$green" "Press CTRL+C (1X ONLY) to stop the scanner "
echo ""
tn=$(date +"%H:%M:%S")
echo -e "\033[33;7mScanner started at $tn , Please Wait\033[0m"
rm -rf "$defdir/stat" >/dev/null 2>&1
stat="1"
echo "1" > $defdir/stat
masscan "$ip" -p "$port" --rate "$rt" --exclude 255.255.255.255 --output-filename "$mass" >/dev/null 2>&1 & echo $! > "$defdir/pid.tmp" & elog
echo ""
tst=$(date +"%H:%M:%S")
echo -e "\033[33;7mScanner stopped/finished at $tst \033[0m"
sleep 4
;;
n|N|No|NO)
exit 1
;;
*)
exit 1
;;
esac
else
echo -e "$green" "Press CTRL+C (1X ONLY) to stop the scanner "
echo ""
tn=$(date +"%H:%M:%S")
echo -e "\033[33;7mScanner started at $tn , Please Wait\033[0m"
rm -rf "$defdir/stat" >/dev/null 2>&1
stat="1"
echo "1" > $defdir/stat
masscan "$ip" -p "$port" --rate "$rt" --output-filename "$mass" >/dev/null 2>&1 & echo $! > $defdir/pid.tmp & elog
echo ""
tst=$(date +"%H:%M:%S")
echo -e "\033[33;7mScanner stopped/finished at $tst \033[0m"
sleep 4
fi
if [ ! -f "$mass" ]
then
echo -e "$yellow" "Scanner results not found"
exit 1
fi
grep 'addr=' < "$mass" | awk '{print $3}' | sed -e s/addr=//g | cut -d '"' -f 2 | tr " " "\n" >$defdir/msfip
msfips="$defdir/msfip"
#check if there was any ip detected with port $port opened
if [ ! -s "$msfips" ]
then
echo -e "$yellow" "It was not detected in $ip any port $port opened."
exit 1
fi
stat="0"
echo ""
echo -e "$orange" " Checking ips :"
echo -e "$yellow" "----------------------------"
echo -e "$green" ""
cat "$defdir/msfip"
echo ""
echo -e "$yellow" "----------------------------"
lc=$(wc -l < $defdir/msfip)
echo "Collected $lc ips"
echo -e "$yellow" "Checking if the $lc ips are vulnerable"
sleep 4
# If scanner ip list is bigger than 500 ips , then split the msfip list in multiple files with 500 ips each one
if [ "$lc" -gt "500" ]
then
splitip
thr="10"
else
if [ "$lc" -gt "20" ]
then
thr="5"
else
thr="1"
fi
msfn
fi
}
# escan only written in terminal
if [ -z "$1" ]
then
chknet
chkdep
logo
mass
exit 1
fi
if [ "$1" == "-er" ]
then
chknet
chkdep
logo
etr
exit 1
fi
#Switch for input ip
if [ "$1" == "-i" ]
then
chknet
if [ -z "$2" ]
then
escan -h
echo -e "$yellow" "Value missing"
echo ""
echo -e "$green" "Try (escan -i 192.168.1.1)"
exit 1
else
ip="$2"
if [ -z "$3" ]
then
chkdep
logo
mass
exit 1
else
if [ "$3" == "-s" ]
then
if [ -z "$4" ]
then
chkdep
logo
mass
exit 1
else
if [[ "$4" -ge 100 && "$4" -le 100000000 ]]
then
rt="$4"
chkdep
logo
mass
exit 1
else
echo "Invalid argument , write escan -h for help"
exit 1
fi
fi
fi
fi
fi
fi
if [ "$1" == "-v" ]
then
if [ -f "$defdir/$vuln" ]
then
logo
echo -e "$orange" "Displaying Vulnerability IP file"
echo -e "$yellow" "Currently stored in $defdir"
echo -e "$cyan" "+----------------------------------------------+"
echo -e "$green" ""
sed -e "s/:445//g" < "$defdir/$vuln"
echo -e "$cyan" "+----------------------------------------------+"
nmip=$(tail -n+3 $defdir/$vuln | wc -l )
echo -e "$orange" "Found $yellow $nmip $orange Records"
exit 1
else
echo -e "$yellow" "Vulnerability IP file list not yet available"
echo -e "$green" "Scan for vulnerale hosts by writing (escan) on terminal"
exit 1
fi
fi
if [ "$1" == "-vo" ]
then
if [ -f "$defdir/$vulnos" ]
then
logo
echo -e "$orange" "Displaying Detailed OS Vulnerability IP file"
echo -e "$yellow" "Currently stored in $defdir"
echo -e "$cyan" "+----------------------------------------------+"
echo -e "$green" ""
sed -e "s/:445//g" < "$defdir/$vulnos"
nmip=$(wc -l < $defdir/$vuln)
echo -e "$cyan" "+----------------------------------------------+"
echo -e "$orange" "Found $yellow $nmip $orange Records"
exit 1
else
if [ -f "$defdir/$vuln" ]
then
echo -e "$green" "To display this file you must first write (escan -c) on terminal so your"
echo -e "$green" "vulnerable ip list can be checked , and then you can use (escan -vo)"
exit 1
else
echo -e "$green" "It was not found a vulnerable ip list , write (escan)"
echo -e "$green" "on your terminal to find vulnerable hosts .)"
exit 1
fi
fi
fi
if [ "$1" == "-u" ]
then
chknet
# Check if eternal scanner is installed on a system path
es=$(whereis escan |awk '{print$2}')
el=$(whereis elog |awk '{print$2}')
if [ -z $es ]
then
git pull origin master
echo -e "$green" "Your Eternal Scanner was updated from Git"
exit 1
else
echo -e "$yellow" "Found escan in : $es"
echo -e "$yellow" "Found elog in : $el"
rm -f $es >/dev/null 2>&1
rm -f $el >/dev/null 2>&1
which wget > /dev/null 2>&1
if [ "$?" -eq "1" ]; then
apt-get install wget -y > /dev/null 2>&1
fi
wget https://raw.githubusercontent.com/peterpt/eternal_scanner/master/check -O $defdir/check > /dev/null 2>&1
wget https://raw.githubusercontent.com/peterpt/eternal_scanner/master/mysmb.py -O $defdir/mysmb.py > /dev/null 2>&1
wget https://raw.githubusercontent.com/peterpt/eternal_scanner/master/mysmb.pyc -O $defdir/mysmb.pyc > /dev/null 2>&1
wget https://raw.githubusercontent.com/peterpt/eternal_scanner/master/escan -O $es > /dev/null 2>&1
wget https://raw.githubusercontent.com/peterpt/eternal_scanner/master/elog -O $el > /dev/null 2>&1
chmod +x $es >/dev/null 2>&1
chmod +x $el >/dev/null 2>&1
echo ""
echo -e "$green" "Eternal Scanner Binaries where updated to your system"
echo ""
exit 1
fi
fi
# escan -l switch activated
if [ "$1" == "-l" ]
then
# check if vuln_OS.txt exists
vfos="$defdir/vuln_OS.txt"
if [ ! -f "$vfos" ]
then
echo -e "$yellow" "Detailed vulerable ip list not builded yet , write (escan -c)"
exit 1
else
schos
fi
fi
# escan -h writen in terminal
if [ "$1" == "-h" ]
then
echo "Eternal Scanner $vers - 2017"
echo "(https://github.com/peterpt/eternal_scanner)"
echo "----------------------------------------------------"
echo "Available Switches :"
echo ""
echo "escan -i 192.168.1.1/24 (Scan Ip/Ip Range)"
echo "escan -s (Scanner speed Min: 100 Max: 10000000 /Default : 500)"
echo "escan -c (Verify if ips in vuln.txt are still vulnerable & update list)"
echo "escan -ck /someiplistfile.txt (Will check current user manual ip list)"
echo "escan -er (Verify if ips in vuln.txt are vulnerable to Eternal Romance Vulnerability)"
echo "escan -l (To search in database)"
echo "escan -v (Display current vulnerable ip list on screen)"
echo "escan -vo (Display current vulnerable detailed OS ip list on screen)"
echo "escan -u (Update Eternal Scanner binaries from github)"
echo "escan -h (This screen)"
echo ""
echo "Example : escan -i 192.168.1.1/24 -s 3000 (for 3000 packets /s)"
echo ""
exit 1
fi
out="$2"
if [ "$1" == "-c" ]
then
chknet
if [ -f "$defdir/$vuln" ]
then
delf
cp "$defdir/$vuln" "$defdir/vuln.bak" >/dev/null 2>&1
cp "$defdir/$vulnos" "$defdir/vuln_OS.bak" >/dev/null 2>&1
cp "$defdir/$vulndp" "$defdir/vuln_DP.bak" >/dev/null 2>&1
rm -f "$defdir/$vulnos" >/dev/null 2>&1
rm -f "$defdir/$vulndp" >/dev/null 2>&1
msfi="$defdir/msfip"
tempf=$(tail -n+3 $defdir/$vuln | sed -e "s/:445//g")
echo "$tempf" > "$defdir/$vulntmp"
tr " " "\n" <$defdir/$vulntmp >$msfi
rm -f "$defdir/$vulntmp" >/dev/null 2>&1
lm=$(cat $defdir/$msfi | wc -l)
rm -f "$defdir/$vuln" >/dev/null 2>&1
if [ "$lm" -gt "500" ]
then
chkdep
logo
splitip
msfm
else
chkdep
logo
msfn
fi
else
echo -e "$yellow" "Vulnerable Ip file was not yet created"
exit 1
fi
fi
if [ "$1" == "-ck" ]
then
chknet
if [ -z "$out" ]
then
echo "No input iplist file to check."
exit 1
else
if [ ! -f "$out" ]
then
echo "No iplist found in : $out"
else
delf
cp "$out" "$defdir/msfip"
msfi=$(wc -l < $defdir/msfip)
if [ "$msfi" -gt "500" ]
then
chkdep
logo
echo -e "$yellow" "Checking user input file : $out"
splitip
exit 1
else
chkdep
logo
echo -e "$yellow" "Checking user input file : $out"
msfn
exit 1
fi
fi
fi
fi
if [ "$1" == "-s" ]
then
chknet
if [ -z "$out" ]
then
echo "Invalid argument , write ./escan -h for help"
exit 1
else
if [[ "$2" -ge 100 && "$2" -le 100000000 ]]
then
rt="$2"
if [ -z "$3" ]
then
chkdep
logo
mass