Class: Nexpose::Engine

Inherits:
Object
  • Object
show all
Includes:
Sanitize
Defined in:
lib/nexpose/engine.rb

Overview

Engine connnection to a Nexpose console.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sanitize

#replace_entities

Constructor Details

#initialize(address, name = nil, port = 40814) ⇒ Engine

Returns a new instance of Engine.



113
114
115
116
117
118
119
120
121
# File 'lib/nexpose/engine.rb', line 113

def initialize(address, name = nil, port = 40814)
  @id = -1
  @address = address
  @name = name
  @name ||= address
  @port = port
  @scope = 'silo'
  @sites = []
end

Instance Attribute Details

#addressObject

The IP address or DNS name of a scan engine.



98
99
100
# File 'lib/nexpose/engine.rb', line 98

def address
  @address
end

#idObject

Unique numeric identifier for the scan engine, assigned by the console in the order of creation.



96
97
98
# File 'lib/nexpose/engine.rb', line 96

def id
  @id
end

#nameObject

A name assigned to the scan engine by the security console.



100
101
102
# File 'lib/nexpose/engine.rb', line 100

def name
  @name
end

#portObject

The port on which the engine listens for requests from the security console.



103
104
105
# File 'lib/nexpose/engine.rb', line 103

def port
  @port
end

#priorityObject

Relative priority of a scan engine. One of: very-low, low, normal, high, very-high



108
109
110
# File 'lib/nexpose/engine.rb', line 108

def priority
  @priority
end

#scopeObject

Whether the engine has a global or silo-specific scope.



105
106
107
# File 'lib/nexpose/engine.rb', line 105

def scope
  @scope
end

#sitesObject

Sites to which the scan engine is assigned.



111
112
113
# File 'lib/nexpose/engine.rb', line 111

def sites
  @sites
end

Class Method Details

.load(connection, id) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/nexpose/engine.rb', line 123

def self.load(connection, id)
  xml = '<EngineConfigRequest session-id="' + connection.session_id + '"'
  xml << %( engine-id="#{id}")
  xml << ' />'
  r = connection.execute(xml, '1.2')

  if r.success
    r.res.elements.each('EngineConfigResponse/EngineConfig') do |config|
      engine = Engine.new(config.attributes['address'],
                          config.attributes['name'],
                          config.attributes['port'])
      engine.id = config.attributes['id']
      engine.scope = config.attributes['scope'] if config.attributes['scope']
      engine.priority = config.attributes['priority'] if config.attributes['priority']
      config.elements.each('Site') do |site|
        engine.sites << SiteSummary.new(site.attributes['id'], site.attributes['name'])
      end
      return engine
    end
  end
  nil
end

Instance Method Details

#add_site(site_id) ⇒ Object

Assign a site to this scan engine.

Parameters:

  • site_id (Fixnum)

    Unique numerical ID of the site.



150
151
152
# File 'lib/nexpose/engine.rb', line 150

def add_site(site_id)
  sites << SiteSummary.new(site_id, nil)
end

#delete(connection) ⇒ Object

Delete this scan engine configuration from the security console.

Parameters:

  • connection (Connection)

    Connection to console where site exists.



194
195
196
# File 'lib/nexpose/engine.rb', line 194

def delete(connection)
  connection.delete_engine(@id, @scope)
end

#save(connection) ⇒ Fixnum

Save this engine configuration to the security console.

Parameters:

  • connection (Connection)

    Connection to console where site exists.

Returns:

  • (Fixnum)

    ID assigned to the scan engine.



177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/nexpose/engine.rb', line 177

def save(connection)
  xml = '<EngineSaveRequest session-id="' + connection.session_id + '">'
  xml << to_xml
  xml << '</EngineSaveRequest>'

  r = connection.execute(xml, '1.2')
  if r.success
    r.res.elements.each('EngineSaveResponse/EngineConfig') do |v|
      return @id = v.attributes['id']
    end
  end
end

#to_xmlObject



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/nexpose/engine.rb', line 156

def to_xml
  xml = '<EngineConfig'
  xml << %( id="#{id}")
  xml << %( address="#{address}")
  xml << %( name="#{replace_entities(name)}")
  xml << %( port="#{port}")
  xml << %( scope="#{scope}") if scope
  xml << %( priority="#{priority}") if priority
  xml << '>'
  sites.each do |site|
    xml << %(<Site id="#{site.id}" />)
  end
  xml << '</EngineConfig>'
  xml
end