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.


688
689
690
691
692
693
694
695
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 688

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.

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.

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.


772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 772

def rpc_analyze_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)
    return ret unless h
    h_result = self.framework.analyze.host(h)
    host_detail = {}
    host_detail[:address] = h.address
    # for now only modules can be returned, in future maybe process whole result map
    unless h_result[:modules].empty?
      host_detail[:modules] = []
      h_result[:modules].each do |mod|
        mod_detail = {}
        mod_detail[:mtype]  = mod.type
        mod_detail[:mname]  = mod.fullname
        host_detail[:modules] << mod_detail
      end
    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.


1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1763

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'.


1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1895

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 avilable 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.

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.


257
258
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
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 257

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
      }
    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:


582
583
584
585
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 582

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.


1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1812

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.


330
331
332
333
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
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 330

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.


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
1424
1425
1426
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1399

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.


1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1286

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.


1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1326

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.


1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
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
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1192

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.


656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 656

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'.


1964
1965
1966
1967
1968
1969
1970
1971
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1964

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] Indiciating whether we've successfully set the driver or not.

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


1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1869

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.


1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1479

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.


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

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.


725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 725

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.


957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 957

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.


1161
1162
1163
1164
1165
1166
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1161

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.


884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 884

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.


1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1691

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.


602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 602

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.

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.

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.


394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 394

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]
  conditions[:address] = opts[:addresses] if opts[:addresses]

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

  ret = {}
  ret[:hosts] = []
  wspace.hosts.where(conditions).offset(offset).order(:address).limit(limit).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
    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.


1658
1659
1660
1661
1662
1663
1664
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1658

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.


1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1585

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.

  • :names (String)

    Names (separated by ',').

  • :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] Host type.

      • 'data' [String] Host 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.


1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1120

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[:name] = opts[:names].strip().split(",") if opts[:names]
  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.inspect
    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:


1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1043

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.


1518
1519
1520
1521
1522
1523
1524
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1518

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:


824
825
826
827
828
829
830
831
832
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 824

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.


1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1549

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 :uniqe, 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.


1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1075

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.


852
853
854
855
856
857
858
859
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 852

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.


1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1446

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)

    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.

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.


454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 454

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).where(conditions).offset(offset).limit(limit).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[:services] << service
  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.


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

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')


1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1936

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.

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.

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.


511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 511

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[:port]
  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(',')
    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:


557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 557

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