-
-
Notifications
You must be signed in to change notification settings - Fork 616
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
Added snmp_security check plugin for various SNMP checks #403
Merged
Merged
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b1ede11
Added snmp_security check plugin for various SNMP checks
6c43605
Extracted each test into their own files
68e589a
Updates for linter
8dd44c5
Fixed style errors and added authNoPriv as a failure
72aba32
removed trailing --
c5b5458
more lint changes
fed11f4
Merge branch 'master' into BANDIT-355-snmpSecPlugin
lukehinds 9c2be03
Merge branch 'master' into BANDIT-355-snmpSecPlugin
ericwb 8c569f4
Merge branch 'master' into BANDIT-355-snmpSecPlugin
ericwb ff06ffe
Merge branch 'master' into BANDIT-355-snmpSecPlugin
ericwb e286114
Update README.rst
ericwb 8f2e079
Update snmp_security_check.py
ericwb ebf9e5a
Update bandit/plugins/snmp_security_check.py
ericwb 1f5d833
Update bandit/plugins/snmp_security_check.py
ericwb 489deee
Update bandit/plugins/snmp_security_check.py
ericwb 371601f
Update examples/snmp.py
ericwb 6eb2af9
Update doc/source/plugins/b508_snmp_insecure_version.rst
ericwb 78c3464
Update doc/source/plugins/b508_snmp_weak_cryptography.rst
ericwb ae02ab3
Update doc/source/plugins/b508_snmp_weak_cryptography.rst
ericwb 2ebf402
Update doc/source/plugins/b508_snmp_insecure_version.rst
ericwb b053aae
Update doc/source/plugins/b508_snmp_insecure_version.rst
ericwb 28c6238
Update doc/source/plugins/b508_snmp_weak_cryptography.rst
ericwb 178b344
Update doc/source/plugins/b508_snmp_insecure_version.rst
ericwb 83b849b
Update doc/source/plugins/b508_snmp_insecure_version.rst
ericwb a05f455
Update b508_snmp_weak_cryptography.rst
ericwb 6eca831
Update snmp_security_check.py
ericwb b530a43
Update snmp_security_check.py
ericwb 5f2a6e9
Merge branch 'master' into BANDIT-355-snmpSecPlugin
ericwb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding:utf-8 -*- | ||
# | ||
# Copyright (c) 2018 SolarWinds, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may | ||
# not use this file except in compliance with the License. You may obtain | ||
# a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
# License for the specific language governing permissions and limitations | ||
# under the License. | ||
import bandit | ||
from bandit.core import test_properties as test | ||
|
||
|
||
@test.checks("Call") | ||
@test.test_id('B508') | ||
def snmp_insecure_version_check(context): | ||
"""**B508: Checking for insecure SNMP versions** | ||
|
||
This test is for checking for the usage of insecure SNMP version like | ||
v1, v2c | ||
|
||
Using the pysnmp documentation: | ||
http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html | ||
|
||
Please update your code to use more secure versions of SNMP. | ||
|
||
.. versionadded:: 1.5.2 | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Jed-Giblin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if context.call_function_name_qual == 'CommunityData': | ||
# We called community data. Lets check our args | ||
if (context.check_call_arg_value("mpModel", 0) or | ||
context.check_call_arg_value("mpModel", 1)): | ||
return bandit.Issue( | ||
severity=bandit.MEDIUM, | ||
confidence=bandit.HIGH, | ||
text="The use of SNMPv1 and SNMPv2 is insecure. " | ||
"You should use SNMPv3 if able.", | ||
lineno=context.get_lineno_for_call_arg("CommunityData"), | ||
) | ||
|
||
|
||
@test.checks("Call") | ||
@test.test_id('B509') | ||
def snmp_crypto_check(context): | ||
|
||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""**B509: Checking for weak cryptography** | ||
|
||
This test is for checking for the usage of insecure SNMP cryptography: | ||
v3 using noAuthNoPriv. | ||
|
||
Using the pysnmp documentation: | ||
http://snmplabs.com/pysnmp/examples/hlapi/asyncore/sync/manager/cmdgen/snmp-versions.html | ||
|
||
Please update your code to use more secure versions of SNMP. For example: | ||
|
||
Instead of: | ||
`CommunityData('public', mpModel=0)` | ||
|
||
Use (Defaults to usmHMACMD5AuthProtocol and usmDESPrivProtocol | ||
`UsmUserData("securityName", "authName", "privName")` | ||
|
||
.. versionadded:: 1.5.2 | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Jed-Giblin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if context.call_function_name_qual == 'UsmUserData': | ||
if context.call_args_count < 3: | ||
return bandit.Issue( | ||
severity=bandit.MEDIUM, | ||
confidence=bandit.HIGH, | ||
text="You should not use SNMPv3 without encryption. " | ||
"noAuthNoPriv & authNoPriv is insecure", | ||
lineno=context.get_lineno_for_call_arg("UsmUserData"), | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
---------------------------- | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
B508: snmp_weak_cryptography | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
---------------------------- | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. automodule:: bandit.plugins.snmp_security_check | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. autofunction:: snmp_crypto_check | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:noindex: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--------------------------- | ||
B508: snmp_insecure_version | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--------------------------- | ||
|
||
.. automodule:: bandit.plugins.snmp_security_check | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
.. autofunction:: snmp_insecure_version_check | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:noindex: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from pysnmp.hlapi import CommunityData, UsmUserData | ||
|
||
# SHOULD FAIL | ||
a = CommunityData('public', mpModel=0) | ||
# SHOULD FAIL | ||
insecure = UsmUserData("securityName") | ||
# SHOULD FAIL | ||
auth_no_priv = UsmUserData("securityName","authName") | ||
# SHOULD PASS | ||
less_insecure = UsmUserData("securityName","authName","privName") | ||
ericwb marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to SPDX short form of the license.