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 logger to TwisterTCPLayer for error handling and made PyRDP more "scanner compliant" #136

Merged
merged 1 commit into from
Aug 1, 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
6 changes: 3 additions & 3 deletions pyrdp/layer/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class TwistedTCPLayer(IntermediateLayer, Protocol):
"""

def __init__(self):
self.log = logging.getLogger(LOGGER_NAMES.PYRDP)
super().__init__(TCPParser())
self.connectedEvent = asyncio.Event()
self.logSSLRequired = False
Expand Down Expand Up @@ -91,9 +92,8 @@ def dataReceived(self, data: bytes):
except KeyboardInterrupt:
raise
except Exception as e:
log = logging.getLogger(LOGGER_NAMES.PYRDP)
log.exception(e)
log.error("Exception occurred when receiving: %(data)s" , {"data": hexlify(data).decode()})
self.log.exception(e)
self.log.error("Exception occurred when receiving: %(data)s" , {"data": hexlify(data).decode()})
raise

def sendBytes(self, data: bytes):
Expand Down
4 changes: 4 additions & 0 deletions pyrdp/mitm/TCPMITM.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def __init__(self, client: TwistedTCPLayer, server: TwistedTCPLayer, attacker: T
self.recorder = recorder
self.serverConnector = serverConnector

# Allows a lower layer to raise error tagged with the correct sessionID
self.client.log = log
self.server.log = log

self.clientObserver = self.client.createObserver(
onConnection = self.onClientConnection,
onDisconnection = self.onClientDisconnection,
Expand Down
5 changes: 4 additions & 1 deletion pyrdp/parser/rdp/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ def parseClientCoreData(self, stream: BytesIO) -> ClientCoreData:
core.postBeta2ColorDepth = Uint16LE.unpack(stream)
core.clientProductId = Uint16LE.unpack(stream)
core.serialNumber = Uint32LE.unpack(stream)
core.highColorDepth = HighColorDepth(Uint16LE.unpack(stream))

# Should match HighColorDepth enum most of the time, but in order to support scanners and we script, we have to loosely accept this one
# Anyway, the server will reject it and enforce another one
core.highColorDepth = Uint16LE.unpack(stream)
core.supportedColorDepths = Uint16LE.unpack(stream)
core.earlyCapabilityFlags = Uint16LE.unpack(stream)
core.clientDigProductId = decodeUTF16LE(stream.read(64))
Expand Down