search

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DiscoverAndSaveShares

func DiscoverAndSaveShares(host, username, password string) (string, error)

DiscoverAndSaveShares discovers SMB shares on a host and saves them to a temp file

func DiscoverShares

func DiscoverShares(host, username, password string, config *SearchConfig) (map[string]*smb2.Share, error)

func LoadPatternsFromFile

func LoadPatternsFromFile(filename string) ([]string, error)

LoadPatternsFromFile loads search patterns from a file

func MountShares

func MountShares(session *smb2.Session, shareNames []string, config *SearchConfig) map[string]*smb2.Share

func SearchMultipleSharesStream

func SearchMultipleSharesStream(fs map[string]*MountedShare, config *SearchConfig, fileContentCache *scanner.FileContentCache, resultsChan chan<- *SearchResult) error

SearchMultipleSharesStream faz busca em múltiplos shares e envia resultados em tempo real para o canal

func SearchShare

func SearchShare(fs *smb2.Share, shareName string, startPath string, config *SearchConfig, results chan<- *SearchResult, fileContentCache *scanner.FileContentCache) error

SearchShare searches a mounted SMB share for files matching the search criteria

Types

type CacheEntry

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

type CircuitBreaker

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

CircuitBreaker implementation

func NewCircuitBreaker

func NewCircuitBreaker(threshold int32, timeout time.Duration) *CircuitBreaker

func (*CircuitBreaker) Execute

func (cb *CircuitBreaker) Execute(operation func() error) error

type DirCache

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

DirCache implementation

func NewDirCache

func NewDirCache(ttl time.Duration) *DirCache

func (*DirCache) Get

func (dc *DirCache) Get(path string) ([]os.FileInfo, bool)

func (*DirCache) Set

func (dc *DirCache) Set(path string, entries []os.FileInfo)

type FileJob

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

type FileTypeCache

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

FileTypeCache armazena os tipos de arquivo detectados

type LeetSpeakMap

type LeetSpeakMap map[string][]string

LeetSpeakMap define o mapeamento de caracteres para suas variações leet speak

type MountedShare added in v1.5.4

type MountedShare struct {
	Share     *smb2.Share
	StartPath string
	ShareName string
}

MountedShare represents a mounted SMB share with an optional start path

type SearchConfig

type SearchConfig struct {
	// Search by filename patterns
	SearchFilenames  bool
	FilenamePatterns []string

	// Search by content patterns
	SearchContents  bool
	ContentPatterns []string

	// Search by regex patterns
	SearchRegex   bool
	RegexPatterns []*regexp.Regexp

	// Maximum file size to search (in bytes)
	MaxFileSize int64

	// File extensions to search
	FileExtensions []string

	// Verbose output
	Verbose bool

	// Case sensitive search (default: false)
	CaseSensitive bool

	// Restrict search to share root (default: true)
	RestrictToShareRoot bool

	// Timeout for search operations (default: 5 minutes)
	Timeout time.Duration

	// Skip special shares like IPC$ (default: true)
	SkipSpecialShares bool

	// Maximum directory depth for recursive search (default: 10)
	MaxDepth int

	// Extra verbose logging (default: false)
	ExtraVerbose bool

	// Maximum workers for parallel processing
	MaxWorkers int

	// Buffer size for worker pool
	BufferSize int

	// Directory cache TTL
	DirCacheTTL time.Duration

	// Maximum circuit breaker threshold
	CircuitBreakerThreshold int

	// Enable search in binary files (default: false)
	SearchBinary bool

	// Minimum string length for binary extraction
	MinBinaryStringLen int

	// Maximum cache file size for content (em bytes)
	MaxCacheFileSize int64

	// Adiciona flag para filtrar arquivos grandes no modo no-copy
	FilterLargeFiles bool

	// Lista de shares a serem excluídos da busca (pode ser sobrescrita por config)
	ExcludedShares []string

	// Patterns or extensions to exclude from copy
	ExcludePatterns []string

	// Minimum date for filtering files
	MinDate time.Time

	// Maximum date for filtering files
	MaxDate time.Time

	// Delay entre operações SMB para evitar sobrecarga do servidor
	OperationDelay time.Duration
}

SearchConfig holds the configuration for file searching

func NewSearchConfig

func NewSearchConfig() *SearchConfig

NewSearchConfig creates a new search configuration with default values

func (*SearchConfig) AddContentPattern

func (c *SearchConfig) AddContentPattern(pattern string)

AddContentPattern adds a content pattern to search for

func (*SearchConfig) AddFileExtension

func (c *SearchConfig) AddFileExtension(ext string)

AddFileExtension adds a file extension to the list of extensions to search

func (*SearchConfig) AddFilenamePattern

func (c *SearchConfig) AddFilenamePattern(pattern string)

AddFilenamePattern adds a filename pattern to search for

func (*SearchConfig) AddRegexPattern

func (c *SearchConfig) AddRegexPattern(pattern string) error

AddRegexPattern adds a regex pattern to search for

type SearchPatterns

type SearchPatterns struct {
	Patterns struct {
		Credentials  []string     `yaml:"credentials"`
		Sensitive    []string     `yaml:"sensitive"`
		Extensions   []string     `yaml:"extensions"`
		Regex        []string     `yaml:"regex"`
		LeetSpeakMap LeetSpeakMap `yaml:"leet_speak_map"`
		SearchConfig struct {
			CaseSensitive  bool     `yaml:"case_sensitive"`
			MaxFileSize    int64    `yaml:"max_file_size"`
			Exclude        []string `yaml:"exclude"`
			ExcludedShares []string `yaml:"excluded_shares"`
			MaxDepth       int      `yaml:"max_depth"`
		} `yaml:"search_config"`
	} `yaml:"patterns"`
}

func LoadPatterns

func LoadPatterns(filename string) (*SearchPatterns, error)

func MergePatterns

func MergePatterns(cmdPatterns, filePatterns *SearchPatterns) *SearchPatterns

MergePatterns combina padrões da linha de comando com padrões do arquivo Se flags de busca (-m, -e, -r) forem passadas, só o leet_speak_map do arquivo é mantido

func (*SearchPatterns) ProcessLeetSpeak

func (sp *SearchPatterns) ProcessLeetSpeak(word string) []string

ProcessLeetSpeak gera variações de uma palavra usando o mapeamento leet speak

type SearchResult

type SearchResult struct {
	ShareName    string
	FilePath     string
	MatchValue   string
	MatchType    string // "filename", "content", "regex", "extension", "large_file"
	FileSize     int64
	IsDirectory  bool
	ContentMatch string // Conteúdo encontrado no arquivo
	RegexMatch   string // Padrão regex que deu match
}

SearchResult represents a search result

func SearchMultipleShares

func SearchMultipleShares(fs map[string]*smb2.Share, config *SearchConfig, fileContentCache *scanner.FileContentCache) ([]*SearchResult, error)

SearchMultipleShares searches multiple shares concurrently (Legacy: assumes root path)

func SearchMultipleSharesWithMessages

func SearchMultipleSharesWithMessages(fs map[string]*smb2.Share, config *SearchConfig, fileContentCache *scanner.FileContentCache, messages *[]string) ([]*SearchResult, error)

Versão que acumula mensagens no slice messages (Legacy: assumes root path)

type WorkerPool

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

WorkerPool manages a pool of workers for file processing

func NewWorkerPool

func NewWorkerPool(numWorkers int, results chan<- *SearchResult) *WorkerPool

func (*WorkerPool) Start

func (wp *WorkerPool) Start(ctx context.Context, fileContentCache *scanner.FileContentCache)

Jump to

Keyboard shortcuts

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