I’m using WFPSampler and I want to log each and every single packet.
The callout PerformBasicPacketExaminationAtOutboundNetwork
handles packets at FWPS_LAYER_OUTBOUND_IPPACKET_V4
layer
And I added a DbgPrint
that will be called whenever there’s a TCP packet destined to port 4000.
(I’ve written a script to send files to TCP port 4000)
status = KrnlHlprIPHeaderGet((NET_BUFFER_LIST*)pClassifyData->pPacket,
&pHeader,
&needToFreeMemory,
ipHeaderSize);
...
if(KrnlHlprFwpsLayerIsIPv4(pClassifyValues->layerId))
{
IP_HEADER_V4* pIPv4Header = (IP_HEADER_V4*)pHeader;
if (pIPv4Header && pIPv4Header->protocol == IPPROTO_TCP)
{
USHORT ipHeaderSize2 = pIPv4Header->headerLength * 4;
TCP_HDR* tcpHeader = (TCP_HDR*)((UCHAR*)pIPv4Header + ipHeaderSize2);
if (htons(tcpHeader->th_dport) == 4000)
{
**DbgPrint**( // <--- what I've done
"[T: %p] [Sport: %u] [Dport: %u] [Total len: %u] Receiving an IPV4 TCP packet, seq: %u\n",
KeGetCurrentThread(),
htons(tcpHeader->th_sport),
htons(tcpHeader->th_dport),
pIPv4Header->totalLength,
htonl(tcpHeader->th_seq));
And I found out that the amount of times that this DbgPrint
gets printed is much fewer than the actual amount of packets that were sent.
For example WireShark
shows that there are 44351 packets (all are outbound packets).
But my DbgPrint was printed only 3578 times, whose sequences can all be found in the WireShark pcap
file.
Note: I’ve made sure the packets are correctly filtered, all of the 44351 packets were in the outbound direction, and having destination port to 4000.
**Seems like a WFP callout doesn't get all the packets, why is that?**