15

I use the rdpy-rdpmitm demo of rdpy to implement a rdp proxy, but I want to check the password before connecting to target and let client re-input username and password. My code is like this; how do I implement OnReady method?

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
João Almeida
  • 4,487
  • 2
  • 19
  • 35
sundq
  • 735
  • 2
  • 9
  • 28

2 Answers2

1

try using recursion:

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)

this way it repeats until the password is correct

  • This is what I would suggest as well. You only will have to watch out when you add future function brackets, those will be repeated as well! – monamona Dec 02 '17 at 07:35
0

I don't really know the library you are using, but can't you just test for an error if the connection fails and then retry the connection by your previous code, i.e. something along the lines of:

Python 2.x

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

Python 3.x

password = input("Please re-enter your password")
IcyTv
  • 405
  • 4
  • 12