Class: PxnxJruby::NexposeConnection
- Inherits:
-
Object
- Object
- PxnxJruby::NexposeConnection
- Includes:
- Callable
- Defined in:
- lib/pxnx_jruby/nexpose_connection.rb
Instance Attribute Summary collapse
-
#devices_to_quarantine ⇒ Object
Returns the value of attribute devices_to_quarantine.
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#nsc ⇒ Object
Returns the value of attribute nsc.
-
#scan_info ⇒ Object
Returns the value of attribute scan_info.
-
#site ⇒ Object
Returns the value of attribute site.
Class Method Summary collapse
Instance Method Summary collapse
-
#call ⇒ Object
TODO Allow scan options.
-
#initialize(ips, options = {}) ⇒ NexposeConnection
constructor
A new instance of NexposeConnection.
Constructor Details
#initialize(ips, options = {}) ⇒ NexposeConnection
Returns a new instance of NexposeConnection.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 14 def initialize(ips, = {}) @log = LoggerFactory.getLogger(NexposeConnection.become_java!) @nsc = Nexpose::Connection.new([:nexpose_data][:nxconsole], [:nexpose_data][:nxuser], ENV['NEXPOSE_PASSWORD'], [:nexpose_data][:nexpose_port]) @log.info("Connecting to nexpose console: #{options[:nexpose_data][:nxconsole]}.") @nsc.login @ip_list = ips = end |
Instance Attribute Details
#devices_to_quarantine ⇒ Object
Returns the value of attribute devices_to_quarantine.
12 13 14 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 12 def devices_to_quarantine @devices_to_quarantine end |
#ip ⇒ Object
Returns the value of attribute ip.
12 13 14 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 12 def ip @ip end |
#nsc ⇒ Object
Returns the value of attribute nsc.
12 13 14 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 12 def nsc @nsc end |
#scan_info ⇒ Object
Returns the value of attribute scan_info.
12 13 14 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 12 def scan_info @scan_info end |
#site ⇒ Object
Returns the value of attribute site.
12 13 14 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 12 def site @site end |
Class Method Details
.is_valid_scan_template(options) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 64 def self.is_valid_scan_template() nsc = Nexpose::Connection.new([:nexpose_data][:nxconsole], [:nexpose_data][:nxuser], ENV['NEXPOSE_PASSWORD'], [:nexpose_data][:nexpose_port]) nsc.login PxnxJruby::NxLogger.instance.on_connect([:nexpose_data][:nxconsole], [:nexpose_data][:nexpose_port], nsc.session_id, "{}") return nsc.list_scan_templates.select{|template_summary| template_summary.id.eql?([:nexpose_data][:scan_template_id])}.any? end |
Instance Method Details
#call ⇒ Object
TODO Allow scan options.
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 62 |
# File 'lib/pxnx_jruby/nexpose_connection.rb', line 27 def call begin @ip = @ip_list.is_a?(Array) ? @ip_list : Array.new(1, @ip_list) @site = Nexpose::Site.new("pxGrid-Nexpose-#{DateTime.now.strftime('%Y%jT%H%M%SZ')}", [:nexpose_data][:scan_template_id]) @site.description = "Rapid7 Nexpose - Cisco pxGrid Integration scan job saved at #{DateTime.now.strftime('%Y%jT%H%M%SZ')}" @log.info("Scanning IPs <#{@ip.each{|ip| ip}}> on site <#{@site.name}>.") @ip.each { |ip| @site.add_ip(ip) } @site.engine = [:nexpose_data][:engine] unless .empty? @site.save(@nsc) @scan_info = @site.scan(@nsc) # Hold this thread until the scan has finished # Add ', :verbose => true' to get more info. WaitUtil.wait_for_condition('waiting_for_scan_to_finish', :timeout_sec => [:nexpose_data][:scan_timeout], :delay_sec => 30) do @completed = true if %w(unknown dispatched running integrating).include? (@nsc.scan_status(@scan_info.id)) @completed = false @log.debug("Scan still running for site <#{@site.name}>") end @completed end @log.info("Scan completed for site #{@site.name}>") devices = @nsc.devices(@site.id) @devices_to_quarantine = devices.map { |d| d.address if d.risk_score >= [:nexpose_data][:riskscore]} Thread.new do eps_broker = PxnxJruby::EpsBroker.new([:grid_connection].grid) @log.info("Quarantining device(s) <#{@devices_to_quarantine}> for site <#{@site.name}>.") eps_broker.quarantine_ip(@devices_to_quarantine) unless @devices_to_quarantine.empty? end unless [:debug] == true @log.debug("Deleting temporary site <#{@site.name}>, logging out and exiting.") @site.delete(@nsc) unless [:debug] == true @nsc.logout unless [:debug] == true rescue Exception => e @log.error("Exception while running a Nexpose connection thread! Message is <#{e.message}> and stacktrace is <#{e.backtrace.join("\n")}>.") end end |