Skip to content

Commit 022c52d

Browse files
committed
Added bundling to handle many sessions at once.
1 parent c098313 commit 022c52d

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

data/php/hop.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
//like /path/hop.php?/uRIcksm_lOnGidENTifIEr
1111

1212
//Looks for a file with a name or contents prefix, if found, send it and deletes it
13-
function findSendDelete($tempdir, $prefix){
13+
function findSendDelete($tempdir, $prefix, $one=true){
1414
if($dh = opendir($tempdir)){
1515
while(($file = readdir($dh)) !== false){
1616
if(strpos($file, $prefix) !== 0){
1717
continue;
1818
}
1919
readfile($tempdir."/".$file);
2020
unlink($tempdir."/".$file);
21-
break;
21+
if($one){
22+
break;
23+
}
2224
}
2325
}
2426
}
@@ -37,7 +39,7 @@ function findSendDelete($tempdir, $prefix){
3739
fwrite($f, $postdata);
3840
fclose($f);
3941
}else{
40-
findSendDelete($tempdir, "up_");
42+
findSendDelete($tempdir, "up_", false);
4143
}
4244
}else if($_SERVER['REQUEST_METHOD'] === 'POST'){
4345
//get data
@@ -56,6 +58,8 @@ function findSendDelete($tempdir, $prefix){
5658
$urlen = strlen($url);
5759
fwrite($f, pack('V', $urlen));
5860
fwrite($f, $url);
61+
$postdatalen = strlen($postdata);
62+
fwrite($f, pack('V', $postdatalen));
5963
fwrite($f, $postdata);
6064
fclose($f);
6165
//Initial query will be a GET and have a 12345 in it

lib/msf/core/handler/reverse_hop_http.rb

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -104,42 +104,44 @@ def start_handler
104104
next
105105
end
106106

107-
# validate response
107+
# validate responses, handle each message down
108108
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
143145
end
144146
end
145147
hop_http.monitor_thread = nil #make sure we're out

0 commit comments

Comments
 (0)