|
| 1 | +""" |
| 2 | +Utility script to verify that every site mentioned in the tab named "Case Studies" have a mention to OSHP. |
| 3 | +
|
| 4 | +The goal is to allow detection of site not mentioning the OSHP anymore and then update the "Case Studies" content. |
| 5 | +
|
| 6 | +Try to not use any external dependency to stay the more portable possible. |
| 7 | +""" |
| 8 | +import re |
| 9 | +import urllib.request |
| 10 | + |
| 11 | +OSHP_MARKER_STRINGS = ["owasp secure headers project", "https://owasp.org/www-project-secure-headers", "https://www.owasp.org/index.php/security_headers", "secure headers project"] |
| 12 | +DEFAULT_ENCODING = "utf-8" |
| 13 | +IGNORED_HTTP_RESPONSE_CODES = [401] |
| 14 | +SOURCE_MD_FILE = "../tab_casestudies.md" |
| 15 | +USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" |
| 16 | + |
| 17 | + |
| 18 | +def verify_mention(site_url): |
| 19 | + oshp_is_mentioned = "NO" |
| 20 | + request = urllib.request.Request(url=site_url, method="GET") |
| 21 | + request.add_header("User-Agent", USER_AGENT) |
| 22 | + request.add_header("Accept", "*/*") |
| 23 | + request.add_header("Accept-Encoding", "deflate") |
| 24 | + try: |
| 25 | + # Assume by default that site refer to static non SPA page |
| 26 | + with urllib.request.urlopen(request) as f: |
| 27 | + content = f.read().decode(DEFAULT_ENCODING) |
| 28 | + content_lower = content.lower() |
| 29 | + for marker in OSHP_MARKER_STRINGS: |
| 30 | + if marker in content_lower: |
| 31 | + oshp_is_mentioned = "YES" |
| 32 | + break |
| 33 | + # If mention is not detected then try to check if it's an SPA |
| 34 | + if oshp_is_mentioned == "NO": |
| 35 | + expr = r'app\.[a-f0-9]+\.js' |
| 36 | + bundles = re.findall(expr, content) |
| 37 | + if len(bundles) > 0 or "React" in content: |
| 38 | + oshp_is_mentioned = "NO => SPA" |
| 39 | + except urllib.error.HTTPError as e: |
| 40 | + if e.code in IGNORED_HTTP_RESPONSE_CODES: |
| 41 | + oshp_is_mentioned = f"HTTP {e.code}" |
| 42 | + return oshp_is_mentioned |
| 43 | + |
| 44 | + |
| 45 | +def extract_site_urls(): |
| 46 | + expr = r'\*\s+\[[a-zA-Z0-9\s_\-\.]+\]\((.*?)\)' |
| 47 | + with open(SOURCE_MD_FILE, mode="r", encoding=DEFAULT_ENCODING) as f: |
| 48 | + content = f.read() |
| 49 | + return re.findall(expr, content) |
| 50 | + |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + verify_mention("https://eoahgl4pezvrojk.m.pipedream.net/") |
| 54 | + print("[+] Extract site urls...") |
| 55 | + site_urls = extract_site_urls() |
| 56 | + print(f"{len(site_urls)} urls founds.") |
| 57 | + print("[+] Verify mention to OSHP on each site...") |
| 58 | + lines = [] |
| 59 | + for site_url in site_urls: |
| 60 | + if site_url.strip().startswith("http"): |
| 61 | + oshp_is_mentioned = verify_mention(site_url) |
| 62 | + lines.append(f"[{str(oshp_is_mentioned):<9}] {site_url}") |
| 63 | + lines.sort() |
| 64 | + print("\n".join(lines)) |
0 commit comments