Skip to content

Instantly share code, notes, and snippets.

@pich4ya
Created December 3, 2022 05:34
Show Gist options
  • Save pich4ya/c046378ed8ae8705147dad7ec9e0f6fc to your computer and use it in GitHub Desktop.
Save pich4ya/c046378ed8ae8705147dad7ec9e0f6fc to your computer and use it in GitHub Desktop.
OS Command Injection Vulnerability in Java Spring
@RestController
public class ReportController {
@PostMapping("/report")
public ResponseEntity<String> generateReport(@RequestParam String report_name) {
String cmd = "bash -c \"generate_report.sh " + report_name + "\"";
try {
Process proc = Runtime.getRuntime().exec(cmd);
int exitValue = proc.waitFor();
if (exitValue == 0) {
return new ResponseEntity<>("Report generated successfully", HttpStatus.OK);
} else {
return new ResponseEntity<>("Error generating report", HttpStatus.INTERNAL_SERVER_ERROR);
}
} catch (Exception e) {
// Log exception
return new ResponseEntity<>("Error generating report", HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment