|
| 1 | +import csv |
| 2 | +import json |
| 3 | +import sys |
| 4 | + |
| 5 | +# Convert a CSV file following the CIS 4.0 Microsoft365 Benchmark into a Prowler v3.0 Compliance JSON file |
| 6 | +# CSV fields: |
| 7 | +# Section #,Recommendation #,Profile,Title,Assessment Status,Description,Rationale Statement,Impact Statement,Remediation Procedure,Audit Procedure,Additional Information,CIS Controls,CIS Safeguards 1 (v8),CIS Safeguards 2 (v8),CIS Safeguards 3 (v8),v8 IG1,v8 IG2,v8 IG3,CIS Safeguards 1 (v7),CIS Safeguards 2 (v7),CIS Safeguards 3 (v7),v7 IG1,v7 IG2,v7 IG3,References,Default Value |
| 8 | + |
| 9 | +# Get the CSV filename to convert from |
| 10 | +file_name = sys.argv[1] |
| 11 | + |
| 12 | +# Create the output JSON object |
| 13 | +output = {"Framework": "CIS", "Version": "4.0", "Requirements": []} |
| 14 | + |
| 15 | +# Open the CSV file and read the rows |
| 16 | +try: |
| 17 | + with open(file_name, newline="", encoding="utf-8") as f: |
| 18 | + reader = csv.reader(f, delimiter=",") |
| 19 | + next(reader) # Skip the header row |
| 20 | + for row in reader: |
| 21 | + attribute = { |
| 22 | + "Section": row[0], |
| 23 | + "Profile": row[2], |
| 24 | + "AssessmentStatus": row[4], |
| 25 | + "Description": row[5], |
| 26 | + "RationaleStatement": row[6], |
| 27 | + "ImpactStatement": row[7], |
| 28 | + "RemediationProcedure": row[8], |
| 29 | + "AuditProcedure": row[9], |
| 30 | + "AdditionalInformation": row[10], |
| 31 | + "References": row[24], |
| 32 | + } |
| 33 | + if row[4] != "": |
| 34 | + output["Requirements"].append( |
| 35 | + { |
| 36 | + "Id": row[1], |
| 37 | + "Description": row[5], |
| 38 | + "Checks": [], |
| 39 | + "Attributes": [attribute], |
| 40 | + } |
| 41 | + ) |
| 42 | +except UnicodeDecodeError: |
| 43 | + # If there is an error reading the file with the default encoding, try with ISO-8859-1 |
| 44 | + with open(file_name, newline="", encoding="ISO-8859-1") as f: |
| 45 | + reader = csv.reader(f, delimiter=",") |
| 46 | + next(reader) # Skip the header row |
| 47 | + for row in reader: |
| 48 | + attribute = { |
| 49 | + "Section": row[0], |
| 50 | + "Profile": row[2], |
| 51 | + "AssessmentStatus": row[4], |
| 52 | + "Description": row[5], |
| 53 | + "RationaleStatement": row[6], |
| 54 | + "ImpactStatement": row[7], |
| 55 | + "RemediationProcedure": row[8], |
| 56 | + "AuditProcedure": row[9], |
| 57 | + "AdditionalInformation": row[10], |
| 58 | + "References": row[24], |
| 59 | + } |
| 60 | + if row[4] != "": |
| 61 | + output["Requirements"].append( |
| 62 | + { |
| 63 | + "Id": row[1], |
| 64 | + "Description": row[5], |
| 65 | + "Checks": [], |
| 66 | + "Attributes": [attribute], |
| 67 | + } |
| 68 | + ) |
| 69 | + |
| 70 | +# Save the output JSON file |
| 71 | +with open("cis_4.0_microsoft365.json", "w", encoding="utf-8") as outfile: |
| 72 | + json.dump(output, outfile, indent=4, ensure_ascii=False) |
| 73 | + |
| 74 | +print("Archivo JSON generado exitosamente.") |
0 commit comments