-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
192 lines (90 loc) · 4.47 KB
/
main.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
import sys
import getinfo
import shodan
import ipcalc
import ipaddress
APIKEY = open("API.txt", "r")
SHODAN_API_KEY = APIKEY.read().splitlines()
api = shodan.Shodan(SHODAN_API_KEY)
#IPCAL - CALCULA A RANGE
def calcr(ip):
for address in ipcalc.Network(ip):
try:
ip = str(address)
getinfo.main(ip)
except Exception as err:
print(f"{err}")
# FUNCAO PARA UTILIZAR DEMAIS CONSULTAS DO SHODAN
def shodan_search(page, loopcount, shodan_query):
query = api.search(query=shodan_query, page=page)
total = len(query['matches'])
if total == 0:
print(f"\n [!] Try another query :)")
sys.exit(0)
print(f"\n ┏━ [!] Found {total} results for this query")
print(" ┗━ [!] This query will consume your API credits")
for x in range(total):
ip = query['matches'][x]['ip_str']
getinfo.main(ip)
if loopcount != query['total']:
page = page + 1
loopcount = loopcount + 1
shodan_search(page, loopcount, shodan_query)
else:
sys.exit(0)
def get_domain(domain):
shodan_get_domain = api.dns.domain_info(domain=domain, history=True, type=None, page=1)
print("\n [!] This query will consume your API credits")
print(f"\n ┏━ [!] ┃━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━[ {domain} ]━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┃")
for x in shodan_get_domain['data']:
print(f" ┃ ┗━ [+] DOMAIN: {x['subdomain']}.{domain} TYPE: {x['type']}\n ┃ ┃ ┗━ [+] VALUE: {x['value']}\n ┃ ┃")
for x in shodan_get_domain['data']:
try:
ip = str(ipaddress.ip_address(x['value']))
getinfo.main(ip)
except Exception as e:
pass
def main():
try:
shodan_query = sys.argv[1]
# CONDICAO PARA REALIZAR CONSULTAS GRATUITAS NA API DO SHODAN
if shodan_query[0:5] == "host:":
ip = shodan_query[5:]
if shodan_query[-3:-2] == "/":
calcr(ip)
else:
getinfo.main(ip)
# IMPLEMENTACAO DA ENTRADA DE DADOS VIA ARQUIVO
elif shodan_query[0:5] == "file:":
file_list = shodan_query[5:]
with open(file_list, 'r') as file:
for line in file:
line_file = line.strip()
if line_file[-3:-2] == "/":
ip = line_file
calcr(ip)
else:
try:
ip = str(ipaddress.ip_address(line_file))
getinfo.main(ip)
except:
domain = line.strip()
get_domain(domain)
elif shodan_query[0:7] == "domain:":
domain = shodan_query[7:]
get_domain(domain)
elif shodan_query == "--xdbupdate":
getinfo.get_xdb_update()
else:
loopcount = 1
page = 1
try:
shodan_search(page, loopcount, shodan_query)
except Exception as e:
print(e)
except Exception as e:
print("[+] Err:", e)
getinfo.get_banner()
pass
if __name__ == "__main__":
main()