
Twisted Python में रिमोट डेस्कटॉप प्रोटोकॉल

ट्विस्टेड पायथन में रिमोट डेस्कटॉप प्रोटोकॉल।
RDPY माइक्रोसॉफ्ट RDP (रिमोट डेस्कटॉप प्रोटोकॉल) प्रोटोकॉल (क्लाइंट और सर्वर दोनों पक्ष) का एक शुद्ध पायथन कार्यान्वयन है। RDPY घटना-संचालित नेटवर्क इंजन ट्विस्टेड पर बनाया गया है। RDPY मानक RDP सुरक्षा परत, SSL पर RDP और NLA प्रमाणीकरण (ntlmv2 प्रमाणीकरण प्रोटोकॉल के माध्यम से) का समर्थन करता है।
RDPY निम्नलिखित RDP और VNC बाइनरी प्रदान करता है:
RDPY पूरी तरह से पायथन में लागू किया गया है, सिवाय बिटमैप डिकम्प्रेशन एल्गोरिदम के जो प्रदर्शन उद्देश्यों के लिए C में लागू किया गया है।
निर्भरताएँ केवल pyqt4 बाइनरी के लिए आवश्यक हैं:
डेबियन-आधारित सिस्टम के लिए उदाहरण:
sudo apt-get install python-qt4
OS X पर होमब्रू के साथ PyQt स्थापित करने का उदाहरण:
$ brew install qt sip pyqt
$ git clone https://github.com/citronneur/rdpy.git rdpy
$ pip install twisted pyopenssl qt4reactor service_identity rsa pyasn1
$ python rdpy/setup.py install
या PIP का उपयोग करें:
$ pip install rdpy
वर्चुअलएनवी के लिए, आपको इसमें qt4 लाइब्रेरी को लिंक करना होगा:
$ 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 कुछ बहुत उपयोगी बाइनरी के साथ आता है। ये बाइनरी लिनक्स और विंडोज संगत हैं।
rdpy-rdpclient एक सरल RDP Qt4 क्लाइंट है।
$ rdpy-rdpclient.py [-u उपयोगकर्ता_नाम] [-p पासवर्ड] [-d डोमेन] [-r rss_आउटपुट_फ़ाइल] [...] XXX.XXX.XXX.XXX[:3389]
आप rdpy-rdpclient का उपयोग रिकॉर्डर सत्र परिदृश्य में कर सकते हैं, जो rdpy-rdphoneypot में उपयोग किया जाता है।
rdpy-vncclient एक सरल VNC Qt4 क्लाइंट है।
$ rdpy-vncclient.py [-p पासवर्ड] XXX.XXX.XXX.XXX[:5900]
rdpy-rdpscreenshot लॉगिन स्क्रीन को फ़ाइल में सहेजता है।
$ rdpy-rdpscreenshot.py [-w चौड़ाई] [-l ऊँचाई] [-o आउटपुट_फ़ाइल_पथ] XXX.XXX.XXX.XXX[:3389]
rdpy-vncscreenshot पहली स्क्रीन अपडेट को फ़ाइल में सहेजता है।
$ rdpy-vncscreenshot.py [-p पासवर्ड] [-o आउटपुट_फ़ाइल_पथ] XXX.XXX.XXX.XXX[:5900]
rdpy-rdpmitm एक RDP प्रॉक्सी है जो आपको RDP प्रोटोकॉल पर मैन इन द मिडिल हमला करने की अनुमति देता है। सत्र परिदृश्य को rss फ़ाइल में रिकॉर्ड करता है जिसे rdpy-rssplayer द्वारा पुन: चलाया जा सकता है।
$ rdpy-rdpmitm.py -o आउटपुट_निर्देशिका [-l सुनने_का_पोर्ट] [-k निजी_कुंजी_फ़ाइल_पथ] [-c प्रमाणपत्र_फ़ाइल_पथ] [-r (XP या सर्वर 2003 क्लाइंट के लिए)] लक्ष्य_होस्ट[:लक्ष्य_पोर्ट]
आउटपुट निर्देशिका का उपयोग rss फ़ाइल को निम्नलिखित प्रारूप (YYYYMMDDHHMMSS_ip_index.rss) में सहेजने के लिए किया जाता है। निजी कुंजी फ़ाइल और प्रमाणपत्र फ़ाइल SSL कनेक्शन के लिए क्लासिक क्रिप्टोग्राफ़िक फ़ाइलें हैं। RDP प्रोटोकॉल अपनी स्वयं की सुरक्षा परत पर बातचीत कर सकता है। यदि दोनों पैरामीटरों में से कोई भी छोड़ दिया जाता है, तो सर्वर मानक RDP को सुरक्षा परत के रूप में उपयोग करता है।
rdpy-rdphoneypot एक RDP हनी पॉट है। RDP प्रोटोकॉल के माध्यम से परिदृश्य को फिर से चलाने के लिए रिकॉर्ड किए गए सत्र परिदृश्य का उपयोग करें।
$ rdpy-rdphoneypot.py [-l सुनने_का_पोर्ट] [-k निजी_कुंजी_फ़ाइल_पथ] [-c प्रमाणपत्र_फ़ाइल_पथ] rss_फ़ाइल_पथ_1 ... rss_फ़ाइल_पथ_N
निजी कुंजी फ़ाइल और प्रमाणपत्र फ़ाइल SSL कनेक्शन के लिए क्लासिक क्रिप्टोग्राफ़िक फ़ाइलें हैं। RDP प्रोटोकॉल अपनी स्वयं की सुरक्षा परत पर बातचीत कर सकता है। यदि दोनों पैरामीटरों में से कोई भी छोड़ दिया जाता है, तो सर्वर मानक RDP को सुरक्षा परत के रूप में उपयोग करता है। अधिक सामान्य स्क्रीन आकार से मेल खाने के लिए आप एक से अधिक फ़ाइलें निर्दिष्ट कर सकते हैं।
rdpy-rssplayer का उपयोग rdpy-rdpmitm या rdpy-rdpclient बाइनरी द्वारा उत्पन्न रिकॉर्ड सत्र परिदृश्य (rss) फ़ाइलों को पुन: चलाने के लिए किया जाता है।
$ rdpy-rssplayer.py rss_फ़ाइल_पथ
RDPY को Qt विजेट के रूप में भी उपयोग किया जा सकता है, rdpy.ui.qt4.QRemoteDesktop वर्ग के माध्यम से। इसे आपके अपने Qt अनुप्रयोग में एम्बेड किया जा सकता है। ट्विस्टेड और Qt को एक साथ काम करने के लिए आपके ऐप में qt4reactor का उपयोग किया जाना चाहिए। अधिक विवरण के लिए, rdpy-rdpclient के स्रोत देखें।
संक्षेप में, RDPY को ट्विस्टेड इंजन के साथ एक प्रोटोकॉल लाइब्रेरी के रूप में उपयोग किया जा सकता है।
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
@param destLeft: xmin position
@param destTop: ymin position
@param destRight: xmax position because RDP can send bitmap with padding
@param destBottom: ymax position because RDP can send bitmap with padding
@param width: width of bitmap
@param height: height of bitmap
@param bitsPerPixel: number of bit per pixel
@param isCompress: use RLE compression
@param data: bitmap data
"""
def onSessionReady(self):
"""
@summary: Windows session is ready
"""
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()
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
@param code: scan code of key
@param isPressed: True if key is down
@see: rdp.RDPServerObserver.onKeyEventScancode
"""
def onKeyEventUnicode(self, code, isPressed):
"""
@summary: Event call when a keyboard event is catch in unicode format
@param code: unicode of key
@param isPressed: True if key is down
@see: rdp.RDPServerObserver.onKeyEventUnicode
"""
def onPointerEvent(self, x, y, button, isPressed):
"""
@summary: Event call on mouse event
@param x: x position
@param y: y position
@param button: 1, 2, 3, 4 or 5 button
@param isPressed: True if mouse button is pressed
@see: rdp.RDPServerObserver.onPointerEvent
"""
def onClose(self):
"""
@summary: Call when human client close connection
@see: rdp.RDPServerObserver.onClose
"""
return MyObserver(controller)
from twisted.internet import reactor
reactor.listenTCP(3389, MyRDPFactory())
reactor.run()
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
@param width: width of new image
@param height: height of new image
@param x: x position of new image
@param y: y position of new image
@param pixelFormat: pixefFormat structure in rfb.message.PixelFormat
@param encoding: encoding type rfb.message.Encoding
@param data: image data in accordance with pixel format and encoding
"""
def onCutText(self, text):
"""
@summary: event when server send cut text event
@param 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()