【问题标题】:How to say if a binary is GS compiled or not, and without symbols?如何判断二进制文件是否经过 GS 编译且没有符号?
【发布时间】:2011-12-11 09:50:46
【问题描述】:

我希望能够确定二进制文件是否经过 GS 编译? /GS 是缓冲区安全检查,使用 cookie。我希望能够在没有符号的情况下以通用的方式找到它。

BinScope 在尝试检查 GS 时为我提供以下信息: E_PDB_NO_DEBUG_INFO(PDB 被剥夺 cv 信息)

有什么想法吗?

【问题讨论】:

    标签: debugging compiler-construction compilation reverse-engineering reverse


    【解决方案1】:

    如果您没有 PDB,除了检查二进制文件并查看函数之外,没有其他好方法可以做到这一点。我原以为应该可以检查记录安全 cookie 位置的 loadconfig 目录,但这并不好。即使程序使用 /GS- 编译,链接的 CRT 函数仍然使用 cookie:

    >dumpbin /loadconfig test.exe
    
    Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    
    Dump of file test.exe
    
    File Type: EXECUTABLE IMAGE
    
      Section contains the following load config:
    
                00000048 size
                       0 time date stamp
                    0.00 Version
                       0 GlobalFlags Clear
                       0 GlobalFlags Set
                       0 Critical Section Default Timeout
                       0 Decommit Free Block Threshold
                       0 Decommit Total Free Threshold
                00000000 Lock Prefix Table
                       0 Maximum Allocation Size
                       0 Virtual Memory Threshold
                       0 Process Heap Flags
                       0 Process Affinity Mask
                       0 CSD Version
                    0000 Reserved
                00000000 Edit list
       >        00408000 Security Cookie      <
                00407840 Safe Exception Handler Table
                       3 Safe Exception Handler Count
    
        Safe Exception Handler Table
    
              Address
              --------
              004025D0
              00404200
              00405160
    

    【讨论】:

      【解决方案2】:

      如果您的二进制文件没有“加载配置”(例如 windows mobile 二进制文件) 我认为识别模式仍然很容易:

      许多函数如下所示:

      ... [function entry]
      .text:01005188                 mov     eax, ___security_cookie
      .text:0100518D                 mov     [ebp+var_1C], eax
      ... [function body]
      .text:010057F6                 mov     ecx, [ebp+var_1C]
      .text:010057F9                 call    sub_1007147
      ... [function exit]
      

      那么 sub_1007147 看起来像这样:

      .text:01007147                 cmp     ecx, ___security_cookie
      .text:0100714D                 jnz     short loc_1007158
      .text:0100714F                 test    ecx, 0FFFF0000h
      .text:01007155                 jnz     short loc_1007158
      .text:01007157                 retn
      

      引用与其逆向存储在一起的cookie:

      .data:01009600 dword_1009600   dd 0FFFF44BFh
      .data:01009604 ___security_cookie dd 0BB40h
      

      __security_cookie 将有很多引用,而前面的逆只有几个。

      在初始化列表中会有一个用一些伪随机值初始化cookie的函数。

      在二进制文件中搜索这些模式应该可以让您了解是否使用了 /GS。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-09-24
        • 2023-03-03
        • 2022-01-24
        • 2023-03-10
        • 2013-11-24
        相关资源
        最近更新 更多