rex-core 0.1.20 → 0.1.24
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- 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/io/stream_server.rb +182 -202
- data.tar.gz.sig +1 -1
- 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: 879343c39c0c1769143a3d0b5c61ce102e26ac898a50e5eec9581bc2bee47c91
|
4
|
+
data.tar.gz: fca03a370a59dc3d03369fb29f47a0fb5e42dcb66db9d6e7b4f3b0824e9620f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda24ae80de4cfda9e66f3bfe45b93bee23e4b35b57bb55f1fca0784721fa333154c8d6972a01594794a3b479e3a07c7809c0911a573b79315dfa8d01148faea
|
7
|
+
data.tar.gz: a6c8d8c2783a611b50f240e664ab2011da5e6ec5d46b3d7353e12cae0e56140f0ec33973fa7d25c0e10226a12b53815bc76fa3de6363678eb6b8e72cc2e7a569
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -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/io/stream_server.rb
CHANGED
@@ -1,228 +1,208 @@
|
|
1
1
|
# -*- coding: binary -*-
|
2
|
-
require 'thread'
|
3
2
|
|
4
3
|
module Rex
|
5
|
-
module IO
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if (on_client_connect_proc)
|
38
|
-
on_client_connect_proc.call(client)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# This callback is notified when a client connection has data that needs to
|
44
|
-
# be processed.
|
45
|
-
#
|
46
|
-
def on_client_data(client)
|
47
|
-
if (on_client_data_proc)
|
48
|
-
on_client_data_proc.call(client)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# This callback is notified when a client connection has closed.
|
54
|
-
#
|
55
|
-
def on_client_close(client)
|
56
|
-
if (on_client_close_proc)
|
57
|
-
on_client_close_proc.call(client)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Start monitoring the listener socket for connections and keep track of
|
63
|
-
# all client connections.
|
64
|
-
#
|
65
|
-
def start
|
66
|
-
self.clients = []
|
67
|
-
self.client_waiter = ::Queue.new
|
68
|
-
|
69
|
-
self.listener_thread = Rex::ThreadFactory.spawn("StreamServerListener", false) {
|
70
|
-
monitor_listener
|
71
|
-
}
|
72
|
-
self.clients_thread = Rex::ThreadFactory.spawn("StreamServerClientMonitor", false) {
|
73
|
-
monitor_clients
|
74
|
-
}
|
75
|
-
end
|
76
|
-
|
77
|
-
#
|
78
|
-
# Terminates the listener monitoring threads and closes all active clients.
|
79
|
-
#
|
80
|
-
def stop
|
81
|
-
self.listener_thread.kill
|
82
|
-
self.clients_thread.kill
|
83
|
-
|
84
|
-
self.clients.each { |cli|
|
85
|
-
close_client(cli)
|
86
|
-
}
|
87
|
-
end
|
4
|
+
module IO
|
5
|
+
###
|
6
|
+
#
|
7
|
+
# This mixin provides the framework and interface for implementing a streaming
|
8
|
+
# server that can listen for and accept stream client connections. Stream
|
9
|
+
# servers extend this class and are required to implement the following
|
10
|
+
# methods:
|
11
|
+
#
|
12
|
+
# accept
|
13
|
+
# fd
|
14
|
+
#
|
15
|
+
###
|
16
|
+
module StreamServer
|
17
|
+
##
|
18
|
+
#
|
19
|
+
# Abstract methods
|
20
|
+
#
|
21
|
+
##
|
22
|
+
|
23
|
+
##
|
24
|
+
#
|
25
|
+
# Default server monitoring and client management implementation follows
|
26
|
+
# below.
|
27
|
+
#
|
28
|
+
##
|
29
|
+
|
30
|
+
#
|
31
|
+
# This callback is notified when a client connects.
|
32
|
+
#
|
33
|
+
def on_client_connect(client)
|
34
|
+
on_client_connect_proc.call(client) if on_client_connect_proc
|
35
|
+
end
|
88
36
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
detach_client(client)
|
96
|
-
|
97
|
-
begin
|
98
|
-
client.close
|
99
|
-
rescue IOError
|
37
|
+
#
|
38
|
+
# This callback is notified when a client connection has data that needs to
|
39
|
+
# be processed.
|
40
|
+
#
|
41
|
+
def on_client_data(client)
|
42
|
+
on_client_data_proc.call(client) if on_client_data_proc
|
100
43
|
end
|
101
|
-
end
|
102
|
-
end
|
103
44
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
45
|
+
#
|
46
|
+
# This callback is notified when a client connection has closed.
|
47
|
+
#
|
48
|
+
def on_client_close(client)
|
49
|
+
on_client_close_proc.call(client) if on_client_close_proc
|
50
|
+
end
|
110
51
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
52
|
+
#
|
53
|
+
# Start monitoring the listener socket for connections and keep track of
|
54
|
+
# all client connections.
|
55
|
+
#
|
56
|
+
def start
|
57
|
+
self.clients = []
|
58
|
+
self.client_waiter = ::Queue.new
|
117
59
|
|
118
|
-
|
119
|
-
|
120
|
-
# Callback procedures.
|
121
|
-
#
|
122
|
-
##
|
123
|
-
|
124
|
-
#
|
125
|
-
# This callback procedure can be set and will be called when new clients
|
126
|
-
# connect.
|
127
|
-
#
|
128
|
-
attr_accessor :on_client_connect_proc
|
129
|
-
#
|
130
|
-
# This callback procedure can be set and will be called when clients
|
131
|
-
# have data to be processed.
|
132
|
-
#
|
133
|
-
attr_accessor :on_client_data_proc
|
134
|
-
#
|
135
|
-
# This callback procedure can be set and will be called when a client
|
136
|
-
# disconnects from the server.
|
137
|
-
#
|
138
|
-
attr_accessor :on_client_close_proc
|
139
|
-
|
140
|
-
attr_accessor :clients # :nodoc:
|
141
|
-
attr_accessor :listener_thread, :clients_thread # :nodoc:
|
142
|
-
attr_accessor :client_waiter
|
143
|
-
|
144
|
-
protected
|
145
|
-
|
146
|
-
#
|
147
|
-
# This method monitors the listener socket for new connections and calls
|
148
|
-
# the +on_client_connect+ callback routine.
|
149
|
-
#
|
150
|
-
def monitor_listener
|
151
|
-
|
152
|
-
while true
|
153
|
-
begin
|
154
|
-
cli = accept
|
155
|
-
if not cli
|
156
|
-
elog("The accept() returned nil in stream server listener monitor: #{fd.inspect}")
|
157
|
-
::IO.select(nil, nil, nil, 0.10)
|
158
|
-
next
|
60
|
+
self.listener_thread = Rex::ThreadFactory.spawn('StreamServerListener', false) do
|
61
|
+
monitor_listener
|
159
62
|
end
|
63
|
+
self.clients_thread = Rex::ThreadFactory.spawn('StreamServerClientMonitor', false) do
|
64
|
+
monitor_clients
|
65
|
+
end
|
66
|
+
end
|
160
67
|
|
161
|
-
|
162
|
-
|
68
|
+
#
|
69
|
+
# Terminates the listener monitoring threads and closes all active clients.
|
70
|
+
#
|
71
|
+
def stop
|
72
|
+
listener_thread.kill
|
73
|
+
clients_thread.kill
|
163
74
|
|
164
|
-
|
165
|
-
|
75
|
+
clients.each do |cli|
|
76
|
+
close_client(cli)
|
77
|
+
end
|
78
|
+
end
|
166
79
|
|
167
|
-
|
168
|
-
|
80
|
+
#
|
81
|
+
# This method closes a client connection and cleans up the resources
|
82
|
+
# associated with it.
|
83
|
+
#
|
84
|
+
def close_client(client)
|
85
|
+
if client
|
86
|
+
detach_client(client)
|
87
|
+
|
88
|
+
begin
|
89
|
+
client.close
|
90
|
+
rescue IOError
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
169
94
|
|
170
|
-
#
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
elog("Error in stream server server monitor: #{$!}")
|
176
|
-
rlog(ExceptionCallStack)
|
177
|
-
break
|
95
|
+
#
|
96
|
+
# Detach a client. You are now responsible for it, not us
|
97
|
+
#
|
98
|
+
def detach_client(client)
|
99
|
+
clients.delete(client)
|
178
100
|
end
|
179
|
-
end
|
180
|
-
end
|
181
101
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
begin
|
188
|
-
|
189
|
-
# Wait for a notify if our client list is empty
|
190
|
-
if (clients.length == 0)
|
191
|
-
self.client_waiter.pop
|
192
|
-
next
|
102
|
+
#
|
103
|
+
# This method waits on the server listener thread
|
104
|
+
#
|
105
|
+
def wait
|
106
|
+
listener_thread.join if listener_thread
|
193
107
|
end
|
194
108
|
|
195
|
-
|
109
|
+
##
|
110
|
+
#
|
111
|
+
# Callback procedures.
|
112
|
+
#
|
113
|
+
##
|
114
|
+
|
115
|
+
#
|
116
|
+
# This callback procedure can be set and will be called when new clients
|
117
|
+
# connect.
|
118
|
+
#
|
119
|
+
attr_accessor :on_client_connect_proc
|
120
|
+
#
|
121
|
+
# This callback procedure can be set and will be called when clients
|
122
|
+
# have data to be processed.
|
123
|
+
#
|
124
|
+
attr_accessor :on_client_data_proc
|
125
|
+
#
|
126
|
+
# This callback procedure can be set and will be called when a client
|
127
|
+
# disconnects from the server.
|
128
|
+
#
|
129
|
+
attr_accessor :on_client_close_proc
|
130
|
+
|
131
|
+
attr_accessor :clients, :listener_thread, :clients_thread, :client_waiter # :nodoc: # :nodoc:
|
132
|
+
|
133
|
+
protected
|
134
|
+
|
135
|
+
#
|
136
|
+
# This method monitors the listener socket for new connections and calls
|
137
|
+
# the +on_client_connect+ callback routine.
|
138
|
+
#
|
139
|
+
def monitor_listener
|
140
|
+
while true
|
141
|
+
begin
|
142
|
+
cli = accept
|
143
|
+
unless cli
|
144
|
+
elog("The accept() returned nil in stream server listener monitor: #{fd.inspect}")
|
145
|
+
::IO.select(nil, nil, nil, 0.10)
|
146
|
+
next
|
147
|
+
end
|
148
|
+
|
149
|
+
# Append to the list of clients
|
150
|
+
clients << cli
|
151
|
+
|
152
|
+
# Initialize the connection processing
|
153
|
+
on_client_connect(cli)
|
154
|
+
|
155
|
+
# Notify the client monitor
|
156
|
+
client_waiter.push(cli)
|
157
|
+
|
158
|
+
# Skip exceptions caused by accept() [ SSL ]
|
159
|
+
rescue ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED
|
160
|
+
rescue ::Interrupt
|
161
|
+
raise $!
|
162
|
+
rescue ::Exception
|
163
|
+
elog("Error in stream server server monitor: #{$!}")
|
164
|
+
rlog(ExceptionCallStack)
|
165
|
+
break
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
196
169
|
|
197
|
-
|
170
|
+
#
|
171
|
+
# This method monitors client connections for data and calls the
|
172
|
+
# +on_client_data+ routine when new data arrives.
|
173
|
+
#
|
174
|
+
def monitor_clients
|
198
175
|
begin
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
176
|
+
# Wait for a notify if our client list is empty
|
177
|
+
if clients.length == 0
|
178
|
+
client_waiter.pop
|
179
|
+
next
|
180
|
+
end
|
181
|
+
|
182
|
+
sd = Rex::ThreadSafe.select(clients, nil, nil, nil)
|
183
|
+
|
184
|
+
sd[0].each do |cfd|
|
185
|
+
on_client_data(cfd) if clients.include? cfd
|
186
|
+
rescue ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED
|
187
|
+
on_client_close(cfd)
|
188
|
+
close_client(cfd)
|
189
|
+
rescue ::Interrupt
|
190
|
+
raise $!
|
191
|
+
rescue ::Exception
|
192
|
+
close_client(cfd)
|
193
|
+
elog("Error in stream server client monitor: #{$!}")
|
194
|
+
rlog(ExceptionCallStack)
|
195
|
+
end
|
196
|
+
rescue ::Rex::StreamClosedError => e
|
197
|
+
# Remove the closed stream from the list
|
198
|
+
detach_client(e.stream)
|
203
199
|
rescue ::Interrupt
|
204
200
|
raise $!
|
205
201
|
rescue ::Exception
|
206
|
-
close_client(cfd)
|
207
202
|
elog("Error in stream server client monitor: #{$!}")
|
208
203
|
rlog(ExceptionCallStack)
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
rescue ::Rex::StreamClosedError => e
|
214
|
-
# Remove the closed stream from the list
|
215
|
-
detach_client(e.stream)
|
216
|
-
rescue ::Interrupt
|
217
|
-
raise $!
|
218
|
-
rescue ::Exception
|
219
|
-
elog("Error in stream server client monitor: #{$!}")
|
220
|
-
rlog(ExceptionCallStack)
|
221
|
-
end while true
|
204
|
+
end while true
|
205
|
+
end
|
206
|
+
end
|
222
207
|
end
|
223
|
-
|
224
208
|
end
|
225
|
-
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
cc=�:,ۥq���<NS)�-�'����X)���ݥ��ߋb깋��]w\ܷ�IQ��lG�Z�����t��_ڑ�0�EY���<.y�\Bn��
|
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.24
|
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
|