Click here to Skip to main content
15,391,593 members
Articles / Desktop Programming / Win32
Posted 20 Aug 2008


79 bookmarked

802.11 Packet Injection for Windows

Rate me:
Please Sign up or sign in to vote.
4.83/5 (15 votes)
3 Jun 2009CPOL3 min read
Insert custom packets in the 802.11 frame


This project is intended for Windows wireless network developers, and assumes the reader is familiar with the concept of packet injection, 802.11 frames, and IP protocols. The network driver in this package provides a means for developers to create 802.11 packets in user space and send them on the 802.11 layer. The package contains a network driver and an open source command line application. The command line application demonstrates how to use the Packet11 service via DeviceIoControl.


Typically, packet injection is used to test wireless security or break WEP keys (airplay) with "software controlled packets". Although software controlled packets can be used maliciously, they can also provide a better user experience. Mesh networking and virtual access points are two potential and beneficial applications of managing wireless packets. Packet11 is the first step to providing software controlled packets for wireless testing and routing.

To the best of my knowledge, there are no other 802.11 packet injectors for Windows without special adapters (AirPCap). Packets constructed in the 802.11 layer are native to the wireless miniport. Linux has been able to modify native WiFi packets for ages and extend WiFi technology, i.e., MadWiFi. Having more control over native WiFi packets will also extend WiFi capabilities in Windows. Since Windows Vista, Network Driver Interface Specification (NDIS) 6 has given third party Windows developers a better opportunity to manage and extend WiFi adapter capabilities. However, creating and modifying packets in the 802.11 layer is undocumented for Windows.


  • Windows Vista or later
  • Wireless adapter*

*I tested Packet11 on Atheros USB WiFi, Intel PCI WiFi and Rosewill adapters. All were able to send my custom packets. I recommend having a second wireless adapter in monitor mode to look at the packets as they are sent in the air.

Using the Code

I have implemented a new technique since this article was posted that allows a filter driver to originate 802.11 packets without modifying OS generated packets. Now, applications can create and send 802.11 packets using DeviceIoControl.  Obviously, in order to use this function, the Packet11 driver must be installed before using this function.  I have provided commands to install and uninstall the driver.  The readme gives more details on this. Once the driver is installed, we can create and test a custom 802.11 packet.

To demonstrate, I used a probe request type to illustrate one possibility.

// Initialize the 802.11 packet. In this case, a probe request.
void * CreatePacket(
			DOT11_MGMT_SUBTYPE subtype,
			PUCHAR Source,
			PUCHAR Dest,
			PUCHAR Bssid,
			ULONG packetsize


    PDOT11_MGMT_HEADER		pMgmtHeader = NULL;
    PDOT11_PROBE_REQUEST		pProbeRequest = NULL;
    PDOT11_INFO_ELEMENT		pInfoElement = NULL;
    PDOT11_BASIC_RATE		pBasicRate = NULL;
    PDOT11_EXT_RATE		pExtRate = NULL;
    PVOID 			DataBuffer = NULL;

	if(Source == NULL || Dest == NULL || Bssid == NULL){
		printf("CreatePacket ==> null mac address \n");
		return DataBuffer;

	DataBuffer = malloc(packetsize);

	pMgmtHeader = (PDOT11_MGMT_HEADER)(PUCHAR)DataBuffer;
	pMgmtHeader->FrameControl.Version = 0;
	pMgmtHeader->FrameControl.Type = DOT11_FRAME_TYPE_MANAGEMENT;
	pMgmtHeader->FrameControl.Subtype =  subtype;

	//firmware can handle rest of framecontrol
	pMgmtHeader->FrameControl.ToDS = 0;
	pMgmtHeader->FrameControl.FromDS = 0;
	pMgmtHeader->FrameControl.MoreFrag = 0;
	pMgmtHeader->FrameControl.Retry = 0;
	pMgmtHeader->FrameControl.PwrMgt = 0;
	pMgmtHeader->FrameControl.MoreData = 0;
	pMgmtHeader->FrameControl.WEP = 0;
	pMgmtHeader->FrameControl.Order = 0;

	//no specific duration was required to send
	pMgmtHeader->DurationID = 314;

	memcpy(pMgmtHeader->DA, Dest, MAC_ADDR_LEN);
	memcpy(pMgmtHeader->SA, Source, MAC_ADDR_LEN);
	memcpy(pMgmtHeader->BSSID, Bssid, MAC_ADDR_LEN);

	pMgmtHeader->SequenceControl.FragmentNumber = 0;
	pMgmtHeader->SequenceControl.SequenceNumber = 0;

	switch (subtype)
			packetsize = sizeof(DOT11_MGMT_HEADER ) + 
			pProbeRequest = (PDOT11_PROBE_REQUEST)
			((PUCHAR)pMgmtHeader + sizeof(DOT11_MGMT_HEADER ));

			pProbeRequest->ssid.ElementID = 0;  //ssid frame
			pProbeRequest->ssid.Length = 0;

			//the number of rates is up to the user
			pProbeRequest->rateframe.ieheader.ElementID = 1;//rate frame
			pProbeRequest->rateframe.ieheader.Length = 1;	//1 rate object
			pProbeRequest->rateframe.rate[0] = 
					(USHORT)0x82;//mandatory, // 1mbps



	return pMgmtHeader;

The probe request packet is sent with DeviceIoControl.

DeviceHandle = OpenHandle(pPacketuioDevice);

IORequest(DeviceHandle , IOCTL_PACKET11_GET_MAC, NULL, 0, Source, MAC_ADDR_LEN);

PacketLength = sizeof(DOT11_MGMT_HEADER ) + sizeof(DOT11_PROBE_REQUEST) + 1;

pMgmtFrame = CreatePacket(DOT11_MGMT_SUBTYPE_PROBE_REQUEST,Source, 
				BroadCast,BroadCast, PacketLength);

			(PUCHAR)pMgmtFrame, PacketLength, NULL, 0);


When the driver receives the request, it checks the frame type, the source mac address, and the number of packets sent. For now, the frame type must be management. Data frames will be supported in later versions. The source address must match the adapter's mac address to prevent mac spoofing. The final control makes sure no more than two packets are sent in one second intervals. If the user packet passes these checks, the packet is created and sent to the miniport for further processing. Some adapters will send the packet without being associated as long as a channel is set. Some chipsets will only send the user packet while associated. I assume the rules set by the manufacturer while in initialization or operational mode determine if the packet will be sent.

proberequest.png - Click to enlarge image

Side note: Network Monitor 3.2 is an example of the NDIS 6 technology. It can capture 802.11 packets in the air within the range of the adapter.

The highlighted packet above shows that the probe request matches the one defined with packettest.

Related Links


Thanks to Thomas Divine for pointing me in the right direction.


  • Version 1.5 - Beta release - 2/12/2009
  • Version 1.0 - Initial release - 8/20/2008

This is an ongoing project. More updates will come in the future.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Ryan Grevious
United States United States
No Biography provided

Comments and Discussions

GeneralRe: Source code Pin
motocrosserman13-May-10 5:52
Membermotocrosserman13-May-10 5:52 
GeneralLWF in Vista causing system unstable Pin
Rathan Raj16-Feb-09 19:44
MemberRathan Raj16-Feb-09 19:44 
GeneralRe: LWF in Vista causing system unstable [modified] Pin
Ryan Grevious16-Feb-09 21:08
MemberRyan Grevious16-Feb-09 21:08 
GeneralRe: LWF in Vista causing system unstable Pin
Rathan Raj17-Feb-09 3:28
MemberRathan Raj17-Feb-09 3:28 
GeneralRe: LWF in Vista causing system unstable Pin
Ryan Grevious17-Feb-09 12:21
MemberRyan Grevious17-Feb-09 12:21 
GeneralRe: LWF in Vista causing system unstable Pin
Rathan Raj18-Feb-09 3:53
MemberRathan Raj18-Feb-09 3:53 
GeneralRe: LWF in Vista causing system unstable Pin
Rathan Raj24-Feb-09 18:58
MemberRathan Raj24-Feb-09 18:58 
GeneralRe: LWF in Vista causing system unstable Pin
Ryan Grevious25-Feb-09 17:15
MemberRyan Grevious25-Feb-09 17:15 
GeneralNo listening port after install and reboot Pin
joswr1ght21-Nov-08 7:17
Memberjoswr1ght21-Nov-08 7:17 
GeneralRe: No listening port after install and reboot [modified] Pin
Ryan Grevious21-Nov-08 11:48
MemberRyan Grevious21-Nov-08 11:48 
GeneralRe: No listening port after install and reboot Pin
Ryan Grevious12-Feb-09 13:39
MemberRyan Grevious12-Feb-09 13:39 
QuestionChannel control? Pin
joswr1ght13-Nov-08 8:51
Memberjoswr1ght13-Nov-08 8:51 
AnswerRe: Channel control? Pin
Ryan Grevious15-Nov-08 13:08
MemberRyan Grevious15-Nov-08 13:08 
GeneralRe: Channel control? Pin
joswr1ght15-Nov-08 13:45
Memberjoswr1ght15-Nov-08 13:45 
GeneralRe: Channel control? Pin
Ryan Grevious15-Nov-08 14:28
MemberRyan Grevious15-Nov-08 14:28 
Generalerrors when compiling using vc++ 6 Pin
ooropuloo30-Aug-08 5:48
Memberooropuloo30-Aug-08 5:48 
GeneralRe: errors when compiling using vc++ 6 Pin
Ryan Grevious30-Aug-08 11:20
MemberRyan Grevious30-Aug-08 11:20 
GeneralRe: errors when compiling using vc++ 6 Pin
ooropuloo2-Sep-08 5:04
Memberooropuloo2-Sep-08 5:04 
GeneralRe: errors when compiling using vc++ 6 Pin
Ryan Grevious2-Sep-08 11:06
MemberRyan Grevious2-Sep-08 11:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.