保证业务安全,保证业务性能。
1. 业务逻辑更新迭代的时候(代码上线,代码更新)
2. 人为操作导致
自己内部人员,人为误操作导致问题
外部黑客攻击
根据SQL语句中的逻辑判断漏洞,绕过语句授权表判断,从而直接进入数据库,执行相关操作。
提权,root权限,植入webshell。
sqlmap是一个开源的渗透测试工具,可以用来进行自动化检测,利用SQL注入漏洞,获取数据库服务器的权限。它具有功能强大的检测引擎,针对各种不同类型数据库的渗透测试的功能选项,包括获取数据库中存储的数据,访问操作系统文件甚至可以通过外带数据连接的方式执行操作系统命令。
sqlmap支持MySQL, Oracle,PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird,Sybase和SAP MaxDB等数据库的各种安全漏洞检测。
官方网站:http://sqlmap.org/,
下载地址:https://github.com/sqlmapproject/sqlmap/zipball/master
演示视频:https://asciinema.org/a/46601
教程:http://www.youtube.com/user/inquisb/videos
学习网站:超详细SQLMap使用攻略及技巧分享 - FreeBuf网络安全行业门户
-u url 指定需要注入的监测点
--dbs 暴露当前注入系统的数据库列表
--current-db 暴露当前所访问数据库的名字
--tables 列出表
--columns 暴露字段
-D 指定数据库
-T 指定表
--dump 暴露某一字段的内容
Lua解析器下载地址:http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
cd /usr/local/src
wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz
tar zxf LuaJIT-2.1.0-beta3.tar.gz
cd LuaJIT-2.1.0-beta3
make PREFIX=/usr/local/luajit
make install PREFIX=/usr/local/luajit
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1
vim /etc/profile.d/lua.sh
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1
cd /usr/local/src
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.1.tar.gz
tar -xzvf v0.3.1.tar.gz
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.13.tar.gz
tar -xzvf v0.10.13.tar.gz
apt-get update
apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev libssl-dev lua* -y
cd /opt
wget http://nginx.org/download/nginx-1.21.4.tar.gz
tar xf nginx-1.21.4.tar.gz
cd nginx-1.21.4
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --add-module=/usr/local/src/ngx_devel_kit-0.3.1 --add-module=/usr/local/src/lua-nginx-module-0.10.13
make && make install
ll /etc/nginx
ll /usr/sbin/nginx
nginx -V
cd /opt
git clone https://github.com/loveshell/ngx_lua_waf.git
mkdir /etc/nginx/lua.conf
cp -r ngx_lua_waf/* /etc/nginx/lua.conf/
vim /etc/nginx/lua.conf/config.lua
RulePath = "/etc/nginx/lua.conf/"
attacklog = "on"
logdir = "/etc/nginx/lua.conf/logs/hack/"
UrlDeny="on"
Redirect="on"
CookieMatch="on"
postMatch="on"
whiteModule="on"
black_fileExt={"php","jsp"}
ipWhitelist={"127.0.0.1"}
ipBlocklist={"1.0.0.1"}
CCDeny="on"
CCrate="100/60"
DenySeconds="360"
html=[[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>请求不被许可</title>
<style type="text/css">
<!--
body {margin: 0px; padding:0px; font-family:"微软雅黑", Arial, "Trebuchet MS", Verdana, Georgia,Baskerville,Palatino,Times; font-size:16px;}
div{margin-left:auto; margin-right:auto;}
a {text-decoration: none; color: #1064A0;}
a:hover {color: #0078D2;cursor: pointer}
img { border:none; }
h1,h2,h3,h4 {
/* display:block;*/
margin:0;
font-weight:normal;
font-family: "微软雅黑", Arial, "Trebuchet MS", Helvetica, Verdana ;
}
h1{font-size:44px; color:#0188DE; padding:20px 0px 10px 0px;}
h2{color:#0188DE; font-size:16px; padding:10px 0px 40px 0px;}
#wrapper{width:100%;}
#page{width:910px; padding:20px 20px 40px 20px; margin-top:80px;}
.button{width:180px; height:28px; margin-left:0px; margin-top:10px; background:#009CFF; border-bottom:4px solid #0188DE; text-align:center;}
.button a{width:180px; height:28px; display:block; font-size:14px; color:#fff; }
.button a:hover{ background:#5BBFFF;}
a.apply-btn {
display: inline-block;
width: 200px;
height: 50px;
line-height: 50px;
background: #0188DE;
font-size: 20px;
color: #cdfff7;
text-align: center;
}
.detail-info{
padding: 10px 0;
border: 1px solid red;
height: auto;
width: 400px;
position: absolute;
left: 0;
top:21px;
background: #fff;
border-radius: 3px;
display: none;
}
.active .detail-info{
display: block;
}
.msg-item{
padding:0 20px;
line-height: 26px;
font-size: 14px;
color:#000;
}
.msg-item label{
float:left;
height: 26px;
line-height: 26px;
width:100px;
text-align: right;
}
.msg-item div{
overflow: hidden;
line-height: 26px;
word-wrap: break-word;
word-break: break-all;
}
-->
</style></head>
<body>
<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
<div id="wrapper">
<div id="page" style="border-style:dashed; border-color:#e4e4e4; line-height:30px; no-repeat right 130px;">
<h1 style="text-align: center;">很抱歉, 您的操作被防火墙拦截!</h1>
<h2 style="text-align: center;">Sorry, Do not do it. </h2>
<p style="text-align: center;">
<font color="green">您的IP地址已被记录:</font>
<font color="red">
<script type="text/javascript">
document.write(returnCitySN["cip"] + ', 地区:' + returnCitySN["cname"]+",浏览器版本:"+getBrowserInfo());
function getBrowserInfo()
{
var agent = navigator.userAgent.toLowerCase() ;
var regStr_ie = /msie [\d.]+;/gi ;
var regStr_ff = /firefox\/[\d.]+/gi
var regStr_chrome = /chrome\/[\d.]+/gi ;
var regStr_saf = /safari\/[\d.]+/gi ;
//IE
if(agent.indexOf("msie") > 0)
{
return agent.match(regStr_ie) ;
}
//firefox
if(agent.indexOf("firefox") > 0)
{
return agent.match(regStr_ff) ;
}
//Chrome
if(agent.indexOf("chrome") > 0)
{
return agent.match(regStr_chrome) ;
}
//Safari
if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0)
{
return agent.match(regStr_saf) ;
}
}
</script></font></p>
</div>
</div>
</body>
</html>
]]
解释
RulePath = "/etc/nginx/lua.conf/wafconf/" --规则存放目录
attacklog = "on" --是否开启攻击信息记录,需要配置 logdir
logdir = "/etc/nginx/lua.conf/logs/hack/" 存储目录,该目录需要用户自己新建,切需要 nginx 用户的可写权限
UrlDeny="on" --是否拦截 url 访问
Redirect="on" --是否拦截后重定向
CookieMatch="on" --是否拦截 cookie 攻击
postMatch="on" --是否拦截 post 攻击
whiteModule="on" --是否开启 URL 白名单
black_fileExt={"php","jsp"} --填写不允许上传文件后缀类型
ipWhitelist={"127.0.0.1"} --ip 白名单,多个 ip 用逗号分隔
ipBlocklist={"1.0.0.1"} --ip 黑名单,多个 ip 用逗号分隔
CCDeny="on" --是否开启拦截 cc 攻击(需要 nginx.conf 的 http 段增加 lua_shared_dict limit 10m;)
CCrate="100/60" --设置 cc 攻击频率,单位为秒,默认 1 分钟同一个 IP只能请求同一个地址 100 次
DenySeconds="360" --原来攻击被封默认 60秒,这里修改为自定义,我这设定为 360 秒(这里是新加的)
html=[[
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>请求不被许可</title>
<style type="text/css">
<!--
body {margin: 0px; padding:0px; font-family:"微软雅黑", Arial, "Trebuchet MS", Verdana, Georgia,Baskerville,Palatino,Times; font-size:16px;}
div{margin-left:auto; margin-right:auto;}
a {text-decoration: none; color: #1064A0;}
a:hover {color: #0078D2;cursor: pointer}
img { border:none; }
h1,h2,h3,h4 {
/* display:block;*/
margin:0;
font-weight:normal;
font-family: "微软雅黑", Arial, "Trebuchet MS", Helvetica, Verdana ;
}
h1{font-size:44px; color:#0188DE; padding:20px 0px 10px 0px;}
h2{color:#0188DE; font-size:16px; padding:10px 0px 40px 0px;}
#wrapper{width:100%;}
#page{width:910px; padding:20px 20px 40px 20px; margin-top:80px;}
.button{width:180px; height:28px; margin-left:0px; margin-top:10px; background:#009CFF; border-bottom:4px solid #0188DE; text-align:center;}
.button a{width:180px; height:28px; display:block; font-size:14px; color:#fff; }
.button a:hover{ background:#5BBFFF;}
a.apply-btn {
display: inline-block;
width: 200px;
height: 50px;
line-height: 50px;
background: #0188DE;
font-size: 20px;
color: #cdfff7;
text-align: center;
}
.detail-info{
padding: 10px 0;
border: 1px solid red;
height: auto;
width: 400px;
position: absolute;
left: 0;
top:21px;
background: #fff;
border-radius: 3px;
display: none;
}
.active .detail-info{
display: block;
}
.msg-item{
padding:0 20px;
line-height: 26px;
font-size: 14px;
color:#000;
}
.msg-item label{
float:left;
height: 26px;
line-height: 26px;
width:100px;
text-align: right;
}
.msg-item div{
overflow: hidden;
line-height: 26px;
word-wrap: break-word;
word-break: break-all;
}
-->
</style></head>
<body>
<script src="https://pv.sohu.com/cityjson?ie=utf-8"></script>
<div id="wrapper">
<div id="page" style="border-style:dashed; border-color:#e4e4e4; line-height:30px; no-repeat right 130px;">
<h1 style="text-align: center;">很抱歉, 您的操作被防火墙拦截!</h1>
<h2 style="text-align: center;">Sorry, Do not do it. </h2>
<p style="text-align: center;">
<font color="green">您的IP地址已被记录:</font>
<font color="red">
<script type="text/javascript">
document.write(returnCitySN["cip"] + ', 地区:' + returnCitySN["cname"]+",浏览器版本:"+getBrowserInfo());
function getBrowserInfo()
{
var agent = navigator.userAgent.toLowerCase() ;
var regStr_ie = /msie [\d.]+;/gi ;
var regStr_ff = /firefox\/[\d.]+/gi
var regStr_chrome = /chrome\/[\d.]+/gi ;
var regStr_saf = /safari\/[\d.]+/gi ;
//IE
if(agent.indexOf("msie") > 0)
{
return agent.match(regStr_ie) ;
}
//firefox
if(agent.indexOf("firefox") > 0)
{
return agent.match(regStr_ff) ;
}
//Chrome
if(agent.indexOf("chrome") > 0)
{
return agent.match(regStr_chrome) ;
}
//Safari
if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0)
{
return agent.match(regStr_saf) ;
}
}
</script></font></p>
</div>
</div>
</body>
</html>
]]
mkdir -p /etc/nginx/lua.conf/logs/hack/
chown -R nginx.nginx /etc/nginx
vim /nginx/nginx.conf
...
http{
...
lua_package_path "/etc/nginx/lua.conf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /etc/nginx/lua.conf/init.lua;
access_by_lua_file /etc/nginx/lua.conf/waf.lua;
}
vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
http://dudewu.top/test.php?id=../etc/passwd