Skip to content

Commit 000f561

Browse files
committed
Added session data export
1 parent c09796e commit 000f561

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+745
-141
lines changed

lib/metasploit/framework/data_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
require 'metasploit/framework/data_service/stubs/note_data_service'
66
require 'metasploit/framework/data_service/stubs/web_data_service'
77
require 'metasploit/framework/data_service/stubs/service_data_service'
8+
require 'metasploit/framework/data_service/stubs/session_data_service'
9+
require 'metasploit/framework/data_service/stubs/exploit_data_service'
810

911
#
1012
# All data service implementations should include this module to ensure proper implementation
@@ -19,6 +21,8 @@ module DataService
1921
include WebDataService
2022
include NoteDataService
2123
include ServiceDataService
24+
include SessionDataService
25+
include ExploitDataService
2226

2327
def name
2428
raise 'DataLService#name is not implemented';

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ module DataProxyAutoLoader
1010
autoload :WebDataProxy, 'metasploit/framework/data_service/proxy/web_data_proxy'
1111
autoload :WebDataProxy, 'metasploit/framework/data_service/proxy/web_data_proxy'
1212
autoload :ServiceDataProxy, 'metasploit/framework/data_service/proxy/service_data_proxy'
13+
autoload :SessionDataProxy, 'metasploit/framework/data_service/proxy/session_data_proxy'
14+
autoload :ExploitDataProxy, 'metasploit/framework/data_service/proxy/exploit_data_proxy'
1315
include ServiceDataProxy
1416
include HostDataProxy
1517
include VulnDataProxy
1618
include EventDataProxy
1719
include WorkspaceDataProxy
1820
include NoteDataProxy
1921
include WebDataProxy
22+
include SessionDataProxy
23+
include ExploitDataProxy
2024
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module ExploitDataProxy
2+
3+
def report_exploit_attempt(host, opts)
4+
begin
5+
data_service = self.get_data_service()
6+
data_service.report_exploit_attempt(host, opts)
7+
rescue Exception => e
8+
puts"Call to #{data_service.class}#report_exploit_attempt threw exception: #{e.message}"
9+
end
10+
end
11+
12+
def report_exploit_failure(opts)
13+
begin
14+
data_service = self.get_data_service()
15+
data_service.report_exploit_failure(opts)
16+
rescue Exception => e
17+
puts"Call to #{data_service.class}#report_exploit_failure threw exception: #{e.message}"
18+
end
19+
end
20+
21+
def report_exploit_success(opts)
22+
begin
23+
data_service = self.get_data_service()
24+
data_service.report_exploit_success(opts)
25+
rescue Exception => e
26+
puts"Call to #{data_service.class}#report_exploit_success threw exception: #{e.message}"
27+
end
28+
end
29+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module SessionDataProxy
2+
def report_session(opts)
3+
begin
4+
data_service = self.get_data_service()
5+
data_service.report_session(opts)
6+
rescue Exception => e
7+
puts"Call to #{data_service.class}#report_session threw exception: #{e.message}"
8+
end
9+
end
10+
end

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,14 @@ def workspaces
5353
puts"Call to #{data_service.class}#workspaces threw exception: #{e.message}"
5454
end
5555
end
56+
57+
def workspace_associations_counts()
58+
begin
59+
data_service = self.get_data_service()
60+
data_service.workspace_associations_counts()
61+
rescue Exception => e
62+
puts"Call to #{data_service.class}#workspace_associations_counts threw exception: #{e.message}"
63+
end
64+
end
65+
5666
end

lib/metasploit/framework/data_service/remote/http/core.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def initialize(endpoint)
2929
#
3030
# POST data and don't wait for the endpoint to process the data before getting a response
3131
#
32-
def post_data_async(data_hash, path)
33-
post_data(data_hash.merge(EXEC_ASYNC), path)
32+
def post_data_async(path, data_hash)
33+
post_data(path, data_hash.merge(EXEC_ASYNC))
3434
end
3535

3636
#
@@ -41,7 +41,7 @@ def post_data_async(data_hash, path)
4141
#
4242
# @return A wrapped response (ResponseWrapper), see below.
4343
#
44-
def post_data(data_hash, path)
44+
def post_data(path, data_hash)
4545
begin
4646
raise 'Data to post to remote service cannot be null or empty' if (data_hash.nil? or data_hash.empty?)
4747

@@ -57,6 +57,8 @@ def post_data(data_hash, path)
5757
puts "POST request: #{path} with body: #{json_body} failed with code: #{response.code} message: #{response.body}"
5858
return FailedResponse.new(response)
5959
end
60+
rescue Exception => e
61+
puts "Problem with POST request: #{e.message}"
6062
ensure
6163
@client_pool << client
6264
end
@@ -65,12 +67,12 @@ def post_data(data_hash, path)
6567
#
6668
# GET data from the HTTP endpoint
6769
#
68-
# @param data_hash - A hash representation of the object to be posted. Cann be nil or empty.
6970
# @param path - The URI path to post to
71+
# @param data_hash - A hash representation of the object to be posted. Can be nil or empty.
7072
#
7173
# @return A wrapped response (ResponseWrapper), see below.
7274
#
73-
def get_data(data_hash, path)
75+
def get_data(path, data_hash = nil)
7476
begin
7577
client = @client_pool.pop()
7678
request_opts = build_request_opts(GET_REQUEST, data_hash, path)
@@ -84,6 +86,8 @@ def get_data(data_hash, path)
8486
puts "GET request: #{path} failed with code: #{response.code} message: #{response.body}"
8587
return FailedResponse.new(response)
8688
end
89+
rescue Exception => e
90+
puts "Problem with GET request: #{e.message}"
8791
ensure
8892
@client_pool << client
8993
end
@@ -184,7 +188,7 @@ def append_workspace(data_hash)
184188
workspace = data_hash.delete(:wspace)
185189
end
186190

187-
if (workspace and workspace.is_a?(OpenStruct))
191+
if (workspace and (workspace.is_a?(OpenStruct) or workspace.is_a?(::Mdm::Workspace)))
188192
data_hash['workspace'] = workspace.name
189193
end
190194

lib/metasploit/framework/data_service/remote/http/data_service_auto_loader.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ module DataServiceAutoLoader
99
autoload :RemoteVulnDataService, 'metasploit/framework/data_service/remote/http/remote_vuln_data_service'
1010
autoload :RemoteWebDataService, 'metasploit/framework/data_service/remote/http/remote_web_data_service'
1111
autoload :RemoteServiceDataService, 'metasploit/framework/data_service/remote/http/remote_service_data_service'
12+
autoload :RemoteSessionDataService, 'metasploit/framework/data_service/remote/http/remote_session_data_service'
13+
autoload :RemoteExploitDataService, 'metasploit/framework/data_service/remote/http/remote_exploit_data_service'
1214
include RemoteHostDataService
1315
include RemoteEventDataService
1416
include RemoteNoteDataService
1517
include RemoteWorkspaceDataService
1618
include RemoteVulnDataService
1719
include RemoteWebDataService
1820
include RemoteServiceDataService
21+
include RemoteSessionDataService
22+
include RemoteExploitDataService
1923
end

lib/metasploit/framework/data_service/remote/http/remote_event_data_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module RemoteEventDataService
22
EVENT_API_PATH = '/api/1/msf/event'
33

44
def report_event(opts)
5-
self.post_data_async(opts, EVENT_API_PATH)
5+
self.post_data_async(EVENT_API_PATH, opts)
66
end
77
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module RemoteExploitDataService
2+
EXPLOIT_API_PATH = '/api/1/msf/exploit'
3+
4+
def report_exploit_attempt(host, opts)
5+
opts[:host] = host
6+
opts[:exploit_report_type] = "attempt"
7+
self.post_data_async(EXPLOIT_API_PATH, opts)
8+
end
9+
10+
def report_exploit_failure(opts)
11+
opts[:exploit_report_type] = "failure"
12+
self.post_data_async(EXPLOIT_API_PATH, opts)
13+
end
14+
15+
def report_exploit_success(opts)
16+
opts[:exploit_report_type] = "success"
17+
self.post_data_async(EXPLOIT_API_PATH, opts)
18+
end
19+
20+
end

lib/metasploit/framework/data_service/remote/http/remote_host_data_service.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,23 @@ module RemoteHostDataService
77
HOST_SEARCH_PATH = HOST_PATH + "/search"
88

99
def hosts(opts)
10-
json_to_open_struct_object(self.get_data(opts, HOST_PATH), [])
10+
json_to_open_struct_object(self.get_data(HOST_PATH, opts), [])
1111
end
1212

1313
def report_host(opts)
14-
self.post_data_async(opts, HOST_PATH)
14+
self.post_data_async(HOST_PATH, opts)
1515
end
1616

1717
def find_or_create_host(opts)
18-
json_to_open_struct_object(self.post_data(host, HOST_PATH))
18+
json_to_open_struct_object(self.post_data(HOST_PATH, host))
1919
end
2020

2121
def report_hosts(hosts)
22-
self.post_data(hosts, HOST_PATH)
22+
self.post_data(HOST_PATH, hosts)
2323
end
2424

2525
def do_host_search(search)
26-
response = self.post_data(search, HOST_SEARCH_PATH)
26+
response = self.post_data(HOST_SEARCH_PATH, search)
2727
return response.body
2828
end
2929
end

0 commit comments

Comments
 (0)