Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV

Before Posting...

Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


WFPSampler callout doesn't get all the packets

Save_me_O_GodSave_me_O_God Member Posts: 5

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?

Comments

  • Save_me_O_GodSave_me_O_God Member Posts: 5

    Answering my own question, stupid me: I didn't traverse NB

    I though NBL (Net Buffer List) was the only "List", and I didn't expect NB themselves are also lists.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 13-17 May 2024 Live, Online
Developing Minifilters 1-5 Apr 2024 Live, Online
Internals & Software Drivers 11-15 Mar 2024 Live, Online
Writing WDF Drivers 26 Feb - 1 Mar 2024 Live, Online