Jump to content

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


gdfhghjdfghgfhf

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:

 

 

/var/www/clients/client2/web1/web/dl/pp/6250/Ya Basta! - 2002 - Lucha Y Fiesta.zip

/var/www/clients/client2/web1/web/dl/pp/6250/La Souris Déglinguée - 1988 - Quartier Libre.zip

 

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

Here's the script:

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

// $encodedquery = "WWEgQmFzdGEhIC0gMjAwMiAtIEx1Y2hhIFkgRmllc3RhLnppcA==";  // query without accent = WORKS !
$encodedquery = "TGEgU291cmlzIETpZ2xpbmd16WUgLSAxOTg4IC0gUXVhcnRpZXIgTGlicmUuemlw" // 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";
}
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.