From 98e6bae07719445a094fbdf6068e2b4520e82858 Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Wed, 22 Nov 2023 11:51:10 -0500 Subject: [PATCH 1/2] Fix an uninitialized constant error This error was introduced by the loader changes in acf23e9c616a6782aaa4b7a172070460cc170754 --- modules/auxiliary/server/capture/http.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/auxiliary/server/capture/http.rb b/modules/auxiliary/server/capture/http.rb index e47b6442ca83..cd86a3be915c 100644 --- a/modules/auxiliary/server/capture/http.rb +++ b/modules/auxiliary/server/capture/http.rb @@ -3,6 +3,8 @@ # Current source: https://github.com/rapid7/metasploit-framework ## +require 'rex/proto/http/server' + class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::TcpServer include Msf::Auxiliary::Report From e9d6bab975fe00f6adf477bee36715c70eee3430 Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Wed, 22 Nov 2023 13:34:18 -0500 Subject: [PATCH 2/2] Move the ServerClient code into a dedicated file --- lib/rex/proto/http/server.rb | 53 -------------------- lib/rex/proto/http/server_client.rb | 64 ++++++++++++++++++++++++ modules/auxiliary/server/capture/http.rb | 2 - 3 files changed, 64 insertions(+), 55 deletions(-) create mode 100644 lib/rex/proto/http/server_client.rb diff --git a/lib/rex/proto/http/server.rb b/lib/rex/proto/http/server.rb index b6e9586586d0..f340c811bd0b 100644 --- a/lib/rex/proto/http/server.rb +++ b/lib/rex/proto/http/server.rb @@ -6,59 +6,6 @@ module Rex module Proto module Http -### -# -# Runtime extension of the HTTP clients that connect to the server. -# -### -module ServerClient - - # - # Initialize a new request instance. - # - def init_cli(server) - self.request = Request.new - self.server = server - self.keepalive = false - end - - # - # Resets the parsing state. - # - def reset_cli - self.request.reset - end - - # - # Transmits a response and adds the appropriate headers. - # - def send_response(response) - # Set the connection to close or keep-alive depending on what the client - # can support. - response['Connection'] = (keepalive) ? 'Keep-Alive' : 'close' - - # Add any other standard response headers. - server.add_response_headers(response) - - # Send it off. - put(response.to_s) - end - - # - # The current request context. - # - attr_accessor :request - # - # Boolean that indicates whether or not the connection supports keep-alive. - # - attr_accessor :keepalive - # - # A reference to the server the client is associated with. - # - attr_accessor :server - -end - ### # # Acts as an HTTP server, processing requests and dispatching them to diff --git a/lib/rex/proto/http/server_client.rb b/lib/rex/proto/http/server_client.rb new file mode 100644 index 000000000000..69572a71fc34 --- /dev/null +++ b/lib/rex/proto/http/server_client.rb @@ -0,0 +1,64 @@ +# -*- coding: binary -*- +require 'rex/socket' + + +module Rex +module Proto +module Http + +### +# +# Runtime extension of the HTTP clients that connect to the server. +# +### +module ServerClient + + # + # Initialize a new request instance. + # + def init_cli(server) + self.request = Request.new + self.server = server + self.keepalive = false + end + + # + # Resets the parsing state. + # + def reset_cli + self.request.reset + end + + # + # Transmits a response and adds the appropriate headers. + # + def send_response(response) + # Set the connection to close or keep-alive depending on what the client + # can support. + response['Connection'] = (keepalive) ? 'Keep-Alive' : 'close' + + # Add any other standard response headers. + server.add_response_headers(response) + + # Send it off. + put(response.to_s) + end + + # + # The current request context. + # + attr_accessor :request + # + # Boolean that indicates whether or not the connection supports keep-alive. + # + attr_accessor :keepalive + # + # A reference to the server the client is associated with. + # + attr_accessor :server + +end + +end +end +end diff --git a/modules/auxiliary/server/capture/http.rb b/modules/auxiliary/server/capture/http.rb index cd86a3be915c..e47b6442ca83 100644 --- a/modules/auxiliary/server/capture/http.rb +++ b/modules/auxiliary/server/capture/http.rb @@ -3,8 +3,6 @@ # Current source: https://github.com/rapid7/metasploit-framework ## -require 'rex/proto/http/server' - class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::TcpServer include Msf::Auxiliary::Report