Need help with pyrdp?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

583 Stars 134 Forks GNU General Public License v3.0 1.7K Commits 27 Opened issues


RDP man-in-the-middle (mitm) and library for Python with the ability to watch connections live or after the fact

Services available


Need anything else?

Contributors list


pipeline status

PyRDP is a Python 3 Remote Desktop Protocol (RDP) Man-in-the-Middle (MITM) and library.

PyRDP Logo

It features a few tools: - RDP Man-in-the-Middle - Logs credentials used when connecting - Steals data copied to the clipboard - Saves a copy of the files transferred over the network - Crawls shared drives in the background and saves them locally - Saves replays of connections so you can look at them later - Runs console commands or PowerShell payloads automatically on new connections - RDP Player: - See live RDP connections coming from the MITM - View replays of RDP connections - Take control of active RDP sessions while hiding your actions - List the client's mapped drives and download files from them during active sessions - RDP Certificate Cloner: - Create a self-signed X509 certificate with the same fields as an RDP server's certificate

PyRDP was introduced in 2018 in which we demonstrated that we can catch a real threat actor in action. This tool is being developed with both pentest and malware research use cases in mind.

PyRDP Player Replaying an RDP session

Table of Contents

Supported Systems

PyRDP should work on Python 3.6 and up.

This tool has been tested to work on Python 3.6 on Linux (Ubuntu 18.04) and Windows (See section Installing on Windows). It has not been tested on OSX.


Using the Docker Image

This is the easiest installation method if you have docker installed and working.

docker pull gosecure/pyrdp:latest

As an alternative we have a slimmer image without the GUI and ffmpeg dependencies.

docker pull gosecure/pyrdp:latest-slim

From Git Source

We recommend installing PyRDP in a virtual environment to avoid dependency issues.

First, make sure to install the prerequisite packages (on Ubuntu). We provide two types of installs a full one and a slim one. Install the dependencies according to your use case.

# Full install (GUI, transcoding to MP4)
sudo apt install python3 python3-pip python3-dev python3-setuptools python3-venv \
        build-essential python3-dev git openssl \
        libdbus-1-dev libdbus-glib-1-dev libgl1-mesa-glx \
        notify-osd dbus-x11 libxkbcommon-x11-0 \
        libavformat-dev libavcodec-dev libavdevice-dev \
        libavutil-dev libswscale-dev libswresample-dev libavfilter-dev

Slim install (no GUI, no transcoding)

sudo apt install python3 python3-pip python3-setuptools python3-venv
build-essential python3-dev git openssl

Grab PyRDP's source code:

git clone

Then, create your virtual environment in the

directory inside PyRDP's directory:
cd pyrdp
python3 -m venv venv

DO NOT use the root PyRDP directory for the virtual environment folder (

python3 -m venv .
). You will make a mess, and using a directory name like
is more standard anyway.

Before installing the dependencies, you need to activate your virtual environment:

source venv/bin/activate

Finally, you can install the project with Pip:

pip3 install -U pip setuptools wheel

Without GUI and ffmpeg dependencies

pip3 install -U -e .

With GUI and ffmpeg dependencies

pip3 install -U -e '.[full]'

This should install the dependencies required to run PyRDP. If you choose to install without GUI or ffmpeg dependencies, it will not be possible to use

without headless mode (
) or

If you ever want to leave your virtual environment, you can simply deactivate it:


Note that you will have to activate your environment every time you want to have the PyRDP scripts available as shell commands.

Installing on Windows

The steps are almost the same. There are two additional prerequisites.

  1. Any C compiler
  2. OpenSSL. Make sure it is reachable from your

Then, create your virtual environment in PyRDP's directory:

cd pyrdp
python3 -m venv venv

DO NOT use the root PyRDP directory for the virtual environment folder (

python3 -m venv .
). You will make a mess, and using a directory name like
is more standard anyway.

Before installing the dependencies, you need to activate your virtual environment:


Finally, you can install the project with Pip:

pip3 install -U pip setuptools wheel
pip3 install -U -e ".[full]"

This should install all the dependencies required to run PyRDP.

If you ever want to leave your virtual environment, you can simply deactivate it:


Note that you will have to activate your environment every time you want to have the PyRDP scripts available as shell commands.

Building the Docker Image

First of all, build the image by executing this command at the root of PyRDP (where Dockerfile is located):

docker build -t pyrdp .

As an alternative we have a slimmer image without the GUI and ffmpeg dependencies:

docker build -f Dockerfile.slim -t pyrdp .

Afterwards, you can execute PyRDP by invoking the

docker container. See Usage instructions and the Docker specific instructions for details.

Migrating away from pycrypto

Since pycrypto isn't maintained anymore, we chose to migrate to pycryptodome. If you get this error, it means that you are using the module pycrypto instead of pycryptodome.

  File "[...]/pyrdp/pyrdp/pdu/rdp/", line 10, in 
    from Crypto.PublicKey.RSA import RsaKey
ImportError: cannot import name 'RsaKey'

You will need to remove the module pycrypto and reinstall PyRDP.

pip3 uninstall pycrypto
pip3 install -U -e .

Using PyRDP

Using the PyRDP Man-in-the-Middle

or :
to run the MITM.

Assuming you have an RDP server running on
and listening on port 3389, you would run:

When running the MITM for the first time on Linux, a private key and certificate should be generated for you in

. These are used when TLS security is used on a connection. You can use them to decrypt PyRDP traffic in Wireshark, for example.

Specifying the private key and certificate

If key generation didn't work or you want to use a custom key and certificate, you can specify them using the

arguments: -k private_key.pem -c certificate.pem

Connecting to the PyRDP player

If you want to see live RDP connections through the PyRDP player, you will need to specify the ip and port on which the player is listening using the

arguments. Note: the port argument is optional, the default port is 3000. -i -d 3000
Connecting to a PyRDP player when the MITM is running on a server

If you are running the MITM on a server and still want to see live RDP connections, you should use SSH remote port forwarding to forward a port on your server to the player's port on your machine. Once this is done, you pass
and the forwarded port as arguments to the MITM. For example, if port 4000 on the server is forwarded to the player's port on your machine, this would be the command to use: -i -d 4000

Running payloads on new connections

PyRDP has support for running console commands or PowerShell payloads automatically when new connections are made. Due to the nature of RDP, the process is a bit hackish and is not always 100% reliable. Here is how it works:

  1. Wait for the user to be authenticated.
  2. Block the client's input / output to hide the payload and prevent interference.
  3. Send a fake Windows+R sequence and run
  4. Run the payload as a console command and exit the console. If a PowerShell payload is configured, it is run with
    powershell -enc 
  5. Wait a bit to allow the payload to complete.
  6. Restore the client's input / output.

For this to work, you need to set 3 arguments:

  • the payload
  • the delay before the payload starts
  • the payload's duration
Setting the payload

You can use one of the following arguments to set the payload to run:

  • --payload
    , a string containing console commands
  • --payload-powershell
    , a string containing PowerShell commands
  • --payload-powershell-file
    , a path to a PowerShell script
Choosing when to start the payload

For the moment, PyRDP does not detect when the user is logged on. You must give it an amount of time to wait for before running the payload. After this amount of time has passed, it will send the fake key sequences and expect the payload to run properly. To do this, you use the

argument. The delay is in milliseconds. For example, if you expect the user to be logged in within the first 5 seconds, you would use the following arguments:
--payload-delay 5000

This could be made more accurate by leveraging some messages exchanged during RDPDR initialization. See this issue if you're interested in making this work better.

Choosing when to resume normal activity

Because there is no direct way to know when the console has stopped running, you must tell PyRDP how long you want the client's input / output to be blocked. We recommend you set this to the maximum amount of time you would expect the console that is running your payload to be visible. In other words, the amount of time you would expect your payload to complete. To set the payload duration, you use the

argument with an amount of time in milliseconds. For example, if you expect your payload to take up to 5 seconds to complete, you would use the following argument:
--payload-duration 5000

This will block the client's input / output for 5 seconds to hide the console and prevent interference. After 5 seconds, input / output is restored back to normal.

Other MITM arguments

Run --help
for a full list of arguments.

This argument is useful when running PyRDP in Honeypot scenarios to avoid scanner fingerprinting. When the switch is enabled, PyRDP will not downgrade unsupported extensions and let the traffic through transparently. The player will likely not be able to successfully replay video traffic, but the following supported channels should still be accessible:

  • Keystroke recording
  • Mouse position updates
  • Clipboard access (passively)
  • Drive access (passively)

This feature is still a work in progress and some downgrading is currently unavoidable to allow the connection to be established. The following are currently not affected by this switch and will still be disabled:

  • FIPS Encryption
  • Non-TLS encryption protocols
  • ClientInfo compression
  • Virtual Channel compression

NOTE: If being able to eventually replay the full session is important, a good solution is to record the raw RDP traffic using Wireshark and keep the TLS master secrets. Whenever PyRDP adds support for additional extensions, it would then become possible to extract a valid RDP replay file from the raw network capture.


Tells PyRDP to attempt to spoof the source IP address of the client so that the server sees the real IP address instead of the MITM one. This option is only useful in certain scenarios where the MITM is physically a gateway between clients and the server and sees all traffic. Specific examples can be found here.

NOTE: This requires root privileges, only works on Linux and requires manual firewall configuration to ensure that traffic is routed properly.

: Disable Accelerated Graphics Pipeline

PyRDP downgrades video to the the most recent graphics pipeline that it supports. This switch explicitly tells the MITM to not use the Graphics Device Interface Acceleration extensions to stream video. The advantage of this mode is a significant reduction in required bandwidth for high resolution connections.

Note that some GDI drawing orders are currently unimplemented because they appear to be unused. If you have a replay which contains any unsupported or untested order, do not hesitate to share it with the project maintainers so that support can be added as required. (Make sure that the trace does not contain sensitive information)

Using the PyRDP Player

to run the player.

Playing a replay file

You can use the menu to open a new replay file: File > Open.

You can also open replay files when launching the player:   ...

Listening for live connections

The player always listens for live connections. By default, the listening port is 3000, but it can be changed: -p 

Changing the listening address

By default, the player only listens to connections coming from the local machine. We do not recommend opening up the player to other machines. If you still want to change the listening address, you can do it with

: -b 

Other player arguments

Run --help
for a full list of arguments.

Using the PyRDP Certificate Cloner

The PyRDP certificate cloner creates a brand new X509 certificate by using the values from an existing RDP server's certificate. It connects to an RDP server, downloads its certificate, generates a new private key and replaces the public key and signature of the certificate using the new private key. This can be used in a pentest if, for example, you're trying to trick a legitimate user into going through your MITM. Using a certificate that looks like a legitimate certificate could increase your success rate.

Cloning a certificate

You can clone a certificate by using
: cert.pem -o key.pem


parameter defines the path name to use for the generated private key.

Using a custom private key

If you want to use your own private key instead of generating a new one: cert.pem -i input_key.pem

Other cloner arguments

Run --help
for a full list of arguments.

Using PyRDP Convert

is a helper script that performs several useful conversions. The script has the best chance of working on traffic captured by PyRDP due to unsupported RDP protocol features that might be used in a non-intercepted connection.

The following conversions are supported:

  • Network Capture (PCAP) to PyRDP replay file
  • Network Capture to MP4 video file
  • Replay file to MP4 video file

The script supports both encrypted (TLS) network captures (by providing

--secrets ssl.log
) and decrypted PDU exports.

WARNING: pcapng and pcap with nanosecond timestamps are not compatible with

and will create replay files that fail to playback or export to MP4. This is due to incompatible timestamp formats.
# Export the session coming client to a .pyrdp file. --src --secrets ssl.log -o path/to/output capture.pcap

Or as an MP4 video --src --secrets ssl.log -o path/to/output -f mp4 capture.pcap

List the sessions in a network trace, along with the decryptable ones. --list capture.pcap

Note that MP4 conversion requires libavcodec and ffmpeg, so this may require extra steps on Windows.

Manually decrypted network traces can be exported from Wireshark by selecting

File > Export PDUs
and selecting
Layer 7
. When using this method, it is also recommended to filter the exported stream to only contain the TCP stream of the RDP session which must be converted.

First, make sure you configured wireshark to load TLS secrets:

Configure TLS secrets log

Next, export OSI Layer 7 PDUs:

Export OSI Layer 7

And lastly, filter down the trace to contain only the conversation of interest (Optional but recommended) by applying a display filter and clicking

File > Export Specified Packets...

Filtering the exported trace

Now this trace can be used directly in


Configuring PyRDP

Most of the PyRDP configurations are done through command line switches, but it is also possible to use a configuration file for certain settings such as log configuration.

The default configuration files used by PyRDP are located in mitm.default.ini and player.default.ini. Both files are thoroughly documented and can serve as a basis for further configuration.

In the future there are plans to support other aspects of PyRDP configuration through those configuration files.

Using PyRDP as a Library

If you're interested in experimenting with RDP and making your own tools, head over to our documentation section for more information.

Using PyRDP with twistd

The PyRDP MITM component was also implemented as a twistd plugin. This enables you to run it in debug mode and allows you to get an interactive debugging repl (pdb) if you send a

to the twistd process.
twistd --debug pyrdp -t 

Then to get the repl:

killall -SIGUSR2 twistd

Using PyRDP with twistd in Docker

In a directory with our

you can run something like this:
docker-compose run -p 3389:3389 pyrdp twistd --debug pyrdp --target

This will allocate a TTY and you will have access to

's REPL. Trying to add
to the
command will fail because there is no TTY allocated.

Using PyRDP with Bettercap

We developped our own Bettercap module,

, to man-in-the-middle all RDP connections on a given LAN. Check out this document for more information.

Docker Specific Usage Instructions

Since docker restricts the interactions with the host system (filesystem and network), the PyRDP docker image must be run with some parameters depending on your use case. This section documents those parameters.

We refer to the publicly provided docker image but if you built your own replace

with the name of your locally built image.

Mapping a Listening Port

In most of the man-in-the-middle cases you will need to map a port of your host into the docker image. This is achieved by the

) parameters applied to
docker run

For example, to listen on 3389 (RDP's default port) on all interfaces, use:

docker run -p 3389:3389 gosecure/pyrdp

Logs and Artifacts Storage

To store the PyRDP output permanently (logs, files, etc.), add the

) option to the previous command. In this example we store the files relatively to the current directory in
docker run -v $PWD/pyrdp_output:/home/pyrdp/pyrdp_output -p 3389:3389 gosecure/pyrdp

Make sure that your destination directory is owned by a user with a UID of 1000, otherwise you will get permission denied errors. If you are the only non-root user on the system, usually your user will be assigned UID 1000.

Logging the host IP address

If you want PyRDP to log the host IP address in its logs, you can set the

environment variable when using
docker run
docker run -p 3389:3389 -e HOST_IP= gosecure/pyrdp

Using the GUI Player in Docker

Using the player will require you to export the

environment variable from the host to the docker. This redirects the GUI of the player to the host screen. You also need to expose the host's network and prevent Qt from using the MIT-SHM X11 Shared Memory Extension. To do so, add the
options to the run command:
docker run -e DISPLAY=$DISPLAY -e QT_X11_NO_MITSHM=1 --net=host gosecure/pyrdp

Keep in mind that exposing the host's network to docker can compromise the isolation between your container and the host. If you plan on using the player, X11 forwarding using an SSH connection would be a more secure way.

PyRDP Lore

Contributing to PyRDP

See our contribution guidelines.


PyRDP uses code from the following open-source software:

  • RC4-Python for the RC4 implementation.
  • rdesktop for bitmap decompression.
  • rdpy for RC4 keys, the bitmap decompression bindings and the base GUI code for the PyRDP player.
  • FreeRDP for the scan code enumeration.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.