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

Commit bf5e23d

Browse files
committed
Added config, clean code, and optimized imports.
1 parent 36b9292 commit bf5e23d

File tree

7 files changed

+51
-38
lines changed

7 files changed

+51
-38
lines changed

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.Getter;
88
import lombok.RequiredArgsConstructor;
99
import lombok.SneakyThrows;
10+
import lombok.val;
1011
import org.jetbrains.annotations.NotNull;
1112

1213
import java.net.InetAddress;
@@ -44,6 +45,7 @@ private IAttackMethod getMethod(final String method, final Integer byteSize, Att
4445
*/
4546
@SneakyThrows
4647
public void run() {
48+
// Create local variables for our configuration/run args
4749
boolean debug = false;
4850
String ip = null;
4951
Integer port;
@@ -53,19 +55,24 @@ public void run() {
5355
Integer duration;
5456
String method = null;
5557
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));
58+
// Check if user is using config
6459
if (this.parser.get("--config", String.class, null) != null){
60+
// to solve the error, there is no purpose
6561
duration = null;
6662
port = null;
63+
// Add values to FileManager
64+
FileManager.values.add(new Value<>("ip", "0.0.0.0"));
65+
FileManager.values.add(new Value<>("port", 1024));
66+
FileManager.values.add(new Value<>("ppsLimit", 1000));
67+
FileManager.values.add(new Value<>("maxThreads", 5));
68+
FileManager.values.add(new Value<>("byteSize", 1024));
69+
FileManager.values.add(new Value<>("method", "TCPFLOOD"));
70+
FileManager.values.add(new Value<>("verbose", false));
71+
FileManager.values.add(new Value<>("duration", -1));
72+
// Init the FileManager
6773
FileManager.init();
68-
for(Value val : FileManager.values){
74+
// Switch between configuration items and set the values
75+
for(val val : FileManager.values){
6976
switch(val.getName()){
7077
case "ip":{
7178
ip = (String) val.getValue();
@@ -102,9 +109,9 @@ public void run() {
102109

103110
}
104111
}
105-
112+
// See If user isn't using configuration and using run args instead
106113
} else {
107-
//Clears the entire FileManager values because we don't need them.
114+
// Clears the entire FileManager values because we don't need them
108115
FileManager.values.clear();
109116
// Parse command line arguments
110117
debug = this.parser.get("--debug", Boolean.class, false);
@@ -118,16 +125,17 @@ public void run() {
118125
verbose = this.parser.get("--verbose", Boolean.class, false);
119126

120127
}
128+
// Check if values are null
121129
if (ip == null) {
122130
System.out.println("JSSAttack by XenonCommunity");
123131
System.out.println("Usage: java -jar JSSAttack.jar --ip <ip> --port <port> --threads <threads> --byteSize <byteSize> --duration <duration> --method <method> [--verbose] [--debug]");
124132
System.exit(0);
125133
}
126134

127135
// Set logging level based on verbosity and debug mode
128-
if (verbose) {
136+
if (verbose != null && verbose) {
129137
Logger.setCurrentLevel(Logger.LEVEL.VERBOSE);
130-
} else if (debug) {
138+
} else if (debug){
131139
Logger.setCurrentLevel(Logger.LEVEL.DEBUG);
132140
}
133141

@@ -139,12 +147,13 @@ public void run() {
139147
Logger.log(Logger.LEVEL.DEBUG, "ByteSize is: " + byteSize);
140148
Logger.log(Logger.LEVEL.DEBUG, "Duration is: " + duration);
141149
Logger.log(Logger.LEVEL.DEBUG, "Method is: " + method);
142-
150+
assert maxThreads != null;
143151
// Initialize task manager
144152
TaskManager taskManager = new TaskManager(maxThreads + 1);
145153

146154
// Initialize attack parameters
147155
final AttackStatics attackStatics = new AttackStatics(ppsLimit);
156+
assert method != null;
148157
final IAttackMethod attackMethod = getMethod(method, byteSize, attackStatics);
149158
final InetAddress addr = InetAddress.getByName(ip);
150159
Integer finalDuration = duration;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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;
64

75
public class Main {
86
/**

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import lombok.val;
1010
import org.jetbrains.annotations.NotNull;
1111

12-
import java.io.OutputStream;
1312
import java.net.InetAddress;
1413
import java.net.Socket;
1514
import java.net.StandardSocketOptions;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import lombok.RequiredArgsConstructor;
99
import lombok.val;
1010

11-
import java.io.OutputStream;
1211
import java.net.InetAddress;
1312
import java.net.Socket;
1413
import java.net.StandardSocketOptions;
Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
package ir.xenoncommunity.jss.utils;
22

3+
import lombok.AllArgsConstructor;
34
import org.jetbrains.annotations.Nullable;
45

6+
@AllArgsConstructor
57
public class CommandLineParser {
68

79
private final String[] args;
8-
9-
public CommandLineParser(final String[] args) {
10-
this.args = args;
11-
}
12-
1310
public <T> T get(final String arg, final Class<T> type, final @Nullable T defaultValue) {
1411
for (int i = 0; i < args.length - 1; i++) {
1512
if (!args[i].equals(arg)) continue;
@@ -22,14 +19,15 @@ public <T> T get(final String arg, final Class<T> type, final @Nullable T defaul
2219

2320

2421
private <T> T convertToType(final String value, final Class<T> type) {
25-
if (type.equals(String.class)) {
26-
return type.cast(value);
27-
} else if (type.equals(Integer.class)) {
28-
return type.cast(Integer.parseInt(value));
29-
} else if (type.equals(Boolean.class)) {
30-
return type.cast(Boolean.parseBoolean(value));
31-
} else {
32-
throw new IllegalArgumentException("Unsupported type");
33-
}
22+
return type.equals(String.class) ?
23+
type.cast(value)
24+
:
25+
(type.equals(Integer.class)
26+
?
27+
type.cast(Integer.parseInt(value))
28+
:
29+
(type.equals(Boolean.class)
30+
? type.cast(Boolean.parseBoolean(value))
31+
: null));
3432
}
3533
}

src/main/java/ir/xenoncommunity/jss/utils/FileManager.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
package ir.xenoncommunity.jss.utils;
22

33
import ir.xenoncommunity.jss.utils.filemanager.Value;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.SneakyThrows;
47
import lombok.experimental.UtilityClass;
5-
import lombok.*;
8+
import lombok.val;
69

710
import java.io.*;
8-
import java.util.*;
11+
import java.util.ArrayList;
12+
import java.util.List;
913
@Getter
1014
@Setter
1115
@UtilityClass
1216
public class FileManager {
1317
public final File folder = new File("JSS");
1418
public final File config = new File(folder,"config.txt");
1519
public final List<Value> values = new ArrayList<>();
20+
private boolean isSuccess = true;
1621
public void init(){
1722
if(folder.exists() && config.exists()){
1823
readConf();
@@ -32,8 +37,8 @@ public void readConf(){
3237
}
3338
@SneakyThrows
3439
public void saveForFirstTime(){
35-
folder.mkdirs();
36-
config.createNewFile();
40+
isSuccess = folder.mkdirs();
41+
isSuccess = config.createNewFile();
3742
val bw = new BufferedWriter(new FileWriter(config));
3843
values.forEach(e -> {
3944
try {
@@ -42,5 +47,12 @@ public void saveForFirstTime(){
4247
} catch (Exception ignored) {}
4348
});
4449
bw.close();
50+
isFaild();
51+
}
52+
private void isFaild(){
53+
Logger.log(Logger.LEVEL.ERROR, "Please rerun the program.\n" +
54+
"this caused due to lack of permissions,\n" +
55+
"so the program wasn't able to create config files.");
56+
System.exit(0);
4557
}
4658
}

src/main/java/ir/xenoncommunity/jss/utils/filemanager/Value.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import lombok.Getter;
55
import lombok.Setter;
66

7-
import java.util.Objects;
8-
97
@Getter
108
@Setter
119
@AllArgsConstructor

0 commit comments

Comments
 (0)