Land #1847 - Add sorting functionality to notes command
commit
9466022194
|
@ -853,11 +853,13 @@ class Db
|
||||||
print_line " -t <type1,type2> Search for a list of types"
|
print_line " -t <type1,type2> Search for a list of types"
|
||||||
print_line " -h,--help Show this help information"
|
print_line " -h,--help Show this help information"
|
||||||
print_line " -R,--rhosts Set RHOSTS from the results of the search"
|
print_line " -R,--rhosts Set RHOSTS from the results of the search"
|
||||||
print_line " -S,--search Search string to filter by"
|
print_line " -S,--search Regular expression to match for search"
|
||||||
|
print_line " --sort <field1,field2> Fields to sort by (case sensitive)"
|
||||||
print_line
|
print_line
|
||||||
print_line "Examples:"
|
print_line "Examples:"
|
||||||
print_line " notes --add -t apps -n 'winzip' 10.1.1.34 10.1.20.41"
|
print_line " notes --add -t apps -n 'winzip' 10.1.1.34 10.1.20.41"
|
||||||
print_line " notes -t smb.fingerprint 10.1.1.34 10.1.20.41"
|
print_line " notes -t smb.fingerprint 10.1.1.34 10.1.20.41"
|
||||||
|
print_line " notes -S 'nmap.nse.(http|rtsp)' --sort type,output"
|
||||||
print_line
|
print_line
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -892,10 +894,12 @@ class Db
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
types = typelist.strip().split(",")
|
types = typelist.strip().split(",")
|
||||||
when '-R','--rhosts'
|
when '-R', '--rhosts'
|
||||||
set_rhosts = true
|
set_rhosts = true
|
||||||
when '-S', '--search'
|
when '-S', '--search'
|
||||||
search_term = /#{args.shift}/nmi
|
search_term = /#{args.shift}/nmi
|
||||||
|
when '--sort'
|
||||||
|
sort_term = args.shift
|
||||||
when '-h','--help'
|
when '-h','--help'
|
||||||
cmd_notes_help
|
cmd_notes_help
|
||||||
return
|
return
|
||||||
|
@ -942,6 +946,43 @@ class Db
|
||||||
!n.attribute_names.any? { |a| n[a.intern].to_s.match(search_term) }
|
!n.attribute_names.any? { |a| n[a.intern].to_s.match(search_term) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Sort the notes based on the sort_term provided
|
||||||
|
if sort_term != nil
|
||||||
|
sort_terms = sort_term.split(",")
|
||||||
|
note_list.sort_by! do |note|
|
||||||
|
orderlist = []
|
||||||
|
sort_terms.each do |term|
|
||||||
|
term = "ntype" if term == "type"
|
||||||
|
term = "created_at" if term == "Time"
|
||||||
|
if term == nil
|
||||||
|
orderlist << ""
|
||||||
|
elsif term == "service"
|
||||||
|
if note.service != nil
|
||||||
|
orderlist << make_sortable(note.service.name)
|
||||||
|
end
|
||||||
|
elsif term == "port"
|
||||||
|
if note.service != nil
|
||||||
|
orderlist << make_sortable(note.service.port)
|
||||||
|
end
|
||||||
|
elsif term == "output"
|
||||||
|
orderlist << make_sortable(note.data["output"])
|
||||||
|
elsif note.respond_to?(term)
|
||||||
|
orderlist << make_sortable(note.send(term))
|
||||||
|
elsif note.respond_to?(term.to_sym)
|
||||||
|
orderlist << make_sortable(note.send(term.to_sym))
|
||||||
|
elsif note.respond_to?("data") && note.send("data").respond_to?(term)
|
||||||
|
orderlist << make_sortable(note.send("data").send(term))
|
||||||
|
elsif note.respond_to?("data") && note.send("data").respond_to?(term.to_sym)
|
||||||
|
orderlist << make_sortable(note.send("data").send(term.to_sym))
|
||||||
|
else
|
||||||
|
orderlist << ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
orderlist
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Now display them
|
# Now display them
|
||||||
note_list.each do |note|
|
note_list.each do |note|
|
||||||
next if(types and types.index(note.ntype).nil?)
|
next if(types and types.index(note.ntype).nil?)
|
||||||
|
@ -974,6 +1015,22 @@ class Db
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def make_sortable(input)
|
||||||
|
case input.class
|
||||||
|
when String
|
||||||
|
input = input.downcase
|
||||||
|
when Fixnum
|
||||||
|
input = "%016" % input
|
||||||
|
when Time
|
||||||
|
input = input.strftime("%Y%m%d%H%M%S%L")
|
||||||
|
when NilClass
|
||||||
|
input = ""
|
||||||
|
else
|
||||||
|
input = input.inspect.downcase
|
||||||
|
end
|
||||||
|
input
|
||||||
|
end
|
||||||
|
|
||||||
def cmd_loot_help
|
def cmd_loot_help
|
||||||
print_line "Usage: loot <options>"
|
print_line "Usage: loot <options>"
|
||||||
print_line " Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
|
print_line " Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]"
|
||||||
|
|
Loading…
Reference in New Issue