阻止恶意URL请求错误查询BBQ脚本代码
阻止恶意URL请求错误查询BBQ是一个简单的脚本,可保护您的网站免遭恶意URL请求。检查所有传入流量,并悄阻止掉一些恶意请教代码eval(,base64_和过长请求字符串。这是一个简单而可靠的解决方案,非常适合无法使用.htaccess的网站。该阻止脚本可作为WordPress的插件或独立的脚本用于任何PHP -Powered网站。检查以下三部分URL请求:
请求URI
查询字符串
用户代理
1,Wordpress程序复制以下代码放入functions.php
function bbq_core() {
$request_uri_array = apply_filters('request_uri_items', array('@eval', 'eval\(', 'UNION(.*)SELECT', '\(null\)', 'base64_', '\/localhost', '\%2Flocalhost', '\/pingserver', 'wp-config\.php', '\/config\.', '\/wwwroot', '\/makefile', 'crossdomain\.', 'proc\/self\/environ', 'usr\/bin\/perl', 'var\/lib\/php', 'etc\/passwd', '\/https\:', '\/http\:', '\/ftp\:', '\/file\:', '\/php\:', '\/cgi\/', '\.cgi', '\.cmd', '\.bat', '\.exe', '\.sql', '\.ini', '\.dll', '\.htacc', '\.htpas', '\.pass', '\.asp', '\.jsp', '\.tar', '\.bash', '\/\.git', '\/\.svn', ' ', '\<', '\>', '\/\=', '\.\.\.', '\+\+\+', '@@', '\/&&', '\/Nt\.', '\;Nt\.', '\=Nt\.', '\,Nt\.', '\.exec\(', '\)\.html\(', '\{x\.html\(', '\(function\(', '\.php\([0-9]+\)', '(benchmark|sleep)(\s|%20)*\('));
$query_string_array = apply_filters('query_string_items', array('@@', '\(0x', '0x3c62723e', '\;\!--\=', '\(\)\}', '\:\;\}\;', '\.\.\/', '127\.0\.0\.1', 'UNION(.*)SELECT', '@eval', 'eval\(', 'base64_', 'localhost', 'loopback', '\%0A', '\%0D', '\%00', '\%2e\%2e', 'allow_url_include', 'auto_prepend_file', 'disable_functions', 'input_file', 'execute', 'file_get_contents', 'mosconfig', 'open_basedir', '(benchmark|sleep)(\s|%20)*\(', 'phpinfo\(', 'shell_exec\(', '\/wwwroot', '\/makefile', 'path\=\.', 'mod\=\.', 'wp-config\.php', '\/config\.', '\$_session', '\$_request', '\$_env', '\$_server', '\$_post', '\$_get'));
$user_agent_array = apply_filters('user_agent_items', array('acapbot', '\/bin\/bash', 'binlar', 'casper', 'cmswor', 'diavol', 'dotbot', 'finder', 'flicky', 'md5sum', 'morfeus', 'nutch', 'planet', 'purebot', 'pycurl', 'semalt', 'shellshock', 'skygrid', 'snoopy', 'sucker', 'turnit', 'vikspi', 'zmeu'));
$request_uri_string = false;
$query_string_string = false;
$user_agent_string = false;
if (isset($_SERVER['REQUEST_URI']) && !empty($_SERVER['REQUEST_URI'])) $request_uri_string = $_SERVER['REQUEST_URI'];
if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) $query_string_string = $_SERVER['QUERY_STRING'];
if (isset($_SERVER['HTTP_USER_AGENT']) && !empty($_SERVER['HTTP_USER_AGENT'])) $user_agent_string = $_SERVER['HTTP_USER_AGENT'];
if ($request_uri_string || $query_string_string || $user_agent_string) {
if (
// strlen( $_SERVER['REQUEST_URI'] ) > 255 || // optional
preg_match('/'. implode('|', $request_uri_array) .'/i', $request_uri_string) ||
preg_match('/'. implode('|', $query_string_array) .'/i', $query_string_string) ||
preg_match('/'. implode('|', $user_agent_array) .'/i', $user_agent_string)
) {
bbq_response();
}
}
}
add_action('plugins_loaded', 'bbq_core');
function bbq_response() {
header('HTTP/1.1 403 Forbidden');
header('Status: 403 Forbidden');
header('Connection: Close');
exit;
}
2,PHP脚本独立版,置于其他类PHP程序下
<?php
$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;
} ?>
相关文章
让woocommerce将产品标题设置为产品图片的
woocommerce图像标题和alt标签对SEO至关重要,更改每个图像标题和alt标签将花费很长时间。一般优化我们会在函数当中加载代码: add_filter(wp_get_attachment_image_attributes, change_attachement_image_a...
2020-02-29阻止恶意URL请求错误查询BBQ脚本代码
阻止恶意URL请求错误查询BBQ是一个简单的脚本,可保护您的网站免遭恶意URL请求。检查所有传入流量,并悄阻止掉一些恶意请教代码eval(,base64_和过长请求字符串。这是一个简单而可靠...
2020-04-13用户在WooCommerce访问时自动将产品添加到
实现用户在WooCommerce访问时自动将产品添加到购物车代码: /** * 用户在WooCommerce访问时自动将产品添加到购物车zuimoban.com */add_action( template_redirect, add_product_to_cart );function add_product_to_car...
2021-07-31从WordPress数据库中删除孤立的meta帖子元
如果在您的 WordPress网站生命周期中,您已经激活和停用了添加自定义帖子类型或为帖子类型添加其他选项的插件,那么您的网站很有可能包含孤立的meta帖子元。孤立是指他们的父meta帖...
2022-04-05配置WordPress在Zeus服务器重写规则
配置WordPress在Zeus服务器重写规则,rewrite.script 如下: RULE_0_START:# get the document rootmap path into SCRATCH:DOCROOT from /# initialize our variablesset SCRATCH:ORIG_URL = %{URL}set SCRATCH:REQUEST_URI = %{URL}# see if th...
2021-07-31修复WP Super Cache Preload预缓存不工作
WP Super Cache 是一个不错的 WordPress 缓存解决方案,但我无法让预加载功能在 VPS 上工作它甚至无法启动。preload 函数的作用是预先缓存所有帖子、标签等,以使一切更快. 首先要做的是关闭...
2022-04-04上传wordpress图片自动按照日期重命名代
在wordpress上传的图片多数以本地图片名直接上传,若是按照图片本性属性传,在SEO当中能起到很大作用,但是多数我们注意不到,可能包含特殊字符,让wordpress系统自动重新命名是最好...
2022-04-04优化wordPress中使搜索URL看起来更漂亮
使用 WordPress,您可以在Settings - Permalinks中使您的帖子 URL 更漂亮。 不幸的是,没有改进搜索结果页面外观的选项,默认情况下如下所示: www.zuimoban.com/?s=your-query 如您所见,这看起来不...
2022-06-27限制WooCommerce购物车最低付款金额
限制WooCommerce购物车最低付款金额,实现代码如下: /** * Set a minimum order amount for checkout source by zuimoban.com */add_action( woocommerce_checkout_process, wc_minimum_order_amount );add_action( woocommerce_before_ca...
2021-07-31WooCommerce创建新帐户时通知管理员代码
WooCommerce创建新帐户时通知管理员代码 /** * Notify admin when a new customer account is created */ add_action( woocommerce_created_customer, woocommerce_created_customer_admin_notification ); function woocommerce_created_custome...
2021-07-31