From fe08c145f6467cde0a7d80851e466af80872f6ed Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:40:15 +0100 Subject: [PATCH 01/11] Fix WarDrive do_save check for valid GPS --- esp32_marauder/WiFiScan.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 092fa01c0..4cac1b269 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -1821,7 +1821,9 @@ void WiFiScan::executeWarDrive() { String wardrive_line = WiFi.BSSIDstr(i) + "," + ssid + "," + this->security_int_to_string(WiFi.encryptionType(i)) + "," + gps_obj.getDatetime() + "," + (String)WiFi.channel(i) + "," + (String)WiFi.RSSI(i) + "," + gps_obj.getLat() + "," + gps_obj.getLon() + "," + gps_obj.getAlt() + "," + gps_obj.getAccuracy() + ",WIFI\n"; Serial.print((String)this->mac_history_cursor + " | " + wardrive_line); - evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + if (do_save) { + evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + } } } this->channelHop(); From d0f5d89980d6d155a467f74fc543594b68835597 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:43:25 +0100 Subject: [PATCH 02/11] Legacy SD do_save is always true --- esp32_marauder/SDInterface.cpp | 6 +++--- esp32_marauder/SDInterface.h | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 1ca4b3fc1..2dd2183ad 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -143,7 +143,7 @@ void SDInterface::listDir(String str_dir){ } void SDInterface::addPacket(uint8_t* buf, uint32_t len, bool log) { - if ((this->supported) && (this->do_save)) { + if (this->supported) { buffer_obj.addPacket(buf, len, log); } } @@ -300,11 +300,11 @@ bool SDInterface::checkDetectPin() { } void SDInterface::main() { - if ((this->supported) && (this->do_save)) { + if (this->supported) { //Serial.println("Saving packet..."); buffer_obj.forceSave(&SD); } - else if (!this->supported) { + else { if (checkDetectPin()) { delay(100); this->initSD(); diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index e29e62b4e..a646f762d 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -35,7 +35,6 @@ class SDInterface { uint64_t cardSizeMB; //uint64_t cardSizeGB; bool supported = false; - bool do_save = true; String card_sz; From f6c27ed2167f67054b2212c1b82eb62eeffe3f6d Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 16:10:00 +0100 Subject: [PATCH 03/11] Sd+Serial pcapAdd() and logAdd() in buffer_obj --- esp32_marauder/Buffer.cpp | 20 ++++++++++-- esp32_marauder/Buffer.h | 8 +++-- esp32_marauder/EvilPortal.cpp | 33 +------------------- esp32_marauder/EvilPortal.h | 2 -- esp32_marauder/SDInterface.cpp | 8 ----- esp32_marauder/SDInterface.h | 1 - esp32_marauder/WiFiScan.cpp | 51 ++++++++++++------------------- esp32_marauder/WiFiScan.h | 2 -- esp32_marauder/esp32_marauder.ino | 5 ++- 9 files changed, 44 insertions(+), 86 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 90f25a9d8..0f1b36e58 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -53,7 +53,7 @@ void Buffer::close(fs::FS* fs){ Serial.println(text01); } -void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){ +void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){ // buffer is full -> drop packet if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){ //Serial.print(";"); @@ -74,7 +74,7 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){ microSeconds -= seconds*1000*1000; // e.g. 45200400 - 45*1000*1000 = 45200400 - 45000000 = 400us (because we only need the offset) - if (!log) { + if (is_pcap) { write(seconds); // ts_sec write(microSeconds); // ts_usec write(len); // incl_len @@ -84,6 +84,20 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){ write(buf, len); // packet payload } +void Buffer::pcapAdd(wifi_promiscuous_pkt_t *packet, int len) { + bool save_packet = settings_obj.loadSetting(text_table4[7]); + if (save_packet) { + add(packet->payload, len, true); + } +} + +void Buffer::logAdd(String log) { + bool save_packet = settings_obj.loadSetting(text_table4[7]); + if (save_packet) { + add((const uint8_t*)log.c_str(), log.length(), false); + } +} + void Buffer::write(int32_t n){ uint8_t buf[4]; buf[0] = n; @@ -109,7 +123,7 @@ void Buffer::write(uint16_t n){ write(buf,2); } -void Buffer::write(uint8_t* buf, uint32_t len){ +void Buffer::write(const uint8_t* buf, uint32_t len){ if(!writing) return; if(useA){ diff --git a/esp32_marauder/Buffer.h b/esp32_marauder/Buffer.h index a87b751d8..c2dc2f998 100644 --- a/esp32_marauder/Buffer.h +++ b/esp32_marauder/Buffer.h @@ -6,7 +6,7 @@ #include "Arduino.h" #include "FS.h" #include "settings.h" -//#include "SD_MMC.h" +#include "esp_wifi_types.h" #define BUF_SIZE 3 * 1024 // Had to reduce buffer size to save RAM. GG @spacehuhn #define SNAP_LEN 2324 // max len of each recieved packet @@ -21,15 +21,17 @@ class Buffer { void createPcapFile(fs::FS* fs, String fn = "", bool log = false); void open(bool log = false); void close(fs::FS* fs); - void addPacket(uint8_t* buf, uint32_t len, bool log = false); + void pcapAdd(wifi_promiscuous_pkt_t *packet, int len); + void logAdd(String log); void save(fs::FS* fs); void forceSave(fs::FS* fs); void forceSaveSerial(); private: + void add(const uint8_t* buf, uint32_t len, bool is_pcap); void write(int32_t n); void write(uint32_t n); void write(uint16_t n); - void write(uint8_t* buf, uint32_t len); + void write(const uint8_t* buf, uint32_t len); uint8_t* bufA; uint8_t* bufB; diff --git a/esp32_marauder/EvilPortal.cpp b/esp32_marauder/EvilPortal.cpp index 778a1f926..778b9025a 100644 --- a/esp32_marauder/EvilPortal.cpp +++ b/esp32_marauder/EvilPortal.cpp @@ -272,37 +272,6 @@ void EvilPortal::startPortal() { this->runServer = true; } -void EvilPortal::convertStringToUint8Array(const String& str, uint8_t*& buf, uint32_t& len) { - len = str.length(); // Obtain the length of the string - - buf = new uint8_t[len]; // Dynamically allocate the buffer - - // Copy each character from the string to the buffer - for (uint32_t i = 0; i < len; i++) { - buf[i] = static_cast(str.charAt(i)); - } -} - -void EvilPortal::addLog(String log, int len) { - bool save_packet = settings_obj.loadSetting(text_table4[7]); - if (save_packet) { - uint8_t* logBuffer = nullptr; - uint32_t logLength = 0; - this->convertStringToUint8Array(log, logBuffer, logLength); - - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.addPacket(logBuffer, logLength, true); - delete[] logBuffer; - #elif defined(HAS_SD) - sd_obj.addPacket(logBuffer, logLength, true); - delete[] logBuffer; - #else - delete[] logBuffer; - return; - #endif - } -} - void EvilPortal::sendToDisplay(String msg) { #ifdef HAS_SCREEN String display_string = ""; @@ -329,7 +298,7 @@ void EvilPortal::main(uint8_t scan_mode) { String logValue2 = "p: " + this->password; String full_string = logValue1 + " " + logValue2 + "\n"; Serial.print(full_string); - this->addLog(full_string, full_string.length()); + buffer_obj.logAdd(full_string); #ifdef HAS_SCREEN this->sendToDisplay(full_string); #endif diff --git a/esp32_marauder/EvilPortal.h b/esp32_marauder/EvilPortal.h index 76d9444de..f3c36ed61 100644 --- a/esp32_marauder/EvilPortal.h +++ b/esp32_marauder/EvilPortal.h @@ -95,7 +95,6 @@ class EvilPortal { void setupServer(); void startPortal(); void startAP(); - void convertStringToUint8Array(const String& str, uint8_t*& buf, uint32_t& len); void sendToDisplay(String msg); public: @@ -111,7 +110,6 @@ class EvilPortal { String get_user_name(); String get_password(); void setup(); - void addLog(String log, int len); bool begin(LinkedList* ssids, LinkedList* access_points); void main(uint8_t scan_mode); void setHtmlFromSerial(); diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 2dd2183ad..7f80e1b0d 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -73,8 +73,6 @@ bool SDInterface::initSD() { this->card_sz = sz; } - buffer_obj = Buffer(); - if (!SD.exists("/SCRIPTS")) { Serial.println("/SCRIPTS does not exist. Creating..."); @@ -142,12 +140,6 @@ void SDInterface::listDir(String str_dir){ } } -void SDInterface::addPacket(uint8_t* buf, uint32_t len, bool log) { - if (this->supported) { - buffer_obj.addPacket(buf, len, log); - } -} - void SDInterface::openCapture(String file_name) { bool save_pcap = settings_obj.loadSetting("SavePCAP"); if ((this->supported) && (save_pcap)) { diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index a646f762d..e32925be1 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -43,7 +43,6 @@ class SDInterface { void listDir(String str_dir); void listDirToLinkedList(LinkedList* file_names, String str_dir = "/", String ext = ""); File getFile(String path); - void addPacket(uint8_t* buf, uint32_t len, bool log = false); void openCapture(String file_name = ""); void openLog(String file_name = ""); void runUpdate(); diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 4cac1b269..79c2f1cd0 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -242,7 +242,7 @@ extern "C" { Serial.print(wardrive_line); if (do_save) - evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + buffer_obj.logAdd(wardrive_line); } } #endif @@ -1822,7 +1822,7 @@ void WiFiScan::executeWarDrive() { Serial.print((String)this->mac_history_cursor + " | " + wardrive_line); if (do_save) { - evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + buffer_obj.logAdd(wardrive_line); } } } @@ -1847,7 +1847,7 @@ void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color) if (gps_obj.getGpsModuleStatus()) { sd_obj.openLog("wardrive"); String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - evil_portal_obj.addLog(header_line, header_line.length()); + buffer_obj.logAdd(header_line); } #endif } @@ -2075,7 +2075,7 @@ void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color) if (gps_obj.getGpsModuleStatus()) { sd_obj.openLog("station_wardrive"); String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - evil_portal_obj.addLog(header_line, header_line.length()); + buffer_obj.logAdd(header_line); } #endif } @@ -2228,7 +2228,7 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color) #endif } String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - evil_portal_obj.addLog(header_line, header_line.length()); + buffer_obj.logAdd(header_line); } #endif #else @@ -2395,7 +2395,7 @@ void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } } @@ -2554,7 +2554,7 @@ void WiFiScan::apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } } @@ -2680,7 +2680,7 @@ void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } } @@ -2801,7 +2801,7 @@ void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) { #ifdef HAS_GPS @@ -2876,7 +2876,7 @@ void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type } String wardrive_line = (String)addr + "," + essid + "," + wifi_scan_obj.security_int_to_string(snifferPacket->rx_ctrl.channel) + "," + gps_obj.getDatetime() + "," + (String)snifferPacket->rx_ctrl.channel + "," + (String)snifferPacket->rx_ctrl.rssi + "," + gps_obj.getLat() + "," + gps_obj.getLon() + "," + gps_obj.getAlt() + "," + gps_obj.getAccuracy() + ",WIFI"; Serial.println(wardrive_line); - //evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + //buffer_obj.logAdd(wardrive_line); } } #endif @@ -3040,7 +3040,7 @@ void WiFiScan::stationSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t typ access_points->set(ap_index, ap); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -3141,7 +3141,7 @@ void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -3205,7 +3205,7 @@ void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } } @@ -3277,7 +3277,7 @@ void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION_WAR_DRIVE) { #ifdef HAS_GPS @@ -3332,7 +3332,7 @@ void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) if (do_save) { String wardrive_line = (String)addr + "," + (String)addr + ",," + gps_obj.getDatetime() + "," + (String)snifferPacket->rx_ctrl.channel + "," + (String)snifferPacket->rx_ctrl.rssi + "," + gps_obj.getLat() + "," + gps_obj.getLon() + "," + gps_obj.getAlt() + "," + gps_obj.getAccuracy() + ",WIFI"; Serial.println(wardrive_line); - evil_portal_obj.addLog(wardrive_line, wardrive_line.length()); + buffer_obj.logAdd(wardrive_line); } } #endif @@ -3423,7 +3423,7 @@ void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t Serial.println(); - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } } @@ -3884,7 +3884,7 @@ void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) #endif #endif - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } } @@ -3972,7 +3972,7 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) #endif } - addPacket(snifferPacket, len); + buffer_obj.pcapAdd(snifferPacket, len); } void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -4058,20 +4058,7 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t } - addPacket(snifferPacket, len); -} - -void WiFiScan::addPacket(wifi_promiscuous_pkt_t *snifferPacket, int len) { - bool save_packet = settings_obj.loadSetting(text_table4[7]); - if (save_packet) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.addPacket(snifferPacket->payload, len); - #elif defined(HAS_SD) - sd_obj.addPacket(snifferPacket->payload, len); - #else - return; - #endif - } + buffer_obj.pcapAdd(snifferPacket, len); } #ifdef HAS_SCREEN diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index 633b9a5e4..4990f21ec 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -389,7 +389,6 @@ class WiFiScan void StartScan(uint8_t scan_mode, uint16_t color = 0); void StopScan(uint8_t scan_mode); const char* generateRandomName(); - //void addLog(String log, int len); static void getMAC(char *addr, uint8_t* data, uint16_t offset); static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); @@ -404,7 +403,6 @@ class WiFiScan static void activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); static void eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); static void wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); - static void addPacket(wifi_promiscuous_pkt_t *snifferPacket, int len); /*#ifdef HAS_BT enum EBLEPayloadType diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index 44b67a609..4c0edb59a 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -293,9 +293,8 @@ void setup() display_obj.tft.println(F(text_table0[2])); #endif - #ifdef WRITE_PACKETS_SERIAL - buffer_obj = Buffer(); - #elif defined(HAS_SD) + buffer_obj = Buffer(); + #if defined(HAS_SD) // Do some SD stuff if(sd_obj.initSD()) { #ifdef HAS_SCREEN From c61aaf95cd06d4f9ecb5ab2f641422e4fa72d834 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:31:30 +0100 Subject: [PATCH 04/11] Sd+Serial pcapOpen() and logOpen() in buffer_obj --- esp32_marauder/Buffer.cpp | 40 +++++-- esp32_marauder/Buffer.h | 10 +- esp32_marauder/SDInterface.cpp | 16 --- esp32_marauder/SDInterface.h | 2 - esp32_marauder/WiFiScan.cpp | 198 ++++++++++++++------------------- esp32_marauder/WiFiScan.h | 5 +- 6 files changed, 124 insertions(+), 147 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 0f1b36e58..0e4700110 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -6,17 +6,17 @@ Buffer::Buffer(){ bufB = (uint8_t*)malloc(BUF_SIZE); } -void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){ +void Buffer::createFile(String name, bool is_pcap){ int i=0; - if (!log) { + if (is_pcap) { do{ - fileName = "/"+fn+"_"+(String)i+".pcap"; + fileName = "/"+name+"_"+(String)i+".pcap"; i++; } while(fs->exists(fileName)); } else { do{ - fileName = "/"+fn+"_"+(String)i+".log"; + fileName = "/"+name+"_"+(String)i+".log"; i++; } while(fs->exists(fileName)); } @@ -27,7 +27,7 @@ void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){ file.close(); } -void Buffer::open(bool log){ +void Buffer::open(bool is_pcap){ bufSizeA = 0; bufSizeB = 0; @@ -35,7 +35,7 @@ void Buffer::open(bool log){ writing = true; - if (!log) { + if (is_pcap) { write(uint32_t(0xa1b2c3d4)); // magic number write(uint16_t(2)); // major version number write(uint16_t(4)); // minor version number @@ -46,11 +46,29 @@ void Buffer::open(bool log){ } } -void Buffer::close(fs::FS* fs){ - if(!writing) return; - forceSave(fs); - writing = false; - Serial.println(text01); +void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) { + bool save_pcap = settings_obj.loadSetting("SavePCAP"); + if (!save_pcap) { + this->fs = NULL; + this->serial = false; + return; + } + this->fs = fs; + this->serial = serial; + if (this->fs) { + createFile(file_name, is_pcap); + } + if (this->fs || this->serial) { + open(is_pcap); + } +} + +void Buffer::pcapOpen(String file_name, fs::FS* fs, bool serial) { + openFile(file_name, fs, serial, true); +} + +void Buffer::logOpen(String file_name, fs::FS* fs, bool serial) { + openFile(file_name, fs, serial, false); } void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){ diff --git a/esp32_marauder/Buffer.h b/esp32_marauder/Buffer.h index c2dc2f998..6fb14fcf1 100644 --- a/esp32_marauder/Buffer.h +++ b/esp32_marauder/Buffer.h @@ -18,15 +18,17 @@ extern Settings settings_obj; class Buffer { public: Buffer(); - void createPcapFile(fs::FS* fs, String fn = "", bool log = false); - void open(bool log = false); - void close(fs::FS* fs); + void pcapOpen(String file_name, fs::FS* fs, bool serial); + void logOpen(String file_name, fs::FS* fs, bool serial); void pcapAdd(wifi_promiscuous_pkt_t *packet, int len); void logAdd(String log); void save(fs::FS* fs); void forceSave(fs::FS* fs); void forceSaveSerial(); private: + void createFile(String name, bool is_pcap); + void open(bool is_pcap); + void openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap); void add(const uint8_t* buf, uint32_t len, bool is_pcap); void write(int32_t n); void write(uint32_t n); @@ -45,6 +47,8 @@ class Buffer { String fileName = "/0.pcap"; File file; + fs::FS* fs; + bool serial; }; #endif diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 7f80e1b0d..6b1fdc66a 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -140,22 +140,6 @@ void SDInterface::listDir(String str_dir){ } } -void SDInterface::openCapture(String file_name) { - bool save_pcap = settings_obj.loadSetting("SavePCAP"); - if ((this->supported) && (save_pcap)) { - buffer_obj.createPcapFile(&SD, file_name); - buffer_obj.open(); - } -} - -void SDInterface::openLog(String file_name) { - bool save_pcap = settings_obj.loadSetting("SavePCAP"); - if ((this->supported) && (save_pcap)) { - buffer_obj.createPcapFile(&SD, file_name, true); - buffer_obj.open(true); - } -} - void SDInterface::runUpdate() { #ifdef HAS_SCREEN display_obj.tft.setTextWrap(false); diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index e32925be1..f2655fac1 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -43,8 +43,6 @@ class SDInterface { void listDir(String str_dir); void listDirToLinkedList(LinkedList* file_names, String str_dir = "/", String ext = ""); File getFile(String path); - void openCapture(String file_name = ""); - void openLog(String file_name = ""); void runUpdate(); void performUpdate(Stream &updateSource, size_t updateSize); void main(); diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 79c2f1cd0..6328809c5 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -930,15 +930,41 @@ String WiFiScan::freeRAM() return String(s); } +void WiFiScan::startPcap(String file_name) { + buffer_obj.pcapOpen( + file_name, + #if defined(HAS_SD) + sd_obj.supported ? &SD : + #endif + NULL, + // TODO: make commandline options + #ifdef WRITE_PACKETS_SERIAL + true + #else + false + #endif + ); +} + +void WiFiScan::startLog(String file_name) { + buffer_obj.logOpen( + file_name, + #if defined(HAS_SD) + sd_obj.supported ? &SD : + #endif + NULL, + // TODO: make commandline options + #ifdef WRITE_PACKETS_SERIAL + true + #else + false + #endif + ); +} + void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openLog("evil_portal"); - #else - return; - #endif + startLog("evil_portal"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -981,13 +1007,7 @@ void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color) // Function to start running a beacon scan void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("ap"); - #else - return; - #endif + startPcap("ap"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -1428,13 +1448,7 @@ void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color) led_obj.setMode(MODE_SNIFF); #endif - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("packet_monitor"); - #else - return; - #endif + startPcap("packet_monitor"); #ifdef HAS_ILI9341 @@ -1522,11 +1536,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color) display_obj.tft.fillScreen(TFT_BLACK); #endif - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("eapol"); - #endif + startPcap("eapol"); #ifdef HAS_SCREEN #ifdef TFT_SHIELD @@ -1551,13 +1561,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color) display_obj.tftDrawExitScaleButtons(); #endif #else - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("eapol"); - #else - return; - #endif + startPcap("eapol"); #ifdef HAS_SCREEN display_obj.TOP_FIXED_AREA_2 = 48; @@ -1652,13 +1656,7 @@ void WiFiScan::RunMimicFlood(uint8_t scan_mode, uint16_t color) { void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("pwnagotchi"); - #else - return; - #endif + startPcap("pwnagotchi"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -1837,23 +1835,21 @@ void WiFiScan::executeWarDrive() { // Function to start running a beacon scan void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - if (scan_mode == WIFI_SCAN_AP) - sd_obj.openCapture("beacon"); - else if (scan_mode == WIFI_SCAN_WAR_DRIVE) { - #ifdef HAS_GPS - if (gps_obj.getGpsModuleStatus()) { - sd_obj.openLog("wardrive"); - String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); - } - #endif - } - #else - return; - #endif + if (scan_mode == WIFI_SCAN_AP) + startPcap("beacon"); + else if (scan_mode == WIFI_SCAN_WAR_DRIVE) { + #ifdef HAS_GPS + if (gps_obj.getGpsModuleStatus()) { + startLog("wardrive"); + String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; + buffer_obj.logAdd(header_line); + } else { + return; + } + #else + return; + #endif + } #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -1912,13 +1908,7 @@ void WiFiScan::startWardriverWiFi() { void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("station"); - #else - return; - #endif + startPcap("station"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -1961,14 +1951,8 @@ void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color) void WiFiScan::RunRawScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - if (scan_mode != WIFI_SCAN_SIG_STREN) - sd_obj.openCapture("raw"); - #else - return; - #endif + if (scan_mode != WIFI_SCAN_SIG_STREN) + startPcap("raw"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -2014,13 +1998,7 @@ void WiFiScan::RunRawScan(uint8_t scan_mode, uint16_t color) void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - sd_obj.openCapture("deauth"); - #else - return; - #endif + startPcap("deauth"); #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -2065,23 +2043,21 @@ void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color) // Function for running probe request scan void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - if (scan_mode == WIFI_SCAN_PROBE) - sd_obj.openCapture("probe"); - else if (scan_mode == WIFI_SCAN_STATION_WAR_DRIVE) { - #ifdef HAS_GPS - if (gps_obj.getGpsModuleStatus()) { - sd_obj.openLog("station_wardrive"); - String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); - } - #endif - } - #else - return; - #endif + if (scan_mode == WIFI_SCAN_PROBE) + startPcap("probe"); + else if (scan_mode == WIFI_SCAN_STATION_WAR_DRIVE) { + #ifdef HAS_GPS + if (gps_obj.getGpsModuleStatus()) { + startLog("station_wardrive"); + String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; + buffer_obj.logAdd(header_line); + } else { + return; + } + #else + return; + #endif + } #ifdef MARAUDER_FLIPPER flipper_led.sniffLED(); @@ -2212,25 +2188,19 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color) pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false); } else if ((scan_mode == BT_SCAN_WAR_DRIVE) || (scan_mode == BT_SCAN_WAR_DRIVE_CONT)) { - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.open(); - #elif defined(HAS_SD) - #ifdef HAS_GPS - if (gps_obj.getGpsModuleStatus()) { - if (scan_mode == BT_SCAN_WAR_DRIVE) { - #ifdef HAS_SD - sd_obj.openLog("bt_wardrive"); - #endif - } - else if (scan_mode == BT_SCAN_WAR_DRIVE_CONT) { - #ifdef HAS_SD - sd_obj.openLog("bt_wardrive_cont"); - #endif - } - String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); + #ifdef HAS_GPS + if (gps_obj.getGpsModuleStatus()) { + if (scan_mode == BT_SCAN_WAR_DRIVE) { + startLog("bt_wardrive"); } - #endif + else if (scan_mode == BT_SCAN_WAR_DRIVE_CONT) { + startLog("bt_wardrive_cont"); + } + String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; + buffer_obj.logAdd(header_line); + } else { + return; + } #else return; #endif diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index 4990f21ec..6a50091a5 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -389,7 +389,10 @@ class WiFiScan void StartScan(uint8_t scan_mode, uint16_t color = 0); void StopScan(uint8_t scan_mode); const char* generateRandomName(); - + + void startPcap(String file_name); + void startLog(String file_name); + static void getMAC(char *addr, uint8_t* data, uint16_t offset); static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); From 2004a9ecb4e90a667300d991c5d6881befa64b0d Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:43:55 +0100 Subject: [PATCH 05/11] Sd+Serial save() in buffer_obj / out of sd_obj --- esp32_marauder/Buffer.cpp | 95 +++++-------------------------- esp32_marauder/Buffer.h | 6 +- esp32_marauder/SDInterface.cpp | 6 +- esp32_marauder/SDInterface.h | 1 - esp32_marauder/esp32_marauder.ino | 10 ++-- 5 files changed, 24 insertions(+), 94 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 0e4700110..9e1fe2e19 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -153,126 +153,61 @@ void Buffer::write(const uint8_t* buf, uint32_t len){ } } -void Buffer::save(fs::FS* fs){ - if(saving) return; // makes sure the function isn't called simultaneously on different cores - - // buffers are already emptied, therefor saving is unecessary - if((useA && bufSizeB == 0) || (!useA && bufSizeA == 0)){ - //Serial.printf("useA: %s, bufA %u, bufB %u\n",useA ? "true" : "false",bufSizeA,bufSizeB); // for debug porpuses - return; - } - - //Serial.println("saving file"); - - uint32_t startTime = millis(); - uint32_t finishTime; - - file = fs->open(fileName, FILE_APPEND); - if (!file) { - Serial.println(text02 + fileName+"'"); - //useSD = false; - return; - } - - saving = true; - - uint32_t len; - - if(useA){ - file.write(bufB, bufSizeB); - len = bufSizeB; - bufSizeB = 0; - } - else{ - file.write(bufA, bufSizeA); - len = bufSizeA; - bufSizeA = 0; - } - - file.close(); - - finishTime = millis() - startTime; - - //Serial.printf("\n%u bytes written for %u ms\n", len, finishTime); - - saving = false; - -} - -void Buffer::forceSave(fs::FS* fs){ - uint32_t len = bufSizeA + bufSizeB; - if(len == 0) return; - +void Buffer::saveFs(){ file = fs->open(fileName, FILE_APPEND); if (!file) { Serial.println(text02+fileName+"'"); - //useSD = false; return; } - saving = true; - writing = false; - if(useA){ - if(bufSizeB > 0){ file.write(bufB, bufSizeB); - bufSizeB = 0; } - if(bufSizeA > 0){ file.write(bufA, bufSizeA); - bufSizeA = 0; } - } else { - if(bufSizeA > 0){ file.write(bufA, bufSizeA); - bufSizeA = 0; } - if(bufSizeB > 0){ file.write(bufB, bufSizeB); - bufSizeB = 0; } - } file.close(); - - //Serial.printf("saved %u bytes\n",len); - - saving = false; - writing = true; } -void Buffer::forceSaveSerial() { - uint32_t len = bufSizeA + bufSizeB; - if(len == 0) return; - - saving = true; - writing = false; - +void Buffer::saveSerial() { if(useA){ if(bufSizeB > 0){ Serial1.write(bufB, bufSizeB); - bufSizeB = 0; } if(bufSizeA > 0){ Serial1.write(bufA, bufSizeA); - bufSizeA = 0; } } else { if(bufSizeA > 0){ Serial1.write(bufA, bufSizeA); - bufSizeA = 0; } if(bufSizeB > 0){ Serial1.write(bufB, bufSizeB); - bufSizeB = 0; } } +} + +void Buffer::save() { + if((bufSizeA + bufSizeB) == 0) return; + + saving = true; + writing = false; + + if(this->fs) saveFs(); + if(this->serial) saveSerial(); + + bufSizeA = 0; + bufSizeB = 0; saving = false; writing = true; diff --git a/esp32_marauder/Buffer.h b/esp32_marauder/Buffer.h index 6fb14fcf1..cda7a9d7c 100644 --- a/esp32_marauder/Buffer.h +++ b/esp32_marauder/Buffer.h @@ -22,9 +22,7 @@ class Buffer { void logOpen(String file_name, fs::FS* fs, bool serial); void pcapAdd(wifi_promiscuous_pkt_t *packet, int len); void logAdd(String log); - void save(fs::FS* fs); - void forceSave(fs::FS* fs); - void forceSaveSerial(); + void save(); private: void createFile(String name, bool is_pcap); void open(bool is_pcap); @@ -34,6 +32,8 @@ class Buffer { void write(uint32_t n); void write(uint16_t n); void write(const uint8_t* buf, uint32_t len); + void saveFs(); + void saveSerial(); uint8_t* bufA; uint8_t* bufB; diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 6b1fdc66a..37c18bb72 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -276,11 +276,7 @@ bool SDInterface::checkDetectPin() { } void SDInterface::main() { - if (this->supported) { - //Serial.println("Saving packet..."); - buffer_obj.forceSave(&SD); - } - else { + if (!this->supported) { if (checkDetectPin()) { delay(100); this->initSD(); diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index f2655fac1..4bb3b7530 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -46,7 +46,6 @@ class SDInterface { void runUpdate(); void performUpdate(Stream &updateSource, size_t updateSize); void main(); - //void savePacket(uint8_t* buf, uint32_t len); }; #endif diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index 4c0edb59a..65d111583 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -418,14 +418,14 @@ void loop() gps_obj.main(); #endif - #ifdef WRITE_PACKETS_SERIAL - buffer_obj.forceSaveSerial(); - #elif defined(HAS_SD) + // Detect SD card + #if defined(HAS_SD) sd_obj.main(); - #else - return; #endif + // Save buffer to SD and/or serial + buffer_obj.save(); + #ifdef HAS_BATTERY battery_obj.main(currentTime); //temp_obj.main(currentTime); From e560a888c30fcbc3ca79c0794231fdf2bac65612 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:47:35 +0100 Subject: [PATCH 06/11] Buffer state and concurrency improvements --- esp32_marauder/Buffer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 9e1fe2e19..f53d8312f 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -51,6 +51,7 @@ void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) { if (!save_pcap) { this->fs = NULL; this->serial = false; + writing = false; return; } this->fs = fs; @@ -143,6 +144,7 @@ void Buffer::write(uint16_t n){ void Buffer::write(const uint8_t* buf, uint32_t len){ if(!writing) return; + while(saving) delay(10); if(useA){ memcpy(&bufA[bufSizeA], buf, len); @@ -198,10 +200,12 @@ void Buffer::saveSerial() { } void Buffer::save() { - if((bufSizeA + bufSizeB) == 0) return; - saving = true; - writing = false; + + if((bufSizeA + bufSizeB) == 0){ + saving = false; + return; + } if(this->fs) saveFs(); if(this->serial) saveSerial(); @@ -210,5 +214,4 @@ void Buffer::save() { bufSizeB = 0; saving = false; - writing = true; } From bddc7e1d9d44f785bb1c39b90ab49242de390410 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 18:52:30 +0100 Subject: [PATCH 07/11] Send PCAP buffer on main UART console --- esp32_marauder/Buffer.cpp | 31 +++++++- esp32_marauder/CommandLine.cpp | 26 +++---- esp32_marauder/EvilPortal.cpp | 118 ++++++++++++++---------------- esp32_marauder/EvilPortal.h | 11 +-- esp32_marauder/GpsInterface.cpp | 12 +-- esp32_marauder/MenuFunctions.cpp | 30 +++----- esp32_marauder/WiFiScan.cpp | 5 +- esp32_marauder/configs.h | 43 +---------- esp32_marauder/esp32_marauder.ino | 11 --- 9 files changed, 114 insertions(+), 173 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index f53d8312f..6ff725118 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -182,21 +182,44 @@ void Buffer::saveFs(){ } void Buffer::saveSerial() { + // Saves to main console UART, user-facing app will ignore these markers + // Uses / and ] in markers as they are illegal characters for SSIDs + const char* mark_begin = "[BUF/BEGIN]"; + const size_t mark_begin_len = strlen(mark_begin); + const char* mark_close = "[BUF/CLOSE]"; + const size_t mark_close_len = strlen(mark_close); + + // Additional buffer and memcpy's so that a single Serial.write() is called + // This is necessary so that other console output isn't mixed into buffer stream + uint8_t* buf = (uint8_t*)malloc(mark_begin_len + bufSizeA + bufSizeB + mark_close_len); + uint8_t* it = buf; + memcpy(it, mark_begin, mark_begin_len); + it += mark_begin_len; + if(useA){ if(bufSizeB > 0){ - Serial1.write(bufB, bufSizeB); + memcpy(it, bufB, bufSizeB); + it += bufSizeB; } if(bufSizeA > 0){ - Serial1.write(bufA, bufSizeA); + memcpy(it, bufA, bufSizeA); + it += bufSizeA; } } else { if(bufSizeA > 0){ - Serial1.write(bufA, bufSizeA); + memcpy(it, bufA, bufSizeA); + it += bufSizeA; } if(bufSizeB > 0){ - Serial1.write(bufB, bufSizeB); + memcpy(it, bufB, bufSizeB); + it += bufSizeB; } } + + memcpy(it, mark_close, mark_close_len); + it += mark_close_len; + Serial.write(buf, it - buf); + free(buf); } void Buffer::save() { diff --git a/esp32_marauder/CommandLine.cpp b/esp32_marauder/CommandLine.cpp index 094bb7559..196654bf8 100644 --- a/esp32_marauder/CommandLine.cpp +++ b/esp32_marauder/CommandLine.cpp @@ -1035,21 +1035,17 @@ void CommandLine::runCommand(String input) { //} // Update via SD if (sd_sw != -1) { - #ifdef HAS_SD - #ifndef WRITE_PACKETS_SERIAL - if (!sd_obj.supported) { - Serial.println("SD card is not connected. Cannot perform SD Update"); - return; - } - wifi_scan_obj.currentScanMode = OTA_UPDATE; - sd_obj.runUpdate(); - #else - Serial.println("SD card not initialized. Cannot perform SD Update"); - #endif - #else - Serial.println("SD card support disabled. Cannot perform SD Update"); - return; - #endif + #ifdef HAS_SD + if (!sd_obj.supported) { + Serial.println("SD card is not connected. Cannot perform SD Update"); + return; + } + wifi_scan_obj.currentScanMode = OTA_UPDATE; + sd_obj.runUpdate(); + #else + Serial.println("SD card support disabled. Cannot perform SD Update"); + return; + #endif } } } diff --git a/esp32_marauder/EvilPortal.cpp b/esp32_marauder/EvilPortal.cpp index 778b9025a..cf581f15c 100644 --- a/esp32_marauder/EvilPortal.cpp +++ b/esp32_marauder/EvilPortal.cpp @@ -92,41 +92,37 @@ bool EvilPortal::setHtml() { return true; } Serial.println("Setting HTML..."); - #ifndef WRITE_PACKETS_SERIAL - File html_file = sd_obj.getFile("/" + this->target_html_name); - if (!html_file) { + File html_file = sd_obj.getFile("/" + this->target_html_name); + if (!html_file) { + #ifdef HAS_SCREEN + this->sendToDisplay("Could not find /" + this->target_html_name); + this->sendToDisplay("Touch to exit..."); + #endif + Serial.println("Could not find /" + this->target_html_name + ". Use stopscan..."); + return false; + } + else { + if (html_file.size() > MAX_HTML_SIZE) { #ifdef HAS_SCREEN - this->sendToDisplay("Could not find /" + this->target_html_name); + this->sendToDisplay("The given HTML is too large."); + this->sendToDisplay("The Byte limit is " + (String)MAX_HTML_SIZE); this->sendToDisplay("Touch to exit..."); #endif - Serial.println("Could not find /" + this->target_html_name + ". Use stopscan..."); + Serial.println("The provided HTML is too large. Byte limit is " + (String)MAX_HTML_SIZE + "\nUse stopscan..."); return false; } - else { - if (html_file.size() > MAX_HTML_SIZE) { - #ifdef HAS_SCREEN - this->sendToDisplay("The given HTML is too large."); - this->sendToDisplay("The Byte limit is " + (String)MAX_HTML_SIZE); - this->sendToDisplay("Touch to exit..."); - #endif - Serial.println("The provided HTML is too large. Byte limit is " + (String)MAX_HTML_SIZE + "\nUse stopscan..."); - return false; - } - String html = ""; - while (html_file.available()) { - char c = html_file.read(); - if (isPrintable(c)) - html.concat(c); - } - strncpy(index_html, html.c_str(), strlen(html.c_str())); - this->has_html = true; - Serial.println("html set"); - html_file.close(); - return true; + String html = ""; + while (html_file.available()) { + char c = html_file.read(); + if (isPrintable(c)) + html.concat(c); } - #else - return false; - #endif + strncpy(index_html, html.c_str(), strlen(html.c_str())); + this->has_html = true; + Serial.println("html set"); + html_file.close(); + return true; + } } @@ -143,47 +139,43 @@ bool EvilPortal::setAP(LinkedList* ssids, LinkedList* access_ // If there are no SSIDs and there are no APs selected, pull from file // This means the file is last resort if ((ssids->size() <= 0) && (temp_ap_name == "")) { - #ifndef WRITE_PACKETS_SERIAL - File ap_config_file = sd_obj.getFile("/ap.config.txt"); - // Could not open config file. return false - if (!ap_config_file) { + File ap_config_file = sd_obj.getFile("/ap.config.txt"); + // Could not open config file. return false + if (!ap_config_file) { + #ifdef HAS_SCREEN + this->sendToDisplay("Could not find /ap.config.txt."); + this->sendToDisplay("Touch to exit..."); + #endif + Serial.println("Could not find /ap.config.txt. Use stopscan..."); + return false; + } + // Config file good. Proceed + else { + // ap name too long. return false + if (ap_config_file.size() > MAX_AP_NAME_SIZE) { #ifdef HAS_SCREEN - this->sendToDisplay("Could not find /ap.config.txt."); + this->sendToDisplay("The given AP name is too large."); + this->sendToDisplay("The Byte limit is " + (String)MAX_AP_NAME_SIZE); this->sendToDisplay("Touch to exit..."); #endif - Serial.println("Could not find /ap.config.txt. Use stopscan..."); + Serial.println("The provided AP name is too large. Byte limit is " + (String)MAX_AP_NAME_SIZE + "\nUse stopscan..."); return false; } - // Config file good. Proceed - else { - // ap name too long. return false - if (ap_config_file.size() > MAX_AP_NAME_SIZE) { - #ifdef HAS_SCREEN - this->sendToDisplay("The given AP name is too large."); - this->sendToDisplay("The Byte limit is " + (String)MAX_AP_NAME_SIZE); - this->sendToDisplay("Touch to exit..."); - #endif - Serial.println("The provided AP name is too large. Byte limit is " + (String)MAX_AP_NAME_SIZE + "\nUse stopscan..."); - return false; - } - // AP name length good. Read from file into var - while (ap_config_file.available()) { - char c = ap_config_file.read(); - Serial.print(c); - if (isPrintable(c)) { - ap_config.concat(c); - } + // AP name length good. Read from file into var + while (ap_config_file.available()) { + char c = ap_config_file.read(); + Serial.print(c); + if (isPrintable(c)) { + ap_config.concat(c); } - #ifdef HAS_SCREEN - this->sendToDisplay("AP name from config file"); - this->sendToDisplay("AP name: " + ap_config); - #endif - Serial.println("AP name from config file: " + ap_config); - ap_config_file.close(); } - #else - return false; - #endif + #ifdef HAS_SCREEN + this->sendToDisplay("AP name from config file"); + this->sendToDisplay("AP name: " + ap_config); + #endif + Serial.println("AP name from config file: " + ap_config); + ap_config_file.close(); + } } // There are SSIDs in the list but there could also be an AP selected // Priority is SSID list before AP selected and config file diff --git a/esp32_marauder/EvilPortal.h b/esp32_marauder/EvilPortal.h index f3c36ed61..4e5635ade 100644 --- a/esp32_marauder/EvilPortal.h +++ b/esp32_marauder/EvilPortal.h @@ -13,17 +13,12 @@ #include "Display.h" #include #endif -#ifndef WRITE_PACKETS_SERIAL - #include "SDInterface.h" -#else - #include "Buffer.h" -#endif +#include "SDInterface.h" +#include "Buffer.h" #include "lang_var.h" extern Settings settings_obj; -#ifndef WRITE_PACKETS_SERIAL - extern SDInterface sd_obj; -#endif +extern SDInterface sd_obj; #ifdef HAS_SCREEN extern Display display_obj; #endif diff --git a/esp32_marauder/GpsInterface.cpp b/esp32_marauder/GpsInterface.cpp index 5a87a5c31..b1d777c35 100644 --- a/esp32_marauder/GpsInterface.cpp +++ b/esp32_marauder/GpsInterface.cpp @@ -8,19 +8,11 @@ char nmeaBuffer[100]; MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); -#ifndef GPS_SOFTWARE_SERIAL - HardwareSerial Serial2(GPS_SERIAL_INDEX); -#else - EspSoftwareSerial::UART Serial2; -#endif +HardwareSerial Serial2(GPS_SERIAL_INDEX); void GpsInterface::begin() { - #ifndef GPS_SOFTWARE_SERIAL - Serial2.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX); - #else - Serial2.begin(9600, SWSERIAL_8N1, GPS_TX, GPS_RX); - #endif + Serial2.begin(9600, SERIAL_8N1, GPS_TX, GPS_RX); MicroNMEA::sendSentence(Serial2, "$PSTMSETPAR,1201,0x00000042"); MicroNMEA::sendSentence(Serial2, "$PSTMSAVEPAR"); diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index d9739c33e..6459763c7 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -991,14 +991,10 @@ void MenuFunctions::updateStatusBar() // Draw SD info - #ifndef WRITE_PACKETS_SERIAL - if (sd_obj.supported) - the_color = TFT_GREEN; - else - the_color = TFT_RED; - #else + if (sd_obj.supported) + the_color = TFT_GREEN; + else the_color = TFT_RED; - #endif #ifdef HAS_ILI9341 display_obj.tft.drawXBitmap(170, @@ -1080,14 +1076,10 @@ void MenuFunctions::drawStatusBar() MenuFunctions::battery2(true); // Draw SD info - #ifndef WRITE_PACKETS_SERIAL - if (sd_obj.supported) - the_color = TFT_GREEN; - else - the_color = TFT_RED; - #else + if (sd_obj.supported) + the_color = TFT_GREEN; + else the_color = TFT_RED; - #endif #ifdef HAS_ILI9341 display_obj.tft.drawXBitmap(170, @@ -1721,12 +1713,10 @@ void MenuFunctions::RunSetup() wifi_scan_obj.currentScanMode = WIFI_SCAN_OFF; this->changeMenu(whichUpdateMenu.parentMenu); }); - #ifndef WRITE_PACKETS_SERIAL - if (sd_obj.supported) addNodes(&whichUpdateMenu, text_table1[40], TFT_MAGENTA, NULL, SD_UPDATE, [this]() { - wifi_scan_obj.currentScanMode = OTA_UPDATE; - this->changeMenu(&confirmMenu); - }); - #endif + if (sd_obj.supported) addNodes(&whichUpdateMenu, text_table1[40], TFT_MAGENTA, NULL, SD_UPDATE, [this]() { + wifi_scan_obj.currentScanMode = OTA_UPDATE; + this->changeMenu(&confirmMenu); + }); // Confirm SD update menu confirmMenu.parentMenu = &whichUpdateMenu; diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 6328809c5..af8a85e85 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -1398,7 +1398,8 @@ void WiFiScan::RunInfo() #ifdef HAS_SCREEN display_obj.tft.println(text_table4[48]); #endif - #elif defined(HAS_SD) + #endif + #if defined(HAS_SD) if (sd_obj.supported) { #ifdef HAS_SCREEN display_obj.tft.println(text_table4[28]); @@ -1412,8 +1413,6 @@ void WiFiScan::RunInfo() display_obj.tft.println(text_table4[31]); #endif } - #else - return; #endif #ifdef HAS_BATTERY diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index e6acbd375..22059ef26 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -147,10 +147,8 @@ //#define HAS_PWR_MGMT //#define HAS_SCREEN #define HAS_GPS - #ifndef WRITE_PACKETS_SERIAL - #define HAS_SD - #define USE_SD - #endif + #define HAS_SD + #define USE_SD //#define HAS_TEMP_SENSOR #endif @@ -196,20 +194,6 @@ #endif //// END BOARD FEATURES - //// FLIPPER ZERO HAT SETTINGS - #ifdef FLIPPER_ZERO_HAT - - //#ifdef MARAUDER_FLIPPER - // #define USE_FLIPPER_SD - //#endif - - #ifdef XIAO_ESP32_S3 - #define USE_FLIPPER_SD - #endif - - #endif - //// END FLIPPER ZERO HAT SETTINGS - //// POWER MANAGEMENT #ifdef HAS_PWR_MGMT #ifdef MARAUDER_M5STICKC @@ -667,13 +651,7 @@ //// END MENU DEFINITIONS //// SD DEFINITIONS - #ifdef FLIPPER_ZERO_HAT - - #ifdef USE_FLIPPER_SD - #define WRITE_PACKETS_SERIAL - #endif - - #elif defined(USE_SD) + #if defined(USE_SD) #ifdef MARAUDER_V4 #define SD_CS 12 @@ -783,15 +761,6 @@ #endif //// END NEOPIXEL STUFF - //// BOARD PIN OVERRIDES - #ifdef XIAO_ESP32_S3 - #ifdef USE_FLIPPER_SD - #define XIAO_RX1 1 - #define XIAO_TX1 2 - #endif - #endif - //// END BOARD PIN OVERRIDES - //// EVIL PORTAL STUFF #ifdef MARAUDER_M5STICKC #define MAX_HTML_SIZE 11400 @@ -846,11 +815,7 @@ #define GPS_RX 22 #define mac_history_len 512 #elif defined(MARAUDER_FLIPPER) - #ifdef WRITE_PACKETS_SERIAL - #define GPS_SOFTWARE_SERIAL - #else - #define GPS_SERIAL_INDEX 1 - #endif + #define GPS_SERIAL_INDEX 1 #define GPS_TX 9 #define GPS_RX 21 #define mac_history_len 512 diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index 65d111583..3f17fe52e 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -198,17 +198,6 @@ void setup() Serial.begin(115200); - // Starts a second serial channel to stream the captured packets - #ifdef WRITE_PACKETS_SERIAL - - #ifdef XIAO_ESP32_S3 - Serial1.begin(115200, SERIAL_8N1, XIAO_RX1, XIAO_TX1); - #else - Serial1.begin(115200); - #endif - - #endif - //Serial.println("\n\nHello, World!\n"); Serial.println("ESP-IDF version is: " + String(esp_get_idf_version())); From 558fe18d66481fabd7407d87ed9a7c1db933b9fe Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Sun, 31 Dec 2023 19:54:55 +0100 Subject: [PATCH 08/11] Enable serial PCAP with CLI option --- .github/workflows/build_push.yml | 40 -------------------------------- esp32_marauder/CommandLine.cpp | 6 ++--- esp32_marauder/WiFiScan.cpp | 19 ++------------- esp32_marauder/WiFiScan.h | 1 + esp32_marauder/configs.h | 4 ---- esp32_marauder/lang_var.h | 3 +-- 6 files changed, 7 insertions(+), 66 deletions(-) diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml index 7d4098001..b738ef33d 100644 --- a/.github/workflows/build_push.yml +++ b/.github/workflows/build_push.yml @@ -205,27 +205,6 @@ jobs: run: | mv ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.ino.bin ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.flipper.bin - - name: Configure SD Serial for Flipper Zero SD Serial - run: | - pwd - sed -i 's/^ \/\/#define WRITE_PACKETS_SERIAL/ #define WRITE_PACKETS_SERIAL/' esp32_marauder/configs.h - - - name: Build Marauder SD Serial for Flipper Zero WiFi Dev Board - uses: ArminJo/arduino-test-compile@v3.2.1 - with: - sketch-names: esp32_marauder.ino - arduino-board-fqbn: esp32:esp32:esp32s2:PartitionScheme=min_spiffs,FlashSize=4M,PSRAM=enabled - extra-arduino-cli-args: "--warnings none" - - - name: Rename Marauder Flipper SD Serial bin - run: | - mv ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.ino.bin ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.flipper_sd_serial.bin - - - name: Remove SD Serial - run: | - pwd - sed -i 's/^ #define WRITE_PACKETS_SERIAL/ \/\/#define WRITE_PACKETS_SERIAL/' esp32_marauder/configs.h - - name: Build Marauder for Flipper Zero Multi Board uses: ArminJo/arduino-test-compile@v3.2.1 with: @@ -464,13 +443,6 @@ jobs: path: ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.flipper.bin retention-days: 5 - - name: 'Upload Flipper SD Serial Artifact' - uses: actions/upload-artifact@v3 - with: - name: esp32_marauder.flipper_sd_serial.bin - path: ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.flipper_sd_serial.bin - retention-days: 5 - - name: 'Upload MultiboardS3 Artifact' uses: actions/upload-artifact@v3 with: @@ -558,18 +530,6 @@ jobs: asset_content_type: application/bin if: github.event_name != 'pull_request' - - name: Upload Flipper SD Serial Asset - id: upload-flipper-sd-serial-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./esp32_marauder/build/esp32.esp32.esp32s2/esp32_marauder.flipper_sd_serial.bin - asset_name: esp32_marauder.flipper_sd_serial.bin - asset_content_type: application/bin - if: github.event_name != 'pull_request' - - name: Upload MultiboardS3 Asset id: upload-multiboardS3-release-asset uses: actions/upload-release-asset@v1 diff --git a/esp32_marauder/CommandLine.cpp b/esp32_marauder/CommandLine.cpp index 196654bf8..d9337d845 100644 --- a/esp32_marauder/CommandLine.cpp +++ b/esp32_marauder/CommandLine.cpp @@ -9,9 +9,6 @@ void CommandLine::RunSetup() { Serial.println(F("\n\n--------------------------------\n")); Serial.println(F(" ESP32 Marauder \n")); Serial.println(" " + version_number + "\n"); - #ifdef WRITE_PACKETS_SERIAL - Serial.println(F(" >> Serial \n")); - #endif Serial.println(F(" By: justcallmekoko\n")); Serial.println(F("--------------------------------\n\n")); @@ -508,6 +505,9 @@ void CommandLine::runCommand(String input) { //// WiFi/Bluetooth Scan/Attack commands if (!wifi_scan_obj.scanning()) { + // Dump pcap/log to serial too, valid for all scan/attack commands + wifi_scan_obj.save_serial = this->argSearch(&cmd_args, "-serial") != -1; + // Signal strength scan if (cmd_args.get(0) == SIGSTREN_CMD) { Serial.println("Starting Signal Strength Scan. Stop with " + (String)STOPSCAN_CMD); diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index af8a85e85..a0d71187c 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -937,12 +937,7 @@ void WiFiScan::startPcap(String file_name) { sd_obj.supported ? &SD : #endif NULL, - // TODO: make commandline options - #ifdef WRITE_PACKETS_SERIAL - true - #else - false - #endif + save_serial // Set with commandline options ); } @@ -953,12 +948,7 @@ void WiFiScan::startLog(String file_name) { sd_obj.supported ? &SD : #endif NULL, - // TODO: make commandline options - #ifdef WRITE_PACKETS_SERIAL - true - #else - false - #endif + save_serial // Set with commandline options ); } @@ -1394,11 +1384,6 @@ void WiFiScan::RunInfo() display_obj.tft.println(text_table4[27] + free_ram); #endif - #ifdef WRITE_PACKETS_SERIAL - #ifdef HAS_SCREEN - display_obj.tft.println(text_table4[48]); - #endif - #endif #if defined(HAS_SD) if (sd_obj.supported) { #ifdef HAS_SCREEN diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index 6a50091a5..4abed74f8 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -390,6 +390,7 @@ class WiFiScan void StopScan(uint8_t scan_mode); const char* generateRandomName(); + bool save_serial = false; void startPcap(String file_name); void startLog(String file_name); diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index 22059ef26..9f8f87632 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -6,10 +6,6 @@ #define POLISH_POTATO - //Indicates that it must redirect the stream with the captured packets to serial (1) - //If not defined, will write packages to SD card if supported - //#define WRITE_PACKETS_SERIAL - //// BOARD TARGETS //#define MARAUDER_M5STICKC //#define MARAUDER_MINI diff --git a/esp32_marauder/lang_var.h b/esp32_marauder/lang_var.h index a166b3b79..3b4ffc325 100644 --- a/esp32_marauder/lang_var.h +++ b/esp32_marauder/lang_var.h @@ -179,13 +179,12 @@ PROGMEM const char text4_44[] = " AP Scan "; PROGMEM const char text4_45[] = "Clearing Stations..."; PROGMEM const char text4_46[] = "Stations Cleared: "; PROGMEM const char text4_47[] = "Targeted Deauth"; -PROGMEM const char text4_48[] = "Using serial to transmit packets"; //Making tables PROGMEM const char *text_table0[] = {text0_0,text0_1, text0_2, text0_3, text0_4, text0_5, text0_6, text0_7, text0_8}; PROGMEM const char *text_table1[] = {text1_0,text1_1,text1_2,text1_3,text1_4,text1_5,text1_6,text1_7,text1_8,text1_9,text1_10,text1_11,text1_12,text1_13,text1_14,text1_15,text1_16,text1_17,text1_18,text1_19,text1_20,text1_21,text1_22,text1_23,text1_24,text1_25,text1_26,text1_27,text1_28,text1_29,text1_30,text1_31,text1_32,text1_33,text1_34,text1_35,text1_36,text1_37,text1_38,text1_39,text1_40,text1_41,text1_42,text1_43,text1_44,text1_45,text1_46,text1_47,text1_48,text1_49,text1_50,text1_51,text1_52,text1_53,text1_54,text1_55,text1_56,text1_57,text1_58,text1_59,text1_60,text1_61,text1_62}; PROGMEM const char *text_table2[] = {text2_0,text2_1,text2_2,text2_3,text2_4,text2_5,text2_6,text2_7,text2_8,text2_9,text2_10,text2_11,text2_12,text2_13,text2_14}; PROGMEM const char *text_table3[] = {text3_0,text3_1,text3_2,text3_3,text3_4,text3_5}; -PROGMEM const char *text_table4[] = {text4_0,text4_1,text4_2,text4_3,text4_4,text4_5,text4_6,text4_7,text1_54,text4_9,text4_10,text4_11,text4_12,text4_13,text4_14,text4_15,text4_16,text4_17,text4_18,text4_19,text4_20,text4_21,text4_22,text4_23,text4_24,text4_25,text4_26,text4_27,text4_28,text4_29,text4_30,text4_31,text4_32,text4_33,text4_34,text4_35,text4_36,text4_37,text4_38,text4_39,text4_40,text4_41,text4_42,text4_43,text4_44,text4_45,text4_46,text4_47, text4_48}; +PROGMEM const char *text_table4[] = {text4_0,text4_1,text4_2,text4_3,text4_4,text4_5,text4_6,text4_7,text1_54,text4_9,text4_10,text4_11,text4_12,text4_13,text4_14,text4_15,text4_16,text4_17,text4_18,text4_19,text4_20,text4_21,text4_22,text4_23,text4_24,text4_25,text4_26,text4_27,text4_28,text4_29,text4_30,text4_31,text4_32,text4_33,text4_34,text4_35,text4_36,text4_37,text4_38,text4_39,text4_40,text4_41,text4_42,text4_43,text4_44,text4_45,text4_46,text4_47}; #endif From 9d92c5ceb5d42b26937e326a046b56c511e0fea6 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:02:55 +0000 Subject: [PATCH 09/11] Single buffer_obj.append() with overloads --- esp32_marauder/Buffer.cpp | 4 ++-- esp32_marauder/Buffer.h | 4 ++-- esp32_marauder/EvilPortal.cpp | 2 +- esp32_marauder/WiFiScan.cpp | 38 +++++++++++++++++------------------ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 6ff725118..5a0f0b64c 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -103,14 +103,14 @@ void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){ write(buf, len); // packet payload } -void Buffer::pcapAdd(wifi_promiscuous_pkt_t *packet, int len) { +void Buffer::append(wifi_promiscuous_pkt_t *packet, int len) { bool save_packet = settings_obj.loadSetting(text_table4[7]); if (save_packet) { add(packet->payload, len, true); } } -void Buffer::logAdd(String log) { +void Buffer::append(String log) { bool save_packet = settings_obj.loadSetting(text_table4[7]); if (save_packet) { add((const uint8_t*)log.c_str(), log.length(), false); diff --git a/esp32_marauder/Buffer.h b/esp32_marauder/Buffer.h index cda7a9d7c..b88badaa4 100644 --- a/esp32_marauder/Buffer.h +++ b/esp32_marauder/Buffer.h @@ -20,8 +20,8 @@ class Buffer { Buffer(); void pcapOpen(String file_name, fs::FS* fs, bool serial); void logOpen(String file_name, fs::FS* fs, bool serial); - void pcapAdd(wifi_promiscuous_pkt_t *packet, int len); - void logAdd(String log); + void append(wifi_promiscuous_pkt_t *packet, int len); + void append(String log); void save(); private: void createFile(String name, bool is_pcap); diff --git a/esp32_marauder/EvilPortal.cpp b/esp32_marauder/EvilPortal.cpp index cf581f15c..44fa7af68 100644 --- a/esp32_marauder/EvilPortal.cpp +++ b/esp32_marauder/EvilPortal.cpp @@ -290,7 +290,7 @@ void EvilPortal::main(uint8_t scan_mode) { String logValue2 = "p: " + this->password; String full_string = logValue1 + " " + logValue2 + "\n"; Serial.print(full_string); - buffer_obj.logAdd(full_string); + buffer_obj.append(full_string); #ifdef HAS_SCREEN this->sendToDisplay(full_string); #endif diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index a0d71187c..01f4831bf 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -242,7 +242,7 @@ extern "C" { Serial.print(wardrive_line); if (do_save) - buffer_obj.logAdd(wardrive_line); + buffer_obj.append(wardrive_line); } } #endif @@ -1804,7 +1804,7 @@ void WiFiScan::executeWarDrive() { Serial.print((String)this->mac_history_cursor + " | " + wardrive_line); if (do_save) { - buffer_obj.logAdd(wardrive_line); + buffer_obj.append(wardrive_line); } } } @@ -1826,7 +1826,7 @@ void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color) if (gps_obj.getGpsModuleStatus()) { startLog("wardrive"); String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); + buffer_obj.append(header_line); } else { return; } @@ -2034,7 +2034,7 @@ void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color) if (gps_obj.getGpsModuleStatus()) { startLog("station_wardrive"); String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); + buffer_obj.append(header_line); } else { return; } @@ -2181,7 +2181,7 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color) startLog("bt_wardrive_cont"); } String header_line = "WigleWifi-1.4,appRelease=" + (String)MARAUDER_VERSION + ",model=ESP32 Marauder,release=" + (String)MARAUDER_VERSION + ",device=ESP32 Marauder,display=SPI TFT,board=ESP32 Marauder,brand=JustCallMeKoko\nMAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type\n"; - buffer_obj.logAdd(header_line); + buffer_obj.append(header_line); } else { return; } @@ -2349,7 +2349,7 @@ void WiFiScan::pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } } @@ -2508,7 +2508,7 @@ void WiFiScan::apSnifferCallbackFull(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } } @@ -2634,7 +2634,7 @@ void WiFiScan::apSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } } @@ -2755,7 +2755,7 @@ void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_WAR_DRIVE) { #ifdef HAS_GPS @@ -2830,7 +2830,7 @@ void WiFiScan::beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type } String wardrive_line = (String)addr + "," + essid + "," + wifi_scan_obj.security_int_to_string(snifferPacket->rx_ctrl.channel) + "," + gps_obj.getDatetime() + "," + (String)snifferPacket->rx_ctrl.channel + "," + (String)snifferPacket->rx_ctrl.rssi + "," + gps_obj.getLat() + "," + gps_obj.getLon() + "," + gps_obj.getAlt() + "," + gps_obj.getAccuracy() + ",WIFI"; Serial.println(wardrive_line); - //buffer_obj.logAdd(wardrive_line); + //buffer_obj.append(wardrive_line); } } #endif @@ -2994,7 +2994,7 @@ void WiFiScan::stationSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t typ access_points->set(ap_index, ap); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -3095,7 +3095,7 @@ void WiFiScan::rawSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -3159,7 +3159,7 @@ void WiFiScan::deauthSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } } @@ -3231,7 +3231,7 @@ void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_STATION_WAR_DRIVE) { #ifdef HAS_GPS @@ -3286,7 +3286,7 @@ void WiFiScan::probeSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) if (do_save) { String wardrive_line = (String)addr + "," + (String)addr + ",," + gps_obj.getDatetime() + "," + (String)snifferPacket->rx_ctrl.channel + "," + (String)snifferPacket->rx_ctrl.rssi + "," + gps_obj.getLat() + "," + gps_obj.getLon() + "," + gps_obj.getAlt() + "," + gps_obj.getAccuracy() + ",WIFI"; Serial.println(wardrive_line); - buffer_obj.logAdd(wardrive_line); + buffer_obj.append(wardrive_line); } } #endif @@ -3377,7 +3377,7 @@ void WiFiScan::beaconListSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t Serial.println(); - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } } @@ -3838,7 +3838,7 @@ void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) #endif #endif - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } } @@ -3926,7 +3926,7 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) #endif } - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type) @@ -4012,7 +4012,7 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t } - buffer_obj.pcapAdd(snifferPacket, len); + buffer_obj.append(snifferPacket, len); } #ifdef HAS_SCREEN From 470f3f73c75142ccc2f1a6338e845c4f54842efc Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:03:20 +0000 Subject: [PATCH 10/11] Block writes when buffer is not open --- esp32_marauder/Buffer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esp32_marauder/Buffer.cpp b/esp32_marauder/Buffer.cpp index 5a0f0b64c..78a3cb929 100644 --- a/esp32_marauder/Buffer.cpp +++ b/esp32_marauder/Buffer.cpp @@ -61,6 +61,8 @@ void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) { } if (this->fs || this->serial) { open(is_pcap); + } else { + writing = false; } } From f5d07034321c0bed9abf7541b7b88d7d427e83d5 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 2 Jan 2024 12:34:05 +0000 Subject: [PATCH 11/11] Build on PR sync too --- .github/workflows/build_push.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml index b738ef33d..6a0017319 100644 --- a/.github/workflows/build_push.yml +++ b/.github/workflows/build_push.yml @@ -3,7 +3,6 @@ name: Build and Push on: workflow_dispatch: pull_request: - types: [opened, reopened] jobs: # This workflow contains a single job called "build"