Skip to content

Commit 56e95f1

Browse files
committed
Land rapid7#9024, fix bug when manually adding loot
cmd_loot was throwing a stack trace when the host was not properly defined. This fixes it to give a useful error message.
2 parents d9e0d89 + 5b9a4d7 commit 56e95f1

File tree

2 files changed

+32
-28
lines changed
  • lib/msf/ui/console/command_dispatcher
  • spec/lib/msf/ui/console/command_dispatcher

2 files changed

+32
-28
lines changed

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

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ def cmd_hosts(*args)
479479
'SortIndex' => order_by
480480
})
481481

482-
# Sentinal value meaning all
482+
# Sentinel value meaning all
483483
host_ranges.push(nil) if host_ranges.empty?
484484

485485
case
@@ -717,7 +717,7 @@ def cmd_services(*args)
717717
'SortIndex' => order_by
718718
})
719719

720-
# Sentinal value meaning all
720+
# Sentinel value meaning all
721721
host_ranges.push(nil) if host_ranges.empty?
722722
ports = nil if ports.empty?
723723

@@ -1115,7 +1115,7 @@ def make_sortable(input)
11151115
def cmd_loot_help
11161116
print_line "Usage: loot <options>"
11171117
print_line " Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
1118-
print_line " Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] [-t [type]"
1118+
print_line " Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] -t [type]"
11191119
print_line " Del: loot -d [addr1 addr2 ...]"
11201120
print_line
11211121
print_line " -a,--add Add loot to the list of addresses, instead of listing"
@@ -1187,34 +1187,38 @@ def cmd_loot(*args)
11871187
'Columns' => [ 'host', 'service', 'type', 'name', 'content', 'info', 'path' ],
11881188
})
11891189

1190-
# Sentinal value meaning all
1190+
# Sentinel value meaning all
11911191
host_ranges.push(nil) if host_ranges.empty?
11921192

1193-
if mode == :add
1194-
if info.nil?
1195-
print_error("Info required")
1196-
return
1197-
end
1198-
if filename.nil?
1199-
print_error("Loot file required")
1200-
return
1201-
end
1202-
if types.nil? or types.size != 1
1203-
print_error("Exactly one loot type is required")
1204-
return
1205-
end
1206-
type = types.first
1207-
name = File.basename(filename)
1208-
host_ranges.each do |range|
1209-
range.each do |host|
1210-
file = File.open(filename, "rb")
1211-
contents = file.read
1212-
lootfile = framework.db.find_or_create_loot(:type => type, :host => host, :info => info, :data => contents, :path => filename, :name => name)
1213-
print_status("Added loot for #{host} (#{lootfile})")
1193+
if mode == :add
1194+
if host_ranges.compact.empty?
1195+
print_error('Address list required')
1196+
return
1197+
end
1198+
if info.nil?
1199+
print_error("Info required")
1200+
return
12141201
end
1202+
if filename.nil?
1203+
print_error("Loot file required")
1204+
return
1205+
end
1206+
if types.nil? or types.size != 1
1207+
print_error("Exactly one loot type is required")
1208+
return
1209+
end
1210+
type = types.first
1211+
name = File.basename(filename)
1212+
file = File.open(filename, "rb")
1213+
contents = file.read
1214+
host_ranges.each do |range|
1215+
range.each do |host|
1216+
lootfile = framework.db.find_or_create_loot(:type => type, :host => host, :info => info, :data => contents, :path => filename, :name => name)
1217+
print_status("Added loot for #{host} (#{lootfile})")
1218+
end
1219+
end
1220+
return
12151221
end
1216-
return
1217-
end
12181222

12191223
each_host_range_chunk(host_ranges) do |host_search|
12201224
framework.db.hosts(framework.db.workspace, false, host_search).each do |host|

spec/lib/msf/ui/console/command_dispatcher/db_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
expect(@output).to match_array [
149149
"Usage: loot <options>",
150150
" Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]",
151-
" Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] [-t [type]",
151+
" Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] -t [type]",
152152
" Del: loot -d [addr1 addr2 ...]",
153153
" -a,--add Add loot to the list of addresses, instead of listing",
154154
" -d,--delete Delete *all* loot matching host and type",

0 commit comments

Comments
 (0)