Created
December 3, 2022 05:34
-
-
Save pich4ya/c046378ed8ae8705147dad7ec9e0f6fc to your computer and use it in GitHub Desktop.
OS Command Injection Vulnerability in Java Spring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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