Externalize some utils

This commit is contained in:
Just Call Me Koko
2024-11-19 20:56:39 -05:00
parent 792ae898a3
commit ddb1696292
4 changed files with 107 additions and 17 deletions
+1 -1
View File
@@ -1739,7 +1739,7 @@ void MenuFunctions::RunSetup()
for (int x = 0; x < access_points->get(i).stations->size(); x++) {
int cur_ap_sta = access_points->get(i).stations->get(x);
this->addNodes(&wifiStationMenu, wifi_scan_obj.macToString(stations->get(cur_ap_sta)), TFT_CYAN, NULL, KEYBOARD_ICO, [this, i, cur_ap_sta, x](){
this->addNodes(&wifiStationMenu, macToString(stations->get(cur_ap_sta)), TFT_CYAN, NULL, KEYBOARD_ICO, [this, i, cur_ap_sta, x](){
Station new_sta = stations->get(cur_ap_sta);
new_sta.selected = !stations->get(cur_ap_sta).selected;
+26 -10
View File
@@ -38,7 +38,7 @@ extern "C" {
switch (Type) {
case Microsoft: {
const char* Name = this->generateRandomName();
const char* Name = generateRandomName();
uint8_t name_len = strlen(Name);
@@ -414,13 +414,13 @@ WiFiScan::WiFiScan()
{
}
String WiFiScan::macToString(const Station& station) {
/*String WiFiScan::macToString(const Station& station) {
char macStr[18]; // 6 pairs of hex digits + 5 colons + null terminator
snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
station.mac[0], station.mac[1], station.mac[2],
station.mac[3], station.mac[4], station.mac[5]);
return String(macStr);
}
}*/
void WiFiScan::RunSetup() {
if (ieee80211_raw_frame_sanity_check(31337, 0, 0) == 1)
@@ -683,7 +683,7 @@ void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
this->startWiFiAttacks(scan_mode, color, text_table4[47]);
else if (scan_mode == WIFI_ATTACK_AP_SPAM)
this->startWiFiAttacks(scan_mode, color, " AP Beacon Spam ");
else if ((scan_mode == BT_SCAN_ALL) || (BT_SCAN_AIRTAG)){
else if ((scan_mode == BT_SCAN_ALL) || (scan_mode == BT_SCAN_AIRTAG)){
#ifdef HAS_BT
RunBluetoothScan(scan_mode, color);
#endif
@@ -2011,7 +2011,7 @@ void WiFiScan::executeSourApple() {
#endif
}
void WiFiScan::generateRandomName(char *name, size_t length) {
/*void WiFiScan::generateRandomName(char *name, size_t length) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
// Generate the first character as uppercase
@@ -2022,9 +2022,9 @@ void WiFiScan::generateRandomName(char *name, size_t length) {
name[i] = alphabet[rand() % (sizeof(alphabet) - 1)];
}
name[length - 1] = '\0'; // Null-terminate the string
}
}*/
const char* WiFiScan::generateRandomName() {
/*const char* WiFiScan::generateRandomName() {
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int len = rand() % 10 + 1; // Generate a random length between 1 and 10
char* randomName = (char*)malloc((len + 1) * sizeof(char)); // Allocate memory for the random name
@@ -2033,9 +2033,9 @@ const char* WiFiScan::generateRandomName() {
}
randomName[len] = '\0'; // Null-terminate the string
return randomName;
}
}*/
void WiFiScan::generateRandomMac(uint8_t* mac) {
/*void WiFiScan::generateRandomMac(uint8_t* mac) {
// Set the locally administered bit and unicast bit for the first byte
mac[0] = 0x02; // The locally administered bit is the second least significant bit
@@ -2043,6 +2043,20 @@ void WiFiScan::generateRandomMac(uint8_t* mac) {
for (int i = 1; i < 6; i++) {
mac[i] = random(0, 255);
}
}*/
void WiFiScan::setBaseMacAddress(uint8_t macAddr[6]) {
// Use ESP-IDF function to set the base MAC address
esp_err_t err = esp_base_mac_addr_set(macAddr);
// Check for success or handle errors
if (err == ESP_OK) {
Serial.println("Base MAC address successfully set.");
} else if (err == ESP_ERR_INVALID_ARG) {
Serial.println("Error: Invalid MAC address argument.");
} else {
Serial.printf("Error: Failed to set MAC address. Code: %d\n", err);
}
}
void WiFiScan::executeSwiftpairSpam(EBLEPayloadType type) {
@@ -2050,7 +2064,9 @@ void WiFiScan::executeSwiftpairSpam(EBLEPayloadType type) {
uint8_t macAddr[6];
generateRandomMac(macAddr);
esp_base_mac_addr_set(macAddr);
//esp_base_mac_addr_set(macAddr);
this->setBaseMacAddress(macAddr);
NimBLEDevice::init("");
+9 -6
View File
@@ -4,6 +4,7 @@
#define WiFiScan_h
#include "configs.h"
#include "utils.h"
#include <ArduinoJson.h>
#include <algorithm>
@@ -146,18 +147,19 @@ esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, b
};*/
struct mac_addr {
/*struct mac_addr {
unsigned char bytes[6];
};
struct Station {
uint8_t mac[6];
bool selected;
};
};*/
struct AirTag {
String mac; // MAC address of the AirTag
std::vector<uint8_t> payload; // Payload data
bool selected;
};
class WiFiScan
@@ -302,8 +304,8 @@ class WiFiScan
void executeSourApple();
void executeSwiftpairSpam(EBLEPayloadType type);
void startWardriverWiFi();
void generateRandomMac(uint8_t* mac);
void generateRandomName(char *name, size_t length);
//void generateRandomMac(uint8_t* mac);
//void generateRandomName(char *name, size_t length);
String processPwnagotchiBeacon(const uint8_t* frame, int length);
void startWiFiAttacks(uint8_t scan_mode, uint16_t color, String title_string);
@@ -407,12 +409,13 @@ class WiFiScan
void main(uint32_t currentTime);
void StartScan(uint8_t scan_mode, uint16_t color = 0);
void StopScan(uint8_t scan_mode);
const char* generateRandomName();
void setBaseMacAddress(uint8_t macAddr[6]);
//const char* generateRandomName();
bool save_serial = false;
void startPcap(String file_name);
void startLog(String file_name);
String macToString(const Station& station);
//String macToString(const Station& station);
static void getMAC(char *addr, uint8_t* data, uint16_t offset);
static void pwnSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
+71
View File
@@ -0,0 +1,71 @@
#pragma once
#ifndef utils_h
#define utils_h
#include <Arduino.h>
struct mac_addr {
unsigned char bytes[6];
};
struct Station {
uint8_t mac[6];
bool selected;
};
void generateRandomName(char *name, size_t length) {
static const char alphabet[] = "abcdefghijklmnopqrstuvwxyz";
// Generate the first character as uppercase
name[0] = 'A' + (rand() % 26);
// Generate the remaining characters as lowercase
for (size_t i = 1; i < length - 1; ++i) {
name[i] = alphabet[rand() % (sizeof(alphabet) - 1)];
}
name[length - 1] = '\0'; // Null-terminate the string
}
const char* generateRandomName() {
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int len = rand() % 10 + 1; // Generate a random length between 1 and 10
char* randomName = (char*)malloc((len + 1) * sizeof(char)); // Allocate memory for the random name
for (int i = 0; i < len; ++i) {
randomName[i] = charset[rand() % strlen(charset)]; // Select random characters from the charset
}
randomName[len] = '\0'; // Null-terminate the string
return randomName;
}
void generateRandomMac(uint8_t* mac) {
// Set the locally administered bit and unicast bit for the first byte
mac[0] = 0x02; // The locally administered bit is the second least significant bit
// Generate the rest of the MAC address
for (int i = 1; i < 6; i++) {
mac[i] = random(0, 255);
}
}
String macToString(const Station& station) {
char macStr[18]; // 6 pairs of hex digits + 5 colons + null terminator
snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X",
station.mac[0], station.mac[1], station.mac[2],
station.mac[3], station.mac[4], station.mac[5]);
return String(macStr);
}
void convertMacStringToUint8(const String& macStr, uint8_t macAddr[6]) {
// Ensure the input string is in the format "XX:XX:XX:XX:XX:XX"
if (macStr.length() != 17) {
Serial.println("Invalid MAC address format");
return;
}
// Parse the MAC address string and fill the uint8_t array
for (int i = 0; i < 6; i++) {
macAddr[i] = (uint8_t)strtol(macStr.substring(i * 3, i * 3 + 2).c_str(), nullptr, 16);
}
}
#endif