Skip to content

Instantly share code, notes, and snippets.

@bryaneaton
Created April 11, 2023 14:31
Show Gist options
  • Save bryaneaton/23476b3fd462be0a39ffc67072078264 to your computer and use it in GitHub Desktop.
Save bryaneaton/23476b3fd462be0a39ffc67072078264 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from lxml import etree
from pathlib import Path
import random
stig_folder = "./tests/test_data"
def rand():
statuses = ["Open", "NotAFinding", "NotApplicable"]
random.shuffle(statuses)
return statuses.pop()
# accessing and printing files in directory and subdirectory
for filename in Path(stig_folder).glob(
"**/*.ckl",
):
tree = etree.parse(filename)
for s in tree.xpath("//CHECKLIST/STIGS/iSTIG/VULN/STATUS"):
if len(sys.argv) > 1 and sys.argv[1] == "shuffle":
s.text = rand()
elif len(sys.argv) > 1 and sys.argv[1] == "fail":
s.text = "Open"
elif len(sys.argv) > 1 and sys.argv[1] == "pass":
s.text = "NotAFinding"
else:
sys.exit("Please provide an argument: shuffle, fail, or pass")
with open(filename, "wb") as f:
tree.write(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment