Reputation: 1
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
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.
Upvotes: 0
Views: 245
Reputation: 57
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.
Upvotes: 0