Skip to content

Commit 0a4ab99

Browse files
committed
Land rapid7#5149, couchdb_enum cleanup
2 parents 30d6097 + 4410f8d commit 0a4ab99

File tree

1 file changed

+30
-41
lines changed

1 file changed

+30
-41
lines changed

modules/auxiliary/scanner/couchdb/couchdb_enum.rb

Lines changed: 30 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,70 +14,59 @@ 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 on CouchDB using the REST API
18+
(without authentication by default).
1819
},
19-
'Author' => [ 'espreto <robertoespreto[at]gmail.com>' ],
20+
'References' =>
21+
[
22+
['URL', 'https://wiki.apache.org/couchdb/HTTP_database_API']
23+
],
24+
'Author' => [ 'Roberto Soares Espreto <robertoespreto[at]gmail.com>' ],
2025
'License' => MSF_LICENSE
21-
))
26+
))
2227

2328
register_options(
2429
[
2530
Opt::RPORT(5984),
2631
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'] ]),
2832
OptString.new('USERNAME', [false, 'The username to login as']),
2933
OptString.new('PASSWORD', [false, 'The password to login with'])
3034
], self.class)
31-
end
35+
end
3236

3337
def run
3438
username = datastore['USERNAME']
3539
password = datastore['PASSWORD']
3640

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-
5241
begin
42+
res = send_request_cgi(
43+
'uri' => normalize_uri(target_uri.path),
44+
'method' => 'GET',
45+
'authorization' => basic_auth(username, password)
46+
)
47+
5348
temp = JSON.parse(res.body)
54-
rescue JSON::ParserError
55-
print_error("Unable to parse JSON")
49+
rescue ::Rex::ConnectionRefused, ::Rex::HostUnreachable, JSON::ParserError => e
50+
print_error("#{peer} - The following Error was encountered: #{e.class}")
5651
return
5752
end
5853

59-
results = JSON.pretty_generate(temp)
54+
if res.code == 200 && res.headers['Server'].include?('CouchDB')
55+
print_status('Enumerating...')
56+
results = JSON.pretty_generate(temp)
57+
print_good("Found:\n\n#{results}\n")
6058

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
59+
path = store_loot(
60+
'couchdb.enum',
61+
'text/plain',
62+
rhost,
63+
results,
64+
'CouchDB Enum'
65+
)
7566

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}")
67+
print_good("#{peer} - File saved in: #{path}")
7968
else
80-
print_error("Failed to save the result")
69+
print_error("#{peer} - Unable to enum, received \"#{res.code}\"")
8170
end
8271
end
8372
end

0 commit comments

Comments
 (0)