Skip to main content

Lack of data validation - Non Sanitized Variables

Description

The system constructs system commands using inputs that can be manipulated externally, it does not correctly neutralize special elements that could modify the system command.

Impact

Execute unauthorized scripts.

Recommendation

Use whitelists or identifiers that are then transformed into static inputs to Call() calls.

Threat

Authenticated attacker from the Internet.

Expected Remediation Time

⌚ 30 minutes.

Score

Default score using CVSS 3.1. It may change depending on the context of the vulnerability.

Base

  • Attack vector: N
  • Attack complexity: H
  • Privileges required: N
  • User interaction: N
  • Scope: U
  • Confidentiality: L
  • Integrity: H
  • Availability: L

Temporal

  • Exploit code madurity: U
  • Remediation level: X
  • Report confidence: U

Result

  • Vector string: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:H/A:L/E:U/RL:X/RC:U
  • Score:
    • Base: 7.0
    • Temporal: 5.9
  • Severity:
    • Base: High
    • Temporal: Medium

Code Examples

Compliant code

System commands, when needed, are always built using validated or parameterized data

Private main ([] args){
String homeDirectory = System.getProperty("fixedPath");
Process process;
if (isWindows) {
process = Runtime.getRuntime().exec(String.format("cmd.exe /c dir %s", homeDirectory));
} else {
process = Runtime.getRuntime().exec(String.format("sh -c ls %s", homeDirectory));
}
StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;
}

Non compliant code

There are functionalities using unvalidated input data to build system commands

Private main (String userInput){
String homeDirectory = System.getProperty(user.profile);
Process process;
if (isWindows) {
process = Runtime.getRuntime().exec(String.format("cmd.exe /c dir %s", homeDirectory));
} else {
process = Runtime.getRuntime().exec(String.format("sh -c ls %s", homeDirectory));
}
StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), System.out::println);
Executors.newSingleThreadExecutor().submit(streamGobbler);
int exitCode = process.waitFor();
assert exitCode == 0;
}

Requirements