linux中防CC攻击两种实现方法(转)

时间:2021-09-19 19:12:22

CC攻击就是说攻击者利用服务器或代理服务器指向被攻击的主机,然后模仿DDOS,和伪装方法网站,这种CC主要是用来攻击页面的,导致系统性能用完而主机挂掉了,下面我们来看linux中防CC攻击方法。

什么是CC攻击

cc攻击简单就是(ChallengeCollaar)

CC攻击的原理就是攻击者控制某些主机不停地发大量数据包给对方服务器造成服务器资源耗尽,一直到宕机崩溃。CC主要是用来攻击页面的,每个人都有 这样的体验:当一个网页访问的人数特别多的时候,打开网页就慢了,CC就是模拟多个用户(多少线程就是多少用户)不停地进行访问那些需要大量数据操作(就 是需要大量CPU时间)的页面,造成服务器资源的浪费,CPU长时间处于100%,永远都有处理不完的连接直至就网络拥塞,正常的访问被中止。

防止CC攻击方法

我用防止这CC攻击有两种方法
第一种就是利用本机的防火墙来解决可以安装CSF之内的防火墙,这种的弊端是只能防止小规模的CC攻击和DDOS(我的站在阿里云,所以不用太担心DDOS)CC攻击比较猛的话机器也直接CUP跑满了。
第二种方式是添加CDN,这种防止CC攻击的方法是最好的,不过CDN一般都要钱,于是我找到一个https://www.yundun.cn/login,说是专门防CC DDOS的,其实也就是一个CDN,有免费的套餐,足够我这小站用了。

现在就来谈谈我的具体换防护把,

首先安装CSF防火墙,这个比较简单而且不用改域名什么的,小规模的就直接解决了。
一、安装依赖包:

代码如下 复制代码
yum install perl-libwww-perl perl iptables

二、下载并安装 CSF:

代码如下 复制代码
wget http://www.qixoo.qixoo.com/free/csf.tgz
tar -xzf csf.tgz
cd csf
sh install.sh
三、测试 CSF 是否能正常工作:

代码如下 复制代码
[ csf]# perl http://qkxue.net/etc/csf/csftest.pl
Testing ip_tables/iptable_filter...OK
Testing ipt_LOG...OK
Testing ipt_multiport/xt_multiport...OK
Testing ipt_REJECT...OK
Testing ipt_state/xt_state...OK
Testing ipt_limit/xt_limit...OK
Testing ipt_recent...OK
Testing xt_connlimit...OK
Testing ipt_owner/xt_owner...OK
Testing iptable_nat/ipt_REDIRECT...OK
Testing iptable_nat/ipt_DNAT...OK
RESULT: csf should function on this server
四、csf的配置:
CSF的配置文件是

代码如下 复制代码
vim /etc/csf/csf.conf
# Allow incoming TCP ports
# 推荐您更改 SSH 的默认端口(22)为其他端口,但请注意一定要把新的端口加到下一行中
TCP_IN = “20,21,47,81,1723,25,53,80,110,143,443,465,587,993,995〃
# Allow outgoing TCP ports同上,把 SSH 的登录端口加到下一行。
# 在某些程序要求打开一定范围的端口的情况下,例如Pureftpd的passive mode,可使用类似 30000:35000 的方式打开30000-35000范围的端口。
TCP_OUT = “20,21,47,81,1723,25,53,80,110,113,443〃
# Allow incoming UDP ports
UDP_IN = “20,21,53〃
# Allow outgoing UDP ports
# To allow outgoing traceroute add 33434:33523 to this list
UDP_OUT = “20,21,53,113,123〃
# Allow incoming PING 是否允许别人ping你的服务器,默认为1,允许。0为不允许。
ICMP_IN = “1〃
以上这些配置大家一看就懂了,下面再介绍几个比较常用的:
免疫某些类型的小规模 DDos 攻击:
# Connection Tracking. This option enables tracking of all connections from IP
# addresses to the server. If the total number of connections is greater than
# this value then the offending IP address is blocked. This can be used to help
# prevent some types of DOS attack.
#
# Care should be taken with this option. It’s entirely possible that you will
# see false-positives. Some protocols can be connection hungry, e.g. FTP, IMAPD
# and HTTP so it could be quite easy to trigger, especially with a lot of
# closed connections in TIME_WAIT. However, for a server that is prone to DOS
# attacks this may be very useful. A reasonable setting for this option might
# be arround 200.
#
# To disable this feature, set this to 0
CT_LIMIT = "200"##固定时间内同一个IP请求的此数
# Connection Tracking interval. Set this to the the number of seconds between
# connection tracking scans
CT_INTERVAL = "30" ##指上面的固定时间,单位为秒
# Send an email alert if an IP address is blocked due to connection tracking
CT_EMAIL_ALERT = "1" ##是否发送
# If you want to make IP blocks permanent then set this to 1, otherwise blocks
# will be temporary and will be cleared after CT_BLOCK_TIME seconds
# 是否对可疑IP采取永久屏蔽,默认为0,即临时性屏蔽。
CT_PERMANENT = "0"
# If you opt for temporary IP blocks for CT, then the following is the interval
# in seconds that the IP will remained blocked for (e.g. 1800 = 30 mins)
# 临时性屏蔽时间
CT_BLOCK_TIME = "1800"
# If you don’t want to count the TIME_WAIT state against the connection count
# then set the following to “1〃
CT_SKIP_TIME_WAIT = "0" ##是否统计TIME_WAIT链接状态
# If you only want to count specific states (e.g. SYN_RECV) then add the states
# to the following as a comma separated list. E.g. “SYN_RECV,TIME_WAIT”
# Leave this option empty to count all states against CT_LIMIT
CT_STATES = "" ##是否分国家来统计,填写的是国家名
# If you only want to count specific ports (e.g. 80,443) then add the ports
# to the following as a comma separated list. E.g. “80,443〃
#
# Leave this option empty to count all ports against CT_LIMIT
# 对什么端口进行检测,为空则检测所有,防止ssh的话可以为空,统计所有的。
CT_PORTS = ""
做了以上设置之后,可以先测试一下。如果没有问题的话,就更改为正式模式,刚才只是测试模式。
# 把默认的1修改为0。
TESTING = "0"
在/etc/csf/下有csf.allow和csf.deny两个文件,
allow是信任的IP,可以把自己的IP写到这里面防止误封。
deny就是被封的IP。
如果有调整需要重启一下cfs服务

按照上面的方法安装设置CSF基本上小CC攻击就解决了,我的站刚加好也解决了,可以第二天攻击加大了,没办法只有用第二种办法了
注册了云盾帐号,认证域名,更改域名指向到云盾的域名,我加完之后再也没有收到攻击

linux中防CC攻击两种实现方法(转)的更多相关文章

  1. linux安装mysql服务分两种安装方法:

    linux安装mysql服务分两种安装方法: ①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: ②使用官方编译好的二进制文件安装,优点是安装速度 ...

  2. Linux系统防CC攻击自动拉黑IP增强版Shell脚本 《Linux系统防CC攻击自动拉黑IP增强版Shell脚本》来自张戈博客

    前天没事写了一个防CC攻击的Shell脚本,没想到这么快就要用上了,原因是因为360网站卫士的缓存黑名单突然无法过滤后台,导致WordPress无法登录!虽然,可以通过修改本地hosts文件来解决这个 ...

  3. Linux系统中存储设备的两种表示方法

    转:https://blog.csdn.net/holybin/article/details/38637381 一.对于IDE接口的硬盘的两种表示方法: 1.IDE接口硬盘,对于整块硬盘的两种表示方 ...

  4. TQ2440学习笔记——Linux上I2C驱动的两种实现方法(1)

    作者:彭东林 邮箱:pengdonglin137@163.com 内核版本:Linux-3.14 u-boot版本:U-Boot 2015.04 硬件:TQ2440 (NorFlash:2M   Na ...

  5. shell中逻辑与的两种表示方法

    bash中表示逻辑与的两种方法: (1)[ $state == "running" -a $name == "zone1" ] (2)[[ $state == ...

  6. Linux/CentOS防CC攻击脚本

    #!/bin/sh cd /var/log/httpd/ cat access_log|awk > a cp /dev/null access_log cp /dev/null error_lo ...

  7. Web.config中appSettings节点值两种读取方法

        <appSettings>    <add key="ClientPort" value="5252"/>   <add ...

  8. linux内核分析作业4:使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用

    系统调用:库函数封装了系统调用,通过库函数和系统调用打交道 用户态:低级别执行状态,代码的掌控范围会受到限制. 内核态:高执行级别,代码可移植性特权指令,访问任意物理地址 为什么划分级别:如果全部特权 ...

  9. LInux内核分析--使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用

    实验者:江军 ID:fuchen1994 实验描述: 选择一个系统调用(13号系统调用time除外),系统调用列表参见http://codelab.shiyanlou.com/xref/linux-3 ...

随机推荐

  1. JAVA集合介绍

    一.集合概述 Java是一种面向对象语言,如果我们要针对多个对象进行操作,就必须对多个对象进行存储.而数组长度固定,不能满足变化的要求.所以,java提供了集合. 特点 1.        长度可以发 ...

  2. Code First操作Mysql数据库

    前面博客也讲了,自己做一个网站,选用的是MVC+EF Code First+MySql+EasyUI,先说下技术选型.一.为什么选择MVC? 因为之前自己做的系统大部分是webForm,MVC的之前也 ...

  3. 安卓srcCompat弄死我了

    <ImageView android:layout_width="150dp" android:layout_height="120dp" app:src ...

  4. EF在单例模式及C&sol;S方式开发时,操作数据对象以后如果发生异常,要做善后工作。

    try{ 删除或修改 }catch { _DBContext.Refresh(RefreshMode.StoreWins, entity); }

  5. Git基础教程(二)

    继续上篇Git基础教程(一),在开篇之前,先回顾一下上篇中的基本命令. 配置命令:git config --global * 版本库初始化:git init 向版本库添加文件:git add * 提交 ...

  6. LeetCode之&OpenCurlyDoubleQuote;动态规划”:Distinct Subsequences

    题目链接 题目要求: Given a string S and a string T, count the number of distinct subsequences of T in S. A s ...

  7. 一个tomcat下部署不同端口多个应用

    通过配置tmcat的server.xml来实现多端口多应用: <?xml version='1.0' encoding='utf-8'?> <Server port="80 ...

  8. importlib

    Python提供了importlib包作为标准库的一部分.目的就是提供Python中import语句的实现(以及__import__函数).另外,importlib允许程序员创建他们自定义的对象,可用 ...

  9. jupyter notebook设置主题背景&comma;字体和扩展插件

    windows上安装Anaconda (IPython notebook) Anaconda是一个包与环境的管理器,一个Python发行版,以及一个超过1000多个开源包的集合.它是免费和易于安装的, ...

  10. &lbrack;转&rsqb;&lowbar;&lowbar;cdecl与&lowbar;&lowbar;stdcall

    来自Programming Windows 5th Edition The WinMain function is given a type of WINAPI (as is every Window ...