detector

package
v0.0.0-...-6656868 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package detector provides parameter extraction and SQL injection detection.

Package detector provides parameter extraction and SQL injection detection.

Package detector provides parameter extraction and SQL injection detection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindSQLErrors

func FindSQLErrors(body []byte) map[string][]string

FindSQLErrors scans the response body for known SQL error messages. It returns a map of DBMS name to matched error strings.

func InferType

func InferType(value string) engine.ParameterType

InferType guesses the parameter type from its value. - Integers: "123", "-45", "0" - Floats: "1.5", "-3.14", "0.0" - Strings: everything else

func ParseBodyParameters

func ParseBodyParameters(body, contentType string) []engine.Parameter

ParseBodyParameters extracts parameters from POST body. Supports application/x-www-form-urlencoded.

func ParseParameters

func ParseParameters(rawURL, body, contentType string) []engine.Parameter

ParseParameters extracts all parameters from a URL and body. url: the full URL (e.g., "http://example.com/page?id=1&name=test") body: the POST body (e.g., "user=admin&pass=123") contentType: the Content-Type header value Returns: slice of engine.Parameter

func ParseURLParameters

func ParseURLParameters(rawURL string) []engine.Parameter

ParseURLParameters extracts parameters from URL query string only.

Types

type DiffEngine

type DiffEngine struct {
	DynamicPatterns []*regexp.Regexp
}

DiffEngine compares HTTP responses to detect behavioral differences.

func NewDiffEngine

func NewDiffEngine() *DiffEngine

NewDiffEngine creates a DiffEngine with default dynamic content patterns. These patterns strip session IDs, CSRF tokens, timestamps, and other dynamic values that change between requests but are not meaningful for SQL injection detection.

func (*DiffEngine) DiffDetails

func (d *DiffEngine) DiffDetails(a, b *ResponseData) *DiffResult

DiffDetails compares two ResponseData objects and returns detailed differences.

func (*DiffEngine) IsDifferent

func (d *DiffEngine) IsDifferent(a, b []byte, threshold float64) bool

IsDifferent returns true if the similarity ratio of two bodies is below the given threshold.

func (*DiffEngine) Ratio

func (d *DiffEngine) Ratio(a, b []byte) float64

Ratio computes a similarity ratio between two byte slices (0.0 to 1.0). Dynamic content (session IDs, timestamps, etc.) is stripped before comparison. Uses a line-based comparison for multi-line responses.

type DiffResult

type DiffResult struct {
	StatusCodeChanged  bool
	ContentLengthDelta int64
	BodyRatio          float64
	HeaderDiffs        map[string][2]string
	KeywordMatches     []string
}

DiffResult holds the result of comparing two HTTP responses.

type HeuristicDetector

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

HeuristicDetector performs quick probes to identify injectable parameters.

func NewHeuristicDetector

func NewHeuristicDetector(client transport.Client, diffEngine *DiffEngine) *HeuristicDetector

NewHeuristicDetector creates a new detector with the default threshold.

func (*HeuristicDetector) DetectAll

func (d *HeuristicDetector) DetectAll(ctx context.Context, target *engine.ScanTarget) ([]HeuristicResult, error)

DetectAll tests all parameters and returns heuristic results. It sends a baseline request first, then probes each parameter.

type HeuristicResult

type HeuristicResult struct {
	Parameter       engine.Parameter
	Baseline        *transport.Response
	CausesError     bool                // Single quote causes DB error
	DynamicContent  bool                // Parameter value affects response
	ErrorSignatures map[string][]string // DBMS -> matched errors
	PageRatio       float64             // Similarity between baseline and error probe
	IsInjectable    bool                // Overall heuristic assessment
}

HeuristicResult contains results of initial heuristic checks for a parameter.

type ResponseData

type ResponseData struct {
	StatusCode    int
	Headers       map[string][]string
	Body          []byte
	ContentLength int64
}

ResponseData holds an HTTP response for comparison.

Jump to

Keyboard shortcuts

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