Skip to content

Commit 1d63009

Browse files
committed
Clean the code of the module couchdb_enum.
1 parent b5ae3fd commit 1d63009

File tree

1 file changed

+31
-40
lines changed

1 file changed

+31
-40
lines changed

modules/auxiliary/scanner/couchdb/couchdb_enum.rb

Lines changed: 31 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,61 @@ def initialize(info = {})
1414
super(update_info(info,
1515
'Name' => 'CouchDB Enum Utility',
1616
'Description' => %q{
17-
Send a "send_request_cgi()" to enumerate databases and your values on CouchDB (Without authentication by default)
17+
This module enumerates databases and your values on CouchDB
18+
(without authentication by default). It uses the REST API
19+
in order to make it.
1820
},
19-
'Author' => [ 'espreto <robertoespreto[at]gmail.com>' ],
21+
'References' =>
22+
[
23+
['URL', 'https://wiki.apache.org/couchdb/HTTP_database_API']
24+
],
25+
'Author' => [ 'Roberto Soares Espreto <robertoespreto[at]gmail.com>' ],
2026
'License' => MSF_LICENSE
2127
))
2228

2329
register_options(
2430
[
2531
Opt::RPORT(5984),
2632
OptString.new('TARGETURI', [true, 'Path to list all the databases', '/_all_dbs']),
27-
OptEnum.new('HTTP_METHOD', [true, 'HTTP Method, default GET', 'GET', ['GET', 'POST', 'PUT', 'DELETE'] ]),
2833
OptString.new('USERNAME', [false, 'The username to login as']),
2934
OptString.new('PASSWORD', [false, 'The password to login with'])
3035
], self.class)
31-
end
36+
end
3237

3338
def run
3439
username = datastore['USERNAME']
3540
password = datastore['PASSWORD']
3641

37-
uri = normalize_uri(target_uri.path)
38-
res = send_request_cgi({
39-
'uri' => uri,
40-
'method' => datastore['HTTP_METHOD'],
41-
'authorization' => basic_auth(username, password),
42-
'headers' => {
43-
'Cookie' => 'Whatever?'
44-
}
45-
})
46-
47-
if res.nil?
48-
print_error("No response for #{target_host}")
49-
return nil
50-
end
51-
5242
begin
43+
res = send_request_cgi({
44+
'uri' => normalize_uri(target_uri.path),
45+
'method' => 'GET',
46+
'authorization' => basic_auth(username, password)
47+
})
48+
5349
temp = JSON.parse(res.body)
54-
rescue JSON::ParserError
55-
print_error("Unable to parse JSON")
50+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, JSON::ParserError => e
51+
print_error("#{peer} - The following Error was encountered: #{e.class}")
5652
return
5753
end
5854

59-
results = JSON.pretty_generate(temp)
55+
if res.code == 200 && res.headers['Server'] =~ /CouchDB/
6056

61-
if (res.code == 200)
62-
print_good("#{target_host}:#{rport} -> #{res.code}")
63-
print_good("Response Headers:\n\n #{res.headers}")
64-
print_good("Response Body:\n\n #{results}\n")
65-
elsif (res.code == 403) # Forbidden
66-
print_error("Received #{res.code} - Forbidden to #{target_host}:#{rport}")
67-
print_error("Response from server:\n\n #{results}\n")
68-
elsif (res.code == 404) # Not Found
69-
print_error("Received #{res.code} - Not Found to #{target_host}:#{rport}")
70-
print_error("Response from server:\n\n #{results}\n")
71-
else
72-
print_status("Received #{res.code}")
73-
print_line("#{results}")
74-
end
57+
print_status('Enumerating...')
58+
results = JSON.pretty_generate(temp)
59+
print_good("Found:\n\n#{results}\n")
60+
61+
path = store_loot(
62+
'couchdb.enum',
63+
'text/plain',
64+
rhost,
65+
results,
66+
'CouchDB Enum'
67+
)
7568

76-
if res and res.code == 200 and res.headers['Content-Type'] and res.body.length > 0
77-
path = store_loot("couchdb.enum.file", "text/plain", rhost, res.body, "CouchDB Enum Results")
78-
print_status("Results saved to #{path}")
69+
print_good("#{peer} - File saved in: #{path}")
7970
else
80-
print_error("Failed to save the result")
71+
print_error("#{peer} - Unable to enum, received \"#{res.code}\"")
8172
end
8273
end
8374
end

0 commit comments

Comments
 (0)