Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PE: Possible invalid value for security_cookie #537

Closed
Wenzel opened this issue Jan 26, 2021 · 4 comments
Closed

PE: Possible invalid value for security_cookie #537

Wenzel opened this issue Jan 26, 2021 · 4 comments
Assignees
Labels
Good First Issue Issue that can be addressed without an in-depth understanding of LIEF

Comments

@Wenzel
Copy link

Wenzel commented Jan 26, 2021

Describe the bug
requesting the load_configuration.security_cookie can return an invalid value.

To Reproduce
Steps to reproduce the behavior:

  • download cmd.zip and uncompress it to get cmd.exe (winxp executable
  • load it with lief in python
  • get the security cookie
In [1]: import lief

In [2]: pe = lief.parse("/home/wenzel/local/cmd.exe")
Unable to find the section associated with BOUND_IMPORT

In [3]: pe.load_configuration.security_cookie
Out[3]: 1255357304

Expected behavior
The issue is that winchecksec is telling me that cmd.exe doesn't have a stack cookie:

$ winchecksec cmd.exe
Dynamic Base    : "NotPresent"
ASLR            : "NotPresent"
High Entropy VA : "NotPresent"
Force Integrity : "NotPresent"
Isolation       : "Present"
NX              : "NotPresent"
SEH             : "Present"
CFG             : "NotPresent"
RFG             : "NotPresent"
SafeSEH         : "NotPresent"
GS              : "NotPresent"
Authenticode    : "NotPresent"
.NET            : "NotPresent"

And winchecksec GS check is implemented here, by verifying that the security cookie is != 0.
So, assuming that winchecksec is correct, lief should return 0 and not 1255357304

Environment (please complete the following information):

  • System and Version : Ubuntu 20.04
  • Target format PE
  • LIEF commit version: 0.11.0-f58605f but also reproductible with 0.10.0

Thanks !

@romainthomas romainthomas added the Good First Issue Issue that can be addressed without an in-depth understanding of LIEF label Mar 29, 2021
@sudhackar
Copy link

sudhackar commented Nov 30, 2021

I looked at this issue. I used pefile as a reference since I have used it in the past

In [1]: import pefile

In [2]: pe = pefile.PE("/tmp/cmd.exe")

In [3]: hex(pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SecurityCookie)
Out[3]: '0x4ad33b78'

pestudio says the file had

image

Looking at this I looked at other implementations and libraries I have looked at in the past -
https://github.com/saferwall/pe/blob/main/loadconfig.go#L118
matches the size 0x48 identified by the pestudio and it has a SecurityCookie field and building a sample program like such also prints the same cookie

package main

import (
        "log"

        peparser "github.com/saferwall/pe"
)

func main() {
        filename := "/tmp/cmd.exe"
        pe, err := peparser.New(filename, nil)
        if err != nil {
                log.Fatalf("Error while opening file: %s, reason: %v", filename, err)
        }

        err = pe.Parse()
        if err != nil {
                log.Fatalf("Error while parsing file: %s, reason: %v", filename, err)
        }

        log.Printf("%x\n", pe.LoadConfig.LoadCfgStruct.(peparser.ImageLoadConfigDirectory32v2).SecurityCookie)
}
(test3) [petest] ./petest
2021/11/30 13:52:50 4ad33b78

I don't know what to use as a source of truth maybe @Wenzel can help?

@sudhackar
Copy link

sudhackar commented Nov 30, 2021

Also are you sure you ran winchecksec with this attached file?

[build] ./winchecksec -j /tmp/cmd.exe | jq -r ".[].mitigations.gs.presence"
Present
[build] ./winchecksec /tmp/cmd.exe
Results for: /tmp/cmd.exe
Dynamic Base    : "NotPresent"
ASLR            : "NotPresent"
High Entropy VA : "NotPresent"
Force Integrity : "NotPresent"
Isolation       : "Present"
NX              : "NotPresent"
SEH             : "Present"
CFG             : "NotPresent"
RFG             : "NotPresent"
SafeSEH         : "Present"
GS              : "Present"
Authenticode    : "NotPresent"
.NET            : "NotPresent"
[build] md5sum /tmp/cmd.exe
eeb024f2c81f0d55936fb825d21a91d6  /tmp/cmd.exe

@sudhackar
Copy link

sudhackar commented Nov 30, 2021

This is what IDA thinks as well
image
image

@romainthomas
Copy link
Member

I guess this is fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good First Issue Issue that can be addressed without an in-depth understanding of LIEF
Projects
None yet
Development

No branches or pull requests

3 participants