diff --git a/README.md b/README.md index 2c429ae7b..3fc0f8231 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ In August 2019, PyRDP was demo'ed at BlackHat Arsenal ([slides](https://docs.goo ## Table of Contents - [Supported Systems](#supported-systems) - [Installing](#installing) - * [Installing with Docker](#installing-with-docker) * [Installing on Windows](#installing-on-windows) + * [Installing with Docker](#installing-with-docker) * [Migrating away from pycrypto](#Migrating-away-from-pycrypto) - [Using the PyRDP Man-in-the-Middle](#using-the-pyrdp-man-in-the-middle) * [Specifying the private key and certificate](#specifying-the-private-key-and-certificate) @@ -54,7 +54,7 @@ In August 2019, PyRDP was demo'ed at BlackHat Arsenal ([slides](https://docs.goo ## 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). It has not been tested on OSX and Windows. +This tool has been tested to work on Python 3.6 on Linux (Ubuntu 18.04) and Windows (See section [Installing on Windows](#installing-on-windows)). It has not been tested on OSX. ## Installing @@ -108,6 +108,47 @@ deactivate 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](https://wiki.openssl.org/index.php/Binaries). Make sure it is reachable from your `$PATH`. + +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 `venv` is more standard anyway. + +Before installing the dependencies, you need to activate your virtual environment: + +``` +venv\Scripts\activate +``` + +Finally, you can install the project with Pip: + +``` +pip3 install -U pip setuptools wheel +pip3 install -U -e . +``` + +This should install all the dependencies required to run PyRDP. + +If you ever want to leave your virtual environment, you can simply deactivate it: + +``` +deactivate +``` + +Note that you will have to activate your environment every time you want to have the PyRDP scripts available as shell +commands. + ### Installing with Docker First of all, build the image by executing this command at the root of PyRDP (where Dockerfile is located): @@ -150,10 +191,6 @@ docker run -e DISPLAY=$DISPLAY -e QT_X11_NO_MITSHM=1 --net=host pyrdp pyrdp-play Keep in mind that exposing the host's network to the 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. -### Installing on Windows -If you want to install PyRDP on Windows, note that `setup.py` will try to compile `ext/rle.c`, so you will need to have -a C compiler installed. You will also need to generate a private key and certificate to run the MITM. - ### 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. diff --git a/bin/pyrdp-mitm.py b/bin/pyrdp-mitm.py index 815bbe7bf..3599ba46d 100755 --- a/bin/pyrdp-mitm.py +++ b/bin/pyrdp-mitm.py @@ -113,7 +113,12 @@ def generateCertificate(keyPath: str, certificatePath: str) -> bool: :return: True if generation was successful """ - result = os.system("openssl req -newkey rsa:2048 -nodes -keyout %s -x509 -days 365 -out %s -subj '/CN=www.example.com/O=PYRDP/C=US' 2>/dev/null" % (keyPath, certificatePath)) + if os.name != "nt": + nullDevicePath = "/dev/null" + else: + nullDevicePath = "NUL" + + result = os.system("openssl req -newkey rsa:2048 -nodes -keyout %s -x509 -days 365 -out %s -subj \"/CN=www.example.com/O=PYRDP/C=US\" 2>%s" % (keyPath, certificatePath, nullDevicePath)) return result == 0 diff --git a/bin/pyrdp-player.py b/bin/pyrdp-player.py index 18a52c370..311d0c45d 100755 --- a/bin/pyrdp-player.py +++ b/bin/pyrdp-player.py @@ -17,13 +17,13 @@ import logging import logging.handlers import sys +import os from PySide2.QtWidgets import QApplication from pyrdp.logging import LOGGER_NAMES, NotifyHandler from pyrdp.player import MainWindow - def prepareLoggers(logLevel: int, outDir: Path): logDir = outDir / "logs" logDir.mkdir(exist_ok = True) @@ -42,12 +42,15 @@ def prepareLoggers(logLevel: int, outDir: Path): pyrdpLogger.addHandler(fileHandler) pyrdpLogger.setLevel(logLevel) - notifyHandler = NotifyHandler() - notifyHandler.setFormatter(notificationFormatter) - - uiLogger = logging.getLogger(LOGGER_NAMES.PLAYER_UI) - uiLogger.addHandler(notifyHandler) + # https://docs.python.org/3/library/os.html + if os.name != "nt": + notifyHandler = NotifyHandler() + notifyHandler.setFormatter(notificationFormatter) + uiLogger = logging.getLogger(LOGGER_NAMES.PLAYER_UI) + uiLogger.addHandler(notifyHandler) + else: + pyrdpLogger.warning("Notifications are not supported for your platform, they will be disabled.") def main(): """ diff --git a/pyrdp/logging/handlers.py b/pyrdp/logging/handlers.py index 0b13af81b..32f19d920 100644 --- a/pyrdp/logging/handlers.py +++ b/pyrdp/logging/handlers.py @@ -6,8 +6,11 @@ import logging -import notify2 - +# Dependency not installed on Windows. Notifications are not supported +try: + import notify2 +except ImportError: + pass class NotifyHandler(logging.StreamHandler): """ diff --git a/setup.py b/setup.py index d35dc3484..66d531d7d 100755 --- a/setup.py +++ b/setup.py @@ -28,9 +28,7 @@ install_requires=[ 'appdirs', 'cryptography', - 'dbus-python', 'names', - 'notify2', 'pyasn1', 'pycryptodome', 'pyopenssl', @@ -39,5 +37,7 @@ 'rsa', 'service_identity', 'twisted', + 'dbus-python;platform_system!="Windows"', + 'notify2;platform_system!="Windows"' ], ) \ No newline at end of file