web攻击之八:溢出攻击(nginx服务器防sql注入/溢出攻击/spam及禁User-agents)
一、什么是溢出攻擊
首先, 溢出,通俗的講就是意外數據的重新寫入,就像裝滿了水的水桶,繼續裝水就會溢出,而溢出攻擊就是,攻擊者可以控制溢出的代碼,如果程序的對象是內核級別的,如dll、sys文件等,就可以直接操控系統內核了
其次,分類:按對象名加以區分:IIS溢出、SQL溢出等,就是按對象名來加以區分,按特點區分:遠程溢出、本地溢出
最后,溢出的基本原理:一是內存溢出;二是緩沖區溢出
1、內存溢出
內存溢出,是程序使用了不可靠的方式存取/復制內存緩沖區,或者是編輯設置的內存緩沖區太靠近數據結構等,進而導致內存緩沖區溢出,而溢出的字符就會取代后面的數據。例如,c語言不檢查數組邊界,不檢查數據類型的可靠性,而c語言與機器內核代碼接近,能直接訪問內存和寄存器。
2、緩沖區溢出
緩沖區是用戶為程序運行時在計算機中申請的一段連續的內存,它保存了給定類型的數據,而緩沖區溢出就是通過向程序的緩沖區中寫入超過其長度的內容,造成緩沖區的溢出,從而破壞程序的堆棧,使程序轉而執行其他的命令,以達到攻擊的目的。
3、內存、緩沖區、堆、棧的概念與聯系
這部分留著以后單獨闡述
nginx防御方法
本文章給大家介紹一個nginx服務器防sql注入/溢出攻擊/spam及禁User-agents實例代碼,有需要了解的朋友可進入參考。
在配置文件添加如下字段即可
server {
## 禁SQL注入 Block SQL injections
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;
}
## 禁掉文件注入
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|bluespill|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;
# 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;
}
}
總結
以上是生活随笔為你收集整理的web攻击之八:溢出攻击(nginx服务器防sql注入/溢出攻击/spam及禁User-agents)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AE错误代码解释
- 下一篇: mysql savepoint 什么意思