bindings

package
v2.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WafMaxStringLength   = 4096
	WafMaxContainerDepth = 20
	WafMaxContainerSize  = 256
	WafRunTimeout        = 5000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type WafConfig

type WafConfig struct {
	Limits     WafConfigLimits
	Obfuscator WafConfigObfuscator
	FreeFn     uintptr
}

type WafConfigLimits

type WafConfigLimits struct {
	MaxContainerSize  uint32
	MaxContainerDepth uint32
	MaxStringLength   uint32
}

type WafConfigObfuscator

type WafConfigObfuscator struct {
	KeyRegex   uintptr // char *
	ValueRegex uintptr // char *
}

type WafContext

type WafContext uintptr

wafContext is a forward declaration in ddwaf.h header We basically don't need to modify it, only to give it to the waf

type WafDl

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

wafDl is the type wrapper for all C calls to the waf It uses `libwaf` to make C calls All calls must go through this one-liner to be type safe since purego calls are not type safe

func NewWafDl

func NewWafDl() (dl *WafDl, err error)

newWafDl loads the libddwaf shared library and resolves all tge relevant symbols. The caller is responsible for calling wafDl.Close on the returned object once they are done with it so that associated resources can be released.

func (*WafDl) Close

func (waf *WafDl) Close() error

func (*WafDl) Handle

func (waf *WafDl) Handle() uintptr

func (*WafDl) WafContextDestroy

func (waf *WafDl) WafContextDestroy(context WafContext)

func (*WafDl) WafContextInit

func (waf *WafDl) WafContextInit(handle WafHandle) WafContext

func (*WafDl) WafDestroy

func (waf *WafDl) WafDestroy(handle WafHandle)

func (*WafDl) WafGetVersion

func (waf *WafDl) WafGetVersion() string

wafGetVersion returned string is a static string so we do not need to free it

func (*WafDl) WafInit

func (waf *WafDl) WafInit(ruleset *WafObject, config *WafConfig, info *WafObject) WafHandle

wafInit initializes a new WAF with the provided ruleset, configuration and info objects. A cgoRefPool ensures that the provided input values are not moved or garbage collected by the Go runtime during the WAF call.

func (*WafDl) WafKnownAddresses

func (waf *WafDl) WafKnownAddresses(handle WafHandle) []string

wafKnownAddresses returns static strings so we do not need to free them

func (*WafDl) WafObjectFree

func (waf *WafDl) WafObjectFree(obj *WafObject)

func (*WafDl) WafResultFree

func (waf *WafDl) WafResultFree(result *WafResult)

func (*WafDl) WafRun

func (waf *WafDl) WafRun(context WafContext, persistentData, ephemeralData *WafObject, result *WafResult, timeout uint64) WafReturnCode

func (*WafDl) WafUpdate

func (waf *WafDl) WafUpdate(handle WafHandle, ruleset *WafObject, info *WafObject) WafHandle

type WafHandle

type WafHandle uintptr

wafHandle is a forward declaration in ddwaf.h header We basically don't need to modify it, only to give it to the waf

type WafObject

type WafObject struct {
	ParameterName       uintptr
	ParameterNameLength uint64
	Value               uintptr
	NbEntries           uint64
	Type                WafObjectType
	// contains filtered or unexported fields
}

func (*WafObject) IsArray

func (w *WafObject) IsArray() bool

isArray determines whether this WAF Object is an array or not.

func (*WafObject) IsInvalid

func (w *WafObject) IsInvalid() bool

isInvalid determines whether this WAF Object has the invalid type (which is the 0-value).

func (*WafObject) IsMap

func (w *WafObject) IsMap() bool

isMap determines whether this WAF Object is a map or not.

func (*WafObject) IsNil

func (w *WafObject) IsNil() bool

isNil determines whether this WAF Object is nil or not.

func (*WafObject) IsUnusable

func (wo *WafObject) IsUnusable() bool

IsUnusable returns true if the wafObject has no impact on the WAF execution But we still need this kind of objects to forward map keys in case the value of the map is invalid

type WafObjectType

type WafObjectType uint32

wafObjectType is an enum in C which has the size of DWORD. But DWORD is 4 bytes in amd64 and arm64 so uint32 it is.

const (
	WafIntType WafObjectType = 1 << iota
	WafUintType
	WafStringType
	WafArrayType
	WafMapType
	WafBoolType
	WafFloatType
	WafNilType
)
const WafInvalidType WafObjectType = 0

type WafResult

type WafResult struct {
	Timeout      byte
	Events       WafObject
	Actions      WafObject
	Derivatives  WafObject
	TotalRuntime uint64
}

type WafReturnCode

type WafReturnCode int32
const (
	WafErrInternal WafReturnCode = iota - 3
	WafErrInvalidObject
	WafErrInvalidArgument
	WafOK
	WafMatch
)

Jump to

Keyboard shortcuts

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