-
Notifications
You must be signed in to change notification settings - Fork 4
/
ShodanSearch.py
270 lines (262 loc) · 8.68 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
############################################################################
#
# ShodanSearch.py
# © 2021 ABDULKADİR GÜNGÖR All Rights Reserved
# Contact email address: abdulkadir_gungor@outlook.com
#
# Developper: Abdulkadir GÜNGÖR (abdulkadir_gungor@outlook.com)
# Date: 04/2021
# All Rights Reserved (Tüm Hakları Saklıdır)
#
############################################################################
from SearchData import SearchData
from NetworkData import NetworkData
import shodan, socket, os
# Ekranı Temizlemek için
def screenClear():
print("\r\n") # Konsol dışı kullanımda ekranı temizlemek için
# clear screen
# ********************
# Windows
if os.name=='nt':
os.system('cls')
# Linux or MAC
elif os.name=='posix':
os.system('clear')
# ********************
print("")
#
def showBanner():
print()
print('\t#####################################################')
print('\t#/*************************************************\#')
print('\t#**||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||**#')
print('\t#**|| ||**#')
print('\t#**|| Shodan Search V1.1 ||**#')
print('\t#**|| 04/2021 ||**#')
print('\t#**|| ||**#')
print('\t#**|| Developer: Abdulkadir GÜNGÖR ||**#')
print('\t#**|| (abdulkadir_gungor@outlook.com) ||**#')
print('\t#**|| ||**#')
print('\t#**||~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~||**#')
print('\t#\*************************************************/#')
print('\t#####################################################')
print()
print()
#
def showMenu():
print('\t MENU')
print('\t--------------------------------')
print('\t1) Scan Ip/Hostname')
print('\t2) Scan Network')
print()
print()
print('\t(Exit) <<e>>')
# Shodan Api Key
def check_api_key():
try:
with open("Shodan_Api_Key.txt","r") as rfile:
key = rfile.read()
api_key = key.strip()
result = True
except:
api_key = ''
result = False
#
return result, api_key
#
def search_ip_or_hostname(SHODAN_API_KEY):
try:
print()
print('\t{:^40}'.format('#' * 40))
print('\t{:^40}'.format('SHODAN IP/HOSTNAME SEARCH'))
print('\t{:^40}'.format('#' * 40))
print()
print()
print('\t(Input Example) <Input> : www.google.com')
print('\t(Input Example) <Input> : 8.8.8.8')
print()
tmp_input = input('\t<Input> : ')
print()
print()
target_ip = socket.gethostbyname(tmp_input.strip())
api = shodan.Shodan(SHODAN_API_KEY)
host = api.host(target_ip)
data = SearchData()
#
for key in host:
if key == 'ip_str':
data.ip = host[key]
elif key == 'ports':
data.ports = host[key]
elif key == 'os':
data.os = host[key]
elif key == 'last_update':
data.last_update = host[key]
elif key == 'vulns':
data.vulns = host[key]
elif key == 'country_name':
data.country_name = host[key]
elif key == 'city':
data.city = host[key]
elif key == 'org':
data.organization = host[key]
elif key == 'data':
data.data = host[key]
#
print('\t{:^40}'.format('SUMMARY'))
print('\t{}'.format('-' * 40))
print("\tIp :", data.ip)
print("\tCity :", data.city)
print("\tCountry :", data.country_name)
print("\tOrganization :", data.organization)
print("\tLast Update :", data.last_update)
print("\tOs :", data.os)
print("\tPorts :", data.ports)
print("\tVulnerabilities :", data.vulns)
print('\t{}'.format('-' * 40))
print()
print()
print('\t{:^40}'.format('DETAIL(S)'))
print('\t{}'.format('-' * 40))
for item in data.data:
print()
print("\tPort :", item['port'])
try:
print("\tProtocol :", item['transport'])
except:
print("\tProtocol : - ")
try:
print("\tProgram :", item['product'])
except:
print("\tProgram : - ")
try:
print("\tVulnerability(ies) :", item['vulns'])
except:
print("\tVulnerability(ies) : - ")
# print("\tAll Data :", item)
#
print('\t{}'.format('-' * 40))
print()
print()
input("\t(Back) <Enter> :")
#
except:
print("\tAn error occurred!")
print()
print()
input("\t(Back) <Enter> :")
#
def search_network(SHODAN_API_KEY):
try:
print()
print('\t{:^40}'.format('#' * 40))
print('\t{:^40}'.format('SHODAN NETWORK SEARCH'))
print('\t{:^40}'.format('#' * 40))
print()
print()
print('\t(Input Example) <Input> : 8.8.8.0/24 ')
print()
tmp_input = input('\t <Input> : ')
print()
print()
api = shodan.Shodan(SHODAN_API_KEY)
search_tmp = f"net:{tmp_input.strip()}"
network = api.search( search_tmp, minify=False)
#
print('\t{:^40}'.format('RESULT(S)'))
print('\t{}'.format('-' * 40))
print('\tNetwork : {}'.format(tmp_input.strip()))
print('\tTotal Result : {}'.format(network['total']))
print()
print()
#
results = []
for tmp in network['matches']:
data = NetworkData()
#
try:
data.ip = tmp['ip_str']
except:
data.ip = '-'
#
try:
data.port = tmp['port']
except:
data.port = '-'
#
try:
data.os = tmp['os']
except:
data.os = '-'
#
try:
data.vulns = tmp['vulns']
except:
data.vulns = '-'
#
try:
data.organization = tmp['org']
except:
data.organization = '-'
#
try:
data.data = tmp['data']
except:
data.data = '-'
#
results.append(data)
#
if len(results) > 0:
txt_tmp = f"{len(results)} IP(s) are shown"
print('\t{:^40}'.format(txt_tmp))
print('\t{}'.format('-' * 40))
for tmp in results:
print('\t{}:{}'.format(tmp.ip, tmp.port))
print()
print()
for tmp in results:
print('\t{:^40}'.format('DETAILS'))
print('\t{}'.format('-' * 40))
print("\tIp :", tmp.ip)
print("\tOrganization :", tmp.organization)
print("\tOs :", tmp.os)
print("\tPort :", tmp.port)
print("\tVulnerabilities :", tmp.vulns)
print('\t{}'.format('-' * 40))
print()
print()
print()
input("\t(Back) <Enter> :")
except:
print("\tAn error occurred!")
print()
print()
input("\t(Back) <Enter> :")
#
if __name__ == '__main__':
res, SHODAN_API_KEY = check_api_key()
if res:
while True:
screenClear()
showBanner()
showMenu()
tmp = input('\t(Selection) : ')
if tmp.strip().lower() == 'e' :
exit(0)
elif tmp.strip().isdigit():
slc = int(tmp.strip())
if slc == 1:
screenClear()
search_ip_or_hostname(SHODAN_API_KEY)
elif slc == 2:
screenClear()
search_network(SHODAN_API_KEY)
else:
screenClear()
showBanner()
print('\t"Shodan_Api_Key.txt" not found.')
print()
print()
input("\t(Exit) <Enter> :")
exit(0)