ruby-nmap 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -1,3 +1,9 @@
1
+ ### 0.5.0 / 2011-04-11
2
+
3
+ * Require nokogiri ~> 1.3.
4
+ * Require rprogram ~> 0.3.
5
+ * `ip_scan` in {Nmap::Task} should map to `-sO` (thanks corvus).
6
+
1
7
  ### 0.4.1 / 2010-11-23
2
8
 
3
9
  * Fixed a bug in {Nmap::XML#each} where it was calling `each_up_hosts`,
data/README.md CHANGED
@@ -74,8 +74,8 @@ Print NSE script output from an XML scan file:
74
74
  ## Requirements
75
75
 
76
76
  * [nmap](http://www.insecure.org/) >= 5.00
77
- * [nokogiri](http://nokogiri.rubyforge.org/) >= 1.3.0
78
- * [rprogram](http://github.com/postmodern/rprogram) ~> 0.2.0
77
+ * [nokogiri](http://nokogiri.rubyforge.org/) ~> 1.3
78
+ * [rprogram](http://github.com/postmodern/rprogram) ~> 0.3
79
79
 
80
80
  ## Install
81
81
 
data/Rakefile CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'ore-tasks', '~> 0.3.0'
5
+ gem 'ore-tasks', '~> 0.4'
6
6
  require 'ore/tasks'
7
7
 
8
8
  Ore::Tasks.new
@@ -12,7 +12,7 @@ rescue LoadError => e
12
12
  end
13
13
 
14
14
  begin
15
- gem 'rspec', '~> 2.1.0'
15
+ gem 'rspec', '~> 2.4'
16
16
  require 'rspec/core/rake_task'
17
17
 
18
18
  RSpec::Core::RakeTask.new
@@ -22,6 +22,7 @@ rescue LoadError => e
22
22
  end
23
23
  end
24
24
  task :default => :spec
25
+ task :test => :spec
25
26
 
26
27
  begin
27
28
  gem 'yard', '~> 0.6.0'
@@ -13,10 +13,10 @@ has_yard: true
13
13
  requirements: nmap >= 5.00
14
14
 
15
15
  dependencies:
16
- nokogiri: >= 1.3.0
17
- rprogram: ~> 0.2.0
16
+ nokogiri: ~> 1.3
17
+ rprogram: ~> 0.3
18
18
 
19
19
  development_dependencies:
20
- ore-tasks: ~> 0.3.0
21
- rspec: ~> 2.1.0
20
+ ore-tasks: ~> 0.4
21
+ rspec: ~> 2.4
22
22
  yard: ~> 0.6.0
@@ -2,6 +2,9 @@ require 'nmap/status'
2
2
  require 'nmap/address'
3
3
  require 'nmap/os'
4
4
  require 'nmap/port'
5
+ require 'nmap/ip_id_sequence'
6
+ require 'nmap/tcp_sequence'
7
+ require 'nmap/tcp_ts_sequence'
5
8
 
6
9
  require 'nokogiri'
7
10
 
@@ -229,6 +232,57 @@ module Nmap
229
232
  end
230
233
  end
231
234
 
235
+ # Parses the Tcp Sequence number analysis of the host.
236
+ #
237
+ # @yield [tcpsequence]
238
+ # If a block is given, it will be passed the resulting object
239
+ #
240
+ # @yieldparam [TcpSequence] tcpsequence
241
+ # Tcp Sequence number analysis.
242
+ #
243
+ # @return [TcpSequence]
244
+ # The parsed object.
245
+ #
246
+ def tcpsequence(&block)
247
+ if (seq = @node.at('tcpsequence'))
248
+ @tcpsequence = TcpSequence.new(seq,&block)
249
+ end
250
+ end
251
+
252
+ # Parses the IPID sequence number analysis of the host.
253
+ #
254
+ # @yield [ipidsequence]
255
+ # If a block is given, it will be passed the resulting object
256
+ #
257
+ # @yieldparam [IpidSequence] ipidsequence
258
+ # IPID Sequence number analysis.
259
+ #
260
+ # @return [IpidSequence]
261
+ # The parsed object.
262
+ #
263
+ def ipidsequence(&block)
264
+ if (seq = @node.at('ipidsequence'))
265
+ @ipidsequence = IpidSequence.new(seq,&block)
266
+ end
267
+ end
268
+
269
+ # Parses the TCP Timestamp sequence number analysis of the host.
270
+ #
271
+ # @yield [tcptssequence]
272
+ # If a block is given, it will be passed the resulting object
273
+ #
274
+ # @yieldparam [TcpTsSequence] tcptssequence
275
+ # TCP Timestamp Sequence number analysis.
276
+ #
277
+ # @return [TcpTsSequence]
278
+ # The parsed object.
279
+ #
280
+ def tcptssequence(&block)
281
+ if (seq = @node.at('tcptssequence'))
282
+ @tcptssequence = TcpTsSequence.new(seq,&block)
283
+ end
284
+ end
285
+
232
286
  #
233
287
  # Parses the scanned ports of the host.
234
288
  #
@@ -0,0 +1,19 @@
1
+ require 'nmap/sequence'
2
+
3
+ module Nmap
4
+ class IpidSequence < Sequence
5
+
6
+ #
7
+ # Converts the IpidSequence class to a String.
8
+ #
9
+ # @return [String]
10
+ # The String form of the object.
11
+ #
12
+ # @since 0.5.0
13
+ #
14
+ def to_s
15
+ "description=#{description.inspect} values=#{values.inspect}"
16
+ end
17
+
18
+ end
19
+ end
@@ -61,7 +61,7 @@ module Nmap
61
61
  # The OS class information.
62
62
  #
63
63
  def classes
64
- enum_for(:each_class).to_a
64
+ each_class.to_a
65
65
  end
66
66
 
67
67
  #
@@ -99,7 +99,7 @@ module Nmap
99
99
  # The OS match information.
100
100
  #
101
101
  def matches
102
- enum_for(:each_match).to_a
102
+ each_match.to_a
103
103
  end
104
104
 
105
105
  #
@@ -13,6 +13,9 @@ module Nmap
13
13
  # @param [Hash{Symbol => Object}] options
14
14
  # Additional options for nmap.
15
15
  #
16
+ # @param [Hash{Symbol => Object}] exec_options
17
+ # Additional exec-options.
18
+ #
16
19
  # @yield [task]
17
20
  # If a block is given, it will be passed a task object
18
21
  # used to specify options for nmap.
@@ -37,8 +40,10 @@ module Nmap
37
40
  # nmap.verbose = true
38
41
  # end
39
42
  #
40
- def self.scan(options={},&block)
41
- self.find.scan(options,&block)
43
+ # @see #scan
44
+ #
45
+ def self.scan(options={},exec_options={},&block)
46
+ find.scan(options,exec_options,&block)
42
47
  end
43
48
 
44
49
  #
@@ -47,6 +52,9 @@ module Nmap
47
52
  # @param [Hash{Symbol => Object}] options
48
53
  # Additional options for nmap.
49
54
  #
55
+ # @param [Hash{Symbol => Object}] exec_options
56
+ # Additional exec-options.
57
+ #
50
58
  # @yield [task]
51
59
  # If a block is given, it will be passed a task object
52
60
  # used to specify options for nmap.
@@ -57,8 +65,11 @@ module Nmap
57
65
  # @return [Boolean]
58
66
  # Specifies whether the command exited normally.
59
67
  #
60
- def scan(options={},&block)
61
- run_task(Task.new(options,&block))
68
+ # @see http://rubydoc.info/gems/rprogram/0.3.0/RProgram/Program#run-instance_method
69
+ # For additional exec-options.
70
+ #
71
+ def scan(options={},exec_options={},&block)
72
+ run_task(Task.new(options,&block),exec_options)
62
73
  end
63
74
 
64
75
  end
@@ -0,0 +1,57 @@
1
+ module Nmap
2
+ class Sequence
3
+
4
+ #
5
+ # Creates a new sequence object.
6
+ #
7
+ # @param [Nokogiri::XML::Node] node
8
+ # The node that contains the sequence information.
9
+ #
10
+ # @yield [sequence]
11
+ # If a block is given, it will passed the newly created sequence.
12
+ #
13
+ # @yieldparam [Sequence] sequence
14
+ # The newly created sequence object.
15
+ #
16
+ # @since 0.5.0
17
+ #
18
+ def initialize(node)
19
+ @node = node
20
+
21
+ yield self if block_given?
22
+ end
23
+
24
+ #
25
+ # The description of the sequence.
26
+ #
27
+ # @return [String]
28
+ # The sequence class from nmap.
29
+ #
30
+ # @since 0.5.0
31
+ #
32
+ def description
33
+ @node['class']
34
+ end
35
+
36
+ #
37
+ # The values within the sequence.
38
+ #
39
+ # @return [Array<Numeric>]
40
+ # A sample of sequence numbers taken by nmap.
41
+ #
42
+ # @since 0.5.0
43
+ #
44
+ def values
45
+ unless @values
46
+ @values = []
47
+
48
+ if (string = @node['values'])
49
+ string.scan(/[^\s,]+/) { |match| @values << match.to_i(16) }
50
+ end
51
+ end
52
+
53
+ return @values
54
+ end
55
+
56
+ end
57
+ end
@@ -46,7 +46,7 @@ module Nmap
46
46
  # * `--scanflags` - `nmap.tcp_scan_flags`
47
47
  # * `-sZ` - `nmap.sctp_cookie_echo_scan`
48
48
  # * `-sI` - `nmap.idle_scan`
49
- # * `-s0` - `nmap.ip_scan`
49
+ # * `-sO` - `nmap.ip_scan`
50
50
  # * `-b` - `nmap.ftp_bounce_scan`
51
51
  #
52
52
  # ### Port Specification and Scan Order:
@@ -208,7 +208,7 @@ module Nmap
208
208
  long_option :flag => '--scanflags', :name => :tcp_scan_flags
209
209
  short_option :flag => '-sZ', :name => :sctp_cookie_echo_scan
210
210
  short_option :flag => '-sI', :name => :idle_scan
211
- short_option :flag => '-s0', :name => :ip_scan
211
+ short_option :flag => '-sO', :name => :ip_scan
212
212
  short_option :flag => '-b', :name => :ftp_bounce_scan
213
213
 
214
214
  # PORT SPECIFICATION AND SCAN ORDER:
@@ -0,0 +1,41 @@
1
+ require 'nmap/sequence'
2
+
3
+ module Nmap
4
+ class TcpSequence < Sequence
5
+
6
+ #
7
+ # @return [Numeric]
8
+ # The difficulty index from nmap
9
+ #
10
+ # @since 0.5.0
11
+ #
12
+ def index
13
+ @index ||= if (index_string = @node['index'])
14
+ index_string.to_i
15
+ end
16
+ end
17
+
18
+ #
19
+ # @return [String]
20
+ # The difficulty description from nmap
21
+ #
22
+ # @since 0.5.0
23
+ #
24
+ def difficulty
25
+ @node['difficulty']
26
+ end
27
+
28
+ #
29
+ # Converts the TcpSequence class to a String.
30
+ #
31
+ # @return [String]
32
+ # The String form of the object.
33
+ #
34
+ # @since 0.5.0
35
+ #
36
+ def to_s
37
+ "index=#{index} difficulty=#{difficulty.inspect} values=#{values.inspect}"
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require 'nmap/sequence'
2
+
3
+ module Nmap
4
+ class TcpTsSequence < Sequence
5
+
6
+ #
7
+ # Converts the TcpTsSequence class to a String.
8
+ #
9
+ # @return [String]
10
+ # The String form of the object.
11
+ #
12
+ # @since 0.5.0
13
+ #
14
+ def to_s
15
+ "description=#{description.inspect} values=#{values.inspect}"
16
+ end
17
+
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
1
  module Nmap
2
2
  # ruby-nmap version
3
- VERSION = '0.4.1'
3
+ VERSION = '0.5.0'
4
4
  end
@@ -150,7 +150,7 @@ module Nmap
150
150
  # The hosts in the scan.
151
151
  #
152
152
  def hosts
153
- enum_for(:each_host).to_a
153
+ each_host.to_a
154
154
  end
155
155
 
156
156
  #
@@ -183,7 +183,7 @@ module Nmap
183
183
  # The hosts in the scan.
184
184
  #
185
185
  def up_hosts
186
- enum_for(:each_up_host).to_a
186
+ each_up_host.to_a
187
187
  end
188
188
 
189
189
  #
@@ -5,6 +5,11 @@ begin
5
5
  # custom logic here
6
6
  end
7
7
  rescue NameError
8
- STDERR.puts "The 'ruby-nmap.gemspec' file requires Ore."
9
- STDERR.puts "Run `gem install ore-core` to install Ore."
8
+ begin
9
+ require 'ore/specification'
10
+ retry
11
+ rescue LoadError
12
+ STDERR.puts "The 'ruby-nmap.gemspec' file requires Ore."
13
+ STDERR.puts "Run `gem install ore-core` to install Ore."
14
+ end
10
15
  end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'helpers/xml'
3
+
4
+ require 'nmap/tcp_sequence'
5
+ require 'nmap/tcp_ts_sequence'
6
+ require 'nmap/ip_id_sequence'
7
+ require 'nmap/xml'
8
+ require 'cgi'
9
+
10
+ describe TcpSequence do
11
+ include Helpers
12
+
13
+ before(:all) do
14
+ @xml = XML.new(Helpers::SCAN_FILE)
15
+ @tcpsequence = @xml.hosts.first.tcpsequence
16
+ end
17
+
18
+ it "should be accessible from host objects" do
19
+ @tcpsequence.should be_kind_of(TcpSequence)
20
+ end
21
+
22
+ it "should parse the index" do
23
+ @tcpsequence.index.should == 25
24
+ end
25
+
26
+ it "should parse the difficulty description" do
27
+ @tcpsequence.difficulty.should == "Good luck!"
28
+ end
29
+
30
+ it "should parse the values" do
31
+ @tcpsequence.values.should == [0xAF1B39BD,0xAF1C33BD,0xAF1F21BD,0xAF201BBD,0xAF2115BD,0xAF220FBD]
32
+ end
33
+ end
34
+
35
+ describe IpidSequence do
36
+ include Helpers
37
+
38
+ before(:all) do
39
+ @xml = XML.new(Helpers::SCAN_FILE)
40
+ @ipidsequence = @xml.hosts.first.ipidsequence
41
+ end
42
+
43
+ it "should be accessible from host objects" do
44
+ @ipidsequence.should be_kind_of(IpidSequence)
45
+ end
46
+
47
+ it "should parse the description" do
48
+ @ipidsequence.description.should == "Incremental"
49
+ end
50
+
51
+ it "should parse the values" do
52
+ @ipidsequence.values.should == [0x1FB0,0x1FB2,0x1FB4,0x1FB6,0x1FB8,0x1FBA]
53
+ end
54
+ end
55
+
56
+ describe TcpTsSequence do
57
+ include Helpers
58
+
59
+ before(:all) do
60
+ @xml = XML.new(Helpers::SCAN_FILE)
61
+ @tcptssequence = @xml.hosts.first.tcptssequence
62
+ end
63
+
64
+ it "should be accessible from host objects" do
65
+ @tcptssequence.should be_kind_of(TcpTsSequence)
66
+ end
67
+
68
+ it "should parse the description" do
69
+ @tcptssequence.description.should == "2HZ"
70
+ end
71
+
72
+ it "should parse the values" do
73
+ @tcptssequence.values.should == [0x1858,0x1858,0x1859,0x1859,0x1859,0x1859]
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
- gem 'rspec', '~> 2.1.0'
1
+ gem 'rspec', '~> 2.4'
2
2
  require 'rspec'
3
- require 'nmap/version'
4
3
 
4
+ require 'nmap/version'
5
5
  include Nmap
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-nmap
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
4
+ prerelease:
5
+ version: 0.5.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Postmodern
@@ -14,8 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-11-23 00:00:00 -08:00
18
- default_executable:
13
+ date: 2011-04-11 00:00:00 Z
19
14
  dependencies:
20
15
  - !ruby/object:Gem::Dependency
21
16
  name: nokogiri
@@ -23,13 +18,9 @@ dependencies:
23
18
  requirement: &id001 !ruby/object:Gem::Requirement
24
19
  none: false
25
20
  requirements:
26
- - - ">="
21
+ - - ~>
27
22
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 3
31
- - 0
32
- version: 1.3.0
23
+ version: "1.3"
33
24
  type: :runtime
34
25
  version_requirements: *id001
35
26
  - !ruby/object:Gem::Dependency
@@ -40,11 +31,7 @@ dependencies:
40
31
  requirements:
41
32
  - - ~>
42
33
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 2
46
- - 0
47
- version: 0.2.0
34
+ version: "0.3"
48
35
  type: :runtime
49
36
  version_requirements: *id002
50
37
  - !ruby/object:Gem::Dependency
@@ -55,11 +42,7 @@ dependencies:
55
42
  requirements:
56
43
  - - ~>
57
44
  - !ruby/object:Gem::Version
58
- segments:
59
- - 0
60
- - 3
61
- - 0
62
- version: 0.3.0
45
+ version: "0.4"
63
46
  type: :development
64
47
  version_requirements: *id003
65
48
  - !ruby/object:Gem::Dependency
@@ -70,11 +53,7 @@ dependencies:
70
53
  requirements:
71
54
  - - ~>
72
55
  - !ruby/object:Gem::Version
73
- segments:
74
- - 2
75
- - 1
76
- - 0
77
- version: 2.1.0
56
+ version: "2.4"
78
57
  type: :development
79
58
  version_requirements: *id004
80
59
  - !ruby/object:Gem::Dependency
@@ -85,15 +64,12 @@ dependencies:
85
64
  requirements:
86
65
  - - ~>
87
66
  - !ruby/object:Gem::Version
88
- segments:
89
- - 0
90
- - 6
91
- - 0
92
67
  version: 0.6.0
93
68
  type: :development
94
69
  version_requirements: *id005
95
70
  description: A Ruby interface to Nmap, the exploration tool and security / port scanner.
96
- email: postmodern.mod3@gmail.com
71
+ email:
72
+ - postmodern.mod3@gmail.com
97
73
  executables: []
98
74
 
99
75
  extensions: []
@@ -101,6 +77,7 @@ extensions: []
101
77
  extra_rdoc_files:
102
78
  - README.md
103
79
  files:
80
+ - .gemtest
104
81
  - .rspec
105
82
  - .yardopts
106
83
  - ChangeLog.md
@@ -111,6 +88,7 @@ files:
111
88
  - lib/nmap.rb
112
89
  - lib/nmap/address.rb
113
90
  - lib/nmap/host.rb
91
+ - lib/nmap/ip_id_sequence.rb
114
92
  - lib/nmap/os.rb
115
93
  - lib/nmap/os_class.rb
116
94
  - lib/nmap/os_match.rb
@@ -119,8 +97,11 @@ files:
119
97
  - lib/nmap/scan.rb
120
98
  - lib/nmap/scan_task.rb
121
99
  - lib/nmap/scanner.rb
100
+ - lib/nmap/sequence.rb
122
101
  - lib/nmap/status.rb
123
102
  - lib/nmap/task.rb
103
+ - lib/nmap/tcp_sequence.rb
104
+ - lib/nmap/tcp_ts_sequence.rb
124
105
  - lib/nmap/version.rb
125
106
  - lib/nmap/xml.rb
126
107
  - ruby-nmap.gemspec
@@ -131,10 +112,10 @@ files:
131
112
  - spec/nmap_spec.rb
132
113
  - spec/os_spec.rb
133
114
  - spec/port_spec.rb
115
+ - spec/sequence_spec.rb
134
116
  - spec/spec_helper.rb
135
117
  - spec/task_spec.rb
136
118
  - spec/xml_spec.rb
137
- has_rdoc: yard
138
119
  homepage: http://github.com/sophsec/ruby-nmap
139
120
  licenses:
140
121
  - MIT
@@ -148,21 +129,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
129
  requirements:
149
130
  - - ">="
150
131
  - !ruby/object:Gem::Version
151
- segments:
152
- - 0
153
132
  version: "0"
154
133
  required_rubygems_version: !ruby/object:Gem::Requirement
155
134
  none: false
156
135
  requirements:
157
136
  - - ">="
158
137
  - !ruby/object:Gem::Version
159
- segments:
160
- - 0
161
138
  version: "0"
162
139
  requirements:
163
140
  - nmap >= 5.00
164
141
  rubyforge_project: ruby-nmap
165
- rubygems_version: 1.3.7
142
+ rubygems_version: 1.7.2
166
143
  signing_key:
167
144
  specification_version: 3
168
145
  summary: A Ruby interface to Nmap.
@@ -170,6 +147,7 @@ test_files:
170
147
  - spec/host_spec.rb
171
148
  - spec/port_spec.rb
172
149
  - spec/nmap_spec.rb
150
+ - spec/sequence_spec.rb
173
151
  - spec/os_spec.rb
174
152
  - spec/xml_spec.rb
175
153
  - spec/task_spec.rb