\ stig_commenter - /g/pasta 2.4
From me, 3 Months ago, written in PowerShell.
Embed
  1. Function Open-File($initialDirectory,$filter){  
  2.    
  3.     [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null
  4.  
  5.     $OpenFileDialog                  = New-Object System.Windows.Forms.OpenFileDialog
  6.     $OpenFileDialog.initialDirectory = $initialDirectory
  7.     $OpenFileDialog.filter           = $filter
  8.     $OpenFileDialog.Multiselect      = $true
  9.     $OpenFileDialog.ShowDialog() | Out-Null
  10.     $OpenFileDialog.filenames
  11. }
  12.  
  13. $checks = import-csv (Open-File -filter "CSV (Comma delimited) (*.csv)| *.csv" -initialDirectory ($env:USERPROFILE + "\desktop"))
  14. $lists  = Open-File -filter "CKL (Check List) (*.ckl)| *.ckl" -initialDirectory ($env:USERPROFILE + "\desktop")
  15.  
  16. foreach ($l in $lists){
  17.     $xml = [system.xml.xmldocument](get-content $l)
  18.    
  19.     $nodes = ($xml.CHECKLIST.ASSET | Get-Member | where{$_.Definition -like "*set*" -and $_.membertype -eq "Property"}).name
  20.  
  21.     foreach($n in $nodes){
  22.         $res = $xml.CHECKLIST.ASSET.$n
  23.  
  24.         if($res -eq $null){
  25.             $xml.CHECKLIST.ASSET.$n = [string]::Empty
  26.         }
  27.     }
  28.    
  29.     foreach ($c in $checks){
  30.        
  31.         foreach($s in ($xml.CHECKLIST.stigs.istig.vuln)){
  32.            
  33.            foreach($set in $s.stig_data){
  34.                 if($set.ATTRIBUTE_DATA -eq $null){
  35.                     $set.ATTRIBUTE_DATA = [string]::Empty
  36.                 }
  37.             }
  38.            
  39.             if(($s.stig_data | where{$_.VULN_ATTRIBUTE -eq "Vuln_Num"}).ATTRIBUTE_DATA -eq $c.VulnID){    #$s.stig_data.attribute_data
  40.                 write-host $l.split("\")[-1] " - " $c.VulnID
  41.                
  42.                 [string]$sev = ($s.stig_data | where{$_.vuln_attribute -eq "Severity"} | select attribute_data).attribute_data
  43.  
  44.                 $status = switch($c.status){
  45.                     "Not A Finding"  {'NotAFinding'}
  46.                     "Open"           {'Open'}
  47.                     "Not Applicable" {'Not_Applicable'}
  48.                     "Not Reviewed"   {'Not_Reviewed'}
  49.                     default          {'Not_Reviewed'}
  50.                 }
  51.                
  52.                 if($status -eq "Open"){
  53.                     continue
  54.                 }
  55.  
  56.                 $s.comments = $c.comments
  57.                 $s.status = $status
  58.                 #$s.SEVERITY_OVERRIDE = $sev
  59.                 #$s.SEVERITY_JUSTIFICATION = "N/A"
  60.             }else{
  61.                 [string]$sev = ($s.stig_data | where{$_.vuln_attribute -eq "Severity"} | select attribute_data).attribute_data
  62.                 #$s.SEVERITY_OVERRIDE = $sev
  63.                 #$s.SEVERITY_JUSTIFICATION = "N/A"
  64.             }
  65.         }
  66.     }
  67.     $xml.Save($l)
  68. }