Skip to content

Fail to run Linux command with double quotes using executeSystemCommand #858

Closed
@raine93

Description

@raine93

I am trying to execute a Linux command using executeSystemCommand but it unable to execute

Command:
/bin/sh -c "chown 0777 /var/test/123.sh"

tried to follow this solution but it will just give error 0777: "chown: command not found
https://stackoverflow.com/questions/71204716/how-should-esapi-executesystemcommand-sanitise-the-file-path-properly-to-satisfy

I put the full path of chown, it will also give the error 0777: "/usr/bin/chown: No such file or directory

Code:

Executor executor = ESAPI.executor();
File binSh = new File("/bin/sh").getCanonicalFile();

Codec codec = new UnixCodec();
List params = new ArrayList();

File workdir = new File( "/var");

params.add("-c");
params.add("\"chown");
params.add("0777");
params.add("/var/test/123.sh\"");

ExecuteResult result = executor.executeSystemCommand(binSh, params, workdir, codec, true, false);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions