Re: Packet Filtering API (PfSetLogBuffer)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On May 29, 10:20 am, Swando...@xxxxxxxx wrote:
On May 27, 11:33 am, Swando...@xxxxxxxx wrote:



I have a question about logging (PfSetLogBuffer) with the MS Packet
Filtering API.http://msdn.microsoft.com/en-us/library/aa376636.aspx

I know that this API is no longer supported, but it is the only option
for programmatic packet filtering on legacy (pre-Vista) Windows (i.e.
before the Windows Filtering Platform).  I only need to filter by IP
(I don't even care about port) so I would prefer not to have to write
a kernel component (an NDIS driver or filter hook driver) -- I'd
prefer to use user-mode APIs for simplicity and stability.

To my question:

I am using the Packet Filtering APIs to drop packets matching certain
IPs I want to filter.  The APIs work correctly in this regard -- they
drop the correct packets.

Now I am trying to set up logging, through the use of the PfMakeLog,
PfSetLogBuffer functions.  This does not work correctly.  In fact, it
appears to smash the stack on my Windows XP SP2 test system.

Consider the following sample function:

<code>

extern PBYTE LogBuffer;

DWORD ThreadProc( LPVOID pArg )
{
    DWORD RetVal, EntriesLogged, EntriesLost, BytesWritten;
    CHAR  buffer[ MAX_PATH ];

    for( ; ; ) {

        if( WaitForSingleObject( hEvent, INFINITE ) == WAIT_FAILED )
break;

        PBYTE NewBuffer = new BYTE[ LOG_BUFFER_SIZE ];
        RetVal = PfSetLogBuffer( NewBuffer, LOG_BUFFER_SIZE, 64, 1,
&EntriesLogged, &EntriesLost, &BytesWritten );

        PFLOGFRAME* pLogFrame = (PFLOGFRAME*) LogBuffer;

        printf( "Caught packet (rule %d)\r\n", pLogFrame-

dwFilterRule );

        delete [] LogBuffer;
        LogBuffer = NewBuffer;

        ResetEvent( hEvent );

    }

    return 0;

}

</code>

This function is spawned via CreateThread and should just wait for log
data (signaled by the hEvent I pass to PfMakeLog when I call it
earlier).

And it does print correctly the first time the function is called.

However, the second time the function is called the stack gets
smashed.  Before this call:

RetVal = PfSetLogBuffer( NewBuffer, LOG_BUFFER_SIZE, 64, 1,
&EntriesLogged, &EntriesLost, &BytesWritten );

The buffer (CHAR  buffer[ MAX_PATH ] ) contains some junk data.  After
that call, the first 8 bytes of the buffer have been overwritten with
the addresses of EntriesLost and BytesWritten.  I did not pass the
address of the char buffer to the PfSetLogBuffer function at all.
Therefore, it is somehow overwriting the stack.

In addition, after the second call to this function, the program
segfaults and dies.  Given that the char buffer is being overwritten,
I assume there is more massive memory/stack corruption somewhere, and
indeed if I try to unwind the stack with a debugger afterwards the
frame has been totally corrupted.

I do not understand what is going on here.  I must be doing something
wrong, but I can't see what.  Or are the APIs just buggy?

Thank you very much for any light anyone can shed.

Anyone?

I apologize for wasting everyone's time. I found the answer to the
problem, and it has nothing to do with the APIs or the actual code.
My compiler was using a bad calling convention and the stack was being
"cleaned up" twice.
.



Relevant Pages

  • Re: sygate 5.5 free not active ?
    ... This is PoC code, not working attack code. ... > The second was caught by the software firewall I use and likewise didn't ... because the new Zone Alarm Pro versions are filtering Windows messages. ...
    (comp.security.firewalls)
  • Re: sygate 5.5 free not active ?
    ... This is PoC code, not working attack code. ... > The second was caught by the software firewall I use and likewise didn't ... because the new Zone Alarm Pro versions are filtering Windows messages. ...
    (comp.security.firewalls)
  • Re: Master list of registered IPs?
    ... > Not really - 169.254/16 can be used as a source or destination on the ... >>Ingress filtering, but not egress filtering, which is a good idea as ... > traffic inbound on those ports, then silently drop that range of inbound ... expose local windows shares. ...
    (comp.unix.questions)
  • Re: GPO to push out 2 different version of office.
    ... > Right now I have windows 2003 server with windows xp Clients. ... > I understand GPO priority but How does that work if one GPO says ... This may be one of those uncommon reasons for preferring filtering. ...
    (microsoft.public.win2000.active_directory)
  • Re: question about reconstruction windows with STFT-synthesis
    ... Spectrum estimation by ... Frequency domain FIR filtering using overlap-add block processing. ... that describes such windows. ...
    (comp.dsp)