Git Product home page Git Product logo

pedigest's Introduction

pedigest

Helper functions for calculating the authenticode digest for a portable executable file. This repo complements the CiDllDemo repository.

This piece of code was originally meant to run in kernel mode but it works just as well in userland too.

Here's what you need to make this work in usermode

Link against bcrypt.lib instead of ksecdd.lib and use malloc/free instead of ExAllocatePoolWithTag/ExFreePool.

Sample usage

You need to map the PE image into system memory first. Either use ZwReadFile or ZwCreateSection / MmMapViewInSystemSpace.

UINT32 digestIdentifier;
ULONG digestSize;
ULONG securityDirSize;
PUCHAR digest = NULL;
LPWIN_CERTIFICATE cert = NULL;

NTSTATUS status = CalculatePeDigest(
  baseAddrOfView, 
  (ULONG)viewSize,
  &digestIdentifier,
  &digestSize,
  (PVOID*)&digest,
  &cert,
  &securityDirSize
);

The CalculatePeDigest function only accepts properly formatted PE/COFF files. Don't forget to check for the returned status before using the output. If the out cert is still null it means that the PE did not contain an embedded signature and you need to call CiVerifyHashInCatalog to check if the file has been signed in a catalog file.

Disclaimer

I have used a rather primitive approach of finding out the correct message digest algorithm for a given PE image: pattern matching. There are certainly more elegant and better ways of doing it. I discourage using this kind of approach in production code.

pedigest's People

Contributors

mihaly044 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.