@@ -104,42 +104,44 @@ def start_handler
104
104
next
105
105
end
106
106
107
- # validate response
107
+ # validate responses, handle each message down
108
108
received = res . body
109
- next if received . length < 12 || received . slice! ( 0 , MAGIC . length ) != MAGIC
110
-
111
- # good response
112
- delay = 0 # we're talking, speed up
113
- urlen = received . slice! ( 0 , 4 ) . unpack ( 'V' ) [ 0 ]
114
- urlpath = received . slice! ( 0 , urlen )
115
-
116
- # do not want handlers to change while we dispatch this
117
- hop_http . lock . lock
118
- #received is now the binary contents of the message
119
- if hop_http . handlers . include? urlpath
120
- pack = Rex ::Proto ::Http ::Packet . new
121
- pack . body = received
122
- hop_http . current_url = urlpath
123
- hop_http . handlers [ urlpath ] . call ( hop_http , pack )
124
- hop_http . lock . unlock
125
- elsif !closed_handlers . include? urlpath
126
- hop_http . lock . unlock
127
- #New session!
128
- conn_id = urlpath . gsub ( "/" , "" )
129
- # Short-circuit the payload's handle_connection processing for create_session
130
- # We are the dispatcher since we need to handle the comms to the hop
131
- create_session ( hop_http , {
132
- :passive_dispatcher => self ,
133
- :conn_id => conn_id ,
134
- :url => uri . to_s + conn_id + "/\x00 " ,
135
- :expiration => datastore [ 'SessionExpirationTimeout' ] . to_i ,
136
- :comm_timeout => datastore [ 'SessionCommunicationTimeout' ] . to_i ,
137
- :ssl => false ,
138
- } )
139
- # send new stage to hop so next inbound session will get a unique ID.
140
- hop_http . send_new_stage
141
- else
142
- hop_http . lock . unlock
109
+ until received . length < 12 || received . slice! ( 0 , MAGIC . length ) != MAGIC
110
+
111
+ # good response
112
+ delay = 0 # we're talking, speed up
113
+ urlen = received . slice! ( 0 , 4 ) . unpack ( 'V' ) [ 0 ]
114
+ urlpath = received . slice! ( 0 , urlen )
115
+ datalen = received . slice! ( 0 , 4 ) . unpack ( 'V' ) [ 0 ]
116
+
117
+ # do not want handlers to change while we dispatch this
118
+ hop_http . lock . lock
119
+ #received now starts with the binary contents of the message
120
+ if hop_http . handlers . include? urlpath
121
+ pack = Rex ::Proto ::Http ::Packet . new
122
+ pack . body = received . slice! ( 0 , datalen )
123
+ hop_http . current_url = urlpath
124
+ hop_http . handlers [ urlpath ] . call ( hop_http , pack )
125
+ hop_http . lock . unlock
126
+ elsif !closed_handlers . include? urlpath
127
+ hop_http . lock . unlock
128
+ #New session!
129
+ conn_id = urlpath . gsub ( "/" , "" )
130
+ # Short-circuit the payload's handle_connection processing for create_session
131
+ # We are the dispatcher since we need to handle the comms to the hop
132
+ create_session ( hop_http , {
133
+ :passive_dispatcher => self ,
134
+ :conn_id => conn_id ,
135
+ :url => uri . to_s + conn_id + "/\x00 " ,
136
+ :expiration => datastore [ 'SessionExpirationTimeout' ] . to_i ,
137
+ :comm_timeout => datastore [ 'SessionCommunicationTimeout' ] . to_i ,
138
+ :ssl => false ,
139
+ } )
140
+ # send new stage to hop so next inbound session will get a unique ID.
141
+ hop_http . send_new_stage
142
+ else
143
+ hop_http . lock . unlock
144
+ end
143
145
end
144
146
end
145
147
hop_http . monitor_thread = nil #make sure we're out
0 commit comments