Skip to content

Commit

Permalink
Feature: '-f' parameter without "TERM" shows the Top 20.
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc-st committed Jul 9, 2023
1 parent 019a22d commit 241139e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ HTTP Headers Analyzer<br />
:heavy_check_mark: The analysis includes dozens of references, official documentation and technical articles.<br />
:heavy_check_mark: i10n: analysis results in English or Spanish.<br />
:heavy_check_mark: Saves each analysis, showing (at the end) the improvements or deficiencies in relation to the last one.<br />
:heavy_check_mark: Shows statistics: either for all scans performed against all URLs or for a specific URL.<br />
:heavy_check_mark: Shows analysis statistics: either against a specific URL or all of them.<br />
:heavy_check_mark: Shows fingerprint statistics: either against a specific term or the Top 20.<br />
:heavy_check_mark: Code reviewed via <a href="https://pypi.org/project/pycodestyle/" target="_blank">pycodestyle<a>, <a href="https://marketplace.visualstudio.com/items?itemName=SonarSource.sonarlint-vscode" target="_blank">SonarLint<a> and <a href="https://marketplace.visualstudio.com/items?itemName=sourcery.sourcery" target="_blank">Sourcery<a>.<br />
:heavy_check_mark: Tested, one by one, on thousands of URLs.<br />
:heavy_check_mark: Fully tested and working on Windows (10 20H2 - 19042.985) and Linux (Kali 2021.1).<br />
Expand Down Expand Up @@ -157,20 +158,20 @@ https://github.com/rfc-st/humble/releases
(Windows) $ py humble.py
(Linux) $ python3 humble.py

usage: humble.py [-h] [-a] [-b] [-f TERM] [-g] [-l {es}] [-o {html,pdf,txt}] [-r] [-u URL] [-v]
usage: humble.py [-h] [-a] [-b] [-f [TERM]] [-g] [-l {es}] [-o {html,pdf,txt}] [-r] [-u URL] [-v]

humble (HTTP Headers Analyzer) - https://github.com/rfc-st/humble

options:
-h, --help show this help message and exit
-a Show statistics of the performed analysis (will be global if '-u' URL is omitted)
-b Show a brief analysis; if omitted, a detailed analysis will be shown.
-f TERM Show statistics for fingerprint headers related to the term E.g., Akamai, Google.
-g Show guidelines on securing most used web servers/services.
-l {es} Displays the analysis in the indicated language; if omitted, English will be used.
-o {html,pdf,txt} Save analysis to file (URL_headers_yyyymmdd.ext).
-r Show HTTP response headers and a detailed analysis.
-u URL URL to analyze, with schema. E.g., https://google.com
-b Show a brief analysis; if omitted, a detailed analysis will be shown
-f [TERM] Show fingerprint statistics (will be the Top 20 if "TERM", e.g. "Google", is omitted)
-g Show guidelines on securing most used web servers/services
-l {es} Displays the analysis in the indicated language; if omitted, English will be used
-o {html,pdf,txt} Save analysis to file (URL_headers_yyyymmdd.ext)
-r Show HTTP response headers and a detailed analysis
-u URL URL to analyze, with schema. E.g. https://google.com
-v, --version Show version and checks for updates
```
Expand Down
61 changes: 46 additions & 15 deletions humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from fpdf import FPDF
from time import time
from datetime import datetime
from collections import defaultdict
from collections import Counter, defaultdict
from os import linesep, path, remove
from colorama import Fore, Style, init
from argparse import ArgumentParser, RawDescriptionHelpFormatter
Expand Down Expand Up @@ -149,21 +149,44 @@ def check_updates(version):
print(f"\n{get_detail('[update_error]')}")


def fng_analytics_global_groups(fng_lines):
pattern = r'\[([^\]]+)\]'
content_count = Counter(match.strip() for line in fng_lines for match in
re.findall(pattern, line))
total_lines = len(fng_lines)
print(f"{get_detail('[fng_top]', replace=True)}{total_lines}\
{get_detail('[fng_top_2]', replace=True)}\n")
for content, count in content_count.most_common(20):
percentage = round(count / total_lines * 100, 2)
print(f" [{content}]: {percentage}% ({count})")


def fng_analytics_global():
print(f"\n{Style.BRIGHT}{get_detail('[fng_stats]', replace=True)}\
{Style.RESET_ALL}{get_detail('[fng_source]', replace=True)}\n")
with open(path.join('additional', F_FILE), 'r', encoding='utf8') as fng_f:
fng_lines = fng_f.readlines()
fng_analytics_global_groups(fng_lines)


def fng_analytics_groups(fng_lines, term):
pattern = r'\[(.*?)\]'
distinct_content = {re.search(pattern, line)[1].strip() for line in
fng_lines if re.search(pattern, line) and term.lower()
in re.search(pattern, line)[1].lower()}
term_count = sum(re.search(pattern, line) and term.lower() in
re.search(pattern, line)[1].lower() for line in fng_lines)
distinct_content = \
{match[1].strip()
for line in fng_lines if (match := re.search(pattern, line)) and
term.lower() in match[1].lower()}
term_count = sum(bool((match := re.search(pattern, line)) and term.lower()
in match[1].lower()) for line in fng_lines)
return distinct_content, term_count


def fng_analytics_sorted(fng_lines, term, distinct_content):
for content in sorted(distinct_content):
print(f"\n [{content}]")
for line in fng_lines:
if term.lower() in line.lower() and content in line:
match = re.search(r'\[(.*?)\]', line)
if match and term.lower() in match[1].lower() \
and content == match[1].strip():
print(f" {line[:line.find('[')].strip()}")


Expand Down Expand Up @@ -687,19 +710,20 @@ def request_exceptions():
parser.add_argument("-a", dest='URL_A', action="store_true", help="Show \
statistics of the performed analysis (will be global if '-u' URL is omitted)")
parser.add_argument("-b", dest='brief', action="store_true", help="Show a \
brief analysis; if omitted, a detailed analysis will be shown.")
parser.add_argument("-f", type=str, dest='term', help="Show statistics \
for fingerprint headers related to the term E.g., Akamai, Google.")
brief analysis; if omitted, a detailed analysis will be shown")
parser.add_argument("-f", nargs='?', type=str, dest='term', help="Show \
fingerprint statistics (will be the Top 20 if \"TERM\", e.g. \"Google\", is \
omitted)")
parser.add_argument("-g", dest='guides', action="store_true", help="Show \
guidelines on securing most used web servers/services.")
guidelines on securing most used web servers/services")
parser.add_argument("-l", dest='lang', choices=['es'], help="Displays the \
analysis in the indicated language; if omitted, English will be used.")
analysis in the indicated language; if omitted, English will be used")
parser.add_argument("-o", dest='output', choices=['html', 'pdf', 'txt'],
help="Save analysis to file (URL_headers_yyyymmdd.ext).")
help="Save analysis to file (URL_headers_yyyymmdd.ext)")
parser.add_argument("-r", dest='ret', action="store_true", help="Show HTTP \
response headers and a detailed analysis.")
response headers and a detailed analysis")
parser.add_argument('-u', type=str, dest='URL', help="URL to analyze, with \
schema. E.g., https://google.com")
schema. E.g. https://google.com")
parser.add_argument("-v", "--version", action="store_true",
help="Show version and checks for updates")

Expand All @@ -712,6 +736,13 @@ def request_exceptions():
check_updates(version)
sys.exit()

if args.term is None and '-f' in sys.argv:
details_f = get_details_lines()
if args.lang:
details_f = get_details_lines()
fng_analytics_global()
sys.exit()

if args.term:
term = args.term
details_f = get_details_lines()
Expand Down
8 changes: 7 additions & 1 deletion i10n/details.txt
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,10 @@ Highlights
(source: "additional/fingerprint.txt")

[fng_add]
Related to
Related to

[fng_top]
Top 20 in relation to the

[fng_top_2]
headers of the source
8 changes: 7 additions & 1 deletion i10n/details_es.txt
Original file line number Diff line number Diff line change
Expand Up @@ -881,4 +881,10 @@ A destacar
(fuente: "additional/fingerprint.txt")

[fng_add]
Asociadas a
Asociadas a

[fng_top]
Top 20 en relación a las

[fng_top_2]
cabeceras del fichero fuente

0 comments on commit 241139e

Please sign in to comment.