Skip to content

Commit f176e33

Browse files
authored
Merge pull request #12 from clee-r7/ms-2911
Ms 2911
2 parents 13aa1c6 + 272c5bc commit f176e33

33 files changed

+224
-543
lines changed

lib/metasploit/framework/command/console.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def driver_options
7979
driver_options['DatabaseEnv'] = options.environment
8080
driver_options['DatabaseMigrationPaths'] = options.database.migrations_paths
8181
driver_options['DatabaseYAML'] = options.database.config
82-
driver_options['DatabaseRemoteProcess'] = options.database.remote_process
8382
driver_options['DeferModuleLoads'] = options.modules.defer_loads
8483
driver_options['DisableBanner'] = options.console.quiet
8584
driver_options['DisableDatabase'] = options.database.disable

lib/metasploit/framework/data_service.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,30 @@ def name
3333
def active
3434
raise 'DataLService#active is not implemented';
3535
end
36+
37+
#
38+
# Hold metadata about a data service
39+
#
40+
class Metadata
41+
attr_reader :id
42+
attr_reader :name
43+
attr_reader :active
44+
45+
def initialize (id, name, active)
46+
self.id = id
47+
self.name = name
48+
self.active = active
49+
end
50+
51+
#######
52+
private
53+
#######
54+
55+
attr_writer :id
56+
attr_writer :name
57+
attr_writer :active
58+
59+
end
3660
end
3761
end
3862
end

lib/metasploit/framework/data_service/proxy/core.rb

Lines changed: 25 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def initialize(opts = {})
2828
#
2929
def error
3030
return @error if (@error)
31-
return @data_service.error if @data_service
32-
return "none"
31+
return @current_data_service.error if @current_data_service
32+
return 'none'
3333
end
3434

3535
def is_local?
36-
if (@data_service)
37-
return (@data_service.name == 'local_db_service')
36+
if (@current_data_service)
37+
return (@current_data_service.name == 'local_db_service')
3838
end
3939

4040
return false
@@ -44,8 +44,8 @@ def is_local?
4444
# Determines if the data service is active
4545
#
4646
def active
47-
if (@data_service)
48-
return @data_service.active
47+
if (@current_data_service)
48+
return @current_data_service.active
4949
end
5050

5151
return false
@@ -57,8 +57,6 @@ def active
5757
#
5858
def register_data_service(data_service, online=false)
5959
validate(data_service)
60-
61-
puts "Registering data service: #{data_service.name}"
6260
data_service_id = @data_service_id += 1
6361
@data_services[data_service_id] = data_service
6462
set_data_service(data_service_id, online)
@@ -70,67 +68,51 @@ def register_data_service(data_service, online=false)
7068
def set_data_service(data_service_id, online=false)
7169
data_service = @data_services[data_service_id.to_i]
7270
if (data_service.nil?)
73-
puts "Data service with id: #{data_service_id} does not exist"
74-
return nil
71+
raise "Data service with id: #{data_service_id} does not exist"
7572
end
7673

7774
if (!online && !data_service.active)
78-
puts "Data service not online: #{data_service.name}, not setting as active"
79-
return nil
75+
raise "Data service not online: #{data_service.name}, not setting as active"
8076
end
8177

82-
puts "Setting active data service: #{data_service.name}"
83-
@data_service = data_service
78+
@current_data_service = data_service
8479
end
8580

8681
#
87-
# Prints out a list of the current data services
82+
# Retrieves metadata about the data services
8883
#
89-
def print_data_services()
84+
def get_services_metadata()
85+
services_metadata = []
9086
@data_services.each_key {|key|
91-
out = "id: #{key}, description: #{@data_services[key].name}"
92-
if (!@data_service.nil? && @data_services[key].name == @data_service.name)
93-
out += " [active]"
94-
end
95-
puts out #hahaha
87+
name = @data_services[key].name
88+
active = !@current_data_service.nil? && name == @current_data_service.name
89+
services_metadata << Metasploit::Framework::DataService::Metadata.new(key, name, active)
9690
}
91+
92+
services_metadata
9793
end
9894

9995
#
10096
# Used to bridge the local db
10197
#
10298
def method_missing(method, *args, &block)
103-
#puts "Attempting to delegate method: #{method}"
104-
unless @data_service.nil?
105-
@data_service.send(method, *args, &block)
99+
dlog ("Attempting to delegate method: #{method}")
100+
unless @current_data_service.nil?
101+
@current_data_service.send(method, *args, &block)
106102
end
107103
end
108104

109105
def respond_to?(method_name, include_private=false)
110-
unless @data_service.nil?
111-
return @data_service.respond_to?(method_name, include_private)
106+
unless @current_data_service.nil?
107+
return @current_data_service.respond_to?(method_name, include_private)
112108
end
113109

114110
false
115111
end
116112

117-
#
118-
# Attempt to shutdown the local db process if it exists
119-
#
120-
def exit_called
121-
if @pid
122-
puts 'Killing db process'
123-
begin
124-
Process.kill("TERM", @pid)
125-
rescue Exception => e
126-
puts "Unable to kill db process: #{e.message}"
127-
end
128-
end
129-
end
130-
131113
def get_data_service
132-
raise 'No registered data_service' unless @data_service
133-
return @data_service
114+
raise 'No registered data_service' unless @current_data_service
115+
return @current_data_service
134116
end
135117

136118
#######
@@ -143,14 +125,11 @@ def setup(opts)
143125
if !db_manager.nil?
144126
register_data_service(db_manager, true)
145127
@usable = true
146-
elsif opts['DatabaseRemoteProcess']
147-
run_remote_db_process(opts)
148-
@usable = true
149128
else
150129
@error = 'disabled'
151130
end
152131
rescue Exception => e
153-
puts "Unable to initialize a dataservice #{e.message}"
132+
raise "Unable to initialize data service: #{e.message}"
154133
end
155134
end
156135

@@ -170,19 +149,6 @@ def data_service_exist?(data_service)
170149
return false
171150
end
172151

173-
174-
def run_remote_db_process(opts)
175-
# started with no signal to prevent ctrl-c from taking out db
176-
db_script = File.join( Msf::Config.install_root, "msfdb -ns")
177-
wait_t = Open3.pipeline_start(db_script)
178-
@pid = wait_t[0].pid
179-
puts "Started process with pid #{@pid}"
180-
181-
endpoint = URI.parse('http://localhost:8080')
182-
remote_host_data_service = Metasploit::Framework::DataService::RemoteHTTPDataService.new(endpoint)
183-
register_data_service(remote_host_data_service, true)
184-
end
185-
186152
end
187153
end
188154
end

lib/metasploit/framework/data_service/proxy/credential_data_proxy.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def create_credential(opts)
55
data_service = self.get_data_service()
66
data_service.create_credential(opts)
77
rescue Exception => e
8-
puts "Call to #{data_service.class}#create_credential threw exception: #{e.message}"
8+
elog "Problem creating credential: #{e.message}"
99
end
1010
end
1111

@@ -14,8 +14,7 @@ def creds(opts = {})
1414
data_service = self.get_data_service
1515
data_service.creds(opts)
1616
rescue Exception => e
17-
puts "Call to #{data_service.class}#credentials threw exception: #{e.message}"
18-
e.backtrace.each { |line| puts "#{line}\n" }
17+
elog "Problem retrieving credentials: #{e.message}"
1918
end
2019
end
2120
end

lib/metasploit/framework/data_service/proxy/event_data_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def report_event(opts)
55
data_service = self.get_data_service()
66
data_service.report_event(opts)
77
rescue Exception => e
8-
puts"Call to #{data_service.class}#report_event threw exception: #{e.message}"
8+
elog "Problem reporting event: #{e.message}"
99
end
1010
end
1111

lib/metasploit/framework/data_service/proxy/exploit_data_proxy.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ def report_exploit_attempt(host, opts)
55
data_service = self.get_data_service()
66
data_service.report_exploit_attempt(host, opts)
77
rescue Exception => e
8-
puts"Call to #{data_service.class}#report_exploit_attempt threw exception: #{e.message}"
8+
elog "Problem reporting exploit attempt: #{e.message}"
99
end
1010
end
1111

@@ -14,7 +14,7 @@ def report_exploit_failure(opts)
1414
data_service = self.get_data_service()
1515
data_service.report_exploit_failure(opts)
1616
rescue Exception => e
17-
puts"Call to #{data_service.class}#report_exploit_failure threw exception: #{e.message}"
17+
elog "Problem reporting exploit failure: #{e.message}"
1818
end
1919
end
2020

@@ -23,7 +23,7 @@ def report_exploit_success(opts)
2323
data_service = self.get_data_service()
2424
data_service.report_exploit_success(opts)
2525
rescue Exception => e
26-
puts"Call to #{data_service.class}#report_exploit_success threw exception: #{e.message}"
26+
elog "Problem reporting exploit success: #{e.message}"
2727
end
2828
end
2929
end

lib/metasploit/framework/data_service/proxy/host_data_proxy.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ def hosts(wspace = workspace, non_dead = false, addresses = nil, search_term = n
1010
opts[:search_term] = search_term
1111
data_service.hosts(opts)
1212
rescue Exception => e
13-
puts "Call to #{data_service.class}#hosts threw exception: #{e.message}"
13+
elog "Problem retrieving hosts: #{e.message}"
1414
end
1515
end
1616

1717
# TODO: Shouldn't this proxy to RemoteHostDataService#find_or_create_host ?
1818
# It's currently skipping the "find" part
1919
def find_or_create_host(opts)
20-
puts 'Calling find host'
2120
report_host(opts)
2221
end
2322

@@ -28,8 +27,7 @@ def report_host(opts)
2827
data_service = self.get_data_service()
2928
data_service.report_host(opts)
3029
rescue Exception => e
31-
puts "Call to #{data_service.class}#report_host threw exception: #{e.message}"
32-
opts.each { |k, v| puts "#{k} : #{v}" }
30+
elog "Problem reporting host: #{e.message}"
3331
end
3432
end
3533

@@ -38,7 +36,7 @@ def report_hosts(hosts)
3836
data_service = self.get_data_service()
3937
data_service.report_hosts(hosts)
4038
rescue Exception => e
41-
puts "Call to #{data_service.class}#report_hosts threw exception: #{e.message}"
39+
elog "Problem reporting hosts: #{e.message}"
4240
end
4341
end
4442

@@ -47,21 +45,21 @@ def delete_host(opts)
4745
data_service = self.get_data_service()
4846
data_service.delete_host(opts)
4947
rescue Exception => e
50-
puts "Call to #{data_service.class}#delete_host threw exception: #{e.message}"
48+
elog "Problem removing host: #{e.message}"
5149
end
5250
end
5351

5452
private
5553

5654
def valid(opts)
5755
unless opts[:host]
58-
puts 'Invalid host hash passed, :host is missing'
56+
ilog 'Invalid host hash passed, :host is missing'
5957
return false
6058
end
6159

6260
# Sometimes a host setup through a pivot will see the address as "Remote Pipe"
6361
if opts[:host].eql? "Remote Pipe"
64-
puts "Invalid host hash passed, address was of type 'Remote Pipe'"
62+
ilog "Invalid host hash passed, address was of type 'Remote Pipe'"
6563
return false
6664
end
6765

lib/metasploit/framework/data_service/proxy/loot_data_proxy.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def report_loot(opts)
88
end
99
data_service.report_loot(opts)
1010
rescue Exception => e
11-
puts "Call to #{data_service.class}#report_loot threw exception: #{e.message}"
11+
elog "Problem reporting loot: #{e.message}"
1212
end
1313
end
1414

@@ -18,9 +18,9 @@ def loots(wspace, opts = {})
1818
opts[:wspace] = wspace
1919
data_service.loot(opts)
2020
rescue Exception => e
21-
puts "Call to #{data_service.class}#loots threw exception: #{e.message}"
22-
e.backtrace.each { |line| puts "#{line}\n" }
21+
elog "Problem retrieving loot: #{e.message}"
2322
end
2423
end
24+
2525
alias_method :loot, :loots
2626
end

lib/metasploit/framework/data_service/proxy/nmap_data_proxy.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ def import_nmap_xml_file(args = {})
55
data_service = self.get_data_service()
66
data_service.import_nmap_xml_file(args)
77
rescue Exception => e
8-
puts "Call to #{data_service.class}#import_nmap_xml_file threw exception: #{e.message}"
9-
e.backtrace { |line| puts "#{line}\n"}
8+
elog "Problem importing NMAP XML: #{e.message}"
109
end
1110
end
1211
end

lib/metasploit/framework/data_service/proxy/note_data_proxy.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ def report_note(opts)
44
data_service = self.get_data_service()
55
data_service.report_note(opts)
66
rescue Exception => e
7-
puts"Call to #{data_service.class}#report_note threw exception: #{e.message}"
7+
elog "Problem reporting note: #{e.message}"
88
end
99
end
1010
end

0 commit comments

Comments
 (0)