Use cloudflare or some other firewall to block some countries if you can. China, Hong Kong, Russia. This does not stop all the spam however and does not work if you need those countries to be able to access of course. But it was helpful to let me actually use the admin panel as the server was getting hammered pretty hard.
Enable the build in Google Recaptcha or use an alternative plugin if you have not updated Magento to 2.3.0+
In Magento 2.3 to enable the built in Google reCAPTCHA.
- Visit Stores > Settings > Configuration > Security > Google reCAPTCHA
- Generate Recaptcha v2 invisible recaptcha or I'm not a bot keys.
- Enter them into the admin config on that page and enable it on the frontend for Use in Create user.
Enabling for other features can't really hurt either however.
For cleaning up existing accounts find patterns in their input and create queries to select them whilst ensuring your normal users are not part of that set of data.
You can delete them from the customer_entity table.
Example SQL from a site I cleaned up:
Craft your own as it would need to be mindful of your circumstances your dataset etc don't hold me responsible if you wipe wrong users take backup first!
DELETE FROM customer_entity
WHERE SUBSTRING_INDEX(email, '\@', -1) IN ('pp.com',
'sf-express.com',
'qqlong.com',
'kinohit.win',
'sohu.com',
'21cn.com',
'yeah.net',
'koreamail.com',
'aliyun.com',
'mail.ru',
'VIP.SINA.COM',
'yahoo.co.in',
'icload.com',
'sogou.com',
'vip.qq.com',
'sina.cn',
'189.cn',
'wo.com.cn',
'qq.cn',
'sina.com.cn',
'126.cn',
'yahoo.com.cn',
'3g.cn',
'163.com',
'167.com',
'139.com',
'126.com',
'130.com',
'144.com',
'123.com',
'ca800.com',
'168.com',
'188.com',
'1974.com',
'qq.co',
'sina.com',
'qq.com',
'qq.con',
'QQ.come',
'yandex.com',
'5ol.com',
'yeat.net',
'yahoo.cn')
OR lastname LIKE '%http://%'
OR lastname LIKE '%https://%'
OR lastname LIKE '%【%】%'
OR lastname LIKE '%tw55.cc%'
OR lastname LIKE '%www.ope2228.com%'
Way 1: Enable Google reCAPTCHA
Ensure the old basic Magento Captcha is disabled. Customers > Customer Configuration > CAPTCHA
Enable CAPTCHA on Storefront: No
As it will conflict with the Google reCAPTCHA...
Official documentation links:
https://docs.magento.com/m2/ce/user_guide/configuration/security/google-recaptcha.html
https://docs.magento.com/m2/ce/user_guide/stores/security-google-recaptcha.html
Way 2: add SpamUsersFilter Plugin
//MyCompany/ValidateAttributeLength/etc/frontend/di.xml
<type name="Magento\Customer\Model\AccountManagement">
<plugin disabled="false" name="MyCompany_ValidateAttributeLength_Plugin_Magento_Customer_Model_AccountManagement" sortOrder="10" type="MyCompany\ValidateAttributeLength\Plugin\Magento\Customer\Model\AccountManagement"/>
</type>
//MyCompany/ValidateAttributeLength/Plugin/Magento/Customer/Model/AccountManagement.php
<?php
namespace MyCompany\ValidateAttributeLength\Plugin\Magento\Customer\Model;
use \Magento\Framework\Exception\LocalizedException;
class AccountManagement
{
public function beforeCreateAccount(
\Magento\Customer\Model\AccountManagement $subject,
$customer
)
{
$regexp = '/(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\.[A-Z0-9]{1,})\.?/im';
$firstName = $customer->getFirstname();
$lastName = $customer->getLastname();
if (strlen($firstName) > 70 || strlen($lastName) > 70) {
throw new \Exception(__("Name to long"));
} elseif (preg_match($regexp, $lastName . $firstName)) {
throw new LocalizedException(__("Site name doesn't allowed"));
}
}
}
The bots just seem to hit the account creation endpoint (Yes even if you delete the Create Account buttons/links from your theme) but deleting their accounts or deactivating is recommended as they could sleep till later and spam other things and they use up space in your DB anyway....
Good luck everyone.