Class: ViolentRuby::VulnerabilityScanner
- Inherits:
-
Object
- Object
- ViolentRuby::VulnerabilityScanner
- Defined in:
- lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb
Overview
Vulnerability Scanner provides a friendly interface to easily manage banner grabbing targets to match a list of known vulnerable services that we want to identify.
Create a new Vulnerability Scanner
The Vulnerability Scanner scanner class can be setup in a few flexible ways.
Banner Grabbing
The Vulnerability Scanner provides a simple banner grabbing method which can be used.
Example Usage
The VulnerabilityScanner is meant to be easy and flexible to use.
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#check_vulnerabilities(banner, file = false) ⇒ Boolean
(also: #vulnerable?)
Check if a given banner is included in a given file which should contain a list of vulnerable banners to match against in order to determine vulnerabilities.
-
#initialize(args = {}) ⇒ VulnerabilityScanner
constructor
Create a new instance of the vulnerability scanner.
-
#retrieve_banner(ip, port, seconds = 2) ⇒ String, Boolean
Retrieve a banner from a given ip and port for a given ammount of seconds, or default for two seconds.
-
#scan(args = {}) ⇒ void
Do the scanning!.
Constructor Details
#initialize(args = {}) ⇒ VulnerabilityScanner
Create a new instance of the vulnerability scanner.
93 94 95 96 97 98 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 93 def initialize(args = {}) @targets = [] @known_vulnerabilities = [] self.targets = args[:targets] if args[:targets] self.known_vulnerabilities = args[:known_vulnerabilities] if args[:known_vulnerabilities] end |
Instance Attribute Details
#known_vulnerabilities ⇒ Object
85 86 87 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 85 def known_vulnerabilities @known_vulnerabilities end |
#targets ⇒ Object
83 84 85 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 83 def targets @targets end |
Instance Method Details
#check_vulnerabilities(banner, file = false) ⇒ Boolean Also known as: vulnerable?
Check if a given banner is included in a given file which should contain a list of vulnerable banners to match against in order to determine vulnerabilities.
129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 129 def check_vulnerabilities(, file = false) if file File.readlines(file).map(&:strip).each do |line| return true if line.match?() end else @known_vulnerabilities.each do |vulnerability| return true if vulnerability.match?() end end false end |
#retrieve_banner(ip, port, seconds = 2) ⇒ String, Boolean
Retrieve a banner from a given ip and port for a given ammount of seconds, or default for two seconds.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 107 def (ip, port, seconds = 2) = false Timeout.timeout(seconds) do socket = TCPSocket.new(ip, port) = socket.recv(1024) socket.close end return false unless .strip! yield if block_given? rescue false end |
#scan(args = {}) ⇒ void
This method returns an undefined value.
Do the scanning!
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/violent_ruby/vulnerability_scanner/vulnerability_scanner.rb', line 155 def scan(args = {}) ip_addrs = handle_ip(args) ports = handle_port(args) timeout = handle_timeout(args) file = handle_file(args) results = [] ip_addrs.each do |ip| ports.each do |port| (ip, port, timeout) do || results << result(ip, port, ) if vulnerable?(, file) end end end results end |