Giter Club home page Giter Club logo

generate-cat-file's Introduction

Generate Microsoft Security Catalog (.cat) files

When building Windows drivers for 64 bit versions of Windows a Microsoft Security Catalog (.cat) file is required when the driver is added to the driver store. This file contains SHA1 hashes of other files used by the driver (usually the mydriver.sys and the mydriver.inf file). To date as of my knowledge there is no open source implementation that does not depend on the wintrust.dll library (which would require either a Windows build machine or wine which unfortunately does not implement this particular feature). So I wrote a small C program from scratch that creates the .cat file.

Usage

You would normally use the utility via the gencat.sh (bash) shell script as follows:

./gencat.sh -o mydriver.cat -h myhardwareID mydriver.inf mydriver.sys

So for (example) WinDRBD the command line would be:

generate-cat-file/gencat.sh -o windrbd.cat-unsigned -h windrbd windrbd.inf windrbd.sys

Note that the gencat just generates the cat file with the SHA1 hashes of the files you specify on the command line (mydriver.inf and mydriver.sys in our example). It does not sign the .cat file. Signing a cat file (and also a .sys file) can be done with the osslsigncode utility, which is also open source and runs on Linux. Be sure to pick a modern (2022) version of osslsigncode since .cat file support was only added recently.

Building the C programs

There are two C programs: generate-cat-file.c and strip-pe-image. To compile them any C compiler that supports the C99 standard (required for the bool datatype) should be sufficient. There are no library dependencies for the C programs. To build them run (from the project root file):

make

To install them on your system, do

sudo make install

which would install it into /usr/local/bin.

The only other dependency that comes to my mind is that the sha1sum utility must be installed on your system which is usually the case.

About the .cat file format

Cat files are at least in theory PKCS7 encoded binary files which are described in ASN.1 syntax. ASN.1 is a meta language for data structures that originates in the early 1980's when every single byte counted. Therefore it is a rather complex data structure. Furthermore there are different encodings on the binary level for this data structure. .cat files use the ASN.1 DER format.

Instead of reading through the various definitions I used a (publically available) ASN.1 DER parser written in Java script to understand the format. The URL of this parser is:

http://lapo.it/asn1js/

Furthermore this introduction to the DER encoding was very useful:

https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/

As a last step it was neccessary to strip existing signatures and their checksums from a .sys file (which is similar to an .exe file) when the SHA1 checksum was computed. This allows for changing signatures in the .sys file later without having to rebuild the .cat file.

generate-cat-file's People

Contributors

johannesthoma 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.