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 Windows support #129

Merged
merged 7 commits into from
Aug 19, 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
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion bin/pyrdp-mitm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
15 changes: 9 additions & 6 deletions bin/pyrdp-player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
"""
Expand Down
7 changes: 5 additions & 2 deletions pyrdp/logging/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
install_requires=[
'appdirs',
'cryptography',
'dbus-python',
'names',
'notify2',
'pyasn1',
'pycryptodome',
'pyopenssl',
Expand All @@ -39,5 +37,7 @@
'rsa',
'service_identity',
'twisted',
'dbus-python;platform_system!="Windows"',
'notify2;platform_system!="Windows"'
],
)