J’ai eu à faire récemment à un piratage de WordPress, ce dernier à donné lieu au piratage de tous les sites hébérgés sur le même serveur dont un Prestashop.
Sommaire
La boutique redirige vers des sites étranges
La boutique Prestashop redirigait vers des sites comme lovegreenpencils(.)ga ou .travelfornamewalking(.)ga, une vraie plaid.
Premier
Ca semble être tout et c’est déjà pas mal…
Comment nettoyer ces fichiers?
Je pars donc à la recherche d’une façon de nettoyer les fichiers facilement, je me dis qu’il existe surement un pattern pour trouver les codes. J’ai fini par trouvé un gist pour m’aider à fair ça :
https://gist.github.com/vinvin27/e249f33a5a416c85850a2f569552c165
Pour faire simple, tu peux lancer ces 2 commandes dans un terminal :
Suppression du backdoor JS (qui fait la redirection) :
for f in $(grep -ril "Element.prototype.appendAfter" ./*); do
# Don't fix the fixer itslef :D
if [[ $f == "./fix.sh" ]]; then
continue;
fi
# If a backup exists, we created it, don't process it again
if [[ $(echo $f | grep ".perlbak") ]]; then
continue;
fi
# Otherwise fix all files recursively
echo "Found file $f"
echo "Backing up and fixing the infection"
echo
perl -pi.perlbak -e 's/Element.prototype.appendAfter[sS]*?})();//gi' "${f}"
((filesProcessed ++))
done
Suppression du backdoor PHP
for f in $(grep -ril '$a="h"."ea"."der"' ./*); do
# Don't fix the fixer itslef :D
if [[ $f == "./fix.sh" ]]; then
continue;
fi
# If a backup exists, we created it, don't process it again
if [[ $(echo $f | grep ".perlbak") ]]; then
continue;
fi
# Otherwise fix all files recursively
echo "Found file $f"
echo "Backing up and fixing the infection"
echo
perl -pi.perlbak -e 's/$a="h"."ea"."der"[sS]*?script><?php//gi' "${f}"
((filesProcessed ++))
done
Liste des commandes utiles :
J’ai trouvé sur un autre site, un autre backdoor PHP, voici la commande modifiée pour la faire fonctionner
for f in $(grep -ril '$a=chr(104).chr(101)' ./*); do if [[ $f == "./fix.sh" ]]; then continue; fi; if [[ $(echo $f | grep ".perlbak") ]]; then continue; fi; echo "Found file $f"; echo "Backing up and fixing the infection"; echo; perl -pi.perlbak -e 's/$a=chr(104).chr(101)[sS]*?<?php//gi' "${f}"; ((filesProcessed ++)); done
for f in $(grep -ril '$a="h"."ea"."der"' ./*); do if [[ $f == "./fix.sh" ]]; then continue; fi; if [[ $(echo $f | grep ".perlbak") ]]; then continue; fi; echo "Found file $f"; echo "Backing up and fixing the infection"; echo; perl -pi.perlbak -e 's/<?php <?php $a="h"."ea"."der"[sS]*??>//gi' "${f}"; ((filesProcessed ++)); done
UPDATE wp_posts SET post_content = REPLACE ( post_content, 'https;//main.travelfornamewalking.ga/stat.js?n=ns1', '' )
for f in $(grep -ril '$a="h"."ea"."der"' ./*); do if [[ $f == "./fix.sh" ]]; then continue; fi; if [[ $(echo $f | grep ".perlbak") ]]; then continue; fi; echo "Found file $f"; echo "Backing up and fixing the infection"; echo; perl -pi.perlbak -e 's/<?php $a="h"."ea"."der"[sS]*??>//gi' "${f}"; ((filesProcessed ++)); done