core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2021 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Name    = "shhgit"
	Version = "0.4"
	Author  = "Paul Price (@darkp0rt) - www.darkport.co.uk"
)
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"
)
View Source
      _     _           _ _   
     | |   | |         (_) |  
  ___| |__ | |__   __ _ _| |_ 
 / __| '_ \| '_ \ / _` + "`" + ` | | __|
 \__ \ | | | | | | (_| | | |_ 
 |___/_| |_|_| |_|\__, |_|\__|
                   __/ |      
    v` + Version + `          |___/`
View Source
const SpinnerChars = `|/-\`

Variables

Functions

func CloneRepository

func CloneRepository(session *Session, url string, ref string, dir string) (*git.Repository, 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

func ShowSpinner

func ShowSpinner() func()

Types

type Config

type Config struct {
	GitHubAccessTokens           []string          `yaml:"github_access_tokens"`
	Webhook                      string            `yaml:"webhook,omitempty"`
	WebhookPayload               string            `yaml:"webhook_payload,omitempty"`
	BlacklistedStrings           []string          `yaml:"blacklisted_strings"`
	BlacklistedExtensions        []string          `yaml:"blacklisted_extensions"`
	BlacklistedPaths             []string          `yaml:"blacklisted_paths"`
	BlacklistedEntropyExtensions []string          `yaml:"blacklisted_entropy_extensions"`
	Signatures                   []ConfigSignature `yaml:"signatures"`
}

func ParseConfig

func ParseConfig(options *Options) (*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 GitResource

type GitResource struct {
	Id   int64
	Type GitResourceType
	Url  string
	Ref  string
}

type GitResourceType

type GitResourceType int
const (
	LOCAL_SOURCE GitResourceType = iota
	GITHUB_SOURCE
	GITHUB_COMMENT
	GIST_SOURCE
	BITBUCKET_SOURCE
	GITLAB_SOURCE
)

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
	Local                  *string
	Live                   *string
	ConfigPath             *string
}

func ParseOptions

func ParseOptions() (*Options, error)

type PatternSignature

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

func (PatternSignature) GetContentsMatches

func (s PatternSignature) GetContentsMatches(contents []byte) []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 GitResource
	Gists            chan string
	Comments         chan string
	Context          context.Context
	Clients          chan *GitHubClientWrapper
	ExhaustedClients chan *GitHubClientWrapper
	CsvWriter        *csv.Writer
}

func GetSession

func GetSession() *Session

func (*Session) FreeClient

func (s *Session) FreeClient(client *GitHubClientWrapper)

FreeClient returns the GitHub Client to the pool of available, non-rate-limited channel of clients in the 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(contents []byte) []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(contents []byte) []string

func (SimpleSignature) Match

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

func (SimpleSignature) Name

func (s SimpleSignature) Name() string

type Spinner

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

func New

func New() *Spinner

func (*Spinner) Next

func (s *Spinner) Next() string

Jump to

Keyboard shortcuts

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