From 2f4312630174aff291e9bff1de51ac2c281f3ff8 Mon Sep 17 00:00:00 2001
From: Spacehuhn
Date: Wed, 13 Jan 2021 11:57:42 +0100
Subject: [PATCH] Improved web responsiveness
By only forcing a channel change when required by the attack
---
esp8266_deauther/Attack.cpp | 25 ++++++++++++++-----------
esp8266_deauther/Attack.h | 22 +++++++++++-----------
esp8266_deauther/CLI.cpp | 2 +-
esp8266_deauther/Scan.cpp | 4 ++--
esp8266_deauther/Scan.h | 2 +-
esp8266_deauther/esp8266_deauther.ino | 2 +-
esp8266_deauther/functions.h | 4 ++--
web_interface/attack.html | 7 ++++---
web_interface/js/attack.js | 9 +++++++++
web_interface/js/scan.js | 5 ++++-
web_interface/js/settings.js | 1 +
web_interface/js/site.js | 14 +++++++++++---
web_interface/js/ssids.js | 1 +
13 files changed, 62 insertions(+), 36 deletions(-)
diff --git a/esp8266_deauther/Attack.cpp b/esp8266_deauther/Attack.cpp
index aa94777..da05828 100644
--- a/esp8266_deauther/Attack.cpp
+++ b/esp8266_deauther/Attack.cpp
@@ -69,6 +69,9 @@ void Attack::stop() {
deauth.tc = 0;
beacon.tc = 0;
probe.tc = 0;
+ deauth.active = false;
+ beacon.active = false;
+ probe.active = false;
prntln(A_STOP);
}
}
@@ -244,7 +247,7 @@ void Attack::deauthAllUpdate() {
void Attack::probeUpdate() {
if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) {
if (probe.time <= currentTime - (1000 / probe.maxPkts)) {
- if (settings::getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11);
+ if (settings::getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11, true);
probe.tc += sendProbe(probe.tc);
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_
// send deauth frame
deauthpkt[0] = 0xc0;
- if (sendPacket(deauthpkt, packetSize, ch, 1)) {
+ if (sendPacket(deauthpkt, packetSize, ch, 1, true)) {
success = true;
deauth.packetCounter++;
}
@@ -312,7 +315,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
disassocpkt[0] = 0xa0;
- if (sendPacket(disassocpkt, packetSize, ch, 1)) {
+ if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
success = true;
deauth.packetCounter++;
}
@@ -327,7 +330,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send deauth frame
disassocpkt[0] = 0xc0;
- if (sendPacket(disassocpkt, packetSize, ch, 1)) {
+ if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
success = true;
deauth.packetCounter++;
}
@@ -335,7 +338,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send disassociate frame
disassocpkt[0] = 0xa0;
- if (sendPacket(disassocpkt, packetSize, ch, 1)) {
+ if (sendPacket(disassocpkt, packetSize, ch, 1, false)) {
success = true;
deauth.packetCounter++;
}
@@ -347,7 +350,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
}
bool Attack::sendBeacon(uint8_t tc) {
- if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11);
+ if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11, true);
mac[5] = tc;
return sendBeacon(mac, ssids.getName(tc).c_str(), wifi_channel, ssids.getWPA2(tc));
}
@@ -380,7 +383,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
tmpPacket[37] = ssidLen; // update SSID length byte
memcpy(&tmpPacket[38 + ssidLen], &beaconPacket[70], wpa2 ? 39 : 13); // copy second half of packet into buffer
- bool success = sendPacket(tmpPacket, tmpPacketSize, ch, 1);
+ bool success = sendPacket(tmpPacket, tmpPacketSize, ch, 1, false);
if (success) {
beacon.time = currentTime;
@@ -394,7 +397,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
}
bool Attack::sendProbe(uint8_t tc) {
- if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11);
+ if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11, true);
mac[5] = tc;
return sendProbe(mac, ssids.getName(tc).c_str(), wifi_channel);
}
@@ -408,7 +411,7 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
memcpy(&probePacket[10], mac, 6);
memcpy(&probePacket[26], ssid, ssidLen);
- if (sendPacket(probePacket, packetSize, ch, 1)) {
+ if (sendPacket(probePacket, packetSize, ch, 1, false)) {
probe.time = currentTime;
probe.packetCounter++;
return true;
@@ -417,11 +420,11 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
return false;
}
-bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) {
+bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries, bool force_ch) {
// Serial.println(bytesToStr(packet, packetSize));
// set channel
- setWifiChannel(ch);
+ setWifiChannel(ch, force_ch);
// sent out packet
bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
diff --git a/esp8266_deauther/Attack.h b/esp8266_deauther/Attack.h
index bb35c63..7e42f35 100644
--- a/esp8266_deauther/Attack.h
+++ b/esp8266_deauther/Attack.h
@@ -27,7 +27,7 @@ extern void getRandomMac(uint8_t* mac);
extern void setOutputPower(float dBm);
extern String macToStr(const uint8_t* mac);
extern String bytesToStr(const uint8_t* b, uint32_t size);
-extern void setWifiChannel(uint8_t ch);
+extern void setWifiChannel(uint8_t ch, bool force);
extern bool writeFile(String path, String& buf);
extern int8_t free80211_send(uint8_t* buffer, uint16_t len);
@@ -56,7 +56,7 @@ class Attack {
bool sendProbe(uint8_t tc);
bool sendProbe(uint8_t* mac, const char* ssid, uint8_t ch);
- bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries);
+ bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries, bool force_ch);
bool isRunning();
@@ -152,16 +152,16 @@ class Attack {
};
uint8_t beaconPacket[109] = {
- /* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame
- /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast
- /* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
- /* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
+ /* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame
+ /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast
+ /* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
+ /* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
// Fixed parameters
- /* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK)
- /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
- /* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s
- /* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
+ /* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK)
+ /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
+ /* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s
+ /* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
// Tagged parameters
@@ -196,7 +196,7 @@ class Attack {
/* 85 - 86 */ 0x01, 0x00,
/* 87 - 90 */ 0x00, 0x0f, 0xac, 0x02,
/* 91 - 92 */ 0x02, 0x00,
- /* 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*/
+ /* 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*/
/* 101 - 102 */ 0x01, 0x00,
/* 103 - 106 */ 0x00, 0x0f, 0xac, 0x02,
/* 107 - 108 */ 0x00, 0x00
diff --git a/esp8266_deauther/CLI.cpp b/esp8266_deauther/CLI.cpp
index 2139d60..5401e36 100644
--- a/esp8266_deauther/CLI.cpp
+++ b/esp8266_deauther/CLI.cpp
@@ -1079,7 +1079,7 @@ void CLI::runCommand(String input) {
for (int i = 0; i < packetSize; i++) packet[i] = strtoul((packetStr.substring(i * 2,
i * 2 + 2)).c_str(), NULL, 16);
- if (attack.sendPacket(packet, packetSize, wifi_channel, 10)) {
+ if (attack.sendPacket(packet, packetSize, wifi_channel, 10, true)) {
prntln(CLI_CUSTOM_SENT);
counter++;
} else {
diff --git a/esp8266_deauther/Scan.cpp b/esp8266_deauther/Scan.cpp
index a334ce3..2e5c5e2 100644
--- a/esp8266_deauther/Scan.cpp
+++ b/esp8266_deauther/Scan.cpp
@@ -61,7 +61,7 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
uint8_t channel) {
if (mode != SCAN_MODE_OFF) stop();
- setWifiChannel(channel);
+ setWifiChannel(channel, true);
Scan::continueStartTime = currentTime;
Scan::snifferPacketTime = continueStartTime;
Scan::snifferOutputTime = continueStartTime;
@@ -239,7 +239,7 @@ void Scan::setChannel(uint8_t ch) {
else if (ch < 1) ch = 14;
wifi_promiscuous_enable(0);
- setWifiChannel(ch);
+ setWifiChannel(ch, true);
wifi_promiscuous_enable(1);
}
diff --git a/esp8266_deauther/Scan.h b/esp8266_deauther/Scan.h
index 6baedf5..8c39d2f 100644
--- a/esp8266_deauther/Scan.h
+++ b/esp8266_deauther/Scan.h
@@ -26,7 +26,7 @@ extern SSIDs ssids;
extern uint8_t wifiMode;
-extern void setWifiChannel(uint8_t ch);
+extern void setWifiChannel(uint8_t ch, bool force);
extern bool appendFile(String path, String& buf);
extern bool writeFile(String path, String& buf);
extern void readFileToSerial(const String path);
diff --git a/esp8266_deauther/esp8266_deauther.ino b/esp8266_deauther/esp8266_deauther.ino
index 19a7b85..a47d925 100644
--- a/esp8266_deauther/esp8266_deauther.ino
+++ b/esp8266_deauther/esp8266_deauther.ino
@@ -129,7 +129,7 @@ void setup() {
scan.setup();
// set channel
- setWifiChannel(settings::getWifiSettings().channel);
+ setWifiChannel(settings::getWifiSettings().channel, true);
// dis/enable serial command interface
if (settings::getCLISettings().enabled) {
diff --git a/esp8266_deauther/functions.h b/esp8266_deauther/functions.h
index bdbcc27..e9c5a26 100644
--- a/esp8266_deauther/functions.h
+++ b/esp8266_deauther/functions.h
@@ -311,8 +311,8 @@ void prntln(const uint32_t i) {
}
/* ===== WiFi ===== */
-void setWifiChannel(uint8_t ch) {
- if (/*(ch != wifi_channel) && (ch > 0) &&*/ (ch < 15)) {
+void setWifiChannel(uint8_t ch, bool force) {
+ if (((ch != wifi_channel) || force) && (ch < 15)) {
wifi_channel = ch;
wifi_set_channel(wifi_channel);
}
diff --git a/web_interface/attack.html b/web_interface/attack.html
index a0bc570..f10a69e 100644
--- a/web_interface/attack.html
+++ b/web_interface/attack.html
@@ -44,9 +44,10 @@
In case of an unexpected error, please reload the site and
look at the serial monitor for further debugging.
-
-
-
+
+
+
+
| Attacks |
diff --git a/web_interface/js/attack.js b/web_interface/js/attack.js
index 66bc76e..cfee521 100644
--- a/web_interface/js/attack.js
+++ b/web_interface/js/attack.js
@@ -18,6 +18,12 @@ function draw() {
getE("allpkts").innerHTML = esc(attackJSON[3] + "");
}
+function stopAll() {
+ getFile("run?cmd=stop attack", function () {
+ load();
+ });
+}
+
function start(mode) {
switch (mode) {
case 0:
@@ -31,6 +37,7 @@ function start(mode) {
break;
}
getFile("run?cmd=attack" + (attackJSON[0][0] ? " -d" : "") + (attackJSON[1][0] ? " -b" : "") + (attackJSON[2][0] ? " -p" : ""), function () {
+ setTimeout(load, 2000);
draw();
});
}
@@ -38,6 +45,8 @@ function start(mode) {
function load() {
getFile("attack.json", function (response) {
attackJSON = JSON.parse(response);
+ console.log(response);
+ showMessage("connected");
draw();
});
}
\ No newline at end of file
diff --git a/web_interface/js/scan.js b/web_interface/js/scan.js
index e3379b4..d1c7d5c 100644
--- a/web_interface/js/scan.js
+++ b/web_interface/js/scan.js
@@ -150,7 +150,8 @@ function scan(type) {
+ " -ch " + getE("ch").options[getE("ch").selectedIndex].value;
getFile("run?cmd=" + cmdStr);
duts = parseInt(type);
- setTimeout(buttonFunc, elxtime)
+ setTimeout(buttonFunc, elxtime);
+ setTimeout(load, elxtime);
}
function buttonFunc() {
@@ -171,6 +172,7 @@ function load() {
getFile("run?cmd=save scan", function () {
getFile("scan.json", function (res) {
scanJson = JSON.parse(res);
+ showMessage("connected");
drawScan();
});
});
@@ -178,6 +180,7 @@ function load() {
getFile("run?cmd=save names", function () {
getFile("names.json", function (res) {
nameJson = JSON.parse(res);
+ showMessage("connected");
drawNames();
});
});
diff --git a/web_interface/js/settings.js b/web_interface/js/settings.js
index bd7b1cd..ec8abd0 100644
--- a/web_interface/js/settings.js
+++ b/web_interface/js/settings.js
@@ -5,6 +5,7 @@ var settingsJson = {};
function load() {
getFile("settings.json", function (res) {
settingsJson = JSON.parse(res);
+ showMessage("connected");
draw();
});
}
diff --git a/web_interface/js/site.js b/web_interface/js/site.js
index 4d2d398..8a022ba 100644
--- a/web_interface/js/site.js
+++ b/web_interface/js/site.js
@@ -29,9 +29,17 @@ function convertLineBreaks(str) {
}
function showMessage(msg, closeAfter) {
- getE("status").style.backgroundColor = "#d33";
- console.error("disconnected (" + msg + ")");
- getE("status").innerHTML = "disconnected";
+ if (msg.startsWith("ERROR")) {
+ getE("status").style.backgroundColor = "#d33";
+ getE("status").innerHTML = "disconnected";
+
+ console.error("disconnected (" + msg + ")");
+ } else {
+ getE("status").style.backgroundColor = "#3c5";
+ getE("status").innerHTML = "connected";
+
+ console.log("" + msg + "");
+ }
}
function getFile(adr, callback, timeout, method, onTimeout, onError) {
diff --git a/web_interface/js/ssids.js b/web_interface/js/ssids.js
index 3275bdf..a08704f 100644
--- a/web_interface/js/ssids.js
+++ b/web_interface/js/ssids.js
@@ -6,6 +6,7 @@ function load() {
getFile("run?cmd=save ssids", function () {
getFile("ssids.json", function (res) {
ssidJson = JSON.parse(res);
+ showMessage("connected");
draw();
});
});