core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name    = "shhgit"
	Version = "0.2"
	Author  = "Paul Price (@darkp0rt)"
)
View Source
const (
	FATAL     = 5
	ERROR     = 4
	IMPORTANT = 3
	WARN      = 2
	INFO      = 1
	DEBUG     = 0
)
View Source
const (
	TypeSimple  = "simple"
	TypePattern = "pattern"

	PartExtension = "extension"
	PartFilename  = "filename"
	PartPath      = "path"
	PartContents  = "contents"
)

Variables

Functions

func CloneRepository

func CloneRepository(session *Session, url string, dir string) (*git.Repository, error)

func GetConfigYaml

func GetConfigYaml() ([]byte, error)

func GetEntropy

func GetEntropy(data string) (entropy float64)

func GetGists

func GetGists(session *Session)

func GetHash

func GetHash(s string) string

func GetRepositories

func GetRepositories(session *Session)

func GetRepository

func GetRepository(session *Session, id int64) (*github.Repository, error)

func GetTempDir

func GetTempDir(suffix string) string

func IsSkippableFile

func IsSkippableFile(path string) bool

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

Types

type Config

type Config struct {
	GitHubAccessTokens           []string          `yaml:"github_access_tokens"`
	SlackWebhook                 string            `yaml:"slack_webhook,omitempty"`
	BlacklistedExtensions        []string          `yaml:"blacklisted_extensions"`
	BlacklistedPaths             []string          `yaml:"blacklisted_paths"`
	BlacklistedEntropyExtensions []string          `yaml:"blacklisted_entropy_extensions"`
	Signatures                   []ConfigSignature `yaml:"signatures"`
}

func ParseConfig

func ParseConfig() (*Config, error)

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"`
	Verifier string `yaml:"verifier,omitempty"`
}

type GitHubClientWrapper

type GitHubClientWrapper struct {
	*github.Client
	Token            string
	RateLimitedUntil time.Time
}

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) SetDebug

func (l *Logger) SetDebug(d bool)

func (*Logger) SetSilent

func (l *Logger) SetSilent(d bool)

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 GetMatchingFiles

func GetMatchingFiles(dir string) []MatchFile

func NewMatchFile

func NewMatchFile(path string) MatchFile

func (MatchFile) CanCheckEntropy

func (match MatchFile) CanCheckEntropy() bool

type Options

type Options struct {
	Threads                *int
	Silent                 *bool
	Debug                  *bool
	MaximumRepositorySize  *uint
	MaximumFileSize        *uint
	CloneRepositoryTimeout *uint
	EntropyThreshold       *float64
	MinimumStars           *uint
	PathChecks             *bool
	ProcessGists           *bool
	TempDirectory          *string
	CsvPath                *string
	SearchQuery            *string
}

func ParseOptions

func ParseOptions() (*Options, error)

type PatternSignature

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

func (PatternSignature) GetContentsMatches

func (s PatternSignature) GetContentsMatches(file MatchFile) []string

func (PatternSignature) Match

func (s PatternSignature) Match(file MatchFile) (bool, string)

func (PatternSignature) Name

func (s PatternSignature) Name() string

type Session

type Session struct {
	sync.Mutex

	Version      string
	Log          *Logger
	Options      *Options
	Config       *Config
	Signatures   []Signature
	Repositories chan int64
	Gists        chan string
	Context      context.Context
	Clients      []*GitHubClientWrapper
	CsvWriter    *csv.Writer
}

func GetSession

func GetSession() *Session

func (*Session) GetClient

func (s *Session) GetClient() *GitHubClientWrapper

func (*Session) InitCsvWriter

func (s *Session) InitCsvWriter()

func (*Session) InitGitHubClients

func (s *Session) InitGitHubClients()

func (*Session) InitLogger

func (s *Session) InitLogger()

func (*Session) InitSignatures

func (s *Session) InitSignatures()

func (*Session) InitThreads

func (s *Session) InitThreads()

func (*Session) Start

func (s *Session) Start()

func (*Session) WriteToCsv

func (s *Session) WriteToCsv(line []string)

type Signature

type Signature interface {
	Name() string
	Match(file MatchFile) (bool, string)
	GetContentsMatches(file MatchFile) []string
}

func GetSignatures

func GetSignatures(s *Session) []Signature

type SimpleSignature

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

func (SimpleSignature) GetContentsMatches

func (s SimpleSignature) GetContentsMatches(file MatchFile) []string

func (SimpleSignature) Match

func (s SimpleSignature) Match(file MatchFile) (bool, string)

func (SimpleSignature) Name

func (s SimpleSignature) Name() string

Jump to

Keyboard shortcuts

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