Jump to content

Spammer bypasses contact form. Captcha no effect.


sumsel

Recommended Posts

Hi folks,

 

I could use some help.

 

A chinese fraud and virus spammer has decided to send me tons of messages via contact form.

 

However he doesn't need the contact form to do that, and I have no clue how that is even possible.

 

How did I find out? I replaced the contact-form.tpl with a static html page which stated that due to spam the contact form was temporarily disabled. But I still got spam via contact form!! With no contact form even present in the shop!!

 

That sender seems to have a way to call the scripts usually used in the contact form to send messages, and does not need any forms.

 

I put the shop into maintenance mode. I didn't get spam then. At least something.

 

For obvious reasons, that is not my preferred permanent solution.

 

Then I searched this forum, and successfully found and implemented a recaptcha for my contact form. Put the shop back online. Got spam again. Put the shop offline.

 

What do I do against that??

 

Thanks for any hints.

  • Like 1
Link to comment
Share on other sites

Yes that is indeed what it seems like. So what do I do? I can live with a shop that doesnt have the contact form functionality. I tested disabling the email feature but that also disables all emails during product ordering, a no-go. I would like to disable selectively the email through contact form function. Any hints how I can achieve that? Of course a more advanced solution which really prevents this kind of spam would be better, but first things first. I want my shop back, without contact form spam. Hope somebody can help. Thanks!

  • Like 1
Link to comment
Share on other sites

I hope you are aware of the Send-to-a-friend module spam problem and that it isn't that problem that you have. That module allowed spammers to use your site to send spam. By now there is an upgrade that solves the problem. https://www.prestashop.com/forums/topic/539185-somebody-sending-out-spam-using-the-send-to-a-friend-module/

 

As far as I can see the forms are processed in the file controllers/front/ContactController.php. You might want to change that file.

  • Like 1
Link to comment
Share on other sites

Thank you. I have seen the sent to friend spam issue, and as I have never had the send to a friend function active, I concluded this was unrelated.

 

I'm currently experimenting with the contactcontroller.php and will post any results I may get.

  • Like 1
Link to comment
Share on other sites

I am now trying the Hammer method, search and destroy. I renamed ContactController.php to _ContactController.php, with the intention of killing any process which would rely on this controller to work, hoping that sending spam through a bot is one of those processes.

 

This leads to a 404 error when somebody tries to open the contact form, no matter which content is in that contact form.

 

So I also unhooked the contact block from the DisplayNav position. For the average user, there simply is no contact form any more, and as our customer service email address is displayed on every page, I think that is no problem in itself.

 

Of course this method is the most dirty way thinkable, and I'm not entirely sure what else I have destroyed with this, so not a recommendation but merely a report what I'm doing to my shop. If I get more insights, I will post again. Should I forget to post, then that's a sign it may have worked as I intended ;)

  • Like 1
Link to comment
Share on other sites

1.6.1.7 here.

 

In the couple of hours since renaming the controller no spam has arrived, but an order has gone through and I received the email notification about that. Guess I will leave it like that, unless someome can point out a cleaner solution.

  • Like 1
Link to comment
Share on other sites

SOLVED!!!!

Problem was that the captcha algo has to be activated in the contactcontroller.php;

 

1: enter reCaptcha and generate the keys with your domain

2: Add <script src=https://www.google.com/recaptcha/api.js'></script> to header.tp just before the </head> tag

3: Add <div class="g-recaptcha" data-sitekey="[public Google key]"></div> to contact-form.tpl just before</form> tag

4:  go to /controllers/front/ContactController.php and just efter this line : $this->errors[] = Tools::displayError('Bad file extension');

add:

} else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response')))){

    $this->errors[] = Tools::displayError('Captcha not verified');

            }

 

Thats it!

 

For prestashop 1.6.1.5

Edited by javior00 (see edit history)
  • Like 5
  • Thanks 4
Link to comment
Share on other sites

  • 5 weeks later...
  • 7 months later...
  • 2 weeks later...
On 17/05/2017 at 10:00 AM, javior00 said:

SOLVED!!!!

Problem was that the captcha algo has to be activated in the contactcontroller.php;

 

1: enter reCaptcha and generate the keys with your domain

2: Add <script src=https://www.google.com/recaptcha/api.js'></script> to header.tp just before the </head> tag

3: Add <div class="g-recaptcha" data-sitekey="[public Google key]"></div> to contact-form.tpl just before</form> tag

4:  go to /controllers/front/ContactController.php and just efter this line : $this->errors[] = Tools::displayError('Bad file extension');

add:

} else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response')))){

    $this->errors[] = Tools::displayError('Captcha not verified');

            }

 

Thats it!

 

For prestashop 1.6.1.5

Just missing quote so it would be : 

<script src='https://www.google.com/recaptcha/api.js'></script>

 

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

On 17/05/2017 at 1:30 PM, javior00 said:

SOLVED!!!!

Problem was that the captcha algo has to be activated in the contactcontroller.php;

 

1: enter reCaptcha and generate the keys with your domain

2: Add <script src=https://www.google.com/recaptcha/api.js'></script> to header.tp just before the </head> tag

3: Add <div class="g-recaptcha" data-sitekey="[public Google key]"></div> to contact-form.tpl just before</form> tag

4:  go to /controllers/front/ContactController.php and just efter this line : $this->errors[] = Tools::displayError('Bad file extension');

add:

} else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response')))){

    $this->errors[] = Tools::displayError('Captcha not verified');

            }

 

Thats it!

 

For prestashop 1.6.1.5

Worked for 1.6.1.4. Thanks a lot.

Link to comment
Share on other sites

On 22/02/2018 at 10:33 AM, nberga said:

Hi,

I follow these steps but now y contact form doens't work, what did i do wrong? 

 

try without "{ }" in ContactController.php like this

else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response'))))

    $this->errors[] = Tools::displayError('Captcha not verified');

and don't miss ' in  <script src='https://www.google.com/recaptcha/api.js'>

works on PrestaShop 1.6.0.11 

Link to comment
Share on other sites

On 24.2.2018 at 11:07 AM, Place2 said:

 

try without "{ }" in ContactController.php like this


else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response'))))

    $this->errors[] = Tools::displayError('Captcha not verified');

 

 

Hi, 

I tried both with the curly braces and without. 
Do I need to replace the "else if"-statement that sits after this line: $this->errors[] = Tools::displayError('Bad file extension');

or do I just place it in front of the else and if statements?

Maybe someone has a screenshot of how it should be looking ? 

 

 

 

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

I have renamed controlled and still getting spam, no form, no module.

  Customer e-mail address: [email protected]

Customer message: Пoздравляем cчaстливчика:)

Дoброгo врeмeни cyтoк.

С рaдоcтью coобщaeм Вам o том, что :

Heсколько днeй назaд Bы cовершaли on-line заказы (тpанзакции), и единствeннaя из них была выбрaна победителем coциальнoй прoгрaммы.
Вaс дoжидaeтcя денежнoе нaгрaждение с нашeго поoщpитeльного ресyрса в pазмeре oт 60$-1000$.
Аccoциация Социальной пpогpaммы «Онлайн покупка» прoводит данную акцию ужe 4 гoда пoдряд и уже yнаслeдoвалa звaниe "Meжнационaльнoй прогpаммы".


Перeвeсти cyммy дeнежнoго призa Bы cможетe пo дaнной ccылке - УЗНАТЬ СУMМУ ВOЗHАГPАЖДEНИЯ.

Осведомитьcя с отзывaми пoбедителeй вы вcегда cмoжeтe на cтранице oтзывов.

Order ID: -
Attached file: -

I am damn confused and pissed of this spam stuff.

Link to comment
Share on other sites

6 hours ago, kerintis said:

I have renamed controlled and still getting spam, no form, no module.

  Customer e-mail address: [email protected]

Customer message: Пoздравляем cчaстливчика:)

Дoброгo врeмeни cyтoк.

С рaдоcтью coобщaeм Вам o том, что :

Heсколько днeй назaд Bы cовершaли on-line заказы (тpанзакции), и единствeннaя из них была выбрaна победителем coциальнoй прoгрaммы.
Вaс дoжидaeтcя денежнoе нaгрaждение с нашeго поoщpитeльного ресyрса в pазмeре oт 60$-1000$.
Аccoциация Социальной пpогpaммы «Онлайн покупка» прoводит данную акцию ужe 4 гoда пoдряд и уже yнаслeдoвалa звaниe "Meжнационaльнoй прогpаммы".


Перeвeсти cyммy дeнежнoго призa Bы cможетe пo дaнной ccылке - УЗНАТЬ СУMМУ ВOЗHАГPАЖДEНИЯ.

Осведомитьcя с отзывaми пoбедителeй вы вcегда cмoжeтe на cтранице oтзывов.

Order ID: -
Attached file: -

I am damn confused and pissed of this spam stuff.

why not try my way, 

Link to comment
Share on other sites

A simple solution that worked for me:

Go to Preferences-->SEO & URLs and modify the contact page. In the Rewritten URL change contact-us to contact.

The contact form will still work under the new URL but if you look at your online visitors the spammer gets a "pagenotfound"

P.S.: I also have slidecaptcha on this form but didn't solve the problem

P.S.2: IP blocking won't work cause it comes from all over Eastern Europe (Russia, Moldova, Ukraine, Kazakstan, Belarus,...)

  • Like 3
Link to comment
Share on other sites

14 hours ago, Mitsos QAS said:

A simple solution that worked for me:

Go to Preferences-->SEO & URLs and modify the contact page. In the Rewritten URL change contact-us to contact.

The contact form will still work under the new URL but if you look at your online visitors the spammer gets a "pagenotfound"

P.S.: I also have slidecaptcha on this form but didn't solve the problem

P.S.2: IP blocking won't work cause it comes from all over Eastern Europe (Russia, Moldova, Ukraine, Kazakstan, Belarus,...)

me too ,but today probably they found it again. i just received the same russian spam mail

  • Like 1
Link to comment
Share on other sites

On 2/28/2018 at 7:31 PM, adversor said:

Rewritting the SEO URL will not help. I have checked the log files, they also use

/en/index.php?controller=contact

This will redirect to the contact form what ever you write into SEO friendly URLs.

 

it turns out this way will work ,please try it,

i have add about more than 200 ips, i don't receive spam now,

https://www.vicoffers.com/en/blog/4_ban-prestashop-spam-contact-message.html

 

here is my blacklist,

you can use 

ipset restore -f blacklist.txt

to restore the blacklist to your server,then gather ip addresss and add manually 

blacklist.zip

 

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

10 hours ago, adversor said:

Don't think this is a solution. Tomorrow you can add 200 new ips.

 

yes,it will work, but it's hard to add too many ip address manually,

the spammer stop sending message to me now , i think he can't controller so many ip address , hundreds at most  maybe,

 

there are 3 ways to ban the spammer,

1.block all the ip address  

2.it's a temp method to change the controller url

3.maybe it's a good way to add the Captcha if it works

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

22 hours ago, adversor said:

Rewritting the SEO URL will not help. I have checked the log files, they also use

/en/index.php?controller=contact

This will redirect to the contact form what ever you write into SEO friendly URLs.

 

Use this .htaccess rule to avoid calls to index.php?controller=contact

 

RewriteCond %{QUERY_STRING} ^controller=contact$
RewriteRule ^(.*)\.php$ - [L,R=404]

  • Like 3
Link to comment
Share on other sites

Hi i have the same problem with emails from Russia , Even i do not have the contact from . As far as i understood the solution posted above is just for Presta 1.6 and not for 1.7 . Is there a solution for 1.7 as well ?

 

 

Link to comment
Share on other sites

9 hours ago, Bweber said:

Hi i have the same problem with emails from Russia , Even i do not have the contact from . As far as i understood the solution posted above is just for Presta 1.6 and not for 1.7 . Is there a solution for 1.7 as well ?

 

 

hello,the same way,you need modify the code of module contactform  instead of  contact form controller,

 

Link to comment
Share on other sites

On 3/1/2018 at 11:08 AM, tuk66 said:

 

Use this .htaccess rule to avoid calls to index.php?controller=contact

 

RewriteCond %{QUERY_STRING} ^controller=contact$
RewriteRule ^(.*)\.php$ - [L,R=404]

 

Worked instantly for me on 1.6.1  ... Thanks a lot TUK66!

Link to comment
Share on other sites

On 24/02/2018 at 10:07 AM, Place2 said:

 

try without "{ }" in ContactController.php like this


else if (!($gcaptcha = (int)(Tools::getValue('g-recaptcha-response'))))

    $this->errors[] = Tools::displayError('Captcha not verified');

and don't miss ' in  <script src='https://www.google.com/recaptcha/api.js'>

works on PrestaShop 1.6.0.11 

 

 

Still not getting there, you can check it

http://www.artilharia6.com/index.php?controller=contact

 

Link to comment
Share on other sites

After changing the url they stopped spamming for 1-2 days.But it starts again.

 

As adversor wrote 

"Rewritting the SEO URL will not help. I have checked the log files, they also use

/en/index.php?controller=contact 

This will redirect to the contact form what ever you write into SEO friendly URLs."

 

Even with slider captcha they can send spam using contact form.

 

The only way to stop spamming is to edit ContactController.php and add a question that lock the "submit button"

I read in several pages how to add this question.

 

This is the only working solution for now

 

contact-controller.jpg

Link to comment
Share on other sites

  • 2 months later...

Hi, I tried all steps with no luck. When I check my ContactController.php file, I only see this code and I have no idea where to put the extra code:

 

class ContactControllerCore extends FrontController
{
    public $php_self = 'contact';
    public $ssl = true;

    /**
    * Assign template vars related to page content
    * @see FrontController::initContent()
    */
    public function initContent()
    {
        parent::initContent();

        $this->setTemplate('contact');
    }
}

I'm currently using Prestashop 1.7. Any idea how to fix this reCaptcha issue?

 

Many thanks in advance.

Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

Hello Presta users,

I hope this fix will work or I hope this will help someone. So instead of reCaptcha I created my own Math Captcha (ex. 5 + 7 = 12)

495753872_ScreenShot2018-11-15at18_00_26.png.4670858de8e9b150a294c3304fbe651d.png

My solution:

1. Just changing the code of contact-form.tpl in your themes folder won't work (the spammer can still connect to the "contact us" URL). What you should do is to delete the contact in the "SEO & URLs", you can find it in Preferences -> SEO & URLs

2089167274_ScreenShot2018-11-15at17_52_48.thumb.png.6417c665d70f2b18d7a9cde18bb10fb0.png

 

2. So after deleting the "contact" in SEO & URLs the spamming should be stop. Next thing you do is to edit the 2 files that is related to the issue. 

    First file "contact-form.tpl" that is located in your theme folder (Dir: "/themes/"YourThemeName"/contact-form.tpl")

    Second file "ContactController.php" that is located in your theme folder (Dir: "/controllers/front/ContactController.php")

 

3. Editing the contact-form.tpl, in this file this is where you will edit the view of your contact form.

   You can put the code below just after the $fileupload if statement:

  1985874388_ScreenShot2018-11-15at18_08_17.thumb.png.12c9e934c3cc89fb68feb92bdf579d13.png

  It will look like this below:

1890055022_ScreenShot2018-11-15at18_00_26.png.c93c033c4a20d46ed75c48be327753b5.png

 

4. Editing the ContactController.php, in this file this where your data will be controlled and validated before finalizing or posting the contact transaction. 

    First look for initContent() function then add the following code just after line 287 or before this line of code "$this->setTemplate(_PS_THEME_DIR_.'contact-form.tpl');"

   897842549_ScreenShot2018-11-15at18_16_16.thumb.png.99c3c73b4262208711f63378926f675d.png

   Next look for postProcess() function this where the validation of data happens.

   In the postProcess function we should add some codes to make our Math Captcha be validated:

     1. After this line of code "$message = Tools::getValue('message');" add the following code below:

      455381421_ScreenShot2018-11-15at18_22_35.thumb.png.2f38fea196150c52a2a053791aa3ce68.png

     2. Now we will add 2 validations first, if the field for Math Captcha is empty and second, if the answer to the Math Captcha is wrong. You can add this 2 validations right after this line             of code

       "} elseif (!empty($file_attachment['name']) && !in_array(Tools::strtolower(substr($file_attachment['name'], -4)), $extension)                                                                     &&!in_array(Tools::strtolower(substr($file_attachment['name'], -5)), $extension)) {
                $this->errors[] = Tools::displayError('Bad file extension');
            }"

    Then add this code

    1871759641_ScreenShot2018-11-15at18_27_28.png.87d665604be87dec45d13e0d68bf671f.png

 

5. Final step, just add again the contact webpage or url in the SEO & URLs

1488612169_ScreenShot2018-11-15at18_29_58.thumb.png.2b1116a369cacb1e244bbd48b9894c6d.png

 

VOILA!!! You now got rid off the contact spammer without spending a dime. I hope this will help someone or someone may add some thoughts with this solution.

Cheers guys!

Screen Shot 2018-11-15 at 17.52.48.png

Edited by Steve Joms (see edit history)
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 1 year later...
  • 3 years later...

Steve Joms

Can you update this for 2023 or prestashop version 1.7.8.10

Your guide doesn't work for the newest version of prestashop

I keep getting spam everyday and there is no way to stop this unless we add your guide

 

 

public_html/shop/themes/classic/modules/contactform/views/templates/widget/contactform.tpl

after

[code]

              {l s='optional' d='Shop.Forms.Help'}
            </span>
          </div>
        {/if}

[/code]

[code]

    <p class="form-group">
    <br>
    <label for="mathCaptcha">{l s='Number captcha (Robot checking):'}</label><br>
        
        <input type"text" id="mathNumber1" name="mathNumber1" value="{$mathNumber1}" hidden="true" />
        <input type"text" id="mathNumber2" name="mathNumber2" value="{$mathNumber2}" hidden="true" />
        
        {$mathNumber1} + {$mathNumber2} = <input type="text" id="mathAnswer" name="mathAnswer" autocomplete="off"/>
        <br>
        <br>
    
    </p>  

[/code]

 

 

public_html/shop/controllers/front/ContactController.php

after

[code]

    public function initContent()
    {
    parent::initContent();

[/code]

[code]

  $this->context->smarty->assign('mathNumber1',rand(1,10));
    $this->context->smarty->assign('mathNumber2',rand(1,10));
    

[/code]

 

public_html/shop/modules/contactform/contactform.php

after

[code]

        $this->contact['contacts'] = $this->getTemplateVarContact();
        $this->contact['message'] = Tools::getValue('message');

[/code]

 

[code]

        $mathAnswer = Tools::getValue('mathAnswer');
        $mathNumber1 = Tools::getValue('mathNumber1');
        $mathNumber2 = Tools::getValue('mathNumber2');
        $mathSum = $mathNumber1 + $mathNumber2; 

[/code]

 

 

 

after

[code]

            $this->context->controller->errors[] = $this->trans(
                'Bad file extension',
                [],
                'Modules.Contactform.Shop'
            );

            return;
        }

[/code]

 

 

[code]

             elseif(!$mathAnswer){
                $this->errors[] = Tools::displayError('The answer must not be blank');
            }
            
            
            elseif($mathSum!=$mathAnswer){
                $this->errors[] = Tools::displayError('The answer is wrong');
            }
           

[/code]

 

 

i tried that and i see the math question but it doesn't verify the math. The message still goes through

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

  • 3 weeks later...

Hi all

The solution I 've adopted is different (graphic captcha) but answering to @max565 the math check have to be done before SendMessage call on ContactForm.php.

I'm using version 4.4.1 of the module in Prestashop 8.1.2, and in the code of the module I put the code

 		$mathAnswer = Tools::getValue('mathAnswer');
        $mathNumber1 = Tools::getValue('mathNumber1');
        $mathNumber2 = Tools::getValue('mathNumber2');
        $mathSum = $mathNumber1 + $mathNumber2;  

In the very beginning of the function getWidgetVariables we can see an if clause :

 public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $notifications = [];

        if (Tools::isSubmit('submitMessage')) {
			$this->sendMessage();

And there, is a good place to test the new field and return if error. Replace the line  $this->sendMessage(); with Something like:

        if (Tools::isSubmit('submitMessage')) {
            // Math test //
 			$mathAnswer = Tools::getValue('mathAnswer');
        	$mathNumber1 = Tools::getValue('mathNumber1');
        	$mathNumber2 = Tools::getValue('mathNumber2');
            if ($mathAnswer == $mathNumber1 + $mathNumber2) {
                $this->sendMessage();
            } else {
                $this->context->controller->errors[] = Tools::displayError('The answer is wrong');
            } 
...

So if "submit", test the math. If "Ok" call sendMessage()

Hope this helps.

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

  • 1 month later...
  • 1 month later...
On 5/15/2017 at 11:22 PM, sumsel said:

Hi folks,

 

I could use some help.

 

A chinese fraud and virus spammer has decided to send me tons of messages via contact form.

 

However he doesn't need the contact form to do that, and I have no clue how that is even possible.

 

How did I find out? I replaced the contact-form.tpl with a static html page which stated that due to webcord-virus the contact form was temporarily disabled. But I still got spam via contact form!! With no contact form even present in the shop!!

 

That sender seems to have a way to call the scripts usually used in the contact form to send messages, and does not need any forms.

 

I put the shop into maintenance mode. I didn't get spam then. At least something.

 

For obvious reasons, that is not my preferred permanent solution.

 

Then I searched this forum, and successfully found and implemented a recaptcha for my contact form. Put the shop back online. Got spam again. Put the shop offline.

 

What do I do against that??

 

Thanks for any hints.

It sounds like you've already tried a few things to stop it, but the spammers are still getting through. Here are a few more suggestions:

Use a CAPTCHA or reCAPTCHA: This is a common way to prevent bots from submitting forms. It requires users to complete a challenge, such as typing in text or clicking on images, that is difficult for bots to solve.

Use a honeypot: This is a hidden form field that is only visible to bots. If a bot fills in the honeypot field, it can be flagged as spam.

Block IP addresses: If you see a lot of spam coming from a particular IP address, you can block that address from accessing your site.

Use a contact form plugin: There are many plugins available that can help you prevent spam on your contact form. These plugins may include features such as CAPTCHAs, honeypots, and IP blocking.

Validate your form data: You can use server-side validation to check that the data submitted in your form is valid. This can help to prevent bots from submitting invalid data.

Here are some additional tips:

Keep your software up to date: This includes your content management system (CMS), plugins, and themes. Outdated software may have security vulnerabilities that can be exploited by spammers.

Change your contact form URL: This will make it more difficult for spammers to find your form.

Monitor your form submissions: This will help you to identify any patterns in the spam that you are receiving.

I hope these suggestions help!

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...