-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtriop.py
862 lines (748 loc) · 65.2 KB
/
triop.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
#!/usr/bin/env python
#
# TriOp
# Tool for quickly gathering information from Shodan.io about the number of IPs which satisfy large number of different queries
#
# Author: Jan Kopriva (https://untrustednetwork.net)
# Licence: GPLv3 (http://www.gnu.org/licenses/gpl-3.0.html)
#
# Version 1.5 (1/2023)
import csv
from datetime import datetime
import glob
import os
import re
import shutil
import string
import sys
import time
import urllib.request
from optparse import OptionParser
from shodan import Shodan
basic_search_list = ["22","23","25","53","80","123","161","389","443","445","636","3389","has_ipv6:true","has_screenshot:true","has_ssl:true","has_vuln:true"]
vuln_list_high = ["1999-0045", "1999-0067", "1999-0233", "1999-0253", "1999-0349", "1999-0407", "1999-0412", "1999-0449", "1999-0450", "1999-0777", "1999-0874", "1999-0926", "1999-1011", "1999-1053", "1999-1199", "1999-1233", "1999-1293", "1999-1376", "2000-0457", "2000-0525", "2000-0746", "2000-0884", "2000-0886", "2000-0970", "2000-0981", "2000-0999", "2000-1104", "2000-1139", "2001-0144", "2001-0333", "2001-0340", "2001-0506", "2001-0529", "2001-0572", "2001-0766", "2001-0816", "2001-1246", "2001-1380", "2001-1449", "2001-1459", "2001-1507", "2002-0061", "2002-0071", "2002-0074", "2002-0075", "2002-0079", "2002-0081", "2002-0083", "2002-0147", "2002-0148", "2002-0149", "2002-0150", "2002-0229", "2002-0257", "2002-0364", "2002-0392", "2002-0575", "2002-0639", "2002-0640", "2002-0655", "2002-0656", "2002-0661", "2002-0717", "2002-0839", "2002-0843", "2002-0869", "2002-0985", "2002-1337", "2002-1374", "2002-1375", "2002-1376", "2002-1396", "2002-1809", "2002-1921", "2002-1923", "2002-2029", "2002-2261", "2002-2272", "2002-2309", "2003-0016", "2003-0097", "2003-0131", "2003-0150", "2003-0161", "2003-0166", "2003-0172", "2003-0249", "2003-0308", "2003-0386", "2003-0542", "2003-0545", "2003-0681", "2003-0682", "2003-0693", "2003-0694", "2003-0695", "2003-0714", "2003-0780", "2003-0786", "2003-0787", "2003-0789", "2003-0860", "2003-0861", "2003-0863", "2003-0993", "2003-1562", "2004-0205", "2004-0488", "2004-0492", "2004-0542", "2004-0574", "2004-0811", "2004-0836", "2004-0840", "2004-0885", "2004-1019", "2004-1065", "2004-1082", "2004-2343", "2005-0245", "2005-0560", "2005-1042", "2005-1344", "2005-1409", "2005-1687", "2005-2108", "2005-2572", "2005-2612", "2005-2700", "2005-3390", "2005-3391", "2005-3392", "2005-4360", "2006-0058", "2006-0097", "2006-0200", "2006-1012", "2006-1017", "2006-1047", "2006-1049", "2006-2313", "2006-2314", "2006-2667", "2006-2753", "2006-2937", "2006-2940", "2006-3017", "2006-3738", "2006-3747", "2006-4028", "2006-4433", "2006-4481", "2006-4482", "2006-4483", "2006-4485", "2006-4812", "2006-4924", "2006-5051", "2006-5444", "2006-5465", "2006-5706", "2006-5794", "2006-6578", "2006-7008", "2006-7009", "2006-7010", "2007-0039", "2007-0213", "2007-0233", "2007-0262", "2007-0448", "2007-0539", "2007-0555", "2007-0905", "2007-0906", "2007-0909", "2007-0910", "2007-0911", "2007-1277", "2007-1376", "2007-1381", "2007-1399", "2007-1412", "2007-1413", "2007-1453", "2007-1461", "2007-1581", "2007-1649", "2007-1700", "2007-1718", "2007-1777", "2007-1825", "2007-1864", "2007-1870", "2007-1883", "2007-1885", "2007-1887", "2007-1888", "2007-1889", "2007-1890", "2007-2246", "2007-2511", "2007-2821", "2007-2844", "2007-2897", "2007-3279", "2007-3280", "2007-3294", "2007-3949", "2007-3997", "2007-4033", "2007-4255", "2007-4586", "2007-4657", "2007-4658", "2007-4659", "2007-4660", "2007-4661", "2007-4662", "2007-4663", "2007-4752", "2007-4825", "2007-4894", "2007-4995", "2007-5424", "2007-6299", "2007-6423", "2007-6601", "2008-0074", "2008-0075", "2008-0145", "2008-0194", "2008-0226", "2008-0599", "2008-1446", "2008-1930", "2008-2050", "2008-2051", "2008-2107", "2008-2108", "2008-2146", "2008-2271", "2008-2384", "2008-2392", "2008-2999", "2008-3225", "2008-3227", "2008-3228", "2008-3658", "2008-3747", "2008-4102", "2008-4105", "2008-4359", "2008-4360", "2008-4769", "2008-4793", "2008-5557", "2008-5624", "2008-5625", "2008-5658", "2008-5695", "2008-5844", "2008-6171", "2008-6767", "2008-7002", "2009-0653", "2009-1491", "2009-1535", "2009-1890", "2009-1891", "2009-2446", "2009-2762", "2009-2853", "2009-3023", "2009-3215", "2009-3245", "2009-3291", "2009-3292", "2009-3293", "2009-3546", "2009-3559", "2009-4018", "2009-4143", "2009-4484", "2009-4565", "2009-4611", "2010-0425", "2010-0742", "2010-1129", "2010-1169", "2010-1256", "2010-1447", "2010-1866", "2010-1868", "2010-2225", "2010-2730", "2010-3864", "2010-3867", "2010-3972", "2010-4166", "2010-4221", "2010-4252", "2010-4344", "2010-4478", "2010-4696", "2011-1092", "2011-1148", "2011-1153", "2011-1407", "2011-1764", "2011-1938", "2011-2687", "2011-3122", "2011-3125", "2011-3129", "2011-3130", "2011-3192", "2011-3268", "2011-3379", "2011-3559", "2011-4109", "2011-4130", "2011-4899", "2012-0553", "2012-0830", "2012-0882", "2012-1116", "2012-1598", "2012-1618", "2012-1823", "2012-2110", "2012-2131", "2012-2311", "2012-2335", "2012-2376", "2012-2386", "2012-2399", "2012-2400", "2012-2688", "2012-2747", "2012-2750", "2012-3158", "2012-3163", "2012-3554", "2013-1453", "2013-1492", "2013-1635", "2013-1839", "2013-1900", "2013-1902", "2013-1903", "2013-2249", "2013-4115", "2013-4338", "2013-4339", "2013-4559", "2013-5697", "2013-6420", "2014-0001", "2014-0185", "2014-1475", "2014-1692", "2014-2323", "2014-3512", "2014-3513", "2014-3515", "2014-3567", "2014-3669", "2014-5203", "2014-6632", "2014-7228", "2014-7981", "2014-7984", "2014-8142", "2014-8176", "2014-8626", "2014-9425", "2014-9426", "2014-9427", "2014-9653", "2014-9705", "2014-9912", "2015-0231", "2015-0273", "2015-0292", "2015-1351", "2015-1503", "2015-1635", "2015-2213", "2015-2331", "2015-2787", "2015-3306", "2015-3307", "2015-3329", "2015-4022", "2015-4025", "2015-4026", "2015-4116", "2015-4147", "2015-4598", "2015-4599", "2015-4600", "2015-4601", "2015-4602", "2015-4603", "2015-4642", "2015-4947", "2015-5589", "2015-5590", "2015-5600", "2015-6527", "2015-6565", "2015-6659", "2015-6831", "2015-6832", "2015-6834", "2015-6835", "2015-6836", "2015-7297", "2015-7857", "2015-7858", "2015-8562", "2015-8564", "2015-8565", "2015-8616", "2015-8617", "2015-8769", "2015-8835", "2015-8865", "2015-8880", "2016-0705", "2016-0766", "2016-0798", "2016-0799", "2016-10009", "2016-10012", "2016-10160", "2016-1904", "2016-2108", "2016-2109", "2016-2177", "2016-2182", "2016-2554", "2016-2842", "2016-3065", "2016-3078", "2016-3088", "2016-3132", "2016-3141", "2016-3168", "2016-3607", "2016-3947", "2016-4071", "2016-4072", "2016-4073", "2016-4342", "2016-4344", "2016-4345", "2016-4346", "2016-4473", "2016-4537", "2016-4538", "2016-4539", "2016-4540", "2016-4541", "2016-4542", "2016-4543", "2016-4544", "2016-5093", "2016-5094", "2016-5095", "2016-5096", "2016-5768", "2016-5769", "2016-5770", "2016-5771", "2016-5772", "2016-5773", "2016-6288", "2016-6290", "2016-6291", "2016-6294", "2016-6295", "2016-6296", "2016-6303", "2016-6304", "2016-6308", "2016-7048", "2016-7124", "2016-7126", "2016-7127", "2016-7129", "2016-7134", "2016-7411", "2016-7413", "2016-7414", "2016-7417", "2016-7479", "2016-7480", "2016-7568", "2016-8670", "2016-8858", "2016-9081", "2016-9137", "2016-9138", "2016-9836", "2016-9935", "2016-9936", "2017-10391", "2017-11142", "2017-11362", "2017-12172", "2017-12868", "2017-12932", "2017-12933", "2017-14723", "2017-15944","2017-16510", "2017-16634", "2017-17663", "2017-3167", "2017-3169", "2017-3249", "2017-3250", "2017-5340", "2017-5611", "2017-6920", "2017-6925", "2017-7269", "2017-7546", "2017-7668", "2017-7679", "2017-8917", "2017-8923", "2017-9119", "2017-9120", "2018-11756", "2018-12882", "2018-15882", "2018-16850", "2018-19518", "2018-20148", "2018-6376", "2018-6789", "2018-7584", "2018-7600", "2018-7602", "2019-0211", "2019-0708", "2019-10149", "2019-10945", "2019-11043","2019-11072", "2019-11510", "2019-12525", "2019-12765", "2019-12815", "2019-13917", "2019-1579","2019-1652", "2019-16928", "2019-19781", "2019-6339", "2019-7524", "2019-7743", "2019-9020", "2019-9021", "2019-9023", "2019-9025", "2019-9193", "2019-9641", "2020-0796", "2020-11651", "2020-13671", "2020-1938", "2020-2021", "2020-28949", "2020-36193", "2020-5902","2021-26855", "2021-26857", "2021-26858", "2021-27065", "2021-31206", "2021-31207", "2021-34473", "2021-34523", "2021-39226", "2021-40438", "2021-41773", "2021-42013", "2022-0028", "2022-36804"]
vuln_list_medium = ["1999-0007", "1999-0012", "1999-0107", "1999-0154", "1999-0191", "1999-0278", "1999-0281", "1999-0348", "1999-0448", "1999-0736", "1999-0737", "1999-0738", "1999-0739", "1999-0867", "1999-1035", "1999-1148", "1999-1223", "1999-1375", "1999-1451", "1999-1478", "1999-1537", "1999-1544", "2000-0024", "2000-0025", "2000-0071", "2000-0114", "2000-0126", "2000-0226", "2000-0246", "2000-0258", "2000-0304", "2000-0408", "2000-0413", "2000-0535", "2000-0630", "2000-0631", "2000-0672", "2000-0770", "2000-0858", "2000-0868", "2000-0869", "2000-0913", "2000-0992", "2000-1147", "2000-1204", "2000-1205", "2000-1206", "2000-1254", "2001-0004", "2001-0042", "2001-0096", "2001-0108", "2001-0122", "2001-0146", "2001-0334", "2001-0335", "2001-0336", "2001-0337", "2001-0361", "2001-0509", "2001-0543", "2001-0545", "2001-0653", "2001-0709", "2001-0729", "2001-0730", "2001-0731", "2001-0925", "2001-1072", "2001-1099", "2001-1141", "2001-1243", "2001-1247", "2001-1255", "2001-1319", "2001-1382", "2001-1385", "2002-0049", "2002-0055", "2002-0072", "2002-0073", "2002-0253", "2002-0368", "2002-0419", "2002-0484", "2002-0654", "2002-0659", "2002-0840", "2002-0969", "2002-0986", "2002-1156", "2002-1181", "2002-1182", "2002-1373", "2002-1568", "2002-1592", "2002-1593", "2002-1658", "2002-1694", "2002-1695", "2002-1717", "2002-1718", "2002-1783", "2002-1790", "2002-1850", "2002-1873", "2002-1908", "2002-1954", "2002-2012", "2002-2103", "2002-2214", "2002-2215", "2003-0017", "2003-0073", "2003-0078", "2003-0083", "2003-0132", "2003-0134", "2003-0147", "2003-0189", "2003-0190", "2003-0192", "2003-0223", "2003-0225", "2003-0226", "2003-0245", "2003-0253", "2003-0254", "2003-0442", "2003-0460", "2003-0543", "2003-0544", "2003-0718", "2003-0851", "2003-0904", "2003-1302", "2003-1303", "2003-1307", "2003-1342", "2003-1418", "2003-1480", "2003-1580", "2004-0079", "2004-0081", "2004-0112", "2004-0113", "2004-0173", "2004-0174", "2004-0175", "2004-0263", "2004-0457", "2004-0493", "2004-0594", "2004-0595", "2004-0747", "2004-0748", "2004-0751", "2004-0786", "2004-0809", "2004-0940", "2004-0942", "2004-0956", "2004-0957", "2004-0958", "2004-1020", "2004-1392", "2004-1653", "2004-2069", "2004-2760", "2005-0004", "2005-0244", "2005-0246", "2005-0247", "2005-0420", "2005-0453", "2005-0524", "2005-0525", "2005-0709", "2005-0710", "2005-0738", "2005-0799", "2005-1043", "2005-1102", "2005-1636", "2005-1688", "2005-1797", "2005-2070", "2005-2088", "2005-2089", "2005-2107", "2005-2109", "2005-2110", "2005-2558", "2005-2573", "2005-2678", "2005-2728", "2005-2797", "2005-2798", "2005-2946", "2005-2969", "2005-2970", "2005-3352", "2005-3353", "2005-3357", "2005-3388", "2005-3389", "2005-3747", "2005-3883", "2005-4463", "2006-0026", "2006-0105", "2006-0207", "2006-0225", "2006-0553", "2006-0814", "2006-0883", "2006-0903", "2006-0985", "2006-0986", "2006-0996", "2006-1015", "2006-1173", "2006-1263", "2006-1490", "2006-1516", "2006-1517", "2006-1518", "2006-1796", "2006-1990", "2006-1991", "2006-2702", "2006-3011", "2006-3081", "2006-3389", "2006-3390", "2006-3469", "2006-3918", "2006-4020", "2006-4023", "2006-4154", "2006-4227", "2006-4339", "2006-4343", "2006-4434", "2006-4743", "2006-4925", "2006-5052", "2006-5178", "2006-5540", "2006-5541", "2006-5542", "2006-5705", "2006-5752", "2006-6016", "2006-6017", "2006-6383", "2006-6579", "2006-6808", "2006-7243", "2006-7250", "2007-0106", "2007-0107", "2007-0109", "2007-0136", "2007-0540", "2007-0541", "2007-0556", "2007-0658", "2007-0907", "2007-1001", "2007-1049", "2007-1230", "2007-1244", "2007-1278", "2007-1285", "2007-1286", "2007-1287", "2007-1375", "2007-1378", "2007-1379", "2007-1380", "2007-1396", "2007-1401", "2007-1409", "2007-1411", "2007-1452", "2007-1454", "2007-1460", "2007-1475", "2007-1484", "2007-1521", "2007-1522", "2007-1582", "2007-1583", "2007-1584", "2007-1599", "2007-1622", "2007-1709", "2007-1710", "2007-1711", "2007-1717", "2007-1741", "2007-1743", "2007-1824", "2007-1835", "2007-1862", "2007-1869", "2007-1884", "2007-1886", "2007-1893", "2007-1894", "2007-1897", "2007-1900", "2007-2243", "2007-2369", "2007-2510", "2007-2583", "2007-2691", "2007-2692", "2007-2748", "2007-2872", "2007-3007", "2007-3102", "2007-3140", "2007-3238", "2007-3239", "2007-3240", "2007-3241", "2007-3278", "2007-3303", "2007-3304", "2007-3639", "2007-3790", "2007-3799", "2007-3806", "2007-3946", "2007-3947", "2007-3948", "2007-3950", "2007-3996", "2007-3998", "2007-4010", "2007-4063", "2007-4064", "2007-4139", "2007-4154", "2007-4441", "2007-4465", "2007-4507", "2007-4528", "2007-4652", "2007-4654", "2007-4670", "2007-4727", "2007-4769", "2007-4782", "2007-4783", "2007-4784", "2007-4840", "2007-4850", "2007-4887", "2007-4889", "2007-4893", "2007-5000", "2007-5105", "2007-5106", "2007-5128", "2007-5135", "2007-5416", "2007-5447", "2007-5593", "2007-5594", "2007-5595", "2007-5596", "2007-5597", "2007-5898", "2007-5899", "2007-5900", "2007-6013", "2007-6067", "2007-6203", "2007-6304", "2007-6318", "2007-6388", "2007-6420", "2007-6422", "2007-6514", "2007-6600", "2007-6750", "2007-6752", "2008-0005", "2008-0191", "2008-0193", "2008-0195", "2008-0196", "2008-0272", "2008-0273", "2008-0276", "2008-0455", "2008-0664", "2008-0891", "2008-0983", "2008-1111", "2008-1270", "2008-1304", "2008-1384", "2008-1483", "2008-1531", "2008-1533", "2008-1657", "2008-1678", "2008-1729", "2008-2068", "2008-2079", "2008-2168", "2008-2247", "2008-2248", "2008-2364", "2008-2665", "2008-2666", "2008-2829", "2008-2936", "2008-2939", "2008-2998", "2008-3222", "2008-3226", "2008-3233", "2008-3234", "2008-3659", "2008-3660", "2008-3740", "2008-3742", "2008-3743", "2008-3744", "2008-3745", "2008-3963", "2008-4097", "2008-4098", "2008-4103", "2008-4104", "2008-4106", "2008-4107", "2008-4109", "2008-4122", "2008-4298", "2008-4789", "2008-4790", "2008-5077", "2008-5113", "2008-5278", "2008-5498", "2008-6532", "2008-6533", "2008-6762", "2008-7068", "2008-7247", "2008-7265", "2008-7270", "2009-0113", "2009-0543", "2009-0590", "2009-0789", "2009-0819", "2009-1195", "2009-1271", "2009-1272", "2009-1280", "2009-1377", "2009-1378", "2009-1386", "2009-1387", "2009-1490", "2009-1523", "2009-1524", "2009-1575", "2009-1576", "2009-1938", "2009-1939", "2009-1940", "2009-2334", "2009-2372", "2009-2373", "2009-2374", "2009-2409", "2009-2431", "2009-2432", "2009-2626", "2009-2687", "2009-2699", "2009-2851", "2009-2854", "2009-2904", "2009-2939", "2009-3229", "2009-3230", "2009-3231", "2009-3294", "2009-3555", "2009-3557", "2009-3558", "2009-3579", "2009-3622", "2009-3639", "2009-3890", "2009-3945", "2009-3946", "2009-4017", "2009-4019", "2009-4028", "2009-4030", "2009-4034", "2009-4136", "2009-4142", "2009-4355", "2009-4418", "2009-4444", "2009-4487", "2009-4609", "2009-4610", "2009-4612", "2009-5016", "2009-5026", "2010-0010", "2010-0295", "2010-0308", "2010-0397", "2010-0408", "2010-0433", "2010-0434", "2010-0639", "2010-0682", "2010-0740", "2010-0928", "2010-1128", "2010-1130", "2010-1170", "2010-1452", "2010-1621", "2010-1633", "2010-1649", "2010-1848", "2010-1849", "2010-1850", "2010-1860", "2010-1861", "2010-1862", "2010-1864", "2010-1899", "2010-1914", "2010-1915", "2010-1917", "2010-1975", "2010-2023", "2010-2024", "2010-2068", "2010-2093", "2010-2094", "2010-2097", "2010-2100", "2010-2101", "2010-2190", "2010-2191", "2010-2484", "2010-2531", "2010-2731", "2010-2791", "2010-2939", "2010-2950", "2010-2951", "2010-3062", "2010-3063", "2010-3064", "2010-3065", "2010-3072", "2010-3091", "2010-3092", "2010-3433", "2010-3436", "2010-3676", "2010-3677", "2010-3678", "2010-3679", "2010-3680", "2010-3681", "2010-3682", "2010-3683", "2010-3685", "2010-3686", "2010-3709", "2010-3710", "2010-3712", "2010-3833", "2010-3834", "2010-3835", "2010-3836", "2010-3837", "2010-3838", "2010-3839", "2010-3840", "2010-3870", "2010-4015", "2010-4150", "2010-4156", "2010-4180", "2010-4257", "2010-4345", "2010-4409", "2010-4536", "2010-4645", "2010-4652", "2010-4697", "2010-4698", "2010-4699", "2010-4700", "2010-4755", "2010-5106", "2010-5107", "2010-5293", "2010-5294", "2010-5295", "2010-5296", "2010-5298", "2011-0014", "2011-0017", "2011-0411", "2011-0419", "2011-0420", "2011-0421", "2011-0441", "2011-0495", "2011-0539", "2011-0701", "2011-0708", "2011-0752", "2011-0753", "2011-0754", "2011-0755", "2011-1137", "2011-1360", "2011-1398", "2011-1464", "2011-1466", "2011-1467", "2011-1468", "2011-1469", "2011-1470", "2011-1471", "2011-1473", "2011-1657", "2011-1720", "2011-1928", "2011-1929", "2011-2166", "2011-2167", "2011-2202", "2011-2262", "2011-2483", "2011-2488", "2011-2509", "2011-2710", "2011-2889", "2011-2890", "2011-3126", "2011-3127", "2011-3128", "2011-3182", "2011-3189", "2011-3205", "2011-3207", "2011-3210", "2011-3267", "2011-3348", "2011-3368", "2011-3607", "2011-3639", "2011-3730", "2011-3818", "2011-4078", "2011-4096", "2011-4108", "2011-4153", "2011-4317", "2011-4318", "2011-4321", "2011-4362", "2011-4461", "2011-4576", "2011-4577", "2011-4619", "2011-4718", "2011-4885", "2011-4898", "2011-4909", "2011-4910", "2011-4911", "2011-4956", "2011-4957", "2011-5035", "2011-5049", "2011-5095", "2011-5270", "2011-5279", "2012-0027", "2012-0031", "2012-0050", "2012-0053", "2012-0057", "2012-0087", "2012-0101", "2012-0102", "2012-0104", "2012-0113", "2012-0115", "2012-0116", "2012-0118", "2012-0119", "2012-0120", "2012-0484", "2012-0485", "2012-0490", "2012-0540", "2012-0550", "2012-0551", "2012-0572", "2012-0574", "2012-0578", "2012-0583", "2012-0781", "2012-0782", "2012-0788", "2012-0789", "2012-0811", "2012-0819", "2012-0820", "2012-0821", "2012-0822", "2012-0825", "2012-0826", "2012-0831", "2012-0835", "2012-0836", "2012-0837", "2012-0866", "2012-0867", "2012-0868", "2012-0883", "2012-0884", "2012-0937", "2012-1117", "2012-1165", "2012-1171", "2012-1172", "2012-1181", "2012-1589", "2012-1590", "2012-1591", "2012-1599", "2012-1611", "2012-1612", "2012-1688", "2012-1689", "2012-1690", "2012-1696", "2012-1697", "2012-1702", "2012-1703", "2012-1705", "2012-1734", "2012-1735", "2012-1757", "2012-1936", "2012-2143", "2012-2153", "2012-2213", "2012-2329", "2012-2333", "2012-2336", "2012-2401", "2012-2402", "2012-2403", "2012-2404", "2012-2413", "2012-2532", "2012-2655", "2012-2686", "2012-2748", "2012-2749", "2012-2922", "2012-3144", "2012-3147", "2012-3150", "2012-3155", "2012-3166", "2012-3173", "2012-3177", "2012-3180", "2012-3365", "2012-3384", "2012-3385", "2012-3414", "2012-3488", "2012-3489", "2012-3499", "2012-3502", "2012-4071", "2012-4235", "2012-4388", "2012-4421", "2012-4448", "2012-4531", "2012-4532", "2012-4553", "2012-4554", "2012-4557", "2012-4558", "2012-5060", "2012-5381", "2012-5533", "2012-5643", "2012-5651", "2012-5652", "2012-5653", "2012-5671", "2012-5827", "2012-6113", "2012-6633", "2012-6634", "2012-6635", "2012-6707", "2013-0166", "2013-0189", "2013-0235", "2013-0236", "2013-0237", "2013-0246", "2013-0255", "2013-0316", "2013-0367", "2013-0368", "2013-0371", "2013-0375", "2013-0383", "2013-0384", "2013-0385", "2013-0386", "2013-0389", "2013-1391", "2013-1454", "2013-1508", "2013-1512", "2013-1521", "2013-1523", "2013-1552", "2013-1555", "2013-1643", "2013-1824", "2013-1862", "2013-1896", "2013-1899", "2013-1901", "2013-2070", "2013-2110", "2013-2173", "2013-2199", "2013-2200", "2013-2201", "2013-2202", "2013-2203", "2013-2204", "2013-2205", "2013-2376", "2013-2378", "2013-2389", "2013-2392", "2013-3056", "2013-3057", "2013-3058", "2013-3059", "2013-3242", "2013-3267", "2013-3735", "2013-3783", "2013-3793", "2013-3794", "2013-3801", "2013-3802", "2013-3804", "2013-3805", "2013-3808", "2013-3809", "2013-4113", "2013-4123", "2013-4248", "2013-4352", "2013-4353", "2013-4422", "2013-4508", "2013-4548", "2013-4635", "2013-4636", "2013-5576", "2013-5704", "2013-5738", "2013-5891", "2013-6171", "2013-6385", "2013-6386", "2013-6388", "2013-6389", "2013-6438", "2013-6449", "2013-6450", "2013-6501", "2013-6712", "2013-7226", "2013-7233", "2013-7327", "2013-7328", "2013-7456", "2014-0060", "2014-0061", "2014-0062", "2014-0063", "2014-0064", "2014-0065", "2014-0066", "2014-0067", "2014-0098", "2014-0117", "2014-0118", "2014-0128", "2014-0160", "2014-0165", "2014-0166", "2014-0195", "2014-0198", "2014-0207", "2014-0221", "2014-0224", "2014-0226", "2014-0231", "2014-0236", "2014-0237", "2014-0238", "2014-0384", "2014-0386", "2014-0401", "2014-0402", "2014-0412", "2014-1476", "2014-1607", "2014-2020", "2014-2324", "2014-2419", "2014-2436", "2014-2440", "2014-2497", "2014-2532", "2014-2653", "2014-2669", "2014-2957", "2014-2972", "2014-2983", "2014-3430", "2014-3470", "2014-3478", "2014-3479", "2014-3480", "2014-3487", "2014-3505", "2014-3506", "2014-3507", "2014-3508", "2014-3509", "2014-3510", "2014-3511", "2014-3523", "2014-3566", "2014-3568", "2014-3569", "2014-3570", "2014-3571", "2014-3572", "2014-3583", "2014-3587", "2014-3597", "2014-3609", "2014-3668", "2014-3670", "2014-3710", "2014-4258", "2014-4260", "2014-4670", "2014-4698", "2014-5019", "2014-5020", "2014-5022", "2014-5120", "2014-5139", "2014-5204", "2014-5205", "2014-5265", "2014-5266", "2014-5267", "2014-6270", "2014-6412", "2014-6520", "2014-6631", "2014-7141", "2014-7142", "2014-7229", "2014-7982", "2014-7983", "2014-8109", "2014-8275", "2014-9016", "2014-9031", "2014-9032", "2014-9033", "2014-9034", "2014-9035", "2014-9036", "2014-9037", "2014-9038", "2014-9039", "2014-9652", "2014-9749", "2014-9767", "2015-0204", "2015-0205", "2015-0206", "2015-0207", "2015-0208", "2015-0209", "2015-0228", "2015-0232", "2015-0253", "2015-0285", "2015-0286", "2015-0287", "2015-0288", "2015-0289", "2015-0290", "2015-0291", "2015-0293", "2015-0881", "2015-1352", "2015-1788", "2015-1789", "2015-1790", "2015-1791", "2015-1792", "2015-1793", "2015-1794", "2015-2080", "2015-2348", "2015-2575", "2015-2749", "2015-2750", "2015-2783", "2015-3165", "2015-3184", "2015-3185", "2015-3193", "2015-3194", "2015-3195", "2015-3196", "2015-3197", "2015-3200", "2015-3231", "2015-3232", "2015-3233", "2015-3234", "2015-3237", "2015-3330", "2015-3411", "2015-3412", "2015-3429", "2015-3438", "2015-3439", "2015-3440", "2015-4000", "2015-4021", "2015-4024", "2015-4148", "2015-4604", "2015-4605", "2015-4644", "2015-5288", "2015-5289", "2015-5352", "2015-5397", "2015-5400", "2015-5608", "2015-5623", "2015-5730", "2015-5731", "2015-5732", "2015-5733", "2015-5734", "2015-6564", "2015-6658", "2015-6660", "2015-6661", "2015-6665", "2015-6833", "2015-6837", "2015-6838", "2015-6939", "2015-7774", "2015-7803", "2015-7804", "2015-7859", "2015-7899", "2015-7943", "2015-8563", "2015-8834", "2015-8838", "2015-8873", "2015-8874", "2015-8877", "2015-8879", "2015-8935", "2015-8994", "2015-9253", "2016-0703", "2016-0704", "2016-0736", "2016-0768", "2016-0773", "2016-0777", "2016-0778", "2016-0797", "2016-0800", "2016-10002", "2016-10003", "2016-10010", "2016-10148", "2016-10158", "2016-10159", "2016-10161", "2016-10162", "2016-10397", "2016-10708", "2016-10712", "2016-1531", "2016-1546", "2016-1903", "2016-1907", "2016-2105", "2016-2106", "2016-2161", "2016-2176", "2016-2179", "2016-2180", "2016-2181", "2016-2183", "2016-2193", "2016-2221", "2016-2222", "2016-2390", "2016-2569", "2016-2570", "2016-2571", "2016-2572", "2016-3142", "2016-3162", "2016-3163", "2016-3164", "2016-3165", "2016-3166", "2016-3167", "2016-3169", "2016-3170", "2016-3171", "2016-3185", "2016-3948", "2016-4029", "2016-4051", "2016-4052", "2016-4053", "2016-4054", "2016-4070", "2016-4343", "2016-4553", "2016-4554", "2016-4555", "2016-4556", "2016-4566", "2016-4567", "2016-4975", "2016-4979", "2016-5114", "2016-5116", "2016-5385", "2016-5387", "2016-5399", "2016-5423", "2016-5424", "2016-5519", "2016-5528", "2016-5766", "2016-5767", "2016-5832", "2016-5833", "2016-5834", "2016-5835", "2016-5836", "2016-5837", "2016-5838", "2016-5839", "2016-6174", "2016-6211", "2016-6212", "2016-6289", "2016-6292", "2016-6297", "2016-6302", "2016-6305", "2016-6306", "2016-6307", "2016-6634", "2016-6635", "2016-6896", "2016-6897", "2016-7052", "2016-7053", "2016-7054", "2016-7125", "2016-7128", "2016-7130", "2016-7131", "2016-7132", "2016-7133", "2016-7169", "2016-7412", "2016-7416", "2016-7418", "2016-7478", "2016-7570", "2016-7571", "2016-7572", "2016-8610", "2016-8740", "2016-8743", "2016-9244", "2016-9449", "2016-9450", "2016-9451", "2016-9452", "2016-9837", "2016-9838", "2016-9933", "2016-9934", "2017-1000600", "2017-1001000", "2017-10140", "2017-10385", "2017-10393", "2017-10400", "2017-11143", "2017-11144", "2017-11145", "2017-11147", "2017-11364", "2017-11612", "2017-11628", "2017-12934", "2017-14595", "2017-14596", "2017-14718", "2017-14719", "2017-14720", "2017-14721", "2017-14722", "2017-14724", "2017-14725", "2017-14726", "2017-14798", "2017-14990", "2017-15098", "2017-15099", "2017-15130", "2017-15132", "2017-15710", "2017-15715", "2017-15906", "2017-16633", "2017-16642", "2017-16944", "2017-17091", "2017-3247", "2017-3730", "2017-3731", "2017-3732", "2017-3733", "2017-3735", "2017-3736", "2017-3737", "2017-3738", "2017-5487", "2017-5488", "2017-5489", "2017-5490", "2017-5491", "2017-5492", "2017-5493", "2017-5610", "2017-5612", "2017-6377", "2017-6379", "2017-6381", "2017-6441", "2017-6514", "2017-6815", "2017-6816", "2017-6818", "2017-6819", "2017-6919", "2017-6921", "2017-6922", "2017-6923", "2017-6924", "2017-6927", "2017-6929", "2017-6932", "2017-7189", "2017-7272", "2017-7484", "2017-7485", "2017-7486", "2017-7547", "2017-7548", "2017-7659", "2017-7890", "2017-7963", "2017-7983", "2017-7984", "2017-7986", "2017-7987", "2017-7988", "2017-7989", "2017-8057", "2017-8295", "2017-9061", "2017-9062", "2017-9063", "2017-9064", "2017-9065", "2017-9066", "2017-9067", "2017-9118", "2017-9788", "2017-9789", "2017-9798", "2017-9933", "2017-9934", "2018-0732", "2018-0733", "2018-0734", "2018-0735", "2018-0737", "2018-0739", "2018-1000024", "2018-1000027", "2018-1000773", "2018-10100", "2018-10101", "2018-10102", "2018-10546", "2018-10547", "2018-10548", "2018-10549", "2018-1058", "2018-10915", "2018-10925", "2018-1115", "2018-11321", "2018-11322", "2018-11323", "2018-11324", "2018-11325", "2018-11327", "2018-1172", "2018-11763", "2018-12711", "2018-12712", "2018-12895", "2018-1301", "2018-1302", "2018-1303", "2018-1312", "2018-1333", "2018-14028", "2018-14851", "2018-14883", "2018-14884", "2018-15132", "2018-15473", "2018-15881", "2018-15919", "2018-17082", "2018-17189", "2018-17199", "2018-17855", "2018-17856", "2018-17857", "2018-17858", "2018-17859", "2018-19052", "2018-19131", "2018-19132", "2018-19395", "2018-19396", "2018-19520", "2018-19935", "2018-20147", "2018-20150", "2018-20151", "2018-20152", "2018-20783", "2018-2911", "2018-3152", "2018-3210", "2018-5711", "2018-5712", "2018-5776", "2018-6377", "2018-6378", "2018-6379", "2018-6380", "2018-6389", "2018-8011", "2018-8045", "2018-8581", "2018-9861", "2019-0190", "2019-0196", "2019-0197", "2019-0215", "2019-0217", "2019-0220", "2019-10130", "2019-10691", "2019-10946", "2019-11034", "2019-11035", "2019-11036", "2019-11038", "2019-11039", "2019-11040", "2019-11358", "2019-11809", "2019-11876", "2019-12527", "2019-12529", "2019-12764", "2019-12766", "2019-13345", "2019-14654", "2019-1543", "2019-1559", "2019-1653", "2019-3814", "2019-6109", "2019-6110", "2019-6111", "2019-6261", "2019-6264", "2019-6338", "2019-6340", "2019-6977", "2019-7739", "2019-7740", "2019-7741", "2019-7742", "2019-7744", "2019-8942", "2019-8943", "2019-9022", "2019-9024", "2019-9637", "2019-9638", "2019-9639", "2019-9640", "2019-9675", "2019-9711", "2019-9712", "2019-9713", "2019-9714", "2019-9787", "2020-11652", "2015-0228", "2015-0253", "2015-3185", "2019-11358"]
vuln_list_low = ["1999-0861", "1999-1538", "2000-0167", "2000-0649", "2001-0666", "2001-1029", "2001-1349", "2001-1534", "2002-0121", "2002-0422", "2002-0507", "2002-1233", "2002-1827", "2002-1876", "2003-1581", "2003-1582", "2004-0381", "2004-0388", "2004-0837", "2004-0959", "2004-0975", "2004-1387", "2004-1834", "2005-0711", "2005-1410", "2005-2666", "2005-3054", "2005-3319", "2006-0208", "2006-0369", "2006-0678", "2006-0733", "2006-0760", "2006-1014", "2006-1494", "2006-1549", "2006-1608", "2006-2563", "2006-2660", "2006-3486", "2006-4031", "2006-4226", "2006-4380", "2006-4484", "2006-4486", "2006-4625", "2006-5229", "2006-7204", "2006-7232", "2007-0124", "2007-1420", "2007-1732", "2007-1742", "2007-2509", "2007-2727", "2007-3108", "2007-4153", "2007-5621", "2007-5710", "2007-6039", "2007-6303", "2007-6421", "2008-0456", "2008-2937", "2008-3259", "2008-3741", "2008-3889", "2008-4456", "2008-5161", "2008-5814", "2008-6170", "2008-6299", "2009-0591", "2009-0603", "2009-0754", "2009-1279", "2009-1844", "2009-2521", "2009-3094", "2009-3891", "2009-4369", "2009-4370", "2009-4371", "2010-0733", "2010-1626", "2010-2008", "2010-2535", "2010-3093", "2010-3094", "2010-5297", "2011-0700", "2011-1945", "2011-4327", "2011-4415", "2011-5000", "2012-0021", "2012-0075", "2012-0081", "2012-0112", "2012-0114", "2012-0287", "2012-0492", "2012-0814", "2012-0827", "2012-1588", "2012-2102", "2012-2531", "2012-2687", "2012-3149", "2012-3156", "2012-3160", "2012-3197", "2012-3450", "2012-4422", "2012-5096", "2012-5868", "2012-6095", "2013-0169", "2013-0244", "2013-0245", "2013-1427", "2013-1502", "2013-1506", "2013-1511", "2013-1548", "2013-2391", "2013-3812", "2013-4340", "2013-4560", "2013-5739", "2013-5908", "2013-6387", "2014-0076", "2014-0393", "2014-0420", "2014-0437", "2014-2430", "2014-2431", "2014-2432", "2014-2438", "2014-3956", "2014-3981", "2014-4243", "2014-4721", "2014-5021", "2014-5240", "2014-5459", "2015-1787", "2015-3455", "2015-5622", "2015-6563", "2016-0701", "2016-0702", "2016-10011", "2016-2107", "2016-2178", "2016-7055", "2016-7056", "2016-7168", "2016-8612", "2016-9263", "2016-9963", "2017-1000369", "2017-3239", "2017-3626", "2017-6814", "2017-6817", "2017-6928", "2017-7418", "2018-1053", "2018-10545", "2018-11326", "2018-11328", "2018-1283", "2018-15880", "2018-20149", "2018-20153", "2018-20685", "2018-5407", "2019-10909", "2019-1552", "2019-6262", "2019-6263", "2019-6341"]
def TriOpMain(options):
if (isFile(options.output_file) and ((options.country_names == False and options.mode == "search") or options.mode == "get")):
if (input("File with the name '" + options.output_file + "' already exists and will be rewritten. Do you wish to continue? [y/N]").lower() != "y"):
return 0;
else:
os.remove(options.output_file)
if (options.kev):
getKEVData(options)
if (options.mode == "search"):
options.parameter_file = "kev_temp_data"
options.filter = "vuln"
if (options.mode == "add"):
if (isFile(options.input_file) != 1):
error("File with additional searches not found.")
return 0;
if (options.filename_load == '' and options.search_file == ''):
error("No existing input file(s) specified.")
return 0;
if (options.filename_load != ''):
for file in glob.glob('./*'):
name = file.strip(string.punctuation)
if (options.filename_load in name):
if (isFile(file)):
if (options.verbose):
print('File ' + name + ' added as an add file.')
addToFile(options,name)
if (options.search_file != ''):
if (isFile(options.search_file)):
if (options.verbose):
print('File ' + options.search_file + ' added as an add file.')
addToFile(options,options.search_file)
else:
error('File "' + options.search_file + '" not found.')
elif (options.mode == "get"):
files = getFiles(options)
for f in files:
processContents(f, options)
elif (options.mode == "search"):
shodan_io = ''
if (options.key != ''):
shodan_io = Shodan(options.key)
else:
try:
keyfile = open("api.key", "r")
shodan_io = Shodan(keyfile.read())
keyfile.close()
except:
error("Could not read contents of the key file.")
print(sys.exc_info()[1])
sys.exit()
if (options.filename_load != ''):
if (options.search_file != ''):
options.search_file = options.search_file + ","
for file in glob.glob('./*'):
name = file.strip(string.punctuation)
if (options.filename_load in name):
options.search_file = options.search_file + name + ','
if (options.verbose):
print('File ' + name + ' added as a search file.')
options.search_file = options.search_file.rstrip(',')
if (options.fix_errors):
if (not fixErrors(options,shodan_io)):
print("No errors detected.")
else:
parameterSearch = False
parameters = ['']
if (options.country != ''):
options.filter = "country"
options.parameter = options.country
elif (options.country_file != ''):
options.filter = "country"
options.parameter_file = options.country_file
if (options.parameter != ''):
parameterSearch = True
parameters = options.parameter.split(',')
elif (options.parameter_file != ''):
parameterSearch = True
parameters = getFileContents(options.parameter_file,0)
if (parameterSearch):
for p in parameters:
if (options.verbose):
print('Processing parameter: ' + p + '...')
parameterizedSearch(p,options,shodan_io,'')
else:
if (options.verbose):
print('Processing search parameters.')
parameterizedSearch("",options,shodan_io,'')
if (isFile("kev_temp_data")):
os.remove("kev_temp_data")
def addToFile(options,file):
contents = getFileContents(file,1)
count = len(contents[0])
additions = getFileContents(options.input_file,1)
if (options.kev):
removal = []
for a in additions:
for c in contents:
if (a[0] in c[0]):
removal.append(a)
break
for r in removal:
additions.remove(r)
for a in additions:
a[0] = "vuln:" + a[0]
parameter = "";
if (options.filter != ""):
for search in contents:
try:
if (options.filter in search[0]):
parameterEnd = search[0].find(" ",search[0].find(options.filter))
if (parameterEnd == -1):
parameter = search[0][search[0].find(options.filter):]
else:
parameter = search[0][search[0].find(options.filter):parameterEnd]
break
except:
error('Error "' + str(sys.exc_info()[1]) + '" while searching for parameterized input in ' + file + '.')
if (parameter == ""):
error('Parameter ' + options.filter + " not found in " + file + ". Skipping addition to this file...")
return 0;
adds = []
for addition in additions:
newAddition = []
newAddition.append(addition[0] + " " + parameter)
adds.append(newAddition)
additions = adds
for addition in additions:
newSearch=addition
for i in range(count-1):
newSearch.append('-')
contents.append(newSearch)
try:
with open(file, 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
writer.writerows(contents)
print("New searches appended to file " + file + ".")
except:
error('Error "' + str(sys.exc_info()[1]) + '" while writing to ' + file + '.')
def runSearch(options,search,shodan_io):
try:
if (options.verbose):
print("Getting data for " + search)
data = shodan_io.count(search)["total"]
if (options.verbose or options.search != ''):
print('Current IP count for query ' + search + ' is ' + str(data))
return str(data)
except:
if (str(sys.exc_info()[1]) == 'Invalid API key'):
error('Invalid API key used. Exiting.')
sys.exit()
else:
if (int(options.retry_level) > 0):
retries = 1
while (int(options.retry_level) >= retries):
error('Error "' + str(sys.exc_info()[1]) + '" while processing server response. Applying ' + str(retries * 5) + ' second backoff period.')
time.sleep(retries * 5)
try:
print('Retrying.')
data = shodan_io.count(search)["total"]
if (options.verbose or options.search != ''):
print('Current IP count for query ' + search + ' is ' + str(data))
return data
except:
retries = retries + 1
error('Error while processing server response. Skipping search ' + search)
return 'error'
else:
error('Error while processing server response. Skipping search ' + search)
return 'error'
def processContents(readFile, options):
data = getFileContents(readFile,1)
workingSet = []
hasDate = 0
newData = data
oldData = []
tempData = []
if (not isFile(options.output_file)):
found = False
if (newData[0][0] == 'Date'):
workingSet.append(newData[0])
workingSet[0][0] = options.search
hasDate = 1
for i in range(hasDate,len(newData)):
if (newData[i][0].find(options.search)>=0):
newData[i][0] = readFile
workingSet.append(newData[i])
found = True
break
if (not found):
print("Term " + options.search + " not found in " + readFile +" - skipping.")
return 0
else:
index = 0
for i in range(0,len(newData)):
if (newData[i][0].find(options.search)>=0):
index = i
break
if (index == 0):
print("Term " + options.search + " not found in " + readFile +" - skipping.")
return 0
oldData = getFileContents(options.output_file,1)
tempData.append(newData[0])
tempData.append(newData[index])
newData = tempData
size = len (oldData)
for e in oldData:
workingSet.append([e[0]])
workingSet.append([readFile])
newDataPosition = 1
oldDataPosition = 1
oldDataDone = False
newDataDone = False
oldDate = datetime.strptime(oldData[0][oldDataPosition], '%Y-%m-%d')
newDate = datetime.strptime(newData[0][newDataPosition], '%Y-%m-%d')
while (not oldDataDone or not newDataDone):
if (not oldDataDone and not newDataDone):
if (oldDate == newDate):
workingSet[0].append(oldDate.strftime('%Y-%m-%d'))
for i in range (1,len(oldData)):
workingSet[i].append(oldData[i][oldDataPosition])
workingSet[len(workingSet)-1].append(newData[1][newDataPosition])
oldDataPosition = oldDataPosition + 1
newDataPosition = newDataPosition + 1
elif (oldDate < newDate):
workingSet[0].append(oldDate.strftime('%Y-%m-%d'))
for i in range (1,len(oldData)):
workingSet[i].append(oldData[i][oldDataPosition])
workingSet[len(workingSet)-1].append('')
oldDataPosition = oldDataPosition + 1
else:
workingSet[0].append(newDate.strftime('%Y-%m-%d'))
for i in range (1,len(oldData)):
workingSet[i].append('')
workingSet[len(workingSet)-1].append(newData[1][newDataPosition])
newDataPosition = newDataPosition + 1
elif (not oldDataDone):
workingSet[0].append(oldDate.strftime('%Y-%m-%d'))
for i in range (1,len(oldData)):
workingSet[i].append(oldData[i][oldDataPosition])
workingSet[len(workingSet)-1].append('')
oldDataPosition = oldDataPosition + 1
elif (not newDataDone):
workingSet[0].append(newDate.strftime('%Y-%m-%d'))
for i in range (1,len(oldData)):
workingSet[i].append('')
workingSet[len(workingSet)-1].append(newData[1][newDataPosition])
newDataPosition = newDataPosition + 1
if (newDataPosition == len(newData[0])):
newDataDone = True
else:
newDate = datetime.strptime(newData[0][newDataPosition], '%Y-%m-%d')
if (oldDataPosition == len(oldData[0])):
oldDataDone = True
else:
oldDate = datetime.strptime(oldData[0][oldDataPosition], '%Y-%m-%d')
print("File " + readFile + " processed")
saveOutput(workingSet, options)
def saveOutput(data,options):
try:
with open(options.output_file, 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
writer.writerows(data)
except:
error("Could not write to file " + options.output_file + "...")
print(sys.exc_info()[1])
def parameterizedSearch(parameter,options,shodan_io,fileToSearch):
searches = ['']
data = ''
output = []
search = True
if (options.search != ''):
searches = options.search.split(',')
elif (fileToSearch != ''):
searches = getFileContents(fileToSearch,0)
else:
fileCount = options.search_file.split(',')
if (len(fileCount) == 1):
searches = getFileContents(options.search_file,0)
fileToSearch = options.search_file
else:
search = False
for f in fileCount:
parameterizedSearch(parameter,options,shodan_io,f)
basic_searches = []
vuln_searches = []
if (options.basic_search):
for s in searches:
for p in basic_search_list:
if (p.isnumeric()):
basic_searches.append(s + " port:" + p)
else:
basic_searches.append(s + " " + p)
if (options.vuln_search_level > 0):
for s in searches:
print ("Checking whether Shodan detects any vulnerabilities for search " + s + ".")
if (int(runSearch(options,s + " has_vuln:true",shodan_io))>0):
for v in vuln_list_high:
vuln_searches.append(s + " vuln:CVE-" + v)
if (options.vuln_search_level > 1):
for v in vuln_list_medium:
vuln_searches.append(s + " vuln:CVE-" + v)
if (options.vuln_search_level == 3):
for v in vuln_list_low:
vuln_searches.append(s + " vuln:CVE-" + v)
else:
print("No vulnerabilities detected for search " + s + ". Skipping CVE enumeration...")
if (options.basic_search):
searches.extend(basic_searches)
if (options.vuln_search_level > 0):
searches.extend(vuln_searches)
if (search):
if (searches[0].split(',')[0].casefold()=='date'):
output.append(datetime.now().strftime('%Y-%m-%d'))
for s in searches:
if (s.casefold() == 'date'):
continue
if (options.filter != ""):
s = (s + ' ' + options.filter + ':"' + parameter + '"').lstrip(' ')
time.sleep(1)
count = runSearch(options,s,shodan_io)
output.append(count)
if (options.search_file != ''):
if (options.append):
appendData(output, fileToSearch, options)
if (options.output_file != ''):
parameters = []
if (options.parameter != ''):
parameters = options.parameter.split(',')
elif (options.parameter_file != ''):
parameters = getFileContents(options.parameter_file,0)
if (options.country_names):
options.filter_names = True
if (options.filter_names):
if (parameter == ""):
saveData(output,options.output_file,options,searches,options.filter,parameter)
else:
newName = generateFileName(options.output_file, parameter)
saveData(output,newName,options,searches,options.filter,parameter)
elif (len(parameters)>1):
if (parameter == parameters[0]):
saveData(output,options.output_file,options,searches,options.filter,parameter)
else:
addData(output,options.output_file,options,searches,options.filter,parameter)
else:
saveData(output,options.output_file,options,searches,options.filter,parameter)
def generateFileName(originalName,parameter):
position = originalName.rfind('.')
parameter = parameter.replace('/','-')
parameter = "".join( x for x in parameter if (x.isalnum() or x in "._-"))
newName = originalName[0:position] + '-' + parameter + originalName[position:]
return newName
def saveData(data,file,options,searches,filter,parameter):
newSearches = []
for s in searches:
newSearch = s
if (filter != ""):
newSearch = newSearch + " " + filter + ":'" + parameter + "'"
newSearches.append(newSearch.lstrip(' '))
searches = newSearches
try:
if (options.verbose):
print('Saving to file ' + file)
all = []
with open(file, 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
if (searches[0][:4].lower() != "date"):
dateRow = ["Date"]
dateRow.append(datetime.now().strftime('%Y-%m-%d'))
all.append(dateRow)
for i in range(len(data)):
dataRow = []
dataRow.append(searches[i])
dataRow.append(data[i])
all.append(dataRow)
writer.writerows(all)
print("Output saved to file " + file + "...")
except:
error("Could not write to file " + file + "...")
print(sys.exc_info()[1])
sys.exit()
def addData(data,file,options,searches,filter,parameter):
newSearches = []
for s in searches:
newSearch = s
if (filter != ""):
newSearch = newSearch + " " + filter + ":'" + parameter + "'"
newSearches.append(newSearch.lstrip(' '))
searches = newSearches
try:
if (options.verbose):
print('Saving to file ' + file)
all = []
with open(file,'r') as csvinput:
reader = csv.reader(csvinput)
all = []
rowLen = 0
for row in reader:
all.append(row)
for i in range(len(data)):
dataRow = []
dataRow.append(searches[i])
dataRow.append(data[i])
all.append(dataRow)
with open(file, 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
writer.writerows(all)
print("Output added to file " + file + "...")
except:
error("Could not write to file " + file + "...")
print(sys.exc_info()[1])
sys.exit()
def appendData(data, file, options):
try:
if (options.verbose):
print('Saving to file ' + file)
with open(file,'r') as csvinput:
reader = csv.reader(csvinput)
hasDate = False
all = []
rowLen = 0
with open(file+'temp', 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
skip = False
row = next(reader)
rowLen = len(row)
count = 0
if (row[0]=='Date'):
row.append(datetime.now().strftime('%Y-%m-%d'))
all.append(row)
if (options.append):
count = 1
else:
skip=True
for d in range(len(data)-count):
if (not skip):
row = next(reader)
skip=False
while (len(row) < rowLen):
row.append('')
row.append(data[d+count])
all.append(row)
writer.writerows(all)
shutil.move(file+'temp', file)
if (options.verbose):
print(datetime.now().strftime('%H:%M:%S') + " - Output appended to file " + file + "...")
else:
print("Output appended to file " + file + "...")
except:
error("Could not write to file " + file + "...")
print(sys.exc_info()[1])
sys.exit()
def fixErrors(options,shodan_io):
files = options.search_file.split(',')
anyFix = False
for f in files:
errorFound = False
try:
contents=[]
readfile = open(f, "r")
reader = csv.reader(readfile)
for row in reader:
contents.append(row)
readfile.close()
change = False
for c in contents:
if (c[len(c)-1] == 'error'):
if (options.verbose):
errorFound = True
anyFix = True
print("Error value detected.")
change = True
if (options.verbose):
print("Getting replacement data for " + c[0])
time.sleep(1)
c[len(c)-1] = runSearch(options,c[0],shodan_io)
if (change):
try:
with open(f, 'w') as csvoutput:
writer = csv.writer(csvoutput, lineterminator='\n')
writer.writerows(contents)
print("Output saved to file " + f + "...")
except:
error("Could not access file " + f + "...")
print(sys.exc_info()[1])
if (not errorFound and options.verbose):
print('No error found in file ' + f)
except:
error("Could not access file " + f + "...")
print(sys.exc_info()[1])
if (anyFix):
return True
else:
return False
def getFileContents(file,wholelines):
try:
contents=[]
readfile = open(file, "r")
reader = csv.reader(readfile)
if (wholelines == 1):
for row in reader:
contents.append(row)
else:
for row in reader:
contents.append(row[0])
readfile.close()
return contents
except:
error("Could not read file " + file + "...")
print(sys.exc_info()[1])
def getKEVData(options):
try:
if (options.kev_full):
kev_data = urllib.request.urlopen('https://www.cisa.gov/sites/default/files/csv/known_exploited_vulnerabilities.csv')
lines = [l.decode('utf-8') for l in kev_data.readlines()]
kev_vulns = csv.reader(lines)
vuln_list = []
for row in kev_vulns:
vuln_list.append(row[0])
vuln_list.pop(0)
with open("kev_temp_data", 'w') as output:
for row in vuln_list:
output.write(row + "\n")
else:
kev_data = urllib.request.urlopen('https://untrustednetwork.net/triop/kev')
lines = [l.decode('utf-8') for l in kev_data.readlines()]
with open("kev_temp_data", 'w') as output:
for row in lines:
line = row.replace("\r\n", "\n")
output.write(line)
except:
error("Could not download or save data from CISA Known Exploited Vulnerabilities catalogue.")
print(sys.exc_info()[1])
def checkOptions(options):
if (options.kev != 1 and options.kev_full):
error("Option 'kev_full' may only be used in conjunction with option 'kev'.")
return 0
if (options.kev):
if ((options.vuln_search_level != 0 or options.basic_search or options.mode != "search" or options.parameter != '' or options.parameter_file != '') and (options.mode != "add")):
error("Option 'kev' is only supported in the 'search' mode with -s or -S operators or in the 'add' mode.")
return 0
else:
if (options.input_file != ''):
error("No additional input file may be specified when 'kev' parameter is used.")
return 0
else:
options.input_file = "kev_temp_data"
if (options.mode == "add" and options.filter == ''):
print("No filter was specified and the 'kev' parameter is set, only plain 'vuln:CVE-XXXX-XXXX' queries will be added to search file(s).")
if ((options.vuln_search_level != 0 or options.basic_search) and options.mode != "search"):
error("Options 'basic_search' and 'vuln_search_level' are supported only for use in the 'search' mode.")
return 0
if (options.mode == "add"):
if ((options.filename_load != '' or options.search_file != '') and (options.input_file != '')):
return 1
else:
error("File name(s) of existing search file(s) (-f/-S) and an input file with additional searches (-I) have to be specified for use of TriOp in the 'add' mode. Filter (--filter) specification is optional.")
return 0
elif (options.mode == "get"):
if (options.search == '' or (options.search_file == '' and options.filename_load == '') or options.output_file == ''):
error("Input file(s) (-S/-f), output file (-O) and search parameters (-s) have to be specified for use of TriOp in the 'get' mode.")
return 0
else:
return 1
elif (options.mode == "search"):
if (options.vuln_search_level < 0 or options.vuln_search_level > 3):
error("Level of impact of vulnerabilities has to be between 0 and 3.")
return 0
if (options.retry_level < 0):
error("Number of retries can not be negative.")
return 0
if (options.key != ''):
if (options.save_key == True):
try:
keyfile = open("api.key", "w")
keyfile.write(options.key)
keyfile.close()
print("API key output to file.")
except:
error("Could not write to a key file.")
print(sys.exc_info()[1])
elif (not isFile('api.key')):
error("No API key specified (-k) and no key file was found. API key is required for use of TriOp in the 'search' mode.")
return 0
if (((options.search == '' and options.search_file == '') or (options.search != '' and options.search_file != '')) and options.filename_load == ""):
error("Exactly one of the search parameters (-s/-S or -f) has to be set for use of TriOp in the 'search' mode.")
return 0
if (options.country != '' and options.country_file != ''):
error("Only one of the country parameters (-c/-C) may be set.")
return 0
if ((options.country != '' or options.country_file != '') and (options.parameter != '' or options.parameter_file != '')):
error("Country search (-c/-C) can not be used in conjunction with parameterized search (-p/-P).")
return 0
if (options.filter == '' and (options.parameter != '' or options.parameter_file != '')):
error("Filter (--filter) has to be specified for use of the parameterized search.")
return 0
if (options.filter != '' and (options.parameter == '' and options.parameter_file == '')):
error("Filter (--filter) must be used in conjunction with one of the parameter options (-p/-P).")
return 0
if (options.parameter != '' and options.parameter_file != ''):
error("Only one of the filter parameters (-p/-P) may be set.")
return 0
if ((options.country_names or options.filter_names) and options.output_file == ''):
error("Output file (-O) has to be specified in order to use parameterized file names.")
return 0
searchFileCount = 0
if (options.search_file != ''):
searchFiles = options.search_file.split(',')
searchFileCount = len(searchFiles)
for f in searchFiles:
if (not isFile(f)):
error("File " + f + " not found.")
return 0
if (options.country_file != ''):
countryFiles = options.country_file.split(',')
for f in countryFiles:
if(not isFile(f)):
error("File " + f + " not found.")
return 0
if (options.parameter_file != ''):
parameterFiles = options.parameter_file.split(',')
for f in parameterFiles:
if(not isFile(f)):
error("File " + f + " not found.")
return 0
if (options.output_file != ''):
outputFiles = options.country_file.split(',')
if (len(outputFiles) > 1):
error("Only one output file may be specified (with or without the --country_names or --filter_names option) for use of TriOp in the 'search' mode.")
return 0
if (options.search_file == options.output_file and options.search_file != ''):
error("Output file and input file are set to the same path - this setting is unsupported. If you wish to add results of searches to existing file, use the 'append results' (-a) option.")
return 0
return 1
else:
error("Unsupported mode (-m) specified - only 'add','get' and 'search' modes are supported.")
return 0
def getFiles(options):
files = []
if (options.filename_load != ''):
if (options.search_file != ''):
options.search_file = options.search_file + ','
for file in glob.glob('./*'):
name = file.strip(string.punctuation)
if (options.filename_load in name):
options.search_file = options.search_file + name + ','
if (options.verbose):
print('File ' + name + ' added as an input file.')
options.search_file = options.search_file.rstrip(',')
files = options.search_file.split(',')
return files
def error(text):
print()
print("ERROR: " + text)
print()
def isFile(file):
return (os.path.exists(file) and os.path.isfile(file))
def main():
print("TriOp 1.5")
info='''%prog [options]
Tool for quickly gathering information from Shodan.io about the number of IPs which satisfy large number of different queries
Created by Jan Kopriva
You may find a tutorial on how to use TriOp at https://untrustednetwork.net/en/triop/
'''
parser = OptionParser(info)
parser.add_option("-m", "--mode", type=str, default='search',
help="mode in which TriOp should operate - 'search' (default - subits queries to Shodan and displays/saves their results to new/existing search files), 'add' (adds new search strings to existing search file(s)) or 'get' (extracts data for a first instance of specified search string from existing search file(s))")
parser.add_option("-k", "--key", type=str, default='',
help="API key for Shodan")
parser.add_option("--save_key", action="store_true", default=False,
help="""save key in a plaintext key file, used in conjunction with option -k
!!!WARNING - DO NOT USE IN SHARED COMPUTER ENVIRONMENTS!!!""")
parser.add_option("-s", "--search", type=str, default='',
help="comma-separated list of search criteria")
parser.add_option("-S", "--search_file", type=str, default='',
help="input CVE file(s) with first row specifying search definitions")
parser.add_option("-f", "--filename_load", type=str, default='',
help="load all files in the same directory which contain specified string in their name as search inputs")
parser.add_option("--filter", type=str, default='',
help='filter for use with list of query terms (-p/-P) to which it should be prepended or to specify filters to be added to input searches in the "add" mode')
parser.add_option("-p", "--parameter", type=str, default='',
help='comma-separated list of query terms for use with a filter (--filter)')
parser.add_option("-P", "--parameter_file", type=str, default='',
help='input CVE file(s) with first row specifying query terms for use with a filter (--filter)')
parser.add_option("-O", "--output_file", type=str, default='',
help="output to specified CSV file")
parser.add_option("--filter_names", action="store_true", default=False,
help="save results into filter-specific files")
parser.add_option("-a", "--append", action="store_true", default=False,
help="append results to input file(s) - used in conjunction with -S")
parser.add_option("-v", "--verbose", action="store_true", default=False,
help="print status messages")
parser.add_option("-e", "--fix_errors", action="store_true", default=False,
help='repeat all previously unsuccessful searches from the last row of a CSV file')
parser.add_option("-r", "--retry_level", type=int, default=2,
help='number indicating how many retries should be attempted - 0-n (default = 2)')
parser.add_option("-I", "--input_file", type=str, default='',
help="input file with additional searches for use in the 'add' mode")
parser.add_option("-c", "--country", type=str, default='',
help='comma-separated list of countries - DEPRECATED (use -p and --filter instead)')
parser.add_option("-C", "--country_file", type=str, default='',
help='input CVE file(s) with first row specifying country codes - DEPRECATED (use -P and --filter instead)')
parser.add_option("--country_names", action="store_true", default=False,
help="save results into country-specific files - DEPRECATED (use parameterized search (-p/-P) and --filter_names instead)")
parser.add_option("--basic_search", action="store_true", default=False,
help="add search parameters for common ports, TLS support existence of vulnerabilities, etc. to all input searches in the 'search' mode")
parser.add_option("--vuln_search_level", type=int, default=0,
help="""add search parameters for CVEs, which Shodan is capable of finding, to all input searches in the 'search' mode: 0 - none (default), 1 - high impact vulnerabilities, 2 - high and medium impact vulnerabilities, 3 - all vulnerabilities
!!!WARNING - slow - adds several hundred or thousand of modifications to each input search!!!""")
parser.add_option("--kev", action="store_true", default=False,
help="add search parameters for those CVEs from the CISA Known Exploited Vulnerabilities catalogue that Shodan is capable of detecting")
parser.add_option("--kev_full", action="store_true", default=False,
help="modifier for the 'kev' parameter that will use all CVEs from the CISA Known Exploited Vulnerabilities catalogue in relevant queries - even those that Shodan might not be capable of detecting")
(options, args) = parser.parse_args()
if (len(args) == 0):
if (checkOptions(options)):
TriOpMain(options)
else:
print("Unknown input:")
for arg in args:
print(" " + arg)
return
if __name__ == '__main__':
main()