Detecting and Mitigating SQL Injection in .NET Applications Using AI-Based Anomaly Detection
Detecting and Mitigating SQL Injection in .NET Applications Using AI-Based Anomaly Detection
Abstract: SQL Injection (SQLi) persists as a major threat to .NET applications since attackers can inject harmful SQL code
into databases for database manipulation purposes. The presence of this vulnerability leads to hackers gaining access to
unauthorized data and causing system integrity failure while resulting in lost data which threatens organizations utilizing
these applications.
Signature-based detection systems demonstrate limited effectiveness when it comes to detecting contemporary or
innovative SQLi attacks that create new patterns. Artificial Intelligence through anomaly detection technology provides a
capable defensive solution to overcome this particular challenge. The normal behavior patterns of SQL queries inside
applications become manageable for AI systems through machine learning algorithms to detect abnormal patterns that
signal SQLi attack vulnerabilities.
The research introduces a specific AI-based anomaly detection system designed for .NET application environments.
Our research method begins with collecting SQL query logs then performing data preprocessing before extracting important
features which are used to train a machine learning model to detect between valid and hostile SQL queries. The detection
process relies on an RNN autoencoder which understands SQL query sequences thus identifying anomalous patterns related
to SQL injection.
Experimental testing shows that the proposed method reaches high detection precision alongside minimal false alarms
while detecting recognized as well as unrecognized SQLi attacks. The security position of .NET applications becomes more
robust through the implementation of this AI-based anomaly detection system in protecting against current and future SQLi
attacks.
Keywords: SQL Injection (SQLi), .NET Security, AI-Based Anomaly Detection, Machine Learning for Cybersecurity, SQL Query
Analysis, Recurrent Neural Networks (RNN), Threat Mitigation Strategies, Cybersecurity in Web Applications.
How to Cite: Sohan Singh Chinthalapudi (2025). Detecting and Mitigating SQL Injection in .NET Applications Using AI-Based
Anomaly Detection. International Journal of Innovative Science and Research Technology, 10(3), 2582-2595.
https://doi.org/10.38124/ijisrt/25mar1676
Considering the above diagram, SQL normal and SQL H. Machine Learning and AI in Cybersecurity
injection attack data flow. All subsequent strings after-are Organizations underwent major change because ML and
recognized as comments, and two SQL queries are processed AI were combined with cybersecurity to improve threat
in this instance. The result of the query process shows detection and response. Real-time malicious activity
administrator's information of the DBMS. (c) Piggy-Backed identification depends on AI-based Intrusion Detection
Queries. This attack inserts malicious SQL queries into a Systems (IDS) because these systems have become necessary
normal SQL query. It is possible because many SQL queries security tools. AIL-based IDS systems are examined together
can be processed if the operator '';'' is added after each query. with previous research on SQL injection attack anomaly
Query 3 is an instance. Note that the operator '';'' is inserted at detection within this section.
the end of query. Query 3: SELECT * FROM user WHERE
id='admin' AND password='1234'; DROP TABLE user;-'; I. Survey of AI-Based Intrusion Detection Systems (IDS)
The result of query 3 is to delete the user table. (d) Stored AI-based IDS exploits complex algorithms as its
Procedures Recently, DBMS has provided a stored analytical tools to detect patterns of cyberattacks within
procedures method with which a user can store his own network flows. Modern IDS systems detect threats through
function that can be used as needed. To use the function, a signature-based methods although these methods show
collection of SQL queries is included. An instance is shown reduced effectiveness when encountering new developing
in query 4. Query 4: CREATE PROCEDURE techniques threats. AI-based IDS utilizes machine learning models to
keep evolving.DBO @userName varchar2, @pass varchar2, identify both anomalies and newly discovered attacks known
AS EXEC("SELECT * FROM user WHERE id='" + as zero-day attacks through its system. Sommer and Paxson
@userName + "' and password='" + @password + "'); GO (2010) identify shortcomings within type signature-based
This scheme is also vulnerable to attacks such as piggy- systems yet the researchers endorse machine learning as an
backed queries. approach to produce better detection results. The modern AI-
driven IDS received its core development from the research
The traditional SQL injection prevention methods that output of these workers.
include parameterized queries along with stored procedures
and ORM frameworks with WAFs have effectively reduced Deep learning technologies made into recent
SQLi vulnerabilities. The weaknesses observed in rule-based developments to improve the functionality of AI-based IDS
approaches demonstrate that developers require better and systems. The research group of Yin et al. (2017) developed an
adaptable security solutions to fulfill their needs. Machine IDS system that implemented convolutional neural networks
learning and context-aware systems offer potential as a for detecting network intrusions effectively. The researchers
solution to enhance the defensive measures against SQLi applied their model to conduct training on the NSL-KDD
attacks as there. dataset because it functions as the standard evaluation
benchmark for IDS assessment. The research evaluation
showed deep learning techniques excel at detecting complex
network traffic patterns and deliver superior results beyond
decision trees and support vector machines (SVMs).
The integration of AI into IDS represents a significant utilized for training received data from normal and malicious
shift towards more proactive and adaptive cybersecurity queries to produce an exceptional result of lower than 2%
measures. By leveraging machine learning and deep learning false positives. The authors stated that successful defense
models, AI-based IDS can analyze vast amounts of network depends on an organization's ability to learn continuously
traffic data to detect anomalies that may signify potential while attacks persist.
intrusions. This capability is crucial in identifying zero-day
attacks that traditional signature-based systems might Mathematically, the Anomaly Detection Process can be
overlook. Represented as follows:
Fig 2 Detecting SQL Injection from Ensemble Learning and Boosting Models.
Accuracy: Formula:
Accuracy Measures the Proportion of Correctly
Classified Instances (both SQLi and Normal Queries) out of
all Instances.
Formula:
Interpretation:
Formula:
Interpretation:
Impact:
A high FPR means the system generates too many false Impact:
alarms, potentially causing unnecessary blocking of A high FNR means that many SQLi attacks go
legitimate users. undetected, making the system unreliable for security.
Definition:
The proportion of actual SQLi attacks incorrectly
classified as benign queries.
H. AI-Based SQL Injection Detection and Mitigation Detecting Malicious Payloads in Real-Time
Web applications remain highly vulnerable to SQL The identification of harmful code snippets inside SQL
Injection (SQLi) attacks because these assaults give intruders queries becomes possible through AI technology. The Natural
access to database systems and expose sensitive info. The Language Processing (NLP) techniques help break query
conventional methods which prevent attacks struggle to components into tokens while performing semantic analysis
counter modern sophisticated attack methods. Web security to detect attack-related patterns and keywords. The prompt
enhancement occurs through AI integration into SQLi analysis of threats becomes essential because it grants quick
detection and mitigation strategies which implement a abilities to respond to dangers. The research by Alghawazi, et
proactive solution. al (2022) showed that neural networks function to evaluate
incoming queries during real-time operations for SQLi
I. How AI Detects SQLi Patterns detection purposes before achieving the database.
Identifying Abnormal SQL Query Structures J. Implementing AI-Driven Anomaly Detection in NET
The training algorithms of AI models especially
machine learning algorithms learn to detect nonstandard SQL Steps to Integrate Machine Learning Models in .NET
query patterns. These models receive numerous legitimate Applications
SQL queries for analysis and use this data to understand The implementation of AI-based SQL injection
typical operational sequences and patterns. AI systems detection in .NET applications demands that three primary
identify potential maliciousness in queries when they deviate activities take place.
from previously learned normal patterns. Unorthodox 'OR
1=1' conditions and strange UNION statements trigger such A large preprocessed dataset consisting of SQL queries
alerts. An established Support Vector Machines (SVM) to along with legitimate and malicious examples needs to be
achieve analysis of query structures for the detection of collected. Prepare the data by converting speech into
benign and malicious queries. tokens while selecting essential characteristics from it.
Machine learning algorithms (Decision Trees and Neural
Networks and others) should be selected properly
Table 5 The Relationship Between the Complexity of Different AI Models and their Processing Times.
AI Model Processing Time (ms/query) Accuracy (%) False Positive Rate (%)
Decision Tree 0.5 87 12
Random Forest 1.2 91 10
Autoencoder 3.4 94 8
CNN-LSTM Model 5.1 97 6
Hybrid AI Approach 7.8 98.5 3.5
The security mechanisms benefit from FL to achieve interact in real-time with potential threats (Sutton & Barto,
continuous enhancement through multiple organizations 2018).
leading to GDPR compliance. The future development of FL
for SQLi detection needs to address three key objectives: The implementation of dynamic security rules based on
performance enhancement, communication cost reduction attack patterns is possible through an intelligent security
and resistance against adversarial attacks. agent built with an RL-based system. Resolving false
negative cases by 20% was one of the benefits of Q-learning-
Using Reinforcement Learning for Adaptive Security based SQLi defense mechanisms explained by Lo, et al.
Measures (2022).
Traditional AI-based SQLi detection models use pre-
defined patterns together with training data for static Mathematically, the RL Framework for SQLi Defense can
operation. Static models have become insufficient for modern be Represented as follows:
cyber threats because the threats continuously develop new
sophistication. RL delivers dynamic threat response through Q(s,a) ← Q(s,a) + α[r+γmaxQ(s′,a′) − Q(s,a)]
models that develop security policies optimally because they