@@ -14,70 +14,59 @@ def initialize(info = {})
14
14
super ( update_info ( info ,
15
15
'Name' => 'CouchDB Enum Utility' ,
16
16
'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).
18
19
} ,
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>' ] ,
20
25
'License' => MSF_LICENSE
21
- ) )
26
+ ) )
22
27
23
28
register_options (
24
29
[
25
30
Opt ::RPORT ( 5984 ) ,
26
31
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' ] ] ) ,
28
32
OptString . new ( 'USERNAME' , [ false , 'The username to login as' ] ) ,
29
33
OptString . new ( 'PASSWORD' , [ false , 'The password to login with' ] )
30
34
] , self . class )
31
- end
35
+ end
32
36
33
37
def run
34
38
username = datastore [ 'USERNAME' ]
35
39
password = datastore [ 'PASSWORD' ]
36
40
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
-
52
41
begin
42
+ res = send_request_cgi (
43
+ 'uri' => normalize_uri ( target_uri . path ) ,
44
+ 'method' => 'GET' ,
45
+ 'authorization' => basic_auth ( username , password )
46
+ )
47
+
53
48
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 } " )
56
51
return
57
52
end
58
53
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 " )
60
58
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
+ )
75
66
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 } " )
79
68
else
80
- print_error ( "Failed to save the result " )
69
+ print_error ( "#{ peer } - Unable to enum, received \" #{ res . code } \" " )
81
70
end
82
71
end
83
72
end
0 commit comments