From 6220a44e7ef415242aa432c27010ff4327436094 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Sat, 31 Mar 2018 19:04:56 +0200 Subject: [PATCH] salt bugfix --- src/main.cpp | 5 +++-- src/rcommand.cpp | 2 +- src/wifisniffer.cpp | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 714c0751..25893c29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,7 +42,7 @@ configData_t cfg; // struct holds current device configuration osjob_t sendjob, initjob; // LMIC // Initialize global variables -int macnum = 0, blenum = 0; +int macnum = 0, blenum = 0, salt; uint64_t uptimecounter = 0; bool joinstate = false; @@ -187,7 +187,7 @@ void wifi_sniffer_loop(void * pvParameters) { configASSERT( ( ( uint32_t ) pvParameters ) == 1 ); // FreeRTOS check uint8_t channel = 1; - int nloop=0, lorawait=0, salt = rand() % 256; // random int between 0 and 255 used for salting MAC hashes + int nloop=0, lorawait=0, salt=rand() % 256; // random int between 0 and 255 used for salting MAC hashes ESP_LOGI(TAG, "Scan initialzied, salt value: %i", salt); while (true) { @@ -218,6 +218,7 @@ void wifi_sniffer_loop(void * pvParameters) { // clear counter if not in cumulative counter mode if (cfg.countermode != 1) { macs.clear(); // clear macs container + srand(macnum); // use macnum to reinitialize pseudorandom generator macnum = 0; u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 1063fb52..166e41ee 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -69,7 +69,7 @@ void set_reset(int val) { ESP_LOGI(TAG, "Remote command: reset MAC counter"); macs.clear(); // clear macs container macnum = 0; - //salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes + salt = rand() % 256; // get new random int between 0 and 255 for salting MAC hashes u8x8.clearLine(0); u8x8.clearLine(1); // clear Display counter u8x8.clearLine(5); u8x8.setCursor(0, 5); diff --git a/src/wifisniffer.cpp b/src/wifisniffer.cpp index 8b84ea00..c6f3265a 100644 --- a/src/wifisniffer.cpp +++ b/src/wifisniffer.cpp @@ -77,7 +77,8 @@ void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type) { if (!(addr2int & WIFI_MAC_FILTER_MASK)) { // filter local and group MACs // alt and hash MAC, and if new unique one, store hash in container and increment counter on display - addr2int <<= 8 || salt; // append salt value to MAC before hashing it + addr2int <<= 8; + addr2int += salt; // append salt value to MAC before hashing it itoa(addr2int, macbuf, 10); // convert 64 bit MAC to base 10 decimal string hashedmac = rokkit(macbuf, 10); // hash MAC for privacy, use 10 chars to fit in uint32_t container newmac = macs.insert(hashedmac); // store hashed MAC if new unique