ruby-nmap 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +3 -2
- data/ChangeLog.md +17 -0
- data/LICENSE.txt +1 -1
- data/README.md +0 -2
- data/lib/nmap/command.rb +57 -18
- data/lib/nmap/version.rb +3 -1
- data/lib/nmap/xml/address.rb +2 -0
- data/lib/nmap/xml/cpe/url.rb +2 -0
- data/lib/nmap/xml/cpe.rb +3 -1
- data/lib/nmap/xml/hop.rb +2 -0
- data/lib/nmap/xml/host.rb +14 -12
- data/lib/nmap/xml/host_script.rb +3 -1
- data/lib/nmap/xml/hostname.rb +2 -0
- data/lib/nmap/xml/ip_id_sequence.rb +3 -1
- data/lib/nmap/xml/os.rb +5 -3
- data/lib/nmap/xml/os_class.rb +3 -1
- data/lib/nmap/xml/os_match.rb +2 -0
- data/lib/nmap/xml/port.rb +4 -2
- data/lib/nmap/xml/postscript.rb +3 -1
- data/lib/nmap/xml/prescript.rb +3 -1
- data/lib/nmap/xml/run_stat.rb +2 -0
- data/lib/nmap/xml/scan.rb +2 -0
- data/lib/nmap/xml/scan_task.rb +2 -0
- data/lib/nmap/xml/scanner.rb +2 -0
- data/lib/nmap/xml/script.rb +2 -0
- data/lib/nmap/xml/scripts.rb +3 -2
- data/lib/nmap/xml/sequence.rb +3 -1
- data/lib/nmap/xml/service.rb +3 -1
- data/lib/nmap/xml/status.rb +2 -0
- data/lib/nmap/xml/tcp_sequence.rb +4 -2
- data/lib/nmap/xml/tcp_ts_sequence.rb +3 -1
- data/lib/nmap/xml/traceroute.rb +3 -1
- data/lib/nmap/xml/uptime.rb +2 -0
- data/lib/nmap/xml.rb +9 -7
- data/lib/nmap.rb +5 -3
- data/ruby-nmap.gemspec +2 -4
- data/spec/command_spec.rb +507 -23
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e3189bf536d0b75455d40015a117eb26746aefbde6a6cccd605860be7fb8b6f
|
4
|
+
data.tar.gz: 303dcff7ac2ecb8f0a3e923ba9834e3044fd976be710a5f76d702e986827a640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 879272c70b52dc9b77abbb1990b4b48973d7a8f2e01b9a608ce9c3ce9a7c5240abeab1fc4bcdc4d30c59a8790b083f82a85a3254d962d0ccab0f7e4d2608c480
|
7
|
+
data.tar.gz: 709b91ce49dd96614de4441305a711cdb18fcb8185fffcc988f8c65ba9989785d65f69bf5e3dc05af7686ca26b0db43c90fb4710e86be44ddc20340042741507
|
data/.github/workflows/ruby.yml
CHANGED
@@ -9,14 +9,15 @@ jobs:
|
|
9
9
|
fail-fast: false
|
10
10
|
matrix:
|
11
11
|
ruby:
|
12
|
-
- '2.7'
|
13
12
|
- '3.0'
|
14
13
|
- '3.1'
|
14
|
+
- '3.2'
|
15
|
+
- '3.3'
|
15
16
|
- jruby
|
16
17
|
- truffleruby
|
17
18
|
name: Ruby ${{ matrix.ruby }}
|
18
19
|
steps:
|
19
|
-
- uses: actions/checkout@
|
20
|
+
- uses: actions/checkout@v4
|
20
21
|
- name: Set up Ruby
|
21
22
|
uses: ruby/setup-ruby@v1
|
22
23
|
with:
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,20 @@
|
|
1
|
+
### 1.0.3 / 2024-01-25
|
2
|
+
|
3
|
+
* Switched to using `require_relative` to improve load-times.
|
4
|
+
* Added `# frozen_string_literal: true` to all files.
|
5
|
+
|
6
|
+
#### Nmap::Command
|
7
|
+
|
8
|
+
* The `--mtu` option now accepts an option numeric value.
|
9
|
+
|
10
|
+
### 1.0.2 / 2023-09-01
|
11
|
+
|
12
|
+
#### Nmap::Command
|
13
|
+
|
14
|
+
* Fixed a typo in the `--unprivileged` option mapping.
|
15
|
+
* Improved validations for port number, service name, port range, and
|
16
|
+
port list String values.
|
17
|
+
|
1
18
|
### 1.0.1 / 2022-12-12
|
2
19
|
|
3
20
|
* Fixed an infinite loop in {Nmap::XML::Script#parse_tables}. (@myztique)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
data/lib/nmap/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'command_mapper/command'
|
2
4
|
|
3
5
|
module Nmap
|
@@ -185,17 +187,23 @@ module Nmap
|
|
185
187
|
#
|
186
188
|
class Command < CommandMapper::Command
|
187
189
|
|
190
|
+
#
|
191
|
+
# Represents a port number.
|
188
192
|
#
|
189
193
|
# @api private
|
190
194
|
#
|
191
195
|
class Port < CommandMapper::Types::Num
|
192
196
|
|
193
|
-
|
197
|
+
# Regular expression that validates a port number.
|
198
|
+
PORT_NUMBER_REGEXP = /[1-9][0-9]{0,3}|[1-5][0-9][0-9][0-9][0-9]|6[0-4][0-9][0-9][0-9]|65[0-4][0-9][0-9]|655[0-2][0-9]|6553[0-5]/
|
194
199
|
|
195
|
-
|
200
|
+
# Regular expression that validates a service name.
|
201
|
+
SERVICE_NAME_REGEXP = /[A-Za-z][A-Za-z0-9]*(?:[\/_-][A-Za-z0-9]+)*\*?/
|
196
202
|
|
203
|
+
# Regular expression that validates either a port number or service name.
|
197
204
|
PORT_REGEXP = /(?:#{PORT_NUMBER_REGEXP}|#{SERVICE_NAME_REGEXP})/
|
198
205
|
|
206
|
+
# Regular expression that validates either a port number or service name.
|
199
207
|
REGEXP = /\A#{PORT_REGEXP}\z/
|
200
208
|
|
201
209
|
#
|
@@ -206,22 +214,22 @@ module Nmap
|
|
206
214
|
end
|
207
215
|
|
208
216
|
#
|
209
|
-
# Validates the given value.
|
217
|
+
# Validates the given port number value.
|
210
218
|
#
|
211
219
|
# @param [Object] value
|
220
|
+
# The value to validate.
|
212
221
|
#
|
213
222
|
# @return [true, (false, String)]
|
223
|
+
# Returns true if the value is valid, or `false` and a validation error
|
224
|
+
# message if the value is not compatible.
|
214
225
|
#
|
215
226
|
def validate(value)
|
216
227
|
case value
|
217
228
|
when String
|
218
|
-
|
219
|
-
when /\A#{PORT_NUMBER_REGEXP}\z/
|
220
|
-
super(value)
|
221
|
-
when /\A#{SERVICE_NAME_REGEXP}\z/
|
229
|
+
if value =~ REGEXP
|
222
230
|
return true
|
223
231
|
else
|
224
|
-
return [false, "must be a port number or service name (#{value.inspect})"]
|
232
|
+
return [false, "must be a valid port number or service name (#{value.inspect})"]
|
225
233
|
end
|
226
234
|
else
|
227
235
|
super(value)
|
@@ -232,8 +240,10 @@ module Nmap
|
|
232
240
|
# Formats the given value.
|
233
241
|
#
|
234
242
|
# @param [Integer, String] value
|
243
|
+
# The port number value to format.
|
235
244
|
#
|
236
245
|
# @return [String]
|
246
|
+
# The formatted port number.
|
237
247
|
#
|
238
248
|
def format(value)
|
239
249
|
case value
|
@@ -246,21 +256,28 @@ module Nmap
|
|
246
256
|
|
247
257
|
end
|
248
258
|
|
259
|
+
#
|
260
|
+
# Represents a port range.
|
249
261
|
#
|
250
262
|
# @api private
|
251
263
|
#
|
252
264
|
class PortRange < Port
|
253
265
|
|
254
|
-
|
266
|
+
# Regular expression to validate either a port or a port range.
|
267
|
+
PORT_RANGE_REGEXP = /(?:#{PORT_NUMBER_REGEXP})?-(?:#{PORT_NUMBER_REGEXP})?|#{PORT_REGEXP}/
|
255
268
|
|
269
|
+
# Regular expression to validate either a port or a port range.
|
256
270
|
REGEXP = /\A#{PORT_RANGE_REGEXP}\z/
|
257
271
|
|
258
272
|
#
|
259
|
-
# Validates the given value.
|
273
|
+
# Validates the given port or port range value.
|
260
274
|
#
|
261
275
|
# @param [Object] value
|
276
|
+
# The port or port range value to validate.
|
262
277
|
#
|
263
278
|
# @return [true, (false, String)]
|
279
|
+
# Returns true if the value is valid, or `false` and a validation error
|
280
|
+
# message if the value is not compatible.
|
264
281
|
#
|
265
282
|
def validate(value)
|
266
283
|
case value
|
@@ -279,22 +296,24 @@ module Nmap
|
|
279
296
|
|
280
297
|
return true
|
281
298
|
when String
|
282
|
-
|
283
|
-
return
|
299
|
+
if value =~ REGEXP
|
300
|
+
return true
|
301
|
+
else
|
302
|
+
return [false, "must be a valid port number, port range, or service name (#{value.inspect})"]
|
284
303
|
end
|
285
|
-
|
286
|
-
return true
|
287
304
|
else
|
288
305
|
super(value)
|
289
306
|
end
|
290
307
|
end
|
291
308
|
|
292
309
|
#
|
293
|
-
# Formats the given value.
|
310
|
+
# Formats the given port or port range value.
|
294
311
|
#
|
295
312
|
# @param [Range, Integer, String] value
|
313
|
+
# The port or port range value to format.
|
296
314
|
#
|
297
315
|
# @return [String]
|
316
|
+
# The formatted port or port range.
|
298
317
|
#
|
299
318
|
def format(value)
|
300
319
|
case value
|
@@ -307,13 +326,17 @@ module Nmap
|
|
307
326
|
|
308
327
|
end
|
309
328
|
|
329
|
+
#
|
330
|
+
# Represents a list of ports or port ranges.
|
310
331
|
#
|
311
332
|
# @api private
|
312
333
|
#
|
313
334
|
class PortRangeList < CommandMapper::Types::List
|
314
335
|
|
336
|
+
# Regular expression for validating a port or port range.
|
315
337
|
PORT_RANGE_REGEXP = PortRange::PORT_RANGE_REGEXP
|
316
338
|
|
339
|
+
# Regular expression for validating an nmap port range.
|
317
340
|
REGEXP = /\A(?:[TUS]:)?#{PORT_RANGE_REGEXP}(?:,(?:[TUS]:)?#{PORT_RANGE_REGEXP})*\z/
|
318
341
|
|
319
342
|
#
|
@@ -327,8 +350,11 @@ module Nmap
|
|
327
350
|
# Validates the given port range list value.
|
328
351
|
#
|
329
352
|
# @param [Object] value
|
353
|
+
# The given port range list value to validate.
|
330
354
|
#
|
331
355
|
# @return [true, (false, String)]
|
356
|
+
# Returns true if the value is valid, or `false` and a validation error
|
357
|
+
# message if the value is not compatible.
|
332
358
|
#
|
333
359
|
def validate(value)
|
334
360
|
case value
|
@@ -371,11 +397,13 @@ module Nmap
|
|
371
397
|
}
|
372
398
|
|
373
399
|
#
|
374
|
-
# Formats the given value.
|
400
|
+
# Formats the given port range list value.
|
375
401
|
#
|
376
402
|
# @param [Hash, Range, String, Integer] value
|
403
|
+
# The port range list value.
|
377
404
|
#
|
378
405
|
# @return [String]
|
406
|
+
# The formatted port range list.
|
379
407
|
#
|
380
408
|
def format(value)
|
381
409
|
case value
|
@@ -399,16 +427,21 @@ module Nmap
|
|
399
427
|
|
400
428
|
end
|
401
429
|
|
430
|
+
#
|
431
|
+
# Represents a list of protocols.
|
402
432
|
#
|
403
433
|
# @api private
|
404
434
|
#
|
405
435
|
ProtocolList = PortRangeList
|
406
436
|
|
437
|
+
#
|
438
|
+
# Represents a unit of time.
|
407
439
|
#
|
408
440
|
# @api private
|
409
441
|
#
|
410
442
|
class Time < CommandMapper::Types::Str
|
411
443
|
|
444
|
+
# Regular expression for validating a unit of time.
|
412
445
|
REGEXP = /\A\d+(?:h|m|s|ms)?\z/
|
413
446
|
|
414
447
|
#
|
@@ -443,6 +476,8 @@ module Nmap
|
|
443
476
|
|
444
477
|
end
|
445
478
|
|
479
|
+
#
|
480
|
+
# Represents a hex string.
|
446
481
|
#
|
447
482
|
# @api private
|
448
483
|
#
|
@@ -478,11 +513,14 @@ module Nmap
|
|
478
513
|
|
479
514
|
end
|
480
515
|
|
516
|
+
#
|
517
|
+
# Represents one or more TCP scan flags.
|
481
518
|
#
|
482
519
|
# @api private
|
483
520
|
#
|
484
521
|
class ScanFlags < CommandMapper::Types::Str
|
485
522
|
|
523
|
+
# Mapping of symbol scan flags to String values.
|
486
524
|
FLAGS = {
|
487
525
|
urg: 'URG',
|
488
526
|
ack: 'ACK',
|
@@ -492,6 +530,7 @@ module Nmap
|
|
492
530
|
fin: 'FIN'
|
493
531
|
}
|
494
532
|
|
533
|
+
# Regular expression to validate the given scan flags.
|
495
534
|
REGEXP = /\A(?:\d+|(?:URG|ACK|PSH|RST|SYN|FIN)+)\z/
|
496
535
|
|
497
536
|
#
|
@@ -697,7 +736,7 @@ module Nmap
|
|
697
736
|
|
698
737
|
# FIREWALL/IDS EVASION AND SPOOFING:
|
699
738
|
option '-f', name: :packet_fragments
|
700
|
-
option '--mtu'
|
739
|
+
option '--mtu', value: {type: Num.new, required: false}
|
701
740
|
option '-D', name: :decoys, value: {type: List.new}
|
702
741
|
option '-S', name: :spoof, value: true
|
703
742
|
option '-e', name: :interface, value: true
|
@@ -752,7 +791,7 @@ module Nmap
|
|
752
791
|
option '--send-eth'
|
753
792
|
option '--send-ip'
|
754
793
|
option '--privileged'
|
755
|
-
option '--
|
794
|
+
option '--unprivileged'
|
756
795
|
option '--release-memory'
|
757
796
|
option '--noninteractive', name: :non_interactive
|
758
797
|
option '-V', name: :version
|
data/lib/nmap/version.rb
CHANGED
data/lib/nmap/xml/address.rb
CHANGED
data/lib/nmap/xml/cpe/url.rb
CHANGED
data/lib/nmap/xml/cpe.rb
CHANGED
data/lib/nmap/xml/hop.rb
CHANGED
data/lib/nmap/xml/host.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'status'
|
4
|
+
require_relative 'address'
|
5
|
+
require_relative 'hostname'
|
6
|
+
require_relative 'os'
|
7
|
+
require_relative 'port'
|
8
|
+
require_relative 'ip_id_sequence'
|
9
|
+
require_relative 'tcp_sequence'
|
10
|
+
require_relative 'tcp_ts_sequence'
|
11
|
+
require_relative 'uptime'
|
12
|
+
require_relative 'traceroute'
|
13
|
+
require_relative 'host_script'
|
12
14
|
|
13
15
|
require 'nokogiri'
|
14
16
|
require 'time'
|
@@ -258,7 +260,7 @@ module Nmap
|
|
258
260
|
# @yield [uptime]
|
259
261
|
# If a block is given, it will be passed the resulting object
|
260
262
|
#
|
261
|
-
# @yieldparam [Uptime]
|
263
|
+
# @yieldparam [Uptime]
|
262
264
|
# Uptime value.
|
263
265
|
#
|
264
266
|
# @return [Uptime]
|
data/lib/nmap/xml/host_script.rb
CHANGED
data/lib/nmap/xml/hostname.rb
CHANGED
data/lib/nmap/xml/os.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'os_class'
|
4
|
+
require_relative 'os_match'
|
3
5
|
|
4
6
|
module Nmap
|
5
7
|
class XML
|
@@ -71,7 +73,7 @@ module Nmap
|
|
71
73
|
def each_match
|
72
74
|
return enum_for(__method__) unless block_given?
|
73
75
|
|
74
|
-
@node.xpath("osmatch").
|
76
|
+
@node.xpath("osmatch").each do |osclass|
|
75
77
|
os_match = OSMatch.new(
|
76
78
|
osclass['name'],
|
77
79
|
osclass['accuracy'].to_i
|
data/lib/nmap/xml/os_class.rb
CHANGED
data/lib/nmap/xml/os_match.rb
CHANGED
data/lib/nmap/xml/port.rb
CHANGED
data/lib/nmap/xml/postscript.rb
CHANGED
data/lib/nmap/xml/prescript.rb
CHANGED
data/lib/nmap/xml/run_stat.rb
CHANGED
data/lib/nmap/xml/scan.rb
CHANGED
data/lib/nmap/xml/scan_task.rb
CHANGED
data/lib/nmap/xml/scanner.rb
CHANGED
data/lib/nmap/xml/script.rb
CHANGED
data/lib/nmap/xml/scripts.rb
CHANGED
data/lib/nmap/xml/sequence.rb
CHANGED
data/lib/nmap/xml/service.rb
CHANGED
data/lib/nmap/xml/status.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sequence'
|
2
4
|
|
3
5
|
module Nmap
|
4
6
|
class XML
|
@@ -14,7 +16,7 @@ module Nmap
|
|
14
16
|
# The difficulty index from nmap
|
15
17
|
#
|
16
18
|
# @since 0.5.0
|
17
|
-
#
|
19
|
+
#
|
18
20
|
def index
|
19
21
|
@index ||= if (index_string = @node['index'])
|
20
22
|
index_string.to_i
|
data/lib/nmap/xml/traceroute.rb
CHANGED
data/lib/nmap/xml/uptime.rb
CHANGED
data/lib/nmap/xml.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'xml/scanner'
|
4
|
+
require_relative 'xml/scan_task'
|
5
|
+
require_relative 'xml/scan'
|
6
|
+
require_relative 'xml/host'
|
7
|
+
require_relative 'xml/run_stat'
|
8
|
+
require_relative 'xml/prescript'
|
9
|
+
require_relative 'xml/postscript'
|
8
10
|
|
9
11
|
require 'nokogiri'
|
10
12
|
|
data/lib/nmap.rb
CHANGED
data/ruby-nmap.gemspec
CHANGED
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
|
8
8
|
gem.name = gemspec.fetch('name')
|
9
9
|
gem.version = gemspec.fetch('version') do
|
10
|
-
|
11
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
-
|
13
|
-
require 'nmap/version'
|
10
|
+
require_relative 'lib/nmap/version'
|
14
11
|
Nmap::VERSION
|
15
12
|
end
|
16
13
|
|
@@ -20,6 +17,7 @@ Gem::Specification.new do |gem|
|
|
20
17
|
gem.authors = Array(gemspec['authors'])
|
21
18
|
gem.email = gemspec['email']
|
22
19
|
gem.homepage = gemspec['homepage']
|
20
|
+
gem.metadata = gemspec['metadata'] if gemspec['metadata']
|
23
21
|
|
24
22
|
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
25
23
|
|