Skip to content

Instantly share code, notes, and snippets.

@dru1d-foofus
Created October 21, 2023 19:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dru1d-foofus/172c6b7507962c6722c1fca873c6155f to your computer and use it in GitHub Desktop.
Save dru1d-foofus/172c6b7507962c6722c1fca873c6155f to your computer and use it in GitHub Desktop.
Certipy JSON Parser
#! /usr/bin/env python3
#######################
# Certipy JSON Parser #
# dru1d #
#######################
import json
import argparse
def parse_json_file(file_path):
with open(file_path, 'r') as file:
data = json.load(file)
results = []
# Extract details for Certificate Authorities
for key, ca in data["Certificate Authorities"].items():
ca_name = ca["CA Name"]
vulnerabilities = ca.get("[!] Vulnerabilities", {})
vuln_status = "Vulnerable: " + ", ".join(vulnerabilities.values()) if vulnerabilities else "Not Vulnerable"
ca_output = f"CA|{ca_name}|{vuln_status}"
results.append(ca_output)
# Extract details for Certificate Templates
for key, template in data["Certificate Templates"].items():
template_name = template["Template Name"]
is_enabled = template["Enabled"]
extended_key_usage = ",".join(template.get("Extended Key Usage", []))
# Check for Enrollment Permissions and then Enrollment Rights
enrollment_rights_list = template.get("Permissions", {}).get("Enrollment Permissions", {}).get("Enrollment Rights", [])
enrollment_rights = ",".join(enrollment_rights_list)
vulnerabilities = template.get("[!] Vulnerabilities", {})
vuln_status = "Vulnerable: " + ", ".join(vulnerabilities.values()) if vulnerabilities else "Not Vulnerable"
template_output = f"Template|{template_name}|{is_enabled}|{extended_key_usage}|{enrollment_rights}|{vuln_status}"
results.append(template_output)
return "\n".join(results)
def main():
parser = argparse.ArgumentParser(description="Parse a JSON file for certificate information.")
parser.add_argument('-f', '--file', required=True, help='Path to the JSON file to be parsed.')
args = parser.parse_args()
output = parse_json_file(args.file)
print(output)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment