text: from besspin.base.utils.misc import *
  import re, logging
  
  poc_dictionaryAttack_rootPassword = "Besspin"
  poc_dictionaryAttack_usePamTally = False
  
  def dictionaryAttack (target):
      timeout = 10
      
      outLog = ''
      shTest = "dictionaryAttack.sh"
      pocRootPassword = poc_dictionaryAttack_rootPassword
      pocUsePamTally = poc_dictionaryAttack_usePamTally
  
      printAndReport (">> Adjusting Root password -legally- to \"{0}\".".format(pocRootPassword))
      target.switchUser()
      if (pocUsePamTally):
          outLog += target.runCommand("sed -i \'15iauth    required    pam_tally2.so    deny=3    even_deny_root    debug\' /etc/pam.d/common-auth",timeout=timeout)[1]
      outLog += target.runCommand ("passwd",endsWith="New password:",timeout=timeout)[1]
      outLog += target.runCommand (pocRootPassword,endsWith="Retype new password:",timeout=timeout)[1]
      outLog += target.runCommand (pocRootPassword,expectedContents="password updated successfully",timeout=timeout)[1]
      target.rootPassword = pocRootPassword
      printAndReport (">> Root password updated successfully!")
      target.switchUser()
  
      printAndReport (">> Logged in as <{0}>.".format(target.userName))
  
      retCommand = target.runCommand("./{0}".format(shTest),endsWith="Password:",expectedContents=">> Trying",erroneousContents=">>>>>End",timeout=timeout)
      outLog += retCommand[1]
      isBreached = False
      while (retCommand[0] and (not retCommand[2])): #while no-timeout and no-error
          tryThisPlanet = None
          for line in retCommand[1].splitlines():
              planetMatch = re.match(r'^>> Trying <(?P<planet>\w+)>...$',line)
              if (planetMatch is not None):
                  tryThisPlanet = planetMatch.group('planet')
          if (tryThisPlanet is None):
              outLog += target.runCommand ("\x03",timeout=timeout)[1]
              break
          retCommand = target.runCommand(tryThisPlanet,endsWith=["Password:", '#'],expectedContents=">> Trying",erroneousContents=">>>>>End",exitOnError=False,suppressErrors=True,timeout=timeout)
          if (retCommand[3] == 1): #This would also imply that retCommand[0] is false and thus breaking the loop
              isBreached = True 
          outLog += retCommand[1]
  
      if (">>>>>End" in retCommand[1]):
          printAndReport ("{0}: <dictionaryAttack> ended without breach!".format(target.filename))
          return outLog
  
      #retCommand = target.runCommand ("\x03",endsWith="#",shutdownOnError=False,timeout=timeout)
      #outLog += retCommand[1]
      #if ( (not retCommand[0]) or retCommand[2] ): #failed
      if (not isBreached):
          printAndReport ("{0}: <dictionaryAttack> terminated without breach!".format(target.filename))
          return outLog
  
      outLog += target.runCommand ("echo \">> BREACHED! Executing this on a root shell!\"",endsWith='#',timeout=timeout)[1]
      outLog += target.runCommand ("exit",timeout=timeout)[1]
  
      return outLog