Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the digital signature stored when code signing a exe file in windows?

As stated in the question title. However, I am using a "trick" where i store extra data after the executable to be used at runtime (see here).

Signing my executable appears to break this 'trick' however, so my question is where is the signature stored in the exe (PE) file?

I am usingsigntool from microsoft to sign my executable.

like image 908
horseyguy Avatar asked Dec 05 '17 04:12

horseyguy


People also ask

How do I find the signature of an EXE file?

Check the signature on an EXE or MSI file Right-click the EXE or MSI file and select Properties. Click the Digital Signatures tab to check the signature.

Where is digital signature stored?

Click File > Info > View Signatures. In the list, on a signature name, click the down-arrow, and then click Signature Details.

What is digital signature for exe files?

Executable signing certificates, commonly referred to as code signing certificates, are digital files you can use to digitally sign executable files (.exe files). The code signing certificate uses a cryptographic hash that validates the executable file's integrity and authenticity.

How is digital signature stored?

When a signer digitally signs a document, a cryptographic hash is generated for the document. That cryptographic hash is then encrypted using the sender's private key, which is stored in a secure HSM box. It is then appended to the document and sent to the recipients along with the sender's public key.


2 Answers

An embedded digital signature is always appended to the end of the executable file, whether or not you have custom data attached to it. The attached data is included in the hash of the signature.

The location and size of the signature is stored in the security directory of the PE header. Extracting that information goes like this:

  • Locate and read the IMAGE_OPTIONAL_HEADER of the PE file.
  • IMAGE_OPTIONAL_HEADER::DataDirectory is an array of IMAGE_DATA_DIRECTORY structures. Index it by IMAGE_DIRECTORY_ENTRY_SECURITY (undocumented but declared in winnt.h) to locate the entry of the security directory.
  • IMAGE_DATA_DIRECTORY::VirtualAddress contains the file offset (not the RVA) of the signature and IMAGE_DATA_DIRECTORY::Size contains the size of the signature.

References:

  • PE Format (MSDN)
  • Peering inside the PE (somewhat more readable, with examples)
  • IMAGE_DATA_DIRECTORY values
  • The Case of the Missing Digital Signatures Tab
like image 186
zett42 Avatar answered Oct 06 '22 08:10

zett42


The format of a signed PE file is documented by Microsoft:

Windows Authenticode Portable Executable Signature Format [This link downloads a WORD doc]

like image 22
Remy Lebeau Avatar answered Oct 06 '22 09:10

Remy Lebeau