[wp] 攻防世界 isc-07

首先看源代码里的这一段:

if (isset($_GET[id]) && floatval($_GET[id]) !== '1' && substr($_GET[id], -1) === '9') {
        include 'config.php';
        $id = mysql_real_escape_string($_GET[id]);
        $sql="select * from cetc007.user where id='$id'";
        $result = mysql_query($sql);
        $result = mysql_fetch_object($result);
      } else {
        $result = False;
        die();
      }

这里有几个要考虑的点
1.floatval( G E T [ i d ] ) ! = = 1 2. s u b s t r ( _GET[id]) !== '1' 2.substr( _GET[id], -1) === ‘9’,也就是字符串的最后一位为9
因为语句接下来是会用于sql语句查询的,所以可以构造如下的payload:

id=n'--9

经过测试当n=1时result=TRUE;
在这里插入图片描述

      if(!$result)die("<br >something wae wrong ! <br>");
      if($result){
        echo "id: ".$result->id."</br>";
        echo "name:".$result->user."</br>";
        $_SESSION['admin'] = True;
      }

此时我们获得了admin的权限
接下来对下面这段代码进行审计:

<?php
     if ($_SESSION['admin']) {
       $con = $_POST['con'];
       $file = $_POST['file'];
       $filename = "backup/".$file;

       if(preg_match('/.+\.ph(p[3457]?|t|tml)$/i', $filename)){
          die("Bad file extension");
       }else{
            chdir('uploaded');
           $f = fopen($filename, 'w');
           fwrite($f, $con);
           fclose($f);
       }
     }
     ?>

接下来应该是要绕过preg_match传个后门
flie=1.php/.就可以绕过
前面有个假目录,也要绕过也下:
file=…/1.php/.
接下来传一句话应该就能看到flag了,
但是不知咋滴我在攻防世界上模拟的环境里面就是无法写入1.php,疯狂404…
花了金币看了wp和我的做法差不多,按着wp里的方法复现也还是创建不了…
…算了,就这样吧

发布了32 篇原创文章 · 获赞 9 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40884727/article/details/100882275
今日推荐