-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjdef.py
More file actions
executable file
·156 lines (136 loc) · 5.97 KB
/
jdef.py
File metadata and controls
executable file
·156 lines (136 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/python
print "\n Basic Junos OVAL Content Creator."
print "Copyright (c) 2013, C3isecurity."
print "All rights reserved."
print "version 0.2.1\n"
# The program creates a basic, very simple, OVAL defintion content based on
# the Open Vulnerability Assessment Lanaguage (OVAL) specifications. It is
# part of the Security Content Automation Protocol (SCAP). The program
# builds a XML defintion file for Juniper Junos.
# import for date and time
import datetime
import time
# import for argument
from sys import argv
# Date and timestamp of defintion
now = datetime.datetime.now()
def_timestamp = now.strftime("%Y-%m-%dT%H:%M:%S")
def_timestamp_line = "\t\t\t\t<submitted date=\"%s\">\n" % def_timestamp
oval_timestamp = now.strftime("%Y-%m-%dT%H:%M:%S")
oval_timestamp_line = " <oval:timestamp>%s</oval:timestamp>\n" % oval_timestamp
#script, filename = argv
# Write to file name filename.xml
target = open ("filename.xml", 'w')
# Defintion creation. Input need to create defintion.
# input def_id used the definition number
# INPUT needs to global
print "Definition ID:"
def_id = raw_input("> ")
def_id_line = "\t<definition class=\"compliance\" id=\"oval:com.c3isecurity.oval:def:%s\" version=\"0\">\n" % def_id
# input Def Title
print "\nDefinition Title:"
def_title = raw_input("> ")
def_title_line = "\t\t<title>%s</title>\n" % def_title
# input Def_CCE ref_id
print "\nCCE ID:"
def_CCE_ref = raw_input("> ")
def_CCE_ref_line = "\t\t<reference source=\"CCE\" ref_id=\"%s\" ref_url=\"http://www.c3isecurity.com/home/junos-hardening\"/>\n" % def_CCE_ref
# input Definition Comment
print "\nDescription"
def_description = raw_input("> ")
def_description_line = "\t\t<description>%s</description>\n" % def_description
# input comment
print "\nComment:"
def_comment = raw_input("> ")
def_comment_line = "\t\t<criterion comment=\"%s\" test_ref=\"oval:com.c3isecurity.oval:tst:%s\"/>\n" % (def_comment, def_id)
# - - - - - - Functions - - - - - - - #
def preamble ():
# XML file preamble function
target.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
target.write("""<oval_definitions xsi:schemaLocation=\"http://oval.mitre.org/XMLSchema/oval-definitions-5 oval-defintions-schema.xsd
http://oval.mitre.org/XMLSchema/oval-definitions-5#netconf netconf-definitions-schema.xsd
http://oval.mitre.org/XMLSchema/oval-common-5 oval-common-schema.xsd\"
xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:oval=\"http://oval.mitre.org/XMLSchema/oval-common-5\"
xmlns:oval-def=\"http://oval.mitre.org/XMLSchema/oval-definitions-5\">\n""")
target.write(""" <generator>
<oval:product_name>Juniper Junos OVAL Creator</oval:product_name>
<oval:schema_version>5.10</oval:schema_version>\n """)
target.write(oval_timestamp_line)
target.write(" </generator>\n")
def definition ():
#-----------DEFINITION function----------------#
target.write("<definitions>\n")
target.write(def_id_line)
target.write("\t\t<metadata>\n")
target.write(def_title_line)
target.write("\t\t\t<affected family=\"junos\">\n")
target.write("\t\t\t\t<product>Juniper JUNOS</product>\n")
target.write("\t\t\t</affected>\n")
target.write(def_CCE_ref_line)
target.write(def_description_line)
target.write("\t\t<oval_repository>\n")
target.write("\t\t\t<dates>\n")
target.write(def_timestamp_line)
target.write("\t\t\t\t<contributor organization=\"C3isecurity\">Luis Nunez</contributor>\n")
target.write("\t\t\t\t</submitted>\n")
target.write("\t\t\t</dates>\n")
target.write("\t\t\t<status>INITIAL SUBMISSION</status>\n")
target.write("\t\t</oval_repository>\n")
target.write("\t</metadata>\n")
target.write("\t<criteria operator=\"AND\">\n")
target.write(def_comment_line)
target.write("\t</criteria>\n")
target.write("\t</definition>\n")
target.write("</definitions>\n")
#-----------DEFINITIONS----------------#
def def_test():
target.write("<tests>\n")
config_test_line = "\t<config_test xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5#netconf\" check=\"at least one\" check_existence=\"at_least_one_exists\" comment=\"%s\" id=\"oval:com.c3isecurity.oval:tst:%s\" version=\"0\">\n" % (def_comment, def_id)
target.write(config_test_line)
object_ref_line = "\t\t<object object_ref=\"oval:com.c3isecurity.oval:obj:%s\"/>" % def_id
target.write("\t</config_test>\n")
target.write("</tests>\n")
def def_objects ():
target.write("<objects>\n")
config_object_line = "\t<config_object xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5#netconf\" comment=\"%s\" id=\"oval:org.c3isecurity.oval:obj:%s\" version=\"0\">\n" % (def_comment, def_id)
target.write(config_object_line)
# input Xpath
print "\nXpath of command"
xpath_location = raw_input(">")
xpath_location_line = "\t\t<xpath>%s</xpath>\n" % xpath_location
#<xpath>//protocols/ospf/area/interface/authentication/md5/key/text()</xpath>
target.write(xpath_location_line)
target.write("\t</config_object>\n")
target.write("</objects>\n")
def def_state ():
target.write("<states>\n")
config_state_line = "\t<config_state xmlns=\"http://oval.mitre.org/XMLSchema/oval-definitions-5#netconf\" comment=\"%s\" id=\"oval:com.c3isecurity.oval:ste:%s\" version=\"0\">\n" % (def_comment, def_id)
target.write(config_state_line)
# input value
print "\nValue: "
state_value = raw_input("> ")
state_value_line = "\t\t<value_of datatype=\"string\" operation=\"pattern match\">%s</value_of>\n" % state_value
target.write(state_value_line)
target.write("\t</config_state>\n")
target.write("\t</states>\n")
def def_rearmatter():
target.write("</oval_definitions>")
# - - - Start writing to file - - - #
preamble ()
definition ()
def_test ()
def_objects ()
def_state ()
def_rearmatter()
# Close file
target.close()
# Open filename.xml
def_file = open("filename.xml")
# Print the contents of file
print "\n"
print "-------------------------------------------"
print "Contents of file\n"
print def_file.read()
print "--------------------------------------------"