source

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package source feeds files to the scanner from a directory tree or a container image's flattened filesystem, and records every file it could not read so a scan never claims coverage it did not have.

Only two kinds of file are read in full: executables (ELF, Mach-O, PE), which may be PHP runtimes, and the package-database files the caller asks for. Everything else is identified from its first bytes and passed over.

Index

Constants

This section is empty.

Variables

View Source
var ContainerStorage = []string{"/var/lib/docker/", "/var/lib/containerd/", "/var/lib/containers/", "/var/snap/docker/common/var-lib-docker/"}

ContainerStorage holds container image layers. Lower layers keep files that the running image replaced, so scanning them as a filesystem reports copies nothing runs. Scan the images themselves with `php2shell-scan image`.

View Source
var DefaultExcludes = []string{"/proc/", "/sys/", "/dev/"}

DefaultExcludes are pseudo-filesystems, applied when scanning a system root. Pseudo-filesystems mounted anywhere else are also detected by type (pseudoFS).

Functions

This section is empty.

Types

type File

type File struct {
	Path string
	Data []byte
	// Executable is true when the file starts like an ELF, Mach-O or PE file.
	Executable bool
}

File is one regular file's absolute path (within the scanned root) and content.

type Options

type Options struct {
	// MaxFileSize: executables larger than this are skipped and recorded.
	MaxFileSize int64
	// Exclude lists absolute path prefixes inside the root to skip entirely.
	Exclude []string
	// Wanted selects non-executable files to read in full (package databases).
	Wanted func(abs string) bool
	// IsExecutable decides from a file's first bytes whether to read it.
	IsExecutable func(head []byte) bool
	// Symlink receives every symbolic link (absolute path, target as written).
	Symlink func(abs, target string)
	// Hardlink receives every tar hard link (absolute path, absolute path of the
	// file it names, which appeared earlier in the stream).
	Hardlink func(abs, target string)
}

Options control what is read.

type Skip

type Skip struct {
	Path   string `json:"path"`
	Reason string `json:"reason"`
	// Excluded is true for deliberate exclusions (pseudo-filesystems, container
	// storage), which do not make a scan incomplete.
	Excluded bool `json:"excluded,omitempty"`
}

Skip records a file or directory that was not scanned, and why.

func Dir

func Dir(root string, opts Options, visit Visitor) ([]Skip, int, error)

Dir walks root without following symlinks. Paths passed to visit are absolute within root ("/usr/bin/php" for root "/" and for an extracted image at "./rootfs").

func Tar

func Tar(r io.Reader, opts Options, visit Visitor) ([]Skip, int, error)

Tar reads a flattened filesystem tar stream (an image's final filesystem, or a `docker export`). Whiteouts must already be applied by the caller. Hard links name a file that appears earlier in the stream, so they are not read again.

type Visitor

type Visitor func(File) error

Visitor receives each file read. Returning an error stops the walk.

Jump to

Keyboard shortcuts

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