Skip to content

Commit

Permalink
Fix proxy extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Phasip committed Nov 15, 2024
1 parent 33717fc commit 316dd5f
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions extensions/proxy/proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Proxy
HB = BeEF::Core::Models::HookedBrowser
H = BeEF::Core::Models::Http
@response = nil
@ssl_context = nil

# Multi-threaded Tunneling Proxy: listens on host:port configured in extensions/proxy/config.yaml
# and forwards requests to the hooked browser using the Requester component.
Expand All @@ -20,14 +21,14 @@ def initialize
@proxy_server = TCPServer.new(@conf.get('beef.extension.proxy.address'), @conf.get('beef.extension.proxy.port'))

# setup proxy for SSL/TLS
ssl_context = OpenSSL::SSL::SSLContext.new
@ssl_context = OpenSSL::SSL::SSLContext.new
# ssl_context.ssl_version = :TLSv1_2

# load certificate
begin
cert_file = @conf.get('beef.extension.proxy.cert')
cert = File.read(cert_file)
ssl_context.cert = OpenSSL::X509::Certificate.new(cert)
@ssl_context.cert = OpenSSL::X509::Certificate.new(cert)
rescue StandardError
print_error "[Proxy] Could not load SSL certificate '#{cert_file}'"
end
Expand All @@ -36,17 +37,14 @@ def initialize
begin
key_file = @conf.get('beef.extension.proxy.key')
key = File.read(key_file)
ssl_context.key = OpenSSL::PKey::RSA.new(key)
@ssl_context.key = OpenSSL::PKey::RSA.new(key)
rescue StandardError
print_error "[Proxy] Could not load SSL key '#{key_file}'"
end

ssl_server = OpenSSL::SSL::SSLServer.new(@proxy_server, ssl_context)
ssl_server.start_immediately = false

loop do
ssl_socket = ssl_server.accept
Thread.new ssl_socket, &method(:handle_request)
socket = @proxy_server.accept
Thread.new socket, &method(:handle_request)
end
end

Expand All @@ -69,6 +67,7 @@ def handle_request(socket)
break if line.strip.empty?
end
socket.puts("HTTP/1.0 200 Connection established\r\n\r\n")
socket = OpenSSL::SSL::SSLSocket(socket, @ssl_context)
socket.accept
print_debug("[PROXY] Handled CONNECT to #{host_port}")
request_line = socket.readline
Expand Down

0 comments on commit 316dd5f

Please sign in to comment.