Skip to content

Commit

Permalink
Minor: Code optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc-st committed Jan 24, 2025
1 parent ad98f2e commit 6e583cb
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a target="_blank" href="https://github.com/rfc-st/humble/blob/master/screenshots/humble_python.PNG" title="Minimum Python version required to run this tool"><img src="https://img.shields.io/badge/Python-%3E%3D3.8-blue?labelColor=343b41"></a>
<a target="_blank" href="LICENSE" title="License of this tool"><img src="https://img.shields.io/badge/License-MIT-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/releases" title="Latest release of this tool"><img src="https://img.shields.io/github/v/release/rfc-st/humble?display_name=release&label=Latest%20Release&labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/commits/master" title="Latest commit of this tool"><img src="https://img.shields.io/badge/Latest_Commit-2025--01--18-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/commits/master" title="Latest commit of this tool"><img src="https://img.shields.io/badge/Latest_Commit-2025--01--24-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://pkg.kali.org/pkg/humble" title="Official tool in Kali Linux"><img src="https://img.shields.io/badge/Kali%20Linux-Tool-blue?labelColor=343b41"></a>
<br />
<a target="_blank" href="#" title="Featured on:"><img src="https://img.shields.io/badge/Featured%20on:-343b41"></a>
Expand Down
40 changes: 22 additions & 18 deletions humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
XML_STRING = ('Ref: ', 'Value: ', 'Valor: ')

current_time = datetime.now().strftime("%Y/%m/%d - %H:%M:%S")
local_version = datetime.strptime('2025-01-18', '%Y-%m-%d').date()
local_version = datetime.strptime('2025-01-24', '%Y-%m-%d').date()


class SSLContextAdapter(requests.adapters.HTTPAdapter):
Expand Down Expand Up @@ -295,16 +295,15 @@ def get_l10n_content():


def get_analysis_results():
print_detail_l('[analysis_time]')
print(round(end - start, 2), end="")
print_detail_l('[analysis_time_sec]')
analysis_t = str(round(end - start, 2)).rstrip()
print(f"{get_detail('[analysis_time]', replace=True)} {analysis_t}\
{get_detail('[analysis_time_sec]', replace=True)}")
t_cnt = sum([m_cnt, f_cnt, i_cnt[0], e_cnt])
analysis_totals = save_analysis_results(t_cnt)
analysis_diff = compare_analysis_results(*analysis_totals, en_cnt=en_cnt,
m_cnt=m_cnt, f_cnt=f_cnt,
i_cnt=i_cnt, e_cnt=e_cnt,
t_cnt=t_cnt)
print("")
print_analysis_results(*analysis_diff, t_cnt=t_cnt)
analysis_grade = grade_analysis(en_cnt, m_cnt, f_cnt, i_cnt, e_cnt)
print(f"{get_detail(analysis_grade)}")
Expand Down Expand Up @@ -775,9 +774,7 @@ def delete_lines(reliable=True):
def print_export_path(filename, reliable):
delete_lines(reliable=False) if reliable else delete_lines()
if '-c' not in sys.argv:
print("")
print_detail_l('[report]')
print(path.abspath(filename))
print(f"{print_detail_s('[report]')} {path.abspath(filename)}")


def print_nowarnings():
Expand Down Expand Up @@ -816,8 +813,8 @@ def print_basic_info(export_filename):
print(f" {current_time}")
print(f'{URL_STRING[1]}{URL}')
if export_filename:
print_detail_l('[export_filename]')
print(f"{export_filename}")
print(f"{get_detail('[export_filename]', replace=True)} \
{export_filename}")


def print_extended_info(args, reliable, status_code):
Expand Down Expand Up @@ -889,6 +886,12 @@ def print_detail_r(id_mode, is_red=False):
print("")


def print_detail_s(id_mode):
for i, line in enumerate(l10n_main):
if line.startswith(id_mode):
return f"\n{l10n_main[i+1].rstrip()}"


def get_detail(id_mode, replace=False):
for i, line in enumerate(l10n_main):
if line.startswith(id_mode):
Expand Down Expand Up @@ -1050,7 +1053,8 @@ def check_path_permissions(output_path):
try:
open(path.join(output_path, HUMBLE_FILES[1]), 'w')
except PermissionError:
print(f"\n{get_detail('[args_nowr]', replace=True)}'{output_path}'")
print(f"\n {get_detail('[args_nowr]', replace=True)} \
('{output_path}')")
sys.exit()
else:
remove(path.join(output_path, HUMBLE_FILES[1]))
Expand All @@ -1063,8 +1067,8 @@ def check_output_path(args, output_path):
elif path.exists(output_path):
check_path_permissions(output_path)
else:
print(f"\n{get_detail('[args_noexportpath]', replace=True)}\
('{output_path}').")
print(f"\n {get_detail('[args_noexportpath]', replace=True)} \
('{output_path}')")
sys.exit()


Expand Down Expand Up @@ -1137,9 +1141,8 @@ def print_skipped_headers(args):


def print_unsupported_headers(unsupported_headers):
print("")
print_detail_l('[args_skipped_unknown]')
print(f"{', '.join(f'{header}' for header in unsupported_headers)}")
print(f"\n {get_detail('[args_skipped_unknown]', replace=True)} \
({', '.join(f'\'{header}\'' for header in unsupported_headers)})")
sys.exit()


Expand Down Expand Up @@ -2808,8 +2811,9 @@ def footer(self):
self.set_y(-15)
self.set_font('Helvetica', 'I', 8)
self.set_text_color(0, 0, 0)
self.cell(0, 10, get_detail('[pdf_footer]') + str(self.page_no()) +
get_detail('[pdf_footer2]') + ' {nb}', align='C')
self.cell(0, 10, print_detail_s('[pdf_footer]') + ' ' +
str(self.page_no()) + get_detail('[pdf_footer2]') +
' {nb}', align='C')
pdf = PDF()
pdf_links = (URL_STRING[1], REF_LINKS[2], REF_LINKS[3], URL_LIST[0],
REF_LINKS[4])
Expand Down
14 changes: 7 additions & 7 deletions l10n/details.txt
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@
'humble' (HTTP Headers Analyzer)

[pdf_footer]
Page
Page

[pdf_footer2]
of
Expand Down Expand Up @@ -836,7 +836,7 @@ HTTP Response Headers
Error: The URL scheme provided is either invalid or unsupported.

[report]
Report saved to
Report saved to

[0section]
[0. Info]
Expand Down Expand Up @@ -1315,7 +1315,7 @@ HTTP Response Headers
Findings to review:

[analysis_time]
Done in
Done in

[analysis_time_sec]
seconds! (changes with respect to the last analysis in parentheses)
Expand Down Expand Up @@ -1597,13 +1597,13 @@ Error: The parameter '-op' requires the parameter '-o'.
Error: The parameter '-s' requires at least the name of one HTTP response header.

[args_skipped_unknown]
Error: Remove these HTTP headers from the '-s' parameter as 'humble' does not check them:
Error: Remove these HTTP headers from the '-s' parameter as they are not analyzed

[args_noexportpath]
Error: The indicated PATH does not exist
Error: The indicated PATH does not exist

[args_nowr]
Error: This user does not have write permissions on the path
Error: This user does not have write permissions on the indicated PATH

[args_input_traversal]
Error: The indicated filename, or absolute path, seem wrong
Expand Down Expand Up @@ -1636,7 +1636,7 @@ want to contribute?:
Value:

[export_filename]
File :
File :

[e_grade]
Analysis Grade: E (Review 'Enabled headers')
Expand Down
14 changes: 7 additions & 7 deletions l10n/details_es.txt
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@
'humble' (Analizador de cabeceras HTTP)

[pdf_footer]
Página
Página

[pdf_footer2]
de
Expand Down Expand Up @@ -838,7 +838,7 @@ Cabeceras de respuesta HTTP
Error: El esquema de la URL no es válido o no es compatible.

[report]
Informe guardado en
Informe guardado en

[0section]
[0. Información]
Expand Down Expand Up @@ -1320,7 +1320,7 @@ Cabeceras de respuesta HTTP
Advertencias a revisar:

[analysis_time]
Realizado en
Realizado en

[analysis_time_sec]
segundos! (cambios con respecto al ultimo análisis entre paréntesis)
Expand Down Expand Up @@ -1599,16 +1599,16 @@ Error: la ruta indicada de 'testssl.sh' es incorrecta.
Error: El parámetro '-s' requiere, al menos, el nombre de una cabecera HTTP de respuesta.

[args_skipped_unknown]
Error: Elimina estas cabeceras HTTP del parámetro '-s', ya que 'humble' no las comprueba:
Error: Elimine estas cabeceras HTTP del parámetro '-s' ya que no se analizan

[args_nooutputfmt]
Error: El parámetro '-op' requiere el parámetro '-o'.

[args_noexportpath]
Error: No existe la ruta indicada
Error: No existe la ruta indicada

[args_nowr]
Erorr: Este usuario no tiene permisos de escritura en la ruta
Erorr: Este usuario no tiene permisos de escritura en la ruta indicada

[args_input_traversal]
Error: El nombre del fichero, o la ruta absoluta, indicados parecen erróneos
Expand All @@ -1623,7 +1623,7 @@ Valores
Valor:

[export_filename]
Fich.:
Fich.:

[e_grade]
Nota del análisis: E (Revisa 'Cabeceras habilitadas')
Expand Down

0 comments on commit 6e583cb

Please sign in to comment.