300-215 Question 96
Single answerDuring a forensic investigation, you are presented with the following code snippet found in a compromised system:
function checkUserInput(input) {
let evalResult;
try {
evalResult = eval(input);
} catch (e) {
console.log('Error executing input:', e);
}
return evalResult;
}
What type of code does this snippet represent?
- A
Code demonstrating a potential Command Injection vulnerability
- B
Code demonstrating a potential SQL Injection vulnerability
- C
Code demonstrating a potential Cross-Site Scripting (XSS) vulnerability
- D
Code demonstrating a secure implementation of user input handling
Show answer and explanation
Correct answer: A
Explanation
The eval() function is highly dangerous when used with user-supplied input because it can execute arbitrary code. This is a classic example of a potential Command Injection vulnerability. Proper validation and sanitization of user inputs should be implemented instead of directly executing them.
- A. Correct.
The use of the
eval()function to directly execute user-supplied input is a common pattern for Command Injection vulnerabilities. An attacker could craft malicious input to execute arbitrary system commands or scripts. - B. Incorrect.
SQL Injection vulnerabilities typically involve improper handling of user inputs in SQL queries. This snippet does not include any SQL-related code.
- C. Incorrect.
Cross-Site Scripting (XSS) vulnerabilities are related to the injection of malicious scripts into web pages. This snippet does not involve HTML or browser-side script execution.
- D. Incorrect.
The use of
eval()with user input is inherently insecure. It allows for arbitrary code execution, which is not a secure implementation of user input handling.