-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_methods_checker.py
More file actions
45 lines (36 loc) · 1.42 KB
/
Copy pathhttp_methods_checker.py
File metadata and controls
45 lines (36 loc) · 1.42 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
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
import requests
import argparse
from urllib.parse import urlparse
from suggestions import print_suggestions
requests.packages.urllib3.disable_warnings()
def check_http_methods(url):
"""Check allowed HTTP methods."""
print(f"[*] Checking HTTP methods on {url}")
methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'TRACE', 'CONNECT']
allowed = []
try:
for method in methods:
try:
r = requests.request(method, url, timeout=3)
if r.status_code != 405: # 405 Method Not Allowed
allowed.append(method)
print(f"[+] {method}: Allowed (Status: {r.status_code})")
except Exception:
pass
if 'PUT' in allowed or 'DELETE' in allowed or 'TRACE' in allowed:
finding = "VULNERABILITY: Dangerous HTTP methods allowed"
print(f"[-] {finding}")
print_suggestions(finding)
except Exception as e:
print(f"Error: {e}")
def main():
parser = argparse.ArgumentParser(description="Check allowed HTTP methods.")
parser.add_argument("url", help="Target URL or domain (e.g., example.com)")
args = parser.parse_args()
target = args.url if '://' in args.url else 'http://' + args.url
check_http_methods(target)
if __name__ == "__main__":
main()