-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscanAssetGroup.rb
67 lines (48 loc) · 1.45 KB
/
scanAssetGroup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
62
63
64
65
66
67
#!/usr/bin/env ruby
# Date Created: 04.30.2014
# Written by: BrianWGray
## Script performs the following tasks
## 1.) Initiates scans for assets located within a specified asset Group ID
require 'yaml'
require 'nexpose'
require 'optparse'
require 'highline/import'
require 'csv'
include Nexpose
# Default Values
config = YAML.load_file("conf/nexpose.yaml") # From file
@host = config["hostname"]
@userid = config["username"]
@password = config["passwordkey"]
@port = config["port"]
OptionParser.new do |opts|
opts.banner = "Usage: #{File::basename($0)} [Asset Group ID number] [options]"
opts.separator ''
opts.separator 'This script will re-launch scans against a provided asset group id number.'
opts.separator ''
opts.separator 'Note that this script will always prompt for a connection password.'
opts.separator ''
opts.separator 'Options:'
opts.on_tail('--help', 'Print this help message.') { puts opts; exit }
end.parse!
unless ARGV[0]
$stderr.puts 'Asset Group ID Required.'
exit(1)
end
@agid = ARGV[0]
nsc = Nexpose::Connection.new(@host, @userid, @password, @port)
puts 'logging into Nexpose'
begin
nsc.login
rescue ::Nexpose::APIError => err
$stderr.puts("Connection failed: #{err.reason}")
exit(1)
end
puts 'logged into Nexpose'
at_exit { nsc.logout }
puts "Initializing scans for Site ID #{@agid}"
group = AssetGroup.load(nsc, @agid)
scans = group.rescan_assets(nsc)
puts 'Scan jobs submitted'
puts 'Logging out'
exit