Module: Msf::DBManager::Client
- Included in:
- Msf::DBManager
- Defined in:
- lib/msf/core/db_manager/client.rb
Instance Method Summary collapse
- #find_or_create_client(opts) ⇒ Object
- #get_client(opts) ⇒ Object
-
#report_client(opts) ⇒ Object
Report a client running on a host.
Instance Method Details
#find_or_create_client(opts) ⇒ Object
2 3 4 |
# File 'lib/msf/core/db_manager/client.rb', line 2 def find_or_create_client(opts) report_client(opts) end |
#get_client(opts) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/msf/core/db_manager/client.rb', line 6 def get_client(opts) ::ApplicationRecord.connection_pool.with_connection { opts = opts.clone() # protect the original caller's opts wspace = opts.delete(:workspace) || workspace host = get_host(:workspace => wspace, :host => opts[:host]) || return client = host.clients.where({:ua_string => opts[:ua_string]}).first() return client } end |
#report_client(opts) ⇒ Object
Report a client running on a host.
opts MUST contain
:ua_string
-
the value of the User-Agent header
:host
-
the host where this client connected from, can be an ip address or a Host object
opts can contain
:ua_name
-
one of the Msf::HttpClients constants
:ua_ver
-
detected version of the given client
:campaign
-
an id or Campaign object
Returns a Client.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/msf/core/db_manager/client.rb', line 30 def report_client(opts) return if !active ::ApplicationRecord.connection_pool.with_connection { opts = opts.clone() # protect the original caller's opts addr = opts.delete(:host) || return wspace = opts.delete(:workspace) || workspace report_host(:workspace => wspace, :host => addr) ret = {} host = get_host(:workspace => wspace, :host => addr) client = host.clients.where(ua_string: opts[:ua_string]).first_or_initialize opts[:ua_string] = opts[:ua_string].to_s campaign = opts.delete(:campaign) if campaign case campaign when Campaign opts[:campaign_id] = campaign.id else opts[:campaign_id] = campaign end end opts.each do |k,v| if (client.attribute_names.include?(k.to_s)) client[k] = v elsif !v.blank? dlog("Unknown attribute for Client: #{k}") end end begin framework.events.on_db_client(client) if client.new_record? rescue ::Exception => e wlog("Exception in on_db_client event handler: #{e.class}: #{e}") wlog("Call Stack\n#{e.backtrace.join("\n")}") end if client && client.changed? client.save! end ret[:client] = client } end |