Nessus6 0.1.8 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/bin/launch_incoming_scans +54 -0
- data/bin/launch_incoming_scans.sh +90 -0
- data/lib/Nessus6/scan.rb +52 -2
- data/lib/Nessus6/user.rb +1 -1
- data/lib/Nessus6/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f946afee24ef43e6b6628db34f17781d12d4ee9c
|
4
|
+
data.tar.gz: d143fca91c08c8cf0180f51410dc6e7fce95ffcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79d967ef973421555e7bb5b6a0ca06bf342480f44de6a3c5b8c8943076f90f96aeacc143ba59599d094cf1387455b6b60cf7bc3b6f9ce0161e0b4ce12b90630
|
7
|
+
data.tar.gz: 517c90f4d10b8b2fabc6050143b36c8a9acb974e58ccca8c604c79a25da353599758eda73355a6df880544da35350ba28e5064ddcbd065278ee16e7e05d647a6
|
data/.travis.yml
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'Nessus6'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'logger'
|
6
|
+
|
7
|
+
# Global variables for the script / binary
|
8
|
+
@base_directory = '/opt/scanner'
|
9
|
+
@temp_directory = "#{@base_directory}/temp#{Process.pid}"
|
10
|
+
@incoming_directory = "#{@base_directory}/targets/incoming"
|
11
|
+
@results_directory = "#{@base_directory}/results"
|
12
|
+
@send_mail = '/usr/lib/sendmail -t'
|
13
|
+
|
14
|
+
credentials = {
|
15
|
+
access_key: 'eeb88394142b4b328332c2448e0f04846161493a50feaa454cbb2fa5083919f9',
|
16
|
+
secret_key: 'b0d69c23612754367a84d168f2e7d6769aff1342cb25aa345481cb537164e092'
|
17
|
+
}
|
18
|
+
|
19
|
+
nessus_location = {
|
20
|
+
ip: 'localhost',
|
21
|
+
port: '8834'
|
22
|
+
}
|
23
|
+
|
24
|
+
@append_results = "x-scanner|#{nessus_location[:ip]}"
|
25
|
+
|
26
|
+
# Prep work
|
27
|
+
FileUtils.mkdir_p @temp_directory
|
28
|
+
@logger = Logger.new(STDOUT)
|
29
|
+
@logger.level = Logger::INFO
|
30
|
+
|
31
|
+
# Begin the main portion of the app
|
32
|
+
@logger.debug 'Creating Nessus API Client'
|
33
|
+
@client = Nessus6::Client.new credentials, nessus_location
|
34
|
+
|
35
|
+
Dir.foreach(@incoming_directory) do |file|
|
36
|
+
@logger.debug "Processing #{@incoming_directory}/#{file}"
|
37
|
+
next if file == '.' || file == '..' # skip current / parent directory opts
|
38
|
+
|
39
|
+
@logger.info "Archiving #{@incoming_directory}/#{file} to " \
|
40
|
+
"#{@base_directory}/targets/archive/#{file}."
|
41
|
+
# FileUtils.copy "#{@incoming_directory}/#{file}",
|
42
|
+
# "#{@base_directory}/targets/archive/#{file}"
|
43
|
+
|
44
|
+
@logger.info "Moving #{@incoming_directory}/#{file} to " \
|
45
|
+
"#{@temp_directory}/#{file}"
|
46
|
+
# FileUtils.move "#{@incoming_directory}/#{file}",
|
47
|
+
# "#{@temp_directory}/#{file}"
|
48
|
+
|
49
|
+
@logger.info 'Finding the request ID in the file.'
|
50
|
+
request_id = File.readlines("#{@incoming_directory}/#{file}").select do |line|
|
51
|
+
line =~ /^requestid.*$/
|
52
|
+
end
|
53
|
+
puts request_id
|
54
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
#
|
4
|
+
# Script looks for target files in incoming directory, and launches Nessus
|
5
|
+
#
|
6
|
+
|
7
|
+
BASEDIR=/opt/scanner
|
8
|
+
TEMPDIR=${BASEDIR}/temp$$
|
9
|
+
INCOMINGDIR=${BASEDIR}/targets/incoming
|
10
|
+
RESULTSDIR=${BASEDIR}/results
|
11
|
+
SENDMAIL="/usr/lib/sendmail -t"
|
12
|
+
|
13
|
+
NESSUSBIN=/opt/nessus/bin/nessus
|
14
|
+
NESSUSUSER=scripts
|
15
|
+
NESSUSPASSWORD=XXXXXXXXXXXXXXX
|
16
|
+
|
17
|
+
IPADDR="153.39.86.90"
|
18
|
+
APPENDRESULTS="x-scanner|${IPADDR}"
|
19
|
+
|
20
|
+
mkdir -p ${TEMPDIR}
|
21
|
+
|
22
|
+
#
|
23
|
+
# Grab one file in incoming directory
|
24
|
+
#
|
25
|
+
FILES=`cd ${INCOMINGDIR}; ls -r -1 *.txt | tail -n 1`
|
26
|
+
for file in $FILES
|
27
|
+
do
|
28
|
+
echo "Moving ${INCOMINGDIR}/${file} to ${TEMPDIR}/${file}..."
|
29
|
+
cp ${INCOMINGDIR}/${file} ${BASEDIR}/targets/archive/${file}
|
30
|
+
mv ${INCOMINGDIR}/${file} ${TEMPDIR}/${file}
|
31
|
+
if [ $? -eq 0 ]
|
32
|
+
then
|
33
|
+
#
|
34
|
+
# Find request id
|
35
|
+
#
|
36
|
+
REQUESTID=`cat ${TEMPDIR}/${file} | grep "requestid" | awk '{ print $2 }'`
|
37
|
+
if [ -z ${REQUESTID} ]
|
38
|
+
then
|
39
|
+
REQUESTID=`date -u +%s`
|
40
|
+
else
|
41
|
+
APPENDRESULTS="${APPENDRESULTS}
|
42
|
+
x-requestid|${REQUESTID}"
|
43
|
+
fi
|
44
|
+
|
45
|
+
#
|
46
|
+
# Find scanning method and nessusrc
|
47
|
+
#
|
48
|
+
METHOD=`cat ${TEMPDIR}/${file} | grep "method" | awk '{ print $2 }'`
|
49
|
+
if [ -z ${METHOD} ]
|
50
|
+
then
|
51
|
+
METHOD="default"
|
52
|
+
fi
|
53
|
+
|
54
|
+
# NESSUSRC="${NESSUSRC}.${METHOD}"
|
55
|
+
NESSUSRC="${BASEDIR}/${METHOD}.nessusrc"
|
56
|
+
|
57
|
+
#
|
58
|
+
# Create target file
|
59
|
+
#
|
60
|
+
TARGETFILE=${TEMPDIR}/tmp_target_${IPADDR}_${REQUESTID}.txt
|
61
|
+
RESULTSFILE=${TEMPDIR}/results_${IPADDR}_${REQUESTID}_$$.nbe
|
62
|
+
echo "Creating ${TARGETFILE}..."
|
63
|
+
cat ${TEMPDIR}/${file} | grep "\/" > ${TARGETFILE}
|
64
|
+
|
65
|
+
#
|
66
|
+
# Launch Nessus
|
67
|
+
#
|
68
|
+
echo "Launching Nessus..."
|
69
|
+
${NESSUSBIN} -x -q -c ${NESSUSRC} 127.0.0.1 1241 ${NESSUSUSER} ${NESSUSPASSWORD} ${TARGETFILE} ${RESULTSFILE}
|
70
|
+
if [ $? -eq 0 ] && [ -s ${RESULTSFILE} ]
|
71
|
+
then
|
72
|
+
echo "${APPENDRESULTS}" >> ${RESULTSFILE}
|
73
|
+
else
|
74
|
+
# Nessus failed, move target file back to incoming dir
|
75
|
+
mv ${TEMPDIR}/${file} ${INCOMINGDIR}/${file}
|
76
|
+
rm -rf ${TEMPDIR}
|
77
|
+
exit 1
|
78
|
+
fi
|
79
|
+
|
80
|
+
echo "Moving ${RESULTSFILE} to ${RESULTSDIR}..."
|
81
|
+
|
82
|
+
# copy results to results dir
|
83
|
+
cp ${RESULTSFILE} ${BASEDIR}/archive
|
84
|
+
mv ${RESULTSFILE} ${RESULTSDIR}/
|
85
|
+
echo "Cleaning up ${TEMPDIR}..."
|
86
|
+
rm ${TARGETFILE} ${TEMPDIR}/${file}
|
87
|
+
fi
|
88
|
+
done
|
89
|
+
|
90
|
+
rmdir --ignore-fail-on-non-empty ${TEMPDIR}
|
data/lib/Nessus6/scan.rb
CHANGED
@@ -11,6 +11,18 @@ module Nessus6
|
|
11
11
|
@client = client
|
12
12
|
end
|
13
13
|
|
14
|
+
# Changes the schedule or policy parameters of a scan
|
15
|
+
#
|
16
|
+
# @param scan_id [String, Fixnum] The id of the scan to change.
|
17
|
+
# @param opts [Hash]
|
18
|
+
# @return [Hash] Returns information about the scan in question.
|
19
|
+
def configure(scan_id, opts)
|
20
|
+
response = client.put "scans/#{scan_id}", opts
|
21
|
+
verify response,
|
22
|
+
not_found: 'Scan does not exist.',
|
23
|
+
internal_server_error: 'Error occurred while saving the configuration'
|
24
|
+
end
|
25
|
+
|
14
26
|
# Copies the given scan. Requires can configure scan permissions
|
15
27
|
#
|
16
28
|
# @param scan_id [String, Fixnum] The id of the scan to export.
|
@@ -28,10 +40,21 @@ module Nessus6
|
|
28
40
|
end
|
29
41
|
|
30
42
|
verify response,
|
31
|
-
not_found:
|
43
|
+
not_found: "Scan with Scan ID of #{scan_id} does not exist.",
|
32
44
|
internal_server_error: 'An error occurred while copying.'
|
33
45
|
end
|
34
46
|
|
47
|
+
# Creates a scan.
|
48
|
+
# This request requires standard user permissions.
|
49
|
+
#
|
50
|
+
# @param opts [Hash] The parameters hash required for creating a scan.
|
51
|
+
# @return [Hash]
|
52
|
+
def create(opts)
|
53
|
+
response = @client.post 'scans', opts
|
54
|
+
verify response,
|
55
|
+
internal_server_error: 'An error occurred while saving the scan.'
|
56
|
+
end
|
57
|
+
|
35
58
|
# Deletes a scan. NOTE: Scans in running, paused or stopping states can not
|
36
59
|
# be deleted. This request requires can configure scan permissions
|
37
60
|
#
|
@@ -54,7 +77,7 @@ module Nessus6
|
|
54
77
|
def delete_history(scan_id, query_params = nil)
|
55
78
|
response = @client.delete "scans/#{scan_id}"
|
56
79
|
verify response,
|
57
|
-
not_found:
|
80
|
+
not_found: "Results were not found for scan #{scan_id}.",
|
58
81
|
internal_server_error: 'Failed to delete the results.'
|
59
82
|
end
|
60
83
|
|
@@ -74,6 +97,33 @@ module Nessus6
|
|
74
97
|
JSON.parse response.body
|
75
98
|
end
|
76
99
|
|
100
|
+
# Downloads an exported scan
|
101
|
+
# This request requires can view scan permissions
|
102
|
+
#
|
103
|
+
# @param scan_id [String, Fixnum] The id of the scan to export
|
104
|
+
# @param file_id [String, Fixnum] The id of the file to download (included in response from /scans/{scan_id}/export)
|
105
|
+
def download(scan_id, file_id, write_path = nil)
|
106
|
+
response = @client.get "scans/#{scan_id}/export/#{file_id}/download"
|
107
|
+
hash_response = verify response,
|
108
|
+
not_found: 'The scan or file does not exist.'
|
109
|
+
|
110
|
+
File.open(write_path, 'w+') { |file| file.write response } unless write_path.nil?
|
111
|
+
hash_response
|
112
|
+
end
|
113
|
+
|
114
|
+
# Export the given scan
|
115
|
+
# This request requires can view scan permissions
|
116
|
+
#
|
117
|
+
# @param scan_id [String, Fixnum] The id of the scan to export
|
118
|
+
# @param opts [Hash] The hash of query parameters
|
119
|
+
def export(scan_id, params)
|
120
|
+
response = @client.post "scans/#{scan_id}/export", params
|
121
|
+
verify response,
|
122
|
+
bad_request: 'Missing required parameters: Scan ID or File Format'\
|
123
|
+
' (:format) are required.',
|
124
|
+
not_found: "Scan ID #{scan_id} could not be found. Please try again"
|
125
|
+
end
|
126
|
+
|
77
127
|
# Launches a scan.
|
78
128
|
#
|
79
129
|
# @param scan_id [String, Fixnum] The id of the scan to launch.
|
data/lib/Nessus6/user.rb
CHANGED
data/lib/Nessus6/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Nessus6
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Kirsche
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -110,6 +110,8 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- bin/console
|
113
|
+
- bin/launch_incoming_scans
|
114
|
+
- bin/launch_incoming_scans.sh
|
113
115
|
- bin/setup
|
114
116
|
- lib/Nessus6.rb
|
115
117
|
- lib/Nessus6/editor.rb
|