Skip to content

Commit

Permalink
Add new plugin to check use of pyghmi (#803)
Browse files Browse the repository at this point in the history
* Add new plugin to check use of pyghmi

This patch set adds a new bandit plugin to check the use of pyghmi.

Signed-off-by: Tin Lam <tin@irrational.io>

* Fix example and polish te code.

Signed-off-by: Tin Lam <tin@irrational.io>

* Add new plug-in to check pyghmi

This patch set adds a new bandit plugin to check the use of the
pyghmi library, as the IPMI is known to be an insecured protocol.

Closes: #356
Signed-off-by: Tin Lam <tin@irrational.io>

Co-authored-by: Tin Lam <tin@irrational.io>
Co-authored-by: Eric Brown <browne@vmware.com>
  • Loading branch information
3 people committed Feb 7, 2022
1 parent 9131162 commit d1622bf
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions bandit/blacklists/imports.py
Expand Up @@ -212,6 +212,17 @@
| | | - Cryptodome.Util | |
+------+---------------------+------------------------------------+-----------+
B415: import_pyghmi
-------------------
An IPMI-related module is being imported. IPMI is considered insecure. Use
an encrypted protocol.
+------+---------------------+------------------------------------+-----------+
| ID | Name | Imports | Severity |
+======+=====================+====================================+===========+
| B415 | import_pyghmi | - pyghmi | high |
+------+---------------------+------------------------------------+-----------+
"""
from bandit.blacklists import utils
from bandit.core import issue
Expand Down Expand Up @@ -410,4 +421,16 @@ def gen_blacklist():
)
)

sets.append(
utils.build_conf_dict(
"import_pyghmi",
"B415",
issue.Cwe.CLEARTEXT_TRANSMISSION,
["pyghmi"],
"An IPMI-related module is being imported. IPMI is considered "
"insecure. Use an encrypted protocol.",
"HIGH",
)
)

return {"Import": sets, "ImportFrom": sets, "Call": sets}
5 changes: 5 additions & 0 deletions examples/pyghmi.py
@@ -0,0 +1,5 @@
from pyghmi.ipmi import command

cmd = command.Command(bmc="bmc",
userid="userid",
password="ZjE4ZjI0NTE4YmI2NGJjZDliOGY3ZmJiY2UyN2IzODQK")
8 changes: 8 additions & 0 deletions tests/functional/test_functional.py
Expand Up @@ -831,6 +831,14 @@ def test_no_blacklist_pycryptodome(self):
}
self.check_example("pycryptodome.py", expect)

def test_blacklist_pyghmi(self):
"""Test calling pyghmi methods"""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 0, "HIGH": 1},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 1, "HIGH": 1},
}
self.check_example("pyghmi.py", expect)

def test_snmp_security_check(self):
"""Test insecure and weak crypto usage of SNMP."""
expect = {
Expand Down

0 comments on commit d1622bf

Please sign in to comment.