ruby-nmap 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -0
  3. data/.editorconfig +11 -0
  4. data/.github/workflows/ruby.yml +31 -0
  5. data/ChangeLog.md +118 -71
  6. data/Gemfile +11 -5
  7. data/LICENSE.txt +1 -1
  8. data/README.md +88 -50
  9. data/Rakefile +5 -0
  10. data/UPGRADING.md +47 -0
  11. data/gemspec.yml +5 -5
  12. data/lib/nmap/command.rb +765 -0
  13. data/lib/nmap/version.rb +1 -1
  14. data/lib/nmap/xml/address.rb +38 -0
  15. data/lib/nmap/xml/cpe/url.rb +80 -0
  16. data/lib/nmap/xml/cpe.rb +47 -0
  17. data/lib/nmap/xml/hop.rb +22 -0
  18. data/lib/nmap/xml/host.rb +546 -0
  19. data/lib/nmap/xml/host_script.rb +26 -0
  20. data/lib/nmap/xml/hostname.rb +44 -0
  21. data/lib/nmap/xml/ip_id_sequence.rb +26 -0
  22. data/lib/nmap/xml/os.rb +131 -0
  23. data/lib/nmap/xml/os_class.rb +86 -0
  24. data/lib/nmap/xml/os_match.rb +22 -0
  25. data/lib/nmap/xml/port.rb +114 -0
  26. data/lib/nmap/xml/postscript.rb +26 -0
  27. data/lib/nmap/xml/prescript.rb +26 -0
  28. data/lib/nmap/xml/run_stat.rb +22 -0
  29. data/lib/nmap/xml/scan.rb +38 -0
  30. data/lib/nmap/xml/scan_task.rb +55 -0
  31. data/lib/nmap/xml/scanner.rb +22 -0
  32. data/lib/nmap/xml/script.rb +110 -0
  33. data/lib/nmap/xml/scripts.rb +33 -0
  34. data/lib/nmap/xml/sequence.rb +52 -0
  35. data/lib/nmap/xml/service.rb +172 -0
  36. data/lib/nmap/xml/status.rb +22 -0
  37. data/lib/nmap/xml/tcp_sequence.rb +48 -0
  38. data/lib/nmap/xml/tcp_ts_sequence.rb +26 -0
  39. data/lib/nmap/xml/traceroute.rb +73 -0
  40. data/lib/nmap/xml/uptime.rb +22 -0
  41. data/lib/nmap/xml.rb +31 -44
  42. data/spec/command_spec.rb +726 -0
  43. data/spec/fixtures/down_host_scan.xml +16 -0
  44. data/spec/{address_spec.rb → xml/address_spec.rb} +2 -2
  45. data/spec/{cpe → xml/cpe}/url_spec.rb +1 -1
  46. data/spec/{cpe_examples.rb → xml/cpe_examples.rb} +1 -1
  47. data/spec/{hop_spec.rb → xml/hop_spec.rb} +2 -2
  48. data/spec/{host_script_spec.rb → xml/host_script_spec.rb} +2 -2
  49. data/spec/{host_spec.rb → xml/host_spec.rb} +8 -8
  50. data/spec/{hostname_spec.rb → xml/hostname_spec.rb} +2 -2
  51. data/spec/{ip_id_sequence_spec.rb → xml/ip_id_sequence_spec.rb} +3 -3
  52. data/spec/{os_class_spec.rb → xml/os_class_spec.rb} +3 -3
  53. data/spec/{os_match_spec.rb → xml/os_match_spec.rb} +2 -2
  54. data/spec/{os_spec.rb → xml/os_spec.rb} +3 -3
  55. data/spec/{port_spec.rb → xml/port_spec.rb} +4 -5
  56. data/spec/{postscript_spec.rb → xml/postscript_spec.rb} +2 -2
  57. data/spec/{prescript_spec.rb → xml/prescript_spec.rb} +2 -2
  58. data/spec/{run_stat_spec.rb → xml/run_stat_spec.rb} +2 -2
  59. data/spec/{scan_spec.rb → xml/scan_spec.rb} +2 -2
  60. data/spec/{scan_task_spec.rb → xml/scan_task_spec.rb} +6 -6
  61. data/spec/{scanner_spec.rb → xml/scanner_spec.rb} +3 -3
  62. data/spec/xml/script_spec.rb +137 -0
  63. data/spec/xml/scripts_examples.rb +19 -0
  64. data/spec/{sequence_examples.rb → xml/sequence_examples.rb} +1 -0
  65. data/spec/{service_spec.rb → xml/service_spec.rb} +31 -5
  66. data/spec/{status_spec.rb → xml/status_spec.rb} +2 -2
  67. data/spec/{tcp_sequence_spec.rb → xml/tcp_sequence_spec.rb} +3 -3
  68. data/spec/{tcp_ts_sequence_spec.rb → xml/tcp_ts_sequence_spec.rb} +3 -3
  69. data/spec/{traceroute_spec.rb → xml/traceroute_spec.rb} +3 -3
  70. data/spec/{uptime_spec.rb → xml/uptime_spec.rb} +2 -2
  71. data/spec/xml_spec.rb +73 -44
  72. metadata +72 -66
  73. data/.travis.yml +0 -16
  74. data/lib/nmap/address.rb +0 -34
  75. data/lib/nmap/cpe/url.rb +0 -78
  76. data/lib/nmap/cpe.rb +0 -45
  77. data/lib/nmap/hop.rb +0 -20
  78. data/lib/nmap/host.rb +0 -587
  79. data/lib/nmap/host_script.rb +0 -18
  80. data/lib/nmap/hostname.rb +0 -42
  81. data/lib/nmap/ip_id_sequence.rb +0 -24
  82. data/lib/nmap/os.rb +0 -127
  83. data/lib/nmap/os_class.rb +0 -82
  84. data/lib/nmap/os_match.rb +0 -18
  85. data/lib/nmap/port.rb +0 -110
  86. data/lib/nmap/postscript.rb +0 -16
  87. data/lib/nmap/prescript.rb +0 -16
  88. data/lib/nmap/program.rb +0 -102
  89. data/lib/nmap/run_stat.rb +0 -20
  90. data/lib/nmap/scan.rb +0 -34
  91. data/lib/nmap/scan_task.rb +0 -53
  92. data/lib/nmap/scanner.rb +0 -18
  93. data/lib/nmap/scripts.rb +0 -71
  94. data/lib/nmap/sequence.rb +0 -50
  95. data/lib/nmap/service.rb +0 -170
  96. data/lib/nmap/status.rb +0 -18
  97. data/lib/nmap/task.rb +0 -387
  98. data/lib/nmap/tcp_sequence.rb +0 -46
  99. data/lib/nmap/tcp_ts_sequence.rb +0 -22
  100. data/lib/nmap/traceroute.rb +0 -71
  101. data/lib/nmap/uptime.rb +0 -20
  102. data/spec/scripts_examples.rb +0 -35
  103. data/spec/task_spec.rb +0 -150
@@ -1,71 +0,0 @@
1
- require 'nmap/hop'
2
-
3
- module Nmap
4
- #
5
- # Wraps the `trace` XML element.
6
- #
7
- # @since 0.7.0
8
- #
9
- class Traceroute
10
-
11
- include Enumerable
12
-
13
- #
14
- # Creates a new traceroute.
15
- #
16
- # @param [Nokogiri::XML::Element] node
17
- # The `trace` XML element.
18
- #
19
- def initialize(node)
20
- @node = node
21
- end
22
-
23
- #
24
- # The port used for the traceroute.
25
- #
26
- # @return [Integer, nil]
27
- # The `port` XML attribute.
28
- #
29
- def port
30
- @port ||= if @node['port']
31
- @node['port'].to_i
32
- end
33
- end
34
-
35
- #
36
- # The protocol used for the traceroute.
37
- #
38
- # @return [Symbol, nil]
39
- # The `proto` XML element.
40
- #
41
- def protocol
42
- @protocol ||= if @node['proto']
43
- @node['proto'].to_sym
44
- end
45
- end
46
-
47
- #
48
- # Parses the traceroute information for the host.
49
- #
50
- # @yield [hop]
51
- # Each hop to the host.
52
- #
53
- # @yieldparam [Hop] hop
54
- # A hop to the host.
55
- #
56
- # @return [Traceroute, Enumerator]
57
- # The traceroute.
58
- # If no block was given, an enumerator will be returned.
59
- #
60
- def each
61
- return enum_for(__method__) unless block_given?
62
-
63
- @node.xpath('hop').each do |hop|
64
- yield Hop.new(hop['ipaddr'],hop['host'],hop['ttl'],hop['rtt'])
65
- end
66
-
67
- return self
68
- end
69
-
70
- end
71
- end
data/lib/nmap/uptime.rb DELETED
@@ -1,20 +0,0 @@
1
- module Nmap
2
- #
3
- # Wraps a `uptime` XML element.
4
- #
5
- # @since 0.7.0
6
- #
7
- class Uptime < Struct.new(:seconds, :last_boot)
8
-
9
- #
10
- # Converts the uptime object to a String.
11
- #
12
- # @return [String]
13
- # The String form of the Uptime.
14
- #
15
- def to_s
16
- "uptime: #{self.seconds} (#{self.last_boot})"
17
- end
18
-
19
- end
20
- end
@@ -1,35 +0,0 @@
1
- require 'rspec'
2
-
3
- shared_examples_for "#scripts" do
4
- describe "#scripts" do
5
- subject { super().scripts }
6
-
7
- it { is_expected.to be_kind_of(Hash) }
8
- it { is_expected.not_to be_empty }
9
-
10
- it "should contain String keys" do
11
- expect(subject.keys).to all(be_kind_of(String))
12
- end
13
-
14
- it "should contain String values" do
15
- expect(subject.values).to all(be_kind_of(String))
16
- end
17
- end
18
- end
19
-
20
- shared_examples_for "#script_data" do
21
- describe "#script_data" do
22
- subject { super().script_data }
23
-
24
- it { is_expected.to be_kind_of(Hash) }
25
- it { is_expected.not_to be_empty }
26
-
27
- it "should contain String keys" do
28
- expect(subject.keys).to all(be_kind_of(String))
29
- end
30
-
31
- it "should contain Arrays or Hashes" do
32
- expect(subject.values).to all(be_kind_of(Array).or(be_kind_of(Hash)))
33
- end
34
- end
35
- end
data/spec/task_spec.rb DELETED
@@ -1,150 +0,0 @@
1
- require 'spec_helper'
2
- require 'nmap/task'
3
-
4
- describe Task do
5
- describe "#ports=" do
6
- context "when given an empty Array" do
7
- before { subject.ports = [] }
8
-
9
- it "should ignore empty port Arrays" do
10
- subject.ports = []
11
-
12
- expect(subject.arguments).to eq([])
13
- end
14
- end
15
-
16
- context "when given a String" do
17
- let(:ports) { '80,21,25' }
18
-
19
- before { subject.ports = ports }
20
-
21
- it "should emit the String as is" do
22
- expect(subject.arguments).to eq(['-p', ports])
23
- end
24
- end
25
-
26
- context "when given an Array of Strings" do
27
- let(:ports) { %w[80 21 25] }
28
-
29
- before { subject.ports = ports }
30
-
31
- it "should format an Array of String ports" do
32
- expect(subject.arguments).to eq(['-p', ports.join(',')])
33
- end
34
- end
35
-
36
- context "when given an Array of Integers" do
37
- let(:ports) { [80, 21, 25] }
38
-
39
- before { subject.ports = ports }
40
-
41
- it "should format an Array of Integer ports" do
42
- expect(subject.arguments).to eq(['-p', ports.join(',')])
43
- end
44
- end
45
-
46
- context "when given an Array containing a Range" do
47
- let(:ports) { [80, 21..25] }
48
-
49
- before { subject.ports = ports }
50
-
51
- it "should format the Range" do
52
- expect(subject.arguments).to eq([
53
- '-p', "#{ports[0]},#{ports[1].begin}-#{ports[1].end}"
54
- ])
55
- end
56
- end
57
- end
58
-
59
- shared_examples "optional port range" do |flag,method|
60
- before { subject.send(:"#{method}=",ports) }
61
-
62
- context "when given a Boolean" do
63
- let(:ports) { true }
64
-
65
- it "should emit the '#{flag}' option flag" do
66
- expect(subject.arguments).to eq([flag])
67
- end
68
- end
69
-
70
- context "when given an empty Array" do
71
- let(:ports) { [] }
72
-
73
- it "should emit the '#{flag}' option flag" do
74
- expect(subject.arguments).to eq([flag])
75
- end
76
- end
77
-
78
- context "when given an Array of Integers" do
79
- let(:ports) { [80, 21, 25] }
80
-
81
- it "should emit the '#{flag}' option flag with the Integer ports" do
82
- expect(subject.arguments).to eq(["#{flag}#{ports.join(',')}"])
83
- end
84
- end
85
-
86
- context "when given an Array containing a Range" do
87
- let(:ports) { [80, 21..25] }
88
-
89
- it "should emit the '#{flag}' option flag with the Integer ports" do
90
- expect(subject.arguments).to eq([
91
- "#{flag}#{ports[0]},#{ports[1].begin}-#{ports[1].end}"
92
- ])
93
- end
94
- end
95
- end
96
-
97
- describe "#syn_discovery" do
98
- include_examples "optional port range", '-PS', :syn_discovery
99
- end
100
-
101
- describe "#ack_discovery" do
102
- include_examples "optional port range", '-PA', :ack_discovery
103
- end
104
-
105
- describe "#udp_discovery" do
106
- include_examples "optional port range", '-PU', :udp_discovery
107
- end
108
-
109
- describe "#sctp_init_ping" do
110
- include_examples "optional port range", '-PY', :sctp_init_ping
111
- end
112
-
113
- describe "#ip_ping" do
114
- before { subject.ip_ping = protocols }
115
-
116
- context "when given a Boolean" do
117
- let(:protocols) { true }
118
-
119
- it "should emit the '-PO' option flag" do
120
- expect(subject.arguments).to eq(['-PO'])
121
- end
122
- end
123
-
124
- context "when given an empty Array" do
125
- let(:protocols) { [] }
126
-
127
- it "should emit the '-PO' option flag" do
128
- expect(subject.arguments).to eq(['-PO'])
129
- end
130
- end
131
-
132
- context "when given an Array of Integers" do
133
- let(:protocols) { [80, 21, 25] }
134
-
135
- it "should emit the '-PO' option flag with the Integer ports" do
136
- expect(subject.arguments).to eq(["-PO#{protocols.join(',')}"])
137
- end
138
- end
139
-
140
- context "when given an Array containing a Range" do
141
- let(:protocols) { [80, 21..25] }
142
-
143
- it "should emit the '-PO' option flag with the Integer ports" do
144
- expect(subject.arguments).to eq([
145
- "-PO#{protocols[0]},#{protocols[1].begin}-#{protocols[1].end}"
146
- ])
147
- end
148
- end
149
- end
150
- end