1
- # -*- coding: binary -*-
2
-
3
1
require 'rexml/document'
4
2
require 'rex/parser/nmap_xml'
5
3
require 'msf/core/db_export'
@@ -977,6 +975,10 @@ def cmd_notes(*args)
977
975
def cmd_loot_help
978
976
print_line "Usage: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
979
977
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"
980
982
print_line " -t <type1,type2> Search for a list of types"
981
983
print_line " -h,--help Show this help information"
982
984
print_line " -S,--search Search string to filter by"
@@ -991,31 +993,52 @@ def cmd_loot(*args)
991
993
types = nil
992
994
delete_count = 0
993
995
search_term = nil
996
+ file = nil
997
+ name = nil
998
+ info = nil
994
999
995
1000
while ( arg = args . shift )
996
1001
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" )
1003
1020
return
1004
1021
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 ) )
1014
1037
return
1015
1038
end
1016
1039
end
1017
-
1018
1040
end
1041
+
1019
1042
tbl = Rex ::Ui ::Text ::Table . new ( {
1020
1043
'Header' => "Loot" ,
1021
1044
'Columns' => [ 'host' , 'service' , 'type' , 'name' , 'content' , 'info' , 'path' ] ,
@@ -1024,6 +1047,32 @@ def cmd_loot(*args)
1024
1047
# Sentinal value meaning all
1025
1048
host_ranges . push ( nil ) if host_ranges . empty?
1026
1049
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
+
1027
1076
each_host_range_chunk ( host_ranges ) do |host_search |
1028
1077
framework . db . hosts ( framework . db . workspace , false , host_search ) . each do |host |
1029
1078
host . loots . each do |loot |
0 commit comments