JavaInjection & inputDifficulty 2/3
// src/main/java/com/example/admin/DiagnosticsController.java
package com.example.admin;
import java.io.IOException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class DiagnosticsController {
// Admin-only endpoint (see the security configuration)
@GetMapping("/admin/diagnostics/ping")
public String ping(@RequestParam String host) throws IOException {
String cmd = "ping -c 1 " + host;
Process p = Runtime.getRuntime().exec(new String[] {"sh", "-c", cmd});
return new String(p.getInputStream().readAllBytes());
}
}