-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land #19, externalize db_export command
- Loading branch information
Showing
11 changed files
with
137 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
lib/metasploit/framework/data_service/proxy/db_export_data_proxy.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module DbExportDataProxy | ||
def run_db_export(path, format) | ||
begin | ||
data_service = self.get_data_service | ||
opts = { | ||
path: path, | ||
format: format | ||
} | ||
data_service.run_db_export(opts) | ||
rescue Exception => e | ||
self.log_error(e, "Problem generating DB Export") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/metasploit/framework/data_service/remote/http/remote_db_export_data_service.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'metasploit/framework/data_service/remote/http/response_data_helper' | ||
|
||
module RemoteDbExportDataService | ||
include ResponseDataHelper | ||
|
||
DB_EXPORT_API_PATH = '/api/v1/db-export' | ||
|
||
def run_db_export(opts) | ||
response = json_to_hash(self.get_data(DB_EXPORT_API_PATH, nil, opts)) | ||
|
||
process_file(response[:db_export_file], opts[:path]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'msf/core/db_export' | ||
|
||
module Msf::DBManager::DbExport | ||
def run_db_export(opts) | ||
exporter = Msf::DBManager::Export.new(framework.db.workspace) | ||
|
||
output_file = exporter.send("to_#{opts[:format]}_file".intern, opts[:path]) do |mtype, mstatus, mname| | ||
if mtype == :status | ||
if mstatus == Msf::DBManager::Export::STATUS_START | ||
ilog " >> Starting export of #{mname}" | ||
end | ||
if mstatus == Msf::DBManager::Export::STATUS_COMPLETE | ||
ilog " >> Finished export of #{mname}" | ||
end | ||
end | ||
end | ||
|
||
File.expand_path(output_file) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module DbExportServlet | ||
|
||
def self.api_path | ||
'/api/v1/db-export' | ||
end | ||
|
||
def self.registered(app) | ||
app.get DbExportServlet.api_path, &get_db_export | ||
end | ||
|
||
####### | ||
private | ||
####### | ||
|
||
def self.get_db_export | ||
lambda { | ||
begin | ||
opts = params.symbolize_keys | ||
opts[:path] = File.join(Msf::Config.local_directory, "#{File.basename(opts[:path])}-#{SecureRandom.hex}") | ||
|
||
output_file = get_db.run_db_export(opts) | ||
|
||
encoded_file = Base64.urlsafe_encode64(File.read(File.expand_path(output_file))) | ||
response = {} | ||
response[:db_export_file] = encoded_file | ||
set_json_response(response) | ||
rescue Exception => e | ||
set_error_on_response(e) | ||
ensure | ||
# Ensure the temporary file gets cleaned up | ||
File.delete(opts[:path]) | ||
end | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters