ruby-nmap 0.8.0 → 0.9.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 +8 -7
- data/ChangeLog.md +19 -1
- data/README.md +3 -0
- data/Rakefile +1 -1
- data/gemspec.yml +2 -0
- data/lib/nmap/address.rb +17 -1
- data/lib/nmap/cpe.rb +44 -1
- data/lib/nmap/host.rb +24 -10
- data/lib/nmap/host_script.rb +18 -0
- data/lib/nmap/port.rb +3 -20
- data/lib/nmap/postscript.rb +16 -0
- data/lib/nmap/prescript.rb +16 -0
- data/lib/nmap/scripts.rb +71 -0
- data/lib/nmap/service.rb +13 -1
- data/lib/nmap/task.rb +4 -2
- data/lib/nmap/traceroute.rb +8 -4
- data/lib/nmap/version.rb +1 -1
- data/lib/nmap/xml.rb +30 -0
- data/spec/host_script_spec.rb +6 -0
- data/spec/host_spec.rb +14 -9
- data/spec/local_scan.xml +35 -0
- data/spec/os_class_spec.rb +1 -1
- data/spec/os_spec.rb +1 -1
- data/spec/port_spec.rb +3 -0
- data/spec/postscript_spec.rb +6 -0
- data/spec/prescript_spec.rb +6 -0
- data/spec/scan.xml +166 -88
- data/spec/scripts_examples.rb +25 -0
- data/spec/service_spec.rb +16 -6
- data/spec/spec_helper.rb +2 -1
- data/spec/tcp_ts_sequence_spec.rb +1 -1
- data/spec/xml_spec.rb +14 -2
- metadata +29 -19
- data/lib/nmap/cpe/cpe.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a11debc4eeccebd368b11d1d0444dd142f3dc91
|
4
|
+
data.tar.gz: fa232e147c7cd46e96bd8a15468f6af5b4ff1723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62a04a0bde27b4ae0f9aa015cfa668ca9efe08d596f710c2b01816c9bf6bc333a5f098afb40287f8f918546286ee9414c166624343b9e1ad994009b48b299bec
|
7
|
+
data.tar.gz: be13fe698e9c8197a6877cdcdd6193118326a683ee52b4e23c3f421ce48594faa333da8ead0cfa466ace383cb08d3433374ea28349e117ded444513b79699baa
|
data/.travis.yml
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
before_install:
|
3
|
-
- sudo apt-get install libxml2-dev libxslt1-dev
|
3
|
+
- sudo apt-get install libxml2-dev libxslt1-dev
|
4
4
|
rvm:
|
5
|
-
- 1.9
|
6
|
-
- 2.
|
7
|
-
-
|
8
|
-
-
|
5
|
+
- 2.1.9
|
6
|
+
- 2.2.4
|
7
|
+
- 2.3.1
|
8
|
+
- jruby
|
9
|
+
- rbx
|
9
10
|
matrix:
|
10
11
|
allow_failures:
|
11
|
-
- rvm: jruby
|
12
|
-
- rvm: rbx
|
12
|
+
- rvm: jruby
|
13
|
+
- rvm: rbx
|
13
14
|
script: rake test
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
### 0.9.0 / 2016-07-14
|
2
|
+
|
3
|
+
* Added {Nmap::Address#vendor}.
|
4
|
+
* Added {Nmap::Service#to_s}.
|
5
|
+
* Added {Nmap::HostScript}.
|
6
|
+
* Added {Nmap::Prescript}.
|
7
|
+
* Added {Nmap::Postscript}.
|
8
|
+
* Added {Nmap::XML#prescript}.
|
9
|
+
* Added {Nmap::XML#postscript}.
|
10
|
+
* Added `Nmap::Task#quiet` (aka `-v0`).
|
11
|
+
* `#script_data` methods can now parse arbitrarily nested Arrays/Hashes.
|
12
|
+
* Fixed {Nmap::CPE#each_cpe} to only match child `cpe` elements, not all
|
13
|
+
`cpe` elements within the document.
|
14
|
+
* Changed {Nmap::Service#to_s} to output product/version only if both are
|
15
|
+
present.
|
16
|
+
* Changed `Nmap::Task#skip_discovery` to use `-Pn` instead of `-PN`, which was
|
17
|
+
deprecated in nmap >= 7.00.
|
18
|
+
|
1
19
|
### 0.8.0 / 2014-04-16
|
2
20
|
|
3
21
|
* Added {Nmap::XML#each_down_host}.
|
@@ -94,7 +112,7 @@
|
|
94
112
|
### 0.3.0 / 2010-11-08
|
95
113
|
|
96
114
|
* Added {Nmap::Host#scripts}.
|
97
|
-
* Added {Nmap::Port#scripts}.
|
115
|
+
* Added {Nmap::Scripts#scripts Nmap::Port#scripts}.
|
98
116
|
|
99
117
|
### 0.2.0 / 2010-10-29
|
100
118
|
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
* [Issues](https://github.com/sophsec/ruby-nmap/issues)
|
5
5
|
* [Documentation](http://rubydoc.info/gems/ruby-nmap/frames)
|
6
6
|
* [Email](mailto:postmodern.mod3 at gmail.com)
|
7
|
+
* [![Build Status](https://travis-ci.org/sophsec/ruby-nmap.svg)](https://travis-ci.org/sophsec/ruby-nmap)
|
7
8
|
|
8
9
|
## Description
|
9
10
|
|
@@ -71,6 +72,7 @@ Print NSE script output from an XML scan file:
|
|
71
72
|
|
72
73
|
## Requirements
|
73
74
|
|
75
|
+
* [ruby] >= 2.0.0
|
74
76
|
* [nmap] >= 5.00
|
75
77
|
* [nokogiri] ~> 1.3
|
76
78
|
* [rprogram] ~> 0.3
|
@@ -86,5 +88,6 @@ Copyright (c) 2009-2014 Postmodern
|
|
86
88
|
See {file:LICENSE.txt} for license information.
|
87
89
|
|
88
90
|
[nmap]: http://www.insecure.org/
|
91
|
+
[ruby]: https://www.ruby-lang.org/
|
89
92
|
[nokogiri]: http://nokogiri.rubyforge.org/
|
90
93
|
[rprogram]: https://github.com/postmodern/rprogram#readme
|
data/Rakefile
CHANGED
@@ -32,5 +32,5 @@ task :doc => :yard
|
|
32
32
|
|
33
33
|
file 'spec/scan.xml' do
|
34
34
|
puts ">>> Scanning scanme.nmap.org ..."
|
35
|
-
sh 'sudo nmap -v -sS -sU -A -O -oX spec/scan.xml scanme.nmap.org'
|
35
|
+
sh 'sudo nmap -v -sS -sU -A -O --script ssh2-enum-algos,ssh-hostkey -oX spec/scan.xml scanme.nmap.org'
|
36
36
|
end
|
data/gemspec.yml
CHANGED
data/lib/nmap/address.rb
CHANGED
@@ -2,7 +2,23 @@ module Nmap
|
|
2
2
|
#
|
3
3
|
# Represents an IP or MAC address and Vendor name.
|
4
4
|
#
|
5
|
-
class Address < Struct.new(:type, :addr)
|
5
|
+
class Address < Struct.new(:type, :addr, :vendor)
|
6
|
+
|
7
|
+
#
|
8
|
+
# Initializes the address.
|
9
|
+
#
|
10
|
+
# @param [Symbol] type
|
11
|
+
# The type of address.
|
12
|
+
#
|
13
|
+
# @param [String] addr
|
14
|
+
# The address.
|
15
|
+
#
|
16
|
+
# @param [String, nil] vendor
|
17
|
+
# The optional vendor.
|
18
|
+
#
|
19
|
+
def initialize(type,addr,vendor=nil)
|
20
|
+
super(type,addr,vendor)
|
21
|
+
end
|
6
22
|
|
7
23
|
#
|
8
24
|
# Converts the address to a String.
|
data/lib/nmap/cpe.rb
CHANGED
@@ -1,2 +1,45 @@
|
|
1
1
|
require 'nmap/cpe/url'
|
2
|
-
|
2
|
+
|
3
|
+
module Nmap
|
4
|
+
#
|
5
|
+
# Mixins that adds methods for parsing [Common Platform Enumeration
|
6
|
+
# (CPE)][CPE] information.
|
7
|
+
#
|
8
|
+
# [CPE]: http://nmap.org/book/output-formats-cpe.html
|
9
|
+
#
|
10
|
+
# @since 0.7.0
|
11
|
+
#
|
12
|
+
module CPE
|
13
|
+
#
|
14
|
+
# Parses each Common Platform Enumeration (CPE) String.
|
15
|
+
#
|
16
|
+
# @yield [cpe]
|
17
|
+
# Passes each CPE URL to the given block.
|
18
|
+
#
|
19
|
+
# @yieldparam [URL] cpe
|
20
|
+
# The CPE URL.
|
21
|
+
#
|
22
|
+
# @return [Enumerator]
|
23
|
+
# If no block is given, an enumerator object will be returned.
|
24
|
+
#
|
25
|
+
def each_cpe
|
26
|
+
return enum_for(__method__) unless block_given?
|
27
|
+
|
28
|
+
@node.xpath('cpe').each do |cpe|
|
29
|
+
yield URL.parse(cpe.inner_text)
|
30
|
+
end
|
31
|
+
|
32
|
+
return self
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Parses each Common Platform Enumeration (CPE) String.
|
37
|
+
#
|
38
|
+
# @return [Array<URL>]
|
39
|
+
# The CPE URLs.
|
40
|
+
#
|
41
|
+
def cpe
|
42
|
+
each_cpe.to_a
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/nmap/host.rb
CHANGED
@@ -8,6 +8,7 @@ require 'nmap/tcp_sequence'
|
|
8
8
|
require 'nmap/tcp_ts_sequence'
|
9
9
|
require 'nmap/uptime'
|
10
10
|
require 'nmap/traceroute'
|
11
|
+
require 'nmap/host_script'
|
11
12
|
|
12
13
|
require 'nokogiri'
|
13
14
|
require 'time'
|
@@ -92,7 +93,8 @@ module Nmap
|
|
92
93
|
@node.xpath("address[@addr]").each do |addr|
|
93
94
|
address = Address.new(
|
94
95
|
addr['addrtype'].to_sym,
|
95
|
-
addr['addr']
|
96
|
+
addr['addr'],
|
97
|
+
addr['vendor']
|
96
98
|
)
|
97
99
|
|
98
100
|
yield address
|
@@ -132,8 +134,8 @@ module Nmap
|
|
132
134
|
# @since 0.8.0
|
133
135
|
#
|
134
136
|
def vendor
|
135
|
-
@vendor ||= if (vendor = @node.at("address
|
136
|
-
vendor
|
137
|
+
@vendor ||= if (vendor = @node.at("address/@vendor"))
|
138
|
+
vendor.inner_text
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
@@ -511,16 +513,28 @@ module Nmap
|
|
511
513
|
#
|
512
514
|
# @since 0.3.0
|
513
515
|
#
|
516
|
+
# @deprecated Use {#host_script} instead.
|
517
|
+
#
|
514
518
|
def scripts
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
@scripts[script['id']] = script['output']
|
520
|
-
end
|
519
|
+
if host_script
|
520
|
+
host_script.scripts
|
521
|
+
else
|
522
|
+
{}
|
521
523
|
end
|
524
|
+
end
|
522
525
|
|
523
|
-
|
526
|
+
#
|
527
|
+
# The NSE scripts ran against the host.
|
528
|
+
#
|
529
|
+
# @return [HostScript, nil]
|
530
|
+
# Contains the host script output and data.
|
531
|
+
#
|
532
|
+
# @since 0.9.0
|
533
|
+
#
|
534
|
+
def host_script
|
535
|
+
@host_script ||= if (hostscript = @node.at('hostscript'))
|
536
|
+
HostScript.new(hostscript)
|
537
|
+
end
|
524
538
|
end
|
525
539
|
|
526
540
|
#
|
data/lib/nmap/port.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'nmap/service'
|
2
|
+
require 'nmap/scripts'
|
2
3
|
|
3
4
|
module Nmap
|
4
5
|
#
|
@@ -6,6 +7,8 @@ module Nmap
|
|
6
7
|
#
|
7
8
|
class Port
|
8
9
|
|
10
|
+
include Scripts
|
11
|
+
|
9
12
|
#
|
10
13
|
# Creates a new Port object.
|
11
14
|
#
|
@@ -70,26 +73,6 @@ module Nmap
|
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
73
|
-
#
|
74
|
-
# The output from the NSE scripts ran against the open port.
|
75
|
-
#
|
76
|
-
# @return [Hash{String => String}]
|
77
|
-
# The NSE script names and output.
|
78
|
-
#
|
79
|
-
# @since 0.3.0
|
80
|
-
#
|
81
|
-
def scripts
|
82
|
-
unless @scripts
|
83
|
-
@scripts = {}
|
84
|
-
|
85
|
-
@node.xpath('script').each do |script|
|
86
|
-
@scripts[script['id']] = script['output']
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
return @scripts
|
91
|
-
end
|
92
|
-
|
93
76
|
alias to_i number
|
94
77
|
|
95
78
|
#
|
data/lib/nmap/scripts.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
module Nmap
|
2
|
+
module Scripts
|
3
|
+
#
|
4
|
+
# The output from the NSE scripts ran against the open port.
|
5
|
+
#
|
6
|
+
# @return [Hash{String => String}]
|
7
|
+
# The NSE script names and output.
|
8
|
+
#
|
9
|
+
# @since 0.3.0
|
10
|
+
#
|
11
|
+
def scripts
|
12
|
+
unless @scripts
|
13
|
+
@scripts = {}
|
14
|
+
|
15
|
+
@node.xpath('script').each do |script|
|
16
|
+
@scripts[script['id']] = script['output']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
return @scripts
|
21
|
+
end
|
22
|
+
|
23
|
+
#
|
24
|
+
# The structured output of the NSE scripts.
|
25
|
+
#
|
26
|
+
# @return [Hash{String => Hash{String => Array<String>}}]
|
27
|
+
# The NSE script names and their structured output.
|
28
|
+
#
|
29
|
+
# @since 0.9.0
|
30
|
+
#
|
31
|
+
def script_data
|
32
|
+
unless @script_data
|
33
|
+
@script_data = {}
|
34
|
+
|
35
|
+
traverse = lambda do |node|
|
36
|
+
case node.name
|
37
|
+
when 'script', 'table'
|
38
|
+
unless node.xpath('*[@key]').empty?
|
39
|
+
hash = {}
|
40
|
+
|
41
|
+
node.elements.each do |element|
|
42
|
+
hash[element['key']] = traverse.call(element)
|
43
|
+
end
|
44
|
+
|
45
|
+
hash
|
46
|
+
else
|
47
|
+
array = []
|
48
|
+
|
49
|
+
node.elements.each do |element|
|
50
|
+
array << traverse.call(element)
|
51
|
+
end
|
52
|
+
|
53
|
+
array
|
54
|
+
end
|
55
|
+
when 'elem'
|
56
|
+
node.inner_text
|
57
|
+
else
|
58
|
+
raise(NotImplementedError,"unrecognized XML NSE element: #{node}")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
@node.xpath('script').each do |script|
|
63
|
+
@script_data[script['id']] = traverse.call(script)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
return @script_data
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
data/lib/nmap/service.rb
CHANGED
@@ -152,7 +152,19 @@ module Nmap
|
|
152
152
|
@confidence ||= @node.get_attribute('conf').to_i
|
153
153
|
end
|
154
154
|
|
155
|
-
|
155
|
+
#
|
156
|
+
# Converts the service to a String.
|
157
|
+
#
|
158
|
+
# @return [String]
|
159
|
+
# String containing {#product} and {#version}, or {#name}.
|
160
|
+
#
|
161
|
+
def to_s
|
162
|
+
if (product && version)
|
163
|
+
"#{product} #{version}"
|
164
|
+
else
|
165
|
+
name
|
166
|
+
end
|
167
|
+
end
|
156
168
|
|
157
169
|
end
|
158
170
|
end
|
data/lib/nmap/task.rb
CHANGED
@@ -15,7 +15,7 @@ module Nmap
|
|
15
15
|
#
|
16
16
|
# * `-sL` - `nmap.list`
|
17
17
|
# * `-sn` - `nmap.ping`
|
18
|
-
# * `-
|
18
|
+
# * `-Pn` - `nmap.skip_discovery`
|
19
19
|
# * `-PS` - `nmap.syn_discovery`
|
20
20
|
# * `-PA` - `nmap.ack_discovery`
|
21
21
|
# * `-PU` - `nmap.udp_discovery`
|
@@ -131,6 +131,7 @@ module Nmap
|
|
131
131
|
# ### Verbosity and Debugging:
|
132
132
|
#
|
133
133
|
# * `-v` - `nmap.verbose`
|
134
|
+
# * `-v0` - `nmap.quiet`
|
134
135
|
# * `-d` - `nmap.debug`
|
135
136
|
# * `--reason` - `nmap.show_reason`
|
136
137
|
# * `--stats-every` - `nmap.stats_every`
|
@@ -178,7 +179,7 @@ module Nmap
|
|
178
179
|
# HOST DISCOVERY:
|
179
180
|
short_option :flag => '-sL', :name => :list
|
180
181
|
short_option :flag => '-sn', :name => :ping
|
181
|
-
short_option :flag => '-
|
182
|
+
short_option :flag => '-Pn', :name => :skip_discovery
|
182
183
|
short_option :flag => '-PS', :name => :syn_discovery
|
183
184
|
short_option :flag => '-PA', :name => :ack_discovery
|
184
185
|
short_option :flag => '-PU', :name => :udp_discovery
|
@@ -300,6 +301,7 @@ module Nmap
|
|
300
301
|
|
301
302
|
# Verbosity and Debugging:
|
302
303
|
short_option :flag => '-v', :name => :verbose
|
304
|
+
short_option :flag => '-v0', :name => :quiet
|
303
305
|
short_option :flag => '-d', :name => :debug
|
304
306
|
long_option :flag => '--reason', :name => :show_reason
|
305
307
|
long_option :flag => '--stats-every'
|