Vulnerable-Web-Application CVE semgrep_id:PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec:25:25
Improper control of generation of code ('Code Injection')
Ссылка на строку:
Описание уязвимости
Тип: Code Injection (CWE-94)
Описание: Выполнение некостантных команд может привести к внедрению команд (Command Injection).
Категория: SAST (Static Application Security Testing)
Критичность: Critical
Файл: CommandExecution/CommandExec-1.php
Строка: 25
Проблема
В строке echo shell_exec($_GET["username"])
используется функция shell_exec
, которая выполняет команду, переданную ей в качестве аргумента. В данном случае аргумент берется из пользовательского ввода ($_GET["username"]
), что может привести к выполнению произвольных команд на сервере.
Варианты исправления
-
Использование безопасных альтернатив:
if(isset($_GET["username"])){ echo htmlspecialchars($_GET["username"]); }
-
Валидация и очистка входных данных:
function validateInput($input) { $input = trim($input); $input = stripslashes($input); $input = htmlspecialchars($input); return $input; } if(isset($_GET["username"])){ $username = validateInput($_GET["username"]); echo $username; }
-
Ограничение доступа к функциям выполнения команд: Если необходимо использовать функции выполнения команд, ограничьте доступ к ним только для доверенных пользователей или определенных условий.
Ссылки на статьи
- CWE-94: Improper Control of Generation of Code ('Code Injection')
- OWASP A03:2021 - Injection
- OWASP A1:2017 - Injection
Описание:
Executing non-constant commands. This can lead to command injection.Исходный JSON:
{
"id": "934b341362739a44db84d4cd15b2ffe2108a3515b387cb5bad6ab5a1e5bb00b0",
"category": "sast",
"name": "Improper control of generation of code ('Code Injection')",
"description": "Executing non-constant commands. This can lead to command injection.",
"cve": "semgrep_id:PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec:25:25",
"severity": "Critical",
"scanner": {
"id": "semgrep",
"name": "Semgrep"
},
"location": {
"file": "CommandExecution/CommandExec-1.php",
"start_line": 25
},
"identifiers": [
{
"type": "semgrep_id",
"name": "PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec",
"value": "PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec"
},
{
"type": "cwe",
"name": "CWE-94",
"value": "94",
"url": "https://cwe.mitre.org/data/definitions/94.html"
},
{
"type": "owasp",
"name": "A03:2021 - Injection",
"value": "A03:2021"
},
{
"type": "owasp",
"name": "A1:2017 - Injection",
"value": "A1:2017"
},
{
"type": "phpcs_security_audit_source",
"name": "PHPCS Security Audit Test ID PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec",
"value": "PHPCS_SecurityAudit.BadFunctions.SystemExecFunctions.WarnSystemExec"
}
]
}
```