This project implements an advanced security system designed to protect web applications from Command Injection attacks. By leveraging Natural Language Processing (NLP) and Machine Learning, the system identifies malicious patterns in user inputs that traditional signature-based filters might miss.
- NLP-Powered Detection: Uses
TfidfVectorizerwith character-level n-grams (2-4) to capture structural nuances of command injection payloads. - Automated ML Pipeline: Integrates preprocessing and classification into a robust
sklearn.pipeline. - Hyperparameter Optimization: Utilizes
GridSearchCVto optimize Logistic Regression and Random Forest models. - Middleware Simulation: Includes logic to categorize inputs into
BLOCK,LOG_AND_ALLOW, orALLOWbased on confidence thresholds.
- Language: Python
- Libraries: Scikit-learn, Pandas, NumPy, Seaborn, Matplotlib
- Techniques: TF-IDF (Char n-grams), Logistic Regression, Random Forest
Before training the model, you must generate the training data:
- Run the Dataset Creation Notebook (
Command Line Injection-Dataset_Creation.ipynb). This script will synthesize a balanced dataset of benign and malicious strings and save it asadvanced_command_injection_dataset.jsonlin the project directory.
Install the required Python dependencies:
pip install pandas scikit-learn seaborn matplotlib- Run the main project notebook to load the generated
.jsonlfile. - The script will perform a stratified split, tune hyperparameters, and save the best-performing pipeline to
adv_model/Logistic_Regression_pipeline.pkl.
Use the inspect_input() function within the notebook to test the real-time middleware logic against custom strings.
- Best Model: Logistic Regression (C=10)
- Accuracy: ~99.98%
- F1-Score: 1.00
This project is licensed under the MIT License.