With the world\'s fast evolving digital environment, web applications are at the centre of action in all industries like e-commerce, finance, healthcare, and education. With their increasing complexity and size, they are also open to enhanced cyber threats. One of the most stubborn and destructive among them is SQL Injection (SQLi), which involves attackers leveraging flaws in an application\'s database interaction layer to inject malicious SQL code through user inputs. It has serious repercussions, ranging from unauthorized access to data, loss or corruption of data, and total control of the backend database server. This project seeks to develop and deploy a complete, real-time SQL Injection detection and alert system that counters these attacks through a multi-layered security model. The solution proposed uses both proactive and reactive defence systems to provide strong protection. Proactive techniques involve input sanitization, parameterized queries, and web application firewalls to stop malicious input from being sent to the database. Concurrently, the reactive part entails real-time SQL query monitoring with machine learning techniques and pattern matching to identify anomalous or suspicious activity pointing to SQLi attempts. Once a threat is identified, the system promptly alerts administrators and activates automated containment processes to contain damage and avoid escalation. This comprises blocking suspect IP addresses, closing affected sessions, and logging events for analysis. By combining multiple defence layers and focusing on real-time detection and response, this system not only mitigates existing SQLi attack vectors but is also responsive to changing threat patterns. Overall, the proposed framework strengthens the security posture of web applications as a whole and ensures the confidentiality, integrity, and availability of sensitive data in an ever-connected digital space.
Introduction
Web-based operations in critical industries handle sensitive data and face significant cybersecurity risks, with SQL Injection (SQLi) attacks being one of the most common and dangerous threats. SQLi exploits vulnerabilities in input validation to inject malicious SQL code, potentially leading to data breaches, unauthorized access, or system compromise. Despite growing cybersecurity awareness, SQLi remains prevalent due to insecure coding and weak defenses.
The paper proposes a robust security framework combining secure coding practices, Zero Trust architecture, multi-factor authentication (MFA), and real-time anomaly detection via Snort IDS to prevent and detect SQLi attacks. Parameterized queries and input sanitization form the proactive defense, while Snort provides a reactive, real-time alert system. Testing showed 100% blocking of various SQLi attack types with minimal system overhead.
A comprehensive literature survey reviews existing research and methods, including machine learning models for SQLi detection and evolving attack techniques, highlighting the need for adaptive, multi-layered defense systems.
The methodology involved creating a deliberately vulnerable web application with Python (Flask) and MySQL, simulating attacks using automated (SQLmap) and manual tools, and then applying secure coding, JWT authentication, MFA, RBAC, and Snort-based detection. Results demonstrate effective SQLi mitigation with high accuracy and manageable performance impact.
Future work should focus on adaptive machine learning models, behavioral analysis for covert attacks, broader injection detection (e.g., XPath, NoSQL), and integration with centralized security monitoring systems.
Conclusion
During this research, we studied the imminent threat of SQL injection attacks and proposed a main protective measure that enables secure coding, the Zero Trust model, and detection via honeytokens. The attack aims of SQL injections stem from a lack of proper validation of user input and insufficiently secured database access, which poses a lingering threat to many web applications. Based on the data collected, it was evident that the use of parameterized queries in addition to validation checks significantly enhances security.
Moreover, the adoption of Zero Trust policies greatly enhances security fortification for the system, since no user or element is considered as taken for granted — Instead, they are subjected under control, authentication, and hostile internal threat mitigation systems which are critical for epidemiology core components shield cores. The use of honeytokens permits users to have advanced beyond identification to sophisticated identification systems that raise red flags for heightened posturing against advanced persistent threats that could otherwise sneak past firewalls and/or intrusion detection systems.
As mentioned, these additional defensive layers have improved the prior single-tier solutions. While able to improve the prevention and detection capabilities within the proposed framework, further investigation would be best focused on automation of identification systems using the core concept of machine intelligence.
References
[1] S. S. A. Krishnan, A. N. Sabu, ; Priya, P. Sajan, and ; A L Sreedeep, “SQL Injection Detection Using Machine Learning,” 2021.
[2] Niranjan. Suri and Giacomo. Cabri, Adaptive, dynamic, and resilient systems. CRC Press, Taylor & Francis Group, 2014.
[3] U. Farooq, “Ensemble Machine Learning Approaches for Detection of SQL Injection Attack,” in TehnickiGlasnik, University North, 2021, pp. 112–120. doi: 10.31803/tg-20210205101347.
[4] R. Pedro, D. Castro, P. Carreira, and N. Santos, “From Prompt Injections to SQL Injection Attacks: How Protected is Your LLM-Integrated Web Application?,” Jan. 2025, [Online]. Available: http://arxiv.org/abs/2308.01990
[5] C. I. Biringa and G. I. Kul, “A Secure Design Pattern Approach Toward Tackling Lateral-Injection Attacks.”
[6] H. S. Anderson and P. Roth, “EMBER: An Open Dataset for Training Static PE Malware Machine Learning Models,” Apr. 2018, [Online]. Available: http://arxiv.org/abs/1804.04637
[7] K. Tasdemiret al., “Advancing SQL Injection Detection for High-Speed Data Centers: A Novel Approach Using Cascaded NLP,” Dec. 2023, [Online]. Available: http://arxiv.org/abs/2312.13041
[8] M. Olalere, “A Naïve Bayes Based Pattern Recognition Model for Detection and Categorization of Structured Query Language Injection Attack,” International Journal of Cyber-Security and Digital Forensics, vol. 7, no. 2, pp. 189–199, 2018, doi: 10.17781/P002396.
[9] F. Yudo Hernawan, I. Hidayatulloh, and I. Fuaddina Adam, “Hybrid method integrating SQL-IF and Naïve Bayes for SQL injection attack avoidance,” Journal of Engineering and Applied Technology, vol. 1, no. 2, 2020, [Online]. Available: https://journal.uny.ac.id/index.php/jeatech
[10] F. G. Deriba, A. O. Salau, S. H. Mohammed, T. M. Kassa, and W. B. Demilie, “Development of a Compressive Framework Using Machine Learning Approaches for SQL Injection Attacks,” PrzegladElektrotechniczny, vol. 98, no. 7, pp. 181–187, 2022, doi: 10.15199/48.2022.07.30.
[11] 2017 IFIP IEEE Symposium on Integrated Network and Service Management (IM). IEEE, 2017.
[12] I. Zada et al., “Enhancing IoT cybersecurity through lean-based hybrid feature selection and ensemble learning: A visual analytics approach to intrusion detection,” PLoS One, vol. 20, no. 7 July, Jul. 2025, doi: 10.1371/journal.pone.0328050.
[13] S. Mishra, “SQL Injection Detection Using Machine Learning,” San Jose State University, San Jose, CA, USA, 2019. doi: 10.31979/etd.j5dj-ngvb.
[14] Y. Abdulmalik, “An Improved SQL Injection Attack Detection Model Using Machine Learning Techniques,” International Journal of Innovative Computing, vol. 11, no. 1, pp. 53–57, Apr. 2021, doi: 10.11113/ijic.v11n1.300.
[15] Mohammed A M Oudah and Mohd Fadzli Marhusin, “SQL Injection Detection using Machine Learning: A Review,” Malaysian Journal of Science Health & Technology, vol. 10, no. 1, pp. 39–49, Apr. 2024, doi: 10.33102/mjosht.v10i1.368.
[16] S. Shahadha Mahmood, “SQL Injection Detection Using Machine Learning and Explainability,” Journal of Internet Services and Information Security, vol. 15, no. 2, pp. 309–324, May 2025, doi: 10.58346/jisis.2025.i2.022.
[17] Y. Abdulmalik, “An Improved SQL Injection Attack Detection Model Using Machine Learning Techniques,” International Journal of Innovative Computing, vol. 11, no. 1, pp. 53–57, Apr. 2021, doi: 10.11113/ijic.v11n1.300.
[18] J. M. Alkhathami and S. M. Alzahrani, “DETECTION OF SQL INJECTION ATTACKS USING MACHINE LEARNING IN CLOUD COMPUTING PLATFORM,” J Theor Appl Inf Technol, vol. 15, no. 15, 2022, [Online]. Available: www.jatit.org
[19] Niranjan. Suri and Giacomo. Cabri, Adaptive, dynamic, and resilient systems. CRC Press, Taylor & Francis Group, 2014.
[20] M. Alghawazi, D. Alghazzawi, and S. Alarifi, “Deep Learning Architecture for Detecting SQL Injection Attacks Based on RNN Autoencoder Model,” Mathematics, vol. 11, no. 15, Aug. 2023, doi: 10.3390/math11153286.
[21] J. P. Singh, “Analysis of SQL Injection Detection Techniques.” [Online]. Available: http://exploitable-web.com/link.php?id=1’