lib/metasploit/aggregator/http/responder.rb in metasploit-aggregator-0.2.3 vs lib/metasploit/aggregator/http/responder.rb in metasploit-aggregator-1.0.0

- old
+ new

@@ -1,7 +1,8 @@ require "metasploit/aggregator/session_detail_service" require "metasploit/aggregator/http/request" +require "metasploit/aggregator/logger" module Metasploit module Aggregator module Http # a Responder acts a a gateway to convert data from a port to into a Request object @@ -48,22 +49,33 @@ log 'queued to console' # now get the response once available and send back using this connection begin request_obj = recv.pop - @session_service.add_request(request_task, @uri) + @session_service.add_request(request_obj, @uri) + tlv_response = @session_service.eval_tlv_enc(request_obj) + unless tlv_response.nil? + # build a new request with a the new tlv + suppression = Metasploit::Aggregator::Http::Request.forge_request(@uri, tlv_response.to_r, connection) + send << suppression + log "Suppressing cryptTLV on session #{@uri}" + send << request_task + request_obj = recv.pop + @session_service.add_request(suppression, @uri) + end @pending_request = nil request_obj.headers.each do |line| connection.write line end unless request_obj.body.nil? connection.write request_obj.body end connection.flush + @session_service.add_request(request_obj, @uri) log 'message delivered from console' - rescue - log $! + rescue Exception + log "error processing console response for #{@uri}" end close_connection(connection) rescue Exception => e log "an error occurred processing request from #{@uri}" end @@ -80,14 +92,22 @@ end def send_parked_response(connection) address = connection.peeraddr[3] log "sending parked response to #{address}" - Metasploit::Aggregator::Http::Request.parked.headers.each do |line| - connection.puts line + send_response(Metasploit::Aggregator::Http::Request.parked, connection) + end + + def send_response(request_obj, connection) + @pending_request = nil + request_obj.headers.each do |line| + connection.write line end - close_connection(connection) + unless request_obj.body.nil? + connection.write request_obj.body + end + connection.flush end def self.get_data(connection, guaranteed_length) checked_first = has_length = guaranteed_length content_length = 0 @@ -112,10 +132,10 @@ if has_length while body.length < content_length body += connection.read(content_length - body.length) end end - Request.new request_lines, body, connection + Metasploit::Aggregator::Http::Request.new request_lines, body, connection end def get_connection(host, port) TCPSocket.new host, port end \ No newline at end of file