Python 当密码不正确时,如何使rdpy rdpmitm允许客户端重新输入用户名和密码
我使用Python 当密码不正确时,如何使rdpy rdpmitm允许客户端重新输入用户名和密码,python,rdp,Python,Rdp,我使用rdpy-rdpmitm的rdpy演示来实现一个rdp代理,但是我想在连接到目标之前检查密码,让客户端重新输入用户名和密码。我的代码是这样的;如何实现OnReady方法 class ProxyServer(rdp.RDPServerObserver): def __init__(self, controller, target, clientSecurityLevel, rssRecorder): """ @param controller: {RDPServerCon
rdpy-rdpmitm
的rdpy
演示来实现一个rdp代理,但是我想在连接到目标之前检查密码,让客户端重新输入用户名和密码。我的代码是这样的;如何实现OnReady
方法
class ProxyServer(rdp.RDPServerObserver):
def __init__(self, controller, target, clientSecurityLevel, rssRecorder):
"""
@param controller: {RDPServerController}
@param target: {tuple(ip, port)}
@param rssRecorder: {rss.FileRecorder} use to record session
"""
rdp.RDPServerObserver.__init__(self, controller)
self._target = target
self._client = None
self._rss = rssRecorder
self._clientSecurityLevel = clientSecurityLevel
def onReady(self):
"""
@summary: Event use to inform state of server stack
First time this event is called is when human client is connected
Second time is after color depth nego, because color depth nego
restart a connection sequence
@see: rdp.RDPServerObserver.onReady
"""
if self._client is None:
# try a connection
domain, username, password = self._controller.getCredentials()
self._rss.credentials(username, password, domain, self._controller.getHostname())
width, height = self._controller.getScreen()
self._rss.screen(width, height, self._controller.getColorDepth())
if checkPassword(username, password): #password ok
reactor.connectTCP('127.0.0.1', 3389, ProxyClientFactory(self, width, height, domain, username, password,self._clientSecurityLevel))
else:
pass
#how to make client re-input username and password in this place
我真的不知道您正在使用的库,但是如果连接失败,您是否可以只测试一个错误,然后用您以前的代码重试连接,例如,以下代码: python2.x
password = raw_input("Please re-enter your password:")
password = input("Please re-enter your password")
Python3.x
password = raw_input("Please re-enter your password:")
password = input("Please re-enter your password")
尝试使用递归:
class ProxyServer(rdp.RDPServerObserver):
def __init__(self, controller, target, clientSecurityLevel, rssRecorder):
"""
@param controller: {RDPServerController}
@param target: {tuple(ip, port)}
@param rssRecorder: {rss.FileRecorder} use to record session
"""
rdp.RDPServerObserver.__init__(self, controller)
self._target = target
self._client = None
self._rss = rssRecorder
self._clientSecurityLevel = clientSecurityLevel
def onReady(self):
"""
@summary: Event use to inform state of server stack
First time this event is called is when human client is connected
Second time is after color depth nego, because color depth nego
restart a connection sequence
@see: rdp.RDPServerObserver.onReady
"""
if self._client is None:
# try a connection
domain, username, password = self._controller.getCredentials()
self._rss.credentials(username, password, domain, self._controller.getHostname())
width, height = self._controller.getScreen()
self._rss.screen(width, height, self._controller.getColorDepth())
if checkPassword(username, password): #password ok
reactor.connectTCP('127.0.0.1', 3389, ProxyClientFactory(self, width, height, domain, username, password,self._clientSecurityLevel))
else:
onReady(self)
这样它会重复,直到密码正确为止您的代码必须在类内,还是在类外?这也是我的建议。您只需在添加将来的函数括号时小心,这些括号也会重复!