Skip to content

Loading…

loot add/remove for msfconsole #1586

Closed
wants to merge 4 commits into from

3 participants

@jabra-

Here is an example:

msf exploit(handler) > loot --file /tmp/testing.txt -i Test -t cracked -a 192.168.10.100
[*] Added loot 192.168.10.100
msf exploit(handler) > loot -d 192.168.10.100

Loot

host service type name content info path


192.168.10.100 cracked testing.txt text/plain Test /tmp/testing.txt

[*] Deleted 1 loots
msf exploit(handler) > loot -h
Usage: loot [-h] [addr1 addr2 ...] [-t ]

-a,--add Add a loot to the list of addresses, instead of listing
-d,--delete Delete the hosts instead of searching
-f --file File with contents of the loot to add
-i --info Info of the loot to add
-t Search for a list of types
-h,--help Show this help information
-S,--search Search string to filter by

@todb-r7 todb-r7 commented on an outdated diff
lib/msf/ui/console/command_dispatcher/db.rb
@@ -1,5 +1,3 @@
-# -*- coding: binary -*-
-
@todb-r7
todb-r7 added a note

yeah don't delete this please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@todb-r7

Looks okey from an eyeball standpoint, I'll exercise it later today. Thanks @jasbro !

@jabra-

Thanks Todd!

@jabra-

Updated the pull request based on feedback.

@todb todb Make it clear that you're deleting all loot
You don't get to delete just one chunk of loot.
a5600f3
@todb-r7

@jasbro take a look at that PR and tell me what you think. Otherwise I think we're good. Exposing the add/remove iin msfconsole is definitely worthwhile.

@jabra-
@todb-r7 todb-r7 pushed a commit that closed this pull request
@todb todb Merge branch 'feature/loot-manipulation'
Committed this a little backwards which ended up with a merge conflict.
My bad. This should be all copacetic now.

[Fixes #1586]

Conflicts:
	lib/msf/ui/console/command_dispatcher/db.rb
40e801d
@todb-r7 todb-r7 closed this in 40e801d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 13, 2013
  1. @jabra-
  2. @jabra-

    fixed header

    jabra- committed
  3. @todb

    Make it clear that you're deleting all loot

    todb committed
    You don't get to delete just one chunk of loot.
  4. @jabra-

    Merge pull request #1 from todb-r7/feature/loot-manipulation

    jabra- committed
    Make it clear that you're deleting all loot
Showing with 68 additions and 17 deletions.
  1. +68 −17 lib/msf/ui/console/command_dispatcher/db.rb
View
85 lib/msf/ui/console/command_dispatcher/db.rb
@@ -1,5 +1,5 @@
# -*- coding: binary -*-
-
+#
require 'rexml/document'
require 'rex/parser/nmap_xml'
require 'msf/core/db_export'
@@ -977,6 +977,10 @@ def cmd_notes(*args)
def cmd_loot_help
print_line "Usage: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
print_line
+ print_line " -a,--add Add a loot to the list of addresses, instead of listing"
+ print_line " -d,--delete Delete *all* the loot associated with hosts, instead of searching"
+ print_line " -f --file File with contents of the loot to add"
+ print_line " -i --info Info of the loot to add"
print_line " -t <type1,type2> Search for a list of types"
print_line " -h,--help Show this help information"
print_line " -S,--search Search string to filter by"
@@ -991,31 +995,52 @@ def cmd_loot(*args)
types = nil
delete_count = 0
search_term = nil
+ file = nil
+ name = nil
+ info = nil
while (arg = args.shift)
case arg
- when '-d','--delete'
- mode = :delete
- when '-t'
- typelist = args.shift
- if(!typelist)
- print_status("Invalid type list")
+ when '-a','--add'
+ mode = :add
+ when '-d','--delete'
+ mode = :delete
+ when '-f','--file'
+ filename = args.shift
+ if(!filename)
+ print_error("Can't make loot with no filename")
+ return
+ end
+ if (!File.exists?(filename) or !File.readable?(filename))
+ print_error("Can't read file")
+ return
+ end
+ when '-i','--info'
+ info = args.shift
+ if(!info)
+ print_error("Can't make loot with no info")
return
end
- types = typelist.strip().split(",")
- when '-S', '--search'
- search_term = /#{args.shift}/nmi
- when '-h','--help'
- cmd_loot_help
- return
- else
- # Anything that wasn't an option is a host to search for
- unless (arg_host_range(arg, host_ranges))
+ when '-t'
+ typelist = args.shift
+ if(!typelist)
+ print_error("Invalid type list")
+ return
+ end
+ types = typelist.strip().split(",")
+ when '-S', '--search'
+ search_term = /#{args.shift}/nmi
+ when '-h','--help'
+ cmd_loot_help
+ return
+ else
+ # Anything that wasn't an option is a host to search for
+ unless (arg_host_range(arg, host_ranges))
return
end
end
-
end
+
tbl = Rex::Ui::Text::Table.new({
'Header' => "Loot",
'Columns' => [ 'host', 'service', 'type', 'name', 'content', 'info', 'path' ],
@@ -1024,6 +1049,32 @@ def cmd_loot(*args)
# Sentinal value meaning all
host_ranges.push(nil) if host_ranges.empty?
+ if mode == :add
+ if info.nil?
+ print_error("Info required")
+ return
+ end
+ if filename.nil?
+ print_error("Loot file required")
+ return
+ end
+ if types.nil? or types.size != 1
+ print_error("Exactly one note type is required")
+ return
+ end
+ type = types.first
+ name = File.basename(filename)
+ host_ranges.each do |range|
+ range.each do |host|
+ file = File.open(filename, "rb")
+ contents = file.read
+ lootfile = framework.db.find_or_create_loot(:type => type, :host => host,:info => info, :data => contents,:path => filename,:name => name)
+ print_status "Added loot #{host}"
+ end
+ end
+ return
+ end
+
each_host_range_chunk(host_ranges) do |host_search|
framework.db.hosts(framework.db.workspace, false, host_search).each do |host|
host.loots.each do |loot|
Something went wrong with that request. Please try again.