forked from Te-k/analyst-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_test_methods.py
executable file
·62 lines (48 loc) · 1.88 KB
/
http_test_methods.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
#! /usr/bin/env python2
import argparse
import os
import socket
from urlparse import urlparse
import re
import httplib
def send_request(method, host, path):
conn = httplib.HTTPConnection(host)
conn.request(method, path)
return conn.getresponse()
def print_response(res):
print "HTTP/1.1 %i %s" % (res.status, res.reason)
for header in res.getheaders():
print "%s: %s" % (header[0].capitalize(), header[1])
print ""
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Identify the options supported by the web server')
parser.add_argument('-t', '--test', help='Tests all the methods', action='store_true')
parser.add_argument('-v', '--verbose', help='verbose mode', action="count", default=0)
parser.add_argument('host', metavar='HOST', help='Host targeted')
args = parser.parse_args()
# valid the host
hosturl = urlparse(args.host)
if hosturl.netloc == '':
host = hosturl.path
else:
host = hosturl.netloc
if args.test:
print "Testing all HTTP methods"
for method in ["GET", "OPTIONS", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT"]:
res =send_request(method, host, "/")
if args.verbose > 0:
print "%s /" % method
print_response(res)
#print "%s : %i %s" % (method, res.status, res.reason)
#print "%s\n" % repr(res.getheaders())
else:
if res.status == 404 or res.status == 400 or res.status == 405:
print "%s: BLOCKED" % method
else:
print "%s: AUTHORIZED" % method
else:
res = send_request("OPTIONS", host, "/")
if res.getheader('allow'):
print "Methods allowed: %s" % res.getheader('allow')
else:
print "No response from the server to OPTIONS method"