ruby-nmap 0.9.3 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.document +1 -0
- data/.editorconfig +11 -0
- data/.github/workflows/ruby.yml +31 -0
- data/ChangeLog.md +122 -67
- data/Gemfile +11 -5
- data/LICENSE.txt +1 -1
- data/README.md +88 -50
- data/Rakefile +8 -3
- data/UPGRADING.md +47 -0
- data/gemspec.yml +6 -6
- data/lib/nmap/command.rb +765 -0
- data/lib/nmap/version.rb +1 -1
- data/lib/nmap/xml/address.rb +38 -0
- data/lib/nmap/xml/cpe/url.rb +80 -0
- data/lib/nmap/xml/cpe.rb +47 -0
- data/lib/nmap/xml/hop.rb +22 -0
- data/lib/nmap/xml/host.rb +546 -0
- data/lib/nmap/xml/host_script.rb +26 -0
- data/lib/nmap/xml/hostname.rb +44 -0
- data/lib/nmap/xml/ip_id_sequence.rb +26 -0
- data/lib/nmap/xml/os.rb +131 -0
- data/lib/nmap/xml/os_class.rb +86 -0
- data/lib/nmap/xml/os_match.rb +22 -0
- data/lib/nmap/xml/port.rb +114 -0
- data/lib/nmap/xml/postscript.rb +26 -0
- data/lib/nmap/xml/prescript.rb +26 -0
- data/lib/nmap/xml/run_stat.rb +22 -0
- data/lib/nmap/xml/scan.rb +38 -0
- data/lib/nmap/xml/scan_task.rb +55 -0
- data/lib/nmap/xml/scanner.rb +22 -0
- data/lib/nmap/xml/script.rb +110 -0
- data/lib/nmap/xml/scripts.rb +33 -0
- data/lib/nmap/xml/sequence.rb +52 -0
- data/lib/nmap/xml/service.rb +172 -0
- data/lib/nmap/xml/status.rb +22 -0
- data/lib/nmap/xml/tcp_sequence.rb +48 -0
- data/lib/nmap/xml/tcp_ts_sequence.rb +26 -0
- data/lib/nmap/xml/traceroute.rb +73 -0
- data/lib/nmap/xml/uptime.rb +22 -0
- data/lib/nmap/xml.rb +46 -44
- data/ruby-nmap.gemspec +38 -83
- data/spec/command_spec.rb +726 -0
- data/spec/fixtures/down_host_scan.xml +16 -0
- data/spec/{local_scan.xml → fixtures/local_scan.xml} +1 -1
- data/spec/{scan.xml → fixtures/scan.xml} +1 -1
- data/spec/spec_helper.rb +2 -2
- data/spec/{address_spec.rb → xml/address_spec.rb} +2 -2
- data/spec/{cpe → xml/cpe}/url_spec.rb +1 -1
- data/spec/{cpe_examples.rb → xml/cpe_examples.rb} +1 -1
- data/spec/{hop_spec.rb → xml/hop_spec.rb} +2 -2
- data/spec/{host_script_spec.rb → xml/host_script_spec.rb} +2 -2
- data/spec/{host_spec.rb → xml/host_spec.rb} +12 -8
- data/spec/{hostname_spec.rb → xml/hostname_spec.rb} +2 -2
- data/spec/{ip_id_sequence_spec.rb → xml/ip_id_sequence_spec.rb} +3 -3
- data/spec/{os_class_spec.rb → xml/os_class_spec.rb} +3 -3
- data/spec/{os_match_spec.rb → xml/os_match_spec.rb} +2 -2
- data/spec/{os_spec.rb → xml/os_spec.rb} +3 -3
- data/spec/{port_spec.rb → xml/port_spec.rb} +10 -5
- data/spec/{postscript_spec.rb → xml/postscript_spec.rb} +2 -2
- data/spec/{prescript_spec.rb → xml/prescript_spec.rb} +2 -2
- data/spec/{run_stat_spec.rb → xml/run_stat_spec.rb} +2 -2
- data/spec/{scan_spec.rb → xml/scan_spec.rb} +2 -2
- data/spec/{scan_task_spec.rb → xml/scan_task_spec.rb} +6 -6
- data/spec/{scanner_spec.rb → xml/scanner_spec.rb} +3 -3
- data/spec/xml/script_spec.rb +137 -0
- data/spec/xml/scripts_examples.rb +19 -0
- data/spec/{sequence_examples.rb → xml/sequence_examples.rb} +1 -0
- data/spec/{service_spec.rb → xml/service_spec.rb} +31 -5
- data/spec/{status_spec.rb → xml/status_spec.rb} +4 -3
- data/spec/{tcp_sequence_spec.rb → xml/tcp_sequence_spec.rb} +3 -3
- data/spec/{tcp_ts_sequence_spec.rb → xml/tcp_ts_sequence_spec.rb} +3 -3
- data/spec/{traceroute_spec.rb → xml/traceroute_spec.rb} +3 -3
- data/spec/{uptime_spec.rb → xml/uptime_spec.rb} +2 -2
- data/spec/xml_spec.rb +93 -45
- metadata +78 -99
- data/.travis.yml +0 -14
- data/lib/nmap/address.rb +0 -34
- data/lib/nmap/cpe/url.rb +0 -78
- data/lib/nmap/cpe.rb +0 -45
- data/lib/nmap/hop.rb +0 -20
- data/lib/nmap/host.rb +0 -586
- data/lib/nmap/host_script.rb +0 -18
- data/lib/nmap/hostname.rb +0 -42
- data/lib/nmap/ip_id_sequence.rb +0 -24
- data/lib/nmap/os.rb +0 -127
- data/lib/nmap/os_class.rb +0 -82
- data/lib/nmap/os_match.rb +0 -18
- data/lib/nmap/port.rb +0 -99
- data/lib/nmap/postscript.rb +0 -16
- data/lib/nmap/prescript.rb +0 -16
- data/lib/nmap/program.rb +0 -102
- data/lib/nmap/run_stat.rb +0 -20
- data/lib/nmap/scan.rb +0 -34
- data/lib/nmap/scan_task.rb +0 -50
- data/lib/nmap/scanner.rb +0 -18
- data/lib/nmap/scripts.rb +0 -71
- data/lib/nmap/sequence.rb +0 -50
- data/lib/nmap/service.rb +0 -170
- data/lib/nmap/status.rb +0 -18
- data/lib/nmap/task.rb +0 -381
- data/lib/nmap/tcp_sequence.rb +0 -46
- data/lib/nmap/tcp_ts_sequence.rb +0 -22
- data/lib/nmap/traceroute.rb +0 -71
- data/lib/nmap/uptime.rb +0 -20
- data/spec/scripts_examples.rb +0 -35
- data/spec/task_spec.rb +0 -150
data/lib/nmap/version.rb
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module Nmap
|
|
2
|
+
class XML
|
|
3
|
+
#
|
|
4
|
+
# Represents an IP or MAC address and Vendor name.
|
|
5
|
+
#
|
|
6
|
+
# @since 1.0.0
|
|
7
|
+
#
|
|
8
|
+
class Address < Struct.new(:type, :addr, :vendor)
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Initializes the address.
|
|
12
|
+
#
|
|
13
|
+
# @param [Symbol] type
|
|
14
|
+
# The type of address.
|
|
15
|
+
#
|
|
16
|
+
# @param [String] addr
|
|
17
|
+
# The address.
|
|
18
|
+
#
|
|
19
|
+
# @param [String, nil] vendor
|
|
20
|
+
# The optional vendor.
|
|
21
|
+
#
|
|
22
|
+
def initialize(type,addr,vendor=nil)
|
|
23
|
+
super(type,addr,vendor)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Converts the address to a String.
|
|
28
|
+
#
|
|
29
|
+
# @return [String]
|
|
30
|
+
# The address.
|
|
31
|
+
#
|
|
32
|
+
def to_s
|
|
33
|
+
self.addr.to_s
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module Nmap
|
|
2
|
+
class XML
|
|
3
|
+
module CPE
|
|
4
|
+
#
|
|
5
|
+
# Represents a [Common Platform Enumeration (CPE)][CPE] URL.
|
|
6
|
+
#
|
|
7
|
+
# [CPE]: http://nmap.org/book/output-formats-cpe.html
|
|
8
|
+
#
|
|
9
|
+
# @since 1.0.0
|
|
10
|
+
#
|
|
11
|
+
class URL < Struct.new(:part,:vendor,:product,:version,:update,:edition,
|
|
12
|
+
:language)
|
|
13
|
+
|
|
14
|
+
# CPE part codes
|
|
15
|
+
PARTS = {
|
|
16
|
+
'/a' => :application,
|
|
17
|
+
'/h' => :hardware,
|
|
18
|
+
'/o' => :os
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#
|
|
22
|
+
# Parses a CPE URL.
|
|
23
|
+
#
|
|
24
|
+
# @param [String] url
|
|
25
|
+
# The raw URL.
|
|
26
|
+
#
|
|
27
|
+
# @return [URL]
|
|
28
|
+
# The parsed URL.
|
|
29
|
+
#
|
|
30
|
+
def self.parse(url)
|
|
31
|
+
scheme,
|
|
32
|
+
part,
|
|
33
|
+
vendor,
|
|
34
|
+
product,
|
|
35
|
+
version,
|
|
36
|
+
update,
|
|
37
|
+
edition,
|
|
38
|
+
language = url.split(':',8)
|
|
39
|
+
|
|
40
|
+
unless scheme == 'cpe'
|
|
41
|
+
raise(ArgumentError,"CPE URLs must begin with 'cpe:'")
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
vendor = vendor.to_sym
|
|
45
|
+
product = product.to_sym
|
|
46
|
+
language = language.to_sym if language
|
|
47
|
+
|
|
48
|
+
return new(
|
|
49
|
+
PARTS[part],
|
|
50
|
+
vendor,
|
|
51
|
+
product,
|
|
52
|
+
version,
|
|
53
|
+
update,
|
|
54
|
+
edition,
|
|
55
|
+
language
|
|
56
|
+
)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# Converts the CPE URL back into a String.
|
|
61
|
+
#
|
|
62
|
+
# @return [String]
|
|
63
|
+
# The raw CPE URL.
|
|
64
|
+
#
|
|
65
|
+
def to_s
|
|
66
|
+
'cpe:' + [
|
|
67
|
+
PARTS.invert[part],
|
|
68
|
+
vendor,
|
|
69
|
+
product,
|
|
70
|
+
version,
|
|
71
|
+
update,
|
|
72
|
+
edition,
|
|
73
|
+
language
|
|
74
|
+
].compact.join(':')
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
data/lib/nmap/xml/cpe.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'nmap/xml/cpe/url'
|
|
2
|
+
|
|
3
|
+
module Nmap
|
|
4
|
+
class XML
|
|
5
|
+
#
|
|
6
|
+
# Mixins that adds methods for parsing [Common Platform Enumeration
|
|
7
|
+
# (CPE)][CPE] information.
|
|
8
|
+
#
|
|
9
|
+
# [CPE]: http://nmap.org/book/output-formats-cpe.html
|
|
10
|
+
#
|
|
11
|
+
# @since 1.0.0
|
|
12
|
+
#
|
|
13
|
+
module CPE
|
|
14
|
+
#
|
|
15
|
+
# Parses each Common Platform Enumeration (CPE) String.
|
|
16
|
+
#
|
|
17
|
+
# @yield [cpe]
|
|
18
|
+
# Passes each CPE URL to the given block.
|
|
19
|
+
#
|
|
20
|
+
# @yieldparam [URL] cpe
|
|
21
|
+
# The CPE URL.
|
|
22
|
+
#
|
|
23
|
+
# @return [Enumerator]
|
|
24
|
+
# If no block is given, an enumerator object will be returned.
|
|
25
|
+
#
|
|
26
|
+
def each_cpe
|
|
27
|
+
return enum_for(__method__) unless block_given?
|
|
28
|
+
|
|
29
|
+
@node.xpath('cpe').each do |cpe|
|
|
30
|
+
yield URL.parse(cpe.inner_text)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
return self
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
#
|
|
37
|
+
# Parses each Common Platform Enumeration (CPE) String.
|
|
38
|
+
#
|
|
39
|
+
# @return [Array<URL>]
|
|
40
|
+
# The CPE URLs.
|
|
41
|
+
#
|
|
42
|
+
def cpe
|
|
43
|
+
each_cpe.to_a
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
data/lib/nmap/xml/hop.rb
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Nmap
|
|
2
|
+
class XML
|
|
3
|
+
#
|
|
4
|
+
# Represents a hop in a traceroute.
|
|
5
|
+
#
|
|
6
|
+
# @since 1.0.0
|
|
7
|
+
#
|
|
8
|
+
class Hop < Struct.new(:addr, :host, :ttl, :rtt)
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Converts the hop to a String.
|
|
12
|
+
#
|
|
13
|
+
# @return [String]
|
|
14
|
+
# The IP address of the hop.
|
|
15
|
+
#
|
|
16
|
+
def to_s
|
|
17
|
+
self.addr.to_s
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|