Created
September 28, 2022 20:19
-
-
Save davidfischer/67f66d5dd6111b941f2a2244c1a3ec7e to your computer and use it in GitHub Desktop.
Parses a .har file (a recording from the browser's developer console) and outputs the unique domains where a request is made and what that domain resolves to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
import json | |
import subprocess | |
from haralyzer import HarParser, HarPage | |
def get_dns_response(domain): | |
output = subprocess.check_output(["dig", "+short", domain], text=True) | |
return [l.strip() for l in output.split("\n") if len(l.strip()) > 0] | |
def analyze_har(harfile): | |
print(harfile.name) | |
print("=" * 77) | |
unique_hosts = set() | |
har = HarParser(json.loads(harfile.read())) | |
for page in har.pages: | |
print(f"URL: {page.url}") | |
print(f"Hostname: {page.hostname}") | |
for entry in page.entries: | |
unique_hosts.add(entry.request.host) | |
print() | |
print("Unique request hosts") | |
print("--------------------") | |
for hostname in unique_hosts: | |
print(f" - {hostname}") | |
resolves_to = get_dns_response(hostname) | |
print(" =>", ", ".join(resolves_to)) | |
print("\n") | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='Parse a .har file looking for unique request domains and CNAME cloaking.') | |
parser.add_argument('harfiles', nargs='+', metavar="HARFILE", type=argparse.FileType('r')) | |
args = parser.parse_args() | |
for harfile in args.harfiles: | |
analyze_har(harfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment