PHP code example of dragonrun1 / file_path_normalizer

1. Go to this page and download the library: Download dragonrun1/file_path_normalizer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dragonrun1 / file_path_normalizer example snippets



$path = 'C:\Windows\System32\cmd.exe /c dir';
print shell_exec($path);


$path = 'C:\\Windows\\System32\\cmd.exe /c del /q *.*';
print shell_exec($path);


$path = '/bin/bash -c "rm -f *.*"';
print shell_exec($path);


$allowedPath = '/my/web/app/';
$path = '/bin/bash -c "ls -al"';
if (false === strpos($path, $path)) {
    $mess = 'Illegal file path detected must be in ' . $allowedPath;
    throw Exception($mess);
}
print shell_exec($path);


$allowedPath = '/my/web/app/';
$path = '/my/web/app/../../../bin/bash -c "ls -al"';
if (false === strpos($path, $path)) {
    $mess = 'Illegal file path detected must be in ' . $allowedPath;
    throw Exception($mess);
}
print shell_exec($path);
 const MODE_DEFAULT = self::ABSOLUTE_REQUIRED | self::VFS_DISABLED | self::WRAPPER_ALLOWED;