CoolFace
Modelpublic

cycloevan/http-attack-classification

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
Model Card

HTTP Attack Classification Models

A collection of machine learning models for detecting and classifying HTTP-based cyber attacks from raw request logs. Each model takes a raw HTTP request string as input and classifies it into one of 9 attack categories.


Task

  • Task: Multi-class Text Classification
  • Domain: Network Security / Intrusion Detection
  • Input: Raw HTTP request string (method, path, headers, body)
  • Output: One of 9 attack type labels

Attack Types

ClassDescriptionCommon Indicators
Vulnerability_ScanAutomated scanning for known vulnerabilitiessqlmap, nikto, nmap user-agents; repeated probing patterns
System_Cmd_ExecutionOS command injection attempts`\, ;, &&, wget, curl, /bin/sh, boot.ini`
HOST_ScanNetwork host discovery and port scanningMinimal headers, bare GET /, nmap scripting engine
Path_DisclosureDirectory traversal and file path exposure../, ..%2F, /etc/passwd, /etc/shadow, /proc/
SQL_InjectionSQL injection in query parametersUNION SELECT, OR 1=1, --, ', boolean-based blind patterns
Cross_Site_ScriptingXSS payload injection<script>, onerror=, javascript:, alert(), prompt()
Automatically_Searching_InforAutomated information gatheringCrawlers, /_vti_pvt/, robots.txt, sitemap.xml probing
Leakage_Through_NWSensitive file access via networkAccess to config files, logs, backups (.ico, .conf, .bak)
Directory_IndexingBrowsing exposed directory listingsTrailing / on directory paths, source/workspace/src paths

Models

FileModelFeature ExtractionTest AccuracyNotes
tdidf-svc.joblibTF-IDF + LinearSVCword, default87.4%Best generalization
xgb_char.joblibTF-IDF + XGBoostchar, ngram(1,2), max_features=102488.5%Best local accuracy
xgb_word.joblibTF-IDF + XGBoostword, NLTK tokenizer86.7%
lgb_model.joblibTF-IDF + LightGBMword, NLTK tokenizer86.5%
rf_nltk.joblibTF-IDF + RandomForestword, NLTK, n_estimators=100084.8%
rf_gridsearch.joblibTF-IDF + RandomForestword, GridSearchCV best83.6%best: maxdepth=None, nestimators=150
rf_basic.joblibTF-IDF + RandomForestword, default83.3%
catboost.joblibTF-IDF + CatBoostword, NLTK tokenizer83.0%
multinomial_nb.joblibCountVectorizer + MultinomialNBword, default67.5%Baseline
lstm_bidirectional.h5BiLSTMKeras Tokenizer, maxlen=21685.2%Requires Keras/TF
textcnn_model.h5TextCNNKeras Tokenizer, maxlen=25686.1%Requires Keras/TF

Usage

Preprocessing

python
import urllib.parse

def preprocess(payload: str) -> str:
    return urllib.parse.unquote_plus(payload)

sklearn-based models (joblib)

Applies to: tdidf-svc.joblib, xgb_char.joblib, xgb_word.joblib, lgb_model.joblib, rf_*.joblib, catboost.joblib, multinomial_nb.joblib

Each file is a scikit-learn Pipeline with the vectorizer and classifier bundled together — raw text can be passed directly.

python
import joblib

model = joblib.load("xgb_char.joblib")

payloads = [
    "GET /../../../../etc/passwd HTTP/1.1\r\nHost: 10.0.0.1\r\n",
    "GET /search?q=' OR 1=1-- HTTP/1.1\r\nHost: example.com\r\n",
]
predictions = model.predict(payloads)
print(predictions)
# ['Path_Disclosure', 'SQL_Injection']

Keras-based models (.h5)

python
import numpy as np
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
import joblib

model = load_model("lstm_bidirectional.h5")       # or textcnn_model.h5
tokenizer = joblib.load("tokenizer.joblib")        # must be saved separately during training

payloads = ["GET /../../../../etc/passwd HTTP/1.1\r\nHost: 10.0.0.1"]
sequences = tokenizer.texts_to_sequences(payloads)
padded = pad_sequences(sequences, maxlen=216)      # maxlen=256 for TextCNN

pred = model.predict(padded)
label_idx = np.argmax(pred, axis=1)
print(label_idx)

Evaluation

Per-model summary

ModelAccuracyMacro F1Weakest Class (F1)
TF-IDF + XGBoost (char)88.5%0.92SystemCmdExecution (0.84)
TF-IDF + LinearSVC87.4%SystemCmdExecution
TF-IDF + XGBoost (word)86.7%0.90SystemCmdExecution (0.83)
TF-IDF + LightGBM86.5%0.91SystemCmdExecution (0.83)
TextCNN86.1%0.89SystemCmdExecution (0.79)
BiLSTM85.2%0.89SystemCmdExecution (0.78)

Per-class observations

  • Easiest classes: Automatically_Searching_Infor and Leakage_Through_NW achieve F1 ≥ 0.99 across all models — highly distinctive tool signatures (nmap, crawlers) and file access patterns make them trivial to separate.
  • Hardest class: System_Cmd_Execution consistently scores the lowest F1 (0.75–0.84) due to pattern overlap with Vulnerability_Scan. Both classes involve probing behavior with similar HTTP structure.
  • char-level XGBoost advantage: Sub-word character n-grams capture attack-specific tokens like ../, <script>, UNION more robustly than word tokenization, especially for obfuscated payloads.

Architecture Details

BiLSTM

Embedding(22,883 vocab, dim=100, maxlen=216)
→ Bidirectional(LSTM(64)) → LSTM(32) → Dense(512) → Dense(9, softmax)
  • EarlyStopping(monitor=val_accuracy, patience=3) — triggered at epoch 20
  • Saved: lstm_bidirectional.h5 (28 MB)

TextCNN

Embedding(20,000 vocab, dim=128, maxlen=256)
→ Conv1D(128, kernel=3) ─┐
→ Conv1D(128, kernel=4) ──→ GlobalMaxPool → Concat(384) → Dense(256) → Dropout(0.3) → Dense(9, softmax)
→ Conv1D(128, kernel=5) ─┘
Total params: 2.86M
  • EarlyStopping(monitor=val_loss, patience=3) — triggered at epoch 5
  • Saved: textcnn_model.h5 (33 MB)

Key Findings

  • TF-IDF outperforms deep learning on HTTP attack data: attack patterns rely on decisive keywords (UNION SELECT, ../, <script>, wget). Bag-of-words representations capture these directly, while sequential models can be distracted by irrelevant header noise.
  • char-level features beat word-level: Character n-grams handle URL encoding variations and partial token matches more effectively (e.g., %3Cscript%3E vs <script>).
  • Class imbalance effect: Vulnerability_Scan dominates at 37.5% — models tend to over-predict this class for ambiguous samples.

Environment

ItemValue
Python3.12
scikit-learn1.x
XGBoost3.2.0
LightGBM4.6.0
CatBoost1.2.10
TensorFlow / Keras2.x

License

MIT License