Sd+Serial pcapOpen() and logOpen() in buffer_obj

This commit is contained in:
Willy-JL
2023-12-31 18:31:30 +01:00
parent f6c27ed216
commit c61aaf95cd
6 changed files with 124 additions and 147 deletions

View File

@@ -6,17 +6,17 @@ Buffer::Buffer(){
bufB = (uint8_t*)malloc(BUF_SIZE); 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; int i=0;
if (!log) { if (is_pcap) {
do{ do{
fileName = "/"+fn+"_"+(String)i+".pcap"; fileName = "/"+name+"_"+(String)i+".pcap";
i++; i++;
} while(fs->exists(fileName)); } while(fs->exists(fileName));
} }
else { else {
do{ do{
fileName = "/"+fn+"_"+(String)i+".log"; fileName = "/"+name+"_"+(String)i+".log";
i++; i++;
} while(fs->exists(fileName)); } while(fs->exists(fileName));
} }
@@ -27,7 +27,7 @@ void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){
file.close(); file.close();
} }
void Buffer::open(bool log){ void Buffer::open(bool is_pcap){
bufSizeA = 0; bufSizeA = 0;
bufSizeB = 0; bufSizeB = 0;
@@ -35,7 +35,7 @@ void Buffer::open(bool log){
writing = true; writing = true;
if (!log) { if (is_pcap) {
write(uint32_t(0xa1b2c3d4)); // magic number write(uint32_t(0xa1b2c3d4)); // magic number
write(uint16_t(2)); // major version number write(uint16_t(2)); // major version number
write(uint16_t(4)); // minor version number write(uint16_t(4)); // minor version number
@@ -46,11 +46,29 @@ void Buffer::open(bool log){
} }
} }
void Buffer::close(fs::FS* fs){ void Buffer::openFile(String file_name, fs::FS* fs, bool serial, bool is_pcap) {
if(!writing) return; bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP");
forceSave(fs); if (!save_pcap) {
writing = false; this->fs = NULL;
Serial.println(text01); 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){ void Buffer::add(const uint8_t* buf, uint32_t len, bool is_pcap){

View File

@@ -18,15 +18,17 @@ extern Settings settings_obj;
class Buffer { class Buffer {
public: public:
Buffer(); Buffer();
void createPcapFile(fs::FS* fs, String fn = "", bool log = false); void pcapOpen(String file_name, fs::FS* fs, bool serial);
void open(bool log = false); void logOpen(String file_name, fs::FS* fs, bool serial);
void close(fs::FS* fs);
void pcapAdd(wifi_promiscuous_pkt_t *packet, int len); void pcapAdd(wifi_promiscuous_pkt_t *packet, int len);
void logAdd(String log); void logAdd(String log);
void save(fs::FS* fs); void save(fs::FS* fs);
void forceSave(fs::FS* fs); void forceSave(fs::FS* fs);
void forceSaveSerial(); void forceSaveSerial();
private: 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 add(const uint8_t* buf, uint32_t len, bool is_pcap);
void write(int32_t n); void write(int32_t n);
void write(uint32_t n); void write(uint32_t n);
@@ -45,6 +47,8 @@ class Buffer {
String fileName = "/0.pcap"; String fileName = "/0.pcap";
File file; File file;
fs::FS* fs;
bool serial;
}; };
#endif #endif

View File

@@ -140,22 +140,6 @@ void SDInterface::listDir(String str_dir){
} }
} }
void SDInterface::openCapture(String file_name) {
bool save_pcap = settings_obj.loadSetting<bool>("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<bool>("SavePCAP");
if ((this->supported) && (save_pcap)) {
buffer_obj.createPcapFile(&SD, file_name, true);
buffer_obj.open(true);
}
}
void SDInterface::runUpdate() { void SDInterface::runUpdate() {
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.setTextWrap(false); display_obj.tft.setTextWrap(false);

View File

@@ -43,8 +43,6 @@ class SDInterface {
void listDir(String str_dir); void listDir(String str_dir);
void listDirToLinkedList(LinkedList<String>* file_names, String str_dir = "/", String ext = ""); void listDirToLinkedList(LinkedList<String>* file_names, String str_dir = "/", String ext = "");
File getFile(String path); File getFile(String path);
void openCapture(String file_name = "");
void openLog(String file_name = "");
void runUpdate(); void runUpdate();
void performUpdate(Stream &updateSource, size_t updateSize); void performUpdate(Stream &updateSource, size_t updateSize);
void main(); void main();

View File

@@ -930,15 +930,41 @@ String WiFiScan::freeRAM()
return String(s); 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) void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL startLog("evil_portal");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openLog("evil_portal");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -981,13 +1007,7 @@ void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color)
// Function to start running a beacon scan // Function to start running a beacon scan
void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color) void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL startPcap("ap");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("ap");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -1428,13 +1448,7 @@ void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
led_obj.setMode(MODE_SNIFF); led_obj.setMode(MODE_SNIFF);
#endif #endif
#ifdef WRITE_PACKETS_SERIAL startPcap("packet_monitor");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("packet_monitor");
#else
return;
#endif
#ifdef HAS_ILI9341 #ifdef HAS_ILI9341
@@ -1522,11 +1536,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
display_obj.tft.fillScreen(TFT_BLACK); display_obj.tft.fillScreen(TFT_BLACK);
#endif #endif
#ifdef WRITE_PACKETS_SERIAL startPcap("eapol");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("eapol");
#endif
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
#ifdef TFT_SHIELD #ifdef TFT_SHIELD
@@ -1551,13 +1561,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
display_obj.tftDrawExitScaleButtons(); display_obj.tftDrawExitScaleButtons();
#endif #endif
#else #else
#ifdef WRITE_PACKETS_SERIAL startPcap("eapol");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("eapol");
#else
return;
#endif
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.TOP_FIXED_AREA_2 = 48; 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) void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL startPcap("pwnagotchi");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("pwnagotchi");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -1837,23 +1835,21 @@ void WiFiScan::executeWarDrive() {
// Function to start running a beacon scan // Function to start running a beacon scan
void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color) 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) if (scan_mode == WIFI_SCAN_AP)
sd_obj.openCapture("beacon"); startPcap("beacon");
else if (scan_mode == WIFI_SCAN_WAR_DRIVE) { else if (scan_mode == WIFI_SCAN_WAR_DRIVE) {
#ifdef HAS_GPS #ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) { if (gps_obj.getGpsModuleStatus()) {
sd_obj.openLog("wardrive"); 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"; 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.logAdd(header_line);
} } else {
#endif return;
} }
#else #else
return; return;
#endif #endif
}
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -1912,13 +1908,7 @@ void WiFiScan::startWardriverWiFi() {
void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color) void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL startPcap("station");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("station");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); 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) 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) if (scan_mode != WIFI_SCAN_SIG_STREN)
sd_obj.openCapture("raw"); startPcap("raw");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); 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) void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL startPcap("deauth");
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("deauth");
#else
return;
#endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -2065,23 +2043,21 @@ void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
// Function for running probe request scan // Function for running probe request scan
void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color) 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) if (scan_mode == WIFI_SCAN_PROBE)
sd_obj.openCapture("probe"); startPcap("probe");
else if (scan_mode == WIFI_SCAN_STATION_WAR_DRIVE) { else if (scan_mode == WIFI_SCAN_STATION_WAR_DRIVE) {
#ifdef HAS_GPS #ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) { if (gps_obj.getGpsModuleStatus()) {
sd_obj.openLog("station_wardrive"); 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"; 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.logAdd(header_line);
} } else {
#endif return;
} }
#else #else
return; return;
#endif #endif
}
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
flipper_led.sniffLED(); flipper_led.sniffLED();
@@ -2212,25 +2188,19 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color)
pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false); pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false);
} }
else if ((scan_mode == BT_SCAN_WAR_DRIVE) || (scan_mode == BT_SCAN_WAR_DRIVE_CONT)) { 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 #ifdef HAS_GPS
if (gps_obj.getGpsModuleStatus()) { if (gps_obj.getGpsModuleStatus()) {
if (scan_mode == BT_SCAN_WAR_DRIVE) { if (scan_mode == BT_SCAN_WAR_DRIVE) {
#ifdef HAS_SD startLog("bt_wardrive");
sd_obj.openLog("bt_wardrive");
#endif
} }
else if (scan_mode == BT_SCAN_WAR_DRIVE_CONT) { else if (scan_mode == BT_SCAN_WAR_DRIVE_CONT) {
#ifdef HAS_SD startLog("bt_wardrive_cont");
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"; 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.logAdd(header_line);
} else {
return;
} }
#endif
#else #else
return; return;
#endif #endif

View File

@@ -390,6 +390,9 @@ class WiFiScan
void StopScan(uint8_t scan_mode); void StopScan(uint8_t scan_mode);
const char* generateRandomName(); 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 getMAC(char *addr, uint8_t* data, uint16_t offset);
static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type); static void beaconSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);