Answer the question
In order to leave comments, you need to log in
Filtering incoming data?
Hello! Recently my Wordpress site was hacked and infected with viruses. Cleaned the site, improved its performance... On the recommendation of protecting the site, on one of the Internet resources, I added this script for filtering incoming data:
$patt = "~\<\?~i";
if (is_array($_FILES)) {
foreach($_FILES as $anystring=>$file_data) {
if (preg_match($patt,file_get_contents($file_data['tmp_name']))) die("denied by antivirus-alarm 3");
}
}
$patt = "~\/\.\.\/\.\.\/\.\.\/|{0-9a-zA-Z}[80]|eval[^\(]*\(|include[^\(]*\(|base64_decode[^\(]*\(|stripslashes[^\(]*\(|strip_tags[^\(]*\(|fopen[^\(]*\(|chmod[^\(]*\(|chown[^\(]*\(|chgrp[^\(]*\(|unlink[^\(]*\(|unset[^\(]*\(|fgetc[^\(]*\(|fgets[^\(]*\(|file_get_contents[^\(]*\(|file_put_contents[^\(]*\(|fwrite[^\(]*\(|move_uploaded_file[^\(]*\(|is_uploaded_file[^\(]*\(|rmdir[^\(]*\(|fromCharCode[^\(]*\(|tmpfile[^\(]*\(|tempnam[^\(]*\(|phpinfo[^\(]*\(|basename[^\(]*\(|curl_init[^\(]*\(|socket_create[^\(]*\(|popen[^\(]*\(|exec[^\(]*\(|system[^\(]*\(|passthru[^\(]*\(|proc_open[^\(]*\(|gzuncompress[^\(]*\(|shell_exec[^\(]*\(|delete from|insert into~i";
foreach ($_REQUEST as $v1x1) prfilter_x1($v1x1,$patt);
function prfilter_x1($v1x1,$patt) {
ob_start();
if (is_array($v1x1)) {
foreach ($v1x1 as $vx) prfilter_x1($vx,$patt);
}
else {
if ( preg_match($patt, $v1x1) || preg_match($patt, stripslashes($v1x1) ) ) die("denied by antivirus-alarm 1");
if ( preg_match($patt, base64_decode($v1x1) ) || preg_match($patt, stripslashes(base64_decode($v1x1) ) ) ) die("denied by antivirus-alarm 2");
}
ob_end_clean();
}
Answer the question
In order to leave comments, you need to log in
All in one WP security . Install this plugin, it monitors file changes on your site and sends notifications by email. So you can track if shell scripts have been uploaded, or malicious code has been written into any files on your site.
Also, you can shove this command into the cron:
, will look for typical eval() lines in new files and dump their names into the shells_find_log.txt file.
There are tips. Write such things yourself, you will not find exactly the same thing that is necessary for you. You can find something similar, but exactly the same as in your head, you can only write it yourself.
And now closer to the point.
First, to pass data to the database, use MySQLi prepared queries.
In addition, process all data with the following functions.
trim($enteredData); // Удалит все пробелы в начале и в конце стоки
htmlspecialchars($enteredData); // Сделает невозможный SQL инъекцию.
$enteredData = $_POST['field'];
// или
$enteredData = $_GET['field'];
I just have no words, I found this thing on the client's website. He also complained that the pictures did not load.
Hands should be torn off for such checks BLZHAD!!11!#"!%:#*:;
Such a regular expression "~\<\?~i" will work positively on 90% of the pictures, checking from for such a stupidity, forgive me. Man in addition, I set the caseless flag, i.e. the same sensitivity to large and small letters, despite the fact that there are no letters at all in the regular expression. Only an absolutely brainless person can check downloaded files this way.
It is worth disabling short_open_tag on the server and fixing the check at least for this
" ~\<\?php[ a-zA-Z0-9]{5}~" and then I think false positives will be
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question