rex-core 0.1.14 → 0.1.15

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: 12eeafcdb4a07f89d5bab2bc024f330896c62ab9df2c45eadedeea0a85cfa7cb
4
- data.tar.gz: de9d82d23705151fe95b40df2781522110e13d31c9dc9deff2093a8c8ec7c940
3
+ metadata.gz: 30d6d74b1603e11dd926c24e867db559a88c9294fc1b4dc88559d66366928044
4
+ data.tar.gz: 7484592c2f3429b4481700937395ae6f0457b61fdddaf4abd9b780ebfff1de85
5
5
  SHA512:
6
- metadata.gz: 5b0bcea0b20d319598931bc2a4e8111d940019f22995fe12b84a66856d7835318cfa8ce5ad4e330a4a2100408dfe4cfd615a9cfea552a4215fac1541fa2e4a9a
7
- data.tar.gz: b605d32386312678d923c239a9a855c13b9a7137fa249a77ebd96e5a5ce5dc9d0a5c67b3b5280c708eceeb392e43ca937e28f950584d54bcd4af3b0522df0520
6
+ metadata.gz: '0698ecc78c85cb0497065dc82521be98a264784e4e76951d24ac36d82ab7f3a3e7ade7c6993127e1db1513157826edfd137dfe33d4ca71fa139088235f5694c6'
7
+ data.tar.gz: 1b819f79ced4a1656120ceeca644d4a634b5e54923bc3c2887edf76b9e28ed1e4de85c917ffeeef4cce5c239913b398492ba4b3f20f058700ad2b5fc9304427c
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.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.15"
4
4
  end
5
5
  end
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
  #
@@ -306,6 +327,45 @@ module Stream
306
327
 
307
328
  protected
308
329
 
330
+ #
331
+ # The read-write lock used to synchronize access to the stream. This is only
332
+ # set when synchronization has been initialized as performed by
333
+ # #initialize_synchronization.
334
+ #
335
+ attr_accessor :stream_lock
336
+
337
+ #
338
+ # A boolean flag indicating that the resource is to be closed. Blocking
339
+ # operations that are synchronized (such as #read and #write) should evaluate
340
+ # this flag and exit appropriately when there is no data to be processed.
341
+ attr_accessor :close_resource
342
+
343
+ #
344
+ # Synchronize non-state changing access to the stream such as read and write
345
+ # operations. If synchronization has not been initialized, this doesn't do
346
+ # anything.
347
+ #
348
+ def synchronize_access
349
+ self.stream_lock.lock_read unless self.stream_lock.nil?
350
+ begin
351
+ yield
352
+ ensure
353
+ self.stream_lock.unlock_read unless self.stream_lock.nil?
354
+ end
355
+ end
356
+
357
+ #
358
+ # Synchronize state changing operations to the stream such as closing it.
359
+ # If synchronization has not been initialized, this doesn't do anything.
360
+ #
361
+ def synchronize_update
362
+ self.stream_lock.lock_write unless self.stream_lock.nil?
363
+ begin
364
+ yield
365
+ ensure
366
+ self.stream_lock.unlock_write unless self.stream_lock.nil?
367
+ end
368
+ end
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
 
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.15
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-02-04 00:00:00.000000000 Z
97
97
  dependencies:
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
metadata.gz.sig CHANGED
@@ -1 +1 @@
1
- vidN��G����4�E��
1
+ �]��q���Oc���|����`_����� ���u�n�΃w�&?���;󢜒��q�