Jump to content
Nytro

RDPY - Remote Desktop Protocol in Twisted Python

Recommended Posts

Posted

RDPY

Remote Desktop Protocol in twisted python.

RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol (client and server side). RDPY is built over the event driven network engine Twisted.

RDPY provides the following RDP and VNC binaries :

  • RDP Man In The Middle proxy which record session
  • RDP Honeypot
  • RDP screenshoter
  • RDP client
  • VNC client
  • VNC screenshoter
  • RSS Player

Build

RDPY is fully implemented in python, except the bitmap decompression algorithm which is implemented in C for performance purposes.

Dependencies

Dependencies are only needed for pyqt4 binaries :

  • rdpy-rdpclient
  • rdpy-rdpscreenshot
  • rdpy-vncclient
  • rdpy-vncscreenshot
  • rdpy-rssplayer

Linux

Example for Debian based systems :

sudo apt-get install python-qt4

Windows

[TABLE=width: 728]

[TR]

[TH]x86[/TH]

[TH]x86_64[/TH]

[/TR]

[TR]

[TD]PyQt4[/TD]

[TD]PyQt4[/TD]

[/TR]

[TR=bgcolor: #F8F8F8]

[TD]PyWin32[/TD]

[TD]PyWin32[/TD]

[/TR]

[/TABLE]

Build

$ git clone https://github.com/citronneur/rdpy.git rdpy

$ pip install twisted pyopenssl qt4reactor service_identity rsa

$ python rdpy/setup.py install

Or use PIP:

$ pip install rdpy

For virtualenv, you will need to link the qt4 library to it:

$ ln -s /usr/lib/python2.7/dist-packages/PyQt4/ $VIRTUAL_ENV/lib/python2.7/site-packages/

$ ln -s /usr/lib/python2.7/dist-packages/sip.so $VIRTUAL_ENV/lib/python2.7/site-packages/

RDPY Binaries

RDPY comes with some very useful binaries. These binaries are linux and windows compatible.

rdpy-rdpclient

rdpy-rdpclient is a simple RDP Qt4 client.

$ rdpy-rdpclient.py [-u username] [-p password] [-d domain] [-r rss_ouput_file] [...] XXX.XXX.XXX.XXX[:3389]

You can use rdpy-rdpclient in a Recorder Session Scenario, used in rdpy-rdphoneypot.

rdpy-vncclient

rdpy-vncclient is a simple VNC Qt4 client .

$ rdpy-vncclient.py [-p password] XXX.XXX.XXX.XXX[:5900]

rdpy-rdpscreenshot

rdpy-rdpscreenshot saves login screen in file.

$ rdpy-rdpscreenshot.py [-w width] [-l height] [-o output_file_path] XXX.XXX.XXX.XXX[:3389]

rdpy-vncscreenshot

rdpy-vncscreenshot saves the first screen update in file.

$ rdpy-vncscreenshot.py [-p password] [-o output_file_path] XXX.XXX.XXX.XXX[:5900]

rdpy-rdpmitm

rdpy-rdpmitm is a RDP proxy allows you to do a Man In The Middle attack on RDP protocol. Record Session Scenario into rss file which can be replayed by rdpy-rssplayer.

$ rdpy-rdpmitm.py -o output_dir [-l listen_port] [-k private_key_file_path] [-c certificate_file_path] [-r (for XP or server 2003 client)] target_host[:target_port]

Output directory is used to save the rss file with following format (YYYYMMDDHHMMSS_ip_index.rss) The private key file and the certificate file are classic cryptographic files for SSL connections. The RDP protocol can negotiate its own security layer. The CredSSP security layer is planned for an upcoming release. If one of both parameters are omitted, the server use standard RDP as security layer.

rdpy-rdphoneypot

rdpy-rdphoneypot is an RDP honey Pot. Use Recorded Session Scenario to replay scenario through RDP Protocol.

$ rdpy-rdphoneypot.py [-l listen_port] [-k private_key_file_path] [-c certificate_file_path] rss_file_path_1 ... rss_file_path_N

The private key file and the certificate file are classic cryptographic files for SSL connections. The RDP protocol can negotiate its own security layer. The CredSSP security layer is planned for an upcoming release. If one of both parameters are omitted, the server use standard RDP as security layer. You can specify more than one files to match more common screen size.

rdpy-rssplayer

rdpy-rssplayer is use to replay Record Session Scenario (rss) files generates by either rdpy-rdpmitm or rdpy-rdpclient binaries.

$ rdpy-rssplayer.py rss_file_path

RDPY Qt Widget

RDPY can also be used as Qt widget through rdpy.ui.qt4.QRemoteDesktop class. It can be embedded in your own Qt application. qt4reactor must be used in your app for Twisted and Qt to work together. For more details, see sources of rdpy-rdpclient.

RDPY library

In a nutshell RDPY can be used as a protocol library with a twisted engine.

Simple RDP Client

[FONT=Helvetica Neue]from rdpy.protocol.rdp import rdp

class MyRDPFactory(rdp.ClientFactory):

def clientConnectionLost(self, connector, reason):
reactor.stop()

def clientConnectionFailed(self, connector, reason):
reactor.stop()

def buildObserver(self, controller, addr):

class MyObserver(rdp.RDPClientObserver)

def onReady(self):
"""
@summary: Call when stack is ready
"""
#send 'r' key
self._controller.sendKeyEventUnicode(ord(unicode("r".toUtf8(), encoding="UTF-8")), True)
#mouse move and click at pixel 200x200
self._controller.sendPointerEvent(200, 200, 1, true)

def onUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
"""
@summary: Notify bitmap update
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m destLeft: xmin position
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m destTop: ymin position
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m destRight: xmax position because RDP can send bitmap with padding
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m destBottom: ymax position because RDP can send bitmap with padding
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m width: width of bitmap
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m height: height of bitmap
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m bitsPerPixel: number of bit per pixel
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m isCompress: use RLE compression
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m data: bitmap data
"""

def onClose(self):
"""
@summary: Call when stack is close
"""

return MyObserver(controller)

from twisted.internet import reactor
reactor.connectTCP("XXX.XXX.XXX.XXX", 3389), MyRDPFactory())
reactor.run()[/FONT]

Simple RDP Server

[FONT=Helvetica Neue]from rdpy.protocol.rdp import rdp

class MyRDPFactory(rdp.ServerFactory):

def buildObserver(self, controller, addr):

class MyObserver(rdp.RDPServerObserver)

def onReady(self):
"""
@summary: Call when server is ready
to send and receive messages
"""

def onKeyEventScancode(self, code, isPressed):
"""
@summary: Event call when a keyboard event is catch in scan code format
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m code: scan code of key
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m isPressed: True if key is down
@[URL="https://rstforums.com/forum/members/see/"]see[/URL]: rdp.RDPServerObserver.onKeyEventScancode
"""

def onKeyEventUnicode(self, code, isPressed):
"""
@summary: Event call when a keyboard event is catch in unicode format
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m code: unicode of key
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m isPressed: True if key is down
@[URL="https://rstforums.com/forum/members/see/"]see[/URL]: rdp.RDPServerObserver.onKeyEventUnicode
"""

def onPointerEvent(self, x, y, button, isPressed):
"""
@summary: Event call on mouse event
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m x: x position
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m y: y position
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m button: 1, 2 or 3 button
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m isPressed: True if mouse button is pressed
@[URL="https://rstforums.com/forum/members/see/"]see[/URL]: rdp.RDPServerObserver.onPointerEvent
"""

def onClose(self):
"""
@summary: Call when human client close connection
@[URL="https://rstforums.com/forum/members/see/"]see[/URL]: rdp.RDPServerObserver.onClose
"""

return MyObserver(controller)

from twisted.internet import reactor
reactor.listenTCP(3389, MyRDPFactory())
reactor.run()[/FONT]

Simple VNC Client

[FONT=Helvetica Neue]from rdpy.protocol.rfb import rfb

class MyRFBFactory(rfb.ClientFactory):

def clientConnectionLost(self, connector, reason):
reactor.stop()

def clientConnectionFailed(self, connector, reason):
reactor.stop()

def buildObserver(self, controller, addr):
class MyObserver(rfb.RFBClientObserver)

def onReady(self):
"""
@summary: Event when network stack is ready to receive or send event
"""

def onUpdate(self, width, height, x, y, pixelFormat, encoding, data):
"""
@summary: Implement RFBClientObserver interface
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m width: width of new image
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m height: height of new image
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m x: x position of new image
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m y: y position of new image
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m pixelFormat: pixefFormat structure in rfb.message.PixelFormat
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m encoding: encoding type rfb.message.Encoding
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m data: image data in accordance with pixel format and encoding
"""

def onCutText(self, text):
"""
@summary: event when server send cut text event
@[URL="https://rstforums.com/forum/members/para/"]Para[/URL]m text: text received
"""

def onBell(self):
"""
@summary: event when server send biiip
"""

def onClose(self):
"""
@summary: Call when stack is close
"""

return MyObserver(controller)

from twisted.internet import reactor
reactor.connectTCP("XXX.XXX.XXX.XXX", 3389), MyRFBFactory())
reactor.run()[/FONT]

Sursa: https://github.com/citronneur/rdpy

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...