diff --git a/src/main/java/org/sasanlabs/service/vulnerability/commandInjection/CommandInjectionVulnerability.java b/src/main/java/org/sasanlabs/service/vulnerability/commandInjection/CommandInjectionVulnerability.java index 0c7a2c1e..d5a536e2 100644 --- a/src/main/java/org/sasanlabs/service/vulnerability/commandInjection/CommandInjectionVulnerability.java +++ b/src/main/java/org/sasanlabs/service/vulnerability/commandInjection/CommandInjectionVulnerability.java @@ -3,6 +3,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -46,12 +47,18 @@ public class CommandInjectionVulnerability implements ICustomVulnerableEndPoint{ public ResponseBean> getVulnerablePayloadLevelUnsecure( ParameterBean parameterBean) throws ServiceApplicationException, IOException { - Process process = Runtime.getRuntime().exec("ping " + parameterBean.getQueryParamKeyValueMap().get(IP_ADDRESS) + " -c 2"); - (new BufferedReader(new InputStreamReader(process.getInputStream()))).lines().forEach(val -> LOGGER.info(val)); - (new BufferedReader(new InputStreamReader(process.getErrorStream()))).lines().forEach(val -> LOGGER.info(val)); - - return new ResponseBean>(new GenericVulnerabilityResponseBean()); + boolean isWindows = System.getProperty("os.name") + .toLowerCase().startsWith("windows"); + Process process; + if(!isWindows) { + process = new ProcessBuilder(new String[] { "bash", "-c", "ping -c 2 " + parameterBean.getQueryParamKeyValueMap().get(IP_ADDRESS)}).redirectErrorStream(true).start(); + } else { + process = new ProcessBuilder(new String[] { "cmd", "/c", "ping -n 2 " + parameterBean.getQueryParamKeyValueMap().get(IP_ADDRESS)}).redirectErrorStream(true).start(); + } + StringBuilder response = new StringBuilder(); + try(BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { + bufferedReader.lines().forEach(val -> response.append(val).append("\n")); + } + return new ResponseBean>(new GenericVulnerabilityResponseBean(response.toString(), true)); } - - }