Class: Nexpose::Connection
- Inherits:
-
Object
- Object
- Nexpose::Connection
- Includes:
- NexposeAPI, XMLUtils
- Defined in:
- lib/nexpose.rb
Overview
Description
Object that represents a connection to a NeXpose Security Console.
Examples
# Create a new Nexpose Connection on the default port
nsc = Connection.new("10.1.40.10","nxadmin","password")
# Login to NSC and Establish a Session ID
nsc.login()
# Check Session ID
if (nsc.session_id)
puts "Login Successful"
else
puts "Login Failure"
end
# //Logout
logout_success = nsc.logout()
if (! logout_success)
puts "Logout Failure" + "<p>" + nsc.error_msg.to_s
end
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
true if an error condition exists; false otherwise.
-
#error_msg ⇒ Object
readonly
Error message string.
-
#host ⇒ Object
readonly
The hostname or IP Address of the NSC.
-
#password ⇒ Object
readonly
The password used to login to the NSC.
-
#port ⇒ Object
readonly
The port of the NSC (default is 3780).
-
#request_xml ⇒ Object
readonly
The last XML request sent by this object.
-
#response_xml ⇒ Object
readonly
The last XML response received by this object.
-
#session_id ⇒ Object
readonly
Session ID of this connection.
-
#url ⇒ Object
readonly
The URL for communication.
-
#username ⇒ Object
readonly
The username used to login to the NSC.
Instance Method Summary collapse
-
#download(url) ⇒ Object
Download a specific URL.
-
#execute(xml, version = '1.1') ⇒ Object
Execute an API request.
-
#initialize(ip, user, pass, port = 3780, silo_id = nil) ⇒ Connection
constructor
Constructor for Connection.
-
#login ⇒ Object
Establish a new connection and Session ID.
-
#logout ⇒ Object
Logout of the current connection.
Methods included from NexposeAPI
#asset_group_config, #asset_group_delete, #asset_groups_listing, #console_command, #create_multi_tenant_user, #create_silo, #create_silo_profile, #delete_mtu, #delete_silo, #delete_silo_profile, #device_delete, #list_mtu, #list_silo_profiles, #list_silos, #make_xml, #report_config_delete, #report_delete, #report_generate, #report_history, #report_last, #report_template_listing, #scan_activity, #scan_statistics, #scan_status, #scan_stop, #site_delete, #site_device_listing, #site_device_scan_start, #site_listing, #site_scan_history, #system_information
Methods included from XMLUtils
Constructor Details
#initialize(ip, user, pass, port = 3780, silo_id = nil) ⇒ Connection
Constructor for Connection
965 966 967 968 969 970 971 972 973 974 |
# File 'lib/nexpose.rb', line 965 def initialize(ip, user, pass, port = 3780, silo_id = nil) @host = ip @port = port @username = user @password = pass @silo_id = silo_id @session_id = nil @error = false @url = "https://#{@host}:#{@port}/api/VERSION_STRING/xml" end |
Instance Attribute Details
#error ⇒ Object (readonly)
true if an error condition exists; false otherwise
944 945 946 |
# File 'lib/nexpose.rb', line 944 def error @error end |
#error_msg ⇒ Object (readonly)
Error message string
946 947 948 |
# File 'lib/nexpose.rb', line 946 def error_msg @error_msg end |
#host ⇒ Object (readonly)
The hostname or IP Address of the NSC
954 955 956 |
# File 'lib/nexpose.rb', line 954 def host @host end |
#password ⇒ Object (readonly)
The password used to login to the NSC
960 961 962 |
# File 'lib/nexpose.rb', line 960 def password @password end |
#port ⇒ Object (readonly)
The port of the NSC (default is 3780)
956 957 958 |
# File 'lib/nexpose.rb', line 956 def port @port end |
#request_xml ⇒ Object (readonly)
The last XML request sent by this object
948 949 950 |
# File 'lib/nexpose.rb', line 948 def request_xml @request_xml end |
#response_xml ⇒ Object (readonly)
The last XML response received by this object
950 951 952 |
# File 'lib/nexpose.rb', line 950 def response_xml @response_xml end |
#session_id ⇒ Object (readonly)
Session ID of this connection
952 953 954 |
# File 'lib/nexpose.rb', line 952 def session_id @session_id end |
#url ⇒ Object (readonly)
The URL for communication
962 963 964 |
# File 'lib/nexpose.rb', line 962 def url @url end |
#username ⇒ Object (readonly)
The username used to login to the NSC
958 959 960 |
# File 'lib/nexpose.rb', line 958 def username @username end |
Instance Method Details
#download(url) ⇒ Object
Download a specific URL
1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/nexpose.rb', line 1009 def download(url) uri = URI.parse(url) http = Net::HTTP.new(@host, @port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue headers = {'Cookie' => "nexposeCCSessionID=#{@session_id}"} resp, data = http.get(uri.path, headers) data end |
#execute(xml, version = '1.1') ⇒ Object
Execute an API request
1003 1004 1005 1006 |
# File 'lib/nexpose.rb', line 1003 def execute(xml, version = '1.1') @api_version = version APIRequest.execute(@url.sub('VERSION_STRING', @api_version),xml.to_s, @api_version) end |
#login ⇒ Object
Establish a new connection and Session ID
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
# File 'lib/nexpose.rb', line 977 def login begin login_hash = { 'sync-id' => 0, 'password' => @password, 'user-id' => @username } unless @silo_id.nil? login_hash['silo-id'] = @silo_id end r = execute(make_xml('LoginRequest', login_hash)) rescue APIError raise AuthenticationFailed.new(r) end if(r.success) @session_id = r.sid return true end end |