Skip to content

Commit

Permalink
Feature: Improve JSON generation. Now it also accepts '-r' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
rfc-st committed Nov 10, 2023
1 parent 42eea1f commit 51588d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a target="_blank" href="https://www.python.org/downloads/" title="Minimum Python version required to run this tool"><img src="https://img.shields.io/badge/Python-%3E%3D3.9-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-2023--11--08-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-2023--11--10-blue.svg?labelColor=343b41"></a>
<a target="_blank" href="https://github.com/rfc-st/humble/actions?query=workflow%3ACodeQL" title="Results of the last analysis of this tool with CodeQL"><img src="https://github.com/rfc-st/humble/workflows/CodeQL/badge.svg"></a>
<a target="_blank" href="https://owasp.org/www-project-secure-headers/#div-technical" title="Tool accepted as a technical resource for OWASP"><img src="https://img.shields.io/badge/OWASP-Resource-blue?labelColor=343b41"></a>
<a target="_blank" href="https://www.kali.org/tools/humble/" title="Tool accepted in Kali"><img src="https://img.shields.io/badge/Kali%20Linux-Tool-blue?labelColor=343b41"></a>
Expand Down
22 changes: 12 additions & 10 deletions humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@

export_date = datetime.now().strftime("%Y%m%d")
now = datetime.now().strftime("%Y/%m/%d - %H:%M:%S")
version = datetime.strptime('2023-11-08', '%Y-%m-%d').date()
version = datetime.strptime('2023-11-10', '%Y-%m-%d').date()


class PDF(FPDF):
Expand Down Expand Up @@ -749,31 +749,34 @@ def parse_csp(csp_header):

def generate_json(name_e, name_p):
section0 = get_detail('[0section]', replace=True)
sectionh = get_detail('[0headers]', replace=True)
section5 = get_detail('[5compat]', replace=True)
with (open(name_e, 'r', encoding='utf8') as source_txt,
open(name_p, 'w', encoding='utf8') as final_json):
txt_content = source_txt.read()
txt_sections = re.split(r'\[(\d+\.\s[^\]]+)\]\n', txt_content)[1:]
txt_sections = re.split(r'\[(.*?)\]\n', txt_content)[1:]
data = {}
parse_txt_sections(txt_sections, data, section0, section5)
parse_json_sections(txt_sections, data, section0, sectionh, section5)
json_data = json.dumps(data, indent=4, ensure_ascii=False)
final_json.write(json_data)


def parse_txt_sections(txt_sections, data, section0, section5):
def parse_json_sections(txt_sections, data, section0, sectionh, section5):
for i in range(0, len(txt_sections), 2):
json_section = f"[{txt_sections[i]}]"
json_content = txt_sections[i + 1].strip()
if json_section == section5:
json_content = json_content.split('.:')[0].strip()
json_lines = json_content.split('\n')
json_data = write_json_sections(section0, section5, json_section,
json_data = write_json_sections(section0, sectionh, section5,
json_section,
json_lines)
data[json_section] = json_data


def write_json_sections(section0, section5, json_section, json_lines):
if json_section in (section0, section5):
def write_json_sections(section0, sectionh, section5, json_section,
json_lines):
if json_section in (section0, sectionh, section5):
json_data = {}
for line in json_lines:
if ':' in line:
Expand Down Expand Up @@ -935,9 +938,8 @@ def custom_help_formatter(prog):
and (args.URL is None or args.guides is None or args.URL_A is None):
parser.error("'-b', -'o' and '-r' options requires also '-u'.")

if args.output == 'json' and (args.ret or not args.brief):
parser.error("'-o json' currently requires '-b' and does not support '-r'\
.")
if args.output == 'json' and not args.brief:
parser.error("'-o json' currently requires '-b'.")

URL = args.URL
details_f = get_details_lines()
Expand Down

0 comments on commit 51588d2

Please sign in to comment.