nexpose 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0443897c1940a9c3099ecc230589e7925fca9697
4
- data.tar.gz: e31a6036c4170c0fa796b961973601bc9d5db6bb
3
+ metadata.gz: 5bd3b5a70f4342a50d856fede506bd98df0dc3eb
4
+ data.tar.gz: dbdcbcd5fa044c89254d8708ba5c1c51a2c0ca8e
5
5
  SHA512:
6
- metadata.gz: e9b887b9f2564478be53d7b45271d1035fef4f51d19e87f5a729ce0423d1571eb0c9e145f3eba7726992a936596e7db5f6f8b2fbe174f98444ab32ef44f77566
7
- data.tar.gz: 636f2e44bb5b141a5d3d670b4f8290009af0e1f1dc5d2aeea6b1e2c77687f99d6483f6d063fbd696e1f558ac679dc58915dd896103cc7baa8786ddba5793b3c7
6
+ metadata.gz: 55eae9f2e3a7127ed26d893fcb8d03a63c1ec30bb7fd3f3e841bfd7589c58809289a0f9507fafb185570df673cf0810674d043fdd0c8208e093844f5f046ec18
7
+ data.tar.gz: ac462779de54270a9cde72dcb7bae47a22f3d36b34f4d094f067cd2fc74afc1f48c812b4b0981761b2d7eef886a4a42789b9fc8a7523175cd043039acfdfd8d8
@@ -1,13 +1,13 @@
1
1
  # Nexpose-Client
2
2
  [![Gem Version](https://badge.fury.io/rb/nexpose.svg)](http://badge.fury.io/rb/nexpose) [![Build Status](https://travis-ci.org/rapid7/nexpose-client.svg?branch=master)](https://travis-ci.org/rapid7/nexpose-client) [![Test Coverage](https://codeclimate.com/github/rapid7/nexpose-client/badges/coverage.svg)](https://codeclimate.com/github/rapid7/nexpose-client) [![Inline docs](http://inch-ci.org/github/rapid7/nexpose-client.svg?branch=master)](http://inch-ci.org/github/rapid7/nexpose-client) [![Code Climate](https://codeclimate.com/github/rapid7/nexpose-client/badges/gpa.svg)](https://codeclimate.com/github/rapid7/nexpose-client)
3
3
 
4
- This is the official gem package for the Ruby Nexpose API.
4
+ This is the official gem package for the Ruby Nexpose API client library.
5
5
 
6
- For assistance with using the gem, to share your scripts, or to discuss different approaches, please visit the Rapid7 forums for Nexpose: https://community.rapid7.com/community/nexpose/nexpose-apis
6
+ For assistance with using the gem, to share your scripts, or to discuss different approaches, please visit the Rapid7 community: https://community.rapid7.com/
7
7
 
8
- Check out https://github.com/rapid7/nexpose-client/wiki for walk-throughs and release notes for recent versions.
8
+ Check out the [wiki](https://github.com/rapid7/nexpose-client/wiki) for walk-throughs and other documentation. Submit bugs and feature requests on the [issues](https://github.com/rapid7/nexpose-client/issues) page.
9
9
 
10
- This gem is heavily used for internal, automated testing of the Nexpose product. It provides calls to the Nexpose XML APIs version 1.1 and 1.2 (except for some multi-tenant operations). It also includes a number of helper methods which are not currently exposed through alternate means.
10
+ This gem is heavily used for internal, automated testing of the Nexpose product. It provides calls to the Nexpose XML APIs version 1.1 and 1.2, and JSON API 2.1. It also includes a number of helper methods which are not currently exposed through alternate means.
11
11
 
12
12
  ## Release Notes
13
13
 
@@ -65,6 +65,7 @@ require 'nexpose/alert'
65
65
  require 'nexpose/ajax'
66
66
  require 'nexpose/api_request'
67
67
  require 'nexpose/asset'
68
+ require 'nexpose/blackout'
68
69
  require 'nexpose/common'
69
70
  require 'nexpose/console'
70
71
  require 'nexpose/credential'
@@ -78,11 +79,13 @@ require 'nexpose/external'
78
79
  require 'nexpose/filter'
79
80
  require 'nexpose/discovery'
80
81
  require 'nexpose/discovery/filter'
82
+ require 'nexpose/global_blackout'
81
83
  require 'nexpose/global_settings'
82
84
  require 'nexpose/group'
83
85
  require 'nexpose/dag'
84
86
  require 'nexpose/manage'
85
87
  require 'nexpose/multi_tenant_user'
88
+ require 'nexpose/password_policy'
86
89
  require 'nexpose/pool'
87
90
  require 'nexpose/report'
88
91
  require 'nexpose/report_template'
@@ -0,0 +1,44 @@
1
+ module Nexpose
2
+ # Constants useful across the Nexpose module.
3
+ # Configuration structure for blackouts.
4
+ class Blackout < APIObject
5
+ # Whether or not this blackout is enabled.
6
+ attr_accessor :enabled
7
+ # Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.
8
+ attr_accessor :blackout_type
9
+ # The repeat interval based upon type.
10
+ attr_accessor :blackout_interval
11
+ # The earliest date to generate the report on (in ISO 8601 format).
12
+ attr_accessor :blackout_start
13
+ # The amount of time, in minutes, a blackout period should last.
14
+ attr_accessor :blackout_duration
15
+
16
+ def initialize(start, enabled=true, duration, type, interval)
17
+ @blackout_start = start
18
+ @enabled =enabled
19
+ @blackout_duration = duration.to_i
20
+ @blackout_type = type
21
+ @blackout_interval = interval.to_i
22
+ end
23
+
24
+ def self.from_hash(hash)
25
+ repeat_blackout_hash = hash[:repeat_blackout]
26
+ blackout = new(hash[:start_date], hash[:blackout_duration], repeat_blackout_hash[:type], repeat_blackout_hash[:interval])
27
+ blackout
28
+ end
29
+
30
+ def to_h
31
+ blackout_hash = {
32
+ start_date: @blackout_start,
33
+ enabled: @enabled,
34
+ blackout_duration: @blackout_duration,
35
+ }
36
+ repeat_hash= {
37
+ type: @blackout_type,
38
+ interval: @blackout_interval
39
+ }
40
+ blackout_hash[:repeat_blackout] = repeat_hash
41
+ blackout_hash
42
+ end
43
+ end
44
+ end
@@ -35,6 +35,7 @@ module Nexpose
35
35
  HTTPS = 'HTTPS'
36
36
  LDAP = 'LDAP'
37
37
  LDAPS = 'LDAPS'
38
+ SERVICE_PROXY = 'SERVICE_PROXY'
38
39
  end
39
40
 
40
41
  module Type
@@ -43,6 +44,7 @@ module Nexpose
43
44
  ACTIVESYNC = 'ACTIVESYNC'
44
45
  ACTIVESYNC_POWERSHELL = 'ACTIVESYNC_POWERSHELL'
45
46
  ACTIVESYNC_OFFICE365 = 'ACTIVESYNC_OFFICE365'
47
+ DHCP_SERVICE = 'DHCP_SERVICE'
46
48
  end
47
49
 
48
50
  # A unique identifier for this connection.
@@ -101,22 +103,41 @@ module Nexpose
101
103
  @protocol = Protocol::HTTPS
102
104
  end
103
105
 
104
- # Save this discovery connection to a Nexpose console.
106
+ # Save this discovery connection on a given Nexpose console.
105
107
  #
106
108
  # @param [Connection] nsc Connection to a console.
107
109
  #
108
- def save(nsc)
109
- if @id == -1
110
- xml = nsc.make_xml('DiscoveryConnectionCreateRequest')
111
- else
112
- xml = nsc.make_xml('DiscoveryConnectionUpdateRequest')
113
- end
110
+ def create(nsc)
111
+ xml = nsc.make_xml('DiscoveryConnectionCreateRequest')
114
112
  xml.add_element(as_xml)
113
+
115
114
  response = nsc.execute(xml, '1.2')
116
115
  if response.success
117
116
  ret = REXML::XPath.first(response.res, 'DiscoveryConnectionCreateResponse')
118
117
  @id = ret.attributes['id'].to_i unless ret.nil?
119
118
  end
119
+ end
120
+
121
+ # Update this (existing) discovery connection on a given Nexpose console.
122
+ #
123
+ # @param [Connection] nsc Connection to a console.
124
+ # @return [Boolean] whether the update request was successful
125
+ #
126
+ def update(nsc)
127
+ xml = nsc.make_xml('DiscoveryConnectionUpdateRequest')
128
+ xml.add_element(as_xml)
129
+
130
+ response = nsc.execute(xml, '1.2')
131
+ response.success
132
+ end
133
+
134
+ # Save this discovery connection to a Nexpose console.
135
+ #
136
+ # @param [Connection] nsc Connection to a console.
137
+ #
138
+ def save(nsc)
139
+ @id == -1 ? create(nsc) : update(nsc)
140
+
120
141
  @id
121
142
  end
122
143
 
@@ -168,6 +189,7 @@ module Nexpose
168
189
  xml.attributes['exchange-password'] = @exchange_password if @exchange_password
169
190
  xml.attributes['type'] = @type if @type
170
191
  xml.attributes['engine-id'] = @engine_id if @engine_id && @engine_id != -1
192
+ xml.attributes['id'] = @id if @id && @id != -1
171
193
  xml
172
194
  end
173
195
 
@@ -0,0 +1,43 @@
1
+ module Nexpose
2
+
3
+ class GlobalBlackout < APIObject
4
+ require 'json'
5
+ include JsonSerializer
6
+
7
+ # [Array] Blackout starting dates, times and duration for blackout periods.
8
+ attr_accessor :blackout
9
+
10
+ def initialize(blackout)
11
+ @blackout = Array(blackout)
12
+ end
13
+
14
+ def save(nsc)
15
+ params = to_json
16
+ AJAX.post(nsc, '/api/2.1/silo_blackout/', params, AJAX::CONTENT_TYPE::JSON)
17
+ end
18
+
19
+ def to_h
20
+ {
21
+ blackouts:
22
+ (@blackout || []).map { |blackout| blackout.to_h }
23
+ }
24
+ end
25
+
26
+ def to_json
27
+ JSON.generate(to_h)
28
+ end
29
+
30
+ def self.json_initializer(data)
31
+ new(blackout: data)
32
+ end
33
+
34
+ def self.load(nsc)
35
+ uri = '/api/2.1/silo_blackout/'
36
+ resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
37
+ hash = JSON.parse(resp, symbolize_names: true)
38
+ blackout = self.json_initializer(hash).deserialize(hash)
39
+ blackout.blackout = (hash[:blackouts] || []).map { |blackout| Nexpose::Blackout.from_hash(blackout) }
40
+ blackout
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,57 @@
1
+ module Nexpose
2
+ require 'json'
3
+ # Configuration structure for password policies.
4
+ class PasswordPolicy < APIObject
5
+ attr_accessor :policy_name
6
+ attr_accessor :min_length
7
+ attr_accessor :max_length
8
+ attr_accessor :capitals
9
+ attr_accessor :digits
10
+ attr_accessor :special_chars
11
+
12
+ def initialize(policy_name:, min_length:, max_length:, special_chars:, capitals:, digits:)
13
+ @policy_name = policy_name.to_s
14
+ @min_length = min_length.to_i
15
+ @max_length = max_length.to_i
16
+ @special_chars = special_chars.to_i
17
+ @capitals = capitals.to_i
18
+ @digits = digits.to_i
19
+ end
20
+
21
+ def self.from_hash(hash)
22
+ new(policy_name: hash[:policyName],
23
+ min_length: hash[:minLength],
24
+ max_length: hash[:maxLength],
25
+ special_chars: hash[:specialChars],
26
+ capitals: hash[:capitals],
27
+ digits: hash[:digits])
28
+ end
29
+
30
+ def to_h
31
+ {
32
+ policyName: @policy_name,
33
+ minLength: @min_length,
34
+ maxLength: @max_length,
35
+ specialChars: @special_chars,
36
+ capitals: @capitals,
37
+ digits: @digits
38
+ }
39
+ end
40
+
41
+ def to_json
42
+ JSON.generate(to_h)
43
+ end
44
+
45
+ def save(nsc)
46
+ params = to_json
47
+ AJAX.post(nsc, '/api/2.1/password_policy/', params, AJAX::CONTENT_TYPE::JSON)
48
+ end
49
+
50
+ def self.load(nsc)
51
+ uri = '/api/2.1/password_policy/'
52
+ resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
53
+ hash = JSON.parse(resp, symbolize_names: true)
54
+ self.from_hash(hash)
55
+ end
56
+ end
57
+ end
@@ -108,6 +108,8 @@ module Nexpose
108
108
  # [Array] Schedule starting dates and times for scans, and set their frequency.
109
109
  attr_accessor :schedules
110
110
 
111
+ # [Array] Blackout starting dates, times and duration for blackout periods.
112
+ attr_accessor :blackouts
111
113
 
112
114
  # The risk factor associated with this site. Default: 1.0
113
115
  attr_accessor :risk_factor
@@ -162,6 +164,7 @@ module Nexpose
162
164
  @risk_factor = 1.0
163
165
  @config_version = 3
164
166
  @schedules = []
167
+ @blackouts = []
165
168
  @included_scan_targets = { addresses: [], asset_groups: [] }
166
169
  @excluded_scan_targets = { addresses: [], asset_groups: [] }
167
170
  @site_credentials = []
@@ -463,7 +466,7 @@ module Nexpose
463
466
  asset_groups: @excluded_scan_targets[:asset_groups].compact
464
467
  }
465
468
 
466
- {
469
+ hash = {
467
470
  id: @id,
468
471
  name: @name,
469
472
  description: @description,
@@ -484,6 +487,11 @@ module Nexpose
484
487
  organization: @organization.to_h,
485
488
  users: users
486
489
  }
490
+ # @TODO: Revisit this for 2.0.0 update
491
+ # Only pass in blackouts if they were actually specified (for backwards compatibility)
492
+ hash[:blackouts] = @blackouts.map(&:to_h) if @blackouts && @blackouts.any?
493
+
494
+ hash
487
495
  end
488
496
 
489
497
  require 'json'
@@ -510,6 +518,7 @@ module Nexpose
510
518
 
511
519
  site.organization = Organization.create(site.organization)
512
520
  site.schedules = (hash[:schedules] || []).map {|schedule| Nexpose::Schedule.from_hash(schedule) }
521
+ site.blackouts = (hash[:blackouts] || []).map {|blackout| Nexpose::Blackout.from_hash(blackout) }
513
522
  site.site_credentials = hash[:site_credentials].map {|cred| Nexpose::SiteCredentials.new.object_from_hash(nsc,cred)}
514
523
  site.shared_credentials = hash[:shared_credentials].map {|cred| Nexpose::SiteCredentials.new.object_from_hash(nsc,cred)}
515
524
  site.discovery_config = Nexpose::DiscoveryConnection.new.object_from_hash(nsc, hash[:discovery_config]) unless hash[:discovery_config].nil?
@@ -67,6 +67,7 @@ module Nexpose
67
67
  cred.port_restriction = port
68
68
  cred.service = service
69
69
  cred.scope = Credential::Scope::SITE_SPECIFIC
70
+ cred.permission_elevation_type = Credential::ElevationType::NONE
70
71
  cred
71
72
  end
72
73
 
@@ -1,4 +1,4 @@
1
1
  module Nexpose
2
2
  # The latest version of the Nexpose gem
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nexpose/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'nexpose'
8
+ s.version = Nexpose::VERSION
9
+ s.homepage = 'https://github.com/rapid7/nexpose-client'
10
+ s.summary = 'Ruby API for Rapid7 Nexpose'
11
+ s.description = 'This gem provides a Ruby API to the Nexpose vulnerability management product by Rapid7.'
12
+ s.license = 'BSD'
13
+ s.authors = ['HD Moore', 'Chris Lee', 'Michael Daines', 'Brandon Turner', 'Gavin Schneider', 'Scott Green']
14
+ s.email = ['hd_moore@rapid7.com', 'christopher_lee@rapid7.com', 'michael_daines@rapid7.com', 'brandon_turner@rapid7.com', 'gavin_schneider@rapid7.com', 'scott_green@rapid7.com']
15
+ s.files = Dir['[A-Z]*'] + Dir['lib/**/*']
16
+ s.require_paths = ['lib']
17
+ s.extra_rdoc_files = ['README.markdown']
18
+ s.required_ruby_version = '>= 2.1'
19
+ s.platform = 'ruby'
20
+
21
+ s.add_runtime_dependency('rex', '~> 2.0', '>= 2.0.8')
22
+
23
+ s.add_development_dependency('bundler', '~> 1.3')
24
+ s.add_development_dependency('codeclimate-test-reporter', '~> 0.4.6')
25
+ s.add_development_dependency('simplecov', '~> 0.9.1')
26
+ s.add_development_dependency('rspec', '~> 3.2')
27
+ s.add_development_dependency('rubocop', '~> 0.29.0')
28
+ s.add_development_dependency('webmock', '~> 1.20.4')
29
+ s.add_development_dependency('vcr', '~> 2.9.3')
30
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexpose
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - HD Moore
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2015-04-08 00:00:00.000000000 Z
16
+ date: 2015-06-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rex
@@ -160,6 +160,7 @@ files:
160
160
  - lib/nexpose/api.rb
161
161
  - lib/nexpose/api_request.rb
162
162
  - lib/nexpose/asset.rb
163
+ - lib/nexpose/blackout.rb
163
164
  - lib/nexpose/common.rb
164
165
  - lib/nexpose/connection.rb
165
166
  - lib/nexpose/console.rb
@@ -173,12 +174,14 @@ files:
173
174
  - lib/nexpose/error.rb
174
175
  - lib/nexpose/external.rb
175
176
  - lib/nexpose/filter.rb
177
+ - lib/nexpose/global_blackout.rb
176
178
  - lib/nexpose/global_settings.rb
177
179
  - lib/nexpose/group.rb
178
180
  - lib/nexpose/json_serializer.rb
179
181
  - lib/nexpose/maint.rb
180
182
  - lib/nexpose/manage.rb
181
183
  - lib/nexpose/multi_tenant_user.rb
184
+ - lib/nexpose/password_policy.rb
182
185
  - lib/nexpose/pool.rb
183
186
  - lib/nexpose/report.rb
184
187
  - lib/nexpose/report_template.rb
@@ -202,6 +205,7 @@ files:
202
205
  - lib/nexpose/vuln_exception.rb
203
206
  - lib/nexpose/wait.rb
204
207
  - lib/nexpose/web_credentials.rb
208
+ - nexpose.gemspec
205
209
  homepage: https://github.com/rapid7/nexpose-client
206
210
  licenses:
207
211
  - BSD
@@ -222,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
226
  version: '0'
223
227
  requirements: []
224
228
  rubyforge_project:
225
- rubygems_version: 2.4.5
229
+ rubygems_version: 2.4.6
226
230
  signing_key:
227
231
  specification_version: 4
228
232
  summary: Ruby API for Rapid7 Nexpose