-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp-insecure-headers.py
executable file
·82 lines (65 loc) · 2.09 KB
/
http-insecure-headers.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pylint: disable=C0103
# pylint: disable=C0413
# pylint: disable=W0702
'''
Script that that checks for if web server is configured with insecure headers.
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
'''
HEADERS = {
'X-XSS-Protection': '1; mode=block',
'X-Content-Type-Options': 'nosniff',
'Strict-Transport-Security': False
}
import calendar
import os
import sys
import time
import requests
if len(sys.argv) != 2:
print 'Usage: ' + sys.argv[0] + ' [filename]'
print " * filename - File that contains list of urls.\n"
sys.exit(1)
URLS_FILE = sys.argv[1]
if not os.path.isfile(URLS_FILE):
print 'Error: file ' + '"' + URLS_FILE + '"' + " doesn't exist.\n"
sys.exit(1)
URLS = list()
RESULT_FILE = 'http-insecure-headers-' + 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
try:
response = requests.get(url, timeout=3)
except KeyboardInterrupt:
sys.exit(0)
except:
response = None
if response:
for key, value in HEADERS.iteritems():
found = None
try:
header = response.headers[key]
if header != value:
found = url + ',' + key + ',' + header
except KeyError:
if value == False:
found = url + ',' + key + ',[NOT SET]'
except:
pass
if bool(found):
with open(RESULT_FILE, 'a+') as result_file:
result_file.write(url + ',' + found + "\n")