Injection
Overview
Injection vulnerabilities, such as SQL injection and shell injection, are common security threats in software applications. They occur when untrusted data is sent to an interpreter as part of a command or query, leading to unauthorized access or manipulation of data. Bugz provides a set of detection features to identify potential injection vulnerabilities in Python code. These features analyze code for patterns indicative of injection attacks and provide developers with insights into potential security risks.
Vulnerabilities
4001: paramiko_calls
- Description: Detects possible shell injection via Paramiko call, advising users to sanitize inputs properly.
- Severity: Medium
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4002: subprocess_popen_with_shell_equals_true
- Description: Tests for the use of popen with
shell=True, indicating potential shell injection vulnerabilities. - Severity: Low to High
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4003: subprocess_without_shell_equals_true
- Description: Tests for subprocess usage without
shell=True, highlighting potential shell injection vulnerabilities. - Severity: Low
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4004: any_other_function_with_shell_equals_true
- Description: Detects any function calls with
shell=True, indicative of potential shell injection vulnerabilities. - Severity: Medium
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4005: start_process_with_a_shell
- Description: Tests for starting a process with a shell, indicating potential shell injection vulnerabilities.
- Severity: Low
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4006: start_process_with_no_shell
- Description: Tests for starting a process without a shell, indicating potential shell injection vulnerabilities.
- Severity: Low
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4007: start_process_with_partial_path
- Description: Tests for starting a process with a partial path, indicating potential shell injection vulnerabilities.
- Severity: Low
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4008: hardcoded_sql_expressions
- Description: Tests for SQL injection vulnerabilities by detecting hardcoded SQL expressions.
- Severity: Medium to Low
- CWE: CWE-89 (opens in a new tab)
- Reference Links:
4009: linux_commands_wildcard_injection
- Description: Tests for wildcard injection vulnerabilities in Linux commands.
- Severity: Low to High
- CWE: CWE-78 (opens in a new tab)
- Reference Links:
4010: django_extra_used
- Description: Detects potential SQL injection through the Django ORM
extrafunction. - Severity: Medium
- CWE: CWE-89 (opens in a new tab)
- Reference Links:
4011: django_rawsql_used
- Description: Detects potential SQL injection through the Django ORM
RawSQLfunction. - Severity: Medium
- CWE: CWE-89 (opens in a new tab)
- Reference Links:
4012: logging_config_insecure_listen
- Description: Tests for insecure use of
logging.config.listenfunction. - Severity: Medium
- CWE: CWE-94 (opens in a new tab)
- Reference Links:
Best Practices
- Input Validation and Sanitization: Always validate and sanitize user inputs before using them in commands or queries. Validate input data to ensure it conforms to expected formats, and sanitize inputs to remove or escape any potentially harmful characters.
- Use Parameterized Queries: When working with databases, use parameterized queries or prepared statements instead of concatenating user inputs directly into SQL queries. Parameterized queries separate data from the query itself, preventing injection attacks.
- Avoid Shell Commands: Minimize the use of shell commands in Python applications, especially when dealing with user inputs. Instead, leverage built-in Python libraries like
subprocessoroswith appropriate arguments to execute commands securely. - Limit Privileges: Restrict the privileges of the application or service executing commands or queries. Ensure that it has only the necessary permissions to perform its intended tasks, reducing the potential impact of injection attacks.
- Regular Security Audits: Conduct regular security audits and code reviews to identify and address injection vulnerabilities in the codebase. Use automated tools like Bugz to scan code for potential security risks and follow up with manual reviews for comprehensive coverage.
- Educate Developers: Educate developers about the risks associated with injection vulnerabilities and train them to write secure code. Provide resources and guidelines on secure coding practices, including input validation, parameterized queries, and secure command execution.
By following these best practices and leveraging BugZ's injection detection features, developers can enhance the security posture of their Python applications and protect against injection attacks.