ruby-nmap 0.7.0 → 0.8.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 +4 -4
- data/ChangeLog.md +17 -0
- data/Gemfile +7 -5
- data/lib/nmap/address.rb +1 -1
- data/lib/nmap/host.rb +27 -2
- data/lib/nmap/hostname.rb +22 -0
- data/lib/nmap/os.rb +1 -1
- data/lib/nmap/program.rb +23 -0
- data/lib/nmap/task.rb +9 -9
- data/lib/nmap/version.rb +1 -1
- data/lib/nmap/xml.rb +80 -1
- data/ruby-nmap.gemspec +1 -1
- data/spec/address_spec.rb +1 -1
- data/spec/cpe/url_spec.rb +16 -16
- data/spec/cpe_examples.rb +2 -2
- data/spec/hop_spec.rb +1 -1
- data/spec/host_spec.rb +69 -44
- data/spec/hostname_spec.rb +20 -3
- data/spec/ip_id_sequence_spec.rb +2 -2
- data/spec/nmap_spec.rb +1 -1
- data/spec/os_class_spec.rb +20 -10
- data/spec/os_match_spec.rb +1 -1
- data/spec/os_spec.rb +10 -9
- data/spec/port_spec.rb +18 -10
- data/spec/run_stat_spec.rb +1 -1
- data/spec/scan.xml +1 -0
- data/spec/scan_spec.rb +4 -4
- data/spec/scan_task_spec.rb +3 -3
- data/spec/scanner_spec.rb +1 -1
- data/spec/scripts_examples.rb +2 -2
- data/spec/sequence_examples.rb +4 -2
- data/spec/service_spec.rb +11 -11
- data/spec/spec_helper.rb +0 -26
- data/spec/status_spec.rb +1 -1
- data/spec/task_spec.rb +6 -6
- data/spec/tcp_sequence_spec.rb +3 -3
- data/spec/tcp_ts_sequence_spec.rb +2 -2
- data/spec/traceroute_spec.rb +20 -9
- data/spec/uptime_spec.rb +1 -1
- data/spec/xml_spec.rb +82 -44
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 388a408deac159e18f406b2a17c657ba3b775940
|
4
|
+
data.tar.gz: 0e532295c98b5e0b3e1e627b11d1891c3d25dac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c6f4a3931390deb37c27a64358055e04abd6e4f250f2c3379b9085f7885bf714006e43a2ca2bf73c44156f8057a41fc3f17d345663f7f49537f2462e0479c21
|
7
|
+
data.tar.gz: b3e882efab065007b1d7370106ac39f3472114cec80716e37017056f49288b008bed3f4f6cf7db05a8c31f0c0780ccf48aaa3f789f14326b48c271b8d2b00f26
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
### 0.8.0 / 2014-04-16
|
2
|
+
|
3
|
+
* Added {Nmap::XML#each_down_host}.
|
4
|
+
* Added {Nmap::XML#down_hosts}.
|
5
|
+
* Added {Nmap::XML#host}.
|
6
|
+
* Added {Nmap::XML#up_host}.
|
7
|
+
* Added {Nmap::XML#down_host}.
|
8
|
+
* Added {Nmap::Host#hostname}.
|
9
|
+
* Added {Nmap::Hostname#user?}.
|
10
|
+
* Added {Nmap::Hostname#ptr?}.
|
11
|
+
* Added {Nmap::Program.sudo_scan}.
|
12
|
+
* Added {Nmap::Program#sudo_scan}.
|
13
|
+
* Renamed {Nmap::XML.load} to {Nmap::XML.parse}.
|
14
|
+
* Fixed a typo in the `--privileged` flag (@BrentonEarl)
|
15
|
+
* Allow multiple values in the `--script` flag.
|
16
|
+
* Alias {Nmap::Task#script_params} to `script_args`.
|
17
|
+
|
1
18
|
### 0.7.0 / 2014-05-09
|
2
19
|
|
3
20
|
* Added {Nmap::CPE}.
|
data/Gemfile
CHANGED
@@ -3,10 +3,12 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development do
|
6
|
-
gem 'rake'
|
7
|
-
gem 'rubygems-tasks', '~> 0.
|
8
|
-
gem 'rspec', '~>
|
6
|
+
gem 'rake'
|
7
|
+
gem 'rubygems-tasks', '~> 0.2'
|
8
|
+
gem 'rspec', '~> 3.0'
|
9
|
+
|
10
|
+
gem 'json'
|
9
11
|
gem 'simplecov', '~> 0.7'
|
10
|
-
gem 'kramdown'
|
11
|
-
gem 'yard', '~> 0.
|
12
|
+
gem 'kramdown'
|
13
|
+
gem 'yard', '~> 0.8'
|
12
14
|
end
|
data/lib/nmap/address.rb
CHANGED
data/lib/nmap/host.rb
CHANGED
@@ -123,6 +123,20 @@ module Nmap
|
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
#
|
127
|
+
# Parses the MAC vendor of the host.
|
128
|
+
#
|
129
|
+
# @return [String]
|
130
|
+
# The Mac Vendor of the host.
|
131
|
+
#
|
132
|
+
# @since 0.8.0
|
133
|
+
#
|
134
|
+
def vendor
|
135
|
+
@vendor ||= if (vendor = @node.at("address[@vendor]"))
|
136
|
+
vendor['vendor']
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
126
140
|
#
|
127
141
|
# Parses the IPv4 address of the host.
|
128
142
|
#
|
@@ -200,6 +214,17 @@ module Nmap
|
|
200
214
|
each_hostname.to_a
|
201
215
|
end
|
202
216
|
|
217
|
+
#
|
218
|
+
# The primary hostname of the host.
|
219
|
+
#
|
220
|
+
# @return [Hostname, nil]
|
221
|
+
#
|
222
|
+
# @since 0.8.0
|
223
|
+
#
|
224
|
+
def hostname
|
225
|
+
each_hostname.first
|
226
|
+
end
|
227
|
+
|
203
228
|
#
|
204
229
|
# Parses the OS guessing information of the host.
|
205
230
|
#
|
@@ -525,12 +550,12 @@ module Nmap
|
|
525
550
|
# Converts the host to a String.
|
526
551
|
#
|
527
552
|
# @return [String]
|
528
|
-
# The address of the host.
|
553
|
+
# The hostname or address of the host.
|
529
554
|
#
|
530
555
|
# @see address
|
531
556
|
#
|
532
557
|
def to_s
|
533
|
-
address.to_s
|
558
|
+
(hostname || address).to_s
|
534
559
|
end
|
535
560
|
|
536
561
|
#
|
data/lib/nmap/hostname.rb
CHANGED
@@ -6,6 +6,28 @@ module Nmap
|
|
6
6
|
#
|
7
7
|
class Hostname < Struct.new(:type, :name)
|
8
8
|
|
9
|
+
#
|
10
|
+
# Determines if the hostname was specified by the user.
|
11
|
+
#
|
12
|
+
# @return [Boolean]
|
13
|
+
#
|
14
|
+
# @since 0.8.0
|
15
|
+
#
|
16
|
+
def user?
|
17
|
+
self.type == 'user'
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Determines if the hostname is a DNS `PTR`.
|
22
|
+
#
|
23
|
+
# @return [Boolean]
|
24
|
+
#
|
25
|
+
# @since 0.8.0
|
26
|
+
#
|
27
|
+
def ptr?
|
28
|
+
self.type == 'PTR'
|
29
|
+
end
|
30
|
+
|
9
31
|
#
|
10
32
|
# Converts the hostname to a String.
|
11
33
|
#
|
data/lib/nmap/os.rb
CHANGED
data/lib/nmap/program.rb
CHANGED
@@ -49,6 +49,18 @@ module Nmap
|
|
49
49
|
find.scan(options,exec_options,&block)
|
50
50
|
end
|
51
51
|
|
52
|
+
#
|
53
|
+
# Finds the `nmap` program and performs a scan, but runs `nmap` under
|
54
|
+
# `sudo`.
|
55
|
+
#
|
56
|
+
# @see scan
|
57
|
+
#
|
58
|
+
# @since 0.8.0
|
59
|
+
#
|
60
|
+
def self.sudo_scan(options={},exec_options={},&block)
|
61
|
+
find.sudo_scan(options,exec_options,&block)
|
62
|
+
end
|
63
|
+
|
52
64
|
#
|
53
65
|
# Performs a scan.
|
54
66
|
#
|
@@ -75,5 +87,16 @@ module Nmap
|
|
75
87
|
run_task(Task.new(options,&block),exec_options)
|
76
88
|
end
|
77
89
|
|
90
|
+
#
|
91
|
+
# Performs a scan and runs `nmap` under `sudo`.
|
92
|
+
#
|
93
|
+
# @see #scan
|
94
|
+
#
|
95
|
+
# @since 0.8.0
|
96
|
+
#
|
97
|
+
def sudo_scan(options={},exec_options={},&block)
|
98
|
+
sudo_task(Task.new(options,&block),exec_options)
|
99
|
+
end
|
100
|
+
|
78
101
|
end
|
79
102
|
end
|
data/lib/nmap/task.rb
CHANGED
@@ -14,7 +14,7 @@ module Nmap
|
|
14
14
|
# ### Host Discovery:
|
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`
|
@@ -156,8 +156,8 @@ module Nmap
|
|
156
156
|
# * `--versiondb` - `nmap.versiondb`
|
157
157
|
# * `--send-eth` - `nmap.raw_ethernet`
|
158
158
|
# * `--send-ip` - `nmap.raw_ip`
|
159
|
-
# * `--
|
160
|
-
# * `--
|
159
|
+
# * `--privileged` - `nmap.privileged`
|
160
|
+
# * `--unprivileged` - `nmap.unprivileged`
|
161
161
|
# * `--release-memory` - `nmap.release_memory`
|
162
162
|
# * `--interactive` - `nmap.interactive`
|
163
163
|
# * `-V` - `nmap.version`
|
@@ -177,7 +177,7 @@ module Nmap
|
|
177
177
|
|
178
178
|
# HOST DISCOVERY:
|
179
179
|
short_option :flag => '-sL', :name => :list
|
180
|
-
short_option :flag => '-
|
180
|
+
short_option :flag => '-sn', :name => :ping
|
181
181
|
short_option :flag => '-PN', :name => :skip_discovery
|
182
182
|
short_option :flag => '-PS', :name => :syn_discovery
|
183
183
|
short_option :flag => '-PA', :name => :ack_discovery
|
@@ -241,10 +241,10 @@ module Nmap
|
|
241
241
|
|
242
242
|
# SCRIPT SCAN:
|
243
243
|
short_option :flag => '-sC', :name => :default_script
|
244
|
-
long_option :flag => '--script'
|
245
|
-
long_option :flag => '--script-args',
|
246
|
-
|
247
|
-
|
244
|
+
long_option :flag => '--script', :separator => ','
|
245
|
+
long_option :flag => '--script-args', :separator => ','
|
246
|
+
alias script_params script_args
|
247
|
+
alias script_params= script_args=
|
248
248
|
long_option :flag => '--script-trace'
|
249
249
|
long_option :flag => '--script-updatedb', :name => :update_scriptdb
|
250
250
|
|
@@ -323,7 +323,7 @@ module Nmap
|
|
323
323
|
long_option :flag => '--versiondb'
|
324
324
|
long_option :flag => '--send-eth', :name => :raw_ethernet
|
325
325
|
long_option :flag => '--send-ip', :name => :raw_ip
|
326
|
-
long_option :flag => '--
|
326
|
+
long_option :flag => '--privileged'
|
327
327
|
long_option :flag => '--unprivleged'
|
328
328
|
long_option :flag => '--release-memory'
|
329
329
|
long_option :flag => '--interactive'
|
data/lib/nmap/version.rb
CHANGED
data/lib/nmap/xml.rb
CHANGED
@@ -55,10 +55,19 @@ module Nmap
|
|
55
55
|
# @yieldparam [XML] xml
|
56
56
|
# The newly created XML object.
|
57
57
|
#
|
58
|
+
# @since 0.8.0
|
59
|
+
#
|
60
|
+
def self.parse(text,&block)
|
61
|
+
new(Nokogiri::XML(text), &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# @deprecated Use {parse} instead.
|
66
|
+
#
|
58
67
|
# @since 0.7.0
|
59
68
|
#
|
60
69
|
def self.load(text,&block)
|
61
|
-
|
70
|
+
parse(text,&block)
|
62
71
|
end
|
63
72
|
|
64
73
|
#
|
@@ -263,6 +272,65 @@ module Nmap
|
|
263
272
|
each_host.to_a
|
264
273
|
end
|
265
274
|
|
275
|
+
#
|
276
|
+
# Returns the first host.
|
277
|
+
#
|
278
|
+
# @return [Host]
|
279
|
+
#
|
280
|
+
# @since 0.8.0
|
281
|
+
#
|
282
|
+
def host
|
283
|
+
each_host.first
|
284
|
+
end
|
285
|
+
|
286
|
+
#
|
287
|
+
# Parses the hosts that were found to be down during the scan.
|
288
|
+
#
|
289
|
+
# @yield [host]
|
290
|
+
# Each host will be passed to a given block.
|
291
|
+
#
|
292
|
+
# @yieldparam [Host] host
|
293
|
+
# A down host in the scan.
|
294
|
+
#
|
295
|
+
# @return [XML, Enumerator]
|
296
|
+
# The XML parser. If no block was given, an enumerator object will
|
297
|
+
# be returned.
|
298
|
+
#
|
299
|
+
# @since 0.8.0
|
300
|
+
#
|
301
|
+
def each_down_host
|
302
|
+
return enum_for(__method__) unless block_given?
|
303
|
+
|
304
|
+
@doc.xpath("/nmaprun/host[status[@state='down']]").each do |host|
|
305
|
+
yield Host.new(host)
|
306
|
+
end
|
307
|
+
|
308
|
+
return self
|
309
|
+
end
|
310
|
+
|
311
|
+
#
|
312
|
+
# Parses the hosts found to be down during the scan.
|
313
|
+
#
|
314
|
+
# @return [Array<Host>]
|
315
|
+
# The down hosts in the scan.
|
316
|
+
#
|
317
|
+
# @since 0.8.0
|
318
|
+
#
|
319
|
+
def down_hosts
|
320
|
+
each_down_host.to_a
|
321
|
+
end
|
322
|
+
|
323
|
+
#
|
324
|
+
# Returns the first host found to be down during the scan.
|
325
|
+
#
|
326
|
+
# @return [Host]
|
327
|
+
#
|
328
|
+
# @since 0.8.0
|
329
|
+
#
|
330
|
+
def down_host
|
331
|
+
each_down_host.first
|
332
|
+
end
|
333
|
+
|
266
334
|
#
|
267
335
|
# Parses the hosts that were found to be up during the scan.
|
268
336
|
#
|
@@ -296,6 +364,17 @@ module Nmap
|
|
296
364
|
each_up_host.to_a
|
297
365
|
end
|
298
366
|
|
367
|
+
#
|
368
|
+
# Returns the first host found to be up during the scan.
|
369
|
+
#
|
370
|
+
# @return [Host]
|
371
|
+
#
|
372
|
+
# @since 0.8.0
|
373
|
+
#
|
374
|
+
def up_host
|
375
|
+
each_up_host.first
|
376
|
+
end
|
377
|
+
|
299
378
|
#
|
300
379
|
# Parses the hosts that were found to be up during the scan.
|
301
380
|
#
|
data/ruby-nmap.gemspec
CHANGED
@@ -66,7 +66,7 @@ Gem::Specification.new do |gemspec|
|
|
66
66
|
gemspec.extra_rdoc_files = Array(metadata['extra_doc_files'])
|
67
67
|
|
68
68
|
gemspec.post_install_message = metadata['post_install_message']
|
69
|
-
gemspec.requirements = metadata['requirements']
|
69
|
+
gemspec.requirements = Array(metadata['requirements'])
|
70
70
|
|
71
71
|
if gemspec.respond_to?(:required_ruby_version=)
|
72
72
|
gemspec.required_ruby_version = metadata['required_ruby_version']
|
data/spec/address_spec.rb
CHANGED
data/spec/cpe/url_spec.rb
CHANGED
@@ -4,9 +4,9 @@ describe CPE::URL do
|
|
4
4
|
describe "parse" do
|
5
5
|
context "when the URL does not start with 'cpe:'" do
|
6
6
|
it "should raise an ArgumentError" do
|
7
|
-
|
7
|
+
expect {
|
8
8
|
described_class.parse('foo:')
|
9
|
-
}.
|
9
|
+
}.to raise_error(ArgumentError)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -20,13 +20,13 @@ describe CPE::URL do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it "should leave them nil" do
|
23
|
-
subject.vendor.
|
24
|
-
subject.product.
|
25
|
-
subject.version.
|
23
|
+
expect(subject.vendor).to eq(vendor)
|
24
|
+
expect(subject.product).to eq(product)
|
25
|
+
expect(subject.version).to eq(version)
|
26
26
|
|
27
|
-
subject.update.
|
28
|
-
subject.edition.
|
29
|
-
subject.language.
|
27
|
+
expect(subject.update).to be_nil
|
28
|
+
expect(subject.edition).to be_nil
|
29
|
+
expect(subject.language).to be_nil
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
@@ -34,7 +34,7 @@ describe CPE::URL do
|
|
34
34
|
subject { described_class.parse("cpe:/h:foo:bar:baz") }
|
35
35
|
|
36
36
|
it "should parse it as :hardware" do
|
37
|
-
subject.part.
|
37
|
+
expect(subject.part).to eq(:hardware)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -42,7 +42,7 @@ describe CPE::URL do
|
|
42
42
|
subject { described_class.parse("cpe:/a:foo:bar:baz") }
|
43
43
|
|
44
44
|
it "should parse it as :application" do
|
45
|
-
subject.part.
|
45
|
+
expect(subject.part).to eq(:application)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
@@ -50,7 +50,7 @@ describe CPE::URL do
|
|
50
50
|
subject { described_class.parse("cpe:/o:foo:bar:baz") }
|
51
51
|
|
52
52
|
it "should parse it as :os" do
|
53
|
-
subject.part.
|
53
|
+
expect(subject.part).to eq(:os)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -61,14 +61,14 @@ describe CPE::URL do
|
|
61
61
|
let(:version) { '2.6.39' }
|
62
62
|
|
63
63
|
it "should add the scheme 'cpe:'" do
|
64
|
-
subject.to_s.
|
64
|
+
expect(subject.to_s).to start_with('cpe:')
|
65
65
|
end
|
66
66
|
|
67
67
|
context "when fields are nil" do
|
68
68
|
subject { described_class.new(:os,vendor,product,version) }
|
69
69
|
|
70
70
|
it "should omit them" do
|
71
|
-
subject.to_s.
|
71
|
+
expect(subject.to_s).to eq("cpe:/o:#{vendor}:#{product}:#{version}")
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,7 +76,7 @@ describe CPE::URL do
|
|
76
76
|
subject { described_class.new(:hardware) }
|
77
77
|
|
78
78
|
it "should map it to /h" do
|
79
|
-
subject.to_s.
|
79
|
+
expect(subject.to_s).to eq("cpe:/h")
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -84,7 +84,7 @@ describe CPE::URL do
|
|
84
84
|
subject { described_class.new(:application) }
|
85
85
|
|
86
86
|
it "should map it to /h" do
|
87
|
-
subject.to_s.
|
87
|
+
expect(subject.to_s).to eq("cpe:/a")
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
@@ -92,7 +92,7 @@ describe CPE::URL do
|
|
92
92
|
subject { described_class.new(:os) }
|
93
93
|
|
94
94
|
it "should map it to /h" do
|
95
|
-
subject.to_s.
|
95
|
+
expect(subject.to_s).to eq("cpe:/o")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|