mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-21 06:43:13 -08:00
Sd+Serial pcapOpen() and logOpen() in buffer_obj
This commit is contained in:
@@ -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<bool>("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){
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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() {
|
||||
#ifdef HAS_SCREEN
|
||||
display_obj.tft.setTextWrap(false);
|
||||
|
||||
@@ -43,8 +43,6 @@ class SDInterface {
|
||||
void listDir(String str_dir);
|
||||
void listDirToLinkedList(LinkedList<String>* 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();
|
||||
|
||||
@@ -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");
|
||||
startPcap("beacon");
|
||||
else if (scan_mode == WIFI_SCAN_WAR_DRIVE) {
|
||||
#ifdef HAS_GPS
|
||||
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";
|
||||
buffer_obj.logAdd(header_line);
|
||||
}
|
||||
#endif
|
||||
} 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
|
||||
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");
|
||||
startPcap("probe");
|
||||
else if (scan_mode == WIFI_SCAN_STATION_WAR_DRIVE) {
|
||||
#ifdef HAS_GPS
|
||||
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";
|
||||
buffer_obj.logAdd(header_line);
|
||||
}
|
||||
#endif
|
||||
} 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
|
||||
startLog("bt_wardrive");
|
||||
}
|
||||
else if (scan_mode == BT_SCAN_WAR_DRIVE_CONT) {
|
||||
#ifdef HAS_SD
|
||||
sd_obj.openLog("bt_wardrive_cont");
|
||||
#endif
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
#else
|
||||
return;
|
||||
#endif
|
||||
|
||||
@@ -390,6 +390,9 @@ class WiFiScan
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user