api

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContextBackgroundDuration = 3
	DayTime                   = time.Hour * 24
	TopParamStart             = 4
	TopParamEnd               = 50
)
View Source
const (
	// This is the 'fallback' endpoint, when
	// a client tries to request a resource on an
	// endpoint that is not defined, this will be
	// the default response it will get.
	NotFound = "/"

	// This is the health status endpoint.
	// Performing a request to this endpoint the
	// client should receive a lightweight response
	// 'OK' with 200 as status code if everything is
	// behaving correctly.
	Health = "/api/health"

	// This endpoint is intended to serve a summary
	// of the information available for the IP taken
	// as input.
	// Parameter: top
	// Which info? Number of requests, timestamp of
	// the last activity, top X (default 10)
	// methods, path, headers.
	IPInfo = "/api/info/{ip}"

	// This endpoint is intended to serve information about
	// logs, so the requests were made to the Honeypot.
	// These are the parameters the endpoint accepts:
	// - id
	// - ip
	// - method
	// - header
	// - path
	// - date (YYYY-MM-DD)
	// - lt (less than YYYY-MM-DD-HH-MM-SS)
	// - gt (greater than YYYY-MM-DD-HH-MM-SS).
	APILogs = "api/logs"

	// This endpoint is intended to perform a heavy
	// and accurate scan on the logs. It takes as input
	// these parameters:
	// - regex (Go format)
	// - attack (use a list of well known regex)
	// - target (where to apply the regex)
	// - ip
	// - method
	// - header
	// - path
	// - date
	// - lt (less than YYYY-MM-DD-HH-MM-SS)
	// - gt (greater than YYYY-MM-DD-HH-MM-SS).
	APIDetect = "api/detect"

	// This endpoint gives a general overview of the system.
	APIStats = "api/stats"

	// This endpoint gives a detailed overview of the data
	// stored in the DB.
	APIStatsDB = "api/stats/db"
)

Api routes.

View Source
const (
	WriteTimeoutDuration = 15
	ReadTimeoutDuration  = 15
)

Variables

View Source
var (
	ErrPossibleTopValue      = errors.New("possible values for top: method / path / body")
	ErrNoStatsIP             = errors.New("no stats available for the specified IP")
	ErrIDDefined             = errors.New("if id is defined, no other parameters need to be defined")
	ErrDateDefined           = errors.New("if date is defined, lt and gt must be blank")
	ErrLtBeforeGt            = errors.New("lt cannot be before gt")
	ErrHTTPMethodUnknown     = errors.New("http method unknown")
	ErrInvalidIP             = errors.New("ip address is not valid")
	ErrStringToIntConversion = errors.New("failed to convert string to int")
	ErrRetrievingData        = errors.New("error while retrieving data")
	ErrIntegerRange          = errors.New("integer not in the range")
)

Functions

func BuildAPIDetectQuery

func BuildAPIDetectQuery(regex, attack, target, ip, method, header, path, date, lt, gt string) bson.M

BuildAPIDetectQuery.

func BuildAPILogsQuery

func BuildAPILogsQuery(id, ip, method, header, path, date, lt, gt string) bson.M

BuildAPILogsQuery.

func CheckAPIDetectParams

func CheckAPIDetectParams(regex, attack, target, ip, method, header, path, date, lt, gt string) error

CheckAPIDetectParams.

func CheckAPILogsParams

func CheckAPILogsParams(id, ip, method, header, path, date, lt, gt string) error

CheckAPILogsParams.

func GetAPIDetectQuery

func GetAPIDetectQuery(req *http.Request) (bson.M, error)

GetAPIDetectQuery > - regex (Go format) - attack (use a list of well known regex) - target (where to apply the regex) - ip - method - header - path - date - lt (less than YYYY-MM-DD-HH-MM-SS) - gt (greater than YYYY-MM-DD-HH-MM-SS).

func GetAPILogsQuery

func GetAPILogsQuery(req *http.Request) (bson.M, error)

GetAPILogsQuery > - id - ip - method - header - path - date (YYYY-MM-DD) - lt (less than YYYY-MM-DD-HH-MM-SS) - gt (greater than YYYY-MM-DD-HH-MM-SS).

func HealthHandler

func HealthHandler(w http.ResponseWriter, req *http.Request)

HealthHandler tells you if the API server is listening.

func IPInfoHandler

func IPInfoHandler(w http.ResponseWriter, req *http.Request, dbName string, client *mongo.Client)

IPInfoHandler.

func IsIntInTheRange

func IsIntInTheRange(input string, start int, end int) (int, error)

IsIntInTheRange.

func LogsDetectHandler

func LogsDetectHandler(w http.ResponseWriter, req *http.Request, dbName string, client *mongo.Client)

LogsDetectHandler.

func LogsHandler

func LogsHandler(w http.ResponseWriter, req *http.Request, dbName string, client *mongo.Client)

LogsHandler.

func NotFoundHandler

func NotFoundHandler(w http.ResponseWriter, req *http.Request)

NotFoundHandler tells you if the API server is listening.

func Server

func Server()

Server > to be filled.

func StatsDBHandler

func StatsDBHandler(w http.ResponseWriter, req *http.Request, dbName string, client *mongo.Client)

StatsDBHandler.

func StatsHandler

func StatsHandler(w http.ResponseWriter, req *http.Request, dbName string, client *mongo.Client)

StatsHandler.

func Top

func Top(w http.ResponseWriter, req *http.Request, dbName string,
	client *mongo.Client, what string, howMany int, ip string) ([]string, error)

Top.

Types

type IPInfoResponse

type IPInfoResponse struct {
	Logs         int
	LastActivity time.Time
	TopMethods   []string
	TopPaths     []string
	TopBodies    []string
}

IPInfoResponse.

Jump to

Keyboard shortcuts

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