Created
October 21, 2023 19:11
-
-
Save dru1d-foofus/172c6b7507962c6722c1fca873c6155f to your computer and use it in GitHub Desktop.
Certipy JSON Parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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