Merge pull request #21 from n0xa/fixWifiSpam

Fix wifi spam
This commit is contained in:
Noah Axon 2023-11-18 00:58:55 -06:00 committed by GitHub
commit 3486c26877
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 115 deletions

View File

@ -7,7 +7,7 @@
//#define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=-
String buildver="2.0.0rc1";
String buildver="2.0.0rc2";
#define BGCOLOR BLACK
#define FGCOLOR GREEN
@ -65,7 +65,6 @@ QRCODE qrcodes[] = {
// -=-=- FEATURES -=-=-
#define KB
#define HID
#define ACTIVE_LOW_IR
// -=-=- ALIASES -=-=-
#define DISP M5Cardputer.Display
#endif
@ -138,7 +137,7 @@ void switcher_button_proc() {
void check_kb(){
M5Cardputer.update();
if (M5Cardputer.Keyboard.isChange()) {
delay(250);
delay(100);
}
}
#endif
@ -214,7 +213,7 @@ void mmenu_setup() {
cursor = 0;
rstOverride = true;
mmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void mmenu_loop() {
@ -297,7 +296,7 @@ void mmenu_loop() {
cursor = (screen_dim_time / 5) - 1;
rstOverride = true;
dmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void dmenu_loop() {
@ -386,7 +385,7 @@ void smenu_setup() {
cursor = 0;
rstOverride = true;
smenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void smenu_loop() {
@ -436,7 +435,7 @@ int rotation = 1;
cursor = 0;
rstOverride = true;
rmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void rmenu_loop() {
@ -482,7 +481,7 @@ int rotation = 1;
float b = M5.Axp.GetVbatData() * 1.1 / 1000;
int battery = ((b - 3.0) / 1.2) * 100;
battery_drawmenu(battery, b, c);
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void battery_loop() {
@ -525,14 +524,10 @@ void tvbgone_setup() {
void tvbgone_loop()
{
if (check_select_press()) {
delay_ten_us(40000);
while (check_select_press()) {
delay_ten_us(500);
yield();
}
delay(250);
Serial.println("triggered TVBG");
sendAllCodes();
}
yield();
}
/// TVBG-Region MENU ///
@ -583,8 +578,7 @@ void tvbgmenu_loop() {
}
}
void sendAllCodes()
{
void sendAllCodes() {
bool endingEarly = false; //will be set to true if the user presses the button during code-sending
if (region == NA) {
num_codes = num_NAcodes;
@ -621,20 +615,19 @@ void sendAllCodes()
#endif
DISP.setTextSize(TINY_TEXT);
DISP.printf("rti = %d Pair = %d, %d\n", ti >> 1, ontime, offtime);
Serial.printf("TVBG: rti = %d Pair = %d, %d\n", ti >> 1, ontime, offtime);
rawData[k * 2] = offtime * 10;
rawData[(k * 2) + 1] = ontime * 10;
yield();
}
irsend.sendRaw(rawData, (numpairs * 2) , freq);
#if defined(ACTIVE_LOW_IR)
// Set Active Low IRLED high to turn it off after each burst.
digitalWrite(IRLED, HIGH);
#endif
yield();
bitsleft_r = 0;
delay_ten_us(20500);
#if defined(AXP)
if (M5.Axp.GetBtnPress()){
if (M5.Axp.GetBtnPress()) {
endingEarly = true;
current_proc = 1;
isSwitching = true;
@ -642,13 +635,13 @@ void sendAllCodes()
break;
}
#endif
#if defined(KB)
check_kb();
#endif
if (check_select_press()){
while (check_select_press()) {
yield();
}
Serial.println("endingearly");
endingEarly = true;
quickflashLEDx(4);
delay(250);
break;
}
}
@ -780,7 +773,7 @@ void btmenu_setup() {
maelstrom = false;
rstOverride = true;
btmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void btmenu_loop() {
@ -1119,9 +1112,11 @@ void aj_adv(){
}
if (check_next_press()) {
if (sourApple || swiftPair || maelstrom){
isSwitching = true;
current_proc = 16;
btmenu_drawmenu();
} else {
isSwitching = true;
current_proc = 8;
aj_drawmenu();
}
@ -1178,9 +1173,6 @@ void wifispam_setup() {
packetSize -= 26;
}
// generate random mac address
randomMac();
//change WiFi mode
WiFi.mode(WIFI_MODE_STA);
@ -1210,7 +1202,7 @@ void wifispam_setup() {
DISP.print(rickrollssids);
break;
case 3:
// placed here for consistency. no-op since display handled in loop.
DISP.printf(" - Random SSIDs\n", ct);
break;
}
DISP.setTextSize(SMALL_TEXT);
@ -1233,14 +1225,14 @@ void wifispam_loop() {
while(i < len){
i++;
}
beaconSpam(funnyssids);
beaconSpamList(funnyssids);
break;
case 2:
len = sizeof(rickrollssids);
while(i < len){
i++;
}
beaconSpam(rickrollssids);
beaconSpamList(rickrollssids);
break;
case 3:
char* randoms = randomSSID();
@ -1248,7 +1240,7 @@ void wifispam_loop() {
while(i < len){
i++;
}
beaconSpam(randoms);
beaconSpamList(randoms);
break;
}
}
@ -1263,13 +1255,17 @@ void btmaelstrom_loop(){
swiftPair = false;
sourApple = true;
aj_adv();
if (maelstrom){
swiftPair = true;
sourApple = false;
aj_adv();
}
if (maelstrom){
swiftPair = false;
sourApple = false;
aj_loop(); // roll a random device ID
aj_adv();
}
}
/// WIFI MENU ///
@ -1295,7 +1291,7 @@ void wsmenu_setup() {
cursor = 0;
rstOverride = true;
wsmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void wsmenu_loop() {
@ -1359,7 +1355,7 @@ void wscan_result_setup() {
cursor = 0;
rstOverride = true;
wscan_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void wscan_result_loop(){
@ -1475,7 +1471,7 @@ void bootScreen(){
M5Cardputer.update();
if (M5Cardputer.Keyboard.isChange()) {
mmenu_drawmenu();
delay(500);
delay(250);
break;
}
}
@ -1501,7 +1497,7 @@ void qrmenu_setup() {
cursor = 0;
rstOverride = true;
qrmenu_drawmenu();
delay(250); // Prevent switching after menu loads up
delay(500); // Prevent switching after menu loads up
}
void qrmenu_loop() {

View File

@ -76,31 +76,18 @@ const char rickrollssids[] PROGMEM = {
"08 and hurt you\n"
};
const char foobar[] PROGMEM = {
"abh\nfoooo\nbarrr\nbaz\nbat\ngarply\nquux\nheyfuckface\n"
};
#define SSIDLEN 375 /* Change to whatever length you need */
char* randomSSID(){
/* Change to allowable characters */
const char possible[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 -.!)(,?%";
static char ssid[SSIDLEN + 1];
for(int p = 0, i = 0; i < SSIDLEN; i++){
int r = random(0, strlen(possible));
if(r % 7 == 0){
ssid[p++] = '\n'; // inject newlines occasionally :D
}
ssid[p++] = possible[r];
}
ssid[SSIDLEN] = '\n'; DISP.setTextSize(1);
DISP.fillScreen(BLACK);
DISP.setCursor(0, 0, 1);
DISP.println("Spamming Random SSIDs:");
// Maximum broadcast SSID length is 32, but the strings might show longer in the output. Sorry.
DISP.print(ssid);
return ssid;
}
// run-time variables
char emptySSID[32];
char beaconSSID[32];
char randomName[32];
uint8_t channelIndex = 0;
uint8_t macAddr[6];
uint8_t wifi_channel = 1;
uint32_t currentTime = 0;
uint32_t packetSize = 0;
uint32_t packetCounter = 0;
uint32_t attackTime = 0;
uint32_t packetRateTime = 0;
#include <WiFi.h>
@ -121,17 +108,28 @@ const char* generateRandomName() {
return randomName;
}
char* randomSSID() {
const char* charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int len = rand() % 22 + 7; // Generate a random length between 1 and 10
for (int i = 0; i < len; ++i) {
randomName[i] = charset[rand() % strlen(charset)]; // S elect random characters from the charset
}
randomName[len] = '\0'; // Null-terminate the string
return randomName;
}
// run-time variables
char emptySSID[32];
uint8_t channelIndex = 0;
uint8_t macAddr[6];
uint8_t wifi_channel = 1;
uint32_t currentTime = 0;
uint32_t packetSize = 0;
uint32_t packetCounter = 0;
uint32_t attackTime = 0;
uint32_t packetRateTime = 0;
uint8_t packet[128] = { 0x80, 0x00, 0x00, 0x00, //Frame Control, Duration
/*4*/ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, //Destination address
/*10*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //Source address - overwritten later
/*16*/ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, //BSSID - overwritten to the same as the source address
/*22*/ 0xc0, 0x6c, //Seq-ctl
/*24*/ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, //timestamp - the number of microseconds the AP has been active
/*32*/ 0x64, 0x00, //Beacon interval
/*34*/ 0x01, 0x04, //Capability info
/* SSID */
/*36*/ 0x00
};
// beacon frame definition
uint8_t beaconPacket[109] = {
@ -200,26 +198,46 @@ void nextChannel() {
}
}
// generates random MAC
void randomMac() {
for (int i = 0; i < 6; i++)
macAddr[i] = random(256);
void beaconSpam(const char ESSID[]){
Serial.printf("WiFi SSID: %s\n", ESSID);
int set_channel = random(1,12);
esp_wifi_set_channel(set_channel, WIFI_SECOND_CHAN_NONE);
delay(1);
packet[10] = packet[16] = random(256);
packet[11] = packet[17] = random(256);
packet[12] = packet[18] = random(256);
packet[13] = packet[19] = random(256);
packet[14] = packet[20] = random(256);
packet[15] = packet[21] = random(256);
int realLen = strlen(ESSID);
int ssidLen = random(realLen, 33);
int numSpace = ssidLen - realLen;
//int rand_len = sizeof(rand_reg);
int fullLen = ssidLen;
packet[37] = fullLen;
for(int i = 0; i < realLen; i++)
packet[38 + i] = ESSID[i];
for(int i = 0; i < numSpace; i++)
packet[38 + realLen + i] = 0x20;
packet[50 + fullLen] = set_channel;
esp_wifi_80211_tx(WIFI_IF_STA, packet, sizeof(packet), false);
esp_wifi_80211_tx(WIFI_IF_STA, packet, sizeof(packet), false);
esp_wifi_80211_tx(WIFI_IF_STA, packet, sizeof(packet), false);
}
void beaconSpam(const char list[]){
attackTime = currentTime;
// temp variables
void beaconSpamList(const char list[]){
// Parses the char array and splits it into SSIDs
int i = 0;
int j = 0;
int ssidNum = 1;
char tmp;
int ssidsLen = strlen_P(list);
bool sent = false;
// go to next channel
nextChannel();
while (i < ssidsLen) {
// read out next SSID
j = 0;
@ -227,31 +245,10 @@ void beaconSpam(const char list[]){
tmp = pgm_read_byte(list + i + j);
j++;
} while (tmp != '\n' && j <= 32 && i + j < ssidsLen);
uint8_t ssidLen = j - 1;
// set MAC address
macAddr[5] = ssidNum;
ssidNum++;
// write MAC address into beacon frame
memcpy(&beaconPacket[10], macAddr, 6);
memcpy(&beaconPacket[16], macAddr, 6);
// reset SSID
memcpy(&beaconPacket[38], emptySSID, 32);
// write new SSID into beacon frame
memcpy_P(&beaconPacket[38], &list[i], ssidLen);
// set channel for beacon frame
beaconPacket[82] = wifi_channel;
// send packet
for (int k = 0; k < 3; k++) {
packetCounter += esp_wifi_80211_tx(WIFI_IF_STA, beaconPacket, packetSize, 0) == 0;
delay(1);
}
memcpy_P(&beaconSSID, &list[i], ssidLen);
beaconSpam(beaconSSID);
memcpy_P(&beaconSSID, &emptySSID, 32);
i += j;
}
}