42 @param context security context object |
42 @param context security context object |
43 @type SecurityContext |
43 @type SecurityContext |
44 @param config dictionary with configuration data |
44 @param config dictionary with configuration data |
45 @type dict |
45 @type dict |
46 """ |
46 """ |
47 if config and "shell_injection_subprocess" in config: |
47 subProcessFunctionNames = ( |
48 subProcessFunctionNames = config["shell_injection_subprocess"] |
48 config["shell_injection_subprocess"] |
49 else: |
49 if config and "shell_injection_subprocess" in config else |
50 subProcessFunctionNames = SecurityDefaults[ |
50 SecurityDefaults["shell_injection_subprocess"] |
51 "shell_injection_subprocess"] |
51 ) |
52 |
52 |
53 if config and "shell_injection_shell" in config: |
53 shellFunctionNames = ( |
54 shellFunctionNames = config["shell_injection_shell"] |
54 config["shell_injection_shell"] |
55 else: |
55 if config and "shell_injection_shell" in config else |
56 shellFunctionNames = SecurityDefaults["shell_injection_shell"] |
56 SecurityDefaults["shell_injection_shell"] |
|
57 ) |
57 |
58 |
58 vulnerableFunctions = ['chown', 'chmod', 'tar', 'rsync'] |
59 vulnerableFunctions = ['chown', 'chmod', 'tar', 'rsync'] |
59 if ( |
60 if ( |
60 context.callFunctionNameQual in shellFunctionNames or |
61 (context.callFunctionNameQual in shellFunctionNames or |
61 (context.callFunctionNameQual in subProcessFunctionNames and |
62 (context.callFunctionNameQual in subProcessFunctionNames and |
62 context.checkCallArgValue('shell', 'True')) |
63 context.checkCallArgValue('shell', 'True'))) and |
|
64 context.callArgsCount >= 1 |
63 ): |
65 ): |
64 if context.callArgsCount >= 1: |
66 callArgument = context.getCallArgAtPosition(0) |
65 callArgument = context.getCallArgAtPosition(0) |
67 argumentString = '' |
66 argumentString = '' |
68 if isinstance(callArgument, list): |
67 if isinstance(callArgument, list): |
69 for li in callArgument: |
68 for li in callArgument: |
70 argumentString += ' {0}'.format(li) |
69 argumentString = argumentString + ' {0}'.format(li) |
71 elif isinstance(callArgument, str): |
70 elif isinstance(callArgument, str): |
72 argumentString = callArgument |
71 argumentString = callArgument |
73 |
72 |
74 if argumentString != '': |
73 if argumentString != '': |
75 for vulnerableFunction in vulnerableFunctions: |
74 for vulnerableFunction in vulnerableFunctions: |
76 if ( |
75 if ( |
77 vulnerableFunction in argumentString and |
76 vulnerableFunction in argumentString and |
78 '*' in argumentString |
77 '*' in argumentString |
79 ): |
78 ): |
80 lineNo = context.getLinenoForCallArg('shell') |
79 lineNo = context.getLinenoForCallArg('shell') |
81 if lineNo < 1: |
80 if lineNo < 1: |
82 lineNo = context.node.lineno |
81 lineNo = context.node.lineno |
83 offset = context.getOffsetForCallArg('shell') |
82 offset = context.getOffsetForCallArg('shell') |
84 if offset < 0: |
83 if offset < 0: |
85 offset = context.node.col_offset |
84 offset = context.node.col_offset |
86 reportError( |
85 reportError( |
87 lineNo - 1, |
86 lineNo - 1, |
88 offset, |
87 offset, |
89 "S609", |
88 "S609", |
90 "H", |
89 "H", |
91 "M", |
90 "M", |
92 context.callFunctionNameQual |
91 context.callFunctionNameQual |
93 ) |
92 ) |
|