Skip to content

Commit 2f43126

Browse files
author
Spacehuhn
committed
Improved web responsiveness
By only forcing a channel change when required by the attack
1 parent d4ba637 commit 2f43126

File tree

13 files changed

+62
-36
lines changed

13 files changed

+62
-36
lines changed

esp8266_deauther/Attack.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ void Attack::stop() {
6969
deauth.tc = 0;
7070
beacon.tc = 0;
7171
probe.tc = 0;
72+
deauth.active = false;
73+
beacon.active = false;
74+
probe.active = false;
7275
prntln(A_STOP);
7376
}
7477
}
@@ -244,7 +247,7 @@ void Attack::deauthAllUpdate() {
244247
void Attack::probeUpdate() {
245248
if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) {
246249
if (probe.time <= currentTime - (1000 / probe.maxPkts)) {
247-
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11);
250+
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11, true);
248251
probe.tc += sendProbe(probe.tc);
249252

250253
if (probe.tc >= ssids.count()) probe.tc = 0;
@@ -300,7 +303,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
300303
// send deauth frame
301304
deauthpkt[0] = 0xc0;
302305

303-
if (sendPacket(deauthpkt, packetSize, ch, 1)) {
306+
if (sendPacket(deauthpkt, packetSize, ch, 1, true)) {
304307
success = true;
305308
deauth.packetCounter++;
306309
}
@@ -312,7 +315,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
312315

313316
disassocpkt[0] = 0xa0;
314317

315-
if (sendPacket(disassocpkt, packetSize, ch, 1)) {
318+
if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
316319
success = true;
317320
deauth.packetCounter++;
318321
}
@@ -327,15 +330,15 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
327330
// send deauth frame
328331
disassocpkt[0] = 0xc0;
329332

330-
if (sendPacket(disassocpkt, packetSize, ch, 1)) {
333+
if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
331334
success = true;
332335
deauth.packetCounter++;
333336
}
334337

335338
// send disassociate frame
336339
disassocpkt[0] = 0xa0;
337340

338-
if (sendPacket(disassocpkt, packetSize, ch, 1)) {
341+
if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
339342
success = true;
340343
deauth.packetCounter++;
341344
}
@@ -347,7 +350,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
347350
}
348351

349352
bool Attack::sendBeacon(uint8_t tc) {
350-
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11);
353+
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11, true);
351354
mac[5] = tc;
352355
return sendBeacon(mac, ssids.getName(tc).c_str(), wifi_channel, ssids.getWPA2(tc));
353356
}
@@ -380,7 +383,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
380383
tmpPacket[37] = ssidLen; // update SSID length byte
381384
memcpy(&tmpPacket[38 + ssidLen], &beaconPacket[70], wpa2 ? 39 : 13); // copy second half of packet into buffer
382385

383-
bool success = sendPacket(tmpPacket, tmpPacketSize, ch, 1);
386+
bool success = sendPacket(tmpPacket, tmpPacketSize, ch, 1, false);
384387

385388
if (success) {
386389
beacon.time = currentTime;
@@ -394,7 +397,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
394397
}
395398

396399
bool Attack::sendProbe(uint8_t tc) {
397-
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11);
400+
if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11, true);
398401
mac[5] = tc;
399402
return sendProbe(mac, ssids.getName(tc).c_str(), wifi_channel);
400403
}
@@ -408,7 +411,7 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
408411
memcpy(&probePacket[10], mac, 6);
409412
memcpy(&probePacket[26], ssid, ssidLen);
410413

411-
if (sendPacket(probePacket, packetSize, ch, 1)) {
414+
if (sendPacket(probePacket, packetSize, ch, 1, false)) {
412415
probe.time = currentTime;
413416
probe.packetCounter++;
414417
return true;
@@ -417,11 +420,11 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
417420
return false;
418421
}
419422

420-
bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) {
423+
bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries, bool force_ch) {
421424
// Serial.println(bytesToStr(packet, packetSize));
422425

423426
// set channel
424-
setWifiChannel(ch);
427+
setWifiChannel(ch, force_ch);
425428

426429
// sent out packet
427430
bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;

esp8266_deauther/Attack.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ extern void getRandomMac(uint8_t* mac);
2727
extern void setOutputPower(float dBm);
2828
extern String macToStr(const uint8_t* mac);
2929
extern String bytesToStr(const uint8_t* b, uint32_t size);
30-
extern void setWifiChannel(uint8_t ch);
30+
extern void setWifiChannel(uint8_t ch, bool force);
3131
extern bool writeFile(String path, String& buf);
3232
extern int8_t free80211_send(uint8_t* buffer, uint16_t len);
3333

@@ -56,7 +56,7 @@ class Attack {
5656
bool sendProbe(uint8_t tc);
5757
bool sendProbe(uint8_t* mac, const char* ssid, uint8_t ch);
5858

59-
bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries);
59+
bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries, bool force_ch);
6060

6161
bool isRunning();
6262

@@ -152,16 +152,16 @@ class Attack {
152152
};
153153

154154
uint8_t beaconPacket[109] = {
155-
/* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame
156-
/* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast
157-
/* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
158-
/* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
155+
/* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame
156+
/* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast
157+
/* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
158+
/* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
159159

160160
// Fixed parameters
161-
/* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK)
162-
/* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
163-
/* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s
164-
/* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
161+
/* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK)
162+
/* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
163+
/* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s
164+
/* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
165165

166166
// Tagged parameters
167167

@@ -196,7 +196,7 @@ class Attack {
196196
/* 85 - 86 */ 0x01, 0x00,
197197
/* 87 - 90 */ 0x00, 0x0f, 0xac, 0x02,
198198
/* 91 - 92 */ 0x02, 0x00,
199-
/* 93 - 100 */ 0x00, 0x0f, 0xac, 0x04, 0x00, 0x0f, 0xac, 0x04, /*Fix: changed 0x02(TKIP) to 0x04(CCMP) is default. WPA2 with TKIP not supported by many devices*/
199+
/* 93 - 100 */ 0x00, 0x0f, 0xac, 0x04, 0x00, 0x0f, 0xac, 0x04, /*Fix: changed 0x02(TKIP) to 0x04(CCMP) is default. WPA2 with TKIP not supported by many devices*/
200200
/* 101 - 102 */ 0x01, 0x00,
201201
/* 103 - 106 */ 0x00, 0x0f, 0xac, 0x02,
202202
/* 107 - 108 */ 0x00, 0x00

esp8266_deauther/CLI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ void CLI::runCommand(String input) {
10791079
for (int i = 0; i < packetSize; i++) packet[i] = strtoul((packetStr.substring(i * 2,
10801080
i * 2 + 2)).c_str(), NULL, 16);
10811081

1082-
if (attack.sendPacket(packet, packetSize, wifi_channel, 10)) {
1082+
if (attack.sendPacket(packet, packetSize, wifi_channel, 10, true)) {
10831083
prntln(CLI_CUSTOM_SENT);
10841084
counter++;
10851085
} else {

esp8266_deauther/Scan.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
6161
uint8_t channel) {
6262
if (mode != SCAN_MODE_OFF) stop();
6363

64-
setWifiChannel(channel);
64+
setWifiChannel(channel, true);
6565
Scan::continueStartTime = currentTime;
6666
Scan::snifferPacketTime = continueStartTime;
6767
Scan::snifferOutputTime = continueStartTime;
@@ -239,7 +239,7 @@ void Scan::setChannel(uint8_t ch) {
239239
else if (ch < 1) ch = 14;
240240

241241
wifi_promiscuous_enable(0);
242-
setWifiChannel(ch);
242+
setWifiChannel(ch, true);
243243
wifi_promiscuous_enable(1);
244244
}
245245

esp8266_deauther/Scan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern SSIDs ssids;
2626

2727
extern uint8_t wifiMode;
2828

29-
extern void setWifiChannel(uint8_t ch);
29+
extern void setWifiChannel(uint8_t ch, bool force);
3030
extern bool appendFile(String path, String& buf);
3131
extern bool writeFile(String path, String& buf);
3232
extern void readFileToSerial(const String path);

esp8266_deauther/esp8266_deauther.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ void setup() {
129129
scan.setup();
130130

131131
// set channel
132-
setWifiChannel(settings::getWifiSettings().channel);
132+
setWifiChannel(settings::getWifiSettings().channel, true);
133133

134134
// dis/enable serial command interface
135135
if (settings::getCLISettings().enabled) {

esp8266_deauther/functions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ void prntln(const uint32_t i) {
311311
}
312312

313313
/* ===== WiFi ===== */
314-
void setWifiChannel(uint8_t ch) {
315-
if (/*(ch != wifi_channel) && (ch > 0) &&*/ (ch < 15)) {
314+
void setWifiChannel(uint8_t ch, bool force) {
315+
if (((ch != wifi_channel) || force) && (ch < 15)) {
316316
wifi_channel = ch;
317317
wifi_set_channel(wifi_channel);
318318
}

web_interface/attack.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ <h1 class="header" data-translate="attacks">Attacks</h1>
4444
<span data-translate="info_disclaimer">In case of an unexpected error, please reload the site and
4545
look at the serial monitor for further debugging.</span><br>
4646
</p>
47-
48-
<button onclick="load()" class="right" data-translate="reload">reload</button>
49-
47+
<p class="right">
48+
<button onclick="stopAll()" data-translate="stop">stop</button>
49+
<button onclick="load()" data-translate="reload">reload</button>
50+
</p>
5051
<table>
5152
<tr>
5253
<th data-translate="attacks">Attacks</th>

web_interface/js/attack.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ function draw() {
1818
getE("allpkts").innerHTML = esc(attackJSON[3] + "");
1919
}
2020

21+
function stopAll() {
22+
getFile("run?cmd=stop attack", function () {
23+
load();
24+
});
25+
}
26+
2127
function start(mode) {
2228
switch (mode) {
2329
case 0:
@@ -31,13 +37,16 @@ function start(mode) {
3137
break;
3238
}
3339
getFile("run?cmd=attack" + (attackJSON[0][0] ? " -d" : "") + (attackJSON[1][0] ? " -b" : "") + (attackJSON[2][0] ? " -p" : ""), function () {
40+
setTimeout(load, 2000);
3441
draw();
3542
});
3643
}
3744

3845
function load() {
3946
getFile("attack.json", function (response) {
4047
attackJSON = JSON.parse(response);
48+
console.log(response);
49+
showMessage("connected");
4150
draw();
4251
});
4352
}

web_interface/js/scan.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ function scan(type) {
150150
+ " -ch " + getE("ch").options[getE("ch").selectedIndex].value;
151151
getFile("run?cmd=" + cmdStr);
152152
duts = parseInt(type);
153-
setTimeout(buttonFunc, elxtime)
153+
setTimeout(buttonFunc, elxtime);
154+
setTimeout(load, elxtime);
154155
}
155156

156157
function buttonFunc() {
@@ -171,13 +172,15 @@ function load() {
171172
getFile("run?cmd=save scan", function () {
172173
getFile("scan.json", function (res) {
173174
scanJson = JSON.parse(res);
175+
showMessage("connected");
174176
drawScan();
175177
});
176178
});
177179
// Names
178180
getFile("run?cmd=save names", function () {
179181
getFile("names.json", function (res) {
180182
nameJson = JSON.parse(res);
183+
showMessage("connected");
181184
drawNames();
182185
});
183186
});

0 commit comments

Comments
 (0)