diff --git a/core/main/network_stack/handlers/dynamicreconstruction.rb b/core/main/network_stack/handlers/dynamicreconstruction.rb index c8ed8bd60..3eaf82823 100644 --- a/core/main/network_stack/handlers/dynamicreconstruction.rb +++ b/core/main/network_stack/handlers/dynamicreconstruction.rb @@ -30,6 +30,21 @@ module Handlers # Combines packet information and pushes to PQ (packet queue), then checks packets def call(env) @request = Rack::Request.new(env) + + # skip packet checking if the request method is HEAD, PUT, DELETE or if parameters == null + if not self.is_valid_req(@request) + response = Rack::Response.new( + body = [], + status = 404, + header = { + 'Pragma' => 'no-cache', + 'Cache-Control' => 'no-cache', + 'Expires' => '0' + } + ) + return response + end + response = Rack::Response.new( body = [], status = 200, @@ -113,6 +128,17 @@ module Handlers end end end + + # 1. check methods HEAD, PUT, DELETE. return 404 if these methods are called + # 2. check for parameters = null (no parameters). return 404 in this case + # @param [Hash] request the Rack HTTP Request. + def is_valid_req(request) + is_valid = true + if request.put? or request.delete? or request.head? or request.params.empty? + is_valid = false + end + is_valid + end # Assist function for getting parameter from hash # @param [Hash] query Hash to pull key from diff --git a/test/unit/core/main/network_stack/handlers/dynamicreconstruction.rb b/test/unit/core/main/network_stack/handlers/dynamicreconstruction.rb index d86979e54..4b8e02650 100644 --- a/test/unit/core/main/network_stack/handlers/dynamicreconstruction.rb +++ b/test/unit/core/main/network_stack/handlers/dynamicreconstruction.rb @@ -17,20 +17,6 @@ require 'test/unit' require 'webrick' require 'rubygems' require 'curb' -# require "benchmark" - -# keep webrick quiet -class ::WEBrick::HTTPServer - def access_log(config, req, res) - # nop - end -end - -class ::WEBrick::BasicLog - def log(level, data) - # nop - end -end class TC_DynamicReconstruction < Test::Unit::TestCase @@ -48,13 +34,16 @@ class TC_DynamicReconstruction < Test::Unit::TestCase config = {} config[:BindAddress] = '127.0.0.1' config[:Port] = @port.to_s - @server = WEBrick::HTTPServer.new( config ) - @server.mount('/test', BeEF::Core::NetworkStack::Handlers::DynamicReconstruction) - trap("INT") { @server.shutdown } - trap("TERM") { @server.shutdown } + @mounts = {} + @mounts['/test'] = BeEF::Core::NetworkStack::Handlers::DynamicReconstruction.new + @rackApp = Rack::URLMap.new(@mounts) + Thin::Logging.silent = true + @server = Thin::Server.new('127.0.0.1', @port.to_s, @rackApp) + trap("INT") { @server.stop } + trap("TERM") { @server.stop } @pid = fork do - @server.start + @server.start! end end @@ -66,10 +55,10 @@ class TC_DynamicReconstruction < Test::Unit::TestCase def wait_for_server max_waits = 3 sleep_length = 0.00001 - + count = 0 while (count < max_waits) - break if @server.status == :Running + break if @server.running? count += 1 sleep sleep_length end