Skip to content
Snippets Groups Projects
Commit e5f9f2d2 authored by Thibault Debatty's avatar Thibault Debatty
Browse files

validate URL and show HTTP errors

parent a687eceb
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,10 @@ authors = [
description = "HTTP login cracker"
readme = "README.md"
requires-python = ">=3.7"
dependencies = [
'validators'
]
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
......
......@@ -8,6 +8,8 @@ import urllib.request
import concurrent.futures
from threading import Lock
import os
import math
import validators
# print lock
......@@ -17,6 +19,10 @@ LOCK = Lock()
ARGS = None
FOUND = []
def print_safe(string) :
with LOCK:
print(string)
def show_version() :
# where is this file located
dirname = os.path.dirname(__file__)
......@@ -52,14 +58,22 @@ def try_password(password) :
}
encoded_data = urllib.parse.urlencode(data).encode('ascii')
req = urllib.request.Request(ARGS.url, encoded_data)
with urllib.request.urlopen(req) as response:
request = urllib.request.Request(ARGS.url, encoded_data)
try:
response = urllib.request.urlopen(request)
page = response.read().decode()
if not ARGS.failed in page :
FOUND.append(password)
except urllib.error.HTTPError as e:
print_safe("Error: " + repr(e))
except urllib.error.URLError as e:
print_safe("Error: " + repr(e))
def try_passwords(passwords):
'''
Try a list of passwords
......@@ -67,8 +81,7 @@ def try_passwords(passwords):
for password in passwords :
password = password.strip()
with LOCK:
print("login: " + ARGS.login + " password: " + password)
print_safe("login: " + ARGS.login + " password: " + password)
try_password(password)
def islice(iterable, *args):
......@@ -142,10 +155,22 @@ def main():
show_header()
parse_arguments()
if not validators.url(ARGS.url) :
print("URL " + ARGS.url + "is not valid!")
sys.exit(-1)
with open(ARGS.passwords, "r") as passwords_file:
passwords = passwords_file.readlines()
print('Starting: ' + str(ARGS.threads) + ' threads, ' + str(len(passwords)) + ' passwords')
# passwords-per-thread
ppt = math.ceil(float(len(passwords)) / ARGS.threads)
print('URL: ' + ARGS.url)
print('Login: ' + ARGS.login)
print('Trying: ' + str(len(passwords)) + ' passwords with ' + str(ARGS.threads) + ' threads'
+ ' [' + str(ppt) + ' passwords per thread]')
print('')
# https://stackoverflow.com/a/15143994
executor = concurrent.futures.ThreadPoolExecutor(ARGS.threads)
......@@ -157,9 +182,9 @@ def main():
concurrent.futures.wait(futures)
except KeyboardInterrupt:
# User interrupt the program with ctrl+c
print("Stopping threads...")
executor.shutdown(wait=True, cancel_futures=True)
sys.exit(-1)
print_safe("Stopping threads...")
executor.shutdown(wait=False, cancel_futures=True)
sys.exit()
print("Done!")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment