0

Trying to edit a CKL file, which is really just an XML file. I am using the following python script....

import xml.etree.ElementTree as ET

#Load the STIG into a tree structure
stig_file = "STIG.ckl"
tree = ET.parse(stig_file)
root = tree.getroot()

#Modify the "status" attribute of the "VULN" element with ID "V-220650"
for elem in root.iter():
if elem.tag == "VULN" and elem.attrib == "V-220650":
elem.attrib["status"] = "OPEN"
break

#Write the modified STIG back to a file
tree.write("STIG.ckl")`

Here is a pastebin with an example of a section i am trying to edit

https://pastebin.com/N58YNaDH

If you look, I am trying to edit vulnerability "V-220650" and change the status of it to "OPEN"

When I run the python script, I do not get an error, but also see no changes to the file. Would anyone be able to help me with what I am doing wrong. I have a feeling I maybe am just pointing to the wrong area of the file, but not sure where to go from here. Any help would be greatly appreciated.

Also, if there is an easier way to do this, I am open to anything. Thanks!

I have tried the script above, but no luck.

BigJ
  • 1
  • 2

1 Answers1

0

One key thing I notice is that you are trying to edit status as an attribute, when it is actually an element, so you'd want elem.text = "OPEN" I believe.

tripleee
  • 175,061
  • 34
  • 275
  • 318
Fisher8370
  • 47
  • 4
  • Yes I do need assistance. Any type of suggestions to get me going in the right direction would be great. Just want to populate the CKL file. – BigJ Aug 14 '23 at 15:44
  • In addition to that, the pastebin's structure is somewhat more complex than the OP's current code suggests. You'd want to find the `STATUS` element in the tree where the `VULN_ATTRIBUTE` whose text is `Vuln_Num` has an adjacent `ATTRIBUTE_DATA` which contains the string you're looking for. This is significantly more challenging than just finding a single element with that attribute. – tripleee Aug 14 '23 at 17:25
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 16 '23 at 13:46