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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10533e46eeeaa57e4cf26c7944e4414ea3921999e31c6aa54d55de225f32494b
4
- data.tar.gz: 65aaebd79d602846dfc6cf0eecbcdef71cb0ae0282fd0d2dab54a3d1db571587
3
+ metadata.gz: 7e3189bf536d0b75455d40015a117eb26746aefbde6a6cccd605860be7fb8b6f
4
+ data.tar.gz: 303dcff7ac2ecb8f0a3e923ba9834e3044fd976be710a5f76d702e986827a640
5
5
  SHA512:
6
- metadata.gz: b82ab296170e41097a4eaba98480d1c4715643d6288d33f7626d959ad90c8cc925dee6fdf6654ed84e9bf03db1a4c9847bffac312bff4e4067c0b13af92aa145
7
- data.tar.gz: c6c439fd6e7999116dc61fd4b8713fa862be346c4e0c465dbba4c697363e18acb4985dd22358c2de77585579cb87cd91bbda451996e2b104ede04b23284b91e0
6
+ metadata.gz: 879272c70b52dc9b77abbb1990b4b48973d7a8f2e01b9a608ce9c3ce9a7c5240abeab1fc4bcdc4d30c59a8790b083f82a85a3254d962d0ccab0f7e4d2608c480
7
+ data.tar.gz: 709b91ce49dd96614de4441305a711cdb18fcb8185fffcc988f8c65ba9989785d65f69bf5e3dc05af7686ca26b0db43c90fb4710e86be44ddc20340042741507
@@ -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@v2
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2022 Postmodern
1
+ Copyright (c) 2009-2024 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -129,8 +129,6 @@ $ gem install ruby-nmap
129
129
 
130
130
  ## License
131
131
 
132
- Copyright (c) 2009-2022 Postmodern
133
-
134
132
  See {file:LICENSE.txt} for license information.
135
133
 
136
134
  [nmap]: http://www.insecure.org/
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
- PORT_NUMBER_REGEXP = /\d{1,5}/
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
- SERVICE_NAME_REGEXP = /[A-Za-z0-9]+(?:[\/_-][A-Za-z0-9]+)*\*?/
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
- case value
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
- PORT_RANGE_REGEXP = /(?:#{PORT_REGEXP}|#{PORT_REGEXP}?-#{PORT_REGEXP}?)/
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
- unless value =~ REGEXP
283
- return [false, "not a valid port range (#{value.inspect})"]
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 '--unprivleged'
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
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  # ruby-nmap version
3
- VERSION = '1.0.1'
5
+ VERSION = '1.0.3'
4
6
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  module CPE
data/lib/nmap/xml/cpe.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/cpe/url'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cpe/url'
2
4
 
3
5
  module Nmap
4
6
  class XML
data/lib/nmap/xml/hop.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
data/lib/nmap/xml/host.rb CHANGED
@@ -1,14 +1,16 @@
1
- require 'nmap/xml/status'
2
- require 'nmap/xml/address'
3
- require 'nmap/xml/hostname'
4
- require 'nmap/xml/os'
5
- require 'nmap/xml/port'
6
- require 'nmap/xml/ip_id_sequence'
7
- require 'nmap/xml/tcp_sequence'
8
- require 'nmap/xml/tcp_ts_sequence'
9
- require 'nmap/xml/uptime'
10
- require 'nmap/xml/traceroute'
11
- require 'nmap/xml/host_script'
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]
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/scripts'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scripts'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/sequence'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sequence'
2
4
 
3
5
  module Nmap
4
6
  class XML
data/lib/nmap/xml/os.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'nmap/xml/os_class'
2
- require 'nmap/xml/os_match'
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").map do |osclass|
76
+ @node.xpath("osmatch").each do |osclass|
75
77
  os_match = OSMatch.new(
76
78
  osclass['name'],
77
79
  osclass['accuracy'].to_i
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/cpe'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cpe'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
data/lib/nmap/xml/port.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'nmap/xml/service'
2
- require 'nmap/xml/scripts'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'service'
4
+ require_relative 'scripts'
3
5
 
4
6
  module Nmap
5
7
  class XML
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/scripts'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scripts'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/scripts'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'scripts'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
data/lib/nmap/xml/scan.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/script'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'script'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -27,7 +29,6 @@ module Nmap
27
29
 
28
30
  return @scripts
29
31
  end
30
-
31
32
  end
32
33
  end
33
34
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -24,7 +26,7 @@ module Nmap
24
26
  #
25
27
  # @return [String]
26
28
  # The sequence class from nmap.
27
- #
29
+ #
28
30
  # @since 0.5.0
29
31
  #
30
32
  def description
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/cpe'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'cpe'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/sequence'
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
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/sequence'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sequence'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,4 +1,6 @@
1
- require 'nmap/xml/hop'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'hop'
2
4
 
3
5
  module Nmap
4
6
  class XML
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nmap
2
4
  class XML
3
5
  #
data/lib/nmap/xml.rb CHANGED
@@ -1,10 +1,12 @@
1
- require 'nmap/xml/scanner'
2
- require 'nmap/xml/scan_task'
3
- require 'nmap/xml/scan'
4
- require 'nmap/xml/host'
5
- require 'nmap/xml/run_stat'
6
- require 'nmap/xml/prescript'
7
- require 'nmap/xml/postscript'
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
@@ -1,3 +1,5 @@
1
- require 'nmap/program'
2
- require 'nmap/xml'
3
- require 'nmap/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'nmap/program'
4
+ require_relative 'nmap/xml'
5
+ require_relative 'nmap/version'
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
- lib_dir = File.join(File.dirname(__FILE__),'lib')
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