@@ -27,6 +27,7 @@ module ReverseHopHttp
27
27
class << self ; attr_accessor :hop_handlers end
28
28
attr_accessor :monitor_thread # :nodoc:
29
29
attr_accessor :handlers # :nodoc:
30
+ attr_accessor :closed_handlers # :nodoc:
30
31
attr_accessor :mclient # :nodoc:
31
32
attr_accessor :current_url # :nodoc:
32
33
attr_accessor :control # :nodoc:
@@ -57,6 +58,7 @@ def self.general_handler_type
57
58
#
58
59
def setup_handler
59
60
self . handlers = { }
61
+ self . closed_handlers = { }
60
62
end
61
63
62
64
#
@@ -95,7 +97,7 @@ def start_handler
95
97
delay = delay + 1 if delay < 10 # slow down if we're not getting anything
96
98
crequest = hop_http . mclient . request_raw ( { 'method' => 'GET' , 'uri' => control } )
97
99
res = hop_http . mclient . send_recv ( crequest ) # send poll to the hop
98
- next if res == nil
100
+ next if res . nil?
99
101
if res . error
100
102
print_error ( res . error )
101
103
next
@@ -116,7 +118,7 @@ def start_handler
116
118
pack . body = received
117
119
hop_http . current_url = urlpath
118
120
hop_http . handlers [ urlpath ] . call ( hop_http , pack )
119
- else
121
+ elsif ! closed_handlers . include? urlpath
120
122
#New session!
121
123
conn_id = urlpath . gsub ( "/" , "" )
122
124
# Short-circuit the payload's handle_connection processing for create_session
@@ -154,14 +156,15 @@ def stop_handler
154
156
#
155
157
def add_resource ( res , opts = { } )
156
158
self . handlers [ res ] = opts [ 'Proc' ]
157
- start_handler if self . monitor_thread == nil
159
+ start_handler if monitor_thread . nil?
158
160
end
159
161
160
162
#
161
163
# Removes a resource.
162
164
#
163
165
def remove_resource ( res )
164
- self . handlers . delete ( res )
166
+ handlers . delete ( res )
167
+ closed_handlers [ res ] = true
165
168
end
166
169
167
170
#
@@ -175,14 +178,14 @@ def close_client(cli)
175
178
#
176
179
def send_response ( resp )
177
180
if not resp . body . empty?
178
- crequest = self . mclient . request_raw (
181
+ crequest = mclient . request_raw (
179
182
'method' => 'POST' ,
180
- 'uri' => self . control ,
183
+ 'uri' => control ,
181
184
'data' => resp . body ,
182
- 'headers' => { 'X-urlfrag' => self . current_url }
185
+ 'headers' => { 'X-urlfrag' => current_url }
183
186
)
184
187
# if receiving POST data, hop does not send back data, so we can stop here
185
- self . mclient . send_recv ( crequest )
188
+ mclient . send_recv ( crequest )
186
189
end
187
190
end
188
191
@@ -207,7 +210,8 @@ def localinfo
207
210
# Returns the URL of the remote hop end
208
211
#
209
212
def peerinfo
210
- URI ( full_uri ) . host
213
+ uri = URI ( full_uri )
214
+ "#{ uri . host } :#{ uri . port } "
211
215
end
212
216
213
217
#
@@ -231,7 +235,7 @@ def send_new_stage(control)
231
235
url = full_uri + conn_id + "/\x00 "
232
236
233
237
print_status ( "Preparing stage for next session #{ conn_id } " )
234
- blob = self . stage_payload
238
+ blob = stage_payload
235
239
236
240
# Replace the user agent string with our option
237
241
i = blob . index ( "METERPRETER_UA\x00 " )
@@ -270,15 +274,15 @@ def send_new_stage(control)
270
274
blob = encode_stage ( blob )
271
275
272
276
#send up
273
- crequest = self . mclient . request_raw (
277
+ crequest = mclient . request_raw (
274
278
'method' => 'POST' ,
275
279
'uri' => control ,
276
280
'data' => blob ,
277
281
'headers' => { 'X-init' => 'true' }
278
282
)
279
- res = self . mclient . send_recv ( crequest )
283
+ res = mclient . send_recv ( crequest )
280
284
print_status ( "Uploaded stage to hop #{ full_uri } " )
281
- print_error ( res . error ) if res != nil && res . error
285
+ print_error ( res . error ) if ! res . nil? && res . error
282
286
283
287
#return conn info
284
288
[ conn_id , url ]
0 commit comments