add argument for rdpclient script

This commit is contained in:
speyrefitte
2014-07-16 18:51:16 +02:00
parent e1c429b3b9
commit 36e96c1db5
4 changed files with 59 additions and 32 deletions

View File

@@ -22,8 +22,7 @@
example of use rdpy as rdp client
"""
import sys
import os
import sys, os, getopt
# Change path so we find rdpy
sys.path.insert(1, os.path.join(sys.path[0], '..'))
@@ -36,12 +35,15 @@ class RDPClientQtFactory(rdp.ClientFactory):
"""
Factory create a RDP GUI client
"""
def __init__(self, width, height):
def __init__(self, width, height, username, password, domain):
"""
init client with correct definition
"""
self._width = width
self._height = height
self._username = username
self._passwod = password
self._domain = domain
self._w = None
def buildObserver(self, controller):
@@ -59,6 +61,9 @@ class RDPClientQtFactory(rdp.ClientFactory):
#resize session
controller.setScreen(self._width, self._height)
controller.setUsername(self._username)
controller.setPassword(self._passwod)
controller.setDomain(self._domain)
controller.setPerformanceSession()
return client
@@ -86,7 +91,46 @@ class RDPClientQtFactory(rdp.ClientFactory):
reactor.stop()
app.exit()
def help():
print "Usage: rdpy-rdpclient [options] ip[:port]"
print "\t-u: user name"
print "\t-p: password"
print "\t-d: domain"
print "\t-w: width of screen default value is 1024"
print "\t-l: height of screen default value is 800"
if __name__ == '__main__':
#default script argument
username = ""
password = ""
domain = ""
width = 1024
height = 800
try:
opts, args = getopt.getopt(sys.argv[1:], "hu:p:d:w:l")
except getopt.GetoptError:
help()
for opt, arg in opts:
if opt == "-h":
help()
sys.exit()
elif opt == "-u":
username = arg
elif opt == "-p":
password = arg
elif opt == "-d":
domain = arg
elif opt == "-w":
width = int(arg)
elif opt == "-l":
height = int(arg)
if ':' in args[0]:
ip, port = args[0].split(':')
else:
ip, port = args[0], "3389"
#create application
app = QtGui.QApplication(sys.argv)
@@ -95,7 +139,7 @@ if __name__ == '__main__':
qt4reactor.install()
from twisted.internet import reactor
reactor.connectTCP(sys.argv[1], int(sys.argv[2]), RDPClientQtFactory(1024, 800))
reactor.connectTCP(ip, int(port), RDPClientQtFactory(width, height, username, password, domain))
reactor.runReturn()
app.exec_()
reactor.stop()

View File

@@ -423,7 +423,7 @@ class CompositeType(Type):
for name in self._typeName:
try:
s.readType(self.__dict__[name])
readLen += sizeof(self.__dict__[name])
#read is ok but read out of bound
if not self._readLen is None and readLen > self._readLen.value:
#roll back
@@ -440,8 +440,6 @@ class CompositeType(Type):
s.pos -= sizeof(self.__dict__[tmpName])
raise e
readLen += sizeof(self.__dict__[name])
def __write__(self, s):
"""
Call write on each ordered sub type

View File

@@ -484,7 +484,7 @@ class RDPInfo(CompositeType):
#code page
self.codePage = UInt32Le()
#support flag
self.flag = UInt32Le(InfoFlag.INFO_MOUSE | InfoFlag.INFO_UNICODE | InfoFlag.INFO_LOGONERRORS | InfoFlag.INFO_LOGONNOTIFY | InfoFlag.INFO_ENABLEWINDOWSKEY | InfoFlag.INFO_DISABLECTRLALTDEL)
self.flag = UInt32Le(InfoFlag.INFO_MOUSE | InfoFlag.INFO_UNICODE | InfoFlag.INFO_LOGONERRORS | InfoFlag.INFO_LOGONNOTIFY | InfoFlag.INFO_ENABLEWINDOWSKEY | InfoFlag.INFO_DISABLECTRLALTDEL | InfoFlag.INFO_AUTOLOGON)
self.cbDomain = UInt16Le(lambda:sizeof(self.domain) - 2)
self.cbUserName = UInt16Le(lambda:sizeof(self.userName) - 2)
self.cbPassword = UInt16Le(lambda:sizeof(self.password) - 2)
@@ -497,7 +497,7 @@ class RDPInfo(CompositeType):
#shell execute at start of session
self.alternateShell = UniString(readLen = UInt16Le(lambda:self.cbAlternateShell.value - 2))
#working directory for session
self.workingDir = UniString("toto", readLen = UInt16Le(lambda:self.cbWorkingDir.value - 2))
self.workingDir = UniString(readLen = UInt16Le(lambda:self.cbWorkingDir.value - 2))
self.extendedInfo = RDPExtendedInfo(conditional = extendedInfoConditional)
class RDPExtendedInfo(CompositeType):
@@ -629,22 +629,22 @@ class DataPDU(CompositeType):
Create object in accordance self.shareDataHeader.pduType2 value
"""
if self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_UPDATE:
return UpdateDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return UpdateDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
elif self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_SYNCHRONIZE:
return SynchronizeDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return SynchronizeDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
elif self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_CONTROL:
return ControlDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return ControlDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
elif self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_SET_ERROR_INFO_PDU:
return ErrorInfoDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return ErrorInfoDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
elif self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_FONTLIST:
return FontListDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return FontListDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
elif self.shareDataHeader.pduType2.value == PDUType2.PDUTYPE2_FONTMAP:
return FontMapDataPDU(readLen = self.shareDataHeader.uncompressedLength)
return FontMapDataPDU(readLen = self.shareDataHeader.uncompressedLength - 18)
else:
#read all value
return String()
@@ -764,7 +764,7 @@ class FastPathUpdatePDU(CompositeType):
def __init__(self, updateType = 0, updateData = None):
CompositeType.__init__(self)
self.updateHeader = UInt8(updateType)
self.compressionFlags = UInt8(conditional = lambda:(self.updateHeader.value & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED))
self.compressionFlags = UInt8(conditional = lambda:((self.updateHeader.value >> 4) & FastPathOutputCompression.FASTPATH_OUTPUT_COMPRESSION_USED))
self.size = UInt16Le()
def UpdateDataFactory():
@@ -773,10 +773,6 @@ class FastPathUpdatePDU(CompositeType):
"""
if (self.updateHeader.value & 0xf) == FastPathUpdateType.FASTPATH_UPDATETYPE_BITMAP:
return (UInt16Le(FastPathUpdateType.FASTPATH_UPDATETYPE_BITMAP, constant = True), BitmapUpdateDataPDU(readLen = self.size))
elif (self.updateHeader.value & 0xf) == FastPathUpdateType.FASTPATH_UPDATETYPE_SYNCHRONIZE:
return SynchronizeUpdatePDU(readLen = self.size)
else:
return String()
@@ -784,17 +780,6 @@ class FastPathUpdatePDU(CompositeType):
updateData = FactoryType(UpdateDataFactory)
self.updateData = updateData
class SynchronizeUpdatePDU(CompositeType):
"""
PDU is ignored, artefact of T.125
"""
def __init__(self, readLen = None):
"""
@param readLen: Max size of packet
"""
CompositeType.__init__(self, readLen = readLen)
self.pad2Octets = UInt16Le()
class BitmapUpdateDataPDU(CompositeType):
"""

View File

@@ -87,7 +87,7 @@ class TPDUDataHeader(CompositeType):
"""
def __init__(self):
CompositeType.__init__(self)
self.header = UInt8(2, constant = True)
self.header = UInt8(2)
self.messageType = UInt8(MessageType.X224_TPDU_DATA, constant = True)
self.separator = UInt8(0x80, constant = True)