diff --git a/src/main/java/org/joychou/controller/PathTraversal.java b/src/main/java/org/joychou/controller/PathTraversal.java index 1976b01b..510c5f5e 100644 --- a/src/main/java/org/joychou/controller/PathTraversal.java +++ b/src/main/java/org/joychou/controller/PathTraversal.java @@ -7,7 +7,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; +import java.io.BufferedReader; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; @@ -23,7 +25,7 @@ public class PathTraversal { */ @GetMapping("/path_traversal/vul") public String getImage(String filepath) throws IOException { - return getImgBase64(filepath); + return newFile(filepath); } @GetMapping("/path_traversal/sec") @@ -34,7 +36,14 @@ public String getImageSec(String filepath) throws IOException { } return getImgBase64(filepath); } - + public static String newFile(String text) { + try { + File f = new File(text); + return readFile(f); + } catch (Exception e) { + return e.getMessage(); + } + } private String getImgBase64(String imgFile) throws IOException { logger.info("Working directory: " + System.getProperty("user.dir")); @@ -53,4 +62,20 @@ public static void main(String[] argv) throws IOException { String aa = new String(Files.readAllBytes(Paths.get("pom.xml")), StandardCharsets.UTF_8); System.out.println(aa); } + private static String readFile(File file) { + try { + FileReader fileStream = new FileReader(file); + BufferedReader bufferedReader = new BufferedReader(fileStream); + + String line = null; + StringBuilder sb = new StringBuilder(); + + while ((line = bufferedReader.readLine()) != null) { + sb.append(line).append("\n"); + } + return sb.toString(); + } catch (IOException e) { + return "file read failed: " + e; + } + } } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 66bdb978..fff382c1 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ -spring.datasource.url=jdbc:mysql://localhost:3306/java_sec_code?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC +spring.datasource.url=jdbc:mysql://j_mysql:3306/java_sec_code?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=UTC spring.datasource.username=root spring.datasource.password=woshishujukumima spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver