#!/usr/bin/env python # -*- coding: utf-8 -*- """ Copyright (c) 2006-2026 sqlmap developers (https://sqlmap.org) See the file 'LICENSE' for copying permission Adversarial "shitty response" JITTER harness for BOOLEAN-based blind extraction. Boolean-blind decides each bit through the REAL comparison() oracle (--string / --not-string / --regexp / --code / page-ratio). In the wild a target throws transient junk between good responses - gateway 5xx, WAF/rate-limit pages, a Cloudflare "just a moment" interstitial, a captcha, a maintenance banner, a truncated or empty body, an A/B variant, even a page that COINCIDENTALLY contains the --string token (a direction-flipping false positive). This drives the REAL bisection() + REAL comparison() + REAL validateChar() re-validation against a mock oracle that injects that catalog (IID or in bursts) at controllable rates, with NO network, fully deterministic per seed. The template is PAYLOAD_DELIMITER-wrapped so validateChar's per-char '!=' re-check actually fires (the same fidelity trap the time-based harness hit), and the mock sets threadData.lastCode so the unexpectedCode -> validateChar defense engages exactly as in a live run. Two tiers (mirrors tests/test_jitter_stress.py): * TestBooleanJitterRegression - ALWAYS runs. Deterministic, non-flaky guards: clean extraction is perfect, benign dynamic content never corrupts, and a transient unexpected-code response landing on a validation request is ridden out. * TestBooleanJitterSweep - OPT-IN (SQLMAP_JITTER_STRESS=1). The creative failure-surface sweep (IID + bursty), informational + loose bounds, kept out of normal CI. """ import os import random import re import sys import unittest sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from _testutils import bootstrap, set_dbms, reset_dbms bootstrap() from lib.core.data import conf, kb from lib.core.common import getCurrentThreadData, setTechnique from lib.core.datatype import AttribDict from lib.core.enums import HTTP_HEADER, PAYLOAD from lib.core.settings import PAYLOAD_DELIMITER from lib.request.comparison import comparison from lib.request.connect import Connect import lib.techniques.blind.inference as inf _D = PAYLOAD_DELIMITER _TEMPLATE = "%sEXPR=%%s IDX=%%d CMP>%%d%s" % (_D, _D) # delimiter-wrapped -> validateChar '!=' fires _PARSE = re.compile(r"IDX=(\d+) CMP(!=|=|>)(\d+)") _SECRET = "Str0ng!" _STRING = "luther" # realistic-size bodies (shared nav/footer boilerplate) so the "resembles neither model" anomaly guard # behaves as on a real page: benign dynamic noise is proportionally tiny (stays a match), while a junk # interstitial/maintenance/empty body clearly matches neither _BOILER = "