rex-core 0.1.14 → 0.1.18

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12eeafcdb4a07f89d5bab2bc024f330896c62ab9df2c45eadedeea0a85cfa7cb
4
- data.tar.gz: de9d82d23705151fe95b40df2781522110e13d31c9dc9deff2093a8c8ec7c940
3
+ metadata.gz: 00105f554d3867d9592962e1947385e8a4c24993a282e68aeb783b9577723d18
4
+ data.tar.gz: '094b794760fc51748acd69ee3eb84e0116e8c70fe62dac39c9369eef7bdb61f6'
5
5
  SHA512:
6
- metadata.gz: 5b0bcea0b20d319598931bc2a4e8111d940019f22995fe12b84a66856d7835318cfa8ce5ad4e330a4a2100408dfe4cfd615a9cfea552a4215fac1541fa2e4a9a
7
- data.tar.gz: b605d32386312678d923c239a9a855c13b9a7137fa249a77ebd96e5a5ce5dc9d0a5c67b3b5280c708eceeb392e43ca937e28f950584d54bcd4af3b0522df0520
6
+ metadata.gz: d6bfacda21b3c5f5dfdef68f9b82e0dabd703c4f429fa6df3582516babe96876a735c4597f2d52e74a57e8bc769b68db89bc82e751f602e6f99c73601f464b6e
7
+ data.tar.gz: '0159dd0334f7ac82d5c8df4d09b9b6b27126ae085a0557baf87e1eafd43487d6575d45e995d0f9f46d6bc0dc75585adeb37c2a0393d2bd9260070020be393045'
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Core
3
- VERSION = "0.1.14"
3
+ VERSION = "0.1.18"
4
4
  end
5
5
  end
@@ -145,9 +145,10 @@ end
145
145
  #
146
146
  ###
147
147
  module HostCommunicationError
148
- def initialize(addr = nil, port = nil)
149
- self.host = addr
150
- self.port = port
148
+ def initialize(addr = nil, port = nil, reason: nil)
149
+ @host = addr
150
+ @port = port
151
+ @reason = reason
151
152
  end
152
153
 
153
154
  #
@@ -156,7 +157,7 @@ module HostCommunicationError
156
157
  #
157
158
  def addr_to_s
158
159
  if host and port
159
- "(#{host}:#{port})"
160
+ host.include?(':') ? "([#{host}]:#{port})" : "(#{host}:#{port})"
160
161
  elsif host
161
162
  "(#{host})"
162
163
  else
@@ -164,7 +165,13 @@ module HostCommunicationError
164
165
  end
165
166
  end
166
167
 
167
- attr_accessor :host, :port
168
+ def to_s
169
+ str = super
170
+ str << " #{@reason}" if @reason
171
+ str
172
+ end
173
+
174
+ attr_accessor :host, :port, :reason
168
175
  end
169
176
 
170
177
 
@@ -186,7 +193,9 @@ end
186
193
  ###
187
194
  class ConnectionRefused < ConnectionError
188
195
  def to_s
189
- "The connection was refused by the remote host #{addr_to_s}."
196
+ str = "The connection was refused by the remote host #{addr_to_s}."
197
+ str << " #{@reason}" unless @reason.nil?
198
+ str
190
199
  end
191
200
  end
192
201
 
@@ -198,7 +207,9 @@ end
198
207
  ###
199
208
  class HostUnreachable < ConnectionError
200
209
  def to_s
201
- "The host #{addr_to_s} was unreachable."
210
+ str = "The host #{addr_to_s} was unreachable."
211
+ str << " #{@reason}" unless @reason.nil?
212
+ str
202
213
  end
203
214
  end
204
215
 
@@ -209,7 +220,9 @@ end
209
220
  ###
210
221
  class ConnectionTimeout < ConnectionError
211
222
  def to_s
212
- "The connection timed out #{addr_to_s}."
223
+ str = "The connection with #{addr_to_s} timed out."
224
+ str << " #{@reason}" unless @reason.nil?
225
+ str
213
226
  end
214
227
  end
215
228
 
@@ -220,18 +233,17 @@ end
220
233
  #
221
234
  ###
222
235
  class InvalidDestination < ConnectionError
223
- include SocketError
224
- include HostCommunicationError
225
-
226
236
  def to_s
227
- "The destination is invalid: #{addr_to_s}."
237
+ str = "The destination is invalid: #{addr_to_s}."
238
+ str << " #{@reason}" unless @reason.nil?
239
+ str
228
240
  end
229
241
  end
230
242
 
231
243
  ###
232
244
  #
233
245
  # This exception is raised when an attempt to use an address or port that is
234
- # already in use or onot available occurs. such as binding to a host on a
246
+ # already in use or not available occurs. such as binding to a host on a
235
247
  # given port that is already in use, or when a bind address is specified that
236
248
  # is not available to the host.
237
249
  #
@@ -241,7 +253,9 @@ class BindFailed < ::ArgumentError
241
253
  include HostCommunicationError
242
254
 
243
255
  def to_s
244
- "The address is already in use or unavailable: #{addr_to_s}."
256
+ str = "The address is already in use or unavailable: #{addr_to_s}."
257
+ str << " #{@reason}" unless @reason.nil?
258
+ str
245
259
  end
246
260
  end
247
261
 
@@ -255,11 +269,10 @@ end
255
269
  #
256
270
  ##
257
271
  class AddressInUse < ConnectionError
258
- include SocketError
259
- include HostCommunicationError
260
-
261
272
  def to_s
262
- "The address is already in use or unavailable: #{addr_to_s}."
273
+ str = "The address is already in use or unavailable: #{addr_to_s}."
274
+ str << " #{@reason}" unless @reason.nil?
275
+ str
263
276
  end
264
277
  end
265
278
 
data/lib/rex/file.rb CHANGED
@@ -130,7 +130,7 @@ module Find
130
130
  paths.collect!{|d| d.dup}
131
131
  while file = paths.shift
132
132
  catch(:prune) do
133
- yield file.dup.taint
133
+ yield file.dup
134
134
  next unless File.exist? file
135
135
  begin
136
136
  if File.stat(file).directory? then
@@ -145,7 +145,7 @@ module Find
145
145
  else
146
146
  f = File.join(file, f)
147
147
  end
148
- paths.unshift f.untaint
148
+ paths.unshift f
149
149
  end
150
150
  ensure
151
151
  d.close
data/lib/rex/io/stream.rb CHANGED
@@ -25,6 +25,22 @@ module Stream
25
25
  #
26
26
  ##
27
27
 
28
+ #
29
+ # Initialize synchronization for this stream. This should be used if the
30
+ # stream will be written to, read or closed from multiple threads.
31
+ #
32
+ def initialize_synchronization
33
+ self.stream_lock = Rex::ReadWriteLock.new
34
+ self.close_resource = false
35
+ end
36
+
37
+ def close
38
+ self.close_resource = true
39
+ synchronize_update {
40
+ super
41
+ }
42
+ end
43
+
28
44
  #
29
45
  # This method writes the supplied buffer to the stream. This method
30
46
  # intelligent reduces the size of supplied buffers so that ruby doesn't get
@@ -37,28 +53,31 @@ module Stream
37
53
  total_length = buf.length
38
54
  block_size = 32768
39
55
 
40
- begin
41
- while( total_sent < total_length )
42
- s = Rex::ThreadSafe.select( nil, [ fd ], nil, 0.2 )
43
- if( s == nil || s[0] == nil )
44
- next
45
- end
46
- data = buf[total_sent, block_size]
47
- sent = fd.write_nonblock( data )
48
- if sent > 0
49
- total_sent += sent
56
+ synchronize_access {
57
+ begin
58
+ while( total_sent < total_length )
59
+ s = Rex::ThreadSafe.select( nil, [ fd ], nil, 0.2 )
60
+ if( s == nil || s[0] == nil )
61
+ next
62
+ end
63
+ data = buf[total_sent, block_size]
64
+ sent = fd.write_nonblock( data )
65
+ if sent > 0
66
+ total_sent += sent
67
+ end
50
68
  end
69
+ rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
70
+ return nil if self.close_resource
71
+ # Sleep for a half a second, or until we can write again
72
+ Rex::ThreadSafe.select( nil, [ fd ], nil, 0.5 )
73
+ # Decrement the block size to handle full sendQs better
74
+ block_size = 1024
75
+ # Try to write the data again
76
+ retry
77
+ rescue ::IOError, ::Errno::EPIPE
78
+ return nil
51
79
  end
52
- rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
53
- # Sleep for a half a second, or until we can write again
54
- Rex::ThreadSafe.select( nil, [ fd ], nil, 0.5 )
55
- # Decrement the block size to handle full sendQs better
56
- block_size = 1024
57
- # Try to write the data again
58
- retry
59
- rescue ::IOError, ::Errno::EPIPE
60
- return nil
61
- end
80
+ }
62
81
 
63
82
  total_sent
64
83
  end
@@ -67,17 +86,19 @@ module Stream
67
86
  # This method reads data of the supplied length from the stream.
68
87
  #
69
88
  def read(length = nil, opts = {})
70
-
71
- begin
72
- return fd.read_nonblock( length )
73
- rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
74
- # Sleep for a half a second, or until we can read again
75
- Rex::ThreadSafe.select( [ fd ], nil, nil, 0.5 )
76
- # Decrement the block size to handle full sendQs better
77
- retry
78
- rescue ::IOError, ::Errno::EPIPE
79
- return nil
80
- end
89
+ synchronize_access {
90
+ begin
91
+ return fd.read_nonblock( length )
92
+ rescue ::Errno::EAGAIN, ::Errno::EWOULDBLOCK
93
+ return nil if self.close_resource
94
+ # Sleep for a half a second, or until we can read again
95
+ Rex::ThreadSafe.select( [ fd ], nil, nil, 0.5 )
96
+ # Decrement the block size to handle full sendQs better
97
+ retry
98
+ rescue ::IOError, ::Errno::EPIPE
99
+ return nil
100
+ end
101
+ }
81
102
  end
82
103
 
83
104
  #
@@ -304,8 +325,47 @@ module Stream
304
325
  16384
305
326
  end
306
327
 
328
+ #
329
+ # Synchronize non-state changing access to the stream such as read and write
330
+ # operations. If synchronization has not been initialized, this doesn't do
331
+ # anything.
332
+ #
333
+ def synchronize_access
334
+ self.stream_lock.lock_read unless self.stream_lock.nil?
335
+ begin
336
+ yield
337
+ ensure
338
+ self.stream_lock.unlock_read unless self.stream_lock.nil?
339
+ end
340
+ end
341
+
342
+ #
343
+ # Synchronize state changing operations to the stream such as closing it.
344
+ # If synchronization has not been initialized, this doesn't do anything.
345
+ #
346
+ def synchronize_update
347
+ self.stream_lock.lock_write unless self.stream_lock.nil?
348
+ begin
349
+ yield
350
+ ensure
351
+ self.stream_lock.unlock_write unless self.stream_lock.nil?
352
+ end
353
+ end
354
+
307
355
  protected
308
356
 
357
+ #
358
+ # The read-write lock used to synchronize access to the stream. This is only
359
+ # set when synchronization has been initialized as performed by
360
+ # #initialize_synchronization.
361
+ #
362
+ attr_accessor :stream_lock
363
+
364
+ #
365
+ # A boolean flag indicating that the resource is to be closed. Blocking
366
+ # operations that are synchronized (such as #read and #write) should evaluate
367
+ # this flag and exit appropriately when there is no data to be processed.
368
+ attr_accessor :close_resource
309
369
  end
310
370
 
311
371
  end end
@@ -19,10 +19,14 @@ module StreamAbstraction
19
19
  #
20
20
  def initialize_abstraction
21
21
  self.lsock, self.rsock = Rex::Socket.tcp_socket_pair()
22
+
22
23
  self.lsock.extend(Rex::IO::Stream)
23
24
  self.lsock.extend(Ext)
24
25
  self.rsock.extend(Rex::IO::Stream)
25
26
 
27
+ self.lsock.initialize_synchronization
28
+ self.rsock.initialize_synchronization
29
+
26
30
  self.monitor_rsock("StreamMonitorRemote")
27
31
  end
28
32
 
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
@@ -93,7 +93,7 @@ cert_chain:
93
93
  EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
94
94
  9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
95
95
  -----END CERTIFICATE-----
96
- date: 2020-11-30 00:00:00.000000000 Z
96
+ date: 2021-09-29 00:00:00.000000000 Z
97
97
  dependencies:
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
metadata.gz.sig CHANGED
Binary file