From 869822e15c01f2057bbcee66f0807a484d9d68c1 Mon Sep 17 00:00:00 2001 From: Ben Turner <2518196+benpturner@users.noreply.github.com> Date: Fri, 11 Oct 2024 11:19:14 +0100 Subject: [PATCH] Update C2Server.py for Python3.12 fix --- poshc2/server/C2Server.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/poshc2/server/C2Server.py b/poshc2/server/C2Server.py index 9256c3f2..d47bb178 100644 --- a/poshc2/server/C2Server.py +++ b/poshc2/server/C2Server.py @@ -576,14 +576,16 @@ def main(args): if not UseHttp: cert_file = f"{PoshProjectDirectory}posh.crt" key_file = f"{PoshProjectDirectory}posh.key" - + if (os.path.isfile(cert_file)) and (os.path.isfile(key_file)): - try: - httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=key_file, certfile=cert_file, server_side=True, - ssl_version=ssl.PROTOCOL_TLS) + try: + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS) + ssl_context.load_cert_chain(cert_file, key_file) + httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True) except Exception: - httpd.socket = ssl.wrap_socket(httpd.socket, keyfile=key_file, certfile=cert_file, server_side=True, - ssl_version=ssl.PROTOCOL_TLSv1) + ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1) + ssl_context.load_cert_chain(cert_file, key_file) + httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True) else: raise ValueError("Cannot find the certificate files")