Repository navigation
Expand file tree
/
Copy pathheadless.py
More file actions
136 lines (117 loc) · 5.01 KB
/
Copy pathheadless.py
File metadata and controls
136 lines (117 loc) · 5.01 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import argparse
from urllib import request, error
from colorama import Fore
# read user's arguments
parser = argparse.ArgumentParser()
parser.add_argument("-u" , "--url" , type = str , help = "Input host's url")
parser.add_argument("-i" , "--invisible" , action = 'store_true' , help = "Invisible mode. No logo. For the best POC <3")
parser.add_argument("-c" , "--check" , action = 'store_true' , help = "Simple security headers check")
parser.add_argument("-f" , "--full" , action = 'store_true' , help = "Security headers check with full value")
parser.add_argument("-a" , "--all_headers" , action = 'store_true' , help = "Show all headers")
parser.add_argument("-d" , "--disable_redirects" , action = 'store_true' , help = "Disable redirects")
parser.add_argument("-x" , "--cors_check" , action = 'store_true' , help = "Cross origin resource sharing check with full value")
args = parser.parse_args()
# invisible mode
if args.invisible == False:
print('''
)
( /( ( (
)\()) ( ) )\ ) )\ (
((_)\ ))\ ( /( (()/(((_) ))\ ( (
_((_) /((_))(_)) ((_))_ /((_))\ )\
| || |(_)) ((_)_ _| || |(_)) ((_)((_)
| __ |/ -_)/ _` |/ _` || |/ -_)(_-<(_-<
|_||_|\___|\__,_|\__,_||_|\___|/__//__/ v1.0
Security headers testing tool
''')
# security headers list
security_headers = ["X-Frame-Options" , "Strict-Transport-Security" ,
"Permissions-Policy" ,"Content-Security-Policy" ,
"X-Content-Type-Options" , "Referrer-Policy"]
# CORS headers list
cors_headers = ["Access-Control-Allow-Origin" , "Access-Control-Allow-Credentials" ,
"Access-Control-Allow-Headers" , "Access-Control-Allow-Methods" ,
"Access-Control-Expose-Headers" , "Access-Control-Max-Age" ,
"Access-Control-Request-Headers" , "Access-Control-Request-Method" ,
"Origin"]
class main:
# fix input URL
def to_http():
if args.url == None:
print(Fore.RED + 'no URL found.' + Fore.RESET)
exit()
if not args.url.startswith('http://') and not args.url.startswith('https://'):
args.url = 'http://' + args.url
print('Connecting to ' + Fore.BLUE + args.url + Fore.RESET)
# output security headers and values
def list_headers():
print('''
Status of security headers -''')
for header in security_headers:
if request.headers[header] == None:
print(Fore.RED + header + Fore.RESET + ': ' + 'EMPTY')
else:
print(Fore.GREEN + header + Fore.RESET + ': ' + 'ok')
# output all headers
def all_headers():
print('''
All headers -''')
print(request.headers)
# output full values of security headers
def security_headers_full():
print('''
Value of security headers -''')
for header in security_headers:
if request.headers[header] == None:
print(Fore.RED + header + Fore.RESET + ': ' + 'EMPTY')
else:
print(Fore.GREEN + header + Fore.RESET + ': ' + request.headers[header])
# output CORS headers
def cors_headers():
print('''
Value of CORS headers -''')
for cors_header in cors_headers:
if request.headers[cors_header] == None:
print(Fore.RED + cors_header + Fore.RESET + ': ' + 'EMPTY')
else:
print(Fore.GREEN + cors_header + Fore.RESET + ': ' + request.headers[cors_header])
# disable redirects
class NoRedirect(request.HTTPRedirectHandler):
def redirect_request(self, req, fp, code, msg, headers, newurl):
return None
# get target
main.to_http()
# get response from target
if args.disable_redirects == True:
print('Redirection disabled')
opener = request.build_opener(NoRedirect)
request.install_opener(opener)
try:
request = request.urlopen(args.url)
except error.HTTPError as e:
request = e
except error.URLError as e:
print(Fore.RED + 'connection error.' + Fore.RESET)
exit()
print('Response code: ' + str(request.getcode()))
else:
try:
request = request.urlopen(args.url)
except error.HTTPError as e:
request = e
except error.URLError as e:
print(Fore.RED + 'connection error.' + Fore.RESET)
exit()
print('Redirected to ' + Fore.BLUE + request.geturl() + Fore.RESET)
print('Response code: ' + str(request.getcode()))
# show all headers
if args.all_headers == True:
main.all_headers()
# show security headers
if args.check == True and args.full != True:
main.list_headers()
# show full values of security headers
if args.full == True:
main.security_headers_full()
if args.cors_check == True:
main.cors_headers()