Skip to content

Commit 59bc1a3

Browse files
committed
Remove 'puts' logging and cleanup AWS poc
1 parent be0ca39 commit 59bc1a3

27 files changed

+146
-432
lines changed

lib/metasploit/framework/data_service.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ def name
3333
def active
3434
raise 'DataLService#active is not implemented';
3535
end
36+
37+
class Metadata
38+
attr_reader :id
39+
attr_reader :name
40+
attr_reader :active
41+
42+
def initialize (id, name, active)
43+
self.id = id
44+
self.name = name
45+
self.active = active
46+
end
47+
48+
private
49+
attr_writer :id
50+
attr_writer :name
51+
attr_writer :active
52+
53+
end
54+
3655
end
56+
3757
end
3858
end

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

Lines changed: 29 additions & 33 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,45 +68,43 @@ 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
@@ -119,18 +115,18 @@ def respond_to?(method_name, include_private=false)
119115
#
120116
def exit_called
121117
if @pid
122-
puts 'Killing db process'
118+
ilog 'Shutdown called, attempting to kill db process'
123119
begin
124-
Process.kill("TERM", @pid)
120+
Process.kill('TERM', @pid)
125121
rescue Exception => e
126-
puts "Unable to kill db process: #{e.message}"
122+
elog "Unable to kill db process: #{e.message}"
127123
end
128124
end
129125
end
130126

131127
def get_data_service
132-
raise 'No registered data_service' unless @data_service
133-
return @data_service
128+
raise 'No registered data_service' unless @current_data_service
129+
return @current_data_service
134130
end
135131

136132
#######
@@ -150,7 +146,7 @@ def setup(opts)
150146
@error = 'disabled'
151147
end
152148
rescue Exception => e
153-
puts "Unable to initialize a dataservice #{e.message}"
149+
raise "Unable to initialize a dataservice #{e.message}"
154150
end
155151
end
156152

@@ -176,7 +172,7 @@ def run_remote_db_process(opts)
176172
db_script = File.join( Msf::Config.install_root, "msfdb -ns")
177173
wait_t = Open3.pipeline_start(db_script)
178174
@pid = wait_t[0].pid
179-
puts "Started process with pid #{@pid}"
175+
dlog("Started data service process with pid #{@pid}")
180176

181177
endpoint = URI.parse('http://localhost:8080')
182178
remote_host_data_service = Metasploit::Framework::DataService::RemoteHTTPDataService.new(endpoint)

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 "Call to #{data_service.class}#create_credential threw exception: #{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 "Call to #{data_service.class}#credentials threw exception: #{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 "Call to #{data_service.class}#report_event threw exception: #{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 "Call to #{data_service.class}#report_exploit_attempt threw exception: #{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 "Call to #{data_service.class}#report_exploit_failure threw exception: #{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 "Call to #{data_service.class}#report_exploit_success threw exception: #{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
@@ -9,14 +9,13 @@ def hosts(wspace = workspace, non_dead = false, addresses = nil)
99
opts[:addresses] = addresses
1010
data_service.hosts(opts)
1111
rescue Exception => e
12-
puts "Call to #{data_service.class}#hosts threw exception: #{e.message}"
12+
elog "Call to #{data_service.class}#hosts threw exception: #{e.message}"
1313
end
1414
end
1515

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

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

@@ -37,7 +35,7 @@ def report_hosts(hosts)
3735
data_service = self.get_data_service()
3836
data_service.report_hosts(hosts)
3937
rescue Exception => e
40-
puts "Call to #{data_service.class}#report_hosts threw exception: #{e.message}"
38+
elog "Call to #{data_service.class}#report_hosts threw exception: #{e.message}"
4139
end
4240
end
4341

@@ -46,21 +44,21 @@ def delete_host(opts)
4644
data_service = self.get_data_service()
4745
data_service.delete_host(opts)
4846
rescue Exception => e
49-
puts "Call to #{data_service.class}#delete_host threw exception: #{e.message}"
47+
elog "Call to #{data_service.class}#delete_host threw exception: #{e.message}"
5048
end
5149
end
5250

5351
private
5452

5553
def valid(opts)
5654
unless opts[:host]
57-
puts 'Invalid host hash passed, :host is missing'
55+
ilog 'Invalid host hash passed, :host is missing'
5856
return false
5957
end
6058

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

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 "Call to #{data_service.class}#report_loot threw exception: #{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 "Call to #{data_service.class}#loots threw exception: #{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 "Call to #{data_service.class}#import_nmap_xml_file threw exception: #{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 "Call to #{data_service.class}#report_note threw exception: #{e.message}"
88
end
99
end
1010
end

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

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

0 commit comments

Comments
 (0)