-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using powershell to audit STIG rules #729
Comments
Hello @IvanDrag0 , Thanks for the issue. I agree that we could have better coverage by auditing some settings, that we know will not be able to be made "Compliant". The skipped rule settings is a a good example of the use of the script resource to audit, but not change. I think we could create a composite that would have two parameters, getScript and testValue. Basically the getScript would be the query and the testValue would test the results of the get script based on a known good value. An example based on your logic above. $rules = $stig.RuleList | Select-Rule -Type AuditOnlyRule
foreach ( $rule in $rules )
{
Script (Get-ResourceTitle -Rule $rule)
{
GetScript = {
$getScript = $rule.GetScript
return $getScript
}
TestScript = {
$inDesiredState = $true
if($getScript -ne $rule.TestValue)
{
$inDesiredState = $false
}
return $inDesiredState
}
SetScript = { }
}
} If you wanted to provide a list of the rules that could be automated using the method you described above, we could gauge community interest/impact on coverage. Please include your "getScript" and "testValues" if you have handy. Thanks, Eric |
@erjenkin Thank you for the reply. That solution looks like it would work. Since I need this functionality for some of the things that I'm doing, I don't mind trying and write a proof-of-concept. To make sure that I stay within the PowerStig coding guidelines, it looks like I'd need to do the following:
Is that about right? |
That's a good start. We would need to create the convert portion for that rule to dynamically generate the xml based on the raw xccdf. How many rules do you think could be targeted with this new composite including the 3 you referenced earlier, just trying to gauge impact. Thanks, Eric |
All of them. I've done this exercise at work, which is why I'm confident that you could combine powershell, and in some cases the organizational values, to get the results that you're looking for. Currently, when running PowerStig with the latest WindowsClient processed XML file, 85 VIDs are left as Not Reviewed (since PowerStig skipps them). I've done a quick review and you could write a powershell command/function to verify all of them. Here are some examples: WN10-00-000025 - Windows 10 must employ automated mechanisms to determine the state of system components with regard to flaw remediation using the following frequency: continuously, where HBSS is used; 30 days, for any additional internal network scans not covered by HBSS; and annually, for external scans by Computer Network Defense Service Provider (CNDSP). For this STIG, you could use the WMI root\SecurityCenter to get the overall security software health of the system. So the script would like something like this: $inDesiredState = $true ; $AVProduct = Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntivirusProduct ; if ($AVProduct.Count -gt 1) { ForEach ($AV in $AVProduct) { if ($AV.displayName -ne "Windows Defender") { if ($AV.productState -ne "397312") { $inDesiredState = $false } } } } else { if ($AV.productState -ne "397312") { $inDesiredState = $false } } ; return $inDesiredState WN10-00-000035 - The operating system must employ a deny-all, permit-by-exception policy to allow the execution of authorized software programs.
This script would check that AppLocker is enabled and has rules in it. The Convert portion should only identify STIGs that need to be marked as AuditOnly (which it already does, unelss they're manually marked in the XML). To make things "cleaner", I would create a separate XML file which would contain those powershell commands (in the same way that PowerStig has a separate XML file for the main STIG and the Org values). While it is a bit time consuming, PowerStig should at least introduct the ability of doing so and let the community either contribute or populate their own. If someone could create a test branch for me with that capability, I should be able to generate an XML file as a proof-of-concept to let the PowerStig team and community review it and decide on the path forward. |
Here are the contribution guidelines for PowerSTIG, you start at the Forking Repo section. We currently use a resource AuditSystemDsc that does a pretty good job at testing settings that are found in CIM, so expanding that resource to handle some of these may be beneficial to look at. I personally do not like the idea of having a separate XML as it adds to the complexity of PowerSTIG when applying configurations and creates additional maintenance items during quarterly updates . I would prefer a method that uses the existing conversion process to create XML and OrgSettings, but I am not the only voice on the team. https://github.com/microsoft/PowerStig/blob/dev/README.CONTRIBUTING.md If you have any questions while working through the submission let me know. Thanks, |
I've forked the repo and made the updates as we discussed, however, when I test it, it looks like the script DSC is not populating correctly. WindowsClient-10-1.23.xml:
Test config:
The generated MOF file:
It looks like PowerStig is populating the GetScript and TestScript variables verbatim instead of with the provided values for Query and ExpectedValue. Is there something I forgot to change? |
@erjenkin I figured it out! |
While PowerStig is able to audit and configure many STIG rules, it leaves out rules that can only be audited and not changed (for example "WN10-00-000005 - Domain-joined systems must use Windows 10 Enterprise Edition 64-bit version." or "WN10-00-000015 - Windows 10 systems must have Unified Extensible Firmware Interface (UEFI) firmware and be configured to run in UEFI mode, not Legacy BIOS."). This is obviously not a shortcoming of the tool since we can't expect DSC to be able to change Windows version or install UEFI BIOS. However, with that said, PowerStig should still be capable to audit those settings using the Script DSC (or a new resource based on it).
The Script/New DSC would accept a Powershell command/script and the expected return, and use that to verify that the system is compliant with the STIG.
For example, for WN10-00-000015, the following DSC could be used to verify the result:
WN10-00-000020 (Secure Boot must be enabled on Windows 10 systems.) would look similar to this:
This new DSC approach would also need to be able to use regex since, for example, for WN10-00-000005, you'll need to run the following regex:
Since this is similar to how PowerStig handles skipped rules, I would think that implementing a new DSC resource based on this should require major rewrites of existing code (at least based on me looking through the code). I'm very familiar with the STIG rules (especially the ones that can only be audited) so I'd be happy to help provide the necessary Powershell/Regex commands to perform the audits (I've been wanting to find a way to help the project for awhile).
The text was updated successfully, but these errors were encountered: