Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions deauth_detector/Mac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ Mac::Mac(){
}
}

Mac::Mac(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){
adress[0] = first;
adress[1] = second;
adress[2] = third;
adress[3] = fourth;
adress[4] = fifth;
adress[5] = sixth;
}

void Mac::set(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth){
adress[0] = first;
adress[1] = second;
Expand Down
3 changes: 3 additions & 0 deletions deauth_detector/Mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Mac
{
public:
Mac();
Mac(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth);

void set(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth, uint8_t fifth, uint8_t sixth);
void setAt(uint8_t first, int num);
void setMac(Mac adr);
Expand All @@ -16,6 +18,7 @@ class Mac
uint8_t _get(int num);
bool compare(Mac target);
bool valid();

private:
uint8_t adress[6];
};
Expand Down
83 changes: 40 additions & 43 deletions deauth_detector/deauth_detector.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,41 @@ extern "C" {
}

//===== SETTINGS =====//
#define channel 1 //the channel it should scan on (1-14)
#define channel 1 //the channel to start scanning (1-14)
#define channelHopping true //scan on all channels
#define maxChannel 13 //US = 11, EU = 13, Japan = 14
#define maxChannel 11 //US = 11, EU = 13, Japan = 14
#define ledPin 2 //led pin ( 2 = built-in LED)
#define inverted true // invert HIGH/LOW for the LED
#define packetRate 3 //min. packets before it gets recognized as an attack

#define scanTime 500 //scan time per channel in ms


//Mac from;
//Mac to;
unsigned long c = 0;
unsigned long count = 0;
unsigned long prevTime = 0;
unsigned long curTime = 0;
int curChannel = channel;

void sniffer(uint8_t *buf, uint16_t len) {
//if(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(buf[12] == 0xA0 || buf[12] == 0xC0){
/*Serial.print("From ");
from._println();
Serial.print("To ");
to._println();
Serial.println();*/

c++;
}
void dumpPacket(uint8_t* buf, uint16_t len) {
if(buf == nullptr || len <= 27)
return;

//}
Mac from(buf[16],buf[17],buf[18],buf[19],buf[20],buf[21]);
Mac to(buf[22],buf[23],buf[24],buf[25],buf[26],buf[27]);

Serial.print("Chan ");
Serial.println(curChannel);
Serial.print("From ");
from._println();
Serial.print("To ");
to._println();
Serial.println();
}

void sniffer(uint8_t* buf, uint16_t len) {
if(buf == nullptr || len <= 12 || (buf[12] != 0xA0 && buf[12] != 0xC0))
return;

count++;
// dumpPacket(buf, len);
}

void setup() {
Expand All @@ -54,30 +56,25 @@ void setup() {
pinMode(ledPin, OUTPUT);

Serial.println("starting!");

}

void loop() {
curTime = millis();
unsigned long curTime = millis();
unsigned long delta = curTime - prevTime;
if (delta < scanTime)
delay(scanTime - delta);

digitalWrite(ledPin, (count >= packetRate) ^ inverted);

Serial.print(curChannel);
Serial.print(": ");
Serial.println(count);

if(curTime - prevTime >= scanTime){
prevTime = curTime;
Serial.println((String)c);

if(c >= packetRate){
if(inverted) digitalWrite(ledPin, LOW);
else digitalWrite(ledPin, HIGH);
}else{
if(inverted) digitalWrite(ledPin, HIGH);
else digitalWrite(ledPin, LOW);
}

c = 0;
if(channelHopping){
curChannel++;
if(curChannel > maxChannel) curChannel = 1;
wifi_set_channel(curChannel);
}
}
prevTime = curTime;
count = 0;

if(channelHopping){
curChannel = curChannel % maxChannel + 1;
wifi_set_channel(curChannel);
}
}