From 90b2b4c77cb2033a61985676c2d465e97930ea33 Mon Sep 17 00:00:00 2001 From: James Lee Date: Thu, 31 Dec 2009 01:27:04 +0000 Subject: [PATCH] fix the db_add* and db_del* commands, make note output readable on 1.8 git-svn-id: file:///home/svn/framework3/trunk@8042 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/core/db.rb | 1 + lib/msf/ui/console/command_dispatcher/db.rb | 30 ++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/msf/core/db.rb b/lib/msf/core/db.rb index bc5427d6be..ca4f8423d7 100644 --- a/lib/msf/core/db.rb +++ b/lib/msf/core/db.rb @@ -270,6 +270,7 @@ class DBManager # Record a service in the database. # # opts must contain + # :host -- the host where this service is running # :port -- the port where this service listens # :proto -- the protocol (e.g. tcp, udp...) # diff --git a/lib/msf/ui/console/command_dispatcher/db.rb b/lib/msf/ui/console/command_dispatcher/db.rb index c0d5d4b86d..b32bdf1776 100644 --- a/lib/msf/ui/console/command_dispatcher/db.rb +++ b/lib/msf/ui/console/command_dispatcher/db.rb @@ -322,13 +322,13 @@ class Db next if(hosts and (note.host == nil or hosts.index(note.host.address) == nil)) next if(types and types.index(note.ntype) == nil) if (note.host and note.service) - print_status("Time: #{note.created} Note: host=#{note.host.address} service=#{note.service.name} type=#{note.ntype} data=#{note.data}") + print_status("Time: #{note.created} Note: host=#{note.host.address} service=#{note.service.name} type=#{note.ntype} data=#{note.data.inspect}") elsif (note.host) - print_status("Time: #{note.created} Note: host=#{note.host.address} type=#{note.ntype} data=#{note.data}") + print_status("Time: #{note.created} Note: host=#{note.host.address} type=#{note.ntype} data=#{note.data.inspect}") elsif (note.service) - print_status("Time: #{note.created} Note: service=#{note.service.name} type=#{note.ntype} data=#{note.data}") + print_status("Time: #{note.created} Note: service=#{note.service.name} type=#{note.ntype} data=#{note.data.inspect}") else - print_status("Time: #{note.created} Note: type=#{note.ntype} data=#{note.data}") + print_status("Time: #{note.created} Note: type=#{note.ntype} data=#{note.data.inspect}") end end end @@ -336,21 +336,27 @@ class Db def cmd_db_add_host(*args) print_status("Adding #{args.length} hosts...") args.each do |address| - host = framework.db.find_or_create_host(address) + host = framework.db.find_or_create_host(:host => address) print_status("Time: #{host.created} Host: host=#{host.address}") end end def cmd_db_add_port(*args) if (not args or args.length < 3) - print_status("Usage: db_add_port [host] [port] [proto]") + print_status("Usage: db_add_port [proto] [name]") return end - host = framework.db.find_or_create_host(args[0]) + host = framework.db.find_or_create_host(:host => args[0]) return if not host + info = { + :host => host, + :port => args[1].to_i + } + info[:proto] = args[2].downcase if args[2] + info[:name] = args[3].downcase if args[3] - service = framework.db.get_service(host, args[2].downcase, args[1].to_i) + service = framework.db.find_or_create_service(info) return if not service print_status("Time: #{service.created} Service: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state}") @@ -362,7 +368,7 @@ class Db return end - if framework.db.del_service(nil, args[0], args[2].downcase, args[1].to_i) + if framework.db.del_service(args[0], args[2].downcase, args[1].to_i) print_status("Service: host=#{args[0]} port=#{args[1].to_i} proto=#{args[2].downcase} deleted") end end @@ -377,10 +383,10 @@ class Db ntype = args.shift ndata = args.join(" ") - host = framework.db.find_or_create_host(naddr) + host = framework.db.find_or_create_host(:host => naddr) return if not host - note = framework.db.find_or_create_note(host, ntype, ndata) + note = framework.db.find_or_create_note(:host => host, :type => ntype, :data => ndata) return if not note print_status("Time: #{note.created} Note: host=#{note.host.address} type=#{note.ntype} data=#{note.data}") @@ -389,7 +395,7 @@ class Db def cmd_db_del_host(*args) args.each do |address| - if framework.db.del_host(nil, address) + if framework.db.del_host(address) print_status("Host #{address} deleted") end end