Skip to content

Commit 3de8beb

Browse files
committed
Clean code
1 parent 7b9b20a commit 3de8beb

File tree

1 file changed

+47
-17
lines changed

1 file changed

+47
-17
lines changed

modules/auxiliary/scanner/elasticsearch/es_enum.rb

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,77 @@ class Metasploit3 < Msf::Auxiliary
1313

1414
def initialize(info = {})
1515
super(update_info(info,
16-
'Name' => 'ElasticSearch Enum Utility',
17-
'Description' => %q{ Send a request to enumerate ElasticSearch indices},
16+
'Name' => 'ElasticSearch Indeces Enumeration Utility',
17+
'Description' => %q{
18+
This module enumerates ElasticSearch Indeces. It uses the REST API
19+
in order to make it.
20+
},
1821
'Author' =>
1922
[
20-
'Silas Cutler <Silas.Cutler [at] BlackListThisDomain.com>'
23+
'Silas Cutler <Silas.Cutler[at]BlackListThisDomain.com>'
2124
],
2225
'License' => MSF_LICENSE
2326
))
24-
27+
2528
register_options(
2629
[
2730
Opt::RPORT(9200)
2831
], self.class)
2932
end
3033

34+
def peer
35+
"#{rhost}:#{rport}"
36+
end
37+
3138
def run_host(ip)
39+
vprint_status("#{peer} - Querying indeces...")
3240
begin
3341
res = send_request_raw({
3442
'uri' => '/_aliases',
3543
'method' => 'GET',
3644
})
37-
38-
begin
39-
json_body = JSON.parse(res.body)
40-
rescue JSON::ParserError
41-
print_error("Unable to parse JSON")
45+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable
46+
vprint_error("#{peer} - Unable to establish connection")
4247
return
4348
end
4449

45-
if res and res.code == 200 and res.body.length > 0
46-
json_body.each do |index|
47-
print_good("Index : " + index[0])
50+
if res && res.code == 200 && res.body.length > 0
51+
begin
52+
json_body = JSON.parse(res.body)
53+
rescue JSON::ParserError
54+
vprint_error("#{peer} - Unable to parse JSON")
55+
return
4856
end
49-
50-
path = store_loot("elasticsearch.enum.file", "text/plain", ip, res.body, "ElasticSearch Enum Results")
51-
print_good("Results saved to #{path}")
5257
else
53-
print_error("Failed to save the result")
58+
vprint_error("#{peer} - Timeout or unexpected response...")
59+
return
5460
end
5561

56-
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable
62+
report_service(
63+
:host => rhost,
64+
:port => rport,
65+
:proto => 'tcp',
66+
:name => 'elasticsearch'
67+
)
68+
69+
indeces = []
70+
71+
json_body.each do |index|
72+
indeces.push(index[0])
73+
report_note(
74+
:host => rhost,
75+
:port => rport,
76+
:proto => 'tcp',
77+
:type => "elasticsearch.index",
78+
:data => index[0],
79+
:update => :unique_data
80+
)
5781
end
82+
83+
if indeces.length > 0
84+
print_good("#{peer} - ElasticSearch Indeces found: #{indeces.join(", ")}")
85+
end
86+
5887
end
88+
5989
end

0 commit comments

Comments
 (0)