Edit File by line
/home/zeestwma/redstone...
File: clean.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* This script scans the directory for files and performs certain actions based on their content and name.
[2] Fix | Delete
* It also ensures that excluded files are not deleted.
[3] Fix | Delete
*
[4] Fix | Delete
* @author kader
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
// List of forbidden words to check in file content
[8] Fix | Delete
$forbidden_words = ['eval', 'base64_decode', 'shell_exec', 'system', 'passthru', 'exec', 'popen', 'proc_open'];
[9] Fix | Delete
[10] Fix | Delete
// New content for the index.php file
[11] Fix | Delete
$new_index_content = "<?php
[12] Fix | Delete
/**
[13] Fix | Delete
* Front to the WordPress application. This file doesn't do anything, but loads
[14] Fix | Delete
* wp-blog-header.php which does and tells WordPress to load the theme.
[15] Fix | Delete
*
[16] Fix | Delete
* @package WordPress _kader_fix
[17] Fix | Delete
*/
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Tells WordPress to load the WordPress theme and output it.
[21] Fix | Delete
*
[22] Fix | Delete
* @var bool
[23] Fix | Delete
*/
[24] Fix | Delete
define( 'WP_USE_THEMES', true );
[25] Fix | Delete
[26] Fix | Delete
/** Loads the WordPress Environment and Template */
[27] Fix | Delete
require __DIR__ . '/wp-blog-header.php';";
[28] Fix | Delete
[29] Fix | Delete
// Filename for the new index file
[30] Fix | Delete
$new_index_filename = "index.php";
[31] Fix | Delete
[32] Fix | Delete
// List of files to be excluded from deletion
[33] Fix | Delete
$excluded_files = [
[34] Fix | Delete
'cleaner.php', 'fofi.php', 'wp-activate.php', 'wp-blog-header.php',
[35] Fix | Delete
'wp-comments-post.php', 'wp-config.php', 'wp-config-sample.php', 'wp-cron.php',
[36] Fix | Delete
'wp-links-opml.php', 'wp-load.php', 'wp-login.php', 'wp-mail.php', 'wp-settings.php',
[37] Fix | Delete
'wp-signup.php', 'wp-trackback.php', 'xmlrpc.php', 'wordpress_logs.php','cleans.php','clean.php'
[38] Fix | Delete
];
[39] Fix | Delete
[40] Fix | Delete
/**
[41] Fix | Delete
* Checks if the file content contains any forbidden words.
[42] Fix | Delete
*
[43] Fix | Delete
* @param string $file_content The content of the file to check.
[44] Fix | Delete
* @param array $forbidden_words List of forbidden words.
[45] Fix | Delete
* @return bool True if any forbidden word is found, false otherwise.
[46] Fix | Delete
*/
[47] Fix | Delete
function contains_forbidden_words($file_content, $forbidden_words) {
[48] Fix | Delete
foreach ($forbidden_words as $word) {
[49] Fix | Delete
if (stripos($file_content, $word) !== false) {
[50] Fix | Delete
return true;
[51] Fix | Delete
}
[52] Fix | Delete
}
[53] Fix | Delete
return false;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
// Scan the directory for files
[57] Fix | Delete
$files = scandir(__DIR__);
[58] Fix | Delete
[59] Fix | Delete
foreach ($files as $file) {
[60] Fix | Delete
// Skip current and parent directory entries
[61] Fix | Delete
if ($file == '.' || $file == '..' || is_dir($file)) {
[62] Fix | Delete
continue;
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
// Handle the index.php file separately
[66] Fix | Delete
if ($file == 'index.php') {
[67] Fix | Delete
unlink($file);
[68] Fix | Delete
file_put_contents($new_index_filename, $new_index_content);
[69] Fix | Delete
continue;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
// Skip files that are in the excluded list
[73] Fix | Delete
if (in_array($file, $excluded_files)) {
[74] Fix | Delete
continue;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
// Delete specific files
[78] Fix | Delete
$files_to_delete = ['hexfile.txt', 'license.txt', 'tenten.php', 'unzipper.php', 'unzippers.php', 'uxo.txt'];
[79] Fix | Delete
if (in_array($file, $files_to_delete)) {
[80] Fix | Delete
unlink($file);
[81] Fix | Delete
continue;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
// Delete files with numbers in their names or not ending with .php or .txt
[85] Fix | Delete
if (preg_match('/\d/', $file) || !preg_match('/\.(php|txt)$/', $file)) {
[86] Fix | Delete
unlink($file);
[87] Fix | Delete
continue;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
// Check and delete files containing forbidden words
[91] Fix | Delete
if (pathinfo($file, PATHINFO_EXTENSION) == 'php' || pathinfo($file, PATHINFO_EXTENSION) == 'txt') {
[92] Fix | Delete
$file_content = file_get_contents(__DIR__ . '/' . $file);
[93] Fix | Delete
if (contains_forbidden_words($file_content, $forbidden_words)) {
[94] Fix | Delete
unlink($file);
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
// Confirmation message that the cleaning process is complete
[100] Fix | Delete
echo "The cleaning process has been completed successfully.";
[101] Fix | Delete
?>
[102] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function