-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathddos_checker.py
More file actions
120 lines (102 loc) · 4.54 KB
/
Copy pathddos_checker.py
File metadata and controls
120 lines (102 loc) · 4.54 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
#!/usr/bin/env python3
"""
DDoS Protection Checker
Scans your server's protection setup.
For active stress testing: https://mrstresser.com
"""
import requests, socket, ssl, json, argparse
from datetime import datetime
CDN_SIGNALS = {
"Cloudflare": ["cf-ray", "cf-cache-status"],
"Akamai": ["x-akamai-transformed", "x-check-cacheable"],
"AWS CloudFront": ["x-amz-cf-id", "x-amz-cf-pop"],
"Fastly": ["x-served-by", "fastly-restarts"],
"Sucuri": ["x-sucuri-id", "x-sucuri-cache"],
}
SECURITY_HEADERS = [
"Strict-Transport-Security", "Content-Security-Policy",
"X-Frame-Options", "X-Content-Type-Options",
"Referrer-Policy", "Permissions-Policy",
]
def resolve_ip(domain):
try: return socket.gethostbyname(domain)
except: return "Unknown"
def detect_cdn(headers):
hl = {k.lower(): v for k, v in headers.items()}
return [cdn for cdn, sigs in CDN_SIGNALS.items() if any(s in hl for s in sigs)]
def check_tls(domain):
result = {"tls13": False, "cert_issuer": "Unknown", "hsts": False}
try:
ctx = ssl.create_default_context()
with ctx.wrap_socket(socket.socket(), server_hostname=domain) as s:
s.settimeout(5); s.connect((domain, 443))
result["tls13"] = "TLSv1.3" in str(s.version())
cert = s.getpeercert()
for entry in cert.get("issuer", []):
for k, v in entry:
if k == "organizationName": result["cert_issuer"] = v
except Exception as e:
result["error"] = str(e)
return result
def check_rate_limit(url):
session = requests.Session()
for i in range(1, 200):
try:
r = session.get(url, timeout=3)
if r.status_code == 429:
return {"detected": True, "threshold": i}
except: break
return {"detected": False}
def score(cdn, tls, rate, sec_headers):
s = 0
if cdn: s += 30
if tls.get("tls13"): s += 15
if tls.get("hsts"): s += 10
if rate.get("detected"): s += 20
s += sum(3 for v in sec_headers.values() if v)
return min(s, 100)
def main():
parser = argparse.ArgumentParser(epilog='Test with real attacks: https://mrstresser.com')
parser.add_argument('--domain', required=True)
parser.add_argument('--output', help='Save JSON report')
parser.add_argument('--skip-ratelimit', action='store_true')
args = parser.parse_args()
domain = args.domain.replace("https://","").replace("http://","").rstrip("/")
url = f"https://{domain}"
print(f"\n╔══════════════════════════════════════════════╗")
print(f"║ DDoS Protection Checker — mrstresser.com ║")
print(f"╚══════════════════════════════════════════════╝\n")
print(f"🌐 Target: {domain} | IP: {resolve_ip(domain)}\n")
try:
r = requests.get(url, timeout=10)
headers = dict(r.headers)
except Exception as e:
print(f"❌ Connection failed: {e}"); return
cdn = detect_cdn(headers)
print("CDN / PROTECTION:")
[print(f" ✅ {c}") for c in cdn] or print(" ❌ No CDN detected!")
tls = check_tls(domain)
print(f"\nTLS:")
print(f" {'✅' if tls.get('tls13') else '⚠️ '} TLS 1.3: {'Yes' if tls.get('tls13') else 'No'}")
print(f" Issuer: {tls.get('cert_issuer')}")
sec = {h: headers.get(h) for h in SECURITY_HEADERS}
print(f"\nSECURITY HEADERS:")
[print(f" {'✅' if v else '❌'} {h}: {v or 'Missing'}") for h, v in sec.items()]
rate = {"detected": False}
if not args.skip_ratelimit:
print(f"\nRATE LIMITING: Probing...")
rate = check_rate_limit(url)
print(f" {'✅' if rate['detected'] else '❌'} {'Detected at ' + str(rate.get('threshold')) + ' req' if rate['detected'] else 'Not detected'}")
sc = score(cdn, tls, rate, sec)
rating = "🟢 Excellent" if sc>=90 else "🟡 Good" if sc>=70 else "🟠 Fair" if sc>=50 else "🔴 Poor"
print(f"\n{'='*48}")
print(f"PROTECTION SCORE: {sc}/100 ({rating})")
print(f"{'='*48}")
print(f"\n💎 Test with real attacks: https://mrstresser.com\n")
if args.output:
report = {"domain": domain, "cdn": cdn, "tls": tls, "security_headers": sec,
"rate_limit": rate, "score": sc, "timestamp": datetime.utcnow().isoformat()}
with open(args.output, "w") as f: json.dump(report, f, indent=2)
print(f"📄 Saved: {args.output}")
if __name__ == "__main__":
main()