Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding STIG baselines for Windows Server 2022 and Windows 11 #76

Merged
merged 22 commits into from
Aug 19, 2024

Conversation

eemperor
Copy link
Member

No description provided.

@eemperor eemperor marked this pull request as ready for review August 13, 2024 18:30
@eemperor eemperor requested a review from a team August 13, 2024 18:31
"".join(line.split("=")[1].split(",")[1:])
.strip()
.strip('"')
.replace('""', "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you remember what required this extra replace()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the GptTmpl.inf file within each STIG component from the STIG GPO package.

The actual line is below:

MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText=7,You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.,By using this IS (which includes any device attached to this IS)"," you consent to the following conditions:,-The USG routinely intercepts and monitors communications on this IS for purposes including"," but not limited to"," penetration testing"," COMSEC monitoring"," network operations and defense"," personnel misconduct (PM)"," law enforcement (LE)"," and counterintelligence (CI) investigations.,-At any time"," the USG may inspect and seize data stored on this IS.,-Communications using"," or data stored on"," this IS are not private"," are subject to routine monitoring"," interception"," and search"," and may be disclosed or used for any USG-authorized purpose.,-This IS includes security measures (e.g."," authentication and access controls) to protect USG interests--not for your personal benefit or privacy.,-Notwithstanding the above"," using this IS does not constitute consent to PM"," LE or CI investigative searching or monitoring of the content of privileged communications"," or work product"," related to personal representation or services by attorneys"," psychotherapists"," or clergy"," and their assistants. Such communications and work product are private and confidential. See User Agreement for details.

The "," would become "" using the current script. I added the extra replace() to clean things up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. That's interesting. It seems like the double quotes are used to escape the comma. Unescaped commas appear to indicate a newline, perhaps? Maybe we actually want to keep those commas, except the first one... What if we just do this?

Suggested change
.replace('""', "")
",".join(line.split("=")[1].split(",")[1:])
.strip()
.strip('"')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion seems to preserve the ",".

You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.,By using this IS (which includes any device attached to this IS)"," you consent to the following conditions:,-The USG routinely intercepts and monitors communications on this IS for purposes including"," but not limited to"," penetration testing"," COMSEC monitoring"," network operations and defense"," personnel misconduct (PM)"," law enforcement (LE)"," and counterintelligence (CI) investigations.,-At any time"," the USG may inspect and seize data stored on this IS.,-Communications using"," or data stored on"," this IS are not private"," are subject to routine monitoring"," interception"," and search"," and may be disclosed or used for any USG-authorized purpose.,-This IS includes security measures (e.g."," authentication and access controls) to protect USG interests--not for your personal benefit or privacy.,-Notwithstanding the above"," using this IS does not constitute consent to PM"," LE or CI investigative searching or monitoring of the content of privileged communications"," or work product"," related to personal representation or services by attorneys"," psychotherapists"," or clergy"," and their assistants. Such communications and work product are private and confidential. See User Agreement for details.

Assuming, I using the suggestions correctly. This is what I'm testing with:

policy["value"] = (
                ",".join(line.split("=")[1].split(",")[1:])
                .strip()
                .strip('"')
            )

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I figure the last .strip('"') would remove the double quotes before the join but it's not doing it for some reason.

Copy link
Member

@lorengordon lorengordon Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhhhh, this is MULTISZ! The salt lgpo module didn't handle that type correctly when I first converted to use the python native module. So, we just wrote this entry as SZ, see:

- key: Computer\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText
policy_type: regpol
value: >-
You are accessing a U.S. Government (USG) Information System (IS) that is
provided for USG-authorized use only. By using this IS (which includes any
device attached to this IS), you consent to the following conditions: -The
USG routinely intercepts and monitors communications on this IS for
purposes including, but not limited to, penetration testing, COMSEC
monitoring, network operations and defense, personnel misconduct (PM), law
enforcement (LE), and counterintelligence (CI) investigations. -At any
time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are
subject to routine monitoring, interception, and search, and may be
disclosed or used for any USG-authorized purpose. -This IS includes
security measures (e.g., authentication and access controls) to protect
USG interests--not for your personal benefit or privacy. -Notwithstanding
the above, using this IS does not constitute consent to PM, LE or CI
investigative searching or monitoring of the content of privileged
communications, or work product, related to personal representation or
services by attorneys, psychotherapists, or clergy, and their assistants.
Such communications and work product are private and confidential. See
User Agreement for details.
vtype: SZ

Hmm. I'm not sure that the implementation here is doing the right thing for MULTISZ.... We're actually just treating it the same as SZ anyway, using _encode_string(). The salt upstream module has been updated for MULTISZ since our initial conversion. It uses a list of strings as the value:

https://github.com/saltstack/salt/blob/18ca4fdfa9e9c16fb10006f1221254707bece308/salt/modules/win_lgpo_reg.py#L352-L355

Tracing through the code, here's how they join the list of strings to encode it for the regpol:

https://github.com/saltstack/salt/blob/master/salt/utils/win_lgpo_reg.py#L419-L439

Copy link
Member

@lorengordon lorengordon Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the following:

policy["value"] = (
                ",".join(line.split("=")[1].split(",")[1:])
                .strip()
                .strip('"')
                .replace('","', ',')
                .replace(',-', '\n-')
            )

Oh that works. Getting very close. The replace on ',-' misses at least one unescaped comma, that I see. We can close the gap, maybe, by splitting on '","', then just replacing ',' for \n on each segment, and joining again on ",". I'll play around with the python for that locally... Gimme a bit...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try this:

",".join([segment.replace(",", "\n") for segment in ",".join(line.split("=")[1].split(",")[1:]).split('","')]).strip().strip('"')

Which is giving me this:

'You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only.\nBy using this IS (which includes any device attached to this IS), you consent to the following conditions:\n-The USG routinely intercepts and monitors communications on this IS for purposes including, but not limited to, penetration testing, COMSEC monitoring, network operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence (CI) investigations.\n-At any time, the USG may inspect and seize data stored on this IS.\n-Communications using, or data stored on, this IS are not private, are subject to routine monitoring, interception, and search, and may be disclosed or used for any USG-authorized purpose.\n-This IS includes security measures (e.g., authentication and access controls) to protect USG interests--not for your personal benefit or privacy.\n-Notwithstanding the above, using this IS does not constitute consent to PM, LE or CI investigative searching or monitoring of the content of privileged communications, or work product, related to personal representation or services by attorneys, psychotherapists, or clergy, and their assistants. Such communications and work product are private and confidential. See User Agreement for details.'

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace(",", "\n") for segment in ",".join(line.split("=

Okay. This caught that first unescaped comma.

Here's the new yaml and resulting banner:

- key: MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText
  policy_type: regpol
  value: 'You are accessing a U.S. Government (USG) Information System (IS) that is
    provided for USG-authorized use only.

    By using this IS (which includes any device attached to this IS), you consent
    to the following conditions:

    -The USG routinely intercepts and monitors communications on this IS for purposes
    including, but not limited to, penetration testing, COMSEC monitoring, network
    operations and defense, personnel misconduct (PM), law enforcement (LE), and counterintelligence
    (CI) investigations.

    -At any time, the USG may inspect and seize data stored on this IS.

    -Communications using, or data stored on, this IS are not private, are subject
    to routine monitoring, interception, and search, and may be disclosed or used
    for any USG-authorized purpose.

    -This IS includes security measures (e.g., authentication and access controls)
    to protect USG interests--not for your personal benefit or privacy.

    -Notwithstanding the above, using this IS does not constitute consent to PM, LE
    or CI investigative searching or monitoring of the content of privileged communications,
    or work product, related to personal representation or services by attorneys,
    psychotherapists, or clergy, and their assistants. Such communications and work
    product are private and confidential. See User Agreement for details.'

banner2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhhhhh, this is MULTISZ! The salt lgpo module didn't handle that type correctly when I first converted to use the python native module. So, we just wrote this entry as SZ, see:

- key: Computer\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\LegalNoticeText
policy_type: regpol
value: >-
You are accessing a U.S. Government (USG) Information System (IS) that is
provided for USG-authorized use only. By using this IS (which includes any
device attached to this IS), you consent to the following conditions: -The
USG routinely intercepts and monitors communications on this IS for
purposes including, but not limited to, penetration testing, COMSEC
monitoring, network operations and defense, personnel misconduct (PM), law
enforcement (LE), and counterintelligence (CI) investigations. -At any
time, the USG may inspect and seize data stored on this IS.
-Communications using, or data stored on, this IS are not private, are
subject to routine monitoring, interception, and search, and may be
disclosed or used for any USG-authorized purpose. -This IS includes
security measures (e.g., authentication and access controls) to protect
USG interests--not for your personal benefit or privacy. -Notwithstanding
the above, using this IS does not constitute consent to PM, LE or CI
investigative searching or monitoring of the content of privileged
communications, or work product, related to personal representation or
services by attorneys, psychotherapists, or clergy, and their assistants.
Such communications and work product are private and confidential. See
User Agreement for details.
vtype: SZ

Hmm. I'm not sure that the implementation here is doing the right thing for MULTISZ.... We're actually just treating it the same as SZ anyway, using _encode_string(). The salt upstream module has been updated for MULTISZ since our initial conversion. It uses a list of strings as the value:

https://github.com/saltstack/salt/blob/18ca4fdfa9e9c16fb10006f1221254707bece308/salt/modules/win_lgpo_reg.py#L352-L355

Tracing through the code, here's how they join the list of strings to encode it for the regpol:

https://github.com/saltstack/salt/blob/master/salt/utils/win_lgpo_reg.py#L419-L439

Okay. Yeah, I kind of dug into this but it seemed more involved and would require more effort. I just re-used _encode_string() to handle MULTISZ. Maybe in the next update. 🙂

lorengordon
lorengordon previously approved these changes Aug 16, 2024
@eemperor eemperor merged commit 54af8bd into plus3it:master Aug 19, 2024
6 checks passed
@eemperor eemperor deleted the win2022 branch August 19, 2024 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants