Jump to content

Hack Prestashop sur la page de paiement - nettoyage


Eolia

Recommended Posts

On 12/26/2022 at 7:27 PM, Zorse said:

Je regarde ... vous parlez de la partie en bleu ? 
 

Pas mal de fichier on été modifier par le dev web au depart au vu des dates sur les fichiers 
Je fais doucement le tri de peur de detraquer quelque choses.

suite - Google Chrome.jpg

Aprés pas mal de nettoyage j'obtiens ceci :

636812468_script3.1.thumb.jpg.01a7e319c7d34eef2d5a035ca6c53e8f.jpg

Je ne peux pas surpimer les derniers fichiers en orange. Ca engendre des bugs sur les modules concerné. 

En esperant que d'autre fichier ne soit pas créés , je vais surveiller tout ça .

Reste a comprendre comment recevoir le resultat du script en tache cron j'ai bien suivis les conseils de MEDIACOM87, les taches cron s'effectuent correctement mais je ne reçois rien par mail .

 

Encore Merci Eolia ! 

Salut Zorse,
Désolé pour mon français.
J'ai rencontré les mêmes fichiers dans 2 sites Web prestashop avec des versions différentes. Pourriez-vous me dire si vous avez réussi à résoudre définitivement le problème du virus ? et si vous comprenez la cause?
J'utilise le thème "Warehouse Theme Elementor"

Comme vous, grâce au script Eolia, j'ai fait un peu de nettoyage dans les fichiers, mais j'arrive encore occasionnellement à modifier des fichiers qui m'ont fait me déconnecter

Je vous remercie beaucoup

Link to comment
Share on other sites

1 hour ago, Eolia said:

Ok, pigé.

Le script a été mis à jour ;)

 

Merci Eolia :)

Je voulais ajouter quelque chose mais je ne sais pas si cela avait eu un rapport direct avec la fausse page de paiement.

Il y a quelque jours en me rendant dans www/img/cms je me suis aperçu qu'un fichier jpg ou png était suspect.
Son nom wingss.
J'ai tenté de l'ouvrir et finalement c'était un fichier php sous une extension d'image mais avec rien de suspect dedans à part <?php

Mais suite à cela j'ai eu un fichier nommé magentoskin.php qui est apparu (même si je ne vois pas bien le rapport) qui contient du code on dirait en base 64 mais je n'ai pas réussi à le décoder et en plus je ne suis pas spécialiste.
J'ai tout retiré du FTP par sécurité.
Peut être que ceux qui ont étés infectés devrait y jetter un oeil dans ce dossier...
J'espère m'être sorti de ce bourbier.

Link to comment
Share on other sites

Pour ceux qui ne reçoivent pas de mail après le script cela peut-être dû à plusieurs raisons:

- Le script utilise la fonction native mail() de PHP. Si celle-ci est désactivée sur votre serveur le mail ne sera pas envoyée.

- le script utilise le domaine de votre boutique comme domaine expéditeur. Si votre domaine n'a pas de spf, dmarc et/ou dkim dans ses entrées DNS il risque d'être rejeté par votre messagerie.

- Vérifiez dans vos spams.

 

Le script sera intégré dans la prochaine mise à jour de mes versions Prestashop ;) 

image.thumb.png.d66e1daca287df3f00f62c960fe82a0d.png

Link to comment
Share on other sites

Bonjour à toutes et à tous , bonjour @Eolia 

Je suis pour la deuxième fois victime d'une injection et remplacement de formulaire de paiement. La première fois j'ai su trouver assez facilement les fichiers corrompus ( grâce aux dates de modif dans le ftp). Ce nouveau hack prend la forme d'un bouton paypal suivi d'un formulaire bidon.

Mais cette fois impossible d'identifier ces "corruptions". Je fais de la comparaison de fichiers depuis hier et je vais finir par craquer :)

Pour des raisons indépendantes de ma volonté je ne peux malheureusement pas mettre à jour la version php du serveur de notre boutique. ( nous sommes sur la PHP 5.5.28-pl0-gentoo )et du coup je ne peux pas utiliser le Cleaner 😢 .

- Avez vous une solution temporaire afin que je puisse remettre en ligne notre boutique ? Une idée des fichiers à checker en priorité ( ./classes/controller/Controller.php ./classes/db/Db.php ./classes/module/Module.php ./controllers/admin/AdminLoginController.php n'ont rien donné )

- @eolia : est ce que votre Cleaner pourrait être facilement adaptable à une version obsolete de php.

Merci beaucoup pour l'aide que vous m'apporterez

Link to comment
Share on other sites

8 minutes ago, Data_Yoyo said:

Bonjour à toutes et à tous , bonjour @Eolia 

Je suis pour la deuxième fois victime d'une injection et remplacement de formulaire de paiement. La première fois j'ai su trouver assez facilement les fichiers corrompus ( grâce aux dates de modif dans le ftp). Ce nouveau hack prend la forme d'un bouton paypal suivi d'un formulaire bidon.

Mais cette fois impossible d'identifier ces "corruptions". Je fais de la comparaison de fichiers depuis hier et je vais finir par craquer :)

Pour des raisons indépendantes de ma volonté je ne peux malheureusement pas mettre à jour la version php du serveur de notre boutique. ( nous sommes sur la PHP 5.5.28-pl0-gentoo )et du coup je ne peux pas utiliser le Cleaner 😢 .

- Avez vous une solution temporaire afin que je puisse remettre en ligne notre boutique ? Une idée des fichiers à checker en priorité ( ./classes/controller/Controller.php ./classes/db/Db.php ./classes/module/Module.php ./controllers/admin/AdminLoginController.php n'ont rien donné )

- @eolia : est ce que votre Cleaner pourrait être facilement adaptable à une version obsolete de php.

Merci beaucoup pour l'aide que vous m'apporterez

Bonjour, Avez-vous essayé de voir en SSH en écrivant par exemple : grep -rl 'base64_decode' www

Souvent les fichiers qui contiennent ce type d'instructions sont à remplacer par une copie de sauvegarde (à manipuler avec prudence selon les fichiers).
Je pense que déjà cela fait gagner du temps.

Link to comment
Share on other sites

il y a 26 minutes, Data_Yoyo a dit :

Bonjour à toutes et à tous , bonjour @Eolia 

Je suis pour la deuxième fois victime d'une injection et remplacement de formulaire de paiement. La première fois j'ai su trouver assez facilement les fichiers corrompus ( grâce aux dates de modif dans le ftp). Ce nouveau hack prend la forme d'un bouton paypal suivi d'un formulaire bidon.

Mais cette fois impossible d'identifier ces "corruptions". Je fais de la comparaison de fichiers depuis hier et je vais finir par craquer :)

Pour des raisons indépendantes de ma volonté je ne peux malheureusement pas mettre à jour la version php du serveur de notre boutique. ( nous sommes sur la PHP 5.5.28-pl0-gentoo )et du coup je ne peux pas utiliser le Cleaner 😢 .

- Avez vous une solution temporaire afin que je puisse remettre en ligne notre boutique ? Une idée des fichiers à checker en priorité ( ./classes/controller/Controller.php ./classes/db/Db.php ./classes/module/Module.php ./controllers/admin/AdminLoginController.php n'ont rien donné )

- @eolia : est ce que votre Cleaner pourrait être facilement adaptable à une version obsolete de php.

Merci beaucoup pour l'aide que vous m'apporterez

Quelle est votre version Prestashop ?

Link to comment
Share on other sites

Merci pour vos réponses. J'ai réussi à faire mettre à jour notre version de php - (7.1). et lancer le script d'Eolia. Enormément de fichier en orange auxquels j'ai un peu peur de toucher mais ça va certainement m'aider. Thanks again :) 

 

Quote

Bonjour, Avez-vous essayé de voir en SSH en écrivant par exemple : grep -rl 'base64_decode' www

Pas en SSH mais en local. ( J'ai dl l'intégralité du ftp sur mon DD et fait des recherches sur "base64, encode , decode, etc ... "  ça n'a étonnamment rien donné 

Quote

Quelle est votre version Prestashop ?

1.6.1.24 ( la dernière release pour 1.6 si je ne m'abuse )

 

Link to comment
Share on other sites

En rouge

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin-dashboard.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin-products.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin-scene-cropping.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/adminImport.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin_carrier_wizard.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin_order.js

Fichier JS ajouté, inexistant dans la version d'origine => htdocs/js/admin_themes.js

 

J'ai controlé, le code n'avais pas l'air suspect. Je les ai quand même retiré.

Pour les oranges c'est presque l'intégralité des folders : classes, controllers, tools, un peu dans config aussi. Dans la plupart des cas c'est juste un saut de ligne dans l'entête qui déclenche l'alerte.

En remplaçant le folder "Tools" ça a réglé le problème, ( du moins les symptomes ) par contre je me retrouve avec cette erreur fatale pour me reconnecter au back office :( 

Fatal error: Cannot declare class DispatcherCore, because the name is already in use in /var/www/sundisshop.com/htdocs/classes/Dispatcher.php on line 31

 

 

 

 

Link to comment
Share on other sites

Merci Eolia , Elle est en intégralité. Je crains d'avoir remplacé trop de fichiers :( . Comme par hasard je n'ai pas fait de back-up de mon folder "Tools". En remettant mon backup du folder "classes" ça ne résoud pas le probleme.

Fatal error: Cannot declare class DispatcherCore, because the name is already in use in /var/www/sundisshop.com/htdocs/classes/Dispatcher.php on line 31

Link to comment
Share on other sites

Le folder tools est dans l'archive d'origine de la version. Aucun problème pour le récupérer.

Commencez par purger les caches class_index.php qui pourrait être la cause de votre mésaventure.

Sinon recherchez si vous n'avez pas une copue de votre répertoire classes dans une autre répertoire, ce qui expliquerait l'erreur

Link to comment
Share on other sites

Bonjour Doekia,

Merci pour ces bonnes pistes !

Pour résoudre le problème J'ai renommé la class DispatcherCore en DispatcherCore2 dans le fichier Dispatcher.php. J'ai bien conscience que ça risque de me poser des problèmes à l'avenir ça me permet de rouvrir la boutique en attendant.

Il semblerait que le fichier responsable de la modification du formulaire de paiement était dans le folder tools.

Le folder tools est dans l'archive d'origine de la version. Aucun problème pour le récupérer. ( oui si les fichiers ne sont pas censé être modifié c'est ok mais je n'en sais rien )

Commencez par purger les caches class_index.php qui pourrait être la cause de votre mésaventure. ( je ne l'ai pas encore fait , je vais tester )

Sinon recherchez si vous n'avez pas une copue de votre répertoire classes dans une autre répertoire, ce qui expliquerait l'erreur ( j'avais effectivement copier le folder class dans le folder class mais je m'en étais rendu compte avant , je vais quand même voir si j'ai pas un doublon quelquepart ) .

 

Je pense que je suis pas très clair et je m'en excuse mais j'ai la cervelle en bouillie à force de tenter de debugger tout ça :) 
Merci encore pour votre aide et implication.

 

Christophe

 

Link to comment
Share on other sites

Je n'ai jamais rien vu d'ajouté dans le répertoire tools. Donc a moins d'avoir un shop Frankenstein supprimez-le et remplacez par le tools de l'archive

Si vous avez un répertoire classes dans classes en effet vous allez avoir des doublons

Le patch en Dispatcher2 est une très mauvaise idée

Procédez avec méthode  évite les noeuds au cerveau

Après corrections (nettoyage tools et classes/classes), supprimez cache/class_index.php

 

Link to comment
Share on other sites

il y a 54 minutes, Eolia a dit :

D'ailleurs Cleaner devrait vous le dire s'il trouve des fichiers qui n'ont rien à faire dans ces répertoires coeur (/classes, /tools, etc...)

bonjour, cleaner est vraiment super. Par contre il ne prévient pas si il y a un dossier ou des fichiers au meme niveau que l'index de base de prestashop. J'ai, par exemple trouvé un dossier "BE" avec des pages de pub pour un FAI de fibre Belge. C'est normal?

Pour info je l'ai aussi utilisé avec thirty bee, et il fonctionne bien aussi.

Merci encore Eolia!

Link to comment
Share on other sites

il y a une heure, JLCH a dit :

Pour info je l'ai aussi utilisé avec thirty bee, et il fonctionne bien aussi.

Ben pour Thirty Bees il ne peut pas récupérer les md5 pour contrôler l'intégrité.

Concernant les dossiers ajoutés à la racine, c'est un peu plus compliqué si on ne veut pas remplir la page d'orange. Le but initial de ce script est de détecter les modifications/ajout dans le fonctionnement du coeur du système.

Pour le reste, c'est votre site, vous devez le connaitre et savoir si vous avez ajouté ces répertoires ou pas.

Link to comment
Share on other sites

Il y a 13 heures, Eolia a dit :

Ben pour Thirty Bees il ne peut pas récupérer les md5 pour contrôler l'intégrité.

Concernant les dossiers ajoutés à la racine, c'est un peu plus compliqué si on ne veut pas remplir la page d'orange. Le but initial de ce script est de détecter les modifications/ajout dans le fonctionnement du coeur du système.

Pour le reste, c'est votre site, vous devez le connaitre et savoir si vous avez ajouté ces répertoires ou pas.

bonjour,

Thirty Bees : le fait d'avoir compris le principe de cleaner et à partir des informations qu'il donne, ça aide énormément!

Fichiers racines: oui, justement, heureusement  que j'ai trouvé ça "étrange", ne serai-ce de par le nom du dossier. s'il avait mis un nom plus logique (temps, imgs, .well-knowns, (un simple rajout d'un S) etc...) ça aurait été plus dur à voir.

 

Merci

Link to comment
Share on other sites

Bonsoir,

J'ai déjà utilisé votre script il y a quelques mois avec un retour positif pour notre site.

Je viens à nouveau de l’exécuter mais rien ne s'affiche cette fois :

Première exécution j'obtiens ceci :

Strict Standards: date(): We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /homepages/42/d788750705/htdocs/cleaner.php on line 98

Notice: Undefined index: SCRIPT_URI in /homepages/42/d788750705/htdocs/cleaner.php on line 100

Warning: Cannot modify header information - headers already sent by (output started at /homepages/42/d788750705/htdocs/cleaner.php:98) in /homepages/42/d788750705/htdocs/cleaner.php on line 100

Script de nettoyage pour boutiques PrestaShop, version 1.0.16

Votre version doit être mise à jour. Téléchargement de la dernière version et exécution...

 

exécution suivante :

Strict Standards: date(): We selected 'Europe/Berlin' for 'CET/1.0/no DST' instead in /homepages/42/d788750705/htdocs/cleaner.php on line 186

Warning: Cannot modify header information - headers already sent by (output started at /homepages/42/d788750705/htdocs/cleaner.php:186) in /homepages/42/d788750705/htdocs/cleaner.php on line 193

Script de nettoyage et contrôle pour boutiques PrestaShop by @eolia, version 2.0.2
Ce script est fourni gracieusement et en aucun cas son utilisation ne peut être payante ou facturée

Votre version doit être mise à jour. Téléchargement de la dernière version  et exécution...

Pourriez vous m'aider en m'indiquant si j'ai réalisé une mauvaise action ?

D'avance merci.

Cordialement,

Marc.

Link to comment
Share on other sites

il y a 29 minutes, P i l o u a dit :

Bonjour Eolia,

Sur la v1.6.1.30, il me donne ceci :

Fichier php inexistant dans la version d'origine. Contenu à contrôler => public_html/config/settings.inc.php

Ce fichier contenant les infos d'accès à la BDD, je suppose qu'il faut le laisser en place.

Oui bien sûr.

Link to comment
Share on other sites

Il y a 10 heures, KevinNash a dit :

Bonsoir Eolia et merci pour ce script.

Chez moi il ne fonctionne pas, quand je le lance j'ai cette erreur sous PS 1.5.4.1 php5.6 :
 

Uncaught Unknown column 'last_connection_date'

Dans la table ps_employee, je ne peux pas mettre le message complet ici, le forum me bloque ^^

Relancez-le, un correctif a été apporté.

Link to comment
Share on other sites

Ah, effectivement il est encore sur les 1.5, c'est un reste des 1.4 laissé pour la rétro-compat.

Il redirige vers le bon controleur si quelau'un aurait gardé l'url de cette page "non-trouvée"

require_once(dirname(__FILE__).'/config/config.inc.php');
Controller::getController('PageNotFoundController')->run();

J'ai ajusté le script pour qu'il ne l'efface plus sur les 1.5.

Nous avons trouvé des 404.php sur des 1.6/1.7 qui n'étaient pas du tout celui de Prestashop d'où sa suppression.

Link to comment
Share on other sites

  • 2 weeks later...

Eolia, un énorme merci pour votre travail sur ce script. Vous avez sauvé ma journée !

Vers midi avec un collègue on percute : "tiens t'as vu c'est bizarre on n'a pas eu de commandes depuis hier soir"

Là on s'aperçoit que notre page de paiement ne comportait plus les moyens de paiement habituels mais à la place un étrange logo Paypal et un formulaire douteux...

Panique à bord !!!!

Jusqu'à ce que je tombe sur le script qui m'a énormément aidé à identifier les fichiers concernés.

Donc, énooooooorme merci :)

On a changé tous les mots de passe FTP et admin (ils étaient costauds pourtant...) puis on va patcher correctement notre 1.6.1.24 maintenant ...

Link to comment
Share on other sites

il y a 1 minute, kokoon a dit :

Eolia, un énorme merci pour votre travail sur ce script. Vous avez sauvé ma journée !

Vers midi avec un collègue on percute : "tiens t'as vu c'est bizarre on n'a pas eu de commandes depuis hier soir"

Là on s'aperçoit que notre page de paiement ne comportait plus les moyens de paiement habituels mais à la place un étrange logo Paypal et un formulaire douteux...

Panique à bord !!!!

Jusqu'à ce que je tombe sur le script qui m'a énormément aidé à identifier les fichiers concernés.

Donc, énooooooorme merci :)

On a changé tous les mots de passe FTP et admin (ils étaient costauds pourtant...) puis on va patcher correctement notre 1.6.1.24 maintenant ...

Rien à voir avec les mots de passe, le souci vient soit d'un module tiers soit d'un Wordpress sur le même hébergement et pas à jour ou pas sécurisé.

  • Like 1
Link to comment
Share on other sites

On a un vieux Joomla non utilisé dans un autre répertoire que le traditionnel "www", il est inaccessible de l'exterieur.

Ceci dit je viens de tout virer !

Et si çà vient d'un module tiers, cela signifie qu'il comporte des fichiers avec des failles qu'un hacker peut atteindre, c'est çà ?

Et sans passer par FTP ... c'est tendu tout çà quand même. Faut faire gaffe à ce qu'on installe donc !

 

Link to comment
Share on other sites

Un module qui permet de faire de l'upload sans véritable contrôle oui.

Prévu pour charger une image de slider par exemple mais accessible depuis le front et dans lequel on peut envoyer un fichier php par exemple.

  • Like 1
Link to comment
Share on other sites

Il y a 15 heures, Eolia a dit :

Un module qui permet de faire de l'upload sans véritable contrôle oui.

Prévu pour charger une image de slider par exemple mais accessible depuis le front et dans lequel on peut envoyer un fichier php par exemple.

Ok j'ai ma petite idée du module en question du coup, merci.

Petite question complémentaire : recommandez-vous de passer vers votre version 1.6.1.30 pour renforcer la sécurité (en plus de profiter de php 7.4 ou +) ?

Link to comment
Share on other sites

il y a 8 minutes, Eolia a dit :

mes versions améliorent certains point de sécurité, intègrent cleaner en natif mais n'empêcheront jamais l'installation d'un module mal écrit ou d'un Wordpress non sécurisé sur le même hébergement)

Oui évidemment faut rester prudent sur ce qu'on installe, c'est la base ;)

Merci encore pour votre temps et vos conseils Eolia.

Link to comment
Share on other sites

  • 2 weeks later...

Bonjour tout le monde !
Je rencontre exactement le même soucis d'attaque avec un faux formulaire de paiement paypal (screen) qui cache tous les modes de payements principaux et qui demandent des informations bancaires pour le processus de paiement paypal.
Une fonction WindowPaymentPaypal() est appelée dans le body.

En regardant le fil, je n'ai pas trouvé de lien pour télécharger le script réalisé par @Eolia
Auriez-vous un lien pour le télécharger ? ( si il est toujours disponible )

image.thumb.png.e65f8d563dac750ac569829359bc2b5a.png

Link to comment
Share on other sites

Hello,

 

J'ai essayé d'utiliser le cleaner.php mais j'ai eu une erreur "Warning: file_get_contents(https://devcustom.net/public/cleaner.txt): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/zinasto/public_html/cleaner.php on line 94" Que dois-je faire?

Merci 

Link to comment
Share on other sites

Il y a 9 heures, zoomht1 a dit :

Hello,

 

J'ai essayé d'utiliser le cleaner.php mais j'ai eu une erreur "Warning: file_get_contents(https://devcustom.net/public/cleaner.txt): Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /home/zinasto/public_html/cleaner.php on line 94" Que dois-je faire?

Merci 

Relancez le script (Le serveur est passé en mode sécurité hier soir suite à certaines requêtes malveillantes)

  • Confused 1
Link to comment
Share on other sites

1 hour ago, Eolia said:

Alors il vous manque des fichiers...

Le script cherche le fichier xxx_votre_admin/get-file-admin.php qui est bien dans cette version

image.png.c0e1002984b702f799097dd6c5b4bb3e.png

Les fichiers sont bien comme vous pouvez constater si dessous:

-rw-r-----  1 admin admin 25470 Feb 23 15:20 functions.php

-rw-r-----  1 admin admin  1613 Feb 23 15:20 get-file-admin.php

-rw-r-----  1 admin admin  1389 Feb 23 15:20 grider.php

-rw-r-----  1 admin admin  2751 Feb 23 15:20 header.inc.php

Link to comment
Share on other sites

Bonjour Eolia,

 

Notre site a été attaqué - On a mis en ligne le cleaner - Hier le script marcher bien mais ce matin on a cette erreur en rouge

Fichiers source introuvables pour cette version: 1.6.1.24. Les contrôles md5 ne pourront être effectués. 

Plus moyen de voir les fichiers infectés MD5 - tu as une piste ? merci 

 

Edited by blancmarine06 (see edit history)
Link to comment
Share on other sites

il y a une heure, blancmarine06 a dit :

Bonjour Eolia,

 

Notre site a été attaqué - On a mis en ligne le cleaner - Hier le script marcher bien mais ce matin on a cette erreur en rouge

Fichiers source introuvables pour cette version: 1.6.1.24. Les contrôles md5 ne pourront être effectués. 

Plus moyen de voir les fichiers infectés MD5 - tu as une piste ? merci 

 

Vous appelez le script depuis votre boutique ou autrement ?

La dernière version est la 2.0.16

Link to comment
Share on other sites

Après analyse, votre ip a été bloquée car votre serveur tente de hacker d'autres boutiques Prestashop (par exemple à 7h34 ce matin) hébergées par nos soins.

Si vous êtes en erreur 500 c'est que la copie des fichiers ou les correctifs s'est mal passée.

Solution:

renommer votre répertoire racine (wwww, ou public_html ou ...)

Effectuer le remplacement de tous les fichiers coeurs mentionnés en rouge

Supprimer les fichiers ajoutés suspects si vous ne les connaissez pas

Controlez/corrigez les fichiers en orange ainsi que les modules

Renommez votre répertoire racine comme à l'origine.

Si vous n'y arrivez pas, envoyez-moi un accès ftp par message privé.

Link to comment
Share on other sites

il y a 41 minutes, blancmarine06 a dit :

Oui depuis la boutique

--------------------------------------------------------------

Script de nettoyage et contrôle pour boutiques PrestaShop by @eolia, version 2.0.16
Ce script est fourni gracieusement et en aucun cas son utilisation ne peut être payante ou facturée

Le répertoire www/**admin**/filemanager a été patché avec succès.

Mémoire OK. Vous avez la dernière version à jour du script -> Démarrage...

Veuillez supprimer ce message svp il y a les chemins de votre cleaner, merci

  • Like 1
Link to comment
Share on other sites

il y a 41 minutes, blancmarine06 a dit :

Je t'envois en MP les accès - Merci d'avance !

Votre site est fonctionnel et nettoyé.

Juste pour info, vous aviez déjà effectué des nettoyages avant (en supprimant des modules suspects par exemple ?) car là il n'y a pas de porte d'entrée clairement identifiée.

Par sécurité, modifiez TOUS les mots de passe employés.

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Bonjour,

j'ai trouvé votre script, le l'ai telechargé et lors du lancement, j'ai ceci : ( il me demande la dernière version ?, la version de votre fichier)

En vous remerciant.

 

Strict Standards: date(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 93

Strict Standards: date(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 93

Strict Standards: header(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 100

Warning: Cannot modify header information - headers already sent by (output started at /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php:93) in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 100

Script de nettoyage et contrôle pour boutiques PrestaShop by @eolia

Votre version doit être mise à jour. Téléchargement de la dernière version et exécution...

Link to comment
Share on other sites

il y a 3 minutes, alain732 a dit :

Bonjour,

j'ai trouvé votre script, le l'ai telechargé et lors du lancement, j'ai ceci : ( il me demande la dernière version ?, la version de votre fichier)

En vous remerciant.

 

Strict Standards: date(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 93

Strict Standards: date(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 93

Strict Standards: header(): We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 100

Warning: Cannot modify header information - headers already sent by (output started at /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php:93) in /homepages/21/d520998076/htdocs/AlpesBlanc/cleaner.php on line 100

Script de nettoyage et contrôle pour boutiques PrestaShop by @eolia

Votre version doit être mise à jour. Téléchargement de la dernière version et exécution...

Vous avez trouvé mon script où ?

Parce que ça fait un moment que cette ligne a été ajouté pour éviter cette alerte

@date_default_timezone_set('Europe/Paris');

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...

@Eolia 👏👏👏 Excelent travail
Comment puis-je exécuter le script.php et recevoir les informations par e-mail ? Je ne me sens pas en sécurité en l'exécutant via le Web, j'aimerais également planifier une tâche qui le fasse de manière récursive, mais je ne sais pas comment exécutez-le via le terminal.

Link to comment
Share on other sites

4 hours ago, Eolia said:

Vous pouvez appeler le script par son chemin sur votre serveur directement depuis votre terminal /var/www/votre_site/XXXXXXXXXX.php

 

Lors de son exécution sur mon serveur Linux, il génère ces erreurs :

Prestashop 1.7.7.7

php 7.3.29

root@c292cfb04f04:/var/www/html# /var/www/html/4579d13501ef.php 
/var/www/html/4579d13501ef.php: line 1: ?php: No such file or directory
/var/www/html/4579d13501ef.php: line 2: /bin: Is a directory
/var/www/html/4579d13501ef.php: line 3: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 4: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 5: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 6: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 7: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 8: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 10: Changelog: command not found
/var/www/html/4579d13501ef.php: line 11: syntax error near unexpected token `10/07/2022'
/var/www/html/4579d13501ef.php: line 11: `1.0.0 (10/07/2022) - 1er script'

image.png.ccb1cda9ac19798cf327796cf1542d21.png

Edited by Jonnathan (see edit history)
Link to comment
Share on other sites

@Eolia
Prestashop 1.7.8.9
PHP 7.4.33


Lorsque vous essayez d'exécuter le cleaner.php via le Web, il affiche cette erreur

32296785_Capturadepantalla2023-05-03071028.thumb.png.00f3cda08285bde63e5627029be821c5.png

Lorsque vous renommez cleaner.php en 622814d3812c.php, donnez-lui les autorisations chmod 755 et exécutez-le via le Web https://site.com/622814d3812c.php affiche cette erreur :

235840348_Capturadepantalla2023-05-03072451.png.3a48e55723c742ed0cacab537b6e2dce.png

 

195729226_Capturadepantalla2023-05-03071544.png.b48b50e951826e641559e7901eeccaef.png

le navigateur essaie de rafraichir la page toutes les 5 secondes

503174518_Capturadepantalla2023-05-03072729.thumb.png.a62d86e9f03dbf197d1303c4a247f1bc.png

Quel pourrait être le problème?

Edited by Jonnathan (see edit history)
Link to comment
Share on other sites

Le souci vient de votre configuration serveur.

https://blog.hubspot.com/website/ssl-handshake-failed#:~:text=SSL Handshake Failed is an,configuration is causing the error.

https://stackoverflow.com/questions/14078182/openssl-file-get-contents-failed-to-enable-crypto

il y a une heure, Jonnathan a dit :

 

Lors de son exécution sur mon serveur Linux, il génère ces erreurs :

Prestashop 1.7.7.7

php 7.3.29

root@c292cfb04f04:/var/www/html# /var/www/html/4579d13501ef.php 
/var/www/html/4579d13501ef.php: line 1: ?php: No such file or directory
/var/www/html/4579d13501ef.php: line 2: /bin: Is a directory
/var/www/html/4579d13501ef.php: line 3: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 4: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 5: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 6: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 7: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 8: 4579d13501ef.php: command not found
/var/www/html/4579d13501ef.php: line 10: Changelog: command not found
/var/www/html/4579d13501ef.php: line 11: syntax error near unexpected token `10/07/2022'
/var/www/html/4579d13501ef.php: line 11: `1.0.0 (10/07/2022) - 1er script'

image.png.ccb1cda9ac19798cf327796cf1542d21.png

Si vous l'appelez depuis votre serveur utilisez curl, votre console ne sait pas interpréter le langage php

Link to comment
Share on other sites

Bonjour et merci pour cette petite merveille qui m'a été bien utile.

Une question : lors de son action le cleaner modifie-t-il le ovh.config qui est à la racine ? Durant l'après midi pendant lequel j'ai remis en ordre le site j'ai remarqué que le ovh.config avait été modifié : app.engine=php est devenu app.engine=phpcgi . 

Mais je ne sais pas si c'est le script de nettoyage qui a fait cela ou bien le hacker qui est venu "sauver ses billes" avant que ses portes n'ai été fermées, dans ce cas il faut que je modifie le config.

presta 1.6.1.20 hébergement ovh php 7.0

Merci et belle journée

Link to comment
Share on other sites

3 hours ago, Eolia said:

Le souci vient de votre configuration serveur.

https://blog.hubspot.com/website/ssl-handshake-failed#:~:text=SSL Handshake Failed is an,configuration is causing the error.

https://stackoverflow.com/questions/14078182/openssl-file-get-contents-failed-to-enable-crypto

Si vous l'appelez depuis votre serveur utilisez curl, votre console ne sait pas interpréter le langage php

 

Merci pour les liens, j'ai modifié le fuseau horaire dans le cleaner.php et maintenant il tourne mais il me montre ces erreurs :

 

Warning: file_get_contents(https://md5.enter-solutions.com/json/1.7.8.9.json): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/html/622814d3812c.php on line 274

Warning: ZipArchive::close(): Failure to create temporary file: Permission denied in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 376

Warning: ZipArchive::close(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 377

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

Warning: ZipArchive::addFile(): Invalid or uninitialized Zip object in /var/www/html/622814d3812c.php on line 1104

 

 

Et la seule chose qui s'affiche en rouge est celle-ci, mais cela a attiré mon attention: Fichiers source introuvables pour cette version: 1.7.8.9. Les contrôles md5 ne pourront être effectués.

 

Si des messages de nettoyage ou suppression sont affichés en rouge, votre e-boutique est susceptible d'avoir été attaquée et a été protégée d'urgence mais il est nécessaire de restaurer les fichiers modifiés, de changer le nom de votre répertoire admin et de changer les mots de passe des employés de votre boutique.

Fichiers source introuvables pour cette version: 1.7.8.9. Les contrôles md5 ne pourront être effectués.

Contrôle des scripts JS:
Fichier JS à contrôler => html/js/admin.js Voir
Fichier JS à contrôler => html/js/admin/addons.js Voir
Fichier JS à contrôler => html/js/admin/attachments.js Voir
Fichier JS à contrôler => html/js/admin/carrier_wizard.js Voir
Fichier JS à contrôler => html/js/admin/dashboard.js Voir
Fichier JS à contrôler => html/js/admin/email.js Voir
Fichier JS à contrôler => html/js/admin/import.js Voir
Fichier JS à contrôler => html/js/admin/login.js Voir
Fichier JS à contrôler => html/js/admin/modules-position.js Voir
Fichier JS à contrôler => html/js/admin/notifications.js Voir
Fichier JS à contrôler => html/js/admin/price.js Voir
Fichier JS à contrôler => html/js/admin/products.js Voir
Fichier JS à contrôler => html/js/admin/themes.js Voir
Fichier JS à contrôler => html/js/admin/tinymce_loader.js Voir
Fichier JS à contrôler => html/js/cropper/builder.js Voir
Fichier JS à contrôler => html/js/cropper/cropper.js Voir
Fichier JS à contrôler => html/js/cropper/dragdrop.js Voir
Fichier JS à contrôler => html/js/cropper/loader.js Voir
Fichier JS à contrôler => html/js/cropper/prototype.js Voir
Fichier JS à contrôler => html/js/cropper/scriptaculous.js Voir
Fichier JS à contrôler => html/js/fileuploader.js Voir
Fichier JS à contrôler => html/js/retro-compat.js.php Voir
Fichier JS à contrôler => html/js/tools.js Voir
Fichier JS à contrôler => html/js/validate.js Voir
Fichier JS à contrôler => html/js/vendor/bower.json Voir
Fichier JS à contrôler => html/js/vendor/ladda.js Voir

 

 

Link to comment
Share on other sites

  • 2 weeks later...
Il y a 2 heures, boutiquepel a dit :

non mais, mise à part te payer 500€, je veux dire 😇

Se former à identifier les éléments pouvant expliquer le piratage.

Suivre toutes les déclarations de failles identifiées sur les modules PrestaShop.

Réécrire les fichiers problématiques pour éviter le piratage sur des éléments de base comme l'enregistrement de fichiers.

Caster convenablement toutes les requêtes SQL des modules et la récupération des variables, tiers.

Ainsi de suite, rien n'est magique pour ce genre de cas.

https://www.mediacom87.fr/comment-se-premunir-du-piratage-sur-prestashop-et-thirty-bees/

https://www.mediacom87.fr/securite-prestashop-proactive-ou-corrective/

Link to comment
Share on other sites

  • 2 weeks later...

Hello !

Cette cochonnerie est revenu après des mois de tranquillité :( . Après exécution du script et du nettoyage de ce qui me paraissait douteux, la page de paiement est OK sur desktop mais demeure sur mobile. J'ai bien entendu vider le cache Prestashop et du navigateur mobile, essayé sur plusieurs téléphones mais le problème persiste. Je ne comprends pas. Le script me renvoie pourtant un rapport plutôt clean. ( J'ai même supprimer temporairement les overrides et virer les modules que je n'utilisais plus).

Est ce que quelqu'un à déja rencontré ce soucis et aurait des pistes à me fournir ? 

Un grand merci !

image.thumb.png.e08822b96d5bcdc1ad3ef08375119e31.png

 

Link to comment
Share on other sites

Merci pour vos premières pistes. Je suis sous la 1.6.1.24  J'ai bien entendu jetter un oeil a tools/tcpdf/config/lang/bul.php et tools/json/json.php ( copiés en bas de page) et ça ne me parait pas suspect. Ce qui me perturbe c'est qu'ils reviennent après suppression ....

Concernant les modules je ne vois que paypal officiel qui pourrait constituer un problème ( je vais tenter de le désactiver ). Peut être lié aux modules de mon thème mais ça va être compliqué de tout se palucher pour trouver la faille :( .

 

<?php
//============================================================+
// File name   : bul.php
// Begin       : 2004-03-03
// Last Update : 2010-03-22
//
// Description : Language module for TCPDF
//               (contains translated texts)
//               Arabic
//
// Author: Nicola Asuni
//
// (c) Copyright:
//               Nicola Asuni
//               Tecnick.com LTD
//               Manor Coach House, Church Hill
//               Aldershot, Hants, GU12 4RQ
//               UK
//               www.tecnick.com
//               [email protected]
//============================================================+

/**
 * TCPDF language file (contains translated texts).
 * @package com.tecnick.tcpdf
 * @brief TCPDF language file: Bulgarian
 * @author Nicola Asuni
 * @since 2012-03-22
 */
 
// Bulgarian

global $l;
$l = array();

 

<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * Converts to and from JSON format.
 *
 * JSON (JavaScript Object Notation) is a lightweight data-interchange
 * format. It is easy for humans to read and write. It is easy for machines
 * to parse and generate. It is based on a subset of the JavaScript
 * Programming Language, Standard ECMA-262 3rd Edition - December 1999.
 * This feature can also be found in  Python. JSON is a text format that is
 * completely language independent but uses conventions that are familiar
 * to programmers of the C-family of languages, including C, C++, C#, Java,
 * JavaScript, Perl, TCL, and many others. These properties make JSON an
 * ideal data-interchange language.
 *
 * This package provides a simple encoder and decoder for JSON notation. It
 * is intended for use with client-side Javascript applications that make
 * use of HTTPRequest to perform server communication functions - data can
 * be encoded into JSON notation for use in a client-side javascript, or
 * decoded from incoming Javascript requests. JSON format is native to
 * Javascript, and can be directly eval()'ed with no further parsing
 * overhead
 *
 * All strings should be in ASCII or UTF-8 format!
 *
 * LICENSE: Redistribution and use in source and binary forms, with or
 * without modification, are permitted provided that the following
 * conditions are met: Redistributions of source code must retain the
 * above copyright notice, this list of conditions and the following
 * disclaimer. Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following disclaimer
 * in the documentation and/or other materials provided with the
 * distribution.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
 * NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 *
 * @category
 * @package     Services_JSON
 * @author      Michal Migurski <[email protected]>
 * @author      Matt Knapp <mdknapp[at]gmail[dot]com>
 * @author      Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
 * @copyright   2005 Michal Migurski
 * @version     CVS: $Id: json.php 6844 2011-06-03 14:46:51Z dMetzger $
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @link        http://pear.php.net/pepr/pepr-proposal-show.php?id=198
 */

/**
 * Marker constant for Services_JSON::decode(), used to flag stack state
 */
define('SERVICES_JSON_SLICE',   1);

/**
 * Marker constant for Services_JSON::decode(), used to flag stack state
 */
define('SERVICES_JSON_IN_STR',  2);

/**
 * Marker constant for Services_JSON::decode(), used to flag stack state
 */
define('SERVICES_JSON_IN_ARR',  3);

/**
 * Marker constant for Services_JSON::decode(), used to flag stack state
 */
define('SERVICES_JSON_IN_OBJ',  4);

/**
 * Marker constant for Services_JSON::decode(), used to flag stack state
 */
define('SERVICES_JSON_IN_CMT', 5);

/**
 * Behavior switch for Services_JSON::decode()
 */
define('SERVICES_JSON_LOOSE_TYPE', 16);

/**
 * Behavior switch for Services_JSON::decode()
 */
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);

/**
 * Converts to and from JSON format.
 *
 * Brief example of use:
 *
 * <code>
 * // create a new instance of Services_JSON
 * $json = new Services_JSON();
 *
 * // convert a complexe value to JSON notation, and send it to the browser
 * $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
 * $output = $json->encode($value);
 *
 * print($output);
 * // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
 *
 * // accept incoming POST data, assumed to be in JSON notation
 * $input = file_get_contents('php://input', 1000000);
 * $value = $json->decode($input);
 * </code>
 */
class Services_JSON
{
   /**
    * constructs a new JSON instance
    *
    * @param    int     $use    object behavior flags; combine with boolean-OR
    *
    *                           possible values:
    *                           - SERVICES_JSON_LOOSE_TYPE:  loose typing.
    *                                   "{...}" syntax creates associative arrays
    *                                   instead of objects in decode().
    *                           - SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
    *                                   Values which can't be encoded (e.g. resources)
    *                                   appear as NULL instead of throwing errors.
    *                                   By default, a deeply-nested resource will
    *                                   bubble up with an error, so all return values
    *                                   from encode() should be checked with isError()
    */
    function __construct($use = 0)
    {
        $this->use = $use;
    }

   /**
    * convert a string from one UTF-16 char to one UTF-8 char
    *
    * Normally should be handled by mb_convert_encoding, but
    * provides a slower PHP-only method for installations
    * that lack the multibye string extension.
    *
    * @param    string  $utf16  UTF-16 character
    * @return   string  UTF-8 character
    * @access   private
    */
    function utf162utf8($utf16)
    {
        // oh please oh please oh please oh please oh please
        if(function_exists('mb_convert_encoding')) {
            return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
        }

        $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});

        switch(true) {
            case ((0x7F & $bytes) == $bytes):
                // this case should never be reached, because we are in ASCII range
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0x7F & $bytes);

            case (0x07FF & $bytes) == $bytes:
                // return a 2-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xC0 | (($bytes >> 6) & 0x1F))
                     . chr(0x80 | ($bytes & 0x3F));

            case (0xFFFF & $bytes) == $bytes:
                // return a 3-byte UTF-8 character
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0xE0 | (($bytes >> 12) & 0x0F))
                     . chr(0x80 | (($bytes >> 6) & 0x3F))
                     . chr(0x80 | ($bytes & 0x3F));
        }

        // ignoring UTF-32 for now, sorry
        return '';
    }

   /**
    * convert a string from one UTF-8 char to one UTF-16 char
    *
    * Normally should be handled by mb_convert_encoding, but
    * provides a slower PHP-only method for installations
    * that lack the multibye string extension.
    *
    * @param    string  $utf8   UTF-8 character
    * @return   string  UTF-16 character
    * @access   private
    */
    function utf82utf16($utf8)
    {
        // oh please oh please oh please oh please oh please
        if(function_exists('mb_convert_encoding')) {
            return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
        }

        switch(strlen($utf8)) {
            case 1:
                // this case should never be reached, because we are in ASCII range
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return $utf8;

            case 2:
                // return a UTF-16 character from a 2-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr(0x07 & (ord($utf8{0}) >> 2))
                     . chr((0xC0 & (ord($utf8{0}) << 6))
                         | (0x3F & ord($utf8{1})));

            case 3:
                // return a UTF-16 character from a 3-byte UTF-8 char
                // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                return chr((0xF0 & (ord($utf8{0}) << 4))
                         | (0x0F & (ord($utf8{1}) >> 2)))
                     . chr((0xC0 & (ord($utf8{1}) << 6))
                         | (0x7F & ord($utf8{2})));
        }

        // ignoring UTF-32 for now, sorry
        return '';
    }

   /**
    * encodes an arbitrary variable into JSON format
    *
    * @param    mixed   $var    any number, boolean, string, array, or object to be encoded.
    *                           see argument 1 to Services_JSON() above for array-parsing behavior.
    *                           if var is a strng, note that encode() always expects it
    *                           to be in ASCII or UTF-8 format!
    *
    * @return   mixed   JSON string representation of input var or an error if a problem occurs
    * @access   public
    */
    function encode($var)
    {
        switch (gettype($var)) {
            case 'boolean':
                return $var ? 'true' : 'false';

            case 'NULL':
                return 'null';

            case 'integer':
                return (int) $var;

            case 'double':
            case 'float':
                return (float) $var;

            case 'string':
                // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
                $ascii = '';
                $strlen_var = strlen($var);

               /*
                * Iterate over every character in the string,
                * escaping with a slash or encoding to UTF-8 where necessary
                */
                for ($c = 0; $c < $strlen_var; ++$c) {

                    $ord_var_c = ord($var{$c});

                    switch (true) {
                        case $ord_var_c == 0x08:
                            $ascii .= '\b';
                            break;
                        case $ord_var_c == 0x09:
                            $ascii .= '\t';
                            break;
                        case $ord_var_c == 0x0A:
                            $ascii .= '\n';
                            break;
                        case $ord_var_c == 0x0C:
                            $ascii .= '\f';
                            break;
                        case $ord_var_c == 0x0D:
                            $ascii .= '\r';
                            break;

                        case $ord_var_c == 0x22:
                        case $ord_var_c == 0x2F:
                        case $ord_var_c == 0x5C:
                            // double quote, slash, slosh
                            $ascii .= '\\'.$var{$c};
                            break;

                        case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
                            // characters U-00000000 - U-0000007F (same as ASCII)
                            $ascii .= $var{$c};
                            break;

                        case (($ord_var_c & 0xE0) == 0xC0):
                            // characters U-00000080 - U-000007FF, mask 110XXXXX
                            // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                            $char = pack('C*', $ord_var_c, ord($var{$c + 1}));
                            $c += 1;
                            $utf16 = $this->utf82utf16($char);
                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
                            break;

                        case (($ord_var_c & 0xF0) == 0xE0):
                            // characters U-00000800 - U-0000FFFF, mask 1110XXXX
                            // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                            $char = pack('C*', $ord_var_c,
                                         ord($var{$c + 1}),
                                         ord($var{$c + 2}));
                            $c += 2;
                            $utf16 = $this->utf82utf16($char);
                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
                            break;

                        case (($ord_var_c & 0xF8) == 0xF0):
                            // characters U-00010000 - U-001FFFFF, mask 11110XXX
                            // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                            $char = pack('C*', $ord_var_c,
                                         ord($var{$c + 1}),
                                         ord($var{$c + 2}),
                                         ord($var{$c + 3}));
                            $c += 3;
                            $utf16 = $this->utf82utf16($char);
                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
                            break;

                        case (($ord_var_c & 0xFC) == 0xF8):
                            // characters U-00200000 - U-03FFFFFF, mask 111110XX
                            // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                            $char = pack('C*', $ord_var_c,
                                         ord($var{$c + 1}),
                                         ord($var{$c + 2}),
                                         ord($var{$c + 3}),
                                         ord($var{$c + 4}));
                            $c += 4;
                            $utf16 = $this->utf82utf16($char);
                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
                            break;

                        case (($ord_var_c & 0xFE) == 0xFC):
                            // characters U-04000000 - U-7FFFFFFF, mask 1111110X
                            // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                            $char = pack('C*', $ord_var_c,
                                         ord($var{$c + 1}),
                                         ord($var{$c + 2}),
                                         ord($var{$c + 3}),
                                         ord($var{$c + 4}),
                                         ord($var{$c + 5}));
                            $c += 5;
                            $utf16 = $this->utf82utf16($char);
                            $ascii .= sprintf('\u%04s', bin2hex($utf16));
                            break;
                    }
                }

                return '"'.$ascii.'"';

            case 'array':
               /*
                * As per JSON spec if any array key is not an integer
                * we must treat the the whole array as an object. We
                * also try to catch a sparsely populated associative
                * array with numeric keys here because some JS engines
                * will create an array with empty indexes up to
                * max_index which can cause memory issues and because
                * the keys, which may be relevant, will be remapped
                * otherwise.
                *
                * As per the ECMA and JSON specification an object may
                * have any string as a property. Unfortunately due to
                * a hole in the ECMA specification if the key is a
                * ECMA reserved word or starts with a digit the
                * parameter is only accessible using ECMAScript's
                * bracket notation.
                */

                // treat as a JSON object
                if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
                    $properties = array_map(array($this, 'name_value'),
                                            array_keys($var),
                                            array_values($var));

                    foreach($properties as $property) {
                        if(Services_JSON::isError($property)) {
                            return $property;
                        }
                    }

                    return '{' . join(',', $properties) . '}';
                }

                // treat it like a regular array
                $elements = array_map(array($this, 'encode'), $var);

                foreach($elements as $element) {
                    if(Services_JSON::isError($element)) {
                        return $element;
                    }
                }

                return '[' . join(',', $elements) . ']';

            case 'object':
                $vars = get_object_vars($var);

                $properties = array_map(array($this, 'name_value'),
                                        array_keys($vars),
                                        array_values($vars));

                foreach($properties as $property) {
                    if(Services_JSON::isError($property)) {
                        return $property;
                    }
                }

                return '{' . join(',', $properties) . '}';

            default:
                return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
                    ? 'null'
                    : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
        }
    }

   /**
    * array-walking function for use in generating JSON-formatted name-value pairs
    *
    * @param    string  $name   name of key to use
    * @param    mixed   $value  reference to an array element to be encoded
    *
    * @return   string  JSON-formatted name-value pair, like '"name":value'
    * @access   private
    */
    function name_value($name, $value)
    {
        $encoded_value = $this->encode($value);

        if(Services_JSON::isError($encoded_value)) {
            return $encoded_value;
        }

        return $this->encode(strval($name)) . ':' . $encoded_value;
    }

   /**
    * reduce a string by removing leading and trailing comments and whitespace
    *
    * @param    $str    string      string value to strip of comments and whitespace
    *
    * @return   string  string value stripped of comments and whitespace
    * @access   private
    */
    function reduce_string($str)
    {
        $str = preg_replace(array(

                // eliminate single line comments in '// ...' form
                '#^\s*//(.+)$#m',

                // eliminate multi-line comments in '/* ... */' form, at start of string
                '#^\s*/\*(.+)\*/#Us',

                // eliminate multi-line comments in '/* ... */' form, at end of string
                '#/\*(.+)\*/\s*$#Us'

            ), '', $str);

        // eliminate extraneous space
        return trim($str);
    }

   /**
    * decodes a JSON string into appropriate variable
    *
    * @param    string  $str    JSON-formatted string
    *
    * @return   mixed   number, boolean, string, array, or object
    *                   corresponding to given JSON input string.
    *                   See argument 1 to Services_JSON() above for object-output behavior.
    *                   Note that decode() always returns strings
    *                   in ASCII or UTF-8 format!
    * @access   public
    */
    function decode($str)
    {
        $str = $this->reduce_string($str);

        switch (strtolower($str)) {
            case 'true':
                return true;

            case 'false':
                return false;

            case 'null':
                return null;

            default:
                $m = array();

                if (is_numeric($str)) {
                    // Lookie-loo, it's a number

                    // This would work on its own, but I'm trying to be
                    // good about returning integers where appropriate:
                    // return (float)$str;

                    // Return float or int, as appropriate
                    return ((float)$str == (integer)$str)
                        ? (integer)$str
                        : (float)$str;

                } elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
                    // STRINGS RETURNED IN UTF-8 FORMAT
                    $delim = substr($str, 0, 1);
                    $chrs = substr($str, 1, -1);
                    $utf8 = '';
                    $strlen_chrs = strlen($chrs);

                    for ($c = 0; $c < $strlen_chrs; ++$c) {

                        $substr_chrs_c_2 = substr($chrs, $c, 2);
                        $ord_chrs_c = ord($chrs{$c});

                        switch (true) {
                            case $substr_chrs_c_2 == '\b':
                                $utf8 .= chr(0x08);
                                ++$c;
                                break;
                            case $substr_chrs_c_2 == '\t':
                                $utf8 .= chr(0x09);
                                ++$c;
                                break;
                            case $substr_chrs_c_2 == '\n':
                                $utf8 .= chr(0x0A);
                                ++$c;
                                break;
                            case $substr_chrs_c_2 == '\f':
                                $utf8 .= chr(0x0C);
                                ++$c;
                                break;
                            case $substr_chrs_c_2 == '\r':
                                $utf8 .= chr(0x0D);
                                ++$c;
                                break;

                            case $substr_chrs_c_2 == '\\"':
                            case $substr_chrs_c_2 == '\\\'':
                            case $substr_chrs_c_2 == '\\\\':
                            case $substr_chrs_c_2 == '\\/':
                                if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
                                   ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
                                    $utf8 .= $chrs{++$c};
                                }
                                break;

                            case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
                                // single, escaped unicode character
                                $utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
                                       . chr(hexdec(substr($chrs, ($c + 4), 2)));
                                $utf8 .= $this->utf162utf8($utf16);
                                $c += 5;
                                break;

                            case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
                                $utf8 .= $chrs{$c};
                                break;

                            case ($ord_chrs_c & 0xE0) == 0xC0:
                                // characters U-00000080 - U-000007FF, mask 110XXXXX
                                //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                                $utf8 .= substr($chrs, $c, 2);
                                ++$c;
                                break;

                            case ($ord_chrs_c & 0xF0) == 0xE0:
                                // characters U-00000800 - U-0000FFFF, mask 1110XXXX
                                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                                $utf8 .= substr($chrs, $c, 3);
                                $c += 2;
                                break;

                            case ($ord_chrs_c & 0xF8) == 0xF0:
                                // characters U-00010000 - U-001FFFFF, mask 11110XXX
                                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                                $utf8 .= substr($chrs, $c, 4);
                                $c += 3;
                                break;

                            case ($ord_chrs_c & 0xFC) == 0xF8:
                                // characters U-00200000 - U-03FFFFFF, mask 111110XX
                                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                                $utf8 .= substr($chrs, $c, 5);
                                $c += 4;
                                break;

                            case ($ord_chrs_c & 0xFE) == 0xFC:
                                // characters U-04000000 - U-7FFFFFFF, mask 1111110X
                                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                                $utf8 .= substr($chrs, $c, 6);
                                $c += 5;
                                break;

                        }

                    }

                    return $utf8;

                } elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
                    // array, or object notation

                    if ($str{0} == '[') {
                        $stk = array(SERVICES_JSON_IN_ARR);
                        $arr = array();
                    } else {
                        if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
                            $stk = array(SERVICES_JSON_IN_OBJ);
                            $obj = array();
                        } else {
                            $stk = array(SERVICES_JSON_IN_OBJ);
                            $obj = new stdClass();
                        }
                    }

                    array_push($stk, array('what'  => SERVICES_JSON_SLICE,
                                           'where' => 0,
                                           'delim' => false));

                    $chrs = substr($str, 1, -1);
                    $chrs = $this->reduce_string($chrs);

                    if ($chrs == '') {
                        if (reset($stk) == SERVICES_JSON_IN_ARR) {
                            return $arr;

                        } else {
                            return $obj;

                        }
                    }

                    //print("\nparsing {$chrs}\n");

                    $strlen_chrs = strlen($chrs);

                    for ($c = 0; $c <= $strlen_chrs; ++$c) {

                        $top = end($stk);
                        $substr_chrs_c_2 = substr($chrs, $c, 2);

                        if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
                            // found a comma that is not inside a string, array, etc.,
                            // OR we've reached the end of the character list
                            $slice = substr($chrs, $top['where'], ($c - $top['where']));
                            array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
                            //print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                            if (reset($stk) == SERVICES_JSON_IN_ARR) {
                                // we are in an array, so just push an element onto the stack
                                array_push($arr, $this->decode($slice));

                            } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
                                // we are in an object, so figure
                                // out the property name and set an
                                // element in an associative array,
                                // for now
                                $parts = array();
                                
                                if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
                                    // "name":value pair
                                    $key = $this->decode($parts[1]);
                                    $val = $this->decode($parts[2]);

                                    if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
                                        $obj[$key] = $val;
                                    } else {
                                        $obj->$key = $val;
                                    }
                                } elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
                                    // name:value pair, where name is unquoted
                                    $key = $parts[1];
                                    $val = $this->decode($parts[2]);

                                    if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
                                        $obj[$key] = $val;
                                    } else {
                                        $obj->$key = $val;
                                    }
                                }

                            }

                        } elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
                            // found a quote, and we are not inside a string
                            array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
                            //print("Found start of string at {$c}\n");

                        } elseif (($chrs{$c} == $top['delim']) &&
                                 ($top['what'] == SERVICES_JSON_IN_STR) &&
                                 ((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
                            // found a quote, we're in a string, and it's not escaped
                            // we know that it's not escaped becase there is _not_ an
                            // odd number of backslashes at the end of the string so far
                            array_pop($stk);
                            //print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");

                        } elseif (($chrs{$c} == '[') &&
                                 in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
                            // found a left-bracket, and we are in an array, object, or slice
                            array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
                            //print("Found start of array at {$c}\n");

                        } elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
                            // found a right-bracket, and we're in an array
                            array_pop($stk);
                            //print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        } elseif (($chrs{$c} == '{') &&
                                 in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
                            // found a left-brace, and we are in an array, object, or slice
                            array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
                            //print("Found start of object at {$c}\n");

                        } elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
                            // found a right-brace, and we're in an object
                            array_pop($stk);
                            //print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        } elseif (($substr_chrs_c_2 == '/*') &&
                                 in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
                            // found a comment start, and we are in an array, object, or slice
                            array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
                            $c++;
                            //print("Found start of comment at {$c}\n");

                        } elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
                            // found a comment end, and we're in one now
                            array_pop($stk);
                            $c++;

                            for ($i = $top['where']; $i <= $c; ++$i)
                                $chrs = substr_replace($chrs, ' ', $i, 1);

                            //print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");

                        }

                    }

                    if (reset($stk) == SERVICES_JSON_IN_ARR) {
                        return $arr;

                    } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
                        return $obj;

                    }

                }
        }
    }

    /**
     * @todo Ultimately, this should just call PEAR::isError()
     */
    function isError($data, $code = null)
    {
        if (class_exists('pear')) {
            return @PEAR::isError($data, $code);
        } elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
                                 is_subclass_of($data, 'services_json_error'))) {
            return true;
        }

        return false;
    }
}

if (class_exists('PEAR_Error')) {

    class Services_JSON_Error extends PEAR_Error
    {
        function Services_JSON_Error($message = 'unknown error', $code = null,
                                     $mode = null, $options = null, $userinfo = null)
        {
            parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
        }
    }

} else {

    /**
     * @todo Ultimately, this class shall be descended from PEAR_Error
     */
    class Services_JSON_Error
    {
        function Services_JSON_Error($message = 'unknown error', $code = null,
                                     $mode = null, $options = null, $userinfo = null)
        {

        }
    }

}

 

Edited by Data_Yoyo (see edit history)
Link to comment
Share on other sites

il y a 36 minutes, Data_Yoyo a dit :

Peut être lié aux modules de mon thème mais ça va être compliqué de tout se palucher pour trouver la faille

Certainement que ce sont les premiers modules à regarder, ce sont les pires modules présents sur PrestaShop.

Et oui, il faut tout lire, c'est le principe si personne n'a fait le boulot de référencer ces failles avant vous.

Link to comment
Share on other sites

Just now, Mediacom87 said:

Certainement que ce sont les premiers modules à regarder, ce sont les pires modules présents sur PrestaShop.

Et oui, il faut tout lire, c'est le principe si personne n'a fait le boulot de référencer ces failles avant vous.

Oui je suis d'accord. Faire des efforts ok mais encore faut il avoir le bagage pour détecter les failles ( du write , de la base 64 je sais y regarder mais ça s'arrète la )
Est ce qu'en désactivant les modules non natifs + surcharges depuis le BO permet de voir "en un coup d'oeil" si le problème vient d'un module tiers ? 
Même question pour un "switch" de thême ? 

Encore merci !

Link to comment
Share on other sites

  • 2 weeks later...

I am wondering why, as of cleaner.php version 2.0.39, PS versions greater than 1.7 are no longer receiving MD5 integrity checks?  I've attempted to find the answer but I also note that the change history is also no longer part of the script.  Thanks for any advice, and I apologise for using English.

Link to comment
Share on other sites

Good morning,
Prestashop recently changed its urls and it's getting complicated to maintain this kind of script under these conditions.
This script was written for versions 1.6 and PhenixSuite. Some code had been added for 1.7 but it is no longer maintainable.
You can ask Prestashop to set up this kind of script for versions 1.7, 8, 9 etc... but this is no longer my domain.

  • Like 1
Link to comment
Share on other sites

1 minute ago, Eolia said:

Good morning,
Prestashop recently changed its urls and it's getting complicated to maintain this kind of script under these conditions.
This script was written for versions 1.6 and PhenixSuite. Some code had been added for 1.7 but it is no longer maintainable.
You can ask Prestashop to set up this kind of script for versions 1.7, 8, 9 etc... but this is no longer my domain.

Thank you very much for your fast reply and all your work in this area.

Link to comment
Share on other sites

Comparez la liste des fichiers js contenu dans le répertoire /js de l'archive de votre version (1.7.8.9) et supprimez de votre site ceux qui n'ont rien à y faire.

Les fichiers sont en rouge car il comportent des fonctions sensibles.

Et concernant le support pour les versions 1.7 et supérieures, Prestashop faisant tout son possible pour supprimer les liens vers les anciennes versions et ayant autre chose à faire je n'en assure plus le suivi.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...