FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add AvoidUsingBrokenHashAlgorithms by MJVL · Pull Request #1787 · PowerShell/PSScriptAnalyzer · GitHub

Add AvoidUsingBrokenHashAlgorithms - #1787

Merged
James Truher (JamesWTruher) merged 11 commits into
PowerShell:masterfrom
MJVL:hashRule
Aug 11, 2022
Merged

Add AvoidUsingBrokenHashAlgorithms#1787
James Truher (JamesWTruher) merged 11 commits into
PowerShell:masterfrom
MJVL:hashRule

Conversation

Michael Van Leeuwen (MJVL) commented Apr 9, 2022
edited
Loading

Copy link
Copy Markdown
Contributor

PR Summary

This adds a new rule: AvoidUsingBrokenHashAlgorithms.

This rule searches for use of SHA-1 or MD5 within -Algorithm parameters. This mainly serves to flag use with Get-FileHash, but also works for other cmdlets which may use the same parameter scheme. Should other algorithms in the future be deemed insecure, it would be trivial to add them.

At this point both of these algorithms are broken (Microsoft SDL has labeled them as such since 2009), so I think it would be worthwhile to flag these, such that new code doesn't use these algorithms except when needed for backwards compatability.

PR Checklist

Deleted user (ghost) commented Apr 9, 2022
edited by ghost
Loading

Copy link
Copy Markdown


All CLA requirements met.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks for the contribution and very good idea. I'll be giving it a test run but from a high level looks good otherwise. I might suggest something minor around the parameter parsin

Copy link
Copy Markdown
Contributor Author

Thanks for the contribution and very good idea. I'll be giving it a test run but from a high level looks good otherwise. I might suggest something minor around the parameter parsin

Cool, thanks! I'll fix anything as needed when you get a chance to review.

Comment thread docs/Rules/README.md Outdated
Context "When there are violations" {
It "detects broken hash algorithms violations" {
(Invoke-ScriptAnalyzer -ScriptDefinition 'Get-FileHash foo -Algorithm MD5' -Settings $settings).Count | Should -Be 1
(Invoke-ScriptAnalyzer -ScriptDefinition 'Get-FileHash foo -Algorithm SHA1' -Settings $settings).Count | Should -Be 1

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

An optional improvement would be to make it also work when no named parameters are used: Invoke-ScriptAnalyzer -ScriptDefinition 'Get-FileHash foo SHA1'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good idea. Can you see of any cases where this might false flag? Ie, someone opening a file that's named the same as a flagged hashing algorithm?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, because what you would do is check whether the first and second item in the array are not named parameters, i.e. do not start with dash and therefore you know for sure that the first one has to be the file name and the second one the algorithm

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good, I would just change severity from Warning. An optional suggestion on improving parsing but this could also just be a follow up PR as I'd rather want to wrap this up and ship it quickly in the next version of PSSA.
Docs question to Sean Wheeler (@sdwheeler) What do we do with the docs/Rules folder in this repo now? Do we have to replicate the same change here: https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/tree/main/reference/docs-conceptual/PSScriptAnalyzer/Rules

Co-authored-by: Christoph Bergmeister [MVP] <c.bergmeister@gmail.com>

Copy link
Copy Markdown
Contributor Author

Looks good, I would just change severity from Warning. An optional suggestion on improving parsing but this could also just be a follow up PR as I'd rather want to wrap this up and ship it quickly in the next version of PSSA. Docs question to Sean Wheeler (@sdwheeler) What do we do with the docs/Rules folder in this repo now? Do we have to replicate the same change here: https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/tree/main/reference/docs-conceptual/PSScriptAnalyzer/Rules

Thanks for the input! Fixed severities and unit tests based on your review comments.

I lack the bandwidth at the moment to improve the parsing, but it's something I could look into in the future. I think we should leave that as a follow-up PR like you said to get this to ship faster.

Copy link
Copy Markdown
Collaborator

Docs question to Sean Wheeler (@sdwheeler) What do we do with the docs/Rules folder in this repo now? Do we have to replicate the same change here: https://github.com/MicrosoftDocs/PowerShell-Docs-Modules/tree/main/reference/docs-conceptual/PSScriptAnalyzer/Rules

Yes. I just need to know when you are going to release and then I will copy the updated docs from the source repository to the docs repository. Eventually we want a CI job to do that automatically at release time. But for now, I can do it manually.

James Truher (JamesWTruher) added this to the 1.21 milestone Jul 25, 2022
James Truher (JamesWTruher) merged commit a154270 into PowerShell:master Aug 11, 2022
This file contains hidden or 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
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.

4 participants


Back | FazBrowse Home | New Git URL