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

Added client's IP and clientData to allow client identification #123

Merged
merged 2 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions pyrdp/mitm/MCSMITM.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Licensed under the GPLv3 or later.
#

from logging import LoggerAdapter
from typing import Callable, Dict

from pyrdp.enum import ClientCapabilityFlag, EncryptionLevel, EncryptionMethod, HighColorDepth, MCSChannelName, \
Expand All @@ -27,15 +28,18 @@ class MCSMITM:
external callback for building MCS channels when a join request is accepted.
"""

def __init__(self, client: MCSLayer, server: MCSLayer, state: RDPMITMState, recorder: Recorder, buildChannelCallback: Callable[[MCSServerChannel, MCSClientChannel], None]):
def __init__(self, client: MCSLayer, server: MCSLayer, state: RDPMITMState, recorder: Recorder,
buildChannelCallback: Callable[[MCSServerChannel, MCSClientChannel], None], log: LoggerAdapter):
"""
:param client: MCS layer for the client side
:param server: MCS layer for the server side
:param state: the RDP MITM shared state
:param recorder: the recorder for this session
:param buildChannelCallback: function called when MCS channels are built
:param log: logger for the MCS layer.
"""

self.log = log
self.client = client
self.server = server
self.state = state
Expand Down Expand Up @@ -75,9 +79,9 @@ def onConnectInitial(self, pdu: MCSConnectInitialPDU):
gccParser = GCCParser()
rdpClientConnectionParser = ClientConnectionParser()
gccConferenceCreateRequestPDU: GCCConferenceCreateRequestPDU = gccParser.parse(pdu.payload)
rdpClientDataPDU = rdpClientConnectionParser.parse(gccConferenceCreateRequestPDU.payload)

# FIPS is not implemented, so remove this flag if it's set
rdpClientDataPDU = rdpClientConnectionParser.parse(gccConferenceCreateRequestPDU.payload)
rdpClientDataPDU.securityData.encryptionMethods &= ~EncryptionMethod.ENCRYPTION_FIPS
rdpClientDataPDU.securityData.extEncryptionMethods &= ~EncryptionMethod.ENCRYPTION_FIPS

Expand Down Expand Up @@ -114,6 +118,8 @@ def onConnectInitial(self, pdu: MCSConnectInitialPDU):
gccParser.write(serverGCCPDU)
)

self.log.info("Client hostname %(clientName)s", {"clientName": rdpClientDataPDU.coreData.clientName.strip("\x00")})

self.server.sendPDU(serverMCSPDU)

def onConnectResponse(self, pdu: MCSConnectResponsePDU):
Expand Down
3 changes: 2 additions & 1 deletion pyrdp/mitm/TCPMITM.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def onClientConnection(self):
Log the fact that a new client has connected.
"""
self.connectionTime = time.time()
self.log.info("New client connected")
ip = self.client.transport.client[0]
self.log.info("New client connected from %(clientIp)s", {"clientIp": ip})

def onClientDisconnection(self, reason):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyrdp/mitm/mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(self, log: SessionLogger, config: MITMConfig):
self.x224 = X224MITM(self.client.x224, self.server.x224, self.getLog("x224"), self.state, serverConnector, self.startTLS)
"""X224 MITM component"""

self.mcs = MCSMITM(self.client.mcs, self.server.mcs, self.state, self.recorder, self.buildChannel)
self.mcs = MCSMITM(self.client.mcs, self.server.mcs, self.state, self.recorder, self.buildChannel, self.getLog("mcs"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to change but it might cause a conflict with #117 so we just need to watch out for that

"""MCS MITM component"""

self.security: SecurityMITM = None
Expand Down