rhessus 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-07-28
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ .autotest
2
+ History.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ bin/rhessus
7
+ lib/rhessus.rb
8
+ test/test_rhessus.rb
data/README.txt ADDED
@@ -0,0 +1,50 @@
1
+ = rhessus
2
+
3
+ * FIX (url)
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2009 FIX
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
50
+
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+
6
+ Hoe.spec 'rhessus' do
7
+ # developer('FIX', 'FIX@example.com')
8
+
9
+ # self.rubyforge_name = 'rhessusx' # if different than 'rhessus'
10
+ end
11
+
12
+ # vim: syntax=ruby
data/bin/rhessus ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rhessus'
5
+ require 'daemons'
6
+
7
+ Rhessus.init
8
+
9
+ Daemons.run_proc('rhessus') do
10
+ loop do
11
+ if Rhessus.system_load_ok?
12
+ puts "Attemping to get connection..."
13
+ Rhessus::ScanRunner.checkout.fire!
14
+ end
15
+ sleep(5)
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'activeresource'
3
+ module Rhessus
4
+ class Scan < ActiveResource::Base
5
+ self.site = ""
6
+ class << self
7
+ def checkout
8
+ new.tap do |x|
9
+ begin
10
+ x.load(format.decode(post(:checkout).body))
11
+ puts self
12
+ x.should_fire = true
13
+ rescue Exception => e
14
+ puts e
15
+ x.should_fire = false
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ def checkin(result_string)
22
+ self.results = ::Rhessus.parse_results(result_string)
23
+ puts "Attemping to checkin"
24
+ post(:checkin)
25
+ end
26
+
27
+ def failure
28
+ post(:failure)
29
+ end
30
+
31
+ def should_fire?
32
+ @should_fire
33
+ end
34
+
35
+ def should_fire=(x)
36
+ @should_fire = x
37
+ end
38
+ end
39
+ end
data/lib/rhessus.rb ADDED
@@ -0,0 +1,82 @@
1
+ require File.join 'connections', 'scan'
2
+ require 'optparse'
3
+ require 'fastercsv'
4
+ require 'scan_runner'
5
+ module Rhessus
6
+ VERSION = '0.1.0'
7
+ class << self
8
+ # returns the information necessary to start a scan
9
+ # nessus path, -T nbe -q host name password
10
+ def scanner
11
+ return @scanner if @scanner
12
+ exe = @nessus || `which nessus`.chomp
13
+ exe = '/opt/nessus/bin/nessus ' if exe == ""
14
+ options = " -T nbe -q "
15
+ login = " #{@host || 'localhost'} #{@port || 1241} #{@username} #{@password} "
16
+ @scanner = exe + options + login
17
+ end
18
+
19
+ def parse_results(res)
20
+ puts "Attempting Parse"
21
+ res.split("\n").collect {|x|
22
+ r = x.split("|")
23
+ }.select{|x| x[0] == "results"}.
24
+ collect do |result|
25
+ {:ip => result[2],
26
+ :port => result[3],
27
+ :plugin_id => result[4],
28
+ :severity => (case result[5]
29
+ when "Security Note"
30
+ 0
31
+ when "Security Warning"
32
+ 1
33
+ when "Security Hole"
34
+ 2
35
+ end),
36
+ :details => result[6]
37
+ }
38
+ end
39
+ end
40
+
41
+ # Parse the options
42
+ def init
43
+ @host = 'localhost'
44
+ @username = 'admin'
45
+ @password = 'password'
46
+ OptionParser.new do |opts|
47
+ opts.on('-h', '--host [HOST]',
48
+ "The host running the scanner (default localhost)") do |h|
49
+ @host = h
50
+ end
51
+ opts.on('-u', '--username USER',
52
+ "The username on the nessus scanner") do |u|
53
+ @username = u
54
+ end
55
+ opts.on('-p', '--password PASS',
56
+ "The password for the scanner") do |p|
57
+ @password = p
58
+ end
59
+ opts.on('-o', '--port [PORT]',
60
+ "The port of the nessus scanner (default 1241)") do |p|
61
+ @port = p
62
+ end
63
+ opts.on('-s', '--site SITE', "Site to push uploads (incl. http://)") do |s|
64
+ ::Rhessus::Scan.site = s
65
+ end
66
+ opts.on('-n', '--nessus NESSUS', "Nessus executable (unneeded if in path)") do |n|
67
+ @nessus = n
68
+ end
69
+ opts.on('-H', '--help', "Show this message") do |h|
70
+ puts opts
71
+ exit
72
+ end
73
+ end.parse!
74
+ end
75
+
76
+ # If can locate the average 5 minute load of the system
77
+ # and that load is below .6 or the user-defined threshold, returns true
78
+ def system_load_ok?
79
+ true
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,69 @@
1
+ require 'tempfile'
2
+ module Rhessus
3
+ # Encapulates scan targetting and running
4
+ class ScanRunner < Scan
5
+ self.element_name = "scan"
6
+ # waits until it can safely get a fork, then initiates a new scan at its target
7
+ # The forked process attempts to notify the central authority upon being killed that
8
+ # the scan was a failure
9
+ def fire!
10
+ # safely get a fork and fire the scan
11
+ return nil unless should_fire?
12
+ tryagain = true
13
+ pid = nil
14
+ @path = lock(self.targets)
15
+ while tryagain
16
+ begin
17
+ if pid = fork(&self)
18
+ tryagain = false
19
+ end
20
+ rescue Errno::EWOULDBLOCK
21
+ sleep 5
22
+ tryagain = true
23
+ end
24
+ end
25
+ Process.detach(pid)
26
+ end
27
+
28
+ # The procedure that should be executed when the scan actually runs,
29
+ # including signal handling
30
+ def to_proc
31
+ if should_fire?
32
+ Proc.new do
33
+ puts "Attempting to fire scan... #{scan_string}"
34
+ puts "#{::Rhessus.scanner}"
35
+ begin
36
+ Signal.trap("KILL") do
37
+ self.failure
38
+ exit
39
+ end
40
+ Signal.trap("TERM") do
41
+ self.failure
42
+ exit
43
+ end
44
+ checkin(system(::Rhessus.scanner + scan_string) && File.read(@results))
45
+ rescue
46
+ self.failure
47
+ exit
48
+ end
49
+ end
50
+ else
51
+ Proc.new { nil }
52
+ end
53
+ end
54
+
55
+ # Creates a tempfile containing the scans
56
+ def lock(targets)
57
+ @results = Tempfile.new("rhessus-scan-#{self.id}-results").path
58
+ (Tempfile.new("rhessus-scan-#{self.id}-targets").tap do |x|
59
+ x.puts targets
60
+ x.flush
61
+ end).path
62
+ end
63
+
64
+ # the second half of the scanner's data (after host, login, password)
65
+ def scan_string
66
+ " #{@path} #{@results}"
67
+ end
68
+ end
69
+ end
data/rhessus.gemspec ADDED
@@ -0,0 +1,15 @@
1
+ spec = Gem::Specification.new do |s|
2
+ s.author = "Alex Bartlow"
3
+ s.name = "rhessus"
4
+ s.version = "0.0.1"
5
+ s.summary = "Ruby Wrapper for Nessus"
6
+ s.description = "Allows scans to be pulled from central repositories"
7
+ s.require_path = 'lib'
8
+ s.has_rdoc = false
9
+ s.email = "bartlowa@gmail.com"
10
+ s.homepage = "http://alexbarlow.com"
11
+ s.files = Dir['**/*'] - [__FILE__]
12
+ s.executable = "rhessus"
13
+ s.add_dependency('activeresource', '>= 2.3.2')
14
+ s.add_dependency('daemons')
15
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rhessus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Alex Bartlow
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-08 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activeresource
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: daemons
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Allows scans to be pulled from central repositories
36
+ email: bartlowa@gmail.com
37
+ executables:
38
+ - rhessus
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - bin/rhessus
45
+ - History.txt
46
+ - lib/connections/scan.rb
47
+ - lib/rhessus.rb
48
+ - lib/scan_runner.rb
49
+ - Manifest.txt
50
+ - Rakefile
51
+ - README.txt
52
+ - rhessus-0.0.1.gem
53
+ - rhessus.gemspec
54
+ has_rdoc: true
55
+ homepage: http://alexbarlow.com
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ version:
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.5
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Ruby Wrapper for Nessus
82
+ test_files: []
83
+