Created
February 17, 2025 22:47
-
-
Save erangaeb/9a1ea7a43a0593cdda7737fdba8fbd8c to your computer and use it in GitHub Desktop.
nist control parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
# Input text (NIST 800-53 control AC-2 example) | |
nist_control_text = """ | |
a. Identifies and selects the following types of information system accounts to support organizational missions/business functions: [Assignment: organization-defined information system account types]; | |
b. Assigns account managers for information system accounts; | |
c. Establishes conditions for group and role membership; | |
d. Specifies authorized users of the information system, group and role membership, and access authorizations (i.e., privileges) and other attributes (as required) for each account; | |
e. Requires approvals by [Assignment: organization-defined personnel or roles] for requests to create information system accounts; | |
f. Creates, enables, modifies, disables, and removes information system accounts in accordance with [Assignment: organization-defined procedures or conditions]; | |
g. Monitors the use of information system accounts; | |
h. Notifies account managers: | |
1. When accounts are no longer required; | |
2. When users are terminated or transferred; and | |
3. When individual information system usage or need-to-know changes; | |
i. Authorizes access to the information system based on: | |
1. A valid access authorization; | |
2. Intended system usage; and | |
3. Other attributes as required by the organization or associated missions/business functions; | |
j. Reviews accounts for compliance with account management requirements [Assignment: organization-defined frequency]; and | |
k. Establishes a process for reissuing shared/group account credentials (if deployed) when individuals are removed from the group. | |
""" | |
# Function to convert text into structured questions | |
def generate_questions(control_id, text): | |
questions = [] | |
lines = text.strip().split("\n") | |
for line in lines: | |
# Match sub-items (e.g., "a.", "b.", "h.1", etc.) | |
match = re.match(r"([a-z]+|\d+)\.\s*(.*)", line.strip()) | |
if match: | |
key, value = match.groups() | |
formatted_question = f"{control_id}.{key} {value}" | |
questions.append(formatted_question) | |
else: | |
# Handle sub-items under main items (like h.1, h.2, etc.) | |
if questions and line.strip(): | |
last_question = questions.pop() | |
last_key = last_question.split(" ")[0] | |
formatted_question = f"{last_key}.{line.strip()}" | |
questions.append(formatted_question) | |
else: | |
continue | |
return questions | |
# Generate formatted questions for AC-2 | |
control_id = "AC-2" | |
questions = generate_questions(control_id, nist_control_text) | |
# Print formatted output | |
for q in questions: | |
print(q) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment