padding_oracle

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	ModuleID    = "padding-oracle"
	ModuleName  = "CBC Padding Oracle"
	ModuleShort = "Confirms a CBC padding oracle by flipping ciphertext bytes and observing a distinct, reproducible padding-error differential"
)

Variables

View Source
var (
	ModuleDesc = `` /* 625-byte string literal not displayed */

	ModuleConfirmation = "" /* 226-byte string literal not displayed */
	ModuleSeverity     = severity.High
	ModuleConfidence   = severity.Firm
	ModuleTags         = []string{"cryptography", "injection", "heavy"}
)

Functions

func FlipPenultimateByteAt

func FlipPenultimateByteAt(dec []byte, blockSize, byteOffsetFromBlockEnd int) []byte

FlipPenultimateByteAt returns a copy of dec with the low bit of a byte inside the penultimate block flipped. byteOffsetFromBlockEnd counts back from the end of that block: 1 is the last byte, 2 the second-to-last, and so on. Using a different offset probes a different plaintext position, so a second confirmation round exercises a distinct bit position from the first.

It never panics: if dec is too short to hold two whole blocks, or the offset is out of range, the input is returned unchanged (a copy).

func FlipPenultimateLastByte

func FlipPenultimateLastByte(dec []byte, blockSize int) []byte

FlipPenultimateLastByte returns a copy of dec with the low bit of the last byte of the penultimate block (block index n-2) flipped. This changes the last (padding) byte of the final plaintext block.

func MalformedControl

func MalformedControl(encoded string) string

MalformedControl corrupts the ENCODING of an already-encoded ciphertext so the target fails to decode it BEFORE any block decryption runs — yielding a decode/pre-decrypt error class distinct from a padding error. Appending characters outside every base64/hex alphabet guarantees the decode step fails regardless of which encoding was used.

Types

type Candidate

type Candidate struct {
	Decoded   []byte
	BlockSize int
	Encoding  Encoding
}

Candidate is a decoded ciphertext-shaped value plus the metadata a padding- oracle probe needs to mutate and re-encode it.

func DetectCiphertext

func DetectCiphertext(value string) (Candidate, bool)

DetectCiphertext reports whether value looks like a block-cipher (CBC) ciphertext worth probing for a padding oracle, and if so returns the decoded bytes, the inferred block size, and the encoding it decoded from.

It is deliberately conservative: it excludes JWTs, UUIDs, plain hex digests, and anything that decodes to printable text/JSON, and it requires a block- aligned length of at least two blocks plus high-entropy, mostly-non-printable content. It is only ever reached behind a hard "crypto-cbc" tech gate, so a permissive false accept still cannot fire without a rigorous active confirmation.

func (Candidate) Reencode

func (c Candidate) Reencode(b []byte) string

Reencode re-encodes b in the SAME encoding this candidate decoded from, so a mutated ciphertext is transmitted in the exact wire form the target expects.

type Encoding

type Encoding int

Encoding identifies how a ciphertext candidate was wire-encoded, so a mutated ciphertext can be re-encoded in the SAME form the target decodes.

const (
	// EncodingStdBase64 is standard base64 with padding (RFC 4648 §4).
	EncodingStdBase64 Encoding = iota
	// EncodingRawStdBase64 is standard base64 without padding.
	EncodingRawStdBase64
	// EncodingURLBase64 is URL-safe base64 with padding (RFC 4648 §5).
	EncodingURLBase64
	// EncodingRawURLBase64 is URL-safe base64 without padding.
	EncodingRawURLBase64
	// EncodingHex is lowercase/uppercase hexadecimal.
	EncodingHex
)

func (Encoding) String

func (e Encoding) String() string

String returns a short label used in finding metadata.

type Module

type Module struct {
	modkit.BaseActiveModule
}

Module implements the CBC padding-oracle confirmer.

func New

func New() *Module

New creates a new padding-oracle module.

func (*Module) RequiredTechs

func (m *Module) RequiredTechs() []string

RequiredTechs implements modules.TechAware: the executor only dispatches this module against hosts where "crypto-cbc" was detected. The executor gate fails OPEN on unknown hosts, so ScanPerInsertionPoint re-checks and fails CLOSED.

func (*Module) ScanPerInsertionPoint

func (m *Module) ScanPerInsertionPoint(
	ctx *httpmsg.HttpRequestResponse,
	ip httpmsg.InsertionPoint,
	httpClient *http.Requester,
	scanCtx *modkit.ScanContext,
) ([]*output.ResultEvent, error)

ScanPerInsertionPoint confirms a CBC padding oracle at a single insertion point.

Jump to

Keyboard shortcuts

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