Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nla redirection: use certificate of original server #424

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pyrdp/mitm/RDPMITM.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import asyncio
import datetime
import typing
import socket

from OpenSSL import SSL, crypto
from twisted.internet import reactor
from twisted.internet.protocol import Protocol

Expand Down Expand Up @@ -218,7 +220,22 @@ async def connectToServer(self):
self.log.error("Failed to connect to recording host: timeout expired")

def doClientTls(self):
cert = self.server.tcp.transport.getPeerCertificate()
if self.state.isRedirected():
self.log.info(
"Fetching certificate of the original host %(host)s:%(port)d because of NLA redirection",
{
"host": self.state.config.targetHost,
"port": self.state.config.targetPort,
},
)
# Use context from pyrdp
context = ClientTLSContext().getContext()
connection = SSL.Connection(context, socket.socket(socket.AF_INET, socket.SOCK_STREAM))
connection.connect((self.state.config.targetHost, self.state.config.targetPort))
connection.do_handshake()
cert = connection.get_peer_certificate()
else:
cert = self.server.tcp.transport.getPeerCertificate()
if not cert:
# Wait for server certificate
reactor.callLater(1, self.doClientTls)
Expand Down