Nginx server prevents SQL injection/overflow attacks/spam and User-agents bans

Source: Internet
Author: User

Add the following fields to the configuration file:

Server {
# Block SQL injections for SQL Injection
Set $ block_ SQL _injections 0;
If ($ query_string ~ "Union. * select. * \ (") {
Set $ block_ SQL _injections 1;
}
If ($ query_string ~ "Union. * all. * select .*"){
Set $ block_ SQL _injections 1;
}
If ($ query_string ~ "Concat. * \ (") {
Set $ block_ SQL _injections 1;
}
If ($ block_ SQL _injections = 1 ){
Return 444;
}

# Disable file injection
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;
}

# Preventing overflow attacks
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 _] {} (=|\% 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;
}

# Disable the spam Field
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 | ciill | 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;
}

# Disable user-agents
Set $ block_user_agents 0;

# Don't disable wget if you need it to run cron jobs!
# 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;
}
}

Description: SQL Injection, overflow attacks, and spam protection are implemented by disabling the fields contained in the URL. Please add them as needed.
444 is returned, which does not respond to the client at all, saving system resources much more than 403.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.