-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscav.py
More file actions
72 lines (61 loc) · 2.05 KB
/
scav.py
File metadata and controls
72 lines (61 loc) · 2.05 KB
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
#!/usr/bin/python
###
# scav.py
# Search sources for open Elasticsearch instances, and cats the data
# TODO - Add Mongo, S3, Storage Blobs, etc.
import shodan
import requests
import json
API_KEY = "<SHODAN_API_KEY>"
ipList = []
openData = {}
openData['elastic'] = []
###
# searchForData
# The initial collection of data - hosts open on the right ports, and collect their indices
def searchForData(api):
try:
# Search for terms
results_elastic = api.search('product:"Elastic"')
#print(results_elastic)
# Show results
print('Results found: '+str(results_elastic['total']))
for result in results_elastic['matches']:
# Get the IPs
ipList.append(result['ip_str']+':'+str(result['port']))
print("[*] Adding "+result['ip_str']+':'+str(result['port'])+" to the list...")
# Get the 'data' element, which contains a shortlist of indices
# print(result['data'])
# print('')
except shodan.APIError as e:
print('Error: {}'.format(e))
return ipList
###
# accessCheck
# Check if the elasticsearch does not require authentication to query
def accessCheck(ipList):
# Receive the IP List
for ip in ipList:
try:
# GET /_cat/indices and collect the indices
print("[*] Querying http://"+ip+"/_cat/indices")
r = requests.get('http://'+ip+'/_cat/indices', timeout=5)
indices = r.text.split(' ')[2]
# If the request was successful, then add the data to our list of things that we can access
openData['elastic'].append({
'ip': ip,
'indices': indices
})
except Exception as e:
continue
with open('scav-results-elastic.json', 'w') as outfile:
json.dump(openData, outfile)
def main():
# Connect to API
api = shodan.Shodan(API_KEY)
# Search for IP addresses
ipList = searchForData(api)
# Collect Indices based on the IPs
accessCheck(ipList)
if __name__ == "__main__":
main()