Class: Msf::RPC::Simple::Client
- Inherits:
-
Object
- Object
- Msf::RPC::Simple::Client
- Includes:
- Features::Framework, Features::Pro
- Defined in:
- lib/msfrpc-simple/client.rb
Instance Method Summary collapse
- #cleanup ⇒ Object
- #connected? ⇒ Boolean
-
#create_report ⇒ Object
Public: Creates and retuns an xml report.
-
#initialize(user_options) ⇒ Client
constructor
Public: Create a simple client object.
Methods included from Features::Pro
#start_bruteforce, #start_discover, #start_report
Methods included from Features::Framework
#bruteforce_range, #discover_range, #execute_module_and_return_output, #exploit_range
Constructor Details
#initialize(user_options) ⇒ Client
Public: Create a simple client object.
user_options - hash of options to include in our initial connection. project - project name we want to use for this connection.
Returns nothing.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/msfrpc-simple/client.rb', line 25 def initialize() # configure default options @options = { :project => [:project] || "default", :port => [:project] || 55553, :user => [:rpc_user], :pass => [:rpc_pass], :db_host => [:db_host] || "localhost", :db_user => [:db_user], :db_pass => [:db_pass], :db => [:db_name] || "msf" } @options.merge!() # # Connect to the RPC daemon using the default client # @client = Msf::RPC::Client.new(@options) # # Connect to the database based on the included options # _connect_database # # Add a new workspace # @workspace_name = Time.now.utc.to_s.gsub(" ","_").gsub(":","_") _create_workspace # # Create a logger # #@logger = Msf::RPC::Simple::Logger.new end |
Instance Method Details
#cleanup ⇒ Object
103 104 105 106 |
# File 'lib/msfrpc-simple/client.rb', line 103 def cleanup #_send_command("workspace -d #{@workspace_name}") _send_command("db_disconnect") end |
#connected? ⇒ Boolean
108 109 110 |
# File 'lib/msfrpc-simple/client.rb', line 108 def connected? return true if @client.call("core.version") end |
#create_report ⇒ Object
Public: Creates and retuns an xml report
This method is ugly for a number of reasons, but there doesn’t appear to be a way to be notified when the command is completed nor when the
returns a valid xml string
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/msfrpc-simple/client.rb', line 71 def create_report report_path = "/tmp/metasploit_#{@workspace_name}.xml" # Create the report using the db_export command _send_command("db_export #{report_path}\n") # We've sent the command, so let's sit back and wait for th # output to hit the disk. begin xml_string = "" status = Timeout::timeout(240) { # We don't know when the file is going to show up, so # wait for it... until File.exists? report_path do sleep 1 end # Read and clean up the file when it exists... until xml_string.include? "</MetasploitV4>" do sleep 5 xml_string = File.read(report_path) end File.delete(report_path) } rescue Timeout::Error xml_string = "<MetasploitV4></MetasploitV4>" end xml_string end |