Louis Lafreniere: Next Generation Buffer Overrun Protection with /GS++

Sign in to queue

The Discussion

  • User profile image
    sokhaty

    Good video. It's been quite a while I had to write anything in C/C++, so excuse my ignorance.

    But, is there a utility to quickly check if an executable or a DLL contains modules that were compiled with /gs or /gs++ flag? In another words to do some sort of a static analysis of program binaries to have at least some level of confidence that it was hardened against buffer overflows?

    Cheers,

    Seva.

  • User profile image
    louisl

    Microsoft does have an internal tool which groups are required to run before shipping binaries.  This tool ensures several things, and one of these is that /GS was enabled on each modules.  It also requires the binaries to be compiled by a certain minimum compiler version.  So once Dev10 ships and the tool sets the minimum bar to Dev10, it will guarantee all Microsoft products are compiled with /GS++.

    This tool isn't available externally AFAIK, but someone could easily write their own.  The tool looks at the .pdb file.  Using DIA, you could look to make sure each module has /GS using IDiaSymbol::get_hasSecurityChecks().

            -- Louis Lafreniere

  • User profile image
    sokhaty

    Thank you for the pointers, Louis.

    Is there anything that can be used in cases when binaries are coming not from the internal dev.team or a major vendor, like Microsoft, and there is no .pdbs immediately available? Is it possible to blindly search for a sequence of machine code instructions (naive signature matching)? Or in this case /gs injected code "optimized out beyond recognition"?

    Best,

    Seva.

  • User profile image
    louisl

    Plain GS frames are pretty easy to find in disassembly.  Plain GS frames look like:

    sub     esp, 16
    mov     eax, DWORD PTR ___security_cookie
    xor       eax, ebp|esp
    mov     DWORD PTR __$ArrayPad$[ebp|esp], eax

    The scheduler can sometimes interleave some instructions in there.  EH frames are quite a bit trickier to find if compiled for size however, because we use helper calls (like __EH_prolog3_GS) to setup/unlink the frames.  But you could look for the helper code in the image (there are multiple versions to look for), and search for calls to it.  Depending on coding styles though, GS frames can be pretty rare...  Some code doesn't need stack buffers or local structs.  So not finding one doesn't mean the code isn't compiled with /GS.

          -- Louis Lafreniere

  • User profile image
    sokhaty

    Outstanding, it doesn't even look all that scary Smiley A lot of thanks, Louis!

  • User profile image
    Jason Fossen

    Great video!  At the end you mention that Windows 7 was built using /GS++ to some extent.  For the record, so to speak, can you say more about what percentage and/or types of binaries in Windows 7 and Server 2008-R2 were compiled with /GS++ please?  And how much would you attribute the improved performance of Win7 over Vista to the new compiler optimizations? 

     

    It would be good for Windows 7 if you could provide some definitive detail here, since security enhancements are one of the main reasons a company would choose to migrate from XP to 7 sooner rather than later, and things like /GS++ might be important to a CISO at a large organization who needs to justify his/her recommendation to upper management. 

     

    Thank You!

     

  • User profile image
    Charles

    Well, not really. Windows was used for /gs++ testing. That's what Louis was referring to. The actual shipping version of Windows 7 was not compiled with /gs++ (because /gs++ doesn't ship until VS 2010 ships - would we use a beta compiler technology to build a shipping product?) 

     

    So, to be clear: /gs++ was not used for compiling any part of shipping versions of Windows 7.

    C

  • User profile image
    mattthom

    >is there a utility to quickly check if an executable or a DLL contains modules that were compiled with /gs or /gs++ flag?

    in fact, there is! we just released BinScope that does exactly this check, along with a number of other security checks.

     

    https://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=90e6181c-5905-4799-826a-772eafd4440a 

  • User profile image
    petersan

    thanks a lot

     

    comlandcomputerslanditcomputer
    computerslookup
    batchsevenwebhosting.org

Add Your 2 Cents