// [CRUCIBLE-SEED]
// category: command_injection
// severity: critical
// language: java
// expected: Command injection via Runtime.exec array form with unsanitized user argument

import java.io.*;
import javax.servlet.http.*;

public class PingServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        String host = req.getParameter("host");
        // Vulnerable: passing through shell with -c allows injection
        String[] cmd = {"/bin/sh", "-c", "ping -c 4 " + host};
        Process proc = Runtime.getRuntime().exec(cmd);
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(proc.getInputStream()));
        PrintWriter out = resp.getWriter();
        String line;
        while ((line = reader.readLine()) != null) {
            out.println(line + "<br>");
        }
    }
}
