From c6037127cb90c3dcb523efa07ae881adbb33cf31 Mon Sep 17 00:00:00 2001 From: tobozo Date: Thu, 23 Feb 2017 21:43:43 +0100 Subject: [PATCH] merged serial peering logic --- esp8266_deauther/APScan.cpp | 35 ++++- esp8266_deauther/APScan.h | 9 +- esp8266_deauther/ClientScan.cpp | 3 +- esp8266_deauther/ClientScan.h | 3 +- esp8266_deauther/MacList.h | 2 +- esp8266_deauther/SerialServer.h | 187 ++++++++++++++++++++++++++ esp8266_deauther/esp8266_deauther.ino | 154 +++++++++++++-------- 7 files changed, 326 insertions(+), 67 deletions(-) create mode 100644 esp8266_deauther/SerialServer.h diff --git a/esp8266_deauther/APScan.cpp b/esp8266_deauther/APScan.cpp index 35f0a09..0603367 100644 --- a/esp8266_deauther/APScan.cpp +++ b/esp8266_deauther/APScan.cpp @@ -41,7 +41,13 @@ String APScan::getEncryption(int code){ break; } } - +bool APScan::setAsyncIndex() { + asyncIndex = results-1; + if(asyncIndex > maxResults) { + asyncIndex = maxResults-1; + } + return true; +} String APScan::getAPName(int num){ return names[num]; } String APScan::getAPEncryption(int num){ return encryption[num]; } String APScan::getAPVendor(int num){ return vendors[num]; } @@ -56,7 +62,21 @@ int APScan::getAPChannel(int num){ return channels[num]; } Mac APScan::getTarget(){ return aps._get(selected); } - +String APScan::getResult(int i){ + String json = "{ \"aps\":[ "; + json += "{"; + json += "\"id\": "+(String)i+","; + json += "\"channel\": "+(String)getAPChannel(i)+","; + json += "\"mac\": \""+getAPMac(i)+"\","; + json += "\"ssid\": \""+getAPName(i)+"\","; + json += "\"rssi\": "+(String)getAPRSSI(i)+","; + json += "\"encryption\": \""+getAPEncryption(i)+"\","; + json += "\"vendor\": \""+getAPVendor(i)+"\","; + json += "\"selected\": "+getAPSelected(i); + json += "}"; + json += "] }"; + return json; +} String APScan::getResults(){ String json = "{ \"aps\":[ "; for(int i=0;i -1 && !clientScan.sniffing) { + SerialPrintJSON("CLIENT SCAN START"); + clientScan.start(10); + attack.stop(0); + } else { + SerialPrintJSON("CLIENT SCAN SKIPPED"); + } + + } else if(msg=="apscan") { // startAPScan + + if(apScan.start()) { + attack.stopAll(); + apScan.setAsyncIndex(); + incomingSerialData = "aplist"; + return; + } + + } else if(msg=="aplist") { // + if(apScan.results==0) { + incomingSerialData = "apscan"; + return; + } + + if(apScan.asyncIndex>=0) { + Serial.println(apScan.getResult(apScan.asyncIndex)); + apScan.asyncIndex--; + + if(apScan.asyncIndex<0) { + // scan done, reset async index + apScan.setAsyncIndex(); + + } else { + // continue with async printing + return; + } + } else { + // list done, reset async index + apScan.setAsyncIndex(); + } + + } else if(msg=="cjson") { // sendClientResults + Serial.println(clientScan.getResults()); + + } else if(msg=="attackinfo") { // sendAttackInfo + Serial.println( attack.getResults() ); + + } else if(msg.startsWith("cselect ")) { // selectClient(x) + msgNumStr = msg.substring(8); + msgNum = msgNumStr.toInt(); + if(msgNum>-1) { + SerialPrintJSON("SELECTED Client #" + msgNumStr); + clientScan.select(msgNum); + attack.stop(0); + } else { + SerialPrintJSON("INVALID Client #" + msgNumStr); + } + Serial.println( clientScan.getResults() ); + + } else if(msg.startsWith("apjson ")) { // sendAPResults(xx) + msgNumStr = msg.substring(7); + msgNum = msgNumStr.toInt(); + if(msgNum>-1) { + Serial.println( apScan.getResult(msgNum) ); + } else { + SerialPrintJSON("ERROR INVALID AP "); + } + + } else if(msg=="reset") { + ESP.reset(); + + } else if(msg=="clear") { + nameList.clear(); + + } else if(msg.startsWith("apget ")) { // getResultByAPName('blah') + msgNumStr = msg.substring(6); + if(msgNumStr!="") { + int apNum = apScan.getResultByAPName(msgNumStr); + if(apNum>-1) { + Serial.println(apScan.getResult(apNum)); + } else { + SerialPrintJSON("ERROR,AP Not Found:" + msgNumStr); + } + } else { + SerialPrintJSON("ERROR INVALID AP "); + } + + } else if(msg.startsWith("apselect ")) { // selectAP(x) + msgNumStr = msg.substring(9); + msgNum = msgNumStr.toInt(); + if(msgNum>-1) { + if(apScan.select(msgNum)>-1) { + SerialPrintJSON("SELECTED AP #" + String(msgNum) + "/" + msgNumStr); + } else { + SerialPrintJSON("UNSELECTED AP #" + String(msgNum) + "/" + msgNumStr); + } + attack.stopAll(); + } else { + SerialPrintJSON("ERROR INVALID AP "); + } + + } else if(msg.startsWith("cset ")) { // setClientName(x) + msgNumStr = msg.substring(5); + //msgNum = msgNumStr.toInt(); + if(msgNumStr!="") { + SerialPrintJSON("Adding " + msgNumStr + " to namelist"); + nameList.add(clientScan.getClientMac(clientScan.lastSelected), msgNumStr); + } else { + SerialPrintJSON("ERROR INVALID Client"); + } + + } else if(msg.startsWith("attack ")) { // attack(x) + msgNumStr = msg.substring(7); + msgNum = msgNumStr.toInt(); + if(msgNum>-1) { + if(apScan.selected > -1 || msgNum == 3){ + attack.start(msgNum); + SerialPrintJSON("ATTACK Client #" + msgNumStr); + } else { + SerialPrintJSON("ERROR no AP selected"); + } + } else { + SerialPrintJSON("ERROR INVALID Client"); + } + + } + + incomingSerialData = ""; + incomingSerialDataReady = false; + + +} diff --git a/esp8266_deauther/esp8266_deauther.ino b/esp8266_deauther/esp8266_deauther.ino index f0aff36..e0c8c24 100644 --- a/esp8266_deauther/esp8266_deauther.ino +++ b/esp8266_deauther/esp8266_deauther.ino @@ -17,6 +17,8 @@ extern "C" { const static char *ssid = "pwned"; const static char *password = "deauther"; //must have at least 8 characters +#define WIFI_UI_ON false + ESP8266WebServer server(80); /* @@ -31,6 +33,8 @@ APScan apScan; ClientScan clientScan; Attack attack; +#include "SerialServer.h" + void sniffer(uint8_t *buf, uint16_t len){ clientScan.packetSniffer(buf,len); } @@ -41,68 +45,15 @@ void startWifi(){ WiFi.softAP(ssid, password); //for an open network without a password change to: WiFi.softAP(ssid); String _ssid = (String)ssid; String _password = (String)password; + #if WIFI_UI_ON==true Serial.println("SSID: "+_ssid); Serial.println("Password: "+_password); if(_password.length()<8) Serial.println("WARNING: password must have at least 8 characters!"); if(_ssid.length()<1 || _ssid.length()>32) Serial.println("WARNING: SSID length must be between 1 and 32 characters!"); + #endif } - -void setup(){ - - Serial.begin(115200); - delay(2000); - - nameList.begin(); - //nameList.clear(); - nameList.load(); - - Serial.println(""); - Serial.println("starting..."); - - startWifi(); - attack.generate(-1); - - /* ========== Web Server ========== */ - - /* HTML sites */ - server.onNotFound(load404); - - server.on("/", loadIndex); - server.on("/index.html", loadIndex); - server.on("/clients.html", loadClients); - server.on("/attack.html", loadAttack); - server.on("/functions.js", loadFunctionsJS); - - /* header links */ - server.on ("/style.css", loadStyle); - - /* JSON */ - server.on("/APScanResults.json", sendAPResults); - server.on("/APScan.json", startAPScan); - server.on("/APSelect.json", selectAP); - server.on("/ClientScan.json", startClientScan); - server.on("/ClientScanResults.json", sendClientResults); - server.on("/clientSelect.json", selectClient); - server.on("/setName.json", setClientName); - server.on("/attackInfo.json", sendAttackInfo); - server.on("/attackStart.json", startAttack); - - server.begin(); -} - -void loop(){ - if(clientScan.sniffing){ - if(clientScan.stop()){ - startWifi(); - } - } else{ - server.handleClient(); - attack.run(); - } -} - void load404(){ server.send ( 200, "text/html", data_get404()); } void loadIndex(){ server.send ( 200, "text/html", data_getIndexHTML() ); } void loadClients(){ server.send ( 200, "text/html", data_getClientsHTML()); } @@ -165,4 +116,95 @@ void startAttack(){ server.send ( 200, "text/json", "true"); } } -} +} + + + +void setup(){ + + Serial.begin(115200); + delay(2000); + + nameList.begin(); + //nameList.clear(); + nameList.load(); + + Serial.println(""); + Serial.println("starting..."); + + startWifi(); + attack.generate(-1); + + #if WIFI_UI_ON==true + /* ========== Web Server ========== */ + /* HTML sites */ + server.onNotFound(load404); + + server.on("/", loadIndex); + server.on("/index.html", loadIndex); + server.on("/clients.html", loadClients); + server.on("/attack.html", loadAttack); + server.on("/functions.js", loadFunctionsJS); + + /* header links */ + server.on ("/style.css", loadStyle); + + /* JSON */ + server.on("/APScanResults.json", sendAPResults); + server.on("/APScan.json", startAPScan); + server.on("/APSelect.json", selectAP); + server.on("/ClientScan.json", startClientScan); + server.on("/ClientScanResults.json", sendClientResults); + server.on("/clientSelect.json", selectClient); + server.on("/setName.json", setClientName); + server.on("/attackInfo.json", sendAttackInfo); + server.on("/attackStart.json", startAttack); + + server.begin(); + #else + // send MOTD + incomingSerialData = "*"; + incomingSerialDataReady = true; + #endif +} + +void loop(){ + #if WIFI_UI_ON!=true + bool show_hidden = false; + byte inByte = 0; + byte outByte = 0; + #endif + + if(clientScan.sniffing){ + if(clientScan.stop()){ + #if WIFI_UI_ON!=true + SerialPrintJSON( "CLIENT SCAN DONE" ); + Serial.println( clientScan.getResults() ); + #endif + startWifi(); + } + } else{ + #if WIFI_UI_ON==true + server.handleClient(); + #else + if(incomingSerialDataReady) { + handleSerialClient(); + } + #endif + attack.run(); + } + + #if WIFI_UI_ON!=true + if(Serial.available()){ + // Read Arduino IDE Serial Monitor inputs (if available) and capture orders + outByte = Serial.read(); + if(outByte==13) { + incomingSerialDataReady = true; + } else { + incomingSerialData = incomingSerialData + (char)outByte; + } + } + #endif + +} +