Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/http/http_logger_subscriber.rb
Views: 11704
# -*- coding: binary -*-12require 'rex/socket'3require 'rex/text'4require 'digest'56module Rex7module Proto8module Http910class HttpLoggerSubscriber < HttpSubscriber11def initialize(logger:)12raise RuntimeError, "Incompatible logger" unless logger.respond_to?(:print_line) && logger.respond_to?(:datastore)13@logger = logger14end1516# (see Rex::Proto::Http::HttpSubscriber#on_request)17def on_request(request)18if @logger.datastore['HttpTrace']19http_trace_colors = @logger.datastore['HttpTraceColors'].blank? ? 'red/blu' : @logger.datastore['HttpTraceColors'] # Set the default colors if none were provided.20http_trace_colors += '/' if http_trace_colors.count('/') == 0 # Append "/"" to the end of the string if no "/" were found in the string to ensure consistent formatting.21request_color, response_color = http_trace_colors.gsub('/', ' / ').split('/').map { |color| color&.strip.blank? ? '' : "%bld%#{color.strip}" }22request = request.to_s(headers_only: @logger.datastore['HttpTraceHeadersOnly'])23@logger.print_line("#"*20)24@logger.print_line("# Request:")25@logger.print_line("#"*20)26@logger.print_line("%clr#{request_color}#{request}%clr")27end28end2930# (see Rex::Proto::HttpSubscriber#on_response)31def on_response(response)32if @logger.datastore['HttpTrace']33http_trace_colors = @logger.datastore['HttpTraceColors'].blank? ? 'red/blu' : @logger.datastore['HttpTraceColors'] # Set the default colors if none were provided.34http_trace_colors += '/' if http_trace_colors.count('/') == 0 # Append "/"" to the end of the string if no "/" were found in the string to ensure consistent formatting.35request_color, response_color = http_trace_colors.gsub('/', ' / ').split('/').map { |color| color&.strip.blank? ? '' : "%bld%#{color.strip}" }36@logger.print_line("#"*20)37@logger.print_line("# Response:")38@logger.print_line("#"*20)39if response40response = response.to_terminal_output(headers_only: @logger.datastore['HttpTraceHeadersOnly'])41@logger.print_line("%clr#{response_color}#{response}%clr")42else43@logger.print_line("No response received")44end45end46end47end48end49end50end515253