From d0fc78a0bf1cefc326f5042fc067da576db03abb Mon Sep 17 00:00:00 2001 From: Kaden Emley <104032811+kemley76@users.noreply.github.com> Date: Wed, 31 Jul 2024 11:52:58 -0400 Subject: [PATCH] Checklist metadata validation and checklist mapper severities (#2750) * input validation for checklist metadata Signed-off-by: kemley76 * use hdf-converters in hdf2ckl Signed-off-by: kemley76 * updated hdf2ckl tests Signed-off-by: kemley76 * update tests based on changes to ckl mapper Signed-off-by: Kaden Emley * update ckl metadata validation to use hdf-converters helper function Signed-off-by: Kaden Emley * added ability to use local install of inspecjs Signed-off-by: Kaden Emley * update checklist commands and tests Signed-off-by: Kaden Emley * ensure threshold counts stay based off impact Signed-off-by: Kaden Emley * added tests to ensure that converting with invalid metadata display an error message Signed-off-by: Kaden Emley * use checklist types from hdf-converters Signed-off-by: Kaden Emley * remove redundant code in hdf2ckl command Signed-off-by: Kaden Emley * use inspecJS to convert impact to severity Signed-off-by: Kaden Emley * use checklist types from hdf-converters Signed-off-by: Kaden Emley * fix test data Signed-off-by: Kaden Emley * enforce enum matching for user input in generate ckl_metadata command Signed-off-by: Kaden Emley * add backwards compatibility for old checklist metadata format Signed-off-by: Kaden Emley * remove debug statement Signed-off-by: Kaden Emley * fix code smells Signed-off-by: Kaden Emley * linting Signed-off-by: Kaden Emley * format every output json file with 2 space indent Signed-off-by: Kaden Emley * add flags for all metadata fields on hdf2ckl command Signed-off-by: Kaden Emley * clarify instructions on ckl metadata generation Signed-off-by: Kaden Emley * change formating from 4 to 2 space indent Signed-off-by: Kaden Emley * make version and release number optional in checklist metadata generation Signed-off-by: Kaden Emley * update tests to reflect better formatted error messages Signed-off-by: Kaden Emley * update markdown summary table to include row for severity: none Signed-off-by: Kaden Emley * update code and tests to count N/A controls with severity other than none Signed-off-by: Kaden Emley * fix code smells Signed-off-by: Kaden Emley * revert addition of severity-none row to markdown summary table Signed-off-by: Kaden Emley * remove heimdall version when running checklist tests Signed-off-by: Kaden Emley * change return type of string | undefined to string | null Signed-off-by: Kaden Emley --------- Signed-off-by: kemley76 Signed-off-by: Kaden Emley Co-authored-by: Amndeep Singh Mann --- README.md | 47 +- pack-inspecjs.bat | 56 + pack-inspecjs.sh | 40 + package.json | 5 +- src/commands/convert/asff2hdf.ts | 2 +- src/commands/convert/aws_config2hdf.ts | 2 +- src/commands/convert/burpsuite2hdf.ts | 2 +- src/commands/convert/ckl2hdf.ts | 8 +- src/commands/convert/conveyor2hdf.ts | 2 +- src/commands/convert/dbprotect2hdf.ts | 2 +- src/commands/convert/fortify2hdf.ts | 2 +- src/commands/convert/gosec2hdf.ts | 2 +- src/commands/convert/hdf2asff.ts | 4 +- src/commands/convert/hdf2ckl.ts | 165 +- src/commands/convert/hdf2condensed.ts | 2 +- src/commands/convert/index.ts | 38 +- src/commands/convert/ionchannel2hdf.ts | 4 +- src/commands/convert/jfrog_xray2hdf.ts | 2 +- src/commands/convert/nessus2hdf.ts | 4 +- src/commands/convert/netsparker2hdf.ts | 2 +- src/commands/convert/nikto2hdf.ts | 2 +- src/commands/convert/prisma2hdf.ts | 2 +- src/commands/convert/prowler2hdf.ts | 2 +- src/commands/convert/sarif2hdf.ts | 2 +- src/commands/convert/scoutsuite2hdf.ts | 2 +- src/commands/convert/snyk2hdf.ts | 4 +- src/commands/convert/sonarqube2hdf.ts | 2 +- src/commands/convert/trivy2hdf.ts | 2 +- src/commands/convert/twistlock2hdf.ts | 2 +- src/commands/convert/veracode2hdf.ts | 2 +- src/commands/convert/xccdf_results2hdf.ts | 2 +- src/commands/convert/zap2hdf.ts | 2 +- src/commands/generate/ckl_metadata.ts | 92 +- src/commands/generate/inspec_metadata.ts | 2 +- src/resources/files.json | 4 - src/types/checklist.d.ts | 46 - src/utils/checklist.ts | 90 - src/utils/ohdf/types.ts | 4 +- src/utils/threshold.ts | 21 +- test/commands/convert/ckl2hdf.test.ts | 29 + test/commands/convert/hdf2ckl.test.ts | 60 +- test/commands/utils.ts | 3 +- test/commands/validate/threshold.test.ts | 43 + .../HDF/input/RHEL7_overrides_hdf.json | 289 + .../HDF/input/rhel-8_hardened.json | 27721 +++- .../HDF/input/vSphere8_report.json | 22000 +++- .../summary/rhel-8_hardened_output.json | 6 +- .../output/summary/rhel-8_hardened_output.md | 4 +- .../output/summary/rhel-8_hardened_output.yml | 6 +- .../checklist/checklist-RHEL8V1R3-hdf.json | 385 +- .../checklist/converted-rhel7_overrides.ckl | 591 + test/sample_data/checklist/metadata.json | 20 +- test/sample_data/checklist/red_hat_good.ckl | 66133 +++++----- .../checklist/red_hat_good_metadata.ckl | 66133 +++++----- .../ckl_with_invalid_metadata.ckl | 505 + .../sample_input_report/invalid_metadata.json | 19 + .../small_ckl_overrides.ckl | 1592 + .../checklist/small_overrides_hdf.json | 907 + .../checklist/three_stig_checklist-hdf.json | 890 +- .../sample_data/checklist/vSphere8_report.ckl | 45126 ++++--- .../dbprotect-check-hdf-withraw.json | 91127 ++++++++++++- .../dbprotect/dbprotect-check-hdf.json | 26178 +++- .../dbprotect-findings-hdf-withraw.json | 101555 ++++++++++++++- .../dbprotect/dbprotect-findings-hdf.json | 27849 +++- .../thresholds/red_hat_good.counts.good.yml | 8 + ...hel-8_hardened.counts.bad.noimpactHigh.yml | 59 + .../rhel-8_hardened.counts.good.exact.yml | 81 + .../calculateSeverityCounts.sample | 6 +- .../calculateSummariesForExecJSONs.sample | 43 +- .../calculations/calculateTotalCounts.sample | 6 +- .../calculateTotalCountsForSummaries.sample | 41 +- 71 files changed, 388745 insertions(+), 91346 deletions(-) create mode 100644 pack-inspecjs.bat create mode 100755 pack-inspecjs.sh delete mode 100644 src/types/checklist.d.ts delete mode 100644 src/utils/checklist.ts create mode 100644 test/sample_data/HDF/input/RHEL7_overrides_hdf.json create mode 100644 test/sample_data/checklist/converted-rhel7_overrides.ckl create mode 100644 test/sample_data/checklist/sample_input_report/ckl_with_invalid_metadata.ckl create mode 100644 test/sample_data/checklist/sample_input_report/invalid_metadata.json create mode 100644 test/sample_data/checklist/sample_input_report/small_ckl_overrides.ckl create mode 100644 test/sample_data/checklist/small_overrides_hdf.json create mode 100644 test/sample_data/thresholds/rhel-8_hardened.counts.bad.noimpactHigh.yml create mode 100644 test/sample_data/thresholds/rhel-8_hardened.counts.good.exact.yml diff --git a/README.md b/README.md index 998ffa222..f202530e6 100644 --- a/README.md +++ b/README.md @@ -383,20 +383,47 @@ convert hdf2ckl Translate a Heimdall Data Format JSON file into a DISA checklist file USAGE - $ saf convert hdf2ckl -i -o [-h] [-m ] [-H ] [-F ] [-M ] [-I ] + $ saf convert hdf2ckl saf convert hdf2ckl -i -o [-h] [-m ] [--profilename ] [--profiletitle ] [--version ] [--releasenumber ] [--releasedate ] [--marking ] [-H ] [-I ] [-M ] [-F ] [--targetcomment ] [--role Domain Controller|Member Server|None|Workstation] [--assettype Computing|Non-Computing] [--techarea |Application Review|Boundary Security|CDS Admin Review|CDS Technical Review|Database Review|Domain Name System (DNS)|Exchange Server|Host Based System Security (HBSS)|Internal Network|Mobility|Other Review|Releasable Networks (REL)|Releaseable Networks (REL)|Traditional Security|UNIX OS|VVOIP Review|Web Review|Windows OS] [--stigguid ] [--targetkey ] [--webdbsite --webordatabase] [--webdbinstance ] [--vulidmapping gid|id] FLAGS - -F, --fqdn= FQDN for CKL metadata - -H, --hostname= Hostname for CKL metadata - -I, --ip= IP address for CKL metadata - -M, --mac= MAC address for CKL metadata - -h, --help Show CLI help. - -i, --input= (required) Input HDF file - -m, --metadata= Metadata JSON file, generate one with "saf generate ckl_metadata" - -o, --output= (required) Output CKL file + -h, --help Show CLI help. + -i, --input= (required) Input HDF file + -o, --output= (required) Output CKL file + + CHECKLIST METADATA FLAGS + -F, --fqdn= Fully Qualified Domain Name + -H, --hostname= The name assigned to the asset within the network + -I, --ip= IP address + -M, --mac= MAC address + -m, --metadata= Metadata JSON file, generate one with "saf generate ckl_metadata" + --assettype=