-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_shodan.py
122 lines (115 loc) · 3.85 KB
/
get_shodan.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
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import json
driver_path = "/home/ahmetturgut/chromedriver"
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=driver_path,chrome_options=chrome_options)
elastic_array=[]
elastic_company=[]
elastic_size=[]
elastic_indices=[]
mongodb_array=[]
mongodb_company=[]
mongodb_size=[]
mongodb_indices=[]
output = {}
def login():
driver.get("https://account.shodan.io/login")
driver.find_element_by_id("username").send_keys("ahmetturgut97")
driver.find_element_by_id("password").send_keys("Ahmet100$")
driver.find_element_by_name("login_submit").click()
def elastic():
result=driver.find_elements_by_class_name('search-result')
for i in range(len(result)):
a = result[i].find_element_by_class_name('ip')
elastic_array.append(a.text)
company = result[i].find_element_by_class_name('os')
elastic_company.append(company.text)
try:
companys = result[i].find_element_by_class_name('section-green')
elastic_size.append(companys.text)
except:
elastic_size.append("NULL")
all_indicex = result[i].text
indices = all_indicex.split('Elastic Indices:')
elastic_indices.append(indices[1])
def mongodb():
result = driver.find_elements_by_class_name('search-result')
for i in range(len(result)):
a = result[i].find_element_by_class_name('ip')
mongodb_array.append(a.text)
company = result[i].find_element_by_class_name('os')
mongodb_company.append(company.text)
try:
companys = result[i].find_element_by_class_name('section-green')
mongodb_size.append(companys.text)
except:
mongodb_size.append("NULL")
indices = result[i].find_elements_by_class_name('table')
b = ""
for aa in indices:
b += aa.text
mongodb_indices.append(b)
def nextpage():
try:
next = driver.find_element_by_link_text("Next")
next.click()
return 1
except:
return 0
def get_elastic():
driver.get("https://www.shodan.io/search?query=port%3A%229200%22+all%3A%22elastic+indices%22++country%3A%22tr%22")
while True:
prelen = len(elastic_array)
elastic()
next=nextpage()
if next == 0:
break
def get_mongodb():
driver.get("https://www.shodan.io/search?query=all%3A%22mongodb+server+information%22+all%3A%22metrics%22+country%3A%22tr%22")
while True:
prelen = len(mongodb_array)
mongodb()
next=nextpage()
if next == 0:
break
def write():
output['ElasticSearch'] = []
for i in range(len(elastic_array)):
indices=elastic_indices[i]
indicesarray=indices.split('\n')
for j in range(len(indicesarray)):
indicesarray[j]=indicesarray[j].strip()
indicesarray.pop(0)
lastindex=len(indicesarray)
count = indicesarray[lastindex-1].count("...")
if count>0:
indicesarray.pop()
output['ElasticSearch'].append({
'ip': elastic_array[i],
'company': elastic_company[i],
'size': elastic_size[i]
#'indices': indicesarray
})
output['MongoDb'] = []
for i in range(len(mongodb_array)):
indices=mongodb_indices[i]
indicesarray=indices.split('\n')
indicesarray.pop(0)
output['MongoDb'].append({
'ip': mongodb_array[i],
'company': mongodb_company[i],
'size': mongodb_size[i]
#'indices': indicesarray
})
with open('open_DB.json', 'w') as outfile:
json.dump(output, outfile, indent=4)
def main():
login()
get_elastic()
get_mongodb()
driver.close()
write()
if __name__ == '__main__':
main()