-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
96 lines (78 loc) · 2.23 KB
/
main.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
96
## Filename: main.py
# Author: Marcelo Feitoza Parisi
#
# Description: Main component
# of authelia-squid-helper tool.
#
# ###########################
# # DISCLAIMER - IMPORTANT! #
# ###########################
#
# Stuff found here was built as a
# Proof-Of-Concept or Study material
# and should not be considered
# production ready!
#
# USE WITH CARE!
##
import sys
from helpers import first_factor
from helpers import second_factor
from helpers import globalholders
from helpers import config_authentication
def main():
# Checking if config file was provided
if(len(sys.argv) != 2):
print("No config file provided")
sys.exit()
else:
globalholders.config_file = sys.argv[1]
# Loading Authentication Config
authentication = config_authentication.getConfig();
# Expects stdin forever
while True:
# Read stdin
input_buffer = input("")
buffer_split = input_buffer.split()
# Two-Factor Authentication
if(authentication["two_factor"] == True):
# Parsing username/password+appended-token
first_req = {
"username": buffer_split[0],
"password": buffer_split[1][0:-6],
"targetURL": authentication["target_url"],
"keepMeLoggedIn": authentication["keep_logged_in"]
}
# Perform password check
first_response = first_factor.authenticate(first_req)
# Password check passed
if(first_response["status"] == 200):
# Parsing Appended TOKEN
second_req = {
"token": buffer_split[1][-6:],
"targetURL": authentication["target_url"],
"cookie": first_response["cookie"]
}
# Perform token check
second_response = second_factor.authenticate(second_req)
# Return message to stdout
print(second_response["message"])
# Failed password check
else:
# Return message to stdout
print(first_response["message"])
# One-Factor Authentication
else:
# Parsing username/password
first_req = {
"username": buffer_split[0],
"password": buffer_split[1],
"targetURL": authentication["target_url"],
"keepMeLoggedIn": authentication["keep_logged_in"]
}
# Performing password check
first_response = first_factor.authenticate(first_req)
# Return message to stdout
print(first_response["message"])
if __name__ == '__main__':
main()