(2025-10-18, 10:47 PM)Billy_Bob Wrote: (2025-10-18, 02:54 PM)xxcorrosionxx Wrote: Im sure if mybb started to make you pay for there developments the spam bots would dissapear. Until then, since its source is public, its predictable.
I am looking into this code for the htaccess file. What do you think? It was posted here: .htaccess - Blocking bots with apache htaccess - Server Fault
Quote:<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
# block “AI” bots
RewriteCond %{HTTP_USER_AGENT} ^.*(AdsBot-Google|Amazonbot|anthropic-ai|Applebot|Applebot-Extended|AwarioRssBot|AwarioSmartBot|Bytespider|CCBot|ChatGPT|ChatGPT-User|Claude-Web|ClaudeBot|cohere-ai|DataForSeoBot|Diffbot|FacebookBot|facebookexternalhit|Google-Extended|GPTBot|ImagesiftBot|magpie-rawler|omgili|Omgilibot|peer39_crawler|PerplexityBot|YouBot|AhrefsBot|Barkrowler|SemrushBot|DotBot).*$ [NC]
RewriteRule .* - [F,L]
</IfModule>
(2025-10-18, 10:22 PM)Crazycat Wrote: Just read a fewpages, the only intelligent thing is "use cloudflare" (or any system like it).
Nothing in forum core can really stop bots, because they must be stopped before they access the front page. And the php can only react to a front load. So the answer is before the server or before the page is loaded.
Thanks..
That explains why all of the changes do squat to these SQL draining attacks.
Edit to add: I used the rule for the htacess file above. It took my SQL from 98% down to 62% average. I now have spikes in SQL usage but not a constant 98% and forum slowing. Some bots still get by but we are finding the range of IP's they are coming from and blocking. Its much better but there has to be a better way to stop these things.
1.) Turn on Bot Fight Mode (or Super Bot Fight on Pro).
2.) Add rate limiting (or WAF rules) for hot endpoints:
xmlhttp.php, search.php, member.php?action=profile, showthread.php with long querystrings.
3.) Managed Challenge for “AI/SEO bots” UAs you listed (don’t outright block or you’ll chase UA changes forever).
4.) Cache Everything for guests on index/forum display pages (bypass cache on cookies mybbuser/sid).
5.) mod_security (OWASP CRS): enable; add a custom rule to challenge traffic that hits xmlhttp.php/search.php at high frequency.
6.) fail2ban: create an Apache/Nginx jail that bans IPs doing, e.g., > 300 req/5m or > 30 /search.php in 1m.
https://www.youtube.com/watch?v=kgdoVeyoO2E
7.) mod_evasive (Apache) or nginx limit_req (Nginx) for simple burst control.
8.) Smarter .htaccess (keep it simple & safe)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# 3.1 Block empty or obviously scripted UAs
RewriteCond %{HTTP_USER_AGENT} ^\s*$ [OR]
RewriteCond %{HTTP_USER_AGENT} (curl|wget|python-requests|java|okhttp|libwww|httpclient) [NC]
RewriteRule ^ - [F,L]
# 3.2 Your “AI/SEO” bot list -> 403 (can move these to CF WAF as a Challenge instead)
RewriteCond %{HTTP_USER_AGENT} (AdsBot-Google|Amazonbot|anthropic-ai|Applebot|Awario|Bytespider|CCBot|ChatGPT|Claude|cohere-ai|DataForSeoBot|Diffbot|facebookexternalhit|Google-Extended|GPTBot|ImagesiftBot|magpie|omgili|Omgilibot|peer39|PerplexityBot|YouBot|AhrefsBot|Barkrowler|SemrushBot|DotBot) [NC]
RewriteRule ^ - [F,L]
# 3.3 Overly long querystrings (cheap SQL drains)
RewriteCond %{THE_REQUEST} \?
RewriteCond %{QUERY_STRING} .{1024,}
RewriteRule ^ - [F,L]
# 3.4 Disallow uncommon/abused methods
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD)$
RewriteRule ^ - [F,L]
</IfModule>
# 3.5 Deny access to obvious garbage
<FilesMatch "(\.env|composer\.(json|lock)|package\.json|yarn\.lock|phpunit|\.git|\.hg|\.svn)">
Require all denied
</FilesMatch>
MyBB knobs that actually reduce DB work
10.) Guests: disable “Who’s Online” & member list for guests; add a search cooldown and require login for search.
11.) Flood control: set post flood & search flood (ACP → Configuration).
12.) CAPTCHA/Turnstile/hCaptcha on register & any guest actions; add StopForumSpam integration (plugin).
13.) Limit AJAX for guests: many scrapers hammer xmlhttp.php; challenge that path in WAF for non-cookie’d users.
14.) Hide heavy widgets from guests (stats blocks, top posters, big counters).
SQL dropped from 98% → 62%: UA blocking removed the “polite” crawlers; spoofers and distributed hosts kept going. Moving those checks to the edge with challenges + rate limits is what will cut it further (usually into the teens), and caching guest pages drops the remaining read load.
Rule A – Challenge hot endpoints for non-logged-in users (guests):
(if
(http.request.uri.path in {"/xmlhttp.php" "/search.php" "/private.php" "/member.php" "/misc.php"})
and not http.cookie contains "mybbuser="
)
then Managed Challenge
Rule B – Nuke junk user-agents (keep this tight):
(if
http.user_agent eq "" or
http.user_agent ~ "(curl|wget|python-requests|java|okhttp|libwww|httpclient|masscan|nmap)"
)
then Block
Rule C – Rate abuse to showthread/forumdisplay (query floods):
(if
(http.request.uri.path in {"/showthread.php" "/forumdisplay.php"})
and not http.cookie contains "mybbuser="
and http.request.method in {"GET" "HEAD"}
and (len(http.request.uri.query) > 1024 or contains(http.request.uri.query, "sid="))
)
then Managed Challenge