Overview
Traditional network security systems rely on rule-based signature matching, which needs constant manual updates and misses novel attack variants. This project replaces that approach with a machine learning classifier trained on raw HTTP payloads from network security appliance logs.
The model classifies each payload into one of five categories: brute force, cross-site scripting, SQL injection, system command execution or normal. It was built during the KISA AI Security Monitoring Specialist Training Program in South Korea.
Dataset
| Label | Attack type | Count | Share |
|---|---|---|---|
Brute_Force | Credential stuffing with automated tools (Hydra); 100% POST requests | 135,037 | 61.4% |
normal | Legitimate traffic baseline | 44,000 | 20.0% |
Cross_Site_Scripting | XSS from scanner tools (Arachni, Nikto); 97% GET requests | 16,542 | 7.5% |
SQL_Injection | SQLmap-driven injection attempts; HTTP/1.1 only | 12,525 | 5.7% |
System_Cmd_Execution | OS command injection, identified by the Connector user agent | 11,896 | 5.4% |
| Total | 220,000 | 100% | |
Feature engineering
Rather than vectorising raw text, which is computationally expensive at this scale, we ran a statistical frequency analysis across label and payload pairs to find keywords that appeared with high discriminative frequency for specific attack classes. Nine binary or categorical features were extracted from each payload string.
| Feature | What it encodes | Signal |
|---|---|---|
method | HTTP method (GET = 1, POST = 0) | Brute force is 100% POST |
ver | HTTP version (1.0 = 1, 1.1 = 0) | Brute force skews to HTTP/1.0 |
word | OS or tool keyword: hydra (1), linux (2), win (3), mac (4), nikto (5) | hydra appears only in brute force |
sql | “sqlmap” in the payload | Strong indicator of SQL injection |
ar | “arachni” scanner present | XSS and command execution |
uid | “userid” parameter present | Brute force login targeting |
zap | OWASP ZAP scanner present | Active scanning, brute force |
connector | “connector” user agent present | Command execution only |
apple | “applewebkit” user agent present | Distinguishes normal traffic |
Preprocessing pipeline
# Feature extraction and encoding pipeline
def prepro(data):
# Structural features from payload token positions
data['method'] = data['payload'].str.split().str[0] # GET / POST
data['ver'] = data['payload'].str.split().str[1] # HTTP version
# Keyword-based binary feature extraction
data['sql'] = data['payload'].apply(add_sql) # sqlmap presence
data['word'] = data['payload'].apply(add_word) # OS/tool keyword
data['ar'] = data['payload'].apply(add_ar) # arachni scanner
data['uid'] = data['payload'].apply(add_uid) # userid param
data['connector'] = data['payload'].apply(add_con) # connector UA
data['zap'] = data['payload'].apply(add_zap) # ZAP scanner
data['apple'] = data['payload'].apply(add_apple) # AppleWebKit UA
# Label encoding
data['ver'] = data['ver'].map({'HTTP/1.1': 0, 'HTTP/1.0': 1})
data['method'] = data['method'].map({'POST': 0, 'GET': 1})
return data[['method', 'ver', 'word', 'uid', 'ar', 'sql', 'connector', 'zap', 'apple']], tg
Model training
| Train and test split | 80% / 20%, stratified by label |
|---|---|
| Random seed | 42 |
| Test set size | 44,000 samples |
| Stratification | Class distribution preserved across splits |
| Hardware | Intel i9-13900, 64 GB RAM, RTX 4070 |
| Environment | Python 3.12.7, Anaconda, Jupyter Lab |
Why Random Forest
Three classifiers were evaluated. Random Forest, a bagging ensemble, was chosen as the primary model: it matched XGBoost’s overall accuracy, beat Logistic Regression, and trained significantly faster. Randomly sampling subsets of the data and averaging across parallel trees proved more stable on this imbalanced dataset.
Results
| Model | Accuracy |
|---|---|
| Random Forest | 92.6% |
| XGBoost | 92.6% |
| Logistic Regression | 91.7% |
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
Brute_Force | 0.99 | 1.00 | 0.99 | 27,008 |
normal | 0.93 | 0.99 | 0.96 | 8,800 |
SQL_Injection | 1.00 | 0.87 | 0.93 | 2,505 |
Cross_Site_Scripting | 0.55 | 0.87 | 0.67 | 3,308 |
System_Cmd_Execution | 1.00 | 0.02 | 0.04 | 2,379 |
| Weighted average | 0.95 | 0.93 | 0.91 | 44,000 |
Known limitations
Command execution is almost entirely missed
Recall for System_Cmd_Execution is 0.02 (F1 0.04). This comes from the keyword-based feature engineering: the connector feature, while unique to this class, was not enough as a sole discriminator. It is also the smallest class (5.4%), which amplifies the imbalance.
Class imbalance flatters the headline
Brute force makes up 61.4% of samples, pulling overall accuracy up. The weighted F1 of 0.91 leans on brute force’s 0.99; the macro F1 of 0.72 is the truer measure of performance across classes.
Future improvements
- Replace keyword features with TF-IDF or embedding vectorisation of the full payload, removing manual keyword curation and capturing richer signal.
- Apply SMOTE or class-weight balancing to counter brute-force dominance and lift command execution recall.
- Tune hyperparameters with GridSearchCV or Bayesian optimisation (Optuna) to improve XSS and command execution.
- Evaluate on external datasets (UNSW-NB15, KISTI Network Intrusion) to test generalisation beyond the training domain.
- Explore sequence-aware deep learning (LSTM or transformer-based) for payload classification.