首页 > 编程语言 >PHP代码审计——Day6-Frost Pattern

PHP代码审计——Day6-Frost Pattern

时间:2024-04-07 21:34:34浏览次数:464  
标签:字符 .. Day6 Pattern Frost token action PHP data

漏洞解析

class TokenStorage {
    public function performAction($action, $data) {
        switch ($action) {
            case 'create':
                $this->createToken($data);
                break;
            case 'delete':
                $this->clearToken($data);
                break;
            default:
                throw new Exception('Unknown action');
        }
    }

    public function createToken($seed) {
        $token = md5($seed);
        file_put_contents('/tmp/tokens/' . $token, '...data');
    }

    public function clearToken($token) {
        $file = preg_replace("/[^a-z.-_]/", "", $token);
        unlink('/tmp/tokens/' . $file);
    }
}

$storage = new TokenStorage();
$storage->performAction($_GET['action'], $_GET['data']);

考察点:任意文件删除漏洞
正则表达式不严谨:

preg_replace("/[^a-z.-_]/", "", $token)

使用 PHP 的 preg_replace 函数来执行正则表达式替换操作。将字符串变量 $token 中的非小写字母、点号、短横线和下划线的字符替换为空字符串,即删除除了小写字母、点号、短横线和下划线之外的所有字符。

开发者本来的意思应该是将a-z.-_这三个符号外的全部替换为空,这样../../../xx就无法使用,防止进行路径穿越。但是没对-进行转义,所以匹配范围就变成了a-z.字符到_字符之间的所有字符。

因此,攻击者还是可以使用点和斜杠符号进行路径穿越,最终删除任意文件。

当action是delete的时候,会调用clearToken函数,传入参数可以含., /,构造payload:action=delete&data=../../config.php

标签:字符,..,Day6,Pattern,Frost,token,action,PHP,data
From: https://www.cnblogs.com/smile2333/p/18119968

相关文章

  • [Microservices] Microservices Anti-Patterns
    Whiletherearemanypatternsfordoingmicroserviceswell,anequallysignificantnumberofpatternsexistthatcanquicklygetanydevelopmentteamintotrouble.Thefollowingaresomeofthedon’tswhiledevelopingmicroservices:Don’tbuildmicroservi......
  • preg_replace($pattern, $replacement, $subject)函数
    参数:$pattern:正则表达式模式,用于搜索匹配的内容。$replacement:要替换匹配内容的字符串。$subject:被搜索的字符串。这个函数有个“/e”漏洞,“/e”修正符使preg_replace()将replacement参数当作PHP代码进行执行。如果这么做要确保replacement构成一个合法......
  • 设计模式|状态机模式(State Machine Pattern)
    文章目录结构使用步骤示例使用状态机的场景常见面试题状态机模式(StateMachinePattern)是一种用于描述对象的行为软件设计模式,属于行为型设计模式。在状态机模式中,对象的行为取决于其内部状态,并且在不同的状态下,对象可能会有不同的行为。状态机模式通常涉及定义一组状......
  • 【每日C语言】Day6——变量与操作符
    目录2.4变量4.1变量的创建4.2 变量的分类2.5算术操作符:+、-、*、/、%5.1+和-5.2 *5.3 /5.4%2.6赋值操作符:=和复合赋值6.1 连续赋值6.2复合赋值符2.7单目操作符:++、--、+、-7.1++和--7.1.1 前置++ 7.1.2 后置++7.1.3 前置--7.1.4 后置--7.2+和......
  • [Microservices] Microservices Patterns
    Singlepageapplication(SPA)Enabledbymorepowerfulbrowsers,fasterBackendforFrontend(BFF)ProvidesuperiorsupportcomparedtoagenericbackendInsertsalayerbetweenuserexperienceandtheresourcesEnablescustomixeduserexperiencesfordif......
  • 代码随想录打卡Day6
    字符串344.反转字符串classSolution{publicvoidreverseString(char[]s){//注意遍历范围,可以减少循环次数for(inti=0;i<s.length/2;i++){chartmp=s[i];s[i]=s[s.length-i-1];s[s.length-i-1]=t......
  • 就业班 第二阶段 2401--3.26 day6 Shell初识 连接vscode
    远程连接vs_code可能出现的问题C:\Users\41703\.ssh验证远程主机的身份,如果连不上vscode,可以尝试删除这里面的公钥代码。重新安装那个扩展,排除扩展本身的问题谁连过我,并操作了什么curlhttps://gitea.beyourself.org.cn/newrain001/shell-project/raw/branch/master......
  • day6?
    星期六教了分配律带了吃的必须举很简单的例子才好往后面走。下午还好没有出去,大太阳出太阳雨。然后下午玩了下,准备去帮忙做烤肠,终于下定决心买了组装台式,拭目以待,第二天还要去面谈,好紧张,也没啥。4个人,6分钟。排队抽签本身不是最后291/330抽完签变成了4-49我真的会......
  • Kubernetes Antipatterns
    InKubernetes,identifyingandavoidinganti-patternsiscrucialformaintainingarobustcontainerorchestrationenvironment.Thesemisleadingpracticesmayinitiallyappeareffectivebutcanleadtocomplications.ThisreadingexplorestenprevalentKub......
  • LeetCode刷题记录——day6
    1、https://leetcode.cn/problems/length-of-last-word/description/?envType=study-plan-v2&envId=top-interview-150直接从后往前遍历就好classSolution{public:intlengthOfLastWord(strings){intlength=0;intlen=s.length();for(int......