Skip to content

Commit 0ca0cd5

Browse files
jabra-todb
authored andcommitted
loot add/remove command for msfconsole
1 parent d8f46e3 commit 0ca0cd5

File tree

1 file changed

+67
-18
lines changed
  • lib/msf/ui/console/command_dispatcher

1 file changed

+67
-18
lines changed

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

Lines changed: 67 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: binary -*-
2-
31
require 'rexml/document'
42
require 'rex/parser/nmap_xml'
53
require 'msf/core/db_export'
@@ -977,6 +975,10 @@ def cmd_notes(*args)
977975
def cmd_loot_help
978976
print_line "Usage: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
979977
print_line
978+
print_line " -a,--add Add a loot to the list of addresses, instead of listing"
979+
print_line " -d,--delete Delete the hosts instead of searching"
980+
print_line " -f --file File with contents of the loot to add"
981+
print_line " -i --info Info of the loot to add"
980982
print_line " -t <type1,type2> Search for a list of types"
981983
print_line " -h,--help Show this help information"
982984
print_line " -S,--search Search string to filter by"
@@ -991,31 +993,52 @@ def cmd_loot(*args)
991993
types = nil
992994
delete_count = 0
993995
search_term = nil
996+
file = nil
997+
name = nil
998+
info = nil
994999

9951000
while (arg = args.shift)
9961001
case arg
997-
when '-d','--delete'
998-
mode = :delete
999-
when '-t'
1000-
typelist = args.shift
1001-
if(!typelist)
1002-
print_status("Invalid type list")
1002+
when '-a','--add'
1003+
mode = :add
1004+
when '-d','--delete'
1005+
mode = :delete
1006+
when '-f','--file'
1007+
filename = args.shift
1008+
if(!filename)
1009+
print_error("Can't make loot with no filename")
1010+
return
1011+
end
1012+
if (!File.exists?(filename) or !File.readable?(filename))
1013+
print_error("Can't read file")
1014+
return
1015+
end
1016+
when '-i','--info'
1017+
info = args.shift
1018+
if(!info)
1019+
print_error("Can't make loot with no info")
10031020
return
10041021
end
1005-
types = typelist.strip().split(",")
1006-
when '-S', '--search'
1007-
search_term = /#{args.shift}/nmi
1008-
when '-h','--help'
1009-
cmd_loot_help
1010-
return
1011-
else
1012-
# Anything that wasn't an option is a host to search for
1013-
unless (arg_host_range(arg, host_ranges))
1022+
when '-t'
1023+
typelist = args.shift
1024+
if(!typelist)
1025+
print_error("Invalid type list")
1026+
return
1027+
end
1028+
types = typelist.strip().split(",")
1029+
when '-S', '--search'
1030+
search_term = /#{args.shift}/nmi
1031+
when '-h','--help'
1032+
cmd_loot_help
1033+
return
1034+
else
1035+
# Anything that wasn't an option is a host to search for
1036+
unless (arg_host_range(arg, host_ranges))
10141037
return
10151038
end
10161039
end
1017-
10181040
end
1041+
10191042
tbl = Rex::Ui::Text::Table.new({
10201043
'Header' => "Loot",
10211044
'Columns' => [ 'host', 'service', 'type', 'name', 'content', 'info', 'path' ],
@@ -1024,6 +1047,32 @@ def cmd_loot(*args)
10241047
# Sentinal value meaning all
10251048
host_ranges.push(nil) if host_ranges.empty?
10261049

1050+
if mode == :add
1051+
if info.nil?
1052+
print_error("Info required")
1053+
return
1054+
end
1055+
if filename.nil?
1056+
print_error("Loot file required")
1057+
return
1058+
end
1059+
if types.nil? or types.size != 1
1060+
print_error("Exactly one note type is required")
1061+
return
1062+
end
1063+
type = types.first
1064+
name = File.basename(filename)
1065+
host_ranges.each do |range|
1066+
range.each do |host|
1067+
file = File.open(filename, "rb")
1068+
contents = file.read
1069+
lootfile = framework.db.find_or_create_loot(:type => type, :host => host,:info => info, :data => contents,:path => filename,:name => name)
1070+
print_status "Added loot #{host}"
1071+
end
1072+
end
1073+
return
1074+
end
1075+
10271076
each_host_range_chunk(host_ranges) do |host_search|
10281077
framework.db.hosts(framework.db.workspace, false, host_search).each do |host|
10291078
host.loots.each do |loot|

0 commit comments

Comments
 (0)