Skip to content

Commit dc7af31

Browse files
committed
fake server: improve logging
1 parent eddfec1 commit dc7af31

File tree

5 files changed

+16
-12
lines changed

5 files changed

+16
-12
lines changed

pyrdp/logging/log.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class LOGGER_NAMES:
1717
PYRDP = "pyrdp"
1818
MITM = f"{PYRDP}.mitm"
1919
MITM_CONNECTIONS = f"{MITM}.connections"
20+
MITM_FAKE_SERVER = f"{MITM}.fake_server"
2021
PLAYER = f"{PYRDP}.player"
2122
PLAYER_UI = f"{PLAYER}.ui"
2223
NTLMSSP = f"ntlmssp"

pyrdp/mitm/FakeServer.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Copyright (C) 2022
44
# Licensed under the GPLv3 or later.
55
#
6-
import multiprocessing, os, random, shutil, socket, subprocess, threading, time
6+
import logging, multiprocessing, os, random, shutil, socket, subprocess, threading, time
77

88
from tkinter import *
99
from PIL import Image, ImageTk
1010
from pyvirtualdisplay import Display
1111

12-
from logging import LoggerAdapter
12+
from pyrdp.logging import SessionLogger, LOGGER_NAMES
1313

1414
BACKGROUND_COLOR = "#044a91"
1515
IMAGES_DIR = os.path.dirname(__file__) + "/images"
@@ -159,11 +159,14 @@ def show_loading_animation(self, index):
159159

160160

161161
class FakeServer(threading.Thread):
162-
def __init__(self, targetHost: str, targetPort: int, log: LoggerAdapter):
162+
def __init__(self, targetHost: str, targetPort: int = 3389, sessionID: str = None):
163163
super().__init__()
164164
self.targetHost = targetHost
165165
self.targetPort = targetPort
166-
self.log = log
166+
self.log = SessionLogger(
167+
logging.getLogger(LOGGER_NAMES.MITM_FAKE_SERVER), sessionID
168+
)
169+
self.log.info("test")
167170

168171
self._launch_display()
169172

pyrdp/mitm/RDPMITM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def __init__(self, mainLogger: SessionLogger, crawlerLogger: SessionLogger, conf
7878
self.statCounter = StatCounter()
7979
"""Class to keep track of connection-related statistics such as # of mouse events, # of output events, etc."""
8080

81-
self.state = state if state is not None else RDPMITMState(self.config, self.log.sessionID, self.getLog)
81+
self.state = state if state is not None else RDPMITMState(self.config, self.log.sessionID)
8282
"""The MITM state"""
8383

8484
self.client = RDPLayerSet()

pyrdp/mitm/state.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RDPMITMState:
2222
State object for the RDP MITM. This is for data that needs to be shared across components.
2323
"""
2424

25-
def __init__(self, config: MITMConfig, sessionID: str, getLog: Callable[[str], SessionLogger]):
25+
def __init__(self, config: MITMConfig, sessionID: str):
2626
self.requestedProtocols: Optional[NegotiationProtocols] = None
2727
"""The original request protocols"""
2828

@@ -94,9 +94,6 @@ def __init__(self, config: MITMConfig, sessionID: str, getLog: Callable[[str], S
9494
self.fakeServer = None
9595
"""The current fake server"""
9696

97-
self.getLog = getLog
98-
"""Function to create additional loggers"""
99-
10097
self.securitySettings.addObserver(self.crypters[ParserMode.CLIENT])
10198
self.securitySettings.addObserver(self.crypters[ParserMode.SERVER])
10299

@@ -139,9 +136,12 @@ def useRedirectionHost(self):
139136

140137
def useFakeServer(self):
141138
from pyrdp.mitm.FakeServer import FakeServer
139+
142140
self.fakeServer = FakeServer(
143-
self.config.targetHost, self.config.targetPort, self.getLog("")
141+
self.config.targetHost,
142+
targetPort=self.config.targetPort,
143+
sessionID=self.sessionID,
144144
)
145145
self.effectiveTargetHost = "127.0.0.1"
146146
self.effectiveTargetPort = self.fakeServer.port
147-
self.fakeServer.start()
147+
self.fakeServer.start()

test/test_prerecorded.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def sendBytesStub(_: bytes):
122122
config.outDir = output_directory
123123

124124
# replay_transport = FileLayer(output_path)
125-
state = RDPMITMState(config, log.sessionID, lambda name : log.createChild(name))
125+
state = RDPMITMState(config, log.sessionID)
126126
super().__init__(log, log, config, state, CustomMITMRecorder([], state))
127127

128128
self.client.tcp.sendBytes = sendBytesStub

0 commit comments

Comments
 (0)