Improved web responsiveness

By only forcing a channel change when required by the attack
This commit is contained in:
Spacehuhn 2021-01-13 11:57:42 +01:00
parent d4ba63789b
commit 2f43126301
13 changed files with 62 additions and 36 deletions

View File

@ -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;

View File

@ -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

View File

@ -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 {

View File

@ -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);
}

View File

@ -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);

View File

@ -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) {

View File

@ -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);
}

View File

@ -44,9 +44,10 @@
<span data-translate="info_disclaimer">In case of an unexpected error, please reload the site and
look at the serial monitor for further debugging.</span><br>
</p>
<button onclick="load()" class="right" data-translate="reload">reload</button>
<p class="right">
<button onclick="stopAll()" data-translate="stop">stop</button>
<button onclick="load()" data-translate="reload">reload</button>
</p>
<table>
<tr>
<th data-translate="attacks">Attacks</th>

View File

@ -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();
});
}

View File

@ -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();
});
});

View File

@ -5,6 +5,7 @@ var settingsJson = {};
function load() {
getFile("settings.json", function (res) {
settingsJson = JSON.parse(res);
showMessage("connected");
draw();
});
}

View File

@ -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) {

View File

@ -6,6 +6,7 @@ function load() {
getFile("run?cmd=save ssids", function () {
getFile("ssids.json", function (res) {
ssidJson = JSON.parse(res);
showMessage("connected");
draw();
});
});