nginx 拦截非法字符,nginx禁止url访问特定字符,nginx过滤url
off999 2025-01-20 15:40 19 浏览 0 评论
## nginx 拦截非法字符,nginx禁止url访问特定字符,nginx过滤url访问
参考代码一
#前缀为无限,后面的精准屏蔽字符 123
if ($request_uri ~* "123") {
return 403 "I've recorded your ip Wait to check the water meter";
}
参考代码二
#前缀为index.php,后面的精准屏蔽字符 123
if ($request_uri ~* "/index.php\123") {
return 403 "I've recorded your ip Wait to check the water meter";
}
参考代码三
location / {
# 当访问的url中含有/%#时返回404
if ($request_uri ~* "/%#") {
return 404;
}
#当访问url的后面带有?的链接 返回404
if ($request_uri ~* ^/a/m/(.*)\.html\?(.*)$) {
return 404;
}
}注释:
过滤链接中的?在nginx的配置文件中写入
location / {# 当访问的url中含有/%#时返回404if ($request_uri ~* "/%#") {return 404;}#
当访问url的后面带有?的链接 返回404if ($request_uri ~*^/a/m/(.*)\.html\?(.*)$) {return 404;
nginx 正则表达式
=开头表示精确匹配,如 A 中只匹配根目录结尾的请求,后面不能带任何字符串。
^~ 开头表示uri以某个常规字符串开头,不是正则匹配
~ 开头表示区分大小写的正则匹配;
~* 开头表示不区分大小写的正则匹配
.* .匹配任意字符,*匹配数量0到正无穷;
\. \转义,匹配.
/ 通用匹配, 如果没有其它匹配,任何请求都会匹配到
本站测试代码,小白一键复制(注:需要自行根据网站程序定义)
宝塔为例:/www/server/panel/vhost/nginx/你的网站域名.conf,复制代码点击保存
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "../../../../../../") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* ";") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "&") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为无限,后面的是屏蔽字符
if ($request_uri ~* "base64") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\&") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\?") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\;") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\=") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\=") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\_") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\./") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\:") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\base64") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\%") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\wp-content") {
return 403 "I've recorded your ip Wait to check the water meter";
}
#前缀为index.php屏蔽,后面的是屏蔽字符
if ($request_uri ~* "/index.php\;amp") {
return 403 "I've recorded your ip Wait to check the water meter";
}## 附带:nginx ql语句过滤、文件注入禁止、溢出攻击过滤、spam字段过滤、user-agents头过滤
sql语句过滤
if ($request_uri ~* "(cost\()|(concat\()") {
return 444;
}
if ($request_uri ~* "[+|(%20)]union[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]and[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]select[+|(%20)]") {
return 444;
}文件注入禁止
set $block_file_injections 0;
if ($query_string ~ “[a-zA-Z0-9_]=http://”) {
set $block_file_injections 1;
}
if ($query_string ~ “[a-zA-Z0-9_]=(\.\.//?)+”) {
set $block_file_injections 1;
}
if ($query_string ~ “[a-zA-Z0-9_]=/([a-z0-9_.]//?)+”) {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 444;
}溢出攻击过滤
set $block_common_exploits 0;
if ($query_string ~ “(<|%3C).*script.*(>|%3E)”) {
set $block_common_exploits 1;
}
if ($query_string ~ “GLOBALS(=|\[|\%[0-9A-Z]{0,2})”) {
set $block_common_exploits 1;
}
if ($query_string ~ “_REQUEST(=|\[|\%[0-9A-Z]{0,2})”) {
set $block_common_exploits 1;
}
if ($query_string ~ “proc/self/environ”) {
set $block_common_exploits 1;
}
if ($query_string ~ “mosConfig_[a-zA-Z_]{1,21}(=|\%3D)”) {
set $block_common_exploits 1;
}
if ($query_string ~ “base64_(en|de)code\(.*\)”) {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 444;
}spam字段过滤
set $block_spam 0;
if ($query_string ~ “\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b”) {
set $block_spam 1;
}
if ($query_string ~ “\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b”) {
set $block_spam 1;
}
if ($block_spam = 1) {
return 444;
}user-agents头过滤
set $block_user_agents 0;
if ($http_user_agent ~ “Wget”) {
set $block_user_agents 1;
}
# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ “Indy Library”) {
set $block_user_agents 1;
}
# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ “libwww-perl”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GetRight”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GetWeb!”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Go!Zilla”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Download Demon”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “Go-Ahead-Got-It”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “TurnitinBot”) {
set $block_user_agents 1;
}
if ($http_user_agent ~ “GrabNet”) {
set $block_user_agents 1;
}
if ($block_user_agents = 1) {
return 444;
}
}自动防护
if ($request_uri ~* \.(htm|do)\?(.*)$) {
set $req $2;
}
if ($req ~* "(cost\()|(concat\()") {
return 503;
}
if ($req ~* "union[+|(%20)]") {
return 503;
}
if ($req ~* "and[+|(%20)]") {
return 503;
}
if ($req ~* "select[+|(%20)]") {
return 503;
}注:使用上也需要进行相应的调整
- 上一篇:Nginx限流配置详解
- 下一篇:Nginx的location指令
相关推荐
-
- 如何复制粘贴(如何复制粘贴excel表格内容)
-
需要复制文字的时候只要先选中文字,然后同时按住Ctrl+C键,然后松手就已经复制了文字,在需要粘贴的地方同时按住:Ctrl+V就可以看到文字被粘贴了,非常的方便。扩展资料:Alt键,这个键叫做改变,很多快捷键都需要使用到这个键,矩形...
-
2025-11-14 05:51 off999
- hotmail电子邮箱登录(hotmail邮箱在线登录)
-
***@hotmail.com1、其中***是你自己申请的邮箱的用户名。2、hotmail要写在符号@后面。3、最后加上.com,这样就是一个完整的hotmail邮箱的格式。4、比如:zhangj...
- win10iso文件(win10iso文件怎么安装)
-
安装Win10ISO系统文件需要以下步骤:1.首先需要从Microsoft官网下载Win10ISO系统文件,打开网站后选择Win10的版本、语言和架构(32位或64位),点击下载即可。2.下载...
- 英特尔显卡性能排行(英特尔显卡性能排行天梯图)
-
IRIS(英特尔第四/五代集成显卡)英特尔第四代集成显卡,分为HD4200/4400/4600,HD5100/5200。代号为GT2/3/3e,中文名为锐炬。hd420044004600和台式...
- 电脑做系统u盘启动选项(做系统开机u盘怎么选择)
-
操作须知:1、设置U盘启动分很多种:传统legacy机型设置、uefi新机型设置、uefi机型改legacy启动设置2、由于电脑品牌以及机型非常多,这边仅列举一部分电脑的设置方法,3、如果是uefi机...
- 未安装nvidia控制面板(电脑未安装nvidia控制面板)
-
如果你使用的是Nvidia显卡,但未安装Nvidia控制面板,则可能会遇到以下问题:1.无法进行高级显卡设置:Nvidia控制面板提供了高级显卡设置选项,例如显卡超频、显示器分辨率和刷新率、视频调整...
- u盘检测不到怎么修复(u盘检查不了是什么原因)
-
以下是可能的解决办法:1.更换不同的USB端口。有时候电脑某个USB端口可能出现问题,试试换一个不同的端口。2.重启电脑。有时候出现问题的USB端口可能需要重启才能正常。3.插拔几次U盘。有时候...
- win7 共享设置(win7共享设置详细步骤)
-
1.进入控制面板家庭组页打开控制面板找到网络和Internet下面的家庭组和共享选项并打开?2.进入更改高级共享设置打开以后选择更改高级共享设置功能进入?3.开启文件和打印机共享开启文件和打印机共享,...
- 电脑硬盘怎么装步骤图(电脑硬盘怎么装步骤图片)
-
1、查看硬盘的各项信息。硬盘的背面会有硬盘的存储容量以及电压,功率,转速等基本信息。2、购买到的一整块硬盘里面包括硬盘、对接线跟螺丝钉。将对接线和螺丝钉摆在一旁。3、在硬盘的上方会有两个SATA接口,...
- 小马win10永久激活(小马win10永久激活工具使用方法)
-
很简单,重装系统win7,这个可以激活的,然后根据推送升级win10,如果有强迫症可以升级以后重新安装win10系统,以后都是自动联网激活的。安全。小马激活工具win10版是小马专门为windowns...
- win10开机欢迎时间太长(开机欢迎界面时间长)
-
win10第一个就是你系统里的垃圾太多,如果系统垃圾太多,直接清理垃圾就可以解决这个问题,第二个就是你的开机启动项过多,如果开机启动项过多,直接关闭不必要的开机启动项就可以缩短开机时间,就可以解决你...
- 登录126邮箱入口(登录126邮箱入口官网)
-
126邮箱是网易的一个免费邮箱登录入口在浏览器输入:mail.126.com浏览器进入126邮箱网站之后,即可自行登录126邮箱账号。如何在手机上登录126邮箱1、打开手机,找到并打开网易邮箱软件。2...
欢迎 你 发表评论:
- 一周热门
-
-
抖音上好看的小姐姐,Python给你都下载了
-
全网最简单易懂!495页Python漫画教程,高清PDF版免费下载
-
Python 3.14 的 UUIDv6/v7/v8 上新,别再用 uuid4 () 啦!
-
python入门到脱坑 输入与输出—str()函数
-
飞牛NAS部署TVGate Docker项目,实现内网一键转发、代理、jx
-
宝塔面板如何添加免费waf防火墙?(宝塔面板开启https)
-
Python三目运算基础与进阶_python三目运算符判断三个变量
-
(新版)Python 分布式爬虫与 JS 逆向进阶实战吾爱分享
-
慕ke 前端工程师2024「完整」
-
失业程序员复习python笔记——条件与循环
-
- 最近发表
- 标签列表
-
- python计时 (73)
- python安装路径 (56)
- python类型转换 (93)
- python进度条 (67)
- python吧 (67)
- python的for循环 (65)
- python格式化字符串 (61)
- python静态方法 (57)
- python列表切片 (59)
- python面向对象编程 (60)
- python 代码加密 (65)
- python串口编程 (77)
- python封装 (57)
- python写入txt (66)
- python读取文件夹下所有文件 (59)
- python操作mysql数据库 (66)
- python获取列表的长度 (64)
- python接口 (63)
- python调用函数 (57)
- python多态 (60)
- python匿名函数 (59)
- python打印九九乘法表 (65)
- python赋值 (62)
- python异常 (69)
- python元祖 (57)
