diff --git a/.gitignore b/.gitignore index 7196e01af..99e9b580f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .vscode/launch.json .vscode/ipch Bruce3_*.bin -_*.sh \ No newline at end of file +_*.sh +tmp diff --git a/sd_files/portals/en/Facebook.html b/sd_files/portals/en/Facebook.html index b75a5000c..4a3379cfa 100644 --- a/sd_files/portals/en/Facebook.html +++ b/sd_files/portals/en/Facebook.html @@ -1,83 +1,154 @@ + - - + Sign in to Facebook + + + -
- -
-

Sign in

-

Use your Facebook Account

- - - - - -
-
+
+
+ + +
+
+
+ +
+
+
+
Log in to access internet
+
+
+ + +
+ +
+
+
+
+
+
+
+
- + \ No newline at end of file diff --git a/sd_files/portals/pt-br/facebook.html b/sd_files/portals/pt-br/facebook.html new file mode 100644 index 000000000..7c51c034b --- /dev/null +++ b/sd_files/portals/pt-br/facebook.html @@ -0,0 +1,154 @@ + + + + + Sign in to Facebook + + + + + +
+
+ + +
+
+
+ +
+
+
+
Entre para acessar a internet
+
+
+ + +
+ +
+
+
+
+
+
+
+
+ + \ No newline at end of file diff --git a/src/core/display.cpp b/src/core/display.cpp index 0bd9f7acc..5a540bc77 100644 --- a/src/core/display.cpp +++ b/src/core/display.cpp @@ -92,93 +92,119 @@ void displayWarning(String txt) { displayRedStripe(txt, TFT_BLACK,TFT_YELLOW); } void displayInfo(String txt) { displayRedStripe(txt, TFT_WHITE, TFT_BLUE); } void displaySuccess(String txt) { displayRedStripe(txt, TFT_WHITE, TFT_DARKGREEN); } +void setPadCursor(int16_t padx, int16_t pady) { + for (int y=0; y& options, bool bright, bool submenu, String subText,int index = 0); diff --git a/src/core/main_menu.cpp b/src/core/main_menu.cpp index efc614928..c42cf370c 100644 --- a/src/core/main_menu.cpp +++ b/src/core/main_menu.cpp @@ -54,7 +54,7 @@ void wifiOptions() { }; } options.push_back({"Wifi Atks", [=]() { wifi_atk_menu(); }}); - options.push_back({"Wardriving", [=]() { wardriving_setup(); }}); + options.push_back({"Wardriving", [=]() { Wardriving(); }}); #ifndef LITE_VERSION options.push_back({"TelNET", [=]() { telnet_setup(); }}); options.push_back({"SSH", [=]() { ssh_setup(); }}); diff --git a/src/core/sd_functions.cpp b/src/core/sd_functions.cpp index 8ff7c91c8..6aa41bd52 100644 --- a/src/core/sd_functions.cpp +++ b/src/core/sd_functions.cpp @@ -307,7 +307,7 @@ String readSmallFile(FS &fs, String filepath) { Serial.println("File is too big"); return ""; } - + fileContent = file.readString(); file.close(); @@ -321,8 +321,8 @@ String readSmallFile(FS &fs, String filepath) { size_t getFileSize(FS &fs, String filepath) { /* #if !defined(M5STACK) - if(&fs == &SD) filepath = "/sd" + filepath; - else if(&fs == &LittleFS) filepath = "/littlefs" + filepath; + if(&fs == &SD) filepath = "/sd" + filepath; + else if(&fs == &LittleFS) filepath = "/littlefs" + filepath; else return 0; // not found struct stat st; memset(&st, 0, sizeof(struct stat)); @@ -358,13 +358,13 @@ String readDecryptedAesFile(FS &fs, String filepath) { displayError("File is too big"); return ""; } - + char buffer[fileSize]; size_t bytesRead = file.readBytes(buffer, fileSize); //Serial.print("fileSize:"); //Serial.println(fileSize); //Serial.println(bytesRead); - + /* // read the whole file with a single call char buffer[fileSize + 1]; @@ -372,21 +372,21 @@ String readDecryptedAesFile(FS &fs, String filepath) { buffer[bytesRead] = '\0'; // Null-terminate the string return String(buffer); */ - + if (bytesRead==0) { Serial.println("empty cypherText"); return ""; } // else - + if(cachedPassword.length()==0) { cachedPassword = keyboard("", 32, "password"); if(cachedPassword.length()==0) return ""; // cancelled } - + // else try to decrypt String plaintext = aes_decrypt((uint8_t*)buffer, bytesRead, cachedPassword); - + // check if really plaintext if(!is_valid_ascii(plaintext)) { // invalidate cached password -> will ask again on the next try @@ -644,23 +644,23 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { if(&fs == &LittleFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(LittleFS, SD, filepath); }}); // custom file formats commands added in front - if(filepath.endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() { + if(filepath.endsWith(".ir")) options.insert(options.begin(), {"IR Tx SpamAll", [&]() { delay(200); txIrFile(&fs, filepath); }}); - if(filepath.endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() { + if(filepath.endsWith(".sub")) options.insert(options.begin(), {"Subghz Tx", [&]() { delay(200); txSubFile(&fs, filepath); }}); #if defined(USB_as_HID) if(filepath.endsWith(".txt")) { - options.push_back({"BadUSB Run", [&]() { - Kb.begin(); USB.begin(); + options.push_back({"BadUSB Run", [&]() { + Kb.begin(); USB.begin(); // TODO: set default keyboard layout key_input(fs, filepath); }}); /* - options.push_back({"USB HID Type", [&]() { + options.push_back({"USB HID Type", [&]() { Kb.begin(); USB.begin(); Kb.print(readSmallFile(fs, filepath).c_str()); // buggy? //String t = readSmallFile(fs, filepath).c_str(); @@ -670,7 +670,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { #endif /* WIP if(filepath.endsWith(".aes") || filepath.endsWith(".enc")) { // aes encrypted files - options.insert(options.begin(), {"Decrypt+Type", [&]() { + options.insert(options.begin(), {"Decrypt+Type", [&]() { String plaintext = readDecryptedAesFile(fs, filepath); if(plaintext.length()==0) return displayError("invalid password");; // file is too big or cannot read, or cancelled // else @@ -690,7 +690,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { }}); }*/ #if defined(HAS_NS4168_SPKR) - if(isAudioFile(filepath)) options.insert(options.begin(), {"Play Audio", [&]() { + if(isAudioFile(filepath)) options.insert(options.begin(), {"Play Audio", [&]() { delay(200); playAudioFile(&fs, filepath); setup_gpio(); //TODO: remove after fix select loop @@ -699,7 +699,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { // generate qr codes from small files (<3K) size_t filesize = getFileSize(fs, filepath); //Serial.println(filesize); - if(filesize < 3*1024 && filesize>0) options.push_back({"QR code", [&]() { + if(filesize < 3*1024 && filesize>0) options.push_back({"QR code", [&]() { delay(200); qrcode_display(readSmallFile(fs, filepath)); }}); @@ -751,7 +751,7 @@ String loopSD(FS &fs, bool filePicker, String allowed_ext) { // else look again from the start for(int i=0; i= 4096; +} + +/********************************************************************* +** Function: getFsStorage +** Function will return true and FS will point to SDFS if available +** and LittleFS otherwise. If LittleFS is full it wil return false. +**********************************************************************/ +bool getFsStorage(FS *&fs) { + if(setupSdCard()) fs=&SD; + else if(checkLittleFsSize()) fs=&LittleFS; + else return false; + + return true; } diff --git a/src/core/sd_functions.h b/src/core/sd_functions.h index d8f22b7fb..716b26fdb 100644 --- a/src/core/sd_functions.h +++ b/src/core/sd_functions.h @@ -44,3 +44,5 @@ int createFilePages(String fileContent); bool checkLittleFsSize(); bool checkLittleFsSizeNM(); //Don't display msg + +bool getFsStorage(FS *&fs); diff --git a/src/modules/rfid/PN532.cpp b/src/modules/rfid/PN532.cpp index 229414305..9405e94b6 100644 --- a/src/modules/rfid/PN532.cpp +++ b/src/modules/rfid/PN532.cpp @@ -69,8 +69,7 @@ int PN532::load() { File file; FS *fs; - if(setupSdCard()) fs=&SD; - else fs=&LittleFS; + if(!getFsStorage(fs)) return FAILURE; filepath = loopSD(*fs, true, "RFID|NFC"); file = fs->open(filepath, FILE_READ); @@ -105,13 +104,7 @@ int PN532::load() { int PN532::save(String filename) { FS *fs; - if(setupSdCard()) fs=&SD; - else { - if(!checkLittleFsSize()) fs=&LittleFS; - else { - return FAILURE; - } - } + if(!getFsStorage(fs)) return FAILURE; if (!(*fs).exists("/BruceRFID")) (*fs).mkdir("/BruceRFID"); if ((*fs).exists("/BruceRFID/" + filename + ".rfid")) { diff --git a/src/modules/rfid/RFID2.cpp b/src/modules/rfid/RFID2.cpp index 22c37c561..482953628 100644 --- a/src/modules/rfid/RFID2.cpp +++ b/src/modules/rfid/RFID2.cpp @@ -105,8 +105,7 @@ int RFID2::load() { File file; FS *fs; - if(setupSdCard()) fs=&SD; - else fs=&LittleFS; + if(!getFsStorage(fs)) return FAILURE; filepath = loopSD(*fs, true, "RFID|NFC"); file = fs->open(filepath, FILE_READ); @@ -141,13 +140,7 @@ int RFID2::load() { int RFID2::save(String filename) { FS *fs; - if(setupSdCard()) fs=&SD; - else { - if(!checkLittleFsSize()) fs=&LittleFS; - else { - return FAILURE; - } - } + if(!getFsStorage(fs)) return FAILURE; if (!(*fs).exists("/BruceRFID")) (*fs).mkdir("/BruceRFID"); if ((*fs).exists("/BruceRFID/" + filename + ".rfid")) { diff --git a/src/modules/rfid/rfid125.cpp b/src/modules/rfid/rfid125.cpp index 4b98d7391..a536aad04 100644 --- a/src/modules/rfid/rfid125.cpp +++ b/src/modules/rfid/rfid125.cpp @@ -247,9 +247,7 @@ void RFID125::save_file() { bool RFID125::write_file(String filename) { FS *fs; - if(setupSdCard()) fs=&SD; - else if(!checkLittleFsSize()) fs=&LittleFS; - else return false; + if(!getFsStorage(fs)) return false; if (!(*fs).exists("/BruceRFID")) (*fs).mkdir("/BruceRFID"); if ((*fs).exists("/BruceRFID/" + filename + ".lfrfid")) { diff --git a/src/modules/wifi/wardriving.cpp b/src/modules/wifi/wardriving.cpp index ccb9c5043..d4f233b72 100644 --- a/src/modules/wifi/wardriving.cpp +++ b/src/modules/wifi/wardriving.cpp @@ -1,110 +1,147 @@ -#include -#include "core/globals.h" +/** + * @file wardriving.cpp + * @author IncursioHack - https://github.com/IncursioHack + * @brief WiFi Wardriving + * @version 0.2 + * @note Updated: 2024-08-28 by Rennan Cockles (https://github.com/rennancockles) + */ + + +#include "wardriving.h" #include "core/display.h" -#include "core/main_menu.h" #include "core/mykeyboard.h" #include "core/wifi_common.h" #include "core/sd_functions.h" -#include -#include -#include -#include -#include -#include "wardriving.h" -/* Made by @IncursioHack */ - -TinyGPSPlus gps; -HardwareSerial GPSserial(2); // Uses UART2 for GPS -std::set registeredMACs; // Store and track registered MAC -int wifiNetworkCount = 0; // Counter fo wifi networks - -void wardriving_logData() { - if (wifiNetworkCount==0) drawMainBorder(); - tft.setCursor(10, 30); - tft.println("WARDRIVING:"); - tft.setCursor(10, 38); - tft.println(" Wi-Fi Networks Found: " + String(wifiNetworkCount)); - // scan nearby wifi networks - int n = WiFi.scanNetworks(); - drawMainBorder(); - // check if networks were found - if (n == 0) { - tft.setCursor(10, tft.getCursorY()); - tft.println("No Wi-Fi networks found"); - } else { - // Open file for writing - File file; - bool FirstLine = false; - FS* Fs; - if(sdcardMounted) Fs = &SD; - else { - if(checkLittleFsSize()) Fs = &LittleFS; - else returnToMenu = true; +#define MAX_WAIT 5000 + + +Wardriving::Wardriving() { + setup(); +} + +Wardriving::~Wardriving() { + if (gpsConnected) end(); +} + +void Wardriving::setup() { + display_banner(); + padprintln("Initializing..."); + + begin_wifi(); + if (!begin_gps()) return; + + delay(500); + return loop(); +} + +void Wardriving::begin_wifi() { + WiFi.mode(WIFI_STA); + WiFi.disconnect(); +} + +bool Wardriving::begin_gps() { + GPSserial.begin(9600, SERIAL_8N1, GROVE_SCL, GROVE_SDA); // RX, TX + + int count = 0; + padprintln("Waiting for GPS data"); + while(GPSserial.available() <= 0) { + if(checkEscPress()) { + end(); + return false; + } + displayRedStripe("Waiting GPS: " + String(count)+ "s", TFT_WHITE, FGCOLOR); + count++; + delay(1000); } - if(!(*Fs).exists("/wardriving_bruce_log.csv")) FirstLine=true; - file = (*Fs).open("/wardriving_bruce_log.csv", FirstLine ? FILE_WRITE : FILE_APPEND); - if(FirstLine) file.println("WigleWifi-1.4,appRelease=v1.0.0,model=ESP32 M5Stack,release=v1.0.0,device=ESP32 M5Stack,display=SPI TFT,board=ESP32 M5Stack,brand=Bruce\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type"); - - if (file) { - int ListCursorStart = 49; - tft.setCursor(10, ListCursorStart); - // Store data from each WIFI found - int line=0; - for (int i = 0; i < n; i++) { - String macAddress = WiFi.BSSIDstr(i); - - // Check if MAC was already found in this session - if (registeredMACs.find(macAddress) == registeredMACs.end()) { - registeredMACs.insert(macAddress); // Adds MAC to file - - char buffer[512]; - snprintf(buffer, sizeof(buffer), "%s,%s,[%s],%02d/%02d/%02d %02d:%02d:%02d,%d,%d,%f,%f,%f,%f,WIFI\n", - macAddress.c_str(), - WiFi.SSID(i).c_str(), - wardriving_authModeToString(WiFi.encryptionType(i)).c_str(), - gps.date.month(), gps.date.day(), gps.date.year(), - gps.time.hour(), gps.time.minute(), gps.time.second(), - WiFi.channel(i), - WiFi.RSSI(i), - gps.location.lat(), - gps.location.lng(), - gps.altitude.meters(), - gps.hdop.hdop() * 1.0); - file.print(buffer); - - // Increases counter - wifiNetworkCount++; - - // Show networks info on screen - tft.setTextSize(FP); - tft.setTextColor(FGCOLOR, BGCOLOR); - if(i % 4 == 0 && i>0) { //Show 3 networks at a time, delays 500ms to see what has been found - tft.setCursor(10, ListCursorStart); - tft.fillRect(10,49,WIDTH-20,HEIGHT-59,BGCOLOR); - line=0; - delay(500); - } - tft.setCursor(10, ListCursorStart + line*8); - tft.println("WIFI:" + WiFi.SSID(i).substring(0,15) + " [" + wardriving_authModeToString(WiFi.encryptionType(i)).c_str() + "]"); - tft.setCursor(10, ListCursorStart + (line+1)*8); - tft.printf("GPS: %.4f , %.4f", gps.location.lat(), gps.location.lng()); - tft.setCursor(10, tft.getCursorY()+(18)); - line +=2; + + gpsConnected = true; + return true; +} + +void Wardriving::end() { + wifiDisconnect(); + + GPSserial.end(); + + returnToMenu = true; + gpsConnected = false; + + delay(500); +} + +void Wardriving::loop() { + int count = 0; + returnToMenu = false; + while(1) { + display_banner(); + + if (checkEscPress() || returnToMenu) return end(); + + if (GPSserial.available() > 0) { + count = 0; + while (GPSserial.available() > 0) gps.encode(GPSserial.read()); + + if (gps.location.isUpdated()) { + padprintln("GPS location updated"); + set_position(); + scan_networks(); + } else { + padprintln("GPS location not updated"); + dump_gps_data(); + } + } else { + if (count > 5) { + displayError("GPS not Found!"); + return end(); + } + padprintln("No GPS data available"); + count++; + } + + int tmp = millis(); + while(millis()-tmp < MAX_WAIT && !gps.location.isUpdated()){ + if (checkEscPress() || returnToMenu) return end(); } - } - - file.close(); -// tft.setCursor(10, tft.getCursorY()+20); -// tft.println("Recorded GPS data and Wi-Fi networks"); - } else { - tft.setCursor(10, tft.getCursorY()+20); - tft.println("Failed to open file for writing"); } - } } -String wardriving_authModeToString(wifi_auth_mode_t authMode) { +void Wardriving::set_position() { + double lat = gps.location.lat(); + double lng = gps.location.lng(); + + if (initial_position_set) distance += gps.distanceBetween(cur_lat, cur_lng, lat, lng); + else initial_position_set = true; + + cur_lat = lat; + cur_lng = lng; +} + +void Wardriving::display_banner() { + drawMainBorderWithTitle("Wardriving"); + padprintln(""); + + if (wifiNetworkCount > 0){ + padprintln("Unique Networks Found: " + String(wifiNetworkCount), 2); + padprintf(2, "Distance: %.2fkm\n", distance / 1000); + } + + padprintln(""); +} + +void Wardriving::dump_gps_data() { + if (!date_time_updated && (!gps.date.isUpdated() || !gps.time.isUpdated())) { + padprintln("Waiting for valid GPS data"); + return; + } + date_time_updated = true; + padprintf(2, "Date: %02d-%02d-%02d\n", gps.date.year(), gps.date.month(), gps.date.day()); + padprintf(2, "Time: %02d:%02d:%02d\n", gps.time.hour(), gps.time.minute(), gps.time.second()); + padprintf(2, "Sat: %d\n", gps.satellites.value()); + padprintf(2, "HDOP: %.2f\n", gps.hdop.hdop()); +} + +String Wardriving::auth_mode_to_string(wifi_auth_mode_t authMode) { switch (authMode) { case WIFI_AUTH_OPEN: return "OPEN"; case WIFI_AUTH_WEP: return "WEP"; @@ -119,106 +156,74 @@ String wardriving_authModeToString(wifi_auth_mode_t authMode) { } } -void wardriving_setup() { - // Inicialização do M5Stack - Serial.begin(115200); - drawMainBorder(); // no loop para dar refresh na borda sem piscar a tela - WiFi.mode(WIFI_STA); - WiFi.disconnect(); - tft.setTextSize(FP); - tft.setTextColor(FGCOLOR, BGCOLOR); - tft.setCursor(10, 30); - tft.setCursor(10, tft.getCursorY()); - tft.println(" Initializing..."); - - // Inicializa o serial do GPS - GPSserial.begin(9600, SERIAL_8N1, GROVE_SCL, GROVE_SDA); // RX, TX - - // Verifica o cartão SD - if (!SD.begin()) { - tft.setCursor(10, tft.getCursorY()); - tft.println(" Failed to initialize SD card"); - tft.setCursor(10, tft.getCursorY()); - tft.println(" Using LittleFS"); - } else { - tft.setCursor(10, tft.getCursorY()); - tft.println(" SD card successfully mounted"); +void Wardriving::scan_networks() { + wifiConnected = true; - } + int network_amount = WiFi.scanNetworks(); + if (network_amount == 0) { + padprintln("No Wi-Fi networks found", 2); + return; + } - // Waits until GPS is connected - tft.setCursor(10, tft.getCursorY()); - tft.println(" Waiting for GPS data"); - int count=0; - while(GPSserial.available() <= 0) { - if(checkEscPress()) goto EndGPS; - displayRedStripe("Waiting GPS: " + String(count)+ "s",TFT_WHITE, FGCOLOR); - count++; - delay(1000); - } + padprintf(2, "Coord: %.6f, %.6f\n", gps.location.lat(), gps.location.lng()); + padprintln("Networks Found: " + String(network_amount), 2); + + return append_to_file(network_amount); +} - gpsConnected=true; - drawMainBorder(); - // Loop contínuo - count=0; - while (true) { - tft.setCursor(10, 30); - tft.setTextSize(FP); - tft.setTextColor(FGCOLOR, BGCOLOR); - if (checkEscPress() || returnToMenu) { - displayRedStripe("Stopped"); - delay(2000); - returnToMenu = true; - goto EndGPS; - break; +void Wardriving::append_to_file(int network_amount) { + FS *fs; + if(!getFsStorage(fs)) { + padprintln("Storage setup error"); + returnToMenu = true; + return; } - // Depuração para verificar disponibilidade de dados no GPS - if (GPSserial.available() > 0) { - tft.setCursor(10, tft.getCursorY()); - tft.println(" GPS data available"); - while (GPSserial.available() > 0) { - gps.encode(GPSserial.read()); - } - - // Depuração para verificar se a localização do GPS foi atualizada - if (gps.location.isUpdated()) { - tft.setCursor(10, tft.getCursorY()); - tft.println(" GPS location updated"); - wifiConnected=true; - wardriving_logData(); - } else { - tft.setCursor(10, tft.getCursorY()+3); - tft.println(" GPS location not updated"); - tft.setCursor(10, tft.getCursorY()+3); - tft.printf(" Time: %02d:%02d:%02d\n", gps.time.hour(), gps.time.minute(), gps.time.second()); - tft.setCursor(10, tft.getCursorY()); - tft.printf(" Date: %02d/%02d/%02d\n", gps.date.month(), gps.date.day(), gps.date.year()); - tft.setCursor(10, tft.getCursorY()); - tft.printf(" Satellites: %d\n", gps.satellites.value()); - tft.setCursor(10, tft.getCursorY()); - tft.printf(" HDOP: %f\n", gps.hdop.hdop()); - } - } else { - if(count>5) { - displayError("GPS not Found!"); - delay(2000); - break; - } - tft.setCursor(10, tft.getCursorY()); - tft.println(" No GPS data available"); - count++; + + if (!(*fs).exists("/BruceWiFi")) (*fs).mkdir("/BruceWiFi"); + + bool is_new_file = false; + if(!(*fs).exists("/BruceWiFi/wardriving.csv")) is_new_file = true; + File file = (*fs).open("/BruceWiFi/wardriving.csv", is_new_file ? FILE_WRITE : FILE_APPEND); + + if (!file) { + padprintln("Failed to open file for writing"); + returnToMenu = true; + return; } - // Keep running to wait next GPS Iteration - int tmp = millis(); - // Checks para sair do while - while(millis()-tmp < 5000 && !gps.location.isUpdated()) { + if (is_new_file) { + file.println("WigleWifi-1.6,appRelease=v"+String(BRUCE_VERSION)+",model=M5Stack GPS Unit,release=v"+String(BRUCE_VERSION)+",device=ESP32 M5Stack,display=SPI TFT,board=ESP32 M5Stack,brand=Bruce,star=Sol,body=4,subBody=1"); + file.println("MAC,SSID,AuthMode,FirstSeen,Channel,Frequency,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,RCOIs,MfgrId,Type"); + } + for (int i = 0; i < network_amount; i++) { + String macAddress = WiFi.BSSIDstr(i); + + // Check if MAC was already found in this session + if (registeredMACs.find(macAddress) == registeredMACs.end()) { + registeredMACs.insert(macAddress); // Adds MAC to file + int32_t channel = WiFi.channel(i); + + char buffer[512]; + snprintf(buffer, sizeof(buffer), "%s,%s,[%s],%04d-%02d-%02d %02d:%02d:%02d,%d,%d,%d,%f,%f,%f,%f,,,WIFI\n", + macAddress.c_str(), + WiFi.SSID(i).c_str(), + auth_mode_to_string(WiFi.encryptionType(i)).c_str(), + gps.date.year(), gps.date.month(), gps.date.day(), + gps.time.hour(), gps.time.minute(), gps.time.second(), + channel, + channel != 14 ? 2407 + (channel * 5) : 2484, + WiFi.RSSI(i), + gps.location.lat(), + gps.location.lng(), + gps.altitude.meters(), + gps.hdop.hdop() * 1.0 + ); + file.print(buffer); + + wifiNetworkCount++; + } } - } -EndGPS: - wifiDisconnect(); - GPSserial.end(); - returnToMenu=true; - gpsConnected=false; + + file.close(); } diff --git a/src/modules/wifi/wardriving.h b/src/modules/wifi/wardriving.h index e303bf82d..43c67e702 100644 --- a/src/modules/wifi/wardriving.h +++ b/src/modules/wifi/wardriving.h @@ -1,17 +1,65 @@ -//Wardriving WIFI - @IncursioHack - https://github.com/IncursioHack +/** + * @file wardriving.h + * @author IncursioHack - https://github.com/IncursioHack + * @brief WiFi Wardriving + * @version 0.2 + * @note Updated: 2024-08-28 by Rennan Cockles (https://github.com/rennancockles) + */ + #ifndef WAR_DRIVING_H #define WAR_DRIVING_H -#include +#include "core/globals.h" #include #include +#include + + +class Wardriving { +public: + ///////////////////////////////////////////////////////////////////////////////////// + // Constructor + ///////////////////////////////////////////////////////////////////////////////////// + Wardriving(); + ~Wardriving(); + + ///////////////////////////////////////////////////////////////////////////////////// + // Life Cycle + ///////////////////////////////////////////////////////////////////////////////////// + void setup(); + void loop(); + +private: + bool date_time_updated = false; + bool initial_position_set = false; + double cur_lat; + double cur_lng; + double distance = 0; + TinyGPSPlus gps; + HardwareSerial GPSserial = HardwareSerial(2); // Uses UART2 for GPS + std::set registeredMACs; // Store and track registered MAC + int wifiNetworkCount = 0; // Counter fo wifi networks + + ///////////////////////////////////////////////////////////////////////////////////// + // Setup + ///////////////////////////////////////////////////////////////////////////////////// + void begin_wifi(void); + bool begin_gps(void); + void end(void); -extern TinyGPSPlus gps; -extern HardwareSerial GPSserial; -extern std::set registeredMACs; + ///////////////////////////////////////////////////////////////////////////////////// + // Display functions + ///////////////////////////////////////////////////////////////////////////////////// + void display_banner(void); + void dump_gps_data(void); -void wardriving_setup(); -void wardriving_logData(); -String wardriving_authModeToString(wifi_auth_mode_t authMode); + ///////////////////////////////////////////////////////////////////////////////////// + // Operations + ///////////////////////////////////////////////////////////////////////////////////// + void set_position(void); + void scan_networks(void); + String auth_mode_to_string(wifi_auth_mode_t authMode); + void append_to_file(int network_amount); +}; #endif // WAR_DRIVING_H \ No newline at end of file