From 6edfd7d3410477aaf69059ad2c1a090c8327e069 Mon Sep 17 00:00:00 2001 From: 3c7 Date: Wed, 12 Jul 2023 22:29:12 +0200 Subject: [PATCH] Added `hash_from_banner` --- hhhash/__init__.py | 2 +- hhhash/create.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hhhash/__init__.py b/hhhash/__init__.py index 685d7a6..f08de11 100644 --- a/hhhash/__init__.py +++ b/hhhash/__init__.py @@ -1 +1 @@ -from hhhash.create import buildhash +from hhhash.create import buildhash, hash_from_banner diff --git a/hhhash/create.py b/hhhash/create.py index 3e06899..faf5af8 100644 --- a/hhhash/create.py +++ b/hhhash/create.py @@ -15,3 +15,39 @@ def buildhash(url=None, debug=False): m.update(hhhash[1:].encode()) digest = m.hexdigest() return f"hhh:1:{digest}" + +def hash_from_banner(banner, debug=False): + """This allows the creation of hhhash without a request, if the banner string is already available + + Example: + >>> hash_from_banner('''HTTP/1.1 200 OK + ... Content-Type: text/html; charset=ISO-8859-1 + ... Content-Security-Policy-Report-Only: object-src 'none';base-uri 'self';script-src 'nonce-iV-j91UJEG2jNx4j6EeTug' 'strict-dynamic' 'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp + ... P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info." + ... Date: Wed, 12 Jul 2023 20:23:42 GMT + ... Server: gws + ... X-XSS-Protection: 0 + ... X-Frame-Options: SAMEORIGIN + ... Transfer-Encoding: chunked + ... Expires: Wed, 12 Jul 2023 20:23:42 GMT + ... Cache-Control: private + ... Set-Cookie: + ... Set-Cookie: + ... Set-Cookie: + ... Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000''') + hhh:1:d9576f3e7a381562f7d18a514ab095fa8699e96891d346d0042f83e942373215 + """ + hhhash = "" + for line in banner.splitlines(): + if line[:4] == "HTTP": + continue + key = line + if ":" in key: + key, _ = line.split(":", maxsplit=1) + hhhash = f"{hhhash}:{key.strip()}" + if debug: + print(hhhash[1:]) + m = hashlib.sha256() + m.update(hhhash[1:].encode()) + digest = m.hexdigest() + return f"hhh:1:{digest}"