Skip to content

Commit 86a7e36

Browse files
committed
Round 7 of documentation
1 parent 3c50feb commit 86a7e36

File tree

1 file changed

+145
-21
lines changed

1 file changed

+145
-21
lines changed

lib/msf/core/rpc/v10/rpc_db.rb

Lines changed: 145 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ def rpc_create_cracked_credential(xopts)
141141
#
142142
# @param [Hash] xopts Credential options. (See #create_credential Documentation)
143143
# @return [Hash] Credential data. It contains the following keys:
144-
# * :username [String] Username saved.
145-
# * :private [String] Password saved.
146-
# * :private_type [String] Password type.
147-
# * :realm_value [String] Realm.
148-
# * :realm_key [String] Realm key.
149-
# * :host [String] Host (Only avilable if there's a :last_attempted_at and :status)
150-
# * :sname [String] Service name (only available if there's a :last_attempted_at and :status)
151-
# * :status [Status] Login status (only available if there's a :last_attempted_at and :status)
144+
# * 'username' [String] Username saved.
145+
# * 'private' [String] Password saved.
146+
# * 'private_type' [String] Password type.
147+
# * 'realm_value' [String] Realm.
148+
# * 'realm_key' [String] Realm key.
149+
# * 'host' [String] Host (Only avilable if there's a :last_attempted_at and :status)
150+
# * 'sname' [String] Service name (only available if there's a :last_attempted_at and :status)
151+
# * 'status' [Status] Login status (only available if there's a :last_attempted_at and :status)
152152
# @see https://github.com/rapid7/metasploit-credential/blob/master/lib/metasploit/credential/creation.rb#L107 #create_credential Documentation.
153153
# @example Here's how you would use this from the client:
154154
# opts = {
@@ -216,16 +216,20 @@ def rpc_invalidate_login(xopts)
216216
#
217217
# @param [Hash] xopts Options:
218218
# @option xopts [String] :workspace Name of the workspace.
219+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
220+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
221+
# * 500 Database not loaded. Try: rpc.call('console.create')
222+
# * 500 Invalid workspace.
219223
# @return [Hash] Credentials with the following hash key:
220224
# * 'creds' [Array<Hash>] An array of credentials. Each hash in the array will have the following:
221-
# * 'user' [String] Username.
222-
# * 'pass' [String] Password.
223-
# * 'updated_at' [Fixnum] Last updated at.
224-
# * 'type' [String] Password type.
225-
# * 'host' [String] Host.
226-
# * 'port' [Fixnum] Port.
227-
# * 'proto' [String] Protocol.
228-
# * 'sname' [String] Service name.
225+
# * 'user' [String] Username.
226+
# * 'pass' [String] Password.
227+
# * 'updated_at' [Fixnum] Last updated at.
228+
# * 'type' [String] Password type.
229+
# * 'host' [String] Host.
230+
# * 'port' [Fixnum] Port.
231+
# * 'proto' [String] Protocol.
232+
# * 'sname' [String] Service name.
229233
# @example Here's how you would use this from the client:
230234
# rpc.call('db.creds', {})
231235
def rpc_creds(xopts)
@@ -269,6 +273,11 @@ def rpc_creds(xopts)
269273
#
270274
# @param [Hash] xopts Options:
271275
# @option xopts [String] :workspace Name of the workspace.
276+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
277+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
278+
# * 500 Database not loaded. Try: rpc.call('console.create')
279+
# * 500 Invalid workspace.
280+
# You probably want to run: rpc.call('console.create').
272281
# @return [Hash] Host information that starts with the following hash key:
273282
# * 'hosts' [Array<Hash>] An array of hosts. Each hash in the array will have the following:
274283
# * 'created_at' [Fixnum] Creation date.
@@ -329,8 +338,12 @@ def rpc_hosts(xopts)
329338
# @option xopts [String] :address Address.
330339
# @option xopts [String] :ports Port range.
331340
# @option xopts [String] :names Names (Use ',' as the separator).
341+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
342+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
343+
# * 500 Database not loaded. Try: rpc.call('console.create')
344+
# * 500 Invalid workspace.
332345
# @return [Hash] A hash with the following keys:
333-
# * :services [Array<Hash>] In each hash of the array, you will get these keys:
346+
# * 'services' [Array<Hash>] In each hash of the array, you will get these keys:
334347
# * 'host' [String] Host.
335348
# * 'created_at' [Fixnum] Last created at.
336349
# * 'updated_at' [Fixnum] Last updated at.
@@ -340,7 +353,7 @@ def rpc_hosts(xopts)
340353
# * 'name' [String] Service name.
341354
# * 'info' [String] Additional information about the service.
342355
# @example Here's how you would use this from the client:
343-
# rpc.call('db.services')
356+
# rpc.call('db.services', {})
344357
def rpc_services( xopts)
345358
::ActiveRecord::Base.connection_pool.with_connection {
346359
opts, wspace = init_db_opts_workspace(xopts)
@@ -384,6 +397,10 @@ def rpc_services( xopts)
384397
# @option xopts [String] :proto Protocol.
385398
# @option xopts [String] :address Address.
386399
# @option xopts [String] :ports Port range.
400+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
401+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
402+
# * 500 Database not loaded. Try: rpc.call('console.create')
403+
# * 500 Invalid workspace.
387404
# @return [Hash] A hash with the following key:
388405
# * 'vulns' [Array<Hash>] In each hash of the array, you will get these keys:
389406
# * 'port' [Fixnum] Port.
@@ -459,7 +476,7 @@ def rpc_workspaces
459476

460477
# Returns the current workspace.
461478
#
462-
# @raise [Msf::RPC::Exception] Database not loaded.
479+
# @raise [Msf::RPC::Exception] Database not loaded. Try: rpc.call('console.create')
463480
# @return [Hash] A hash with the following keys:
464481
# * 'workspace' [String] Workspace name.
465482
# * 'workspace_id' [Fixnum] Workspace ID.
@@ -505,8 +522,7 @@ def rpc_get_workspace(wspace)
505522
# Sets a workspace.
506523
#
507524
# @param [String] wspace Workspace name.
508-
# @raise [Msf::RPC::Exception] You might get one of the following errors:
509-
# * 500 Database not loaded.
525+
# @raise [Msf::RPC::Exception] 500 Database not loaded.
510526
# @return [Hash] A hash indicating whether the action was successful or not. You will get:
511527
# * 'result' [String] A message that says either 'success' or 'failed'
512528
# @example Here's how you would use this from the client:
@@ -524,6 +540,18 @@ def rpc_set_workspace(wspace)
524540
}
525541
end
526542

543+
544+
# Deletes a workspace.
545+
#
546+
# @param [String] wspace Workspace name.
547+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
548+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
549+
# * 500 Database not loaded. Try: rpc.call('console.create')
550+
# * 404 Workspace not found.
551+
# @return [Hash] A hash indicating the action was successful. It contains the following:
552+
# * 'result' [String] A message that says 'success'.
553+
# @example Here's how you would use this from the client:
554+
# rpc.call('db.wspace', 'temp_workspace')
527555
def rpc_del_workspace(wspace)
528556
::ActiveRecord::Base.connection_pool.with_connection {
529557
db_check
@@ -544,6 +572,18 @@ def rpc_del_workspace(wspace)
544572
}
545573
end
546574

575+
576+
# Adds a new workspace.
577+
#
578+
# @param [String] wspace Workspace name.
579+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
580+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
581+
# * 500 Database not loaded. Try: rpc.call('console.create')
582+
# * 500 Invalid workspace.
583+
# @return [Hash] A hash indicating whether the action was successful or not. You get:
584+
# * 'result' [String] A message that says either 'success' or 'failed'.
585+
# @example Here's how you would use this from the client:
586+
# * rpc.call('db.add_workspace', 'my_new_workspace')
547587
def rpc_add_workspace(wspace)
548588
::ActiveRecord::Base.connection_pool.with_connection {
549589
db_check
@@ -553,6 +593,33 @@ def rpc_add_workspace(wspace)
553593
}
554594
end
555595

596+
597+
# Returns information about a host.
598+
#
599+
# @param [Hash] xopts Options (:addr, :address, :host are the same thing, and you only need one):
600+
# @option xopts [String] :addr Host address.
601+
# @option xopts [String] :address Same as :addr.
602+
# @option xopts [String] :host Same as :address.
603+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
604+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
605+
# * 500 Database not loaded. Try: rpc.call('console.create')
606+
# * 500 Invalid workspace.
607+
# @return [Hash] A hash that contains the following:
608+
# * 'host' [Array<Hash>] Each hash in the array contains the following:
609+
# * 'created_at' [Fixnum] Last created at.
610+
# * 'address' [String] Address.
611+
# * 'mac' [String] Mac address.
612+
# * 'name' [String] Host name.
613+
# * 'state' [String] Host state.
614+
# * 'os_name' [String] OS name.
615+
# * 'os_flavor' [String] OS flavor.
616+
# * 'os_sp' [String] OS service pack.
617+
# * 'os_lang' [String] OS language.
618+
# * 'updated_at' [Fixnum] Last updated at.
619+
# * 'purpose' [String] Purpose. Example: 'server'.
620+
# * 'info' [String] Additional information.
621+
# @example Here's how you would use this from the client:
622+
# rpc.call('db.get_host', {:host => ip})
556623
def rpc_get_host(xopts)
557624
::ActiveRecord::Base.connection_pool.with_connection {
558625
opts, wspace = init_db_opts_workspace(xopts)
@@ -581,6 +648,30 @@ def rpc_get_host(xopts)
581648
}
582649
end
583650

651+
652+
# Reports a new host to the database.
653+
#
654+
# @param [Hash] xopts Information about the host.
655+
# @option xopts [String] :host IP address. You msut supply this.
656+
# @option xopts [String] :state One of the Msf::HostState constants. (See Most::HostState Documentation)
657+
# @option xopts [String] :os_name Something like "Windows", "Linux", or "Mac OS X".
658+
# @option xopts [String] :os_flavor Something like "Enterprise", "Pro", or "Home".
659+
# @option xopts [String] :os_sp Something like "SP2".
660+
# @option xopts [String] :os_lang Something like "English", "French", or "en-US".
661+
# @option xopts [String] :arch one of the ARCH_* constants. (see ARCH Documentation)
662+
# @option xopts [String] :mac Mac address.
663+
# @option xopts [String] :scope Interface identifier for link-local IPv6.
664+
# @option xopts [String] :virtual_host The name of the VM host software, eg "VMWare", "QEMU", "Xen", etc.
665+
# @see https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/host_state.rb Most::HostState Documentation.
666+
# @see https://github.com/rapid7/metasploit-framework/blob/master/lib/rex/constants.rb#L66 ARCH Documentation.
667+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
668+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
669+
# * 500 Database not loaded. Try: rpc.call('console.create')
670+
# * 500 Invalid workspace.
671+
# @return [Hash] A hash indicating whether the action was successful or not. It contains the following:
672+
# * 'result' [String] A message that says either 'success' or 'failed'.
673+
# @example Here's how you would use this from the client:
674+
# rpc.call('db.report_host', {:host => ip})
584675
def rpc_report_host(xopts)
585676
::ActiveRecord::Base.connection_pool.with_connection {
586677
opts, wspace = init_db_opts_workspace(xopts)
@@ -591,6 +682,23 @@ def rpc_report_host(xopts)
591682
}
592683
end
593684

685+
686+
# Reports a service to the database.
687+
#
688+
# @param [Hash] xopts Information about the service.
689+
# @option xopts [String] :host Required. The host where this service is running.
690+
# @option xopts [String] :port Required. The port where this service listens.
691+
# @option xopts [String] :proto Required. The transport layer protocol (e.g. tcp, udp).
692+
# @option xopts [String] :name The application layer protocol (e.g. ssh, mssql, smb).
693+
# @option xopts [String] :sname An alias for the above
694+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
695+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
696+
# * 500 Database not loaded. Try: rpc.call('console.create')
697+
# * 500 Invalid workspace.
698+
# @return [Hash] A hash indicating whether the action was successful or not. It contains:
699+
# * 'result' [String] A message that says either 'success' or 'failed'.
700+
# @example Here's how you would use this from the client:
701+
# rpc.call('db.report_service', {:host=>ip, :port=>8181, :proto=>'tcp', :name=>'http'})
594702
def rpc_report_service(xopts)
595703
::ActiveRecord::Base.connection_pool.with_connection {
596704
opts, wspace = init_db_opts_workspace(xopts)
@@ -1262,6 +1370,17 @@ def rpc_connect(xopts)
12621370

12631371
end
12641372

1373+
1374+
# Returns the database status.
1375+
#
1376+
# @raise [Msf::RPC::ServerException] You might get one of these errors:
1377+
# * 500 ActiveRecord::ConnectionNotEstablished. Try: rpc.call('console.create').
1378+
# * 500 Database not loaded. Try: rpc.call('console.create')
1379+
# @return [Hash] A hash that contains the following keys:
1380+
# * 'driver' [String] Name of the database driver.
1381+
# * 'db' [String] Name of the database.
1382+
# @example Here's how you would use this from the client:
1383+
# rpc.call('db.status')
12651384
def rpc_status
12661385
if (not self.framework.db.driver)
12671386
return {:driver => 'None' }
@@ -1283,6 +1402,11 @@ def rpc_status
12831402
{:driver => 'None' }
12841403
end
12851404

1405+
1406+
# Disconnects the database.
1407+
#
1408+
# @return [Hash] A hash that indicates whether the action was successful or not. It contains:
1409+
# 'result' [String] A message that says either 'success' or 'failed'.
12861410
def rpc_disconnect
12871411
if (self.framework.db)
12881412
self.framework.db.disconnect()

0 commit comments

Comments
 (0)