Skip to content

Commit

Permalink
Merge pull request #110 from VeriDevOps/Auditpol
Browse files Browse the repository at this point in the history
Implemented a new way of checking the bunch of STIGs of AuditPolicy g…
  • Loading branch information
Ildar1 authored Oct 24, 2023
2 parents 2716042 + d1239bf commit c1f4ffb
Show file tree
Hide file tree
Showing 13 changed files with 315 additions and 94 deletions.
1 change: 1 addition & 0 deletions ExternalFiles/check.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auditpol /get /subcategory:"%guid%"
1 change: 1 addition & 0 deletions ExternalFiles/exec.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auditpol /set /subcategory:"%task%" /%parameter%:%value%
95 changes: 5 additions & 90 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,104 +58,19 @@
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>rqcode/stigs/win10_new/Windows10SecurityTechnicalImplementationGuide</mainClass>
<!-- <addClasspath>true</addClasspath>-->
<!-- <classpathPrefix>lib/</classpathPrefix>-->
<mainClass>rqcode.stigs.win10_new.AuditPolicy.AuditPolMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see
https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see
https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- javadoc lifecycle -->
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<!-- Specific for plant UML Doclet -->
<configuration>
<doclet>nl.talsmasoftware.umldoclet.UMLDoclet</doclet>
<docletArtifact>
<groupId>nl.talsmasoftware</groupId>
<artifactId>umldoclet</artifactId>
<version>2.1.0</version>
</docletArtifact>
<additionalOptions>
<!--<additionalOption>...</additionalOption>-->
</additionalOptions>
</configuration>
</plugin>


</plugins>
</pluginManagement>
</build>

<reporting>
<plugins>
<plugin>
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.4.1</version>
<!-- Specific for plant UML Doclet -->
<configuration>
<doclet>nl.talsmasoftware.umldoclet.UMLDoclet</doclet>
<docletArtifact>
<groupId>nl.talsmasoftware</groupId>
<artifactId>umldoclet</artifactId>
<version>2.1.0</version>
</docletArtifact>
<additionalOptions>
<!--<additionalOption>...</additionalOption>-->
</additionalOptions>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
64 changes: 64 additions & 0 deletions src/main/java/rqcode/stigs/win10_new/AuditPolicy/AuditPolMain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@


import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

/*
We are preparing three files:
* exec.txt: This is a simple template of a PowerShell script for setting values.
* check.txt: This is a template of a PowerShell script for obtaining values.
* tasks.properties: This file is used for mapping task numbers (e.g., V-63447) to their corresponding GUID (e.g., {0000-0000-000-0001}). Additionally, we store additional fields for the parameter and value of each task in this file.
How it works:
* The task name is provided as a command-line argument when running the JAR file. For example, when running the JAR, you simply specify the task name (java -jar jarname.jar V-63447).
*
* Next, we read the tasks.properties file and check if the desired task exists. If it doesn't exist, we throw an exception.
* The next step is to read the check.txt file, as it's a template that needs to be filled with real values. We have already obtained the real values from tasks.properties.
* After substituting these values, we have a command ready to be executed.
*/


public class AuditPolMain {

public static void main(String[] args) throws IOException {
String taskName = args[0];

try (InputStream input = AuditPolMain.class.getClassLoader().getResourceAsStream("tasks.properties")) {

Properties properties = new Properties();

if (input == null) {
throw new IllegalArgumentException("file tasks.properties is not found");
}

//load a properties file from class path, inside static method
properties.load(input);

String guid = (String) properties.get(taskName);
String parameter = (String)properties.get(taskName + ".param");
String value = (String)properties.get(taskName + ".value");
if(guid == null || parameter == null || value == null)
throw new IllegalArgumentException(String.format("Task number %s not found!", taskName));


byte[] bytes = Files.readAllBytes(Paths.get("ExternalFiles" + File.separator + "check.txt"));
String exec = new String(bytes);
exec = exec.replaceAll("%task%", guid);
exec = exec.replaceAll("%guid%", guid);
exec = exec.replaceAll("%parameter%", parameter);
exec = exec.replaceAll("%value%", value);
System.out.println(exec);
//Process execResult = Runtime.getRuntime().exec(exec);

} catch (IOException ex) {
ex.printStackTrace();
}

}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class StigClassGenerator {
public static void main(String[] args) {
String fileName = "src/main/java/rqcode/stigs/win10_new/AuditPolicy/stigs/stig_input.txt";
String outputDirectory = "rqcode/stigs/win10_new/AuditPolicy/stigs/outputs";
List<StigInfo> stigInfoList = new ArrayList<>();

try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = br.readLine()) != null) {
String[] parts = line.split("\\s"); // Split by spaces
if (parts.length == 3) {
String stig = parts[0];
String checkValue = parts[1];
String guid = parts[2];
stigInfoList.add(new StigInfo(stig, checkValue, guid));
} else {
System.err.println("Invalid line: " + line);
}
}
} catch (IOException e) {
e.printStackTrace();
}

// Generate StigTemplate classes based on stigInfoList
for (StigInfo stigInfo : stigInfoList) {
String className = "V_" + stigInfo.getStig();
String filePath = outputDirectory + "/" + className + ".java";

try (FileWriter writer = new FileWriter(new File(filePath))) {
writer.write("public class " + className + " extends StigTemplate {\n");
writer.write("\tpublic " + className + "() {\n");
writer.write("\t\tsuper(\"" + stigInfo.getGuid() + "\", \"" + stigInfo.getCheckValue() + "\");\n");
writer.write("\t}\n");
writer.write("}\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}

static class StigInfo {
private String stig;
private String checkValue;
private String guid;

public StigInfo(String stig, String checkValue, String guid) {
this.stig = stig;
this.checkValue = checkValue;
this.guid = guid;
}

public String getStig() {
return stig;
}

public String getCheckValue() {
return checkValue;
}

public String getGuid() {
return guid;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class StigFileParser {
public static void main(String[] args) {
String fileName = "stig_input.txt"; // Change this to your file's path if needed
try (BufferedReader br = new BufferedReader(new FileReader(fileName))) { // Added closing parenthesis
String line;
while ((line = br.readLine()) != null) {
String[] parts = line.split("\\s"); // Split by spaces
if (parts.length == 3) {
String stig = parts[0];
String parameter = parts[1];
String guid = parts[2];
System.out.println("STIG: " + stig);
System.out.println("Parameter: " + parameter);
System.out.println("GUID: " + guid);
System.out.println(); // Separate records
} else {
System.err.println("Invalid line: " + line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package rqcode.stigs.win10_new.AuditPolicy.stigs;

import rqcode.stigs.win10_new.AuditPolicy.AuditPolicyConst;
import rqcode.stigs.win10_new.AuditPolicy.AuditPolicyPattern;
import rqcode.stigs.win10_new.AuditPolicy.AuditPolicyScriptPattern;
import rqcode.stigs.win10_new.patterns.STIGScriptPattern;

import java.util.Map;

public class StigTemplate extends AuditPolicyPattern {
private final STIGScriptPattern policyScriptPattern;

public StigTemplate(String guid, String checkValue) {
policyScriptPattern = new AuditPolicyScriptPattern(
AuditPolicyConst.AUDIT_POLICY_SCRIPT_PATTERN_CHECK, AuditPolicyConst.AUDIT_POLICY_SCRIPT_PATTERN_ENFORCE,
Map.of(
"guid", guid,
"checkValue", checkValue
),
Map.of(
"guid", guid,
"checkValue", checkValue,
"value", "enable"
)
);
pattern = this.policyScriptPattern;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class V_63447 extends AuditPolicyPattern {
),
Map.of(
"guid", "{0CCE9235-69AE-11D9-BED3-505054503030}",
"parameter", "failure",
"checkValue", "failure",
"value", "enable"));

public V_63447() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class V_63449 extends AuditPolicyPattern {
),
Map.of(
"guid", "{0CCE9235-69AE-11D9-BED3-505054503030}",
"parameter", "success",
"checkValue", "success",
"value", "enable"));

public V_63449() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class V_63463 extends AuditPolicyPattern {
),
Map.of(
"guid", "{0CCE9215-69AE-11D9-BED3-505054503030}",
"parameter", "failure",
"checkValue", "failure",
"value", "enable"));

public V_63463() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class V_63467 extends AuditPolicyPattern {
),
Map.of(
"guid", "{0CCE9216-69AE-11D9-BED3-505054503030}",
"parameter", "success",
"checkValue", "success",
"value", "enable"));

public V_63467() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
V-63435 Success {0CCE923F-69AE-11D9-BED3-505054503030}
V-71761 Success {0CCE9231-69AE-11D9-BED3-505054503030}
V-63487 Success {0CCE9228-69AE-11D9-BED3-505054503030}
V-63481 Success {0CCE9230-69AE-11D9-BED3-505054503030}
V-63483 Failure {0CCE9228-69AE-11D9-BED3-505054503030}
V-63467 Success {0CCE9216-69AE-11D9-BED3-505054503030}
V-63463 Failure {0CCE9215-69AE-11D9-BED3-505054503030}
V-63469 Success {0CCE921B-69AE-11D9-BED3-505054503030}
V-63499 Success {0CCE9214-69AE-11D9-BED3-505054503030}
V-63491 Failure {0CCE9213-69AE-11D9-BED3-505054503030}
V-63495 Success {0CCE9213-69AE-11D9-BED3-505054503030}
V-63475 Failure {0CCE922F-69AE-11D9-BED3-505054503030}
V-63471 Failure {0CCE9245-69AE-11D9-BED3-505054503030}
V-63473 Success {0CCE9245-69AE-11D9-BED3-505054503030}
V-63479 Success {0CCE922F-69AE-11D9-BED3-505054503030}
V-63441 Success {0CCE923A-69AE-11D9-BED3-505054503030}
V-63445 Success {0CCE9237-69AE-11D9-BED3-505054503030}
V-63447 Failure {0CCE9235-69AE-11D9-BED3-505054503030}
V-63449 Success {0CCE9235-69AE-11D9-BED3-505054503030}
V-63515 Failure {0CCE9212-69AE-11D9-BED3-505054503030}
V-63513 Success {0CCE9211-69AE-11D9-BED3-505054503030}
V-63459 Success {0CCE921C-69AE-11D9-BED3-505054503030}
V-63457 Success {0CCE9249-69AE-11D9-BED3-505054503030}
V-63455 Success {0CCE9217-69AE-11D9-BED3-505054503030}
V-71759 Failure {0CCE9217-69AE-11D9-BED3-505054503030}
V-63507 Success {0CCE9210-69AE-11D9-BED3-505054503030}
V-63503 Failure {0CCE9214-69AE-11D9-BED3-505054503030}
V-63453 Success {0CCE922B-69AE-11D9-BED3-505054503030}
V-74721 Success {0CCE9224-69AE-11D9-BED3-505054503030}
V-63431 Failure {0CCE923F-69AE-11D9-BED3-505054503030}
V-74411 Success {0CCE9227-69AE-11D9-BED3-505054503030}
V-74409 Failure {0CCE9227-69AE-11D9-BED3-505054503030}
V-75027 Failure {0CCE9224-69AE-11D9-BED3-505054503030}
V-63517 Success {0CCE9212-69AE-11D9-BED3-505054503030}
Loading

1 comment on commit c1f4ffb

@agilebotanist
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Please sign in to comment.