-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathnexposeBackup.rb
59 lines (43 loc) · 1.21 KB
/
nexposeBackup.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
#!/usr/bin/env ruby
# Brian W. Gray
# 07.14.2014
## Script generates a Platform Independent application backup.
require 'yaml'
require 'nexpose'
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"]
nsc = Nexpose::Connection.new(@host, @userid, @password, @port)
puts 'logging into Nexpose'
begin
nsc.login
rescue ::Nexpose::APIError => err
$stderr.puts("Connection failed: #{e.reason}")
exit(1)
end
puts 'logged into Nexpose'
at_exit { nsc.logout }
begin
# Check scan activity wait until there are no scans running
active_scans = nsc.scan_activity
if active_scans.any?
puts "Current scan status: #{active_scans.to_s}"
sleep(15)
end
end while active_scans.any?
time = Time.new
backupDescription = time.strftime("%Y%m%d")+"_PI_Weekly"
# Base backup code use from https://community.rapid7.com/thread/4687
# Start the backup
if active_scans.empty?
platform_independent = true
puts "Initiating Platform Independent backup to local disk"
nsc.backup(platform_independent, backupDescription)
else
end
puts 'Logging out'
exit