1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
//! WAF response verdict taxonomy.
//!
//! This module defines the typed classification of HTTP responses
//! from a WAF-protected target. Verdicts are consumed by the strategy
//! engine to decide which evasion pipeline to try next.
use serde::{Deserialize, Serialize};
use std::fmt;
/// A classification signal that contributed to a verdict.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Signal {
/// HTTP status code observation.
StatusCode { code: u16, expected: u16 },
/// Body contained a known block-page marker.
BodyMarker(String),
/// Body contained a known success marker.
SuccessMarker(String),
/// Response time anomaly relative to baseline.
ResponseTimeAnomaly { baseline_ms: u64, actual_ms: u64 },
/// Connection behavior anomaly.
ConnectionBehavior(ConnectionBehavior),
/// HTTP/2 GOAWAY frame observed.
H2Goaway(String),
/// Baseline fingerprint drift detected.
FingerprintDrift(String),
/// Challenge platform identifier detected in body.
ChallengePlatform(String),
}
impl fmt::Display for Signal {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::StatusCode { code, expected } => {
write!(f, "status {code} (expected {expected})")
}
Self::BodyMarker(m) => write!(f, "body marker: {m}"),
Self::SuccessMarker(m) => write!(f, "success marker: {m}"),
Self::ResponseTimeAnomaly {
baseline_ms,
actual_ms,
} => {
write!(f, "response time {actual_ms}ms (baseline {baseline_ms}ms)")
}
Self::ConnectionBehavior(c) => write!(f, "connection: {c}"),
Self::H2Goaway(reason) => write!(f, "h2 goaway: {reason}"),
Self::FingerprintDrift(d) => write!(f, "fingerprint drift: {d}"),
Self::ChallengePlatform(p) => write!(f, "challenge platform: {p}"),
}
}
}
/// Connection behavior anomalies that influence verdict classification.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ConnectionBehavior {
/// TCP connection was reset (RST) before or during response.
TcpReset,
/// Server returned 200 OK but immediately closed the connection.
OkWithImmediateClose,
/// Server returned 200 OK with a block-page body.
OkWithBlockPage,
/// Standard graceful close after full response.
GracefulClose,
/// Connection timeout.
Timeout,
/// TLS alert or handshake failure.
TlsError,
}
impl fmt::Display for ConnectionBehavior {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::TcpReset => f.write_str("TCP reset"),
Self::OkWithImmediateClose => f.write_str("200 OK with immediate close"),
Self::OkWithBlockPage => f.write_str("200 OK with block page"),
Self::GracefulClose => f.write_str("graceful close"),
Self::Timeout => f.write_str("timeout"),
Self::TlsError => f.write_str("TLS error"),
}
}
}
/// Extracted block reason from a WAF response.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum BlockReason {
/// A specific WAF rule ID was triggered.
RuleId(String),
/// A category of rule was triggered (e.g., "`SQLi`", "XSS").
RuleCategory(String),
/// Vendor-specific block reason string.
VendorReason(String),
/// IP reputation block.
IpReputation,
/// Geographic block.
GeoBlock,
/// Custom block page matched.
CustomBlockPage(String),
/// Unknown / not extractable.
Unknown,
}
impl fmt::Display for BlockReason {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::RuleId(id) => write!(f, "rule {id}"),
Self::RuleCategory(c) => write!(f, "category {c}"),
Self::VendorReason(r) => write!(f, "vendor: {r}"),
Self::IpReputation => f.write_str("IP reputation"),
Self::GeoBlock => f.write_str("geo block"),
Self::CustomBlockPage(p) => write!(f, "block page: {p}"),
Self::Unknown => f.write_str("unknown reason"),
}
}
}
/// WAF response verdict — the output of the response oracle.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Verdict {
/// Request was blocked by the WAF.
Blocked {
/// Optional extracted reason for the block.
reason: Option<BlockReason>,
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// Request was allowed through.
Allowed {
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// Rate limit was applied (429 or 503 with rate-limit headers).
RateLimited {
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// A challenge (CAPTCHA, JS challenge) was returned.
/// Strategy should use a challenge solver or pick a different bypass.
ChallengeRequired {
/// Challenge platform detected (e.g., "cloudflare-challenge", "recaptcha").
platform: Option<String>,
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// Server error (5xx) not attributable to the WAF.
ServerError {
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// Soft block — partial body redaction or modified response.
Partial {
/// Why the response was considered partial.
reason: Option<BlockReason>,
/// Signals that led to this verdict.
signals: Vec<Signal>,
},
/// Conflicting signals — multiple plausible verdicts.
Ambiguous {
/// Competing verdicts and their supporting signals.
competing: Vec<(Verdict, Vec<Signal>)>,
/// Human-readable explanation of the conflict.
explanation: String,
},
}
impl Verdict {
/// Create a simple `Blocked` verdict with no reason.
#[must_use]
pub fn blocked(signals: Vec<Signal>) -> Self {
Self::Blocked {
reason: None,
signals,
}
}
/// Create a `Blocked` verdict with a specific reason.
#[must_use]
pub fn blocked_with_reason(reason: BlockReason, signals: Vec<Signal>) -> Self {
Self::Blocked {
reason: Some(reason),
signals,
}
}
/// Create an `Allowed` verdict.
#[must_use]
pub fn allowed(signals: Vec<Signal>) -> Self {
Self::Allowed { signals }
}
/// Create a `RateLimited` verdict.
#[must_use]
pub fn rate_limited(signals: Vec<Signal>) -> Self {
Self::RateLimited { signals }
}
/// Create a `ChallengeRequired` verdict.
#[must_use]
pub fn challenge_required(platform: Option<String>, signals: Vec<Signal>) -> Self {
Self::ChallengeRequired { platform, signals }
}
/// Create a `ServerError` verdict.
#[must_use]
pub fn server_error(signals: Vec<Signal>) -> Self {
Self::ServerError { signals }
}
/// Create a `Partial` verdict.
#[must_use]
pub fn partial(reason: Option<BlockReason>, signals: Vec<Signal>) -> Self {
Self::Partial { reason, signals }
}
/// Returns true if this verdict represents a hard block.
#[must_use]
pub fn is_blocked(&self) -> bool {
matches!(self, Self::Blocked { .. })
}
/// Returns true if this verdict requires a challenge solver.
#[must_use]
pub fn is_challenge(&self) -> bool {
matches!(self, Self::ChallengeRequired { .. })
}
/// Returns true if this verdict is ambiguous.
#[must_use]
pub fn is_ambiguous(&self) -> bool {
matches!(self, Self::Ambiguous { .. })
}
/// Returns true if the request was allowed (or at least not blocked).
#[must_use]
pub fn is_allowed(&self) -> bool {
matches!(self, Self::Allowed { .. })
}
/// Get all signals attached to this verdict.
#[must_use]
pub fn signals(&self) -> Vec<Signal> {
match self {
Self::Blocked { signals, .. }
| Self::Allowed { signals }
| Self::RateLimited { signals }
| Self::ChallengeRequired { signals, .. }
| Self::ServerError { signals }
| Self::Partial { signals, .. } => signals.clone(),
Self::Ambiguous { competing, .. } => {
competing.iter().flat_map(|(v, _)| v.signals()).collect()
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn verdict_blocked_creation() {
let v = Verdict::blocked(vec![Signal::StatusCode {
code: 403,
expected: 200,
}]);
assert!(v.is_blocked());
assert!(!v.is_allowed());
}
#[test]
fn verdict_challenge_creation() {
let v = Verdict::challenge_required(
Some("cloudflare".into()),
vec![Signal::ChallengePlatform("cloudflare".into())],
);
assert!(v.is_challenge());
assert!(!v.is_blocked());
}
#[test]
fn verdict_ambiguous_signals_flatten() {
let v = Verdict::Ambiguous {
competing: vec![
(
Verdict::blocked(vec![Signal::BodyMarker("denied".into())]),
vec![Signal::BodyMarker("denied".into())],
),
(
Verdict::allowed(vec![Signal::SuccessMarker("ok".into())]),
vec![Signal::SuccessMarker("ok".into())],
),
],
explanation: "conflict".into(),
};
let signals = v.signals();
assert_eq!(signals.len(), 2);
assert!(signals.contains(&Signal::BodyMarker("denied".into())));
assert!(signals.contains(&Signal::SuccessMarker("ok".into())));
}
#[test]
fn block_reason_display() {
assert_eq!(BlockReason::RuleId("1001".into()).to_string(), "rule 1001");
assert_eq!(BlockReason::IpReputation.to_string(), "IP reputation");
}
}