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 ¶
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`.
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 ¶
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").