migrating

This commit is contained in:
2026-05-26 22:16:15 -06:00
commit b031059f95
50 changed files with 2465 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
build
*.old
old
*.bak
*~
sdkconfig
*.lock
.vscode
+8
View File
@@ -0,0 +1,8 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
set(COMPONENTS main esp_netif lwip startup esp_hw_support esp_system nvs_flash esp_wifi)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(wifi-esp-freertos)
+40
View File
@@ -0,0 +1,40 @@
#include "esp_netif.h"
#include "esp_netif_types.h"
#define DHCP_IP CONFIG_DHCP_IP
#define DNS_SERVER CONFIG_DNS_SERVER
// decode DHCP server IP
esp_ip4_addr_t dhcpIP;
esp_netif_str_to_ip4(DHCP_IP, dhcpIP);
// decode DNS server IP
esp_ip4_addr_t dnsIP;
esp_netif_str_to_ip4(DNS_SERVER, dnsIP);
struct esp_netif_dns_info_t dns_ip_wraped = {dnsIP}; // wtf is this shit frong
ESP_ERROR_CHECK(esp_netif_dhcps_start(netifWifi));
ESP_ERROR_CHECK(esp_netif_set_dns_info(netifWifi, ESP_NETIF_DNS_MAIN, dns_ip_wraped));
/*
// new dhcp server lfggggggg
dhcps_t dhcps = dhcps_new();
// set some silly optionsssss
u8_t option_id = ;
ESP_ERROR_CHECK(dhcps_dns_setserver(*dhcps, dnsIP));
ESP_ERROR_CHECK(dhcps_set_option_info(*dhcps,
// run the fucka
ESP_ERROR_CHECK(dhcps_start(*dhcps, netifWifi, dhcpIP));
// get DHCP option
// u8_t option_id_ret;
// u32_t option_len_ret;
// dhcps_option_info(*dhcps, option_id_ret, option_len_ret);
*/
+3
View File
@@ -0,0 +1,3 @@
idf_component_register(SRCS "DELILAHS_FIST-lwip.c" "wifi-esp-freertos.c"
INCLUDE_DIRS ".")
# comment
@@ -0,0 +1,29 @@
#define DHCP_IP CONFIG_DHCP_IP
#define DNS_SERVER CONFIG_DNS_SERVER
// decode DHCP server IP
esp_ip4_addr_t dhcpIP;
esp_netif_str_to_ip4(DHCP_IP, dhcpIP);
// decode DNS server IP
esp_ip4_addr_t dnsIP;
esp_netif_str_to_ip4(DNS_SERVER, dnsIP);
// new dhcp server lfggggggg
dhcps_t dhcps = dhcps_new();
// set some silly optionsssss
ESP_ERROR_CHECK(dhcps_dns_setserver(*dhcps, dnsIP));
// run the fucka
ESP_ERROR_CHECK(dhcps_start(*dhcps, netifWifi, dhcpIP));
/*
// get DHCP option
u8_t option_id_ret;
u32_t option_len_ret;
dhcps_option_info(*dhcps, option_id_ret, option_len_ret);
*/
+103
View File
@@ -0,0 +1,103 @@
menu "WIFI 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 "PrincessPiESP32"
help
Hostname lol
config DEST_IP_ADDR
string "Destination IPv4 Address"
default "10.0.0.255"
help
dst addr, ipv4, string, lfgggg
config DEST_PORT
int "Destination Port"
default 4444
help
dst port, integar, 0-65535
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
config ESP_MAXIMUM_RETRY
int "Maximum retry"
default 5
help
Set the Maximum retry to avoid station reconnecting to the AP unlimited when the AP is really inexistent.
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
menu "DHCP Attacks Configuration"
config DHCP_IP
string "DHCP Server Address"
default "192.168.1.1"
help
ASCII string notation of DHCP server's IPv4 address.
Used in DELILAHS_FIST attacks and MitM attacks.
config DNS_SERVER
string "DNS Server Address"
default "1.0.0.1"
help
ASCII string notation of DHCP server's DNS server.
Used in DELILAHS_FIST attacks and MitM attacks.
endmenu
+214
View File
@@ -0,0 +1,214 @@
#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 "esp_netif.h"
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "lwip/err.h"
#include "wifi-esp-freertos.h"
#define WIFI_SSID CONFIG_WIFI_SSID
#define WIFI_PSK CONFIG_WIFI_PSK
#define HOSTNAME CONFIG_HOSTNAME
#define DEST_IP_ADDR CONFIG_DEST_IP_ADDR
#define DEST_PORT CONFIG_DEST_PORT
// Spoofed mac
uint8_t mac[6] = {0x01,0x02,0x03,0x04,0x05,0x06};
// Time in seconds to loop raw_send_task
float loopSeconds = 1;
// Network timeout in seconds
int timeoutSecs = 10;
// packet contents
static const char *payload = "LETS FUCKING GOOOOO LFGGGGGGGGG";
// Tag for logging
static const char *TAGSUCC = "GreatSucc:";
static const char *TAGFAIL = "EPIC FAIL YOU SUCK:";
// wifi event group for freertos
static EventGroupHandle_t s_wifi_event_group;
static int s_retry_num = 0;
esp_netif_t *netifWifi;
int err;
int errno;
int sockfd;
// ip info after connecting to AP
char str_ipv4[16]; // local ip os esp
char str_ipnm[16]; // netmask
char str_ipgw[16]; // gateway
static void raw_send_task(void *pvParameters) {
// configure the sockaddr
struct sockaddr_in dest_addr;
dest_addr.sin_addr.s_addr = inet_addr(DEST_IP_ADDR);
dest_addr.sin_family = AF_INET;
if((sockfd = socket(AF_INET, SOCK_RAW, IPPROTO_IP)) < 0) {
ESP_LOGE(TAGFAIL, "Error creating socket: %d", errno);
} else {
ESP_LOGI(TAGSUCC, "Socket created");
}
// option lengths
int opt = 1;
int optlen = sizeof(int);
// timeouts
struct timeval timeout;
timeout.tv_sec = timeoutSecs;
timeout.tv_usec = 0;
// options
setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout);
setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt));
setsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, optlen);
if(err < 0) {
ESP_LOGE(TAGFAIL, "Error setting socket options: %d", err);
} else {
ESP_LOGI(TAGSUCC, "Socket options set");
}
while(1) {
int sendErr = sendto(sockfd, payload, strlen(payload), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
if(sendErr < 0) {
ESP_LOGE(TAGFAIL, "Error sending: %d", err);
} else {
ESP_LOGI(TAGSUCC, "Sent!\n\tLooping every %f seconds\n\tDst: %s\n\tPayload: %s\n\tTimeout: %d\n", loopSeconds, DEST_IP_ADDR, payload, timeoutSecs);
}
// delay on loop
vTaskDelay((loopSeconds*1000) / portTICK_PERIOD_MS);
}
}
static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data)
{
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 raw_send_task to FreeRTOS task
xTaskCreate(raw_send_task, "raw_send_task", 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");
wifi_init_sta();
}
@@ -0,0 +1,33 @@
#define ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
#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
// some cozy status bits
#define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1
+106
View File
@@ -0,0 +1,106 @@
== WIFI ==
https://github.com/espressif/esp-idf/tree/v5.2.3/examples/wifi/getting_started/station
== SOCKETS ==
https://pubs.opengroup.org/onlinepubs/007908799/xns/socket.html
// socket functions
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#bsd-sockets-api
// socket options for setsocketopt()
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#socket-options
// socket error handling
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/lwip.html#socket-error-handling
// error codes
https://github.com/espressif/newlib-esp32/blob/master/newlib/libc/include/sys/errno.h
// sockets header file
https://github.com/espressif/esp-lwip/blob/6bc36ec/src/include/lwip/sockets.h
socket(address_family, type, protocol)
Address Family:
AF_INET // ipv4
AF_INET6 // ipv6
AF_UNSPEC // unspecified?
Type:
SOCK_STREAM // tcp
SOCK_DGRAM // udp
SOCK_RAW // raw
Protocols:
IPPROTO_IP
IPPROTO_ICMP
IPPROTO_TCP
IPPROTO_UDP
IPPROTO_IPV6
IPPROTO_ICMPV6
IPPROTO_UDPLITE
IPPROTO_RAW
setsockopt(socket, level)
Level:
SOL_SOCKET
SO_REUSEADDR // Allow local address reuse
SO_KEEPALIVE // keep connections alive
SO_BROADCAST // permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option)
SO_DEBUG // Unimplemented: turn on debugging info recording
SO_ACCEPTCONN // socket has had listen()
SO_DONTROUTE // Unimplemented: just use interface addresses
SO_USELOOPBACK // Unimplemented: bypass hardware when possible
SO_LINGER // linger on close if data present
SO_DONTLINGER ((int)(~SO_LINGER)) // ?
SO_OOBINLINE // Unimplemented: leave received OOB data in line
SO_REUSEPORT // Unimplemented: allow local address & port reuse
SO_SNDBUF // Unimplemented: send buffer size
SO_RCVBUF // receive buffer size
SO_SNDLOWAT // Unimplemented: send low-water mark
SO_RCVLOWAT // Unimplemented: receive low-water mark
SO_SNDTIMEO // send timeout
SO_RCVTIMEO // receive timeout
SO_ERROR // get error status and clear
SO_TYPE // get socket type
SO_CONTIMEO // Unimplemented: connect timeout
SO_NO_CHECK // don't create UDP checksum
SO_BINDTODEVICE // bind to device
IPPROTO_IP
IPPROTO_TCP
IPPROTO_IPV6
IPPROTO_UDPLITE
struct raw_pcb * raw_new (u8_t proto);
err_t raw_connect (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
void raw_disconnect (struct raw_pcb *pcb);
err_t raw_bind (struct raw_pcb *pcb, const ip_addr_t *ipaddr);
err_t raw_sendto (struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *ipaddr);
err_t raw_send (struct raw_pcb *pcb, struct pbuf *p);\
void raw_recv (struct raw_pcb *pcb, raw_recv_fn recv, void *recv_arg);
== DHCP ==
DHCP Starvation attack
Delilah's Fist
/* NETIF */
// esp_netif_dhcps_option - Set or Get DHCP server option.
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_netif.html?highlight=dhcp#_CPPv422esp_netif_dhcps_optionP11esp_netif_t28esp_netif_dhcp_option_mode_t26esp_netif_dhcp_option_id_tPv8uint32_t
// esp_netif_dhcps_start - Start DHCP server (only if enabled in interface object)
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_netif.html?highlight=dhcp#_CPPv421esp_netif_dhcps_startP11esp_netif_t
// esp_netif_set_dns_info - Set DNS Server information (DHCP in this case)
https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/network/esp_netif.html?highlight=dhcp#_CPPv422esp_netif_set_dns_infoP11esp_netif_t20esp_netif_dns_type_tP20esp_netif_dns_info_t
/* LWIP */
// header file
https://github.com/espressif/esp-idf/blob/6e5a178b3120dced7fa5c29c655cc22ea182df3d/components/lwip/include/apps/dhcpserver/dhcpserver.h
// options
https://github.com/espressif/esp-idf/blob/6e5a178b3120dced7fa5c29c655cc22ea182df3d/components/lwip/include/apps/dhcpserver/dhcpserver_options.h
// source file
https://github.com/espressif/esp-idf/blob/6e5a178b3120dced7fa5c29c655cc22ea182df3d/components/lwip/apps/dhcpserver/dhcpserver.c
+10
View File
@@ -0,0 +1,10 @@
# This file was generated using idf.py save-defconfig. It can be edited manually.
# Espressif IoT Development Framework (ESP-IDF) 5.4.0 Project Minimal Configuration
#
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
CONFIG_LWIP_IPV6=n
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n