core

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2023 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (
	FATAL     = 5
	ERROR     = 4
	IMPORTANT = 3
	WARN      = 2
	INFO      = 1
	DEBUG     = 0
)
View Source
const (
	TempDirSuffix          = "SecretScanning"
	ExtractedImageFilesDir = "ExtractedFiles"
)

Variables

Functions

func ContainsBlacklistedString

func ContainsBlacklistedString(input []byte) bool

ContainsBlacklistedString Checks if the input contains a blacklisted string

func CreateRecursiveDir

func CreateRecursiveDir(completePath string) error

CreateRecursiveDir Create directory structure recursively, if they do not exist @parameters completePath - Complete path of directory which needs to be created @returns Error - Errors if any. Otherwise, returns nil

func DeleteFiles

func DeleteFiles(path string, wildCard string)

DeleteFiles Delete all the files and dirs recursively in specified directory @parameters path - Directory whose contents need to be deleted wildcard - patterns to match the filenames (e.g. '*')

func DeleteTmpDir

func DeleteTmpDir(outputDir string) error

DeleteTmpDir Delete the temporary directory @parameters outputDir - Directory which need to be deleted @returns Error - Errors if any. Otherwise, returns nil

func GetCurrentTime

func GetCurrentTime() string

func GetEntropy

func GetEntropy(data string) (entropy float64)

func GetHash

func GetHash(s string) string

func GetJsonFilepath

func GetJsonFilepath(input string) (string, error)

GetJsonFilepath Return complete path and filename for json output file @parameters image - Name of the container image or dir, for which json filename and path will be created @returns string - Sanitized string which can used as path and filename of json output file Error - Errors if path can't be created. Otherwise, returns nil

func GetTimestamp

func GetTimestamp() int64

func GetTmpDir

func GetTmpDir(imageName string) (string, error)

GetTmpDir Create a temporrary directory to extract the conetents of container image @parameters imageName - Name of the container image @returns String - Complete path of the based directory where image will be extracted, empty string if error Error - Errors if any. Otherwise, returns nil

func IsSkippableDir

func IsSkippableDir(path string, baseDir string) bool

IsSkippableFile Checks if the path is blacklisted

func IsSkippableFileExtension

func IsSkippableFileExtension(path string) bool

IsSkippableFileExtension Checks if the file extension is blacklisted

func IsSymLink(path string) bool

IsSymLink Check if input is a symLink, not normal file/dir path - Pathname which needs to be checked for symbolic link @returns bool - Return true if input is a symLink

func LogIfError

func LogIfError(text string, err error)

func PathExists

func PathExists(path string) bool

func Pluralize

func Pluralize(count int, singular string, plural string) string

func UpdateDirsPermissionsRW

func UpdateDirsPermissionsRW(dir string)

UpdateDirsPermissionsRW Update permissions for dirs in container images, so that they can be properly deleted

Types

type Config

type Config struct {
	BlacklistedStrings           []string          `yaml:"blacklisted_strings"`
	BlacklistedExtensions        []string          `yaml:"blacklisted_extensions"`
	BlacklistedPaths             []string          `yaml:"blacklisted_paths"`
	ExcludePaths                 []string          `yaml:"exclude_paths"`
	BlacklistedEntropyExtensions []string          `yaml:"blacklisted_entropy_extensions"`
	Signatures                   []ConfigSignature `yaml:"signatures"`
}

func ParseConfig

func ParseConfig(options *Options) (*Config, error)

func (*Config) Merge added in v1.0.9

func (c *Config) Merge(in *Config)

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

type ConfigSignature

type ConfigSignature struct {
	Name          string `yaml:"name"`
	Part          string `yaml:"part"`
	Match         string `yaml:"match,omitempty"`
	Regex         string `yaml:"regex,omitempty"`
	RegexType     string `yaml:"regextype,omitempty"`
	CompiledRegex *regexp.Regexp
	Verifier      string  `yaml:"verifier,omitempty"`
	Severity      string  `yaml:"severity,omitempty"`
	SeverityScore float64 `yaml:"severityscore,omitempty"`
	ID            int     `yaml:"ID,omitempty"`
}

type Logger

type Logger struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(format string, args ...interface{})

func (*Logger) Important

func (l *Logger) Important(format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(level int, format string, args ...interface{})

func (*Logger) SetDebugLevel

func (l *Logger) SetDebugLevel(d string)

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...interface{})

type MatchFile

type MatchFile struct {
	Path      string
	Filename  string
	Extension string
	Contents  []byte
}

func NewMatchFile

func NewMatchFile(path string) MatchFile

NewMatchFile Creates a new Matchfile data structure

func (MatchFile) CanCheckEntropy

func (match MatchFile) CanCheckEntropy() bool

CanCheckEntropy Checks if entropy based scanning is appropriate for this file

type Options

type Options struct {
	Threads         *int
	DebugLevel      *string
	MaximumFileSize *uint
	TempDirectory   *string
	Local           *string
	HostMountPath   *string
	ConfigPath      *repeatableStringValue
	MergeConfigs    *bool
	OutputPath      *string
	JsonFilename    *string
	ImageName       *string
	MultipleMatch   *bool
	MaxMultiMatch   *uint
	MaxSecrets      *uint
	ContainerId     *string
	ContainerNS     *string
	Quiet           *bool
}

func ParseOptions

func ParseOptions() (*Options, error)

type Session

type Session struct {
	sync.Mutex
	Version string
	Options *Options
	Config  *Config
	Context context.Context
	Log     *Logger
}

func GetSession

func GetSession() *Session

func (*Session) InitLogger

func (s *Session) InitLogger()

func (*Session) InitThreads

func (s *Session) InitThreads()

func (*Session) Start

func (s *Session) Start()

Jump to

Keyboard shortcuts

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