-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobots_txt.py
More file actions
76 lines (64 loc) · 2.73 KB
/
Copy pathrobots_txt.py
File metadata and controls
76 lines (64 loc) · 2.73 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
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore')
import argparse
import requests
from urllib.parse import urlparse
from suggestions import print_suggestions
requests.packages.urllib3.disable_warnings()
SUSPICIOUS_KEYWORDS = ['admin', 'wp-', '.git', '.env', 'backup', 'config', 'db', 'login', 'private', 'staging', 'test']
def analyze_robots(url):
parsed = urlparse(url if '://' in url else 'http://' + url)
robots_url = f"{parsed.scheme}://{parsed.netloc}/robots.txt"
try:
r = requests.get(robots_url, timeout=8)
if r.status_code != 200 or not r.text.strip():
print(f"[-] robots.txt not found at {robots_url}")
return
print(f"[*] Found robots.txt at {robots_url}")
lines = [line.strip() for line in r.text.splitlines() if line.strip() and not line.strip().startswith('#')]
disallows = []
allows = []
sitemaps = []
for line in lines:
lower = line.lower()
if lower.startswith('disallow:'):
path = line.split(':',1)[1].strip()
disallows.append(path)
elif lower.startswith('allow:'):
path = line.split(':',1)[1].strip()
allows.append(path)
elif lower.startswith('sitemap:'):
sm = line.split(':',1)[1].strip()
sitemaps.append(sm)
if sitemaps:
print("[+] robots.txt Sitemap entries:")
for s in sitemaps:
print(f" - {s}")
if disallows:
print(f"[+] robots.txt Disallow entries ({len(disallows)}):")
for p in disallows:
print(f" - {p}")
suspicious = [p for p in disallows if any(k in p.lower() for k in SUSPICIOUS_KEYWORDS)]
if suspicious:
finding = "robots.txt contains disallowed paths that may expose sensitive endpoints"
print(f"[!] {finding}:")
for s in suspicious:
print(f" - {s}")
print_suggestions(finding)
else:
print("[+] robots.txt present but no Disallow entries found.")
if allows:
print(f"[+] robots.txt Allow entries ({len(allows)}):")
for p in allows:
print(f" - {p}")
except requests.RequestException as e:
print(f"[-] Could not fetch robots.txt ({robots_url}): {e}")
def main():
import sys
parser = argparse.ArgumentParser(description="Fetch and analyze robots.txt for a target domain or URL.")
parser.add_argument("target", help="Target URL or domain (e.g., example.com or https://example.com)")
args = parser.parse_args()
analyze_robots(args.target)
if __name__ == "__main__":
main()