|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing checks for the insecure use of SNMP. |
|
8 """ |
|
9 |
|
10 # |
|
11 # This is a modified version of the one found in the bandit package. |
|
12 # |
|
13 # Original Copyright (c) 2018 SolarWinds, Inc. |
|
14 # |
|
15 # SPDX-License-Identifier: Apache-2.0 |
|
16 # |
|
17 |
|
18 |
|
19 def getChecks(): |
|
20 """ |
|
21 Public method to get a dictionary with checks handled by this module. |
|
22 |
|
23 @return dictionary containing checker lists containing checker function and |
|
24 list of codes |
|
25 @rtype dict |
|
26 """ |
|
27 return { |
|
28 "Call": [ |
|
29 (checkInsecureVersion, ("S508",)), |
|
30 (checkWeakCryptography, ("S509",)), |
|
31 ], |
|
32 } |
|
33 |
|
34 |
|
35 def checkInsecureVersion(reportError, context, config): |
|
36 """ |
|
37 Function to check for the use of insecure SNMP version like |
|
38 v1, v2c. |
|
39 |
|
40 @param reportError function to be used to report errors |
|
41 @type func |
|
42 @param context security context object |
|
43 @type SecurityContext |
|
44 @param config dictionary with configuration data |
|
45 @type dict |
|
46 """ |
|
47 if context.callFunctionNameQual == "pysnmp.hlapi.CommunityData" and ( |
|
48 context.checkCallArgValue("mpModel", 0) |
|
49 or context.check_call_arg_value("mpModel", 1) |
|
50 ): |
|
51 # We called community data. Lets check our args |
|
52 reportError( |
|
53 context.node.lineno - 1, |
|
54 context.node.col_offset, |
|
55 "S508", |
|
56 "M", |
|
57 "H", |
|
58 ) |
|
59 |
|
60 |
|
61 def checkWeakCryptography(reportError, context, config): |
|
62 """ |
|
63 Function to check for the use of insecure SNMP cryptography |
|
64 (i.e. v3 using noAuthNoPriv). |
|
65 |
|
66 @param reportError function to be used to report errors |
|
67 @type func |
|
68 @param context security context object |
|
69 @type SecurityContext |
|
70 @param config dictionary with configuration data |
|
71 @type dict |
|
72 """ |
|
73 if ( |
|
74 context.callFunctionNameQual == "pysnmp.hlapi.UsmUserData" |
|
75 and context.callArgsCount < 3 |
|
76 ): |
|
77 reportError(context.node.lineno - 1, context.node.col_offset, "S509", "M", "H") |