-
Notifications
You must be signed in to change notification settings - Fork 2
/
shodanSearch.py
1335 lines (1255 loc) · 65.8 KB
/
shodanSearch.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/env python
# by rcbonz https://github.com/rcbonz/ShodanWizard/
import os
import shodan
import shodan.exception
from pathlib import Path
import json
from colorama import Back, Fore, Style
from datetime import datetime
import requests
import readline
"This script was made with many information available at https://shodan.readthedocs.io/en/latest/api.html"
"The following section was stracted from https://stackoverflow.com/questions/22029562/python-how-to-make-simple-animated-loading-while-process-is-running/66558182#66558182 and adapted for better suit"
from itertools import cycle
from shutil import get_terminal_size
from threading import Thread
from time import sleep
class Loader:
def __init__(self, desc="Loading...", end="Done!", timeout=0.1):
"""
A loader-like context manager
Args:
desc (str, optional): The loader's description. Defaults to "Loading...".
end (str, optional): Final print. Defaults to "Done!".
timeout (float, optional): Sleep time between prints. Defaults to 0.1.
"""
self.desc = desc
self.end = end
self.timeout = timeout
self._thread = Thread(target=self._animate, daemon=True)
self.steps0 = ["--|","--|","--|","-| ","-| ","-| ","| ","| ","| ","| ","| ","| ","| ","| ","-| ","--|"]
self.steps = ["= ","==- ","==--- "," ==----"," ---=="," -=="," ="," |"," ="," -=="," ---==","----== ","==--- ","==- ","= ","| "]
self.steps1 = [" |"," |"," |"," |"," |"," |"," |-","|--","|--","|--","|--"," |-"," |-"," |-"," |"," |"]
self.steps2 = ["⢿","⣻","⣽","⣾","⣷","⣯","⣟","⡿","⢿","⣻","⣽","⣾","⣷","⣯","⣟","⡿"]
self.steps3 = ["⣀","⣶","⣿","⣿","⣿","⣿","⣭","⣭","⣉","⣉","⣒","⣒","⣀","⣀","⣀","⣀"]
self.steps4 = ["-","\\","|","/","-","\\","|","/","-","\\","|","/","-","\\","|","/"]
self.done = False
def start(self):
self._thread.start()
return self
def _animate(self):
for c,d,e,f,g,h in cycle(zip(self.steps,self.steps1,self.steps0,self.steps2,self.steps3,self.steps4)):
if self.done:
break
out(f"{self.desc} " + fyb(e) + fgb(f"{c}") + fyb(d) + f" | " + fcb(f) + " | " + fmb(g) + " | " + frb(h) + " ", msg_type=1, end="")
sleep(self.timeout)
def __enter__(self):
self.start()
def stop(self):
self.done = True
cols = get_terminal_size((80, 20)).columns
out(f"{self.end}" + " " * cols,msg_type=1,end="")
def __exit__(self, exc_type, exc_value, tb):
self.stop()
"Bonz's script starts here."
description = """********************************************************
* *
* shodanSearchTool 0.1b - The Shodan Helper *
* *
* Coded by: B0nz *
* *
********************************************************
"""
SHODAN_API_FILE = 'shodan_api.txt'
HISTORY_LIMIT = '20'
HISTORY_FILE = "searchHistory.txt"
yes_list = ["y","yes","yeah","yup",""]
no_list = ["n","no","nope"]
"Coloring, time and print outputs"
def fr(msg):
return Fore.RED + msg + Fore.RESET
def fg(msg):
return Fore.GREEN + msg + Fore.RESET
def fy(msg):
return Fore.YELLOW + msg + Fore.RESET
def fb(msg):
return Fore.BLUE + msg + Fore.RESET
def fc(msg):
return Fore.CYAN + msg + Fore.RESET
def fm(msg):
return Fore.MAGENTA + msg + Fore.RESET
def frb(msg):
return Fore.RED + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def fgb(msg):
return Fore.GREEN + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def fyb(msg):
return Fore.YELLOW + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def fbb(msg):
return Fore.BLUE + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def fcb(msg):
return Fore.CYAN + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def fmb(msg):
return Fore.MAGENTA + Style.BRIGHT + msg + Fore.RESET + Style.RESET_ALL
def br(msg):
return Back.RED + msg + Back.RESET
def bg(msg):
return Back.GREEN + msg + Back.RESET
def by(msg):
return Back.YELLOW + msg + Back.RESET
def bm(msg):
return Back.YELLOW + Fore.BLACK + Style.NORMAL + " "+msg+" " + Back.RESET + Fore.RESET + Style.RESET_ALL
"Input function"
def inp(prefill=''):
try:
print(Fore.CYAN + Style.BRIGHT, end="")
readline.set_startup_hook(lambda: readline.insert_text(prefill))
inpi = input(" ")
print(Fore.RESET + Style.RESET_ALL, end="")
return inpi
except KeyboardInterrupt:
print(Fore.RESET + Style.RESET_ALL)
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print(Fore.RESET + Style.RESET_ALL)
print("Input function: "+str(err))
finally:
readline.set_startup_hook()
"Helping keep the terminal looking good with time stamp"
def nowF(style="Time"):
if style == "Time":
return str(datetime.now().strftime("%H:%M:%S"))
elif style == "Date":
return str(datetime.now().strftime("%d/%m/%Y"))
elif style == "DateTime":
return str(datetime.now().strftime("%d/%m/%Y - %H:%M:%S"))
elif style == "FolderName":
return str(datetime.now().strftime("%Y.%m.%d-%H.%M"))
"Instead of just printing, function for adding some colors, time info etc"
def out(msg, counter=" ", msg_type=0, end=False):
if end == False:
if msg_type == 1: # Positive message
return print(f'\r[{counter}]' + fg("! ") + fy(str(nowF())) + (' - ') + str(msg))
elif msg_type == 0: # Neutral message
return print(f'\r[{counter}] ' + fy(str(nowF())) + (' - ') + str(msg))
elif msg_type == -1: # Negative message
return print(f'\r[{counter}]' + fr("! ") + fy(str(nowF())) + (' - ') + str(msg))
elif msg_type == 2: # Question message
return print(f'\r[{counter}]' + fb("? ") + fy(str(nowF())) + (' - ') + str(msg))
else:
if msg_type == 1: # Positive message
return print(f'\r[{counter}]' + fg("! ") + fy(str(nowF())) + (' - ') + str(msg), end=end)
elif msg_type == 0: # Neutral message
return print(f'[{counter}] ' + fy(str(nowF())) + (' - ') + str(msg), end=end)
elif msg_type == -1: # Negative message
return print(f'[{counter}]' + fr("! ") + fy(str(nowF())) + (' - ') + str(msg), end=end)
elif msg_type == 2: # Question message
return print(f'\r[{counter}]' + fb("? ") + fy(str(nowF())) + (' - ') + str(msg), end=end)
BADMOFO = """
............. ............*#@&@@&%(&@%((%%((&#/#%%,,,.//(,,,*(**........................................................
........................,@@@@@@@@@@%@@@@%&@@*&&&#*&(%##,(//(,(.,........................................................
.......................%%@@@@@@@&@@@&&&&&@&#&%#%(#(*(%((%#/(%,(*.*......................................................
......................*#@@@@@@@@@@@@@@@@@&&&@@&@*&&&#(%%#(&*#(/#,,.,....................................................
......................@@@@@@@@@@@@@@@@@&@@@@@&&#&&@/##/%#%%#*%//.*(**...................................................
.....................&@@@@@@@@@@@@@@@@@@&@@@@%@@&@@#&((/%((&(/((&,(*/...................................................
....................*%@@@@@@@@@@@@@@@@@@@@@@&@&@%@%@&/(/**(&/(%%*.(#*,..................................................
...................*&@@@@@@@@@@@@@@@@@&@@@@@@@@@&&##/%%%(%&@.#%*&/(*/..................................................
....................*@@@@@@@@@@@&&&@@@@&&&&&&&&&%&&&&%(,%#*##&*%##%#**..................................................
....................*%&@@@@@@@@&%%%%%&&&&&%%%&%&%%%%#/(*,.((&&#((//*(...................................................
....................,##@@@@@@&&&&&&&%&@@@&&&%%&@@&&&&&&&#//#@@@/##*(,...................................................
......................*&@@@@&&&&&&&%%&&@@&&&&&&&&@@&@&@@##&#&@%(#%**....................................................
.......................*@@@@&%%%%%&&&&&&&&&&&%,,(#(%&&&%/,,*%&&%/*......................................................
......................./&&@@&%%%%%%&&&&&&%%%%%%, (&/. .../((#%*.......................................................
......................../#@&@%%%%%%%%&&&%%&@@@@@@&%%&%*,.,*//*#.........................................................
.........................(&%&%%%%%%%&&&&@@@@@%(. . /&%/**/##*..........................................................
............................%@&%%%%%@@@@%&&&&&&#*.*. //**#(............................................................
............................&@@@@&&&@&&&&&&&&&*,*,(%(***//%.............................................................
.............................&@&&&%&&&&&%%%@@@&&&&&#(/#*%*/.............................................................
.............................#%%%%&@@&&&&&&&&&&&&@&%#%&,,((/,...........................................................
.............................,%%%%&@@&%%%&%&&&&#/#%(, #(/((/,.........................................................
.............................,%&&&&&@@@&&&&&&&&@&%,. %%###%%#%#((,.....................................................
..............................#&&&&&&&&&&&&&(*,. ..&&%#%%&@@#&##%%##((########((((/....................................
............................@/,*/&@@@****,,,,,..,*%@&%%&&@@@&&##%&%&&&&&%%%%%%#####((((*................................
..........................@@@,..@@@@@,,,,,,,,,,*/@@&&&@@@@#@&&@&&@@@@@@@@&%#(%@%%%&%%###(*..............................
......................(@@@@@&**,@@@@%/*,,,****/@@&@@@@@@@@%@@@@@@@@@@@@@&&&&%%(###%@@@@&#((.............................
.................*@@@@@@@@@&/,,.@@/**(//*****%@@@@@@@@@@@@@@@@@@@@@@@@@&%&&&%#%@@@&&#(#&&%#(............................
.............,@@@@@@@@@@@@****,@@@(*##(//**/@@@@@@@@@@@@@@@@@@@@@&@@@@&&&%%&%%###((&@@@%#%##*...........................
..........%@@@@@@@@@@@@@@%*,,,@@@&%&%&#(***@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&@@@&&###(##@@@&##(...........................
........&@@@@@@@@@@@@@@@#**//@@@@@@@&%#(//@@@@@@@@@@@@@@@@@@@@@@@@%%@@@@@@@@@@@@@%&@@%(@@@@%(...........................
.......&@@@@@@@@@@@@@@@@#/*,*@@@@@@@&%#*/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&%#@@@@@%%##@@&#...........................
.......@@@@@@@@@@@@@@@%*,,,,@@@@@@@@&/*/&@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&%%&%%%%##@@@@%%#&/...........................
......#@@@@@@@@@@@@@@&/****@@@@@@@@%///(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&%%%%%#%@@@#%&&&%#/......................
......@@@@@@@@@@@@@@@%/*//%@@@@@@@#((/(@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&&&&%%%%%/*,,/#&&&%/*/*................
.....(@@@@@@@@@@@@@@@(/**/@@@@@@@&##*(/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&@@&&&&%%%%%(///*****/(%&&#(##(*............
.....@@@@@@@@@@@@@@@#***,@@@@@@@@%%*(*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&&@&&&&((&%%/,**/***/(#&&&%%#((,.......
.....@@@@@@@@@@@@@@%**,,&@@@@@@@@%*/*,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&@@@@&&&&&&&&&@@@/,*/#%(((/****//(#&&&%%#(/*,..
..../@@@@@@@@@@@@@@,,,,.@@@@@@@@%/*/,%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&&&@@@&#((/(%##((((###(////(####. /,
....@@@@@@@@@@@@@@%***,@@@@@@@@&#,/,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@&%%%&&&@@&%##(#(.,#&&&&&%#(///*//(%@&#(.
....@@@@@@@@@@@@@@(*,,/@@@@@@@@%,*/,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%##%%&&&&&%%&&&&&&&#**//////////((###*.
...*@@@@@@@@@@@@@@*,*,@@@@@@@@&*,**,/@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#(&##%&@@&(((##%&&&#*,#/,... .//(((/..
...%@@@@@@@@@@@@@%/***@@@@@@@@#,**.*%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/&@%(#%%%%%%%&&&&&&%(/,. .,,.*.......
...@@@@@@@@@@@@@@%,**@@@@@@@@@,,**,.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/%@#%%%#####%%%%%%(,,******(##(........
...@@@@@@@@@@@@@@**,*@@@@@@@@#,,**,,@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/%#(%%&%%%#%%%%%%%%%#(((/*,...........
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::'########:::::'###::::'########::::::::::::::::::
::::::::::::::: ##.... ##:::'## ##::: ##.... ##:::::::::::::::::
::::::::::::::: ##:::: ##::'##:. ##:: ##:::: ##:::::::::::::::::
::::::::::::::: ########::'##:::. ##: ##:::: ##:::::::::::::::::
::::::::::::::: ##.... ##: #########: ##:::: ##:::::::::::::::::
::::::::::::::: ##:::: ##: ##.... ##: ##:::: ##:::::::::::::::::
::::::::::::::: ########:: ##:::: ##: ########::::::::::::::::::
:::::::::::::::........:::..:::::..::........:::::::::::::::::::
'##::::'##::'#######::'########:'##::::'##:'########:'########::
:###::'###:'##.... ##:... ##..:: ##:::: ##: ##.....:: ##.... ##:
:####'####: ##:::: ##:::: ##:::: ##:::: ##: ##::::::: ##:::: ##:
:## ### ##: ##:::: ##:::: ##:::: #########: ######::: ########::
:##. #: ##: ##:::: ##:::: ##:::: ##.... ##: ##...:::: ##.. ##:::
:##:.:: ##: ##:::: ##:::: ##:::: ##:::: ##: ##::::::: ##::. ##::
:##:::: ##:. #######::::: ##:::: ##:::: ##: ########: ##:::. ##:
..:::::..:::.......::::::..:::::..:::::..::........::..:::::..::
':########:'##::::'##::'######::'##:::'##:'########:'########:::
::##.....:: ##:::: ##:'##... ##: ##::'##:: ##.....:: ##.... ##::
::##::::::: ##:::: ##: ##:::..:: ##:'##::: ##::::::: ##:::: ##::
::######::: ##:::: ##: ##::::::: #####:::: ######::: ########:::
::##...:::: ##:::: ##: ##::::::: ##. ##::: ##...:::: ##.. ##::::
::##::::::: ##:::: ##: ##::: ##: ##:. ##:: ##::::::: ##::. ##:::
::##:::::::. #######::. ######:: ##::. ##: ########: ##:::. ##::
:..:::::::::.......::::......:::..::::..::........::..:::::..:::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"""
"English, do you speak it?"
def english_mofo():
try:
while True:
out("What country you're from?",msg_type=2, end="")
country = inp()
out(f"{country.title()} ain't no country I've ever heard of. They speak english in {country.title()}???",msg_type=2, end="")
speak = inp()
if speak.lower() in yes_list:
print("|"+44*"-")
out("I'll give you one more chance, lets continue.",msg_type=1)
return True
else:
out("English, motherfucker, do you speak it? [y/n]:",msg_type=2, end="")
en = inp()
if en.lower() in yes_list:
print("|"+44*"-")
out("Goddammit, I'll forgive you this time. Lets continue.",msg_type=1)
return True
else:
out(f"Say {en} again! SAY {en.upper()} AGAIN!!! I DARE YOU! I DOUBLE DARE YOU MOTHERFUCKER! SAY {en.upper()} ONE MORE GODDAMN TIME:",msg_type=2, end="")
last = inp()
if last != en:
print("|"+44*"-")
out("I knew you didn't have balls. Lets continue.",msg_type=1)
return True
else:
out("Do I look like a bitch? [y/n]:",msg_type=2, end="")
en = inp()
print(fmb(BADMOFO))
print("\n\n\n")
print(fmb("Wrong answer motherfucker. This file was deleted, download it again and start over motherfucker."))
print("\n\n\n\n\n\n\n\n\n\n\n\n")
file_to_rem = Path(__file__)
file_to_rem.unlink()
exit()
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print("english_mofo: "+str(err))
"Get Shodan API Key status"
def shodan_status(api):
print("|"+44*"-")
try:
out(bm("Shodan API Status") + ' - Shodan account usage.')
loader = Loader("Getting API information...", "Done.", 0.05).start()
account_info = api.info()
loader.stop()
account_info_msg = f"Here's your " + fy("API INFO") + ":\n\n\t- " + fy("Plan") + ": " + fg(account_info.get("plan")) + "\n\t" + (8+len(account_info.get("plan")))*"-" + "\n\t- " + fy("Query Credits") + ": " + fg(str('{:,}'.format(account_info.get("query_credits")))) + " available from " + fg(str('{:,}'.format(account_info.get("usage_limits").get("query_credits")))) + " plan credits\n\t- " + fy("Monitored IPs") + ": " + fg(str('{:,}'.format(account_info.get("monitored_ips")))) + " available from " + fg(str('{:,}'.format(account_info.get("usage_limits").get("monitored_ips")))) + " plan credits\n\t- " + fy("Scan Credits") + ": " + fg(str('{:,}'.format(account_info.get("scan_credits")))) + " available from " + fg(str('{:,}'.format(account_info.get("usage_limits").get("scan_credits")))) + " plan credits\n"
out(account_info_msg)
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print("shodan_status: "+str(err))
print("Exiting")
exit()
"Handle API Key"
def shodan_api_exists():
"Check if Shodan API Key exists."
api_shodan_key_file = Path(SHODAN_API_FILE)
if api_shodan_key_file.is_file() == False:
out(f"No Shodan API Key found on {SHODAN_API_FILE}, please type a valid API Key now or " + fyb('e') + " to exit:", msg_type=2, end=" \nType here: ")
api_shodan_key_to_file = inp()
if api_shodan_key_to_file == "e":
out("Exiting...", msg_type=-1)
exit()
out('Do you want to store this API Key [Y/n]:', msg_type=2, end="")
store_shodan_api_key = inp()
if store_shodan_api_key.lower() in yes_list:
with open(api_shodan_key_file, "w") as api:
api.write(api_shodan_key_to_file)
out("API Key stored.", msg_type=1)
elif store_shodan_api_key.lower() in no_list:
out("The API Key won't be stored.", msg_type=1)
else:
english_mofo()
out("Invalid answer anyways. API Key won't be stored.", msg_type=-1)
return shodan.Shodan(api_shodan_key_to_file)
else:
api_shodan_key = open(api_shodan_key_file, "r").read().rstrip()
return shodan.Shodan(api_shodan_key)
"Chosing Shodan facets search"
def chose_shodan_facets():
facets_dic = {'1': 'city', '2': 'country', '3': 'device', '4': 'domain', '5': 'has_screenshot', '6': 'hash', '7': 'http.favicon.hash', '8': 'http.title', '9': 'http.waf', '10': 'ip', '11': 'isp', '12': 'link', '13': 'mongodb.database.name', '14': 'org', '15': 'os', '16': 'port', '17': 'product', '18': 'region', '19': 'state', '20': 'tag', '21': 'version', '22': 'vuln', '23': 'vuln.verified'}
while True:
try:
out("Those are the facets options.",msg_type=2)
for i, item in facets_dic.items():
print(f"\t[" + fgb(str(i)) + "] - " + fy(f"{item}"))
print('\t[' +
fyb('b') + '] - To go ' + fy("back") + '\n\t[' +
fyb('e') + '] - To go ' + fy('EXIT') + '')
out("Choose one or more facets to improve your query filtering or one of the above options:",msg_type=2,end="")
facet_choice = inp()
if facet_choice == "b":
return ""
elif facet_choice == "e":
out("Exiting.", msg_type=-1)
exit()
out("How many facets contents do you want display per chosen facet? (1-100, default: 10)",msg_type=2,end="")
facet_qtt = inp()
if facet_qtt == "":
facet_qtt = 10
x = int(facet_qtt)
faces_list = []
for faceidx in facet_choice.replace(" ","").split(","):
faces_list.append((facets_dic[faceidx],x))
return faces_list
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
out(fmb("Error: ")+str(err),msg_type=-1)
continue
"Handling Shodan facets search"
def shodan_facets_choo(api, query):
"The code of this function was stracted and adapted from https://shodan.readthedocs.io/en/latest/examples/query-summary.html"
while True:
try:
faces_list = chose_shodan_facets()
loader = Loader("Getting query facets...", "Done.", 0.05).start()
result = api.count(query, facets=faces_list)
loader.stop()
out('', msg_type=1)
print(fy(f"\tShodan Summary Information -----"))
print(f'\tQuery: ' + fg(query))
print('\tTotal Results: ' + fg(str('{:,}'.format(result['total']))) + "\n")
a = 1
facets_opt = {}
for facet in result['facets']:
print("\t" + fy(facet + " ---"))
for term in result['facets'][facet]:
print(f"\t[" + fgb(str(a)) + "] - " + fy(f"{term['value']}") + ": " + fg(str('{:,}'.format(term['count']))) + " devices")
facets_opt[a] = facet + "," + str(term['value'])
a+=1
print('')
out("Chose one or more " + fy("filter(s)") + ", [" + fyb("S") + "] to skip (default), [" + fyb("b") + "] to go back or [" + fyb("e") + "] to exit:", msg_type=2, end="")
facet_filter = inp()
if facet_filter in ["s","","S"]:
out("Skipping.")
return query
elif facet_filter == "e":
out("Exiting.", msg_type=-1)
exit()
elif facet_filter == "b":
return query
facet_query = ""
facet_filter_list = facet_filter.split(',')
facet_chosen_dict = {}
chosen_facet_list = []
for facet_idx in facet_filter_list:
facet_chosen_dict[facets_opt[int(facet_idx)].split(",")[1]] = facets_opt[int(facet_idx)].split(",")[0]
chosen_facet_list.append(facets_opt[int(facet_idx)].split(",")[0])
chosen_facet_list = list(set(chosen_facet_list))
for chosen_facet in chosen_facet_list:
facet_query = facet_query + f"{chosen_facet}:"
facet_values = [k for k,v in facet_chosen_dict.items() if v == chosen_facet]
for facet_value in facet_values:
facet_query = facet_query + f'"{facet_value}",'
facet_query = facet_query[:-1] + " "
facet_query = facet_query[:-1]
out('To your query will be added: "' + fy(facet_query) + '"')
query = query + " " + facet_query
out('Your query now is: "' + fy(query) + '"')
return query
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
out(fmb("Error: ")+str(err),msg_type=-1)
continue
"Why not to be able to choose Shodan facets filters as one wants?"
def shodan_facets(api, query):
print("|"+44*"-")
out("Do you want to see the " + bm("FACETS") + " before continuing [y/N]?", msg_type=2, end="")
see_facets = inp()
if see_facets.lower() in ["n","no",""]:
return query
while True:
print("|"+44*"-")
try:
query = shodan_facets_choo(api, query)
print("|"+44*"-")
out("Do you want to see even more " + bm("FACETS") + " for your query " + fy(f"'{query}'") + " before continuing [y/N]?", msg_type=2, end="")
see_more_facets = inp()
if see_more_facets.lower() in ["y","yes"]:
continue
elif see_more_facets.lower() in ["","n","no"]:
return query
else:
if english_mofo():
continue
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
out(fmb("Error: ")+str(err),msg_type=-1)
continue
"Shodan queries shared by community helper"
def shodan_shared_queries(api, sort='timestamp', page=1):
shared_dic = {}
if sort not in ["timestamp","votes"]:
result = api.queries_search(sort, page=[1,2,3])
else:
result = api.queries(page=page, sort=sort, order='desc')
if len(result["matches"]) < 1:
out("No results found.", msg_type=-1)
return ""
a = 1
for queries in result["matches"]:
print("\t|----------------")
print(fy("\t Time") + ": " + fg(str(queries["timestamp"][:10])) + fy("\n\t Votes") + ": " + fg(f"{queries['votes']}") + "\n\t" + fy(" Descr.") + ":" + fg(f" {queries['description']}"))
print(fy("\t Title") + ": " + fg(queries["title"]))
print("\t[" + fyb(str(a)) + "] " + fy("Query") + ": " + fyb(f"{queries['query']}"))
shared_dic[a] = queries['query']
a += 1
print("\t|----------------")
print("\t[" + fyb("b") + "] to go " + fy("back") + " to previous list" + "\n\t[" + fyb("e") + "] to " + fy("EXIT"))
return shared_dic
"Shodan queries shared by community"
def shared_queries(api):
print("|"+44*"-")
while True:
try:
out(bm("Shared queries") + " - Do you want to:", msg_type=2)
print("\t[" + fgb("1") + "] list shared " + fy("queries") + " sorted by votes desc." +
"\n\t[" + fgb("2") + "] list shared " + fy("queries") + " sorted by date desc." +
"\n\t[" + fgb("3") + "] search in shared " + fy("queries") + " with a keyword" +
"\n\t[" + fyb("b") + "] to go " + fy("back") + " to previous list" +
"\n\t[" + fyb("e") + "] to " + fy("EXIT"))
out("Please choose one option:", msg_type=2, end="")
shared_opt = inp()
if shared_opt == "1":
out("What page number of results do you want?", msg_type=2, end="")
shared_opt_1 = inp()
if int(shared_opt_1) in range(1,100):
shared_dic = shodan_shared_queries(api, sort='votes', page=int(shared_opt_1))
else:
out("Invalid page number. Try again", msg_type=-1)
elif shared_opt == "2":
out("What page number of results do you want?", msg_type=2, end="")
shared_opt_2 = inp()
if int(shared_opt_2) in range(1,100):
shared_dic = shodan_shared_queries(api, sort='timestamp', page=int(shared_opt_2))
else:
out("Invalid page number. Try again", msg_type=-1)
elif shared_opt == "3":
out("What keyword do you want to search in shared queries?", msg_type=2, end="")
shared_que_keyw = inp()
out("What page number of results do you want?", msg_type=2, end="")
shared_opt_3 = inp()
if int(shared_opt_3) in range(1,100):
shared_dic = shodan_shared_queries(api, sort=shared_que_keyw, page=int(shared_opt_3))
elif shared_opt == "b":
return ""
elif shared_opt == "e":
out("Exiting.",msg_type=-1)
exit()
if type(shared_dic) == str:
continue
out("Chose one of the " + fy("queries") + " or " + fy("options") + " above:", msg_type=2, end="")
optionsha = inp()
if optionsha == "b":
print(optionsha)
return ""
elif optionsha == "e":
out("Exiting.",msg_type=-1)
exit()
else:
query = shared_dic[int(optionsha)]
print(query)
return query
except Exception as err:
out(fmb("Invalid option, try again."),msg_type=-1)
continue
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
"Shodan Wizard step 1"
def wizard_step1():
print("|"+44*"-")
while True:
try:
out(bm("Step 1") + ' - Shodan search options:\n\t[' +
fgb('1') + '] - for query ' + fy('EXAMPLES') + '\n\t[' +
fgb('2') + '] - for query ' + fy('BUILDER') + '\n\t[' +
fgb('3') + '] - for ' + fy('API INFO') + '\n\t[' +
fgb('4') + '] - to check information of a specific ' + fy('HOST') + '\n\t[' +
fgb('5') + '] - use one query from ' + fy('HISTORY') + '\n\t[' +
fgb('6') + '] - type a ' + fy('CUSTOM') + ' query\n\t[' +
fgb('7') + '] - to check queries ' + fy('SHARED') + ' by users\n\t[' +
fgb('8') + '] - to find and build a query based on ' + fy('VULNERABILITIES') + ' \n\t[' +
fyb('e') + '] - to ' + fy('EXIT') + '', msg_type=1)
out('Enter one ' + fgb('option') + ' from above:', msg_type=2, end="")
query = str(inp())
if query in ["1","2","3","4","5","6","7","8","e"]:
return query
else:
print("|"+44*"-")
out(fmb("Invalid option, try again."),msg_type=-1)
continue
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
query_examples_dic = {"1":['"Server: CarelDataServer" "200 Document follows"','Refrigeration Units'],
"2":['"Siemens, SIMATIC" port:161','Siemens Industrial Automation'],
"3":['"Android Debug Bridge" "Device" port:5555','Android Root Bridges'],
"4":["country:KP","All 36 devices in North Korea"],
"5":["port:37777 country:UA","Dahua DVRs in Ukraine"]}
"Shodan Wizard query examples"
def query_examples():
print("|"+44*"-")
while True:
try:
out(bm("Examples") + ' - Check https://github.com/jakejarvis/awesome-shodan-queries for AWESOME Shodan queries!\n\tSome query ' + fy('EXAMPLES') + ' are:')
options_dic = []
for key, value in query_examples_dic.items():
options_dic.append(key)
q = value[0]
d = value[1]
print('\n\t[' + fgb(key) + "] - " + fy(f'{q}') + f" -> {d}")
print('\n\t[' +
fyb('b') + '] - go ' + fy("back") + '\n\t[' +
fyb('e') + '] - to ' + fy('EXIT') + '')
out('Enter one ' + fgb('option') + ' from above:', msg_type=2, end="")
example_option = str(inp())
if example_option in query_examples_dic.keys():
query = query_examples_dic[example_option][0]
return query
elif example_option == "b":
return False
elif example_option == "e":
print("|"+44*"-")
out("Exiting.",msg_type=-1)
exit()
else:
print("\n|"+44*"-")
out(fm("Invalid option '") + fyb(example_option) + fm("' , try again."),msg_type=-1)
continue
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
"Just type a custom query"
def custom_query():
try:
print("|"+44*"-")
out(bm("Custom query") + " - Type your custom query, " + fyb("b") + " to go " + fyb("back") + " or " + fyb("e") + " to exit.", msg_type=2, end="")
query = inp()
if query == "b":
return ""
elif query == "e":
out("Exiting.",msg_type=-1)
exit()
else:
return query
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
out(fmb(str(err)),msg_type=-1)
"Shodan Wizard Start"
def shodan_wizard(api, step=""):
step1 = ""
while True:
try:
if step1 == "":
step1 = wizard_step1()
q1 = step1
if q1 == "e":
print("|"+44*"-")
out("Exiting.",msg_type=-1)
exit()
elif q1 == "1" or step == "examples":
query = query_examples()
if query == False:
step1 = ""
continue
else:
return query, "examples"
elif q1 == "2" or step == "query_builder":
query = query_builder()
if query == "":
step1 = ""
continue
else:
return query, "query_builder"
elif q1 == "3":
shodan_status(api)
step1 = ""
continue
elif q1 == "4":
shodan_host(api)
step1 = ""
continue
elif q1 == "5" or step == "history_search":
query = history_search()
if query == "":
step1 = ""
continue
else:
return query, "history_search"
elif q1 == "6" or step == "custom":
query = custom_query()
if query == "":
step1 = ""
continue
return query, "custom"
elif q1 == "7" or step == "shared_queries":
query = shared_queries(api)
if query == "":
step1 = ""
continue
else:
return query, "shared_queries"
elif q1 == "8" or step == "search_vuln":
print("|"+44*"-")
query = search_vuln()
return query, "custom"
elif q1 in ["2","4","5","6","8"]:
break
else:
print("|"+44*"-")
out(fm("Invalid option '") + fyb(q1) + fm("' , try again."),msg_type=-1)
# return query
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
out(fmb(str(err)),msg_type=-1)
continue
"Use history search as query"
def history_search():
print("|"+44*"-")
while True:
try:
history_file_path = Path(HISTORY_FILE)
if not history_file_path.is_file():
out(bm("Histrory") + " - There are no history records. Try another option.", msg_type=-1)
return ""
out(bm("History") + " - Choose one of your recent queries:", msg_type=1)
with history_file_path.open("r", encoding="utf-8") as f:
content_lines = f.read().splitlines()
if len(content_lines) < int(HISTORY_LIMIT):
hist_lim = len(content_lines)
else:
hist_lim = HISTORY_LIMIT
for line in range(1,hist_lim+1,1):
print("\t[" + fgb(str(line)) + f'] - {content_lines[line-1].split("|")[0]} - ' + fy(f"'{content_lines[line-1].split('|')[1]}'"))
print("\t[" + fyb("b") + f'] - To go ' + fy("back") + "\n\t[" + fyb("e") + f'] - To ' + fy("exit"))
out("Type the number corresponding to the query:", msg_type=2, end="")
query_line = inp()
if query_line == "e":
out("Exiting...", msg_type=-1)
exit()
if query_line == "b":
return ""
query = content_lines[int(query_line)-1].split("|")[1]
content_lines.remove(content_lines[int(query_line)-1])
with history_file_path.open("w+", encoding="utf-8") as s:
for idx in range(0,len(content_lines),1):
s.write(content_lines[idx] + "\n")
line = f'{str(datetime.now().strftime("%d/%m/%Y at %H:%M:%S"))}|{query}'
with history_file_path.open("a", encoding="utf-8") as a:
a.write(line + "\n")
return query
except Exception as err:
out(fmb(str(err)),msg_type=-1)
continue
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
"Query builder"
def query_builder():
print("|"+44*"-")
while True:
try:
shodan_query = ""
out(bm("Query Builder") + " - This builder will help you to build a query. Each question adds a filter. " + fyb("Leave blank") + " if you don't want any of the filters. At anytime type " + fyb("b") + " to go " + fyb("back") + " or " + fyb("e") + " to exit.")
out("Enter a " + fgb("country") + " (two letter format, i.e.: 'US'):", msg_type=2, end="")
country = str(inp()).upper()
if len(country) == 2:
shodan_query = shodan_query + 'country:"'+country+'"'
elif country == "E":
out("Exiting...", msg_type=-1)
exit()
elif country == "B":
return ""
out("Enter a " + fgb("city") + " name:", msg_type=2, end="")
city = str(inp())
if len(city) >= 2:
shodan_query = shodan_query + ' city:"'+city+'"'
elif city == "e":
out("Exiting...", msg_type=-1)
exit()
elif city == "b":
return ""
out("Enter one " + fgb("port") + " or more, using comma to separate them (i.e.: '80,443,8080' or '554'):", msg_type=2, end="")
port = str(inp())
if len(port) >= 2:
shodan_query = shodan_query + ' port:'+port+''
elif port == "e":
out("Exiting...", msg_type=-1)
exit()
elif port == "b":
return ""
out("Finaly, you can optionaly enter any " + fgb("word") + " as filter (i.e.: 'linux upnp avtech'):", msg_type=2, end="")
word = str(inp())
if len(word) >= 2:
shodan_query = shodan_query + f' "{word}"'
elif word == "e":
out("Exiting...", msg_type=-1)
exit()
elif word == "b":
return ""
if shodan_query[0] == " ":
shodan_query = shodan_query[1:]
out("This query will be used: '" + fy(shodan_query) + "'. Confirm? [Y/n]", msg_type=2, end="")
confirm = inp()
if confirm.lower() in yes_list:
return shodan_query
out("Edit your query as you wish or hit " + fy("ENTER") + " to start over:", msg_type=1, end="")
query = inp(shodan_query)
if query == shodan_query:
out("OK, let's start again.",msg_type=1)
continue
else:
out("This query will be used: '" + fy(query) + "'.",msg_type=1)
return query
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print("Error: "+str(err))
exit()
"Vunlerabilities info from nvd.nist.gov"
def vuln_info(vuln):
while True:
try:
print("|"+44*"-")
vuln = str(vuln).upper()
if vuln[:3] != "CVE":
out("You can only get more information on CVEs vulnerabilities. Do you want to use " + fy(f"vuln:{vuln}") + " as query (" + fgb("y") + ") or try another one (" + fgb("n") + ")?", msg_type=2, end="")
vuln_opt1 = inp()
if vuln_opt1 in ["y",""]:
query = "vuln:"+vuln
out("Continuing with query " + fy(query) + ".")
return query
else:
return False
loader = Loader(f"Getting {vuln} information...", "Done.", 0.05).start()
response = requests.get(f"https://services.nvd.nist.gov/rest/json/cves/2.0?cveId={vuln}")
loader.stop()
out(f"Official information about " + fy(vuln) + ".")
if response.status_code == 200:
json_response = response.json()
print(fy(f'\tPublished') + ": " + fg(f'{str(json_response["vulnerabilities"][0]["cve"]["published"])[:10]}'))
print(fy(f'\tLast Modified') + ": " + fg(f'{str(json_response["vulnerabilities"][0]["cve"]["lastModified"])[:10]}'))
print(fy('\tDescription') + ": ", end="")
a = 0
b = 100
descrp = str(json_response["vulnerabilities"][0]["cve"]["descriptions"][0]["value"])
l = (round(len(descrp)/b))+ (len(descrp) % b > 0)
for i in range(0,l):
if i == 0:
print(fg(f'{descrp[a:a+b]}'))
else:
print(fg(f'\t\t {descrp[a:a+b]}'))
a+=b
cvsskey = str(list(json_response["vulnerabilities"][0]["cve"]["metrics"].keys())[0])
print(fy(f'\tCVSSDATA') + ": ")
cvssData = json_response["vulnerabilities"][0]["cve"]["metrics"][cvsskey][0]["cvssData"]
for key, value in cvssData.items():
print(fy(f"\t\t{str(key).capitalize()}") + ": " + fg(f"{str(value).capitalize()}"))
print("\t\t----------")
metrics = json_response["vulnerabilities"][0]["cve"]["metrics"][cvsskey][0]
for key, value in metrics.items():
if type(value) != dict:
print(fy(f"\t\t{str(key).capitalize()}") + ": " + fg(f"{str(value).capitalize()}"))
print("\n\t\tFor more information access: " + fy(f"https://nvd.nist.gov/vuln/detail/{vuln}\n"))
out("Do you want to use " + fy(f"vuln:{vuln}") + " as query [" + fyb("Y") + "], try another one [" + fyb("n") + "], go back [" + fyb("b") + "] or [" + fyb("e") + "] exit?", msg_type=2, end="")
vuln_opt2 = inp()
if vuln_opt2 in yes_list:
query = "vuln:"+vuln
out("Continuing with query " + fy(query) + ".")
return query
elif vuln_opt2 == "e":
out("Exiting...", msg_type=-1)
exit()
elif vuln_opt2 == "b":
return ""
else:
return False
else:
out("API returned error [" + fy(str(response.status_code)) + "] status code.", msg_type=-1)
out("Exiting.", msg_type=-1)
exit()
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
"Build a query based on vulns"
def search_vuln():
print("|"+44*"-")
while True:
try:
out(bm("Vulnerabilities") + " - Choose one of the following vulnerabilities:", msg_type=2)
vulns = ["cve-2015-0204","cve-2015-4000","cve-2015-1635","ms15-034","cve-2020-0796","cve-2014-0160","cve-2019-0708","cve-2021-31206","cve-2022-32548","cve-2021-43798","cve-2019-1652","cve-2019-1653","cve-2017-7269","ms17-010","cve-2021-26855","cve-2021-26857","cve-2021-26858","cve-2021-27065","cve-2021-31207","cve-2021-34473","cve-2021-34523","cve-2015-2080","cve-2022-36804","cve-2013-1899","cve-2019-19781","cve-2019-11510","cve-2013-1391","cve-2020-5902","cve-2016-9244","cve-2020-11651","cve-2020-11652"]
for vuln_number in range(1,len(vulns)):
if vuln_number < 10:
numb = f" {str(vuln_number)}"
else:
numb = str(vuln_number)
print("\t[" + fgb(numb) + f"] - {vulns[vuln_number-1].upper()}" + (21-len(vulns[vuln_number-1]))*" ", end=" ")
if vuln_number % 3 == 0:
print("\n",end="")
print("\t[ " + fyb("b") + "] to go " + fy("back") + " to previous list" +
"\n\t[ " + fyb("e") + "] to " + fy("EXIT"))
out("Your choice:", msg_type=2, end="")
selected_vuln = inp()
if selected_vuln == "e":
out("Exiting...", msg_type=-1)
exit()
elif selected_vuln == "b":
return ""
out("You selected " + fy(vulns[int(selected_vuln)-1]) + ".")
query = vuln_info(vulns[int(selected_vuln)-1])
if query == False:
continue
else:
return query
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print("search_vuln: "+str(err))
out(f"Invalid input " + fy(str(selected_vuln)) + ". Try again.", msg_type=-1)
exit()
"Get Shodan info for specific host"
def shodan_host(api):
print("|"+44*"-")
while True:
try:
out(bm("Host") + " - Type the host IP address (IPV4), [" + fyb("e") + "] to " + fy("exit") + " or [" + fyb("b") + "] to go " + fy("back") + " and start over.", msg_type=2, end="")
host = inp()
if host == "e":
print("")
out("Exiting...", msg_type=-1)
exit()
elif host == "b":
print("")
return ""
else:
out("Confirm search for " + fg(host) + "? [Y/n]", msg_type=2, end="")
confhost = inp()
if confhost not in yes_list:
continue
out("Starting Shodan search for " + fg(host) + "...")
loader = Loader("CStarting Shodan host...", "Done.", 0.05).start()
host_result = api.host(host)
loader.stop()
out("Do you want to " + fyb("print") + " the output [Y/n]?", msg_type=2, end="")
print_output = inp()
if print_output.lower() in yes_list:
out("Shodan returned the following information:")
print("\tIP: " + fg(f"{host_result.get('ip_str','n/a')} ") + "\n\tOrganization: " + fg(f"{host_result.get('org', 'n/a')} ") + "\n\tOperating System: " + fg(f"{host_result.get('os', 'n/a')} "))
for item in host_result['data']:
print("\n\tPort: \t" + fg(str(item['port'])) + "\n\tBanner:")
for itens in str(item['data']).splitlines():
print("\t\t" + fg(itens))
out("Do you want to save the output? Type " + fyb("n") + " or the " + fyb("file name") + " , i.e.: result.json):", msg_type=2, end="")
filename = inp()
if filename != "n":
if filename == "":
filename = f"{str(host_result.get('ip_str','result'))}.json"
resp_json = json.dumps(host_result)
with open(Path(filename), "w") as test:
test.write(resp_json)
out("Result saved as " + fy(filename) + ".")
except KeyboardInterrupt:
print("")
out("Exiting...", msg_type=-1)
exit()
except Exception as err:
print("shodan_host: "+str(err))
"Edit the query"
def edit_query(query):
while True:
try:
print("|"+44*"-")
out("Do you want to " + bm("EDIT") + " the query " + fy(f'"{query}"') + "?")
print("\t[" + fyb("y") + "] To " + fy("edit") + " before continuing")
print("\t[" + fyb("N") + "] To " + fy("use") + " as is")
print("\t[" + fyb("b") + "] To go " + fy("back") + " and start over.")
print("\t[" + fyb("e") + "] To " + fy("exit"))
out("Please choose one of the above:", msg_type=2, end="")
edit_query = inp()
if edit_query.lower() in ["y","yes","yup"]:
print("")
out("Edit the query as you wish:",end="")
query = inp(query)
continue
elif edit_query.lower() in ["n","","no"]:
print("")