rex-core 0.1.23 → 0.1.24

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: a0378775512fe632afba68913d5d3eed8fc39ff2eeaf5a849b4101dbbab49026
4
- data.tar.gz: 8d2cde8487dcb4c9d2c7102eddd0f5777f9ba6bd67ea58649a8fe8ff03203a4c
3
+ metadata.gz: 879343c39c0c1769143a3d0b5c61ce102e26ac898a50e5eec9581bc2bee47c91
4
+ data.tar.gz: fca03a370a59dc3d03369fb29f47a0fb5e42dcb66db9d6e7b4f3b0824e9620f7
5
5
  SHA512:
6
- metadata.gz: 7f88261f6d1982c3b2903224776481a21c16b3336e0c448a934f0daf3b073ae7ebe76f7a6f2e6b5c7aacbd3639a184c559b99c2e8f14091c15a68a3790ba0399
7
- data.tar.gz: 42de568303940c9a7a28ccaa19954d21e05e85b204cb0f4febd761dc150d682fbf6f3a76da5bca9804b082dbc2989e3bcb2013aa65294db6271ee7add0e157cd
6
+ metadata.gz: fda24ae80de4cfda9e66f3bfe45b93bee23e4b35b57bb55f1fca0784721fa333154c8d6972a01594794a3b479e3a07c7809c0911a573b79315dfa8d01148faea
7
+ data.tar.gz: a6c8d8c2783a611b50f240e664ab2011da5e6ec5d46b3d7353e12cae0e56140f0ec33973fa7d25c0e10226a12b53815bc76fa3de6363678eb6b8e72cc2e7a569
checksums.yaml.gz.sig CHANGED
@@ -1,3 +1 @@
1
- oUc)��w>�AǸ��EaĚ%�&�M9�����g�Afw�Q$�y�\
2
- �yI!����)
3
- �M^������`�t�R��?�)���b��5�D�Y�������������{���a��{j���P4�������ݘL�����#��P
1
+ hC�|����%���of�m�����y�A�����1��H �>\g�u�ٿ %q�V}x+���U�!��ȃ�0(g�%>,6[�.œC���`s<e��i$�ss��ʣ������
@@ -1,5 +1,5 @@
1
1
  module Rex
2
2
  module Core
3
- VERSION = "0.1.23"
3
+ VERSION = "0.1.24"
4
4
  end
5
5
  end
@@ -1,228 +1,208 @@
1
1
  # -*- coding: binary -*-
2
- require 'thread'
3
2
 
4
3
  module Rex
5
- module IO
6
-
7
- ###
8
- #
9
- # This mixin provides the framework and interface for implementing a streaming
10
- # server that can listen for and accept stream client connections. Stream
11
- # servers extend this class and are required to implement the following
12
- # methods:
13
- #
14
- # accept
15
- # fd
16
- #
17
- ###
18
- module StreamServer
19
-
20
- ##
21
- #
22
- # Abstract methods
23
- #
24
- ##
25
-
26
- ##
27
- #
28
- # Default server monitoring and client management implementation follows
29
- # below.
30
- #
31
- ##
32
-
33
- #
34
- # This callback is notified when a client connects.
35
- #
36
- def on_client_connect(client)
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
- # This method closes a client connection and cleans up the resources
91
- # associated with it.
92
- #
93
- def close_client(client)
94
- if (client)
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
- # Detach a client. You are now responsible for it, not us
106
- #
107
- def detach_client(client)
108
- self.clients.delete(client)
109
- end
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
- # This method waits on the server listener thread
113
- #
114
- def wait
115
- self.listener_thread.join if self.listener_thread
116
- end
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
- # Append to the list of clients
162
- self.clients << cli
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
- # Initialize the connection processing
165
- on_client_connect(cli)
75
+ clients.each do |cli|
76
+ close_client(cli)
77
+ end
78
+ end
166
79
 
167
- # Notify the client monitor
168
- self.client_waiter.push(cli)
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
- # Skip exceptions caused by accept() [ SSL ]
171
- rescue ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED
172
- rescue ::Interrupt
173
- raise $!
174
- rescue ::Exception
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
- # This method monitors client connections for data and calls the
184
- # +on_client_data+ routine when new data arrives.
185
- #
186
- def monitor_clients
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
- sd = Rex::ThreadSafe.select(clients, nil, nil, nil)
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
- sd[0].each { |cfd|
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
- on_client_data(cfd) if clients.include? cfd
200
- rescue ::EOFError, ::Errno::ECONNRESET, ::Errno::ENOTCONN, ::Errno::ECONNABORTED
201
- on_client_close(cfd)
202
- close_client(cfd)
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
- end
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
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.23
4
+ version: 0.1.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Metasploit Hackers
metadata.gz.sig CHANGED
Binary file