Skip to content

Commit 6e2503b

Browse files
committed
Add loot update
1 parent 49b88db commit 6e2503b

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ def loots(wspace, opts = {})
2929
end
3030
end
3131
alias_method :loot, :loots
32+
33+
def update_loot(opts)
34+
begin
35+
data_service = self.get_data_service
36+
data_service.update_loot(opts)
37+
rescue Exception => e
38+
puts "Call to #{data_service.class}#update_loot threw exception: #{e.message}"
39+
e.backtrace.each { |line| puts "#{line}\n" }
40+
end
41+
end
3242
end

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ def report_loots(loot)
3131
self.post_data(LOOT_API_PATH, loot)
3232
end
3333

34+
def update_loot(opts)
35+
$stderr.puts "RemoteLootDataService.update_host(): opts = #{opts}" # TODO: remove
36+
path = LOOT_API_PATH
37+
if opts && opts[:id]
38+
id = opts.delete(:id)
39+
path = "#{LOOT_API_PATH}/#{id}"
40+
end
41+
json_to_mdm_object(self.put_data(path, opts), LOOT_MDM_CLASS, [])
42+
end
43+
3444
def delete_loot(opts)
3545
json_to_mdm_object(self.delete_data(LOOT_API_PATH, opts), LOOT_MDM_CLASS, [])
3646
end

lib/msf/core/db_manager/http/servlet/loot_servlet.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ def self.api_path
44
'/api/v1/loots'
55
end
66

7+
def self.api_path_with_id
8+
"#{LootServlet.api_path}/?:id?"
9+
end
10+
711
def self.registered(app)
812
app.get LootServlet.api_path, &get_loot
913
app.post LootServlet.api_path, &report_loot
14+
app.put LootServlet.api_path, &udpate_loot
1015
app.delete LootServlet.api_path, &delete_loot
1116
end
1217

@@ -42,6 +47,18 @@ def self.report_loot
4247
}
4348
end
4449

50+
def self.update_loot
51+
lambda {
52+
begin
53+
opts = parse_json_request(request, false)
54+
data = get_db().delete_loot(opts)
55+
set_json_response(data)
56+
rescue Exception => e
57+
set_error_on_response(e)
58+
end
59+
}
60+
end
61+
4562
def self.delete_loot
4663
lambda {
4764
begin

lib/msf/core/db_manager/loot.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ def report_loot(opts)
9191
}
9292
end
9393

94+
def update_loot(opts)
95+
wspace = opts.delete(:workspace) || opts.delete(:wspace) || workspace
96+
if wspace.kind_of? String
97+
wspace = find_workspace(wspace)
98+
end
99+
100+
::ActiveRecord::Base.connection_pool.with_connection {
101+
id = opts.delete(:id)
102+
Mdm::Loot.update(id, opts)
103+
}
104+
end
105+
94106
# Deletes Loot entries based on the IDs passed in.
95107
#
96108
# @param opts[:ids] [Array] Array containing Integers corresponding to the IDs of the Loot entries to delete.

lib/msf/ui/console/command_dispatcher/db.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,8 @@ def cmd_loot(*args)
13081308
types = typelist.strip().split(",")
13091309
when '-S', '--search'
13101310
search_term = args.shift
1311+
when '-u', '--update'
1312+
mode = :update
13111313
when '-h','--help'
13121314
cmd_loot_help
13131315
return
@@ -1376,6 +1378,17 @@ def cmd_loot(*args)
13761378
# )
13771379
# end
13781380
row = []
1381+
if mode == :update
1382+
begin
1383+
loot.info = info if info
1384+
loot.filename = filename if filename
1385+
loot.ltype = types if types
1386+
framework.db.update_loot(loot.as_json.symbolize_keys)
1387+
rescue Exception => e
1388+
elog "There was an error updating loot with ID #{loot.id}: #{e.message}"
1389+
next
1390+
end
1391+
end
13791392
row.push( ((loot.host && loot.host.address) ? loot.host.address : "") )
13801393
if (loot.service)
13811394
svc = (loot.service.name ? loot.service.name : "#{loot.service.port}/#{loot.service.proto}")

0 commit comments

Comments
 (0)