명령어 삽입
Improper Neutralization of Special Elements used in a Command ('Command Injection')
Last updated
Improper Neutralization of Special Elements used in a Command ('Command Injection')
Last updated
import java.io.IOException;
import java.io.InputStream;
@RequestMapping("/runCommand")
public String runCommand(@RequestParam String commandParam) throws IOException {
Process process = Runtime.getRuntime().exec("sh -c " + commandParam);
InputStream inputStream = process.getInputStream();
// 결과 처리
return "Executed";
}import java.io.IOException;
import java.util.List;
@RequestMapping("/runCommand")
public String runCommand(@RequestParam String commandParam) throws IOException {
// 허용된 명령어 제한 리스트 작성
List<String> allowedCommands = List.of("ls", "date", "whoami");
if (!allowedCommands.contains(commandParam)) {
return "Invalid command";
}
ProcessBuilder processBuilder = new ProcessBuilder(commandParam);
Process process = processBuilder.start();
return "Executed";
}