pefiles

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pefiles is the sensor for cryptographic libraries that live as loose files rather than in a package database, which is how most of them exist on Windows (an application bundles its own OpenSSL, NSS or GnuTLS).

It walks a small, allow-listed set of install locations and opens only files whose *names* match a recognised crypto-library pattern. For each it reports a `present` observation by name (heuristic) and, when the file is a well-formed PE image, a second one from its version resource (parsed). It never opens keys, certificates or any other file, never loads or runs anything, and never verifies signatures (Authenticode's revocation checks can reach the network, which a collector must not do: ADR-0004).

A name match alone never yields a capability (ADR-0002): a decoy file called libcrypto-3-x64.dll that is not a PE is listed as present and nothing more.

Index

Constants

View Source
const (
	// Name is the sensor's registry name.
	Name = "pe-files"
	// Version is the version of this sensor's behaviour.
	Version = "0.1.0"
)

Variables

View Source
var ErrNotPE = errors.New("pefiles: not a PE image")

ErrNotPE means the file is not a PE image (a decoy, a text file, a truncated download).

Functions

func ReadImports

func ReadImports(r io.ReaderAt, size int64) ([]string, error)

ReadImports returns the library names in the image's static import table (lower-cased, without duplicates, in file order). Delay-loaded and dynamically loaded libraries are not in this table, so an absent name proves nothing.

The names are chosen by whoever built the file: each is capped, must be printable ASCII, and anything else is skipped rather than reported. It returns ErrNotPE for a file that is not a well-formed PE image, and no names (and no error) for a valid image with no import table.

Types

type Sensor

type Sensor struct {
	// contains filtered or unexported fields
}

Sensor implements sense.Sensor.

func New

func New(env sense.Env) *Sensor

New returns a sensor reading the host described by env.

func (*Sensor) Collect

func (s *Sensor) Collect(ctx context.Context) (evidence.Batch, error)

Collect walks the search locations and returns the observations.

func (*Sensor) Detect

func (s *Sensor) Detect(context.Context) (bool, error)

Detect reports whether any search location exists on the host.

func (*Sensor) Info

func (*Sensor) Info() sense.Info

Info implements sense.Sensor.

type VersionInfo

type VersionInfo struct {
	// File is the file version, dotted ("3.5.7.0") from the fixed-size structure
	// when present, else the FileVersion string. Empty when the resource has none.
	File    string
	Product string // ProductName string
	Arch    string // "amd64", "x86", "arm64" or ""
}

VersionInfo is what a PE's version resource says. Both strings are chosen by whoever built the file (or tampered with it): they are evidence of what the file claims, not proof of what it is.

func ReadVersion

func ReadVersion(r io.ReaderAt, size int64) (VersionInfo, error)

ReadVersion reads the version resource of the PE image in r (of the given size). It returns ErrNotPE for anything that is not a well-formed PE image. A valid image with no version resource returns a Version with only Arch set.

Directories

Path Synopsis
Package pefilestest builds small, valid PE images with a version resource, so the PE parser, the sensor and the pipeline are tested on any OS without shipping real binaries.
Package pefilestest builds small, valid PE images with a version resource, so the PE parser, the sensor and the pipeline are tested on any OS without shipping real binaries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL