diff --git a/core/main/network_stack/assethandler.rb b/core/main/network_stack/assethandler.rb index 07137072a..84832106c 100644 --- a/core/main/network_stack/assethandler.rb +++ b/core/main/network_stack/assethandler.rb @@ -65,10 +65,20 @@ module Handlers # @todo This function should accept a hooked browser session to limit the mounted file to a certain session def bind(file, path=nil, extension=nil, count=-1) url = build_url(path, extension) - @allocations[url] = {'file' => "#{root_dir}"+file, 'path' => path, 'extension' => extension, 'count' => count} - @http_server.mount(url, Rack::File.new(@allocations[url]['file'])) + @allocations[url] = {'file' => "#{root_dir}"+file, + 'path' => path, + 'extension' => extension, + 'count' => count} + + resp_body = File.read("#{root_dir}#{file}") + @http_server.mount( + url, + BeEF::Core::NetworkStack::Handlers::Raw.new('200', {'Content-Type'=>'text/plain'}, resp_body) + ) + @http_server.remap - print_info "File [" + "#{root_dir}"+file + "] bound to url [" + url + "]" + print_info "File [#{file}] bound to url [#{url}]" + url end diff --git a/core/main/network_stack/handlers/raw.rb b/core/main/network_stack/handlers/raw.rb index 7d6ff6f1f..a2af9839a 100644 --- a/core/main/network_stack/handlers/raw.rb +++ b/core/main/network_stack/handlers/raw.rb @@ -10,14 +10,19 @@ module BeEF class Raw - def initialize(status, header={}, body) + def initialize(status, header={}, body=nil) @status = status - @header = header - @body = body + @header = header + @body = body end def call(env) - [@status, @header, @body] + # [@status, @header, @body] + @response = Rack::Response.new( + body = @body, + status = @status, + header = @header + ) end private diff --git a/extensions/admin_ui/api/handler.rb b/extensions/admin_ui/api/handler.rb index 5b827d099..8b4c353bf 100644 --- a/extensions/admin_ui/api/handler.rb +++ b/extensions/admin_ui/api/handler.rb @@ -86,19 +86,16 @@ module API media_dir = File.dirname(__FILE__)+'/../media/' beef_server.mount("#{bp}/media", Rack::File.new(media_dir)) - # mount the favicon file, if we're not imitating a web server. if !config.get("beef.http.web_server_imitation.enable") - beef_server.mount('/favicon.ico', Rack::File.new("#{media_dir}#{config.get("beef.extension.admin_ui.favicon_dir")}/#{config.get("beef.extension.admin_ui.favicon_file_name")}")) + BeEF::Core::NetworkStack::Handlers::AssetHandler.instance.bind( + "/extensions/admin_ui/media#{config.get("beef.extension.admin_ui.favicon_dir")}/#{config.get("beef.extension.admin_ui.favicon_file_name")}", + '/favicon.ico') end self.build_javascript_ui beef_server end - - - end - end end end