2015-11-04 124 views
16

我使用rdpy-rdpmitm演示版rdpy來實現rdp代理服務器,但我想在連接到目標服務器之前檢查密碼並讓客戶端重新啓動輸入用戶名和密碼。我的代碼是這樣的;我如何實施OnReady方法?我如何讓rdpy-rdpmitm讓客戶端在密碼不正確時重新輸入用戶名和密碼

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 
+0

請問你的代碼已經是你的類中,還是可以在外面? –

回答

0

我真的不知道你正在使用的庫,但你不能只測試一個錯誤,如果連接失敗,然後重試由以前的代碼的東西沿着線的連接,即:

的Python 2.x的

password = raw_input("Please re-enter your password:") 

Python 3.x都有

password = input("Please re-enter your password") 
1

嘗試使用遞歸:

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) 

這種方式重複,直到密碼正確

+0

這是我會建議以及。您只需要注意何時添加未來的功能支架,這些內容也會重複使用! – monamona

相關問題