path

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoURL = errors.New("No URL for request")

ErrNoURL is returned when a request has no URL in the request

Functions

This section is empty.

Types

type ClientID

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

ClientID is client identification

func NewClientID

func NewClientID() *ClientID

NewClientID creates a new ClientID object

func (*ClientID) Hit

func (c *ClientID) Hit(ip net.IP, path string)

Hit notifies ClientID that an IP hit a target

func (*ClientID) Match

func (c *ClientID) Match(ip net.IP, targetList []string) bool

Match asks ClientID if the target IP has succeeded in hitting the prereqs

type Path

type Path struct {
	Path string `yaml:"path,omitempty"`
	// HostedFile is the file to host
	HostedFile string `yaml:"hosted_file" json:"-"`
	// ContentType tells the browser what content should be parsed. A list of MIME
	// types can be found here: https://www.freeformatter.com/mime-types-list.html
	ContentType string `yaml:"content_type,omitempty"`
	// Disposition sets the Content-Disposition header
	Disposition struct {
		// Type is the type of disposition. Usually either inline or attachment
		Type string `yaml:"type"`
		// FileName is the name of the file if Content.Type is attachment
		FileName string `yaml:"file_name"`
	} `yaml:"disposition,omitempty"`
	// OnFailure instructs the Path what to do when a failure occurs
	OnFailure struct {
		// Redirect will redirect the user with a 301 to a target address
		Redirect string `yaml:"redirect"`
		// Render will render the following path
		Render string `yaml:"render"`
	} `yaml:"on_failure,omitempty"`
	//ProxyHost proxies the path to this address
	ProxyHost string `yaml:"proxy,omitempty"`
	// CredentialCapture returns the credentials POSTed to the path
	CredentialCapture struct {
		FileOutput string `yaml:"file_output"`
	} `yaml:"credential_capture,omitempty"`
	// contains filtered or unexported fields
}

Path is an available path that can be accessed on the server

func NewPath

func NewPath(path string) (*Path, error)

NewPath parses a yaml file path to create a new Path object

func NewPathArray

func NewPathArray(path string) ([]*Path, error)

NewPathArray creates a Path array based on a target path

func NewPathArrayData

func NewPathArrayData(data []byte) ([]*Path, error)

NewPathArrayData

func NewPathData

func NewPathData(data []byte) (*Path, error)

NewPathData creates a Path object from yaml data

func (*Path) ContentHeaders

func (f *Path) ContentHeaders() map[string]string

ContentHeaders sets the Content-Type and Content-Disposition headers.

func (*Path) ServeHTTP

func (f *Path) ServeHTTP(w http.ResponseWriter, req *http.Request) error

ServeHTTP is an http.HandlerFunc with error which chooses the correct way to respond to an HTTP request

A single path can be either a ProxyHost, Render, or CredentialCapture

func (*Path) ShouldHost

func (f *Path) ShouldHost(req *http.Request, state *State, gip geoip.DB) bool

ShouldHost does the checking to see if the requested file should be given to a target

type Paths

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

Paths is the compilation of parsed paths

func New

func New(serverRoot, proxyPath, dbPath, gcp string) (*Paths, error)

New creates a new Paths variable from the specified base path

func NewDefault

func NewDefault(serverRoot, gcp string) (*Paths, error)

NewDefault instantiates a Paths object with default configuration

func NewDefaultTest

func NewDefaultTest(serverRoot string) (*Paths, error)

For many of the tests, we don't need to apply the global conditionals, so this helper function is for test cases

func (*Paths) Add

func (paths *Paths) Add(path string, pathData *Path)

Add adds a new Path to the global paths list

func (*Paths) AddGeoIP

func (paths *Paths) AddGeoIP(path string) error

AddGeoIP

func (*Paths) AddProxyList

func (paths *Paths) AddProxyList(path string) error

AddProxyList is a flat list of proxies to add in YAML format

func (*Paths) IngestData

func (paths *Paths) IngestData(oPath string) error

AddPath adds a data path which is served when Path - Root is requested

func (*Paths) IngestMeta

func (paths *Paths) IngestMeta(oPath string) error

AddMeta adds a meta (or .info) file to the paths list

func (*Paths) IngestProxy

func (paths *Paths) IngestProxy(oPath string) error

IngestProxy adds the proxy from target path if it exists

func (*Paths) Len

func (paths *Paths) Len() int

Len gets the number of paths

func (*Paths) Match

func (paths *Paths) Match(URI string) (*Path, bool)

Match matches a page given a URI. It returns the specified Path and a boolean value to determine if there was a page that matched the URI

func (*Paths) MatchAndServe

func (paths *Paths) MatchAndServe(w http.ResponseWriter, req *http.Request) (bool, error)

MatchAndServe matches a path, determines if the path should be served, and serves the file based on an HTTP request. If a failure occurs, this function will serve failed pages.

This is a helper function which combines already-exposed functions to make file serving easy.

Returns true when the file was served and false when a 404 page should be returned

func (*Paths) Reload

func (paths *Paths) Reload() error

Reload refreshes the list of paths internally to Paths

func (*Paths) Remove

func (paths *Paths) Remove(path string)

Remove removes a path from the list of usable paths

func (*Paths) RemoveDir

func (paths *Paths) RemoveDir(dir string)

func (*Paths) Serve

func (paths *Paths) Serve(w http.ResponseWriter, req *http.Request) error

Serve serves a page without checking conditionals

type RequestConditions

type RequestConditions struct {
	// AUserAgent is the authorized user agents for a file
	AuthorizedUserAgents []string `yaml:"authorized_useragents,omitempty"`
	// BlacklistUserAgents are blacklisted user agents
	BlacklistUserAgents []string `yaml:"blacklist_useragents,omitempty"`
	// AuthorizedIPRange is the authorized range of IPs who are allowed to access a file
	AuthorizedIPRange []string `yaml:"authorized_iprange,omitempty"`
	// BlacklistIPRange are blacklisted IPs
	BlacklistIPRange []string `yaml:"blacklist_iprange,omitempty"`
	// AuthorizedMethods are the HTTP methods which can access the page
	AuthorizedMethods []string `yaml:"authorized_methods,omitempty"`
	// AuthorizedHeaders are HTTP headers which must be present in order to access a file
	AuthorizedHeaders map[string]string `yaml:"authorized_headers,omitempty"`
	// AuthorizedJA3 are valid JA3 hashes
	AuthorizedJA3 []string `yaml:"authorized_ja3,omitempty"`
	// Exec file executes script/binary and checks stdout
	Exec struct {
		ScriptPath string `yaml:"script"`
		Output     string `yaml:"output"`
	} `yaml:"exec,omitempty"`
	// NotServing does not serve the page when NotServing is true
	NotServing bool `yaml:"not_serving,omitempty"`
	// Serve is the number of times the file should be served
	Serve uint64 `yaml:"serve,omitempty"`
	// PrereqPaths path of hits that need to happen before the current one will succeed
	PrereqPaths []string `yaml:"prereq,omitempty"`
	GeoIP       struct {
		AuthorizedCountries []string `yaml:"authorized_countries"`
		BlacklistCountries  []string `yaml:"blacklist_countries"`
	} `yaml:"geoip"`
}

RequestConditions are the conditions in the http.Request object

func MergeRequestConditions

func MergeRequestConditions(conds ...RequestConditions) (RequestConditions, error)

MergeRequestConditions merges a list of RequestCondition. They are applied starting from the first to the last. It will overwrite later RequestCondition

func NewRequestConditions

func NewRequestConditions(data []byte) (RequestConditions, error)

NewRequestConditions creates an object based on a YAML blob

func (*RequestConditions) ShouldHost

func (c *RequestConditions) ShouldHost(req *http.Request, state *State, gip geoip.DB) bool

ShouldHost returns when an HTTP request should be hosted or not

type State

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

State contains all state for Paths configuration

func NewState

func NewState(dbPath string) (*State, error)

NewState creates the prereqs for managing state in Satellite

func (*State) GetHits

func (s *State) GetHits(path string) (uint64, error)

GetHits gets the number of hits for a target path using the SQLite DB

func (*State) Hit

func (s *State) Hit(req *http.Request) error

Hit will create a path in the DB if it does not exist, and increment the times_served if it does exist

func (*State) MatchPaths

func (s *State) MatchPaths(ip net.IP, paths []string) bool

MatchPaths checks if an IP has hit the specified paths in order to make sure an IP can access a page

func (*State) Remove

func (s *State) Remove(path string) error

Remove removes path from DB

Jump to

Keyboard shortcuts

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