Implementing Firewall Filters for Teredo
Windows allows applications to set a socket option that allows applications to indicate an explicit intent to receive Teredo traffic sent to the host firewall via the Windows Filtering Platform. In Windows, a socket option for setting a protection level is used to allow an application to define what type of traffic it is willing to receive. More specifically, in scenarios involving Teredo traffic, the IPV6_PROTECTION_LEVEL socket option is specified. It is recommended that host firewall implementations maintain the following filters to selectively allow Teredo traffic for an application, while blocking traffic by default for any application without an exemption.
Default Block Filter for Edge Traversed Traffic
A host firewall must always maintain a default block filter within the ALE_AUTH_RECV_ACCEPT_V6 filtering layer for traffic matching the specified Interface Type Tunnel and Tunnel Type Teredo conditions. When implemented, this filter indicates the presence of an edge traversal aware host firewall in the system. This filter is viewed as an API contract between the host firewall and Windows. By default, this filter will block edge traversed traffic to any application.
filter.layerKey = FWPM_LAYER_ALE_AUTH_RECV_ACCEPT_V6;
filter.action.type = FWP_ACTION_BLOCK;
filter.subLayerKey = FWPM_SUBLAYER_EDGE_TRAVERSAL;
filter.weight.type = FWP_UINT64;
filter.weight.uint64 = 0;
filter.flags = 0;
filter.numFilterConditions = 2; // Or 3 depending on including the loopback condition
filter.filterCondition = filterConditions;
filter.displayData.name = L"Teredo Edge Traversal Default Block";
filter.displayData.description = L"Teredo Edge Traversal Default Block Filter.";
// Match Interface type tunnel
filterConditions[0].fieldKey = FWPM_CONDITION_INTERFACE_TYPE;
filterConditions[0].matchType = FWP_MATCH_EQUAL;
filterConditions[0].conditionValue.type = FWP_UINT32;
filterConditions[0].conditionValue.uint32 = IF_TYPE_TUNNEL;
// Match tunnel type Teredo
filterConditions[1].fieldKey = FWPM_CONDITION_TUNNEL_TYPE;
filterConditions[1].matchType = FWP_MATCH_EQUAL;
filterConditions[1].conditionValue.type = FWP_UINT32;
filterConditions[1].conditionValue.uint32 = TUNNEL_TYPE_TEREDO;
// Having this condition is OPTIONAL, including this will automatically exempt
// loopback traffic to receive Teredo.
filterConditions[2].fieldKey = FWPM_CONDITION_FLAGS;
filterConditions[2].matchType = FWP_MATCH_FLAGS_NONE_SET;
filterConditions[2].conditionValue.type = FWP_UINT32;
filterConditions[2].conditionValue.uint32 = FWP_CONDITION_FLAG_IS_LOOPBACK;
Note
The 'Delivery', 'Arrival', and 'Next Hop' classes of interface conditions are used to control a weak-host model and packet forwarding across interfaces. The example above utilizes the 'Delivery' class. Please review Filtering Conditions Available at Each Filtering Layer in the WFP SDK documentation, as your security design must take each case into consideration.
Allow Filter for Exempt Applications
If an application is exempt from receiving Teredo traffic on a listening socket, a permit filter must be implemented within the ALE_AUTH_RCV_ACCEPT_V6 filtering layer on the host firewall. It is important to note that depending on how the exemption is configured by the user or application, the host firewall can include a socket option.
filter.layerKey = FWPM_LAYER_ALE_AUTH_RCV_ACCEPT_V6;
filter.action.type = FWP_ACTION_PERMIT;
filter.subLayerKey = FWPM_SUBLAYER_EDGE_TRAVERSAL;
filter.weight.type = FWP_UINT64;
filter.weight.uint64= 1; // Use a weight higher than the default block
filter.flags = 0;
filter.numFilterConditions = 3; // Or 4 depending on the socket option based condition
filter.filterCondition = filterConditions;
filter.displayData.name = L"Teredo Edge Traversal Allow Application A";
filter.displayData.description = L"Teredo Edge Traversal Allow Application A Filter.";
filterConditions[0].fieldKey = FWPM_CONDITION_INTERFACE_TYPE;
filterConditions[0].matchType = FWP_MATCH_EQUAL;
filterConditions[0].conditionValue.type = FWP_UINT32;
filterConditions[0].conditionValue.uint32 = IF_TYPE_TUNNEL;
filterConditions[1].fieldKey = FWPM_CONDITION_TUNNEL_TYPE;
filterConditions[1].matchType = FWP_MATCH_EQUAL;
filterConditions[1].conditionValue.type = FWP_UINT32;
filterConditions[1].conditionValue.uint32 = TUNNEL_TYPE_TEREDO;
FWP_BYTE_BLOB byteBlob = {0};
filterConditions[2].fieldKey = FWPM_CONDITION_ALE_APP_ID;
filterConditions[2].matchType = FWP_MATCH_EQUAL;
filterConditions[2].conditionValue.type = FWP_BYTE_BLOB_TYPE;
filterConditions[2].conditionValue.byteBlob = &byteBlob;
filterConditions[2].conditionValue.byteBlob->data = (uint8 *) wszApplicationA;
filterConditions[2].conditionValue.byteBlob->size = (wcslen(wszApplicationA) + 1)*sizeof(wchar_t);
// This filter scopes to exemption to ONLY IF the socket option is set, in other words
// application has explicitly opted in to receive Teredo traffic
filterConditions[3].fieldKey = FWPM_CONDITION_ALE_SIO_FIREWALL_SOCKET_PROPERTY;
filterConditions[3].matchType = FWP_MATCH_FLAGS_ALL_SET;
filterConditions[3].conditionValue.type = FWP_UINT32;
filterConditions[3].conditionValue.uint32 = FWP_CONDITION_SOCKET_PROPERTY_FLAG_ALLOW_EDGE_TRAFFIC;
Dormancy Callout Filter
The Teredo service in Windows implements a dormancy model. At any given time, if no applications are listening on a UDP or TCP socket with edge traversal enabled, the service moves to a dormant state. For the dormancy mechanism to work, the host firewall must maintain a callout filter for each exempt application specified within the ALE_AUTH_LISTEN_V6 filtering layer for TCP, and ALE_RESOURCE_ASSIGNMENT_V6 filtering layer for UDP based applications. The following sample below demonstrates a dormancy callout for a TCP application.
filter.layerKey = FWPM_LAYER_ALE_AUTH_LISTEN_V6;
// Use FWPM_LAYER_ALE_RESOURCE_ASSIGNMENT_V6 for UDP based exemption
filter.action.type = FWP_ACTION_CALLOUT_TERMINATING;
filter.action.calloutKey = FWPM_CALLOUT_EDGE_TRAVERSAL_ALE_LISTEN_V6;
// Use FWPM_CALLOUT_EDGE_TRAVERSAL_ALE_RESOURCE_ASSIGNMENT_V6 for UDP based exemption
filter.subLayerKey = FWPM_SUBLAYER_EDGE_TRAVERSAL;
filter.weight.type = FWP_UINT64;
filter.weight.uint64 = 1;
filter.flags = 0;
filter.numFilterConditions = 1; // 2 if including the socket option based condition
filter.filterCondition = filterConditions;
filter.displayData.name = L"Teredo Edge Traversal dormancy callout for app A";
filter.displayData.description = L"Teredo Edge Traversal dormancy callout filter for A.";
FWP_BYTE_BLOB byteBlob = {0};
filterConditions[0].fieldKey = FWPM_CONDITION_ALE_APP_ID;
filterConditions[0].matchType = FWP_MATCH_EQUAL;
filterConditions[0].conditionValue.type = FWP_BYTE_BLOB_TYPE;
filterConditions[0].conditionValue.byteBlob = &byteBlob;
filterConditions[0].conditionValue.byteBlob->data = (uint8 *)wszApplicationA;
filterConditions[0].conditionValue.byteBlob->size = (wcslen(wszApplicationA) + 1)*sizeof(wchar_t);
// This filter scopes to exemption to ONLY IF the socket option is set, in other words
// application has explicitly opted in to receive Teredo traffic
filterConditions[1].fieldKey = FWPM_CONDITION_ALE_SIO_FIREWALL_SOCKET_PROPERTY;
filterConditions[1].matchType = FWP_MATCH_FLAGS_ALL_SET;
filterConditions[1].conditionValue.type = FWP_UINT32;
filterConditions[1].conditionValue.uint32 = FWP_CONDITION_SOCKET_PROPERTY_FLAG_ALLOW_EDGE_TRAFFIC;