waftest

package
v0.6.13 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package waftest implements types and functions for testing WAFs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient(timeout time.Duration) *http.Client

NewHTTPClient creates an HTTP client. Clients and Transports are safe for concurrent use by multiple goroutines and for efficiency should only be created once and re-used. See https://golang.org/pkg/net/http/ for more.

func PrintReport

func PrintReport(tests []Test)

PrintReport prints report about tests.

Types

type Details

type Details struct {
	RuleID     string
	File       string
	LineNumber string
	Data       string
	Match      string
	Tags       []string
}

Details is details field in logs.

type Headers

type Headers struct {
	Host        string
	WafTesterID string `json:"waf-tester-id"`
}

Headers is headers field in logs.

type LogLine

type LogLine struct {
	Transaction Transaction
}

LogLine is a line from logs.

func GetLogLines

func GetLogLines(logspath string) (logs []LogLine, err error)

GetLogLines gets lines of WAF logs from URL or file.

type Message

type Message struct {
	Message string
	Details Details
}

Message is message field in logs.

type Producer

type Producer struct {
	Modsecurity string
	Connector   string
	Components  []string
}

Producer is producer field in logs.

type Request

type Request struct {
	Method  string
	URI     string
	Headers Headers
}

Request is request field in logs.

type Response

type Response struct {
	HTTPCode int `json:"http_code"`
}

Response is response field in logs.

type Test

type Test struct {
	ID                  string
	Title               string
	Desc                string
	Tags                []string
	File                string
	Method              string
	Scheme              string
	Host                string
	Path                string // URI
	URL                 string // scheme + host + Path
	Headers             map[string]string
	Data                []string
	Err                 error
	StatusCode          int // ex: 403
	ExpectedStatusCodes []int
	Status              string // ex: 403 Forbidden
	TestStatus          string
	Logs                []LogLine
	LogContains         string
	LogContainsNot      string
	ExpectError         bool
	Executed            bool
}

Test represents an HTTP test. It contains both request and response fields + additional fields.

func GetTests

func GetTests(path string, exec, noexec, header []string, logspath string) ([]Test, error)

GetTests returns the list of available tests.

func (*Test) Evaluate

func (t *Test) Evaluate(logspath string)

Evaluate evaluates a test from response status or logs. Then it sets overall TestStatus to OK, FAIL or ERR.

func (*Test) Execute

func (t *Test) Execute(URL string, client *http.Client)

Execute executes a Test. It fills in some of the Test fields (like URL, StatusCode).

func (*Test) Print

func (t *Test) Print(flagPrint string)

Print prints basic information about a Test.

func (*Test) PrintVerbose

func (t *Test) PrintVerbose(flagPrint string)

PrintVerbose prints lot of information about a Test.

type Tests

type Tests []*Test

Tests is a collection of Test.

func (*Tests) AddLogs

func (ts *Tests) AddLogs(logspath string) (logsFound int)

AddLogs adds related logs to a Test.

type Transaction

type Transaction struct {
	TimeStamp  string `json:"time_stamp"`
	ClientIP   string `json:"client_ip"`
	ClientPort int    `json:"client_port"`
	HostIP     string `json:"host_ip"`
	HostPort   int    `json:"host_port"`
	Messages   []Message
	Request    Request
	Response   Response
	Producer   Producer
}

Transaction is transaction field in logs.

Jump to

Keyboard shortcuts

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