Last active
April 21, 2017 14:20
-
-
Save webdados/90723adc97d86cf463a63c90338e6bec to your computer and use it in GitHub Desktop.
Search the whole hosting account for files containing specific string(s)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Add the strings to search | |
$strings = array( | |
'_0xaae8', | |
); | |
//Exclude file extensions | |
$extensions_ignore = array( | |
'jpg', | |
'png', | |
'jpeg', | |
'pdf', | |
'gif', | |
); | |
//Go | |
process_folder( './', $strings, $extensions_ignore ); | |
function process_folder( $folder, $strings, $extensions_ignore ) { | |
echo '[ '.$folder.' ]<br/>'; | |
$dir = new DirectoryIterator( $folder ); | |
foreach ( $dir as $file ) { | |
if ( substr( $file->getPathname(), -3 ) != '/..' && substr( $file->getPathname(), -2 ) != '/.' ) { | |
if ( $file->isDir() ) { | |
process_folder( $file->getPathname(), $strings, $extensions_ignore ); | |
} else { | |
if ( !in_array( $file->getExtension(), $extensions_ignore ) ) { | |
$content = file_get_contents( $file->getPathname() ); | |
foreach( $strings as $string ) { | |
if ( strpos( $content, $string ) !== false ) { | |
echo '<span style="color: #ff0000;">'.$file->getPathname().'</span><br/>'; | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment