Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/extensions/s2c_dns_tunnel/api.rb
1154 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 ServerClientDnsTunnel
9
module API
10
module ServerClientDnsTunnelHandler
11
BeEF::API::Registrar.instance.register(BeEF::Extension::ServerClientDnsTunnel::API::ServerClientDnsTunnelHandler,
12
BeEF::API::Server, 'pre_http_start')
13
BeEF::API::Registrar.instance.register(BeEF::Extension::ServerClientDnsTunnel::API::ServerClientDnsTunnelHandler,
14
BeEF::API::Server, 'mount_handler')
15
16
# Starts the S2C DNS Tunnel server at BeEF startup.
17
# @param http_hook_server [BeEF::Core::Server] HTTP server instance
18
def self.pre_http_start(_http_hook_server)
19
configuration = BeEF::Core::Configuration.instance
20
zone = configuration.get('beef.extension.s2c_dns_tunnel.zone')
21
raise ArgumentError, 'zone name is undefined' unless zone.to_s != ''
22
23
# if listen parameter is not defined in the config.yaml then interface with the highest BeEF's IP-address will be choosen
24
listen = configuration.get('beef.extension.s2c_dns_tunnel.listen')
25
Socket.ip_address_list.map { |x| listen = x.ip_address if x.ipv4? } if listen.to_s.empty?
26
27
port = 53
28
protocol = :udp
29
interfaces = [[protocol, listen, port]]
30
dns = BeEF::Extension::ServerClientDnsTunnel::Server.instance
31
dns.run(listen: interfaces, zone: zone)
32
33
print_info "Server-to-Client DNS Tunnel Server: #{listen}:#{port} (#{protocol})"
34
info = ''
35
info += "Zone: #{zone}\n"
36
print_more info
37
end
38
39
# Mounts the handler for processing HTTP image requests.
40
# @param beef_server [BeEF::Core::Server] HTTP server instance
41
def self.mount_handler(beef_server)
42
configuration = BeEF::Core::Configuration.instance
43
zone = configuration.get('beef.extension.s2c_dns_tunnel.zone')
44
beef_server.mount('/tiles', BeEF::Extension::ServerClientDnsTunnel::Httpd.new(zone))
45
end
46
end
47
end
48
end
49
end
50
end
51
52