Jump to content

RegexIterator / Recursive Iterator - can't search file with accents


Guest

Recommended Posts

I have a script that will search for a file inside all directories of my server, then return the full path to the file. The search query comes encoded in base64.

The script works perfectly when searching a file without accents. But as soon as i search for something with accents, it won't work.

Here is my file structure:

 

Quote

 

/var/www/clients/client2/web1/web/dl/pp/6250/[redacted].zip

/var/www/clients/client2/web1/web/dl/pp/6250/[redacted].zip

 

When searching for the first file ([redacted]) it will return the correct path. But when searching for the second file with accents ([redacted]) it will not return any result even if the file exists

Here's the script:

header("Content-type: text/html; charset=utf-8");

// $encodedquery = "[redacted]";  // query without accent = WORKS !
$encodedquery = "[redacted]" // query with accents = DOESNT WORKS

$decode = utf8_encode(base64_decode($encodedquery);
$search = preg_quote($decode);
echo "searching for \"$search\" ....";

        function rsearch($folder, $pattern) {
            $dir = new RecursiveDirectoryIterator($folder);
            $ite = new RecursiveIteratorIterator($dir);
            $files = new RegexIterator($ite, $pattern, RegexIterator::GET_MATCH);
            $fileList = array();
            foreach($files as $file) {
                $fileList = array_merge($fileList, $file);
            }
            return $fileList;
        }

        $root = $_SERVER['DOCUMENT_ROOT'];
        $resultatss = rsearch($root, '/.*\/'.$search.'/');

foreach ($resultatss as $resultat) {
echo "<br>FOUND FILE = $resultat";
}

Hey ungovernable,

just use openssl instead utf8_encode to encode and after to decode the string of the file.

 

So, here is a simple test that I made it for you:

#!/bin/bash
 
openssl enc -base64 <<< 'La Souris Déglinguée - 1988 - Quartier Libre.zip'


Result: 

TGEgU291cmlzIETDqWdsaW5ndcOpZSAtIDE5ODggLSBRdWFydGllciBMaWJyZS56aXAK

# decode the string

openssl enc -base64 -d <<< 'TGEgU291cmlzIETDqWdsaW5ndcOpZSAtIDE5ODggLSBRdWFydGllciBMaWJyZS56
aXAK'

Result: 

La Souris Déglinguée - 1988 - Quartier Libre.zip

So, do you know how to run a bash command(s) inside the php script?

Bash in PHP make me start to sweat nervously ;)

 

Run that script onto your web server and tell me what result you get.

<?php

$str = 'La Souris Déglinguée - 1988 - Quartier Libre.zip';

$enc = "openssl enc -base64 <<< '$str'";

$exc = shell_exec($enc);

$dec = "openssl enc -base64 -d <<< '$exc'";

echo shell_exec($dec);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.