Class: Msf::RPC::RPC_Db

Inherits:
RPC_Base show all
Includes:
Metasploit::Credential::Creation
Defined in:
lib/msf/core/rpc/v10/rpc_db.rb

Instance Attribute Summary

Attributes inherited from RPC_Base

#framework, #job_status_tracker, #service, #tokens, #users

Instance Method Summary collapse

Methods inherited from RPC_Base

#error, #initialize

Constructor Details

This class inherits a constructor from Msf::RPC::RPC_Base

Instance Method Details

#rpc_add_workspace(wspace) ⇒ Hash

Adds a new workspace.

Examples:

Here's how you would use this from the client:

* rpc.call('db.add_workspace', 'my_new_workspace')

Parameters:

  • wspace (String)

    Workspace name.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. You get:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



719
720
721
722
723
724
725
726
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 719

def rpc_add_workspace(wspace)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  wspace = self.framework.db.add_workspace(wspace)
  return { 'result' => 'success' } if wspace
  { 'result' => 'failed' }
}
end

#rpc_analyze_host(xopts) ⇒ Hash

Returns analysis of module suggestions for known data about a host.

  • Array<String>

    :payloads Modules returned will be compatible with at least one payload

Examples:

Here's how you would use this from the client:

rpc.call('db.analyze_host', {:workspace => 'default', :host => ip})

Parameters:

  • xopts (Hash)

    Options (:addr, :address, :host are the same thing, and you only need one):

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :addr (String)

    Host address.

  • :address (String)

    Same as :addr.

  • :host (String)

    Same as :address.

  • :analyze_options (Map<String, Object>)

    All returned modules will support these options

Returns:

  • (Hash)

    A hash that contains the following:

    • 'host' [Array<Hash>] Each hash in the array contains the following:

      • 'address' [String] Address.

      • 'modules' [Array<Hash>] Each hash in the array modules contains the following:

        • 'mtype' [String] Module type.

        • 'mname' [String] Module name. For example: 'windows/wlan/wlan_profile'

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 805

def rpc_analyze_host(xopts)
  ::ApplicationRecord.connection_pool.with_connection {
    _opts, _wspace = init_db_opts_workspace(xopts)
    ret = {
      host: {}
    }
    opts = fix_options(xopts)
    opts.deep_symbolize_keys!
    host = self.framework.db.get_host(opts)
    # consider expanding to support a list of hosts?
    return ret unless host

    # as a consumer options should be a filter object not a top level param
    analyze_options = {}
    analyze_options = opts[:analyze_options] if opts[:analyze_options]
    analyze_result = self.framework.analyze.host(host, **analyze_options)
    # this should just serialize the result as hosts details why did it end up limited?
    module_suggestions = analyze_result[:results].sort_by { |result| result.mod.fullname }
    host_detail = {
      address: host.address,
      modules: module_suggestions.map do |result|
        mod = result.mod
        {
          mtype: mod.type,
          mname: mod.fullname,
          state: result.state,
          description: result.description,
          options: {
            invalid: result.invalid,
            missing: result.missing
          }
        }
      end
    }
    ret[:host] = host_detail
    ret
  }
end

#rpc_clients(xopts) ⇒ Hash

Returns browser clients information.

Examples:

Here's how you would use this from the client:

rpc.call('db.clients', {})

Parameters:

  • xopts (Hash)

    Filters that narrow down the search.

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :ua_name (String)

    User-Agent name.

  • :ua_ver (String)

    Browser version.

  • :addresses (Array)

    Addresses.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'clients' [Array<Hash>] Each hash in the array that contains the following:

    • 'host' [String] Host address.

    • 'ua_string' [String] User-agent string.

    • 'ua_name' [String] Browser name.

    • 'ua_ver' [String] Browser version.

    • 'created_at' [Integer] Creation date.

    • 'updated_at' [Integer] Last updated at.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1806

def rpc_clients(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  conditions = {}
  conditions[:ua_name] = opts[:ua_name] if opts[:ua_name]
  conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver]
  conditions["hosts.address"] = opts[:addresses] if opts[:addresses]

  ret = {}
  ret[:clients] = []

  wspace.clients.includes(:host).where(conditions).offset(offset).limit(limit).each do |c|
    client = {}
    client[:host] = c.host.address.to_s if c.host
    client[:ua_string] = c.ua_string
    client[:ua_name] = c.ua_name
    client[:ua_ver] = c.ua_ver
    client[:created_at] = c.created_at.to_i
    client[:updated_at] = c.updated_at.to_i
    ret[:clients] << client
  end
  ret
}
end

#rpc_connect(xopts) ⇒ Hash

Connects to the database.

This must contain :driver and driver specific options.

Examples:

Here's how you would use this from the client:

rpc.call('db.connect', {:driver=>'postgresql', :host => db_host, :port => db_port, :database => db_name, :username => db_username, :password=> db_password})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :driver (String)

    Driver name. For example: 'postgresql'.

Returns:

  • (Hash)

    A hash that indicates whether the action was successful or not.

    • 'result' [String] A message that says either 'success' or 'failed'.



1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1938

def rpc_connect(xopts)
  opts = fix_options(xopts)
  if not self.framework.db.driver and not opts[:driver]
    return { :result => 'failed' }
  end

  if opts[:driver]
    if self.framework.db.drivers.include?(opts[:driver])
      self.framework.db.driver = opts[:driver]
    else
      return { :result => 'failed' }
    end
  end

  driver = self.framework.db.driver

  case driver
  when 'postgresql'
    opts['adapter'] = 'postgresql'
  else
    return { :result => 'failed' }
  end

  if (not self.framework.db.connect(opts))
    return { :result => 'failed' }
  end
  return { :result => 'success' }

end

#rpc_create_cracked_credential(xopts) ⇒ Metasploit::Credential::Core

Creates a cracked credential.

Examples:

Here's how you would use this from the client:

opts = {
  username: username,
  password: password,
  core_id: core_id
}
rpc.call('db.create_cracked_credential', opts)

Parameters:

  • xopts (Hash)

    Credential options. (See #create_credential Documentation)

Returns:

  • (Metasploit::Credential::Core)

See Also:



156
157
158
159
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 156

def rpc_create_cracked_credential(xopts)
  opts = fix_cred_options(xopts)
  create_cracked_credential(opts)
end

#rpc_create_credential(xopts) ⇒ Hash

Creates a credential.

Examples:

Here's how you would use this from the client:

opts = {
 origin_type: :service,
 address: '192.168.1.100',
 port: 445,
 service_name: 'smb',
 protocol: 'tcp',
 module_fullname: 'auxiliary/scanner/smb/smb_login',
 workspace_id: myworkspace_id,
 private_data: 'password1',
 private_type: :password,
 username: 'Administrator'
}
rpc.call('db.create_cracked_credential', opts)

Parameters:

  • xopts (Hash)

    Credential options. (See #create_credential Documentation)

Returns:

  • (Hash)

    Credential data. It contains the following keys:

    • 'username' [String] Username saved.

    • 'private' [String] Password saved.

    • 'private_type' [String] Password type.

    • 'realm_value' [String] Realm.

    • 'realm_key' [String] Realm key.

    • 'host' [String] Host (Only available if there's a :last_attempted_at and :status)

    • 'sname' [String] Service name (only available if there's a :last_attempted_at and :status)

    • 'status' [Status] Login status (only available if there's a :last_attempted_at and :status)

See Also:



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 189

def rpc_create_credential(xopts)
  opts = fix_cred_options(xopts)
  core = create_credential(opts)

  ret = {
      username: core.public.try(:username),
      private: core.private.try(:data),
      private_type: core.private.try(:type),
      realm_value: core.realm.try(:value),
      realm_key: core.realm.try(:key)
  }

  if opts[:last_attempted_at] && opts[:status]
    opts[:core] = core
    opts[:last_attempted_at] = opts[:last_attempted_at].to_datetime
     = (opts)

    ret[:host]   = .service.host.address,
    ret[:sname]  = .service.name
    ret[:status] = .status
  end
  ret
end

#rpc_creds(xopts) ⇒ Hash

Returns login credentials from a specific workspace.

Examples:

Here's how you would use this from the client:

rpc.call('db.creds', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

Returns:

  • (Hash)

    Credentials with the following hash key:

    • 'creds' [Array<Hash>] An array of credentials. Each hash in the array will have the following:

      • 'user' [String] Username.

      • 'pass' [String] Password.

      • 'updated_at' [Integer] Last updated at.

      • 'type' [String] Password type.

      • 'host' [String] Host.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'sname' [String] Service name.

      • 'realm_key' [String] Realm key type.

      • 'realm_value' [String] Realm value.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 259

def rpc_creds(xopts)
  ::ApplicationRecord.connection_pool.with_connection {
    ret = {}
    ret[:creds] = []
    opts, wspace = init_db_opts_workspace(xopts)
    limit = opts.delete(:limit) || 100
    offset = opts.delete(:offset) || 0
    query = Metasploit::Credential::Core.where(
      workspace_id: wspace
    ).offset(offset).limit(limit)
    query.each do |cred|
      host = ''
      port = 0
      proto = ''
      sname = ''

      unless cred.logins.empty?
         = cred.logins.first
        host = .service.host.address.to_s
        sname = .service.name.to_s if .service.name.present?
        port = .service.port.to_i
        proto = .service.proto.to_s
      end

      updated_at = nil
      pass = nil
      type = nil

      unless cred.private.nil?
        updated_at = cred.private.updated_at.to_i
        pass = cred.private.data.to_s
        type = cred.private.type.to_s
      else
        updated_at = cred.public.updated_at.to_i
      end

      ret[:creds] << {
        :user => cred.public.username.to_s,
        :pass => pass,
        :updated_at => updated_at,
        :type => type,
        :host => host,
        :port => port,
        :proto => proto,
        :sname => sname,
        :realm_key => cred.realm.try(:key),
        :realm_value => cred.realm.try(:value)
      }
    end
    ret
  }
end

#rpc_current_workspaceHash

Returns the current workspace.

Examples:

Here's how you would use this from the client:

rpc.call('db.current_workspace')

Returns:

  • (Hash)

    A hash with the following keys:

    • 'workspace' [String] Workspace name.

    • 'workspace_id' [Integer] Workspace ID.

Raises:



613
614
615
616
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 613

def rpc_current_workspace
  db_check
  { "workspace" => self.framework.db.workspace.name, "workspace_id" => self.framework.db.workspace.id }
end

#rpc_del_client(xopts) ⇒ Hash

Deletes browser information from a client.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_client', {})

Parameters:

  • xopts (Hash)

    Filters that narrow down what to delete.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :addresses (Array)

    Same as :address.

  • :ua_name (String)

    Browser name.

  • :ua_ver (String)

    Browser version.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success'.

    • 'deleted' [Array<Hash>] Each hash in the array contains the following:

      • 'address' [String] Host address.

      • 'ua_string' [String] User-Agent string.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1855

def rpc_del_client(xopts)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  opts = fix_options(xopts)
  wspace = find_workspace(opts[:workspace])
  hosts = []
  clients = []

  if opts[:host] or opts[:address] or opts[:addresses]
    hosts = opts_to_hosts(xopts)
  else
    hosts = wspace.hosts
  end

  hosts.each do |h|
    cret = nil
    if opts[:ua_name] or opts[:ua_ver]
      conditions = {}
      conditions[:ua_name] = opts[:ua_name] if opts[:ua_name]
      conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver]
      cret = h.clients.where(conditions)
    else
      cret = h.clients
    end
    next if cret == nil
    clients << cret if cret.class == ::Mdm::Client
    clients |= cret if cret.class == Array
  end

  deleted = []
  clients.each do |c|
    dent = {}
    dent[:address] = c.host.address.to_s
    dent[:ua_string] = c.ua_string
    deleted << dent
    c.destroy
  end

  { :result => 'success', :deleted => deleted }
}
end

#rpc_del_creds(xopts) ⇒ Hash

Delete credentials from a specific workspace.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_creds', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

Returns:

  • (Hash)

    Credentials with the following hash key:

    • 'result' [String] A message that says 'success'.

    • 'deleted' [Array<Hash>] An array of credentials. Each hash in the array will have the following:

      • 'user' [String] Username.

      • 'pass' [String] Password.

      • 'updated_at' [Integer] Last updated at.

      • 'type' [String] Password type.

      • 'host' [String] Host.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'sname' [String] Service name.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 334

def rpc_del_creds(xopts)
  ::ApplicationRecord.connection_pool.with_connection {
    deleted = []
    ret = {}
    ret[:creds] = []
    opts, wspace = init_db_opts_workspace(xopts)
    limit = opts.delete(:limit) || 100
    offset = opts.delete(:offset) || 0
    query = Metasploit::Credential::Core.where(
      workspace_id: wspace
    ).offset(offset).limit(limit)
    query.each do |cred|
      host = ''
      port = 0
      proto = ''
      sname = ''
      unless cred.logins.empty?
         = cred.logins.first
        host = .service.host.address.to_s
        sname = .service.name.to_s if .service.name.present?
        port = .service.port.to_i
        proto = .service.proto.to_s
      end
      ret[:creds] << {
              :user => cred.public.username.to_s,
              :pass => cred.private.data.to_s,
              :updated_at => cred.private.updated_at.to_i,
              :type => cred.private.type.to_s,
              :host => host,
              :port => port,
              :proto => proto,
              :sname => sname}
      deleted << ret
      cred.destroy
    end
    return { :result => 'success', :deleted => deleted }
  }
end

#rpc_del_host(xopts) ⇒ Hash

Deletes hosts.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_host', {:host=>ip})

Parameters:

  • xopts (Hash)

    Filters to narrow down which hosts to delete.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :addresses (Array)

    Host addresses.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success'.

    • 'deleted' [Array<String>] All the deleted hosts.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1442

def rpc_del_host(xopts)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  opts = fix_options(xopts)
  wspace = find_workspace(opts[:workspace])
  hosts  = []
  if opts[:host] or opts[:address]
    host = opts[:host] || opts[:address]
    hent = wspace.hosts.find_by_address(host)
    return { :result => 'failed' } if hent == nil or hent.class != ::Mdm::Host
    hosts << hent
  elsif opts[:addresses]
    return { :result => 'failed' } if opts[:addresses].class != Array
    conditions = { :address => opts[:addresses] }
    hent = wspace.hosts.where(conditions)
    return { :result => 'failed' } if hent == nil
    hosts |= hent if hent.class == Array
    hosts << hent if hent.class == ::Mdm::Host
  end
  deleted = []
  hosts.each do |h|
    deleted << h.address.to_s
    h.destroy
  end

  return { :result => 'success', :deleted => deleted }
}
end

#rpc_del_note(xopts) ⇒ Hash

Deletes notes.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_note', {:workspace=>'default', :host=>ip, :port=>443, :proto=>'tcp'})

Parameters:

  • xopts (Hash)

    Filters to narrow down which notes to delete.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :addresses (Array)

    Same as :address.

  • :port (Integer)

    Port.

  • :proto (String)

    Protocol.

  • :ntype (String)

    Note type.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success'.

    • 'deleted' [Array<Hash>] Each hash in the array contains the following:

      • 'address' [String] Host address.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'ntype' [String] Note type.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1329

def rpc_del_note(xopts)
  notes = get_notes(xopts)

  deleted = []
  notes.each do |n|
    dent = {}
    dent[:address] = n.host.address.to_s if n.host
    dent[:port] = n.service.port if n.service
    dent[:proto] = n.service.proto if n.service
    dent[:ntype] = n.ntype
    deleted << dent
    n.destroy
  end

  return { :result => 'success', :deleted => deleted }
end

#rpc_del_service(xopts) ⇒ Hash

Deletes services.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_service', {:host=>ip})

Parameters:

  • xopts (Hash)

    Filters to narrow down which services to delete.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :addresses (Array)

    Host addresses.

  • :port (Integer)

    Port.

  • :proto (String)

    Protocol.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success' or 'failed'.

    • 'deleted' [Array<Hash>] If result says success, then you will get this key. Each hash in the array contains:

      • 'address' [String] Host address.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1369

def rpc_del_service(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  hosts  = []
  services = []
  if opts[:host] or opts[:address]
    host = opts[:host] || opts[:address]
    hent = wspace.hosts.find_by_address(host)
    return { :result => 'failed' } if hent == nil or hent.class != ::Mdm::Host
    hosts << hent
  elsif opts[:addresses]
    return { :result => 'failed' } if opts[:addresses].class != Array
    conditions = { :address => opts[:addresses] }
    hent = wspace.hosts.where(conditions)
    return { :result => 'failed' } if hent == nil
    hosts |= hent if hent.class == Array
    hosts << hent if hent.class == ::Mdm::Host
  end
  if opts[:addresses] or opts[:address] or opts[:host]
    hosts.each do |h|
      sret = nil
      if opts[:port] or opts[:proto]
        conditions = {}
        conditions[:port] = opts[:port] if opts[:port]
        conditions[:proto] = opts[:proto] if opts[:proto]
        sret = h.services.where(conditions)
        next if sret == nil
        services << sret if sret.class == ::Mdm::Service
        services |= sret if sret.class == Array
      else
        services |= h.services
      end
    end
  elsif opts[:port] or opts[:proto]
    conditions = {}
    conditions[:port] = opts[:port] if opts[:port]
    conditions[:proto] = opts[:proto] if opts[:proto]
    sret = wspace.services.where(conditions)
    services << sret if sret and sret.class == ::Mdm::Service
    services |= sret if sret and sret.class == Array
  end

  deleted = []
  services.each do |s|
    dent = {}
    dent[:address] = s.host.address.to_s
    dent[:port] = s.port
    dent[:proto] = s.proto
    deleted << dent
    s.destroy
  end

  return { :result => 'success', :deleted => deleted }
}
end

#rpc_del_vuln(xopts) ⇒ Hash

Deletes vulnerabilities.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_vuln', {:host=>ip, :port=>445, :proto=>'tcp'})

Parameters:

  • xopts (Hash)

    Filters that narrow down which vulnerabilities to delete. See below:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :addresses (Array)

    Same as :address.

  • :port (Integer)

    Port.

  • :proto (String)

    Protocol.

  • :name (String)

    Name of the vulnerability.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success'.

    • 'deleted' [Array<Hash>] Each hash in the array contains the following:

      • 'address' [String] Host address.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'name' [String] Vulnerability name.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1235

def rpc_del_vuln(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  opts[:workspace] = opts[:workspace].name
  hosts  = []
  services = []
  vulns = []

  if opts[:host] or opts[:address] or opts[:addresses]
    hosts = opts_to_hosts(opts)
  end

  if opts[:port] or opts[:proto]
    if opts[:host] or opts[:address] or opts[:addresses]
      services = opts_to_services(hosts, opts)
    else
      services = opts_to_services([], opts)
    end
  end

  if opts[:port] or opts[:proto]
    services.each do |s|
      vret = nil
      if opts[:name]
        vret = s.vulns.find_by_name(opts[:name])
      else
        vret = s.vulns.to_a()
      end
      next if vret == nil
      vulns << vret if vret.class == ::Mdm::Vuln
      vulns |= vret if vret.class == Array
    end
  elsif opts[:address] or opts[:host] or opts[:addresses]
    hosts.each do |h|
      vret = nil
      if opts[:name]
        vret = h.vulns.find_by_name(opts[:name])
      else
        vret = h.vulns.to_a()
      end
      next if vret == nil
      vulns << vret if vret.class == ::Mdm::Vuln
      vulns |= vret if vret.class == Array
    end
  else
    vret = nil
    if opts[:name]
      vret = wspace.vulns.find_by_name(opts[:name])
    else
      vret = wspace.vulns.to_a()
    end
    vulns << vret if vret.class == ::Mdm::Vuln
    vulns |= vret if vret.class == Array
  end

  deleted = []
  vulns.each do |v|
    dent = {}
    dent[:address] = v.host.address.to_s if v.host
    dent[:port] = v.service.port if v.service
    dent[:proto] = v.service.proto if v.service
    dent[:name] = v.name
    deleted << dent
    v.destroy
  end

  return { :result => 'success', :deleted => deleted }
}
end

#rpc_del_workspace(wspace) ⇒ Hash

Deletes a workspace.

Examples:

Here's how you would use this from the client:

rpc.call('db.del_workspace', 'temp_workspace')

Parameters:

  • wspace (String)

    Workspace name.

Returns:

  • (Hash)

    A hash indicating the action was successful. It contains the following:

    • 'result' [String] A message that says 'success'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 404 Workspace not found.



687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 687

def rpc_del_workspace(wspace)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  # Delete workspace
  workspace = find_workspace(wspace)
  if workspace.nil?
    error(404, "Workspace not found: #{wspace}")
  elsif workspace.default?
    workspace.destroy
    workspace = self.framework.db.add_workspace(workspace.name)
  else
    # switch to the default workspace if we're about to delete the current one
    self.framework.db.workspace = self.framework.db.default_workspace if self.framework.db.workspace.name == workspace.name
    # now destroy the named workspace
    workspace.destroy
  end
  { 'result' => "success" }
}
end

#rpc_disconnectHash

Disconnects the database.

Examples:

Here's how you would use this from the client:

rpc.call('db.disconnect')

Returns:

  • (Hash)

    A hash that indicates whether the action was successful or not. It contains:

    • 'result' [String] A message that says either 'success' or 'failed'.



2007
2008
2009
2010
2011
2012
2013
2014
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 2007

def rpc_disconnect
  if (self.framework.db)
    self.framework.db.disconnect()
    return { :result => 'success' }
  else
    return { :result => 'failed' }
  end
end

#rpc_driver(xopts) ⇒ Hash

Sets the driver for the database or returns the current one.

Examples:

Here's how you would use this from the client:

# Sets a driver
rpc.call('db.driver', {:driver=>new_driver})
# Returns the current driver
rpc.call('db.driver', {})

Parameters:

  • xopts (Hash)

    Options:

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Hash)

    A hash that contains:

    • 'result' [String] Indicating whether we've successfully set the driver or not.

    • 'driver' [String] If the :driver option isn't set, then this returns the current one.



1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1912

def rpc_driver(xopts)
  opts = fix_options(xopts)
  if opts[:driver]
    if self.framework.db.drivers.include?(opts[:driver])
      self.framework.db.driver = opts[:driver]
      return { :result => 'success' }
    else
      return { :result => 'failed' }

    end
  else
    return { :driver => self.framework.db.driver.to_s }
  end
  return { :result => 'failed' }
end

#rpc_events(xopts) ⇒ Hash

Returns framework events.

Examples:

Here's how you would use this from the client:

rpc.call('db.events', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :limit (Integer)

    Limit.

  • :offset (Integer)

    Offset.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'events' [Array<Hash>] Each hash in the array contains the following:

      • 'host' [String] Host address.

      • 'created_at' [Integer] Creation date.

      • 'updated_at' [Integer] Last updated at.

      • 'name' [String] Event name.

      • 'critical' [Boolean] Criticality.

      • 'username' [String] Username.

      • 'info' [String] Additional information.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1522

def rpc_events(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  ret = {}
  ret[:events] = []

  wspace.events.offset(offset).limit(limit).each do |e|
    event = {}
    event[:host] = e.host.address if e.host
    event[:created_at] = e.created_at.to_i
    event[:updated_at] = e.updated_at.to_i
    event[:name] = e.name
    event[:critical] = e.critical if e.critical
    event[:username] = e.username if e.username
    event[:info] = e.info
    ret[:events] << event
  end
  ret
}
end

#rpc_get_client(xopts) ⇒ Hash

Returns information about a client connection.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_client', {:workspace=>'default', :ua_string=>user_agent, :host=>ip})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :ua_string (String)

    User agent string.

  • :host (String)

    Host IP.

Returns:

  • (Hash)

    A hash that contains the client connection:

    • 'client' [Array<Hash>] Each hash of the array contains the following:

      • 'host' [String] Host IP.

      • 'created_at' [Integer] Created date.

      • 'updated_at' [Integer] Last updated at.

      • 'ua_string' [String] User-Agent string.

      • 'ua_name' [String] User-Agent name.

      • 'ua_ver' [String] User-Agent version.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1048

def rpc_get_client(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  ret = {}
  ret[:client] = []
  c = self.framework.db.get_client(opts)
  if c
    client = {}
    host = c.host
    client[:host] = host.address
    client[:created_at] = c.created_at.to_i
    client[:updated_at] = c.updated_at.to_i
    client[:ua_string] = c.ua_string.to_s
    client[:ua_name] = c.ua_name.to_s
    client[:ua_ver] = c.ua_ver.to_s
    ret[:client] << client
  end
  ret
}
end

#rpc_get_host(xopts) ⇒ Hash

Returns information about a host.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_host', {:workspace => 'default', :host => ip})

Parameters:

  • xopts (Hash)

    Options (:addr, :address, :host are the same thing, and you only need one):

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :addr (String)

    Host address.

  • :address (String)

    Same as :addr.

  • :host (String)

    Same as :address.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'host' [Array<Hash>] Each hash in the array contains the following:

      • 'created_at' [Integer] Last created at.

      • 'address' [String] Address.

      • 'mac' [String] Mac address.

      • 'name' [String] Host name.

      • 'state' [String] Host state.

      • 'os_name' [String] OS name.

      • 'os_flavor' [String] OS flavor.

      • 'os_sp' [String] OS service pack.

      • 'os_lang' [String] OS language.

      • 'updated_at' [Integer] Last updated at.

      • 'purpose' [String] Purpose. Example: 'server'.

      • 'info' [String] Additional information.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 756

def rpc_get_host(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)

  ret = {}
  ret[:host] = []
  opts = fix_options(xopts)
  h = self.framework.db.get_host(opts)
  if h
    host = {}
    host[:created_at] = h.created_at.to_i
    host[:address] = h.address.to_s
    host[:mac] = h.mac.to_s
    host[:name] = h.name.to_s
    host[:state] = h.state.to_s
    host[:os_name] = h.os_name.to_s
    host[:os_flavor] = h.os_flavor.to_s
    host[:os_sp] = h.os_sp.to_s
    host[:os_lang] = h.os_lang.to_s
    host[:updated_at] = h.updated_at.to_i
    host[:purpose] = h.purpose.to_s
    host[:info] = h.info.to_s
    ret[:host] << host
  end
  ret
}
end

#rpc_get_note(xopts) ⇒ Hash

Returns a note.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_note', {:proto => 'tcp', :port => 80})

Parameters:

  • xopts (Hash)

    Options.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :addr (String)

    Host address.

  • :address (String)

    Same as :addr.

  • :host (String)

    Same as :address.

  • :proto (String)

    Protocol.

  • :port (Integer)

    Port.

  • :ntype (String)

    Note type.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'note' [Array<Hash>] Each hash in the array contains the following:

      • 'host' [String] Host.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'created_at' [Integer] Last created at.

      • 'updated_at' [Integer] Last updated at.

      • 'ntype' [String] Note type.

      • 'data' [String] Note data.

      • 'critical' [String] A boolean indicating criticality.

      • 'seen' [String] A boolean indicating whether the note has been seen before.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1002

def rpc_get_note(xopts)
  ret = {}
  ret[:note] = []

  notes = get_notes(xopts)

  notes.each do |n|
    note = {}
    host = n.host
    note[:host] = host.address || "unknown"
    if n.service
      note[:port] = n.service.port
      note[:proto] = n.service.proto
    end
    note[:created_at] = n[:created_at].to_i
    note[:updated_at] = n[:updated_at].to_i
    note[:ntype] = n[:ntype].to_s
    note[:data] = n[:data]
    note[:critical] = n[:critical].to_s
    note[:seen] = n[:seen].to_s
    ret[:note] << note
  end
  ret
end

#rpc_get_ref(name) ⇒ String

Returns an external vulnerability reference.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_ref', ref_name)

Parameters:

  • name (String)

    Reference name.

Returns:

  • (String)

    Reference.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1204
1205
1206
1207
1208
1209
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1204

def rpc_get_ref(name)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  self.framework.db.get_ref(name)
}
end

#rpc_get_service(xopts) ⇒ Hash

Returns information about a service.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_service', {:workspace=>'default', :proto=>'tcp', :port=>443})

Parameters:

  • xopts (Hash)

    Filters for the search, see below:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :proto (String)

    Protocol.

  • :port (Integer)

    Port.

  • :names (String)

    Service names.

Returns:

  • (Hash)

    A hash that contains the following key:

    • 'service' [Array<Hash>] Each hash in the array contains the following:

      • 'host' [String] Host address.

      • 'created_at' [Integer] Creation date.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'state' [String] Service state.

      • 'name' [String] Service name.

      • 'info' [String] Additional information.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 929

def rpc_get_service(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)

  ret = {}
  ret[:service] = []

  host = self.framework.db.get_host(opts)

  services = []
  sret = nil

  if host && opts[:proto] && opts[:port]
    sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port])
  elsif opts[:proto] && opts[:port]
    conditions = {}
    conditions[:state] = [Msf::ServiceState::Open] if opts[:up]
    conditions[:proto] = opts[:proto] if opts[:proto]
    conditions[:port] = opts[:port] if opts[:port]
    conditions[:name] = opts[:names] if opts[:names]
    sret = wspace.services.where(conditions).order("hosts.address, port").to_a()
  elsif host
    sret = host.services.to_a()
  end
  return ret if sret == nil
  services << sret if sret.class == ::Mdm::Service
  services |= sret if sret.class == Array


  services.each do |s|
    service = {}
    host = s.host
    service[:host] = host.address || "unknown"
    service[:created_at] = s[:created_at].to_i
    service[:updated_at] = s[:updated_at].to_i
    service[:port] = s[:port]
    service[:proto] = s[:proto].to_s
    service[:state] = s[:state].to_s
    service[:name] = s[:name].to_s
    service[:info] = s[:info].to_s
    ret[:service] << service
  end
  ret
}
end

#rpc_get_vuln(xopts) ⇒ Hash

Returns vulnerabilities from services or from a host.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_vuln', {:host => ip, :proto => 'tcp'})

Parameters:

  • xopts (Hash)

    Filters to narrow down which vulnerabilities to find.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :address (String)

    Same as :host.

  • :proto (String)

    Protocol.

  • :port (Integer)

    Port.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'vuln' [Array<Hash>] Each hash in the array contains the following:

      • 'host' [String] Host address.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'created_at' [Integer] Creation date.

      • 'updated_at' [Integer] Last updated at.

      • 'name' [String] Vulnerability name.

      • 'info' [String] Additional information.

      • 'refs' [Array<String>] Reference names.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1734

def rpc_get_vuln(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)

  ret = {}
  ret[:vuln] = []

  host = self.framework.db.get_host(opts)

  return ret if not host
  vulns = []

  if opts[:proto] && opts[:port]
    services = []
    sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port])
    return ret if sret == nil
    services << sret if sret.class == ::Mdm::Service
    services |= sret if sret.class == Array

    services.each do |s|
      vulns |= s.vulns
    end
  else
    vulns = host.vulns
  end

  return ret if (not vulns)

  vulns.each do |v|
    vuln= {}
    host= v.host
    vuln[:host] = host.address || "unknown"
    if v.service
      vuln[:port] = v.service.port
      vuln[:proto] = v.service.proto
    end
    vuln[:created_at] = v[:created_at].to_i
    vuln[:updated_at] = v[:updated_at].to_i
    vuln[:name] = v[:name].to_s
    vuln[:info] = v[:info].to_s
    vuln[:refs] = []
    v.refs.each do |r|
      vuln[:refs] << r.name
    end
    ret[:vuln] << vuln
  end
  ret
}
end

#rpc_get_workspace(wspace) ⇒ Hash

Returns the current workspace.

Examples:

Here's how you would use this from the client:

rpc.call('db.get_workspace', 'default')

Parameters:

  • wspace (String)

    workspace name.

Returns:

  • (Hash)

    A hash with the following key:

    • 'workspace' [Array<Hash>] In each hash of the array, you will get these keys:

      • 'name' [String] Workspace name.

      • 'id' [Integer] Workspace ID.

      • 'created_at' [Integer] Last created at.

      • 'updated_at' [Integer] Last updated at.

Raises:

  • (Msf::RPC::Exception)

    You might get one of the following errors:

    • 500 Database not loaded.

    • 500 Invalid workspace.



633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 633

def rpc_get_workspace(wspace)
  db_check
  wspace = find_workspace(wspace)
  ret = {}
  ret[:workspace] = []
  if wspace
    w = {}
    w[:name] = wspace.name
    w[:id] = wspace.id
    w[:created_at] = wspace.created_at.to_i
    w[:updated_at] = wspace.updated_at.to_i
    ret[:workspace] << w
  end
  ret
end

#rpc_hosts(xopts) ⇒ Hash

Returns information about hosts.

Examples:

Here's how you would use this from the client:

rpc.call('db.hosts', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :addresses (String, Array<String>)

    Address or CIDR range to filter by; may be an array of either.

  • :only_up (Boolean)

    If true, return hosts that are up.

  • :limit (Integer)

    Maximum number of hosts to return.

  • :offset (Integer)

    return the hosts starting at index 'offset`.

Returns:

  • (Hash)

    Host information that starts with the following hash key:

    • 'hosts' [Array<Hash>] An array of hosts. Each hash in the array will have the following:

      • 'created_at' [Integer] Creation date.

      • 'address' [String] IP address.

      • 'mac' [String] MAC address.

      • 'name' [String] Computer name.

      • 'state' [String] Host's state.

      • 'os_name' [String] Name of the operating system.

      • 'os_flavor' [String] OS flavor.

      • 'os_sp' [String] Service pack.

      • 'os_lang' [String] OS language.

      • 'updated_at' [Integer] Last updated at.

      • 'purpose' [String] Host purpose (example: server)

      • 'info' [String] Additional information about the host.

      • 'comments' [String] The host's comments.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 403

def rpc_hosts(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)

  conditions = {}
  conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:only_up]

  cidr_addrs = exact_addrs = []
  if opts[:addresses]
    addresses = Array(opts[:addresses])
    cidr_addrs, exact_addrs = addresses.partition { |a| a.to_s.include?('/') }
    cidr_addrs.map! { |c| IPAddr.new(c).cidr }
  end

  limit  = opts.delete(:limit)  || 100
  offset = opts.delete(:offset) || 0

  ret = {}
  ret[:hosts] = []

  host_query = wspace.hosts.where(conditions)
  if exact_addrs.any? || cidr_addrs.any?
    address_filter_sql = []
    bind_values = []

    if exact_addrs.any?
      address_filter_sql << 'hosts.address IN (?)'
      bind_values << exact_addrs
    end

    if cidr_addrs.any?
      address_filter_sql << cidr_addrs.map { 'hosts.address <<= ?::cidr' }.join(' OR ')
      bind_values.concat(cidr_addrs)
    end

    host_query = host_query.where(["(#{address_filter_sql.join(') OR (')})", *bind_values])
  end

  hosts = host_query.order(:address).offset(offset).limit(limit)

  hosts.each do |h|
    host = {}
    host[:created_at] = h.created_at.to_i
    host[:address]    = h.address.to_s
    host[:mac]        = h.mac.to_s
    host[:name]       = h.name.to_s
    host[:state]      = h.state.to_s
    host[:os_name]    = h.os_name.to_s
    host[:os_flavor]  = h.os_flavor.to_s
    host[:os_sp]      = h.os_sp.to_s
    host[:os_lang]    = h.os_lang.to_s
    host[:updated_at] = h.updated_at.to_i
    host[:purpose]    = h.purpose.to_s
    host[:info]       = h.info.to_s
    host[:comments]   = h.comments.to_s
    ret[:hosts] << host
  end
  ret
}
end

#rpc_import_data(xopts) ⇒ Hash

Imports file to the database.

Examples:

Here's how you would use this from the client:

rpc.call('db.import_data', {'data'=>nexpose_scan_results})

Parameters:

  • xopts (Hash)

    A hash that contains:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • 'data' (String)

    Data to import. The method will automatically detect the file type:

    • :acunetix_xml

    • :amap_log

    • :amap_mlog

    • :appscan_xml

    • :burp_session_xml

    • :ci_xml

    • :foundstone_xml

    • :fusionvm_xml

    • :gpp_xml

    • :ip360_aspl_xml

    • :ip360_xml_v3

    • :ip_list

    • :libpcap

    • :mbsa_xml

    • :msf_cred_dump_zip

    • :msf_pwdump

    • :msf_xml

    • :msf_zip

    • :nessus_nbe

    • :nessus_xml

    • :nessus_xml_v2

    • :netsparker_xml

    • :nexpose_rawxml

    • :nexpose_simplexml

    • :nikto_xml

    • :nmap_xml

    • :openvas_new_xml

    • :openvas_xml

    • :outpost24_xml

    • :qualys_asset_xml

    • :qualys_scan_xml

    • :retina_xml

    • :spiceworks_csv

    • :wapiti_xml

Returns:

  • (Hash)

    A hash that indicates the action was successful. It contains the following:

    • 'result' <String> A message that says 'success'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1701
1702
1703
1704
1705
1706
1707
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1701

def rpc_import_data(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  self.framework.db.import(opts)
  return { :result => 'success' }
}
end

#rpc_invalidate_login(xopts) ⇒ void

This method returns an undefined value.

Sets the status of a login credential to a failure.

Examples:

Here's how you would use this from the client:

opts = {
  address: '192.168.1.100',
  port: 445,
  protocol: 'tcp',
  public: 'admin',
  private: 'password1',
  status: 'Incorrect'
}
rpc.call('db.invalidate_login', opts)

Parameters:

  • xopts (Hash)

    Credential data (See #invalidate_login Documentation)

Raises:

See Also:



231
232
233
234
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 231

def (xopts)
  opts = fix_cred_options(xopts)
  (opts)
end

#rpc_loots(xopts) ⇒ Hash

Returns all the looted items.

Examples:

Here's how you would use this from the client:

rpc.call('db.loots', {})

Parameters:

  • xopts (Hash)

    Filters that narrow down the search:

Options Hash (xopts):

  • :workspace (Hash)

    Workspace name.

  • :limit (Integer)

    Limit.

  • :offset (Integer)

    Offset.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'loots' [Array<Hash>] Each hash in the array contains the following:

      • 'host' [String] Host address.

      • 'service' [String] Service name or port.

      • 'ltype' [String] Loot type.

      • 'ctype' [String] Content type.

      • 'data' [String] Looted data.

      • 'created_at' [Integer] Creation date.

      • 'updated_at' [Integer] Last updated at.

      • 'name' [String] Name.

      • 'info' [String] Additional information.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1628

def rpc_loots(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  ret = {}
  ret[:loots] = []
  wspace.loots.offset(offset).limit(limit).each do |l|
    loot = {}
    loot[:host] = l.host.address if l.host
    loot[:service] = l.service.name || l.service.port  if l.service
    loot[:ltype] = l.ltype
    loot[:ctype] = l.content_type
    loot[:data] = l.data
    loot[:created_at] = l.created_at.to_i
    loot[:updated_at] = l.updated_at.to_i
    loot[:name] = l.name
    loot[:info] = l.info
    ret[:loots] << loot
  end
  ret
}
end

#rpc_notes(xopts) ⇒ Hash

Returns notes from the database.

Examples:

Here's how you would use this from the client:

# This gives you all the notes.
rpc.call('db.notes', {})

Parameters:

  • xopts (Hash)

    Filters for the search. See below:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :address (String)

    Host address.

  • :ntype (String)

    Note type.

  • :proto (String)

    Protocol.

  • :ports (String)

    Port change.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'notes' [Array<Hash>] Each hash in the array contains the following:

      • 'time' [Integer] Creation date.

      • 'host' [String] Host address.

      • 'service' [String] Service name or port.

      • 'type' [String] Note type.

      • 'data' [Hash, String, nil] Note data.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1164

def rpc_notes(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  conditions = {}
  conditions["hosts.address"] = opts[:address] if opts[:address]
  conditions[:ntype] = opts[:ntype] if opts[:ntype]
  conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports]
  conditions["services.proto"] = opts[:proto] if opts[:proto]

  ret = {}
  ret[:notes] = []
  wspace.notes.includes(:host, :service).where(conditions).offset(offset).limit(limit).each do |n|
    note = {}
    note[:time] = n.created_at.to_i
    note[:host] = ""
    note[:service] = ""
    note[:host] = n.host.address if n.host
    note[:service] = n.service.name || n.service.port  if n.service
    note[:type ] = n.ntype.to_s
    note[:data] = n.data
    ret[:notes] << note
  end
  ret
}
end

#rpc_report_client(xopts) ⇒ Hash

Reports a client connection.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_client', {:workspace=>'default', :ua_string=>user_agent, :host=>ip})

Parameters:

  • xopts (Hash)

    Information about the client.

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :ua_string (String)

    Required. User-Agent string.

  • :host (String)

    Required. Host IP.

  • :ua_name (String)

    One of the Msf::HttpClients constants. (See Msf::HttpClient Documentation.)

  • :ua_ver (String)

    Detected version of the given client.

  • :campaign (String)

    An id or Campaign object.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.

See Also:



1088
1089
1090
1091
1092
1093
1094
1095
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1088

def rpc_report_client(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  res = self.framework.db.report_client(opts)
  return { :result => 'success' } if res
  { :result => 'failed' }
}
end

#rpc_report_event(xopts) ⇒ Hash

Reports a framework event.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_event', {:username => username, :host=>ip})

Parameters:

  • xopts (Hash)

    Information about the event.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :username (String)

    Username.

  • :host (String)

    Host address.

Returns:

  • (Hash)

    A hash indicating the action was successful. It contains:

    • 'result' [String] A message that says 'success'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1561
1562
1563
1564
1565
1566
1567
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1561

def rpc_report_event(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  res = self.framework.db.report_event(opts)
  { :result => 'success' } if res
}
end

#rpc_report_host(xopts) ⇒ Hash

Reports a new host to the database.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_host', {:host => ip})

Parameters:

  • xopts (Hash)

    Information to report about the host. See below:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :host (String)

    IP address. You must supply this.

  • :state (String)

    One of the Msf::HostState constants. (See Most::HostState Documentation)

  • :os_name (String)

    Something like "Windows", "Linux", or "Mac OS X".

  • :os_flavor (String)

    Something like "Enterprise", "Pro", or "Home".

  • :os_sp (String)

    Something like "SP2".

  • :os_lang (String)

    Something like "English", "French", or "en-US".

  • :arch (String)

    one of the ARCH_* constants. (see ARCH Documentation)

  • :mac (String)

    Mac address.

  • :scope (String)

    Interface identifier for link-local IPv6.

  • :virtual_host (String)

    The name of the VM host software, eg "VMWare", "QEMU", "Xen", etc.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains the following:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.

See Also:



869
870
871
872
873
874
875
876
877
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 869

def rpc_report_host(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)

  res = self.framework.db.report_host(opts)
  return { :result => 'success' } if res
  { :result => 'failed' }
}
end

#rpc_report_loot(xopts) ⇒ Hash

Reports a looted item.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_loot', {})

Parameters:

  • xopts (Hash)

    Information about the looted item.

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    Host address.

  • :port (Integer)

    Port. Should match :service.

  • :proto (String)

    Protocol. Should match :service.

  • :path (String)

    Required. Path where the item was looted.

  • :type (String)

    Loot type.

  • :ctype (String)

    Content type.

  • :name (String)

    Name.

  • :info (String)

    Additional information.

  • :data (String)

    Looted data.

  • :service (Mdm::Service)

    Service where the data was found.

Returns:

  • (Hash)

    A hash that contains the following:

    • 'result' [String] A message that says 'success'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1592

def rpc_report_loot(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  if opts[:host] && opts[:port] && opts[:proto]
    opts[:service] = self.framework.db.find_or_create_service(opts)
  end

  res = self.framework.db.report_loot(opts)
  { :result => 'success' } if res
}
end

#rpc_report_note(xopts) ⇒ Hash

Reports a note.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_note', {:type=>'http_data', :host=>'192.168.1.123', :data=>'data'})

Parameters:

  • xopts (Hash)

    Information about the note.

Options Hash (xopts):

  • :type (String)

    Required. The type of note, e.g. smb_peer_os.

  • :workspace (String)

    The workspace to associate with this note.

  • :host (String)

    An IP address or a Host object to associate with this note.

  • :service (String)

    A Service object to associate with this note.

  • :data (String)

    Whatever it is you're making a note of.

  • :port (Integer)

    Along with :host and :proto, a service to associate with this note.

  • :proto (String)

    Along with :host and :port, a service to associate with this note.

  • A (Hash)

    hash that contains the following information.

    • :unique [Boolean] Allow only a single Note per :host/:type pair.

    • :unique_data [Boolean] Like :unique, but also compare :data.

    • :insert [Boolean] Always insert a new Note even if one with identical values exists.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1120

def rpc_report_note(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  if (opts[:host] or opts[:address]) and opts[:port] and opts[:proto]
    addr = opts[:host] || opts[:address]
    wspace = opts[:workspace] || self.framework.db.workspace
    host = wspace.hosts.find_by_address(addr)
    if host && host.services.count > 0
      service = host.services.find_by_proto_and_port(opts[:proto],opts[:port])
      if service
        opts[:service] = service
      end
    end
  end

  res = self.framework.db.report_note(opts)
  return { :result => 'success' } if res
  { :result => 'failed' }
}
end

#rpc_report_service(xopts) ⇒ Hash

Reports a service to the database.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_service', {:host=>ip, :port=>8181, :proto=>'tcp', :name=>'http'})

Parameters:

  • xopts (Hash)

    Information to report about the service. See below:

Options Hash (xopts):

  • :workspace (String)

    Name of the workspace.

  • :host (String)

    Required. The host where this service is running.

  • :port (String)

    Required. The port where this service listens.

  • :proto (String)

    Required. The transport layer protocol (e.g. tcp, udp).

  • :name (String)

    The application layer protocol (e.g. ssh, mssql, smb).

  • :sname (String)

    An alias for the above

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



897
898
899
900
901
902
903
904
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 897

def rpc_report_service(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  res = self.framework.db.report_service(opts)
  return { :result => 'success' } if res
  { :result => 'failed' }
}
end

#rpc_report_vuln(xopts) ⇒ Hash

Reports a vulnerability.

Examples:

Here's how you would use this from the client:

rpc.call('db.report_vuln', {:host=>ip, :name=>'file upload'})

Parameters:

  • xopts (Hash)

    Information about the vulnerability:

Options Hash (xopts):

  • :workspace (String)

    Workspace name.

  • :host (String)

    The host where this vulnerability resides

  • :name (String)

    The friendly name for this vulnerability (title).

  • :info (String)

    A human readable description of the vuln, free-form text.

  • :refs (Array)

    An array of Ref objects or string names of references.

  • :details (Hash)

    A hash with :key pointed to a find criteria hash and the rest containing VulnDetail fields.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. It contains:

    • 'result' [String] A message that says either 'success' or 'failed'.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1489

def rpc_report_vuln(xopts)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  opts = fix_options(xopts)
  opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace]
  res = self.framework.db.report_vuln(opts)
  return { :result => 'success' } if res
  { :result => 'failed' }
}
end

#rpc_services(xopts) ⇒ Hash

Returns information about services.

Examples:

Here's how you would use this from the client:

rpc.call('db.services', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Name of workspace.

  • :limit (Integer)

    Limit.

  • :offset (Integer)

    Offset.

  • :proto (String)

    Protocol.

  • :address (String)

    Host address.

  • :ports (String)

    Port range.

  • :names (String)

    Names (Use ',' as the separator).

Returns:

  • (Hash)

    A hash with the following keys:

    • 'services' [Array<Hash>] In each hash of the array, you will get these keys:

      • 'host' [String] Host.

      • 'created_at' [Integer] Last created at.

      • 'updated_at' [Integer] Last updated at.

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'state' [String] Service state.

      • 'name' [String] Service name.

      • 'info' [String] Additional information about the service.

      • 'resource' [Hash] Service resource.

      • 'parents' [Array<Hash>] List of parent services with same set of keys as the service.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 492

def rpc_services( xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  conditions = {}
  conditions[:state] = [Msf::ServiceState::Open] if opts[:only_up]
  conditions[:proto] = opts[:proto] if opts[:proto]
  conditions["hosts.address"] = opts[:addresses] if opts[:addresses]
  conditions[:port] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports]
  conditions[:name] = opts[:names].strip().split(",") if opts[:names]

  ret = {}
  ret[:services] = []

  wspace.services.includes(:host, :parents).where(conditions).offset(offset).limit(limit).each do |s|
    ret[:services] << process_service(s)
  end
  ret
}
end

#rpc_set_workspace(wspace) ⇒ Hash

Sets a workspace.

Examples:

Here's how you would use this from the client:

# This will set the current workspace to 'default'
rpc.call('db.set_workspace', 'default')

Parameters:

  • wspace (String)

    Workspace name.

Returns:

  • (Hash)

    A hash indicating whether the action was successful or not. You will get:

    • 'result' [String] A message that says either 'success' or 'failed'

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace

    • 404 Workspace not found.



663
664
665
666
667
668
669
670
671
672
673
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 663

def rpc_set_workspace(wspace)
::ApplicationRecord.connection_pool.with_connection {
  db_check
  workspace = find_workspace(wspace)
  if workspace
    self.framework.db.workspace = workspace
    return { 'result' => "success" }
  end
  { 'result' => 'failed' }
}
end

#rpc_statusHash

Returns the database status.

Examples:

Here's how you would use this from the client:

rpc.call('db.status')

Returns:

  • (Hash)

    A hash that contains the following keys:

    • 'driver' [String] Name of the database driver.

    • 'db' [String] Name of the database.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')



1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1979

def rpc_status
  if (not self.framework.db.driver)
    return {:driver => 'None' }
  end

  cdb = ""
  if framework.db.connection_established?
    ::ApplicationRecord.connection_pool.with_connection { |conn|
      if conn.respond_to? :current_database
        cdb = conn.current_database
      else
        cdb = conn.instance_variable_get(:@config)[:database]
      end
    }
    return {:driver => self.framework.db.driver.to_s , :db => cdb }
  else
    return {:driver => self.framework.db.driver.to_s}
  end
  {:driver => 'None' }
end

#rpc_vulns(xopts) ⇒ Hash

Returns information about reported vulnerabilities.

Examples:

Here's how you would use this from the client:

rpc.call('db.vulns', {})

Parameters:

  • xopts (Hash)

    Options:

Options Hash (xopts):

  • :workspace (String)

    Name of workspace.

  • :limit (Integer)

    Limit.

  • :offset (Integer)

    Offset.

  • :proto (String)

    Protocol.

  • :address (String)

    Address.

  • :ports (String)

    Port range.

  • :names (String)

    Exploit that was used.

Returns:

  • (Hash)

    A hash with the following key:

    • 'vulns' [Array<Hash>] In each hash of the array, you will get these keys:

      • 'port' [Integer] Port.

      • 'proto' [String] Protocol.

      • 'time' [Integer] Time reported.

      • 'host' [String] Vulnerable host.

      • 'name' [String] Exploit that was used.

      • 'refs' [String] Vulnerability references.

      • 'resource' [String] Vulnerability resource.

Raises:

  • (Msf::RPC::ServerException)

    You might get one of these errors:

    • 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').

    • 500 Database not loaded. Try: rpc.call('console.create')

    • 500 Invalid workspace.



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 541

def rpc_vulns(xopts)
::ApplicationRecord.connection_pool.with_connection {
  opts, wspace = init_db_opts_workspace(xopts)
  limit = opts.delete(:limit) || 100
  offset = opts.delete(:offset) || 0

  conditions = {}
  conditions["hosts.address"] = opts[:address] if opts[:address]
  conditions[:name] = opts[:names].strip().split(",") if opts[:names]
  conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports]
  conditions["services.proto"] = opts[:proto] if opts[:proto]

  ret = {}
  ret[:vulns] = []
  wspace.vulns.includes(:service).where(conditions).offset(offset).limit(limit).each do |v|
    vuln = {}
    reflist = v.refs.map { |r| r.name }
    if v.service
      vuln[:port] = v.service.port
      vuln[:proto] = v.service.proto
    else
      vuln[:port] = nil
      vuln[:proto] = nil
    end
    vuln[:time] = v.created_at.to_i
    vuln[:host] = v.host.address || nil
    vuln[:name] = v.name
    vuln[:refs] = reflist.join(',')
    vuln[:resource] = v.resource
    ret[:vulns] << vuln
  end
  ret
}
end

#rpc_workspacesHash

Returns information about workspaces.

Examples:

Here's how you would use this from the client:

rpc.call('db.workspaces')

Returns:

  • (Hash)

    A hash with the following key:

    • 'workspaces' [Array<Hash>] In each hash of the array, you will get these keys:

      • 'id' [Integer] Workspace ID.

      • 'name' [String] Workspace name.

      • 'created_at' [Integer] Last created at.

      • 'updated_at' [Integer] Last updated at.

Raises:



588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 588

def rpc_workspaces
  db_check

  res = {}
  res[:workspaces] = []
  self.framework.db.workspaces.each do |j|
    ws = {}
    ws[:id] = j.id
    ws[:name] = j.name
    ws[:created_at] = j.created_at.to_i
    ws[:updated_at] = j.updated_at.to_i
    res[:workspaces] << ws
  end
  res
end