scanner

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIndexNotFound = errors.New("index part not found")
	ErrFileNotFound  = errors.New("file part not found")
)
View Source
var LockPasswordIter = 4096
View Source
var MaxFileSize int64 = 100 * 1024 * 1024
View Source
var MaxWorkers = 40
View Source
var Now = time.Now

for test purposes

View Source
var Since = time.Since

Functions

This section is empty.

Types

type Action added in v0.2.0

type Action interface {
	Handle(path string, result SummarizedGMalwareResult, report *Report) error
}

type Actions

type Actions struct {
	Deleted    bool
	Quarantine bool
	Log        bool
	Inform     bool
	Verbose    bool
	InformDest io.Writer
}

type Config

type Config struct {
	// Path             string
	QuarantineFolder string
	Workers          int
	Password         string
	Cache            cache.Cacher
	Submitter        Submitter
	Timeout          time.Duration
	WaitOpts         gdetect.WaitForOptions
	Actions          Actions
	CustomActions    []Action
	ScanPeriod       time.Duration
	Extract          bool
	MaxFileSize      int64
}

type Connector

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

func NewConnector

func NewConnector(config Config) *Connector

func (*Connector) Close

func (c *Connector) Close()

func (*Connector) ScanFile

func (c *Connector) ScanFile(ctx context.Context, input string) (err error)

func (*Connector) Start

func (c *Connector) Start() error

type InformAction

type InformAction struct {
	Verbose bool
	Out     io.Writer
}

func (*InformAction) Handle

func (a *InformAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

type Lock

type Lock struct {
	Password string
}

func (*Lock) GetHeader

func (l *Lock) GetHeader(in io.Reader) (entry LockEntry, err error)

func (*Lock) LockFile

func (l *Lock) LockFile(file string, in io.Reader, info os.FileInfo, reason string, out io.Writer) error

func (*Lock) UnlockFile

func (l *Lock) UnlockFile(in io.Reader, out io.Writer) (file string, info os.FileInfo, reason string, err error)

type LockEntry

type LockEntry struct {
	Filepath string
	Reason   string
}

type LockFileInfo

type LockFileInfo struct {
	fs.FileInfo
}

func (*LockFileInfo) Size

func (lfi *LockFileInfo) Size() int64

type Locker

type Locker interface {
	LockFile(file string, in io.Reader, info os.FileInfo, reason string, out io.Writer) error
	UnlockFile(in io.Reader, out io.Writer) (file string, info os.FileInfo, reason string, err error)
	GetHeader(in io.Reader) (entry LockEntry, err error)
}

type LogAction

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

func (*LogAction) Handle

func (a *LogAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

type MockLock

type MockLock struct {
	LockFileMock   func(file string, in io.Reader, info os.FileInfo, reason string, out io.Writer) error
	UnlockFileMock func(in io.Reader, out io.Writer) (file string, info os.FileInfo, reason string, err error)
	GetHeaderMock  func(in io.Reader) (entry LockEntry, err error)
}

func (*MockLock) GetHeader

func (m *MockLock) GetHeader(in io.Reader) (entry LockEntry, err error)

func (*MockLock) LockFile

func (m *MockLock) LockFile(file string, in io.Reader, info os.FileInfo, reason string, out io.Writer) error

func (*MockLock) UnlockFile

func (m *MockLock) UnlockFile(in io.Reader, out io.Writer) (file string, info os.FileInfo, reason string, err error)

type MockSubmitter

type MockSubmitter struct {
	ExtractExpertViewURLMock func(result *gdetect.Result) (urlExpertView string, err error)
	GetResultByUUIDMock      func(ctx context.Context, uuid string) (result gdetect.Result, err error)
	GetResultBySHA256Mock    func(ctx context.Context, sha256 string) (result gdetect.Result, err error)
	GetResultsMock           func(ctx context.Context, from int, size int, tags ...string) (submissions []gdetect.Submission, err error)
	SubmitFileMock           func(ctx context.Context, filepath string, options gdetect.SubmitOptions) (uuid string, err error)
	SubmitReaderMock         func(ctx context.Context, r io.Reader, options gdetect.SubmitOptions) (uuid string, err error)
	WaitForFileMock          func(ctx context.Context, filepath string, options gdetect.WaitForOptions) (result gdetect.Result, err error)
	WaitForReaderMock        func(ctx context.Context, r io.Reader, options gdetect.WaitForOptions) (result gdetect.Result, err error)
	GetProfileStatusMock     func(ctx context.Context) (status gdetect.ProfileStatus, err error)
	GetAPIVersionMock        func(ctx context.Context) (version string, err error)
}

func (*MockSubmitter) ExtractExpertViewURL

func (m *MockSubmitter) ExtractExpertViewURL(result *gdetect.Result) (urlExpertView string, err error)

func (*MockSubmitter) GetAPIVersion

func (m *MockSubmitter) GetAPIVersion(ctx context.Context) (version string, err error)

func (*MockSubmitter) GetProfileStatus

func (m *MockSubmitter) GetProfileStatus(ctx context.Context) (status gdetect.ProfileStatus, err error)

func (*MockSubmitter) GetResultBySHA256

func (m *MockSubmitter) GetResultBySHA256(ctx context.Context, sha256 string) (result gdetect.Result, err error)

func (*MockSubmitter) GetResultByUUID

func (m *MockSubmitter) GetResultByUUID(ctx context.Context, uuid string) (result gdetect.Result, err error)

func (*MockSubmitter) GetResults

func (m *MockSubmitter) GetResults(ctx context.Context, from int, size int, tags ...string) (submissions []gdetect.Submission, err error)

func (*MockSubmitter) SubmitFile

func (m *MockSubmitter) SubmitFile(ctx context.Context, filepath string, options gdetect.SubmitOptions) (uuid string, err error)

func (*MockSubmitter) SubmitReader

func (m *MockSubmitter) SubmitReader(ctx context.Context, r io.Reader, options gdetect.SubmitOptions) (uuid string, err error)

func (*MockSubmitter) WaitForFile

func (m *MockSubmitter) WaitForFile(ctx context.Context, filepath string, options gdetect.WaitForOptions) (result gdetect.Result, err error)

func (*MockSubmitter) WaitForReader

func (m *MockSubmitter) WaitForReader(ctx context.Context, r io.Reader, options gdetect.WaitForOptions) (result gdetect.Result, err error)

type MultiAction

type MultiAction struct {
	Actions []Action
}

func NewMultiAction

func NewMultiAction(actions ...Action) *MultiAction

func (*MultiAction) Handle

func (a *MultiAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

type NoAction

type NoAction struct{}

func (*NoAction) Handle

func (*NoAction) Handle(path string, result SummarizedGMalwareResult, report *Report) error

type QuarantineAction

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

func NewQuarantineAction

func NewQuarantineAction(cache cache.Cacher, root string, locker Locker) *QuarantineAction

func (*QuarantineAction) Handle

func (a *QuarantineAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

func (*QuarantineAction) ListQuarantinedFiles

func (a *QuarantineAction) ListQuarantinedFiles(ctx context.Context) (qfiles chan QuarantinedFile, err error)

func (*QuarantineAction) Restore

func (a *QuarantineAction) Restore(id string) (err error)

type QuarantinedFile

type QuarantinedFile struct {
	LockEntry
	ID string
}

type RemoveFileAction

type RemoveFileAction struct{}

func (*RemoveFileAction) Handle

func (a *RemoveFileAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

type Report

type Report struct {
	FileName           string `json:"file-name"`
	Sha256             string `json:"sha256"`
	Malicious          bool   `json:"malicious"`
	Deleted            bool   `json:"deleted,omitempty"`
	QuarantineLocation string `json:"quarantine-location,omitempty"`
	ExpertViewURL      string `json:"expert-View-url,omitempty"`
	HasBeenRestored    bool   `json:"has-been-restored,omitempty"`
}

type ReportAction

type ReportAction struct{}

func (*ReportAction) Handle

func (a *ReportAction) Handle(path string, result SummarizedGMalwareResult, report *Report) (err error)

type ReportsWriter

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

func NewReportsWriter

func NewReportsWriter(dst io.WriteSeeker) *ReportsWriter

func (*ReportsWriter) Write

func (rw *ReportsWriter) Write(r Report) (err error)

type Submitter

type Submitter interface {
	gdetect.GDetectSubmitter
	ExtractExpertViewURL(result *gdetect.Result) (urlExpertView string, err error)
}

type SummarizedGMalwareResult added in v0.2.0

type SummarizedGMalwareResult struct {
	MaliciousSubfiles map[string]SummarizedGMalwareResult `json:"malicious-subfiles,omitempty"`
	Sha256            string                              `json:"sha256"`
	Malware           bool                                `json:"malware"`
	Malwares          []string                            `json:"malwares"`
}

Jump to

Keyboard shortcuts

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