Skip to content

Instantly share code, notes, and snippets.

@webdados
Last active April 21, 2017 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/90723adc97d86cf463a63c90338e6bec to your computer and use it in GitHub Desktop.
Save webdados/90723adc97d86cf463a63c90338e6bec to your computer and use it in GitHub Desktop.
Search the whole hosting account for files containing specific string(s)
<?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