Rate This Document
Findability
Accuracy
Completeness
Readability

KADD

KADD is an AI-based anomaly data detection library of Kunpeng BoostKit for IDA. It provides SQL injection (SQLi) and prompt injection (PI) detection capabilities.

SQLi Detection Library

In WAF applications, common attacks such as SQLi are detected by using regular expressions or fingerprints to describe attack features and perform text matching. This requires expert capabilities to build and maintain rule libraries. In actual deployment, rule-based detection methods are likely to be bypassed by attackers using rule vulnerabilities, and the method of parsing text to generate fingerprints for matching suffers from low detection throughput. To lower the threshold for building rule sets and improve detection accuracy and throughput, the AI-based SQLi attack detection technology has emerged, which enables fast SQL syntax parsing, SQLi feature extraction, and SQLi detection and inference based on text.

Figure 1 SQLi detection process

KADD implements an SQL injection detection engine that uses DFA lexical analysis and mode recognition (ML/DL). It first splits any input string into an SQL semantic token sequence, and then uses a trained model to output the injection probability in the range of [0, 1]. In this way, it can determine whether the input is an SQL injection attack at the database level, offline, and with low latency. After the DFA outputs the token sequence, you can choose to use the ML (random forest model) or DL (TextCNN) mode for inference and detection.

Figure 2 Lexical analyzer process

As shown in the preceding figure, the lexical analyzer performs SQL syntax parsing on the text to be detected and outputs a token sequence. The core of the lexical analyzer in the runtime is the deterministic finite automaton (DFA) engine. It performs table lookup and state transition based on the content of the text to be detected and the state transition table, and outputs the corresponding token when the accepting state is activated. The state transition table contains a large number of state IDs, which are inconvenient for direct writing, reading, and debugging. To address this, KADD provides syntax for describing DFAs, namely DFALang. Accordingly, the SQL syntax parsing logic is described in the format defined by DFALang. In addition, KADD provides a DFA compiler to compile DFALang into a state transition table. The following describes the logical processes of the ML and DL modes.

Figure 3 Logical process of the ML mode

As shown in the preceding figure, the ML mode detection first performs SQLi feature extraction and calculation based on the token sequence output by the lexical analyzer. Feature extraction consists of two parts. First, a sliding window representing the distance weight is used as a convolution kernel to perform convolution calculation on the token sequence. Then, histogram statistics are collected on the convolution result by the token type dimension, and the token sequence is converted into a feature vector with a fixed dimension. The ML inference engine performs inference and detection based on the feature vectors output by the feature extractor and the model. The detection uses a random forest model to perform binary classification on the feature vectors to determine whether the input is an SQLi attack. During source code compilation, the inference engine preferentially uses the native binary model (krf) on the Kunpeng platform that supports SVE, and otherwise falls back to ONNX Runtime to ensure cross-platform value consistency.

Figure 4 Logical process of the DL mode

As shown in the preceding figure, the DL mode detection first truncates or pads the token sequence output by the lexical analyzer to 300-dimensional data features, feeds the features into the multi-scale TextCNN, and then outputs the inference result to determine whether the input is an SQLi attack. During source code compilation, the inference engine preferentially uses the native binary model (kcn) on the Kunpeng platform that supports SVE, and otherwise falls back to ONNX Runtime to ensure cross-platform value consistency.

Key technologies:

Lexical analyzer, feature extractor, inference engine, ML, and DL.

Applicable scenarios:

SQLi detection, etc.

PI Detection Library

When an LLM provides external services, it must perform security interception on user inputs to defend against prompt injection and jailbreak attacks, such as role-playing, persuasion, mode switching, and refusal suppression. Such attack texts are highly variable and well-camouflaged, making it difficult to balance both accuracy and latency using only keyword rules or a single model: rules are fast but have incomplete coverage, while deep models are accurate but computationally expensive. Therefore, PI adopts a multi-stage cascaded filtering architecture consisting of "rule-first interception + semantic model fallback." The vast majority of normal samples and obviously malicious samples are quickly and directly determined by deterministic rules, while only complex semantic-level attacks that cannot be identified by rules enter the Transformer model for final adjudication, thereby striking a balance among throughput, latency, and accuracy. In addition, ONNX export and INT8 quantization are used to reduce model inference overhead, enabling efficient deployment on Kunpeng CPUs.

Figure 5 PI detection process

The entire detection process uses a three-stage cascaded pipeline with an early-exit mechanism (stop-on-hit policy). The input prompt first passes through the blocklist/trustlist filter (using jieba tokenization + MinHash signatures + MinHashLSH similarity search). A blocklist match is identified as a jailbreak attempt, a trustlist match is allowed to pass, and an unmatched prompt proceeds to the regular expression filter (sequentially searching against 5 pre-compiled regular expressions). Any match here is identified as a jailbreak attempt. Only if there is still no match does the prompt incur the highest computational cost and proceed to the model classification filter (INT8 ONNX version of the fine-tuned Chinese-lert-small model). A hit at any stage immediately returns the result, allowing the vast majority of normal and obviously malicious samples to bypass high-cost inference. The Transformer is only invoked for semantic-level attacks that the rules cannot "understand," thereby balancing throughput and accuracy.

Key technologies:

Blocklist/trustlist detection, regular expression matching, and model classification.

Applicable scenarios:

PI detection and jailbreak detection.