首页 > 解决方案 > 请帮助我理解这个 PHP hack,我怎样才能绕过这个 re

问题描述

我找到了一个php代码,它只能包含这个主题的一个文件,但是这个文件包含数字。它必须绕过这个re。

我尝试使用 file_put_contents 生成具有其他文件名的文件,但仅生成 index.html 中的代码。可以运行 PHP。所以我认为只能绕过这个重新,没有竞争条件

<?php    
 include_once("fl2g.php"); 
 $filename = $_GET['filename']; 
 $filename = $_GET['content']; 
    if(preg_match("/[^a-z\.]/", $filename) == 1) { 
        echo "Hacker"; 
        die(); 
    } 
    $files = scandir('./');  
    foreach($files as $file) { 
        if(is_file($file)){ 
            if ($file !== "index.php") { 
                unlink($file); 
            } 
        } 
    } 
    file_put_contents($filename, $content ); 
   ?>

我希望绕过这个重新

标签: php

解决方案


正则表达式状态:“^”匹配任何不在集合“az”中的字符。(小写“a”到“z”,句号“.”)

Preg_match() 的返回值为 1 如果为假,则为 0 如果为真。

if (preg_match("\[^a-z\.]\", "abc.xyz") == 1) 
// would return true(?) because preg_match() returns false , but false = 1; so it returns true. i think :/

那么它似乎删除了目录中的所有文件?

编辑:要在文件名中添加一个数字,您只需附加这样的内容

$filename = "001".$filename; //makes "001ZZZ"

我对 php/regex 有点生疏了


推荐阅读