wafrift_encoding/encoding/keyword/
sql.rs1use std::fmt::Write as _;
4
5pub fn between_obfuscate(payload: &str) -> String {
9 let mut result = String::with_capacity(payload.len() * 3);
10 for ch in payload.chars() {
11 if ch == '=' {
12 result.push_str(" BETWEEN 0 AND ");
15 } else if ch == '>' {
16 result.push_str(" NOT BETWEEN 0 AND ");
17 } else {
18 result.push(ch);
19 }
20 }
21 result
22}
23
24pub fn unmagic_quotes(payload: impl AsRef<[u8]>) -> String {
29 let payload = payload.as_ref();
30 let payload_str = String::from_utf8_lossy(payload);
31 payload_str.replace('\'', "%bf%27")
34}
35
36pub fn percentage_prefix(payload: &str) -> String {
41 let mut out = String::with_capacity(payload.len() * 2);
42 for ch in payload.chars() {
43 let _ = write!(&mut out, "%{ch}");
44 }
45 out
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn between_obfuscate_basic() {
54 assert_eq!(between_obfuscate("id=1"), "id BETWEEN 0 AND 1");
55 assert_eq!(between_obfuscate("id>0"), "id NOT BETWEEN 0 AND 0");
56 }
57
58 #[test]
59 fn unmagic_quotes_basic() {
60 assert_eq!(unmagic_quotes("' OR 1=1--"), "%bf%27 OR 1=1--");
61 }
62
63 #[test]
64 fn percentage_prefix_basic() {
65 assert_eq!(percentage_prefix("SELECT"), "%S%E%L%E%C%T");
66 }
67}