librex 0.0.44 → 0.0.46

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.
@@ -1,4 +1,4 @@
1
- # $Id: server.rb 11636 2011-01-25 02:24:37Z hdm $
1
+ # $Id: server.rb 13551 2011-08-12 20:26:03Z scriptjunkie $
2
2
  require 'rex/socket'
3
3
  require 'rex/proto/tftp'
4
4
 
@@ -162,7 +162,7 @@ class Server
162
162
 
163
163
  # Read the file contents, and register it as being served once
164
164
  data = data = ::File.open(fn, "rb") { |fd| fd.read(fd.stat.size) }
165
- register_file(fname, data, true)
165
+ register_file(fname, data)
166
166
 
167
167
  # Return the last file in the array
168
168
  return self.files[-1]
@@ -162,6 +162,9 @@ class RangeWalker
162
162
  # given RangeWalker
163
163
  #
164
164
  def include_range?(range_walker)
165
+ return false if ((not @ranges) or @ranges.empty?)
166
+ return false if not range_walker.ranges
167
+
165
168
  range_walker.ranges.all? do |start, stop|
166
169
  ranges.any? do |self_start, self_stop|
167
170
  r = (self_start..self_stop)
@@ -10,7 +10,7 @@ module Rex::Socket::SslTcp
10
10
 
11
11
  begin
12
12
  @@loaded_openssl = false
13
-
13
+
14
14
  begin
15
15
  require 'openssl'
16
16
  @@loaded_openssl = true
@@ -62,64 +62,64 @@ begin
62
62
  when 'SSL2'
63
63
  version = :SSLv2
64
64
  when 'SSL23'
65
- version = :SSLv23
65
+ version = :SSLv23
66
66
  when 'TLS1'
67
67
  version = :TLSv1
68
68
  end
69
69
  end
70
-
70
+
71
71
  # Build the SSL connection
72
72
  self.sslctx = OpenSSL::SSL::SSLContext.new(version)
73
-
73
+
74
74
  # Configure the SSL context
75
75
  # TODO: Allow the user to specify the verify mode and callback
76
76
  # Valid modes:
77
77
  # VERIFY_CLIENT_ONCE
78
- # VERIFY_FAIL_IF_NO_PEER_CERT
78
+ # VERIFY_FAIL_IF_NO_PEER_CERT
79
79
  # VERIFY_NONE
80
80
  # VERIFY_PEER
81
81
  self.sslctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
82
82
  self.sslctx.options = OpenSSL::SSL::OP_ALL
83
-
83
+
84
84
  # Set the verification callback
85
85
  self.sslctx.verify_callback = Proc.new do |valid, store|
86
86
  self.peer_verified = valid
87
87
  true
88
88
  end
89
-
89
+
90
90
  # Tie the context to a socket
91
91
  self.sslsock = OpenSSL::SSL::SSLSocket.new(self, self.sslctx)
92
92
 
93
93
  # XXX - enabling this causes infinite recursion, so disable for now
94
94
  # self.sslsock.sync_close = true
95
95
 
96
-
96
+
97
97
  # Force a negotiation timeout
98
98
  begin
99
- Timeout.timeout(params.timeout) do
100
- if not self.sslsock.respond_to?(:connect_nonblock)
99
+ Timeout.timeout(params.timeout) do
100
+ if not allow_nonblock?
101
101
  self.sslsock.connect
102
102
  else
103
103
  begin
104
104
  self.sslsock.connect_nonblock
105
-
105
+
106
106
  # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
107
107
  rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
108
108
  IO::select(nil, nil, nil, 0.10)
109
- retry
110
-
111
- # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
109
+ retry
110
+
111
+ # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
112
112
  rescue ::Exception => e
113
113
  if ::IO.const_defined?('WaitReadable') and e.kind_of?(::IO::WaitReadable)
114
114
  IO::select( [ self.sslsock ], nil, nil, 0.10 )
115
115
  retry
116
116
  end
117
-
118
- if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
117
+
118
+ if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
119
119
  IO::select( nil, [ self.sslsock ], nil, 0.10 )
120
120
  retry
121
121
  end
122
-
122
+
123
123
  raise e
124
124
  end
125
125
  end
@@ -140,7 +140,7 @@ begin
140
140
  # Writes data over the SSL socket.
141
141
  #
142
142
  def write(buf, opts = {})
143
- return sslsock.write(buf) if not self.sslsock.respond_to?(:write_nonblock)
143
+ return sslsock.write(buf) if not allow_nonblock?
144
144
 
145
145
  total_sent = 0
146
146
  total_length = buf.length
@@ -162,7 +162,7 @@ begin
162
162
 
163
163
  rescue ::IOError, ::Errno::EPIPE
164
164
  return nil
165
-
165
+
166
166
  # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
167
167
  rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
168
168
  # Sleep for a half a second, or until we can write again
@@ -171,24 +171,24 @@ begin
171
171
  block_size = 1024
172
172
  # Try to write the data again
173
173
  retry
174
-
175
- # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
174
+
175
+ # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
176
176
  rescue ::Exception => e
177
177
  if ::IO.const_defined?('WaitReadable') and e.kind_of?(::IO::WaitReadable)
178
178
  IO::select( [ self.sslsock ], nil, nil, retry_time )
179
179
  retry
180
180
  end
181
-
182
- if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
181
+
182
+ if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
183
183
  IO::select( nil, [ self.sslsock ], nil, retry_time )
184
184
  retry
185
185
  end
186
-
186
+
187
187
  # Another form of SSL error, this is always fatal
188
188
  if e.kind_of?(::OpenSSL::SSL::SSLError)
189
189
  return nil
190
190
  end
191
-
191
+
192
192
  # Bubble the event up to the caller otherwise
193
193
  raise e
194
194
  end
@@ -199,8 +199,8 @@ begin
199
199
  #
200
200
  # Reads data from the SSL socket.
201
201
  #
202
- def read(length = nil, opts = {})
203
- if not self.sslsock.respond_to?(:read_nonblock)
202
+ def read(length = nil, opts = {})
203
+ if not allow_nonblock?
204
204
  length = 16384 unless length
205
205
  begin
206
206
  return sslsock.sysread(length)
@@ -209,21 +209,21 @@ begin
209
209
  end
210
210
  return
211
211
  end
212
-
212
+
213
213
 
214
214
  begin
215
- while true
216
- s = Rex::ThreadSafe.select( [ self.sslsock ], nil, nil, 0.10 )
215
+ while true
216
+ s = Rex::ThreadSafe.select( [ self.sslsock ], nil, nil, 0.10 )
217
217
  if( s == nil || s[0] == nil )
218
218
  next
219
- end
220
- return sslsock.read_nonblock( length )
219
+ end
220
+ return sslsock.read_nonblock( length )
221
221
  end
222
-
222
+
223
223
  rescue ::IOError, ::Errno::EPIPE
224
224
  return nil
225
225
 
226
- # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
226
+ # Ruby 1.8.7 and 1.9.0/1.9.1 uses a standard Errno
227
227
  rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
228
228
  # Sleep for a tenth a second, or until we can read again
229
229
  Rex::ThreadSafe.select( [ self.sslsock ], nil, nil, 0.10 )
@@ -231,15 +231,15 @@ begin
231
231
  block_size = 1024
232
232
  # Try to write the data again
233
233
  retry
234
-
234
+
235
235
  # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
236
236
  rescue ::Exception => e
237
237
  if ::IO.const_defined?('WaitReadable') and e.kind_of?(::IO::WaitReadable)
238
238
  IO::select( [ self.sslsock ], nil, nil, 0.5 )
239
239
  retry
240
240
  end
241
-
242
- if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
241
+
242
+ if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
243
243
  IO::select( nil, [ self.sslsock ], nil, 0.5 )
244
244
  retry
245
245
  end
@@ -248,13 +248,13 @@ begin
248
248
  if e.kind_of?(::OpenSSL::SSL::SSLError)
249
249
  return nil
250
250
  end
251
-
251
+
252
252
  raise e
253
253
  end
254
254
 
255
255
  end
256
256
 
257
-
257
+
258
258
  #
259
259
  # Closes the SSL socket.
260
260
  #
@@ -263,35 +263,35 @@ begin
263
263
  super
264
264
  end
265
265
 
266
- #
266
+ #
267
267
  # Ignore shutdown requests
268
268
  #
269
269
  def shutdown(how=0)
270
270
  # Calling shutdown() on an SSL socket can lead to bad things
271
271
  # Cause of http://metasploit.com/dev/trac/ticket/102
272
272
  end
273
-
273
+
274
274
  #
275
275
  # Access to peer cert
276
276
  #
277
277
  def peer_cert
278
278
  sslsock.peer_cert if sslsock
279
279
  end
280
-
280
+
281
281
  #
282
282
  # Access to peer cert chain
283
283
  #
284
284
  def peer_cert_chain
285
285
  sslsock.peer_cert_chain if sslsock
286
286
  end
287
-
287
+
288
288
  #
289
289
  # Access to the current cipher
290
290
  #
291
291
  def cipher
292
292
  sslsock.cipher if sslsock
293
293
  end
294
-
294
+
295
295
  #
296
296
  # Prevent a sysread from the bare socket
297
297
  #
@@ -305,7 +305,20 @@ begin
305
305
  def syswrite(*args)
306
306
  raise RuntimeError, "Invalid syswrite() call on SSL socket"
307
307
  end
308
-
308
+
309
+ #
310
+ # This flag determines whether to use the non-blocking openssl
311
+ # API calls when they are available. This is still buggy on
312
+ # Linux/Mac OS X, but is required on Windows
313
+ #
314
+ def allow_nonblock?
315
+ avail = self.sslsock.respond_to?(:accept_nonblock)
316
+ if avail and Rex::Compat.is_windows
317
+ return true
318
+ end
319
+ false
320
+ end
321
+
309
322
  attr_reader :peer_verified # :nodoc:
310
323
  attr_accessor :sslsock, :sslctx # :nodoc:
311
324
 
@@ -322,3 +335,4 @@ end
322
335
  end
323
336
 
324
337
  end
338
+
@@ -58,8 +58,7 @@ module Rex::Socket::SslTcpServer
58
58
  begin
59
59
  ssl = OpenSSL::SSL::SSLSocket.new(sock, self.sslctx)
60
60
 
61
-
62
- if not ssl.respond_to?(:accept_nonblock)
61
+ if not allow_nonblock?(ssl)
63
62
  ssl.accept
64
63
  else
65
64
  begin
@@ -70,22 +69,22 @@ module Rex::Socket::SslTcpServer
70
69
  IO::select(nil, nil, nil, 0.10)
71
70
  retry
72
71
 
73
- # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
72
+ # Ruby 1.9.2+ uses IO::WaitReadable/IO::WaitWritable
74
73
  rescue ::Exception => e
75
74
  if ::IO.const_defined?('WaitReadable') and e.kind_of?(::IO::WaitReadable)
76
75
  IO::select( [ ssl ], nil, nil, 0.10 )
77
76
  retry
78
77
  end
79
-
80
- if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
78
+
79
+ if ::IO.const_defined?('WaitWritable') and e.kind_of?(::IO::WaitWritable)
81
80
  IO::select( nil, [ ssl ], nil, 0.10 )
82
81
  retry
83
82
  end
84
-
83
+
85
84
  raise e
86
85
  end
87
86
  end
88
-
87
+
89
88
  sock.extend(Rex::Socket::SslTcp)
90
89
  sock.sslsock = ssl
91
90
  sock.sslctx = self.sslctx
@@ -99,7 +98,7 @@ module Rex::Socket::SslTcpServer
99
98
  end
100
99
 
101
100
 
102
- #
101
+ #
103
102
  # Create a new ssl context. If +ssl_cert+ is not given, generates a new
104
103
  # key and a leaf certificate with random values.
105
104
  #
@@ -155,6 +154,19 @@ module Rex::Socket::SslTcpServer
155
154
  return ctx
156
155
  end
157
156
 
157
+ #
158
+ # This flag determines whether to use the non-blocking openssl
159
+ # API calls when they are available. This is still buggy on
160
+ # Linux/Mac OS X, but is required on Windows
161
+ #
162
+ def allow_nonblock?(sock=self.sock)
163
+ avail = sock.respond_to?(:accept_nonblock)
164
+ if avail and Rex::Compat.is_windows
165
+ return true
166
+ end
167
+ false
168
+ end
169
+
158
170
  attr_accessor :sslctx
159
171
  end
160
172
 
@@ -16,6 +16,7 @@ class Input
16
16
  require 'rex/ui/text/input/stdio'
17
17
  require 'rex/ui/text/input/readline'
18
18
  require 'rex/ui/text/input/socket'
19
+ require 'rex/ui/text/input/buffer'
19
20
  require 'rex/ui/text/color'
20
21
 
21
22
  include Rex::Ui::Text::Color
metadata CHANGED
@@ -1,31 +1,27 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: librex
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.46
4
5
  prerelease:
5
- version: 0.0.44
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Metasploit Development Team
9
9
  - Jacob Hammack
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-07-26 00:00:00 -05:00
15
- default_executable:
13
+ date: 2011-08-13 00:00:00.000000000Z
16
14
  dependencies: []
17
-
18
- description: Rex provides a variety of classes useful for security testing and exploit development. Based on SVN Revision 13354
19
- email:
15
+ description: Rex provides a variety of classes useful for security testing and exploit
16
+ development. Based on SVN Revision 13557
17
+ email:
20
18
  - hdm@metasploit.com
21
19
  - jacob.hammack@hammackj.com
22
20
  executables: []
23
-
24
21
  extensions: []
25
-
26
- extra_rdoc_files:
22
+ extra_rdoc_files:
27
23
  - README.markdown
28
- files:
24
+ files:
29
25
  - Rakefile
30
26
  - README.markdown
31
27
  - lib/rex/arch/sparc.rb
@@ -157,6 +153,7 @@ files:
157
153
  - lib/rex/parser/arguments.rb
158
154
  - lib/rex/parser/arguments.rb.ut.rb
159
155
  - lib/rex/parser/burp_session_nokogiri.rb
156
+ - lib/rex/parser/ci_nokogiri.rb
160
157
  - lib/rex/parser/foundstone_nokogiri.rb
161
158
  - lib/rex/parser/ini.rb
162
159
  - lib/rex/parser/ini.rb.ut.rb
@@ -215,6 +212,8 @@ files:
215
212
  - lib/rex/post/meterpreter/extensions/espia/tlv.rb
216
213
  - lib/rex/post/meterpreter/extensions/incognito/incognito.rb
217
214
  - lib/rex/post/meterpreter/extensions/incognito/tlv.rb
215
+ - lib/rex/post/meterpreter/extensions/lanattacks/lanattacks.rb
216
+ - lib/rex/post/meterpreter/extensions/lanattacks/tlv.rb
218
217
  - lib/rex/post/meterpreter/extensions/networkpug/networkpug.rb
219
218
  - lib/rex/post/meterpreter/extensions/networkpug/tlv.rb
220
219
  - lib/rex/post/meterpreter/extensions/priv/fs.rb
@@ -358,6 +357,14 @@ files:
358
357
  - lib/rex/proto/http/server.rb.ut.rb
359
358
  - lib/rex/proto/http.rb
360
359
  - lib/rex/proto/http.rb.ts.rb
360
+ - lib/rex/proto/iax2/call.rb
361
+ - lib/rex/proto/iax2/client.rb
362
+ - lib/rex/proto/iax2/codecs/alaw.rb
363
+ - lib/rex/proto/iax2/codecs/g711.rb
364
+ - lib/rex/proto/iax2/codecs/mulaw.rb
365
+ - lib/rex/proto/iax2/codecs.rb
366
+ - lib/rex/proto/iax2/constants.rb
367
+ - lib/rex/proto/iax2.rb
361
368
  - lib/rex/proto/ntlm/base.rb
362
369
  - lib/rex/proto/ntlm/constants.rb
363
370
  - lib/rex/proto/ntlm/crypt.rb
@@ -485,33 +492,29 @@ files:
485
492
  - lib/rex/zip.rb
486
493
  - lib/rex.rb
487
494
  - lib/rex.rb.ts.rb
488
- has_rdoc: true
489
495
  homepage: http://www.metasploit.com/
490
- licenses:
496
+ licenses:
491
497
  - BSD
492
498
  post_install_message:
493
499
  rdoc_options: []
494
-
495
- require_paths:
500
+ require_paths:
496
501
  - lib
497
- required_ruby_version: !ruby/object:Gem::Requirement
502
+ required_ruby_version: !ruby/object:Gem::Requirement
498
503
  none: false
499
- requirements:
500
- - - ">="
501
- - !ruby/object:Gem::Version
504
+ requirements:
505
+ - - ! '>='
506
+ - !ruby/object:Gem::Version
502
507
  version: 1.8.7
503
- required_rubygems_version: !ruby/object:Gem::Requirement
508
+ required_rubygems_version: !ruby/object:Gem::Requirement
504
509
  none: false
505
- requirements:
506
- - - ">="
507
- - !ruby/object:Gem::Version
508
- version: "0"
510
+ requirements:
511
+ - - ! '>='
512
+ - !ruby/object:Gem::Version
513
+ version: '0'
509
514
  requirements: []
510
-
511
515
  rubyforge_project:
512
- rubygems_version: 1.6.2
516
+ rubygems_version: 1.8.6
513
517
  signing_key:
514
518
  specification_version: 3
515
519
  summary: Ruby Exploitation Library
516
520
  test_files: []
517
-