rex-core 0.1.19 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +3 -3
- data/.github/workflows/verify.yml +45 -0
- data/lib/rex/core/version.rb +1 -1
- data/lib/rex/io/socket_abstraction.rb +170 -180
- data/lib/rex/stopwatch.rb +10 -5
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0378775512fe632afba68913d5d3eed8fc39ff2eeaf5a849b4101dbbab49026
|
4
|
+
data.tar.gz: 8d2cde8487dcb4c9d2c7102eddd0f5777f9ba6bd67ea58649a8fe8ff03203a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f88261f6d1982c3b2903224776481a21c16b3336e0c448a934f0daf3b073ae7ebe76f7a6f2e6b5c7aacbd3639a184c559b99c2e8f14091c15a68a3790ba0399
|
7
|
+
data.tar.gz: 42de568303940c9a7a28ccaa19954d21e05e85b204cb0f4febd761dc150d682fbf6f3a76da5bca9804b082dbc2989e3bcb2013aa65294db6271ee7add0e157cd
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
�
|
3
|
-
|
1
|
+
oUc�)��w>�AǸ��EaĚ%�&�M9�����g�A�fw�Q$�y�\
|
2
|
+
�yI!����)
|
3
|
+
�M^������`�t�R��?�)���b��5�D�Y�������������{���a��{j���P4�������ݘL�����#��P
|
@@ -0,0 +1,45 @@
|
|
1
|
+
name: Verify
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- '*'
|
7
|
+
pull_request:
|
8
|
+
branches:
|
9
|
+
- '*'
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
test:
|
13
|
+
runs-on: ubuntu-18.04
|
14
|
+
timeout-minutes: 40
|
15
|
+
|
16
|
+
strategy:
|
17
|
+
fail-fast: true
|
18
|
+
matrix:
|
19
|
+
ruby:
|
20
|
+
- 2.6
|
21
|
+
- 2.7
|
22
|
+
- 3.0
|
23
|
+
test_cmd:
|
24
|
+
- bundle exec rspec
|
25
|
+
|
26
|
+
env:
|
27
|
+
RAILS_ENV: test
|
28
|
+
|
29
|
+
name: Ruby ${{ matrix.ruby }} - ${{ matrix.test_cmd }}
|
30
|
+
steps:
|
31
|
+
- name: Checkout code
|
32
|
+
uses: actions/checkout@v2
|
33
|
+
|
34
|
+
- name: Setup Ruby
|
35
|
+
uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: ${{ matrix.ruby }}
|
38
|
+
bundler-cache: true
|
39
|
+
|
40
|
+
- name: ${{ matrix.test_cmd }}
|
41
|
+
run: |
|
42
|
+
echo "${CMD}"
|
43
|
+
bash -c "${CMD}"
|
44
|
+
env:
|
45
|
+
CMD: ${{ matrix.test_cmd }}
|
data/lib/rex/core/version.rb
CHANGED
@@ -4,202 +4,192 @@ require 'socket'
|
|
4
4
|
require 'fcntl'
|
5
5
|
|
6
6
|
module Rex
|
7
|
-
module IO
|
8
|
-
|
9
|
-
###
|
10
|
-
#
|
11
|
-
# This class provides an abstraction to a stream based
|
12
|
-
# connection through the use of a streaming socketpair.
|
13
|
-
#
|
14
|
-
###
|
15
|
-
module SocketAbstraction
|
16
|
-
|
17
|
-
###
|
18
|
-
#
|
19
|
-
# Extension information for required Stream interface.
|
20
|
-
#
|
21
|
-
###
|
22
|
-
module Ext
|
23
|
-
|
24
|
-
#
|
25
|
-
# Initializes peer information.
|
7
|
+
module IO
|
8
|
+
###
|
26
9
|
#
|
27
|
-
|
28
|
-
|
29
|
-
@local = local
|
30
|
-
end
|
31
|
-
|
10
|
+
# This class provides an abstraction to a stream based
|
11
|
+
# connection through the use of a streaming socketpair.
|
32
12
|
#
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
13
|
+
###
|
14
|
+
module SocketAbstraction
|
15
|
+
###
|
16
|
+
#
|
17
|
+
# Extension information for required Stream interface.
|
18
|
+
#
|
19
|
+
###
|
20
|
+
module Ext
|
21
|
+
#
|
22
|
+
# Initializes peer information.
|
23
|
+
#
|
24
|
+
def initinfo(peer, local)
|
25
|
+
@peer = peer
|
26
|
+
@local = local
|
27
|
+
end
|
38
28
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
#
|
48
|
-
# Override this method to init the abstraction
|
49
|
-
#
|
50
|
-
def initialize_abstraction
|
51
|
-
self.lsock, self.rsock = Rex::Compat.pipe
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# This method cleans up the abstraction layer.
|
56
|
-
#
|
57
|
-
def cleanup_abstraction
|
58
|
-
self.lsock.close if (self.lsock and !self.lsock.closed?)
|
59
|
-
self.rsock.close if (self.rsock and !self.rsock.closed?)
|
60
|
-
|
61
|
-
self.lsock = nil
|
62
|
-
self.rsock = nil
|
63
|
-
end
|
64
|
-
|
65
|
-
#
|
66
|
-
# Low-level write to the local side.
|
67
|
-
#
|
68
|
-
def syswrite(buffer)
|
69
|
-
lsock.syswrite(buffer)
|
70
|
-
end
|
71
|
-
|
72
|
-
#
|
73
|
-
# Low-level read from the local side.
|
74
|
-
#
|
75
|
-
def sysread(length)
|
76
|
-
lsock.sysread(length)
|
77
|
-
end
|
78
|
-
|
79
|
-
#
|
80
|
-
# Shuts down the local side of the stream abstraction.
|
81
|
-
#
|
82
|
-
def shutdown(how)
|
83
|
-
lsock.shutdown(how)
|
84
|
-
end
|
85
|
-
|
86
|
-
#
|
87
|
-
# Closes both sides of the stream abstraction.
|
88
|
-
#
|
89
|
-
def close
|
90
|
-
cleanup_abstraction
|
91
|
-
super
|
92
|
-
end
|
93
|
-
|
94
|
-
#
|
95
|
-
# Symbolic peer information.
|
96
|
-
#
|
97
|
-
def peerinfo
|
98
|
-
"Remote-side of Pipe"
|
99
|
-
end
|
100
|
-
|
101
|
-
#
|
102
|
-
# Symbolic local information.
|
103
|
-
#
|
104
|
-
def localinfo
|
105
|
-
"Local-side of Pipe"
|
106
|
-
end
|
107
|
-
|
108
|
-
#
|
109
|
-
# The left side of the stream.
|
110
|
-
#
|
111
|
-
attr_reader :lsock
|
112
|
-
#
|
113
|
-
# The right side of the stream.
|
114
|
-
#
|
115
|
-
attr_reader :rsock
|
116
|
-
|
117
|
-
protected
|
118
|
-
|
119
|
-
def monitor_rsock(threadname = "SocketMonitorRemote")
|
120
|
-
self.monitor_thread = Rex::ThreadFactory.spawn(threadname, false) {
|
121
|
-
loop do
|
122
|
-
closed = false
|
123
|
-
buf = nil
|
124
|
-
|
125
|
-
if not self.rsock
|
126
|
-
wlog("monitor_rsock: the remote socket is nil, exiting loop")
|
127
|
-
break
|
29
|
+
#
|
30
|
+
# Symbolic peer information.
|
31
|
+
#
|
32
|
+
def peerinfo
|
33
|
+
(@peer || 'Remote Pipe')
|
128
34
|
end
|
129
35
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
rescue Exception => e
|
136
|
-
wlog("monitor_rsock: exception during select: #{e.class} #{e}")
|
137
|
-
closed = true
|
36
|
+
#
|
37
|
+
# Symbolic local information.
|
38
|
+
#
|
39
|
+
def localinfo
|
40
|
+
(@local || 'Local Pipe')
|
138
41
|
end
|
42
|
+
end
|
139
43
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
44
|
+
#
|
45
|
+
# Override this method to init the abstraction
|
46
|
+
#
|
47
|
+
def initialize_abstraction
|
48
|
+
self.lsock, self.rsock = Rex::Compat.pipe
|
49
|
+
end
|
50
|
+
|
51
|
+
#
|
52
|
+
# This method cleans up the abstraction layer.
|
53
|
+
#
|
54
|
+
def cleanup_abstraction
|
55
|
+
lsock.close if lsock and !lsock.closed?
|
56
|
+
rsock.close if rsock and !rsock.closed?
|
57
|
+
|
58
|
+
self.lsock = nil
|
59
|
+
self.rsock = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Low-level write to the local side.
|
64
|
+
#
|
65
|
+
def syswrite(buffer)
|
66
|
+
lsock.syswrite(buffer)
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Low-level read from the local side.
|
71
|
+
#
|
72
|
+
def sysread(length)
|
73
|
+
lsock.sysread(length)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Shuts down the local side of the stream abstraction.
|
78
|
+
#
|
79
|
+
def shutdown(how)
|
80
|
+
lsock.shutdown(how)
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Closes both sides of the stream abstraction.
|
85
|
+
#
|
86
|
+
def close
|
87
|
+
cleanup_abstraction
|
88
|
+
super
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# Symbolic peer information.
|
93
|
+
#
|
94
|
+
def peerinfo
|
95
|
+
'Remote-side of Pipe'
|
96
|
+
end
|
97
|
+
|
98
|
+
#
|
99
|
+
# Symbolic local information.
|
100
|
+
#
|
101
|
+
def localinfo
|
102
|
+
'Local-side of Pipe'
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# The left side of the stream.
|
107
|
+
#
|
108
|
+
attr_reader :lsock
|
109
|
+
#
|
110
|
+
# The right side of the stream.
|
111
|
+
#
|
112
|
+
attr_reader :rsock
|
113
|
+
|
114
|
+
protected
|
115
|
+
|
116
|
+
def monitor_rsock(threadname = 'SocketMonitorRemote')
|
117
|
+
self.monitor_thread = Rex::ThreadFactory.spawn(threadname, false) do
|
118
|
+
loop do
|
119
|
+
closed = false
|
120
|
+
buf = nil
|
121
|
+
|
122
|
+
unless rsock
|
123
|
+
wlog('monitor_rsock: the remote socket is nil, exiting loop')
|
124
|
+
break
|
146
125
|
end
|
147
|
-
rescue EOFError => e
|
148
|
-
closed = true
|
149
|
-
dlog("monitor_rsock: EOF in rsock")
|
150
|
-
rescue ::Exception => e
|
151
|
-
closed = true
|
152
|
-
wlog("monitor_rsock: exception during read: #{e.class} #{e}")
|
153
|
-
end
|
154
|
-
end
|
155
126
|
|
156
|
-
if( closed == false )
|
157
|
-
total_sent = 0
|
158
|
-
total_length = buf.length
|
159
|
-
while( total_sent < total_length )
|
160
127
|
begin
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
128
|
+
s = Rex::ThreadSafe.select([rsock], nil, nil, 0.2)
|
129
|
+
next if s.nil? || s[0].nil?
|
130
|
+
rescue Exception => e
|
131
|
+
wlog("monitor_rsock: exception during select: #{e.class} #{e}")
|
132
|
+
closed = true
|
133
|
+
end
|
166
134
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
135
|
+
unless closed
|
136
|
+
begin
|
137
|
+
buf = rsock.sysread(32_768)
|
138
|
+
if buf.nil?
|
139
|
+
closed = true
|
140
|
+
wlog('monitor_rsock: closed remote socket due to nil read')
|
141
|
+
end
|
142
|
+
rescue EOFError => e
|
172
143
|
closed = true
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
144
|
+
dlog('monitor_rsock: EOF in rsock')
|
145
|
+
rescue ::Exception => e
|
146
|
+
closed = true
|
147
|
+
wlog("monitor_rsock: exception during read: #{e.class} #{e}")
|
177
148
|
end
|
178
|
-
rescue ::IOError, ::EOFError => e
|
179
|
-
closed = true
|
180
|
-
wlog("monitor_rsock: exception during write: #{e.class} #{e}")
|
181
|
-
break
|
182
149
|
end
|
183
|
-
end
|
184
|
-
end
|
185
150
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
151
|
+
unless closed
|
152
|
+
total_sent = 0
|
153
|
+
total_length = buf.length
|
154
|
+
while total_sent < total_length
|
155
|
+
begin
|
156
|
+
data = buf[total_sent, buf.length]
|
157
|
+
|
158
|
+
# Note that this must be write() NOT syswrite() or put() or anything like it.
|
159
|
+
# Using syswrite() breaks SSL streams.
|
160
|
+
sent = write(data)
|
161
|
+
|
162
|
+
# sf: Only remove the data off the queue is write was successfull.
|
163
|
+
# This way we naturally perform a resend if a failure occured.
|
164
|
+
# Catches an edge case with meterpreter TCP channels where remote send
|
165
|
+
# failes gracefully and a resend is required.
|
166
|
+
if sent.nil?
|
167
|
+
closed = true
|
168
|
+
wlog('monitor_rsock: failed writing, socket must be dead')
|
169
|
+
break
|
170
|
+
elsif sent > 0
|
171
|
+
total_sent += sent
|
172
|
+
end
|
173
|
+
rescue ::IOError, ::EOFError => e
|
174
|
+
closed = true
|
175
|
+
wlog("monitor_rsock: exception during write: #{e.class} #{e}")
|
176
|
+
break
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
next unless closed
|
182
|
+
|
183
|
+
begin
|
184
|
+
close_write if respond_to?('close_write')
|
185
|
+
rescue IOError
|
186
|
+
end
|
187
|
+
break
|
190
188
|
end
|
191
|
-
break
|
192
189
|
end
|
193
190
|
end
|
194
|
-
}
|
195
|
-
end
|
196
|
-
|
197
|
-
protected
|
198
|
-
attr_accessor :monitor_thread
|
199
|
-
attr_writer :lsock
|
200
|
-
attr_writer :rsock
|
201
|
-
|
202
|
-
end
|
203
|
-
|
204
|
-
end; end
|
205
191
|
|
192
|
+
attr_accessor :monitor_thread
|
193
|
+
attr_writer :lsock, :rsock
|
194
|
+
end
|
195
|
+
end; end
|
data/lib/rex/stopwatch.rb
CHANGED
@@ -1,16 +1,21 @@
|
|
1
|
-
module Rex
|
1
|
+
module Rex::Stopwatch
|
2
2
|
|
3
3
|
# This provides a correct way to time an operation provided within a block.
|
4
4
|
#
|
5
5
|
# @see https://blog.dnsimple.com/2018/03/elapsed-time-with-ruby-the-right-way/
|
6
|
+
# @see https://ruby-doc.org/core-2.7.1/Process.html#method-c-clock_gettime
|
7
|
+
#
|
8
|
+
# @param [Symbol] unit The unit of time in which to measure the duration. The
|
9
|
+
# argument is passed to Process.clock_gettime which defines the acceptable
|
10
|
+
# values.
|
6
11
|
#
|
7
12
|
# @yield [] The block whose operation should be timed.
|
8
13
|
#
|
9
|
-
# @return Returns the result of the block and the elapsed time in
|
10
|
-
def self.
|
11
|
-
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
14
|
+
# @return Returns the result of the block and the elapsed time in the specified unit.
|
15
|
+
def self.elapsed_time(unit: :float_second)
|
16
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
|
12
17
|
ret = yield
|
13
|
-
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
|
18
|
+
elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - start
|
14
19
|
|
15
20
|
[ret, elapsed]
|
16
21
|
end
|
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.
|
4
|
+
version: 0.1.23
|
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:
|
96
|
+
date: 2022-01-26 00:00:00.000000000 Z
|
97
97
|
dependencies:
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: rake
|
@@ -132,6 +132,7 @@ executables: []
|
|
132
132
|
extensions: []
|
133
133
|
extra_rdoc_files: []
|
134
134
|
files:
|
135
|
+
- ".github/workflows/verify.yml"
|
135
136
|
- ".gitignore"
|
136
137
|
- ".rspec"
|
137
138
|
- ".travis.yml"
|
metadata.gz.sig
CHANGED
Binary file
|