Npcink Blog
切换菜单

Block Bad Queries - 阻止不良查询

本页目录3 节

是一个简单,超快速的插件,可保护您的网站免遭恶意 URL 请求。烧烤检查所有传入流量,并悄悄块坏请求包含讨厌的东西一样eval(,base64_和过长请求字符串。对于无法使用强大的.htaccess 防火墙的站点,这是一个简单而可靠的解决方案。

很棒的功能

  • 100%即插即用功能
  • 无需配置(可以正常工作)
  • 天生的速度和简单,没有多余的装饰
  • 100%专注于安全性和性能
  • 阻止各种恶意请求
  • 阻止目录遍历攻击
  • 阻止可执行文件上传
  • 阻止 SQL 注入攻击
  • 基于 5G / 6G 防火墙
  • 扫描所有传入流量并阻止不良请求
  • 扫描所有类型的请求:GET,POST,PUT,DELETE 等。
  • 在后台静默工作以保护您的网站
  • 易于使用的无忧安全插件
  • 经过全面测试,无错误的性能
  • 与其他安全性插件兼容
  • 定期更新和“面向未来”
  • 通过白名单/黑名单插件自定义阻止的字符串

隐私

该插件不收集或存储任何用户数据。它不会设置任何 cookie,也不会连接到任何第三方位置。因此,此插件不会以任何方式影响用户隐私。

无论是否使用 Gutenberg 块编辑器,均可完美运行

专业版

要获得高级保护和强大功能,请查看 BBQ Pro。

验证它是否正常

一旦 BBQ 安装,你可以验证它的工作通过请求下列网址从您的网站 S( example.com):

  • http://example.com/proc/self/environ
  • http://example.com/path/?q=%2e%2e
  • http://example.com/path/base64_

这些只是 BBQ 阻止的垃圾类型的示例。如果您的服务器针对这些示例返回 403“ Forbidden”(禁止)响应,则 BBQ 正在执行它的 thang。使用 BBQ 防火墙中包含的模式可以进行更多测试。

这个怎么运作

这基本上是我移植到 PHP 的 G 系列 黑名单的改编。它通过定义一组匹配并阻止恶意 URL 请求的正则表达式来工作。BBQ 扫描每个请求的三个部分:

  • 请求 URI
  • 查询字符串
  • 用户代理

根据策略设计的一组已知攻击模式检查这些变量是防止恶意攻击的有效方法。

BBQ 独立 PHP 脚本

要在非 WP 网站上实现 BBQ 脚本,请为每个页面请求(例如,在每个网页的开头)添加以下代码。

<?php
/*
Plugin Name: Block Bad Queries (BBQ)
Plugin URI: https://perishablepress.com/block-bad-queries/
Description: Automatically protects WordPress against malicious URL requests.
Author: Jeff Starr
Author URI: https://monzillamedia.com/
Version: (standalone)
License: GPL v2
Usage: No configuration necessary. Upload, activate and done. BBQ blocks bad queries automically to protect your site against malicious URL requests.
Tags: security, protect, firewall, php, eval, malicious, url, request, blacklist
*/
$request_uri = $_SERVER['REQUEST_URI'];
$query_string = $_SERVER['QUERY_STRING'];
$user_agent = $_SERVER['HTTP_USER_AGENT'];
// request uri
if ( //strlen($request_uri) > 255 ||
stripos($request_uri, 'eval(') ||
stripos($request_uri, 'CONCAT') ||
stripos($request_uri, 'UNION+SELECT') ||
stripos($request_uri, '(null)') ||
stripos($request_uri, 'base64_') ||
stripos($request_uri, '/localhost') ||
stripos($request_uri, '/pingserver') ||
stripos($request_uri, '/config.') ||
stripos($request_uri, '/wwwroot') ||
stripos($request_uri, '/makefile') ||
stripos($request_uri, 'crossdomain.') ||
stripos($request_uri, 'proc/self/environ') ||
stripos($request_uri, 'etc/passwd') ||
stripos($request_uri, '/https/') ||
stripos($request_uri, '/http/') ||
stripos($request_uri, '/ftp/') ||
stripos($request_uri, '/cgi/') ||
stripos($request_uri, '.cgi') ||
stripos($request_uri, '.exe') ||
stripos($request_uri, '.sql') ||
stripos($request_uri, '.ini') ||
stripos($request_uri, '.dll') ||
stripos($request_uri, '.asp') ||
stripos($request_uri, '.jsp') ||
stripos($request_uri, '/.bash') ||
stripos($request_uri, '/.git') ||
stripos($request_uri, '/.svn') ||
stripos($request_uri, '/.tar') ||
stripos($request_uri, ' ') ||
stripos($request_uri, '<') ||
stripos($request_uri, '>') ||
stripos($request_uri, '/=') ||
stripos($request_uri, '...') ||
stripos($request_uri, '+++') ||
stripos($request_uri, '://') ||
stripos($request_uri, '/&&') ||
// query strings
stripos($query_string, '?') ||
stripos($query_string, ':') ||
stripos($query_string, '[') ||
stripos($query_string, ']') ||
stripos($query_string, '../') ||
stripos($query_string, '127.0.0.1') ||
stripos($query_string, 'loopback') ||
stripos($query_string, '%0A') ||
stripos($query_string, '%0D') ||
stripos($query_string, '%22') ||
stripos($query_string, '%27') ||
stripos($query_string, '%3C') ||
stripos($query_string, '%3E') ||
stripos($query_string, '%00') ||
stripos($query_string, '%2e%2e') ||
stripos($query_string, 'union') ||
stripos($query_string, 'input_file') ||
stripos($query_string, 'execute') ||
stripos($query_string, 'mosconfig') ||
stripos($query_string, 'environ') ||
//stripos($query_string, 'scanner') ||
stripos($query_string, 'path=.') ||
stripos($query_string, 'mod=.') ||
// user agents
stripos($user_agent, 'binlar') ||
stripos($user_agent, 'casper') ||
stripos($user_agent, 'cmswor') ||
stripos($user_agent, 'diavol') ||
stripos($user_agent, 'dotbot') ||
stripos($user_agent, 'finder') ||
stripos($user_agent, 'flicky') ||
stripos($user_agent, 'libwww') ||
stripos($user_agent, 'nutch') ||
stripos($user_agent, 'planet') ||
stripos($user_agent, 'purebot') ||
stripos($user_agent, 'pycurl') ||
stripos($user_agent, 'skygrid') ||
stripos($user_agent, 'sucker') ||
stripos($user_agent, 'turnit') ||
stripos($user_agent, 'vikspi') ||
stripos($user_agent, 'zmeu')
) {
@header('HTTP/1.1 403 Forbidden');
@header('Status: 403 Forbidden');
@header('Connection: Close');
@exit;
} ?>

无需对此代码进行任何更改,因此您应该一切顺利。请注意,此脚本与当前版本的 WP 插件有所不同。已对更新版本的插件进行了优化,以更好地与 WordPress 配合使用,但此版本的 BBQ 总体上仍继续保护非 WP 网站。

请注意,任何时候您都可以使用最新模式在独立脚本中更新 BBQ 黑名单。只需下载 BBQ 插件,然后从主插件文件中复制正则表达式数组即可。