AUTOMATED DETECTION OF SQL INJECTION VULNERABILITIES IN CHATBOTS USING REINFORCEMENT LEARNING

Authors

DOI:

https://doi.org/10.28925/2663-4023.2025.29.873

Keywords:

reinforcement learning; SQL injections; cybersecurity; penetration testing; PPO; A2C; REINFORCE.

Abstract

This paper investigates the use of reinforcement learning algorithms for automated detection of SQL injection vulnerabilities in conversational AI agents that use APIs and databases. It was developed a Gymnasium-compatible environment called SQLiChatbotEnv and implemented a system based on Proximal Policy Optimisation (PPO), Advantage Actor-Critic (A2C) and REINFORCE methods to train an intelligent agent to detect and exploit various types of SQL injections in an automated manner. The created environment simulates realistic scenarios of interaction with vulnerable chatbots, including a multi-component action space, a reward system, and mechanisms for tracking the progress of vulnerability detection. A specialised reinforcement learning environment, SQLiChatbotEnv, simulates real-world scenarios of interaction with vulnerable chatbots and allows you to configure a chatbot environment with one of 5 major database management systems to choose from (MySQL, PostgreSQL, Microsoft SQL Server, Oracle, and SQLite). SQLiChatbotEnv also supports several key types of SQL injections, such as union-based attacks and error-based exploitation, and allows you to explore the database schema – to identify table and column names. The system allows you to use SQL query obfuscation in a message to a chatbot, which allows you to bypass basic security checks that may be present in a real system. Contextual framing allows you to use the natural integration of SQL injection into the conversation, for example, masking with phrases such as ‘I'm trying to understand...’, imitating the behaviour of a regular user. To encourage the agent to search for vulnerabilities efficiently, the system allows you to configure rewards and penalties for typical actions, such as discovering new information, data leakage, or using a SQL injection template that is incompatible with the actual database type. A comparative analysis of the performance of the three reinforcement learning algorithms over 2500 training episodes is conducted. The experimental results show that A2C demonstrates the best combination of convergence speed and learning stability, reaching a reward of 100 points in 30 episodes and a final performance of 232.82 ± 16.44 with the lowest coefficient of variation of 16.5%. PPO is characterised by the slowest convergence to high thresholds (221 episodes to a score of 150) and the highest variability of results (35.6%), but demonstrates the best ability to fully detect all types of vulnerabilities (87.4% of episodes). REINFORCE shows balanced intermediate results with a moderate convergence rate (145 episodes to a reward of 100), stability (coefficient of variation 21.4%) and high efficiency of vulnerability research (78.0% of episodes with all types of attacks). The practical significance of the work is to create an automated tool for testing the security of conversational AI agents. The results of the study demonstrate the prospects of using reinforcement learning for cybersecurity tasks and automating penetration testing processes.

Downloads

Download data is not yet available.

References

OWASP Foundation. (2021). OWASP top 10: The ten most critical web application security risks. https://owasp.org/Top10/

MITRE. (2024). CWE top 25 most dangerous software weaknesses. https://cwe.mitre.org/top25/archive/2024/2024_cwe_top25.html

Capuano, N. (2022). A context-aware model for smart learning environments supporting decision making and adaptation. IEEE Access. Advance online publication. https://www.capuano.cloud/papers/IEEE_Access_2022.pdf

Papadopoulos, P., Iliadis, L., Pimenidis, E., & Loukas, G. (2020). Cybersecurity incident response training using a tabletop exercise approach: A case study from maritime logistics. In Proceedings of the 5th IEEE European Symposium on Security and Privacy Workshops (pp. 2–9). IEEE. https://conferences.computer.org/eurosp/pdfs/EuroSPW2020/859700a002.pdf

Del Verme, M., Sommervoll, Å. Å., Erdődi, L., Totaro, S., & Zennaro, F. M. (2021). SQL injections and reinforcement learning: An empirical evaluation of the role of action structure. In K. Bernsmed & B. Moen (Eds.), Secure IT systems: Proceedings of the 26th Nordic Conference, NordSec 2021 (pp. 95–113). Springer. https://doi.org/10.1007/978-3-030-91638-5_6

Becker, N., Reti, D., Ntagiou, E. V., Wallum, M., & Schotten, H. D. (2024). Evaluation of reinforcement learning for autonomous penetration testing using A3C, Q-learning and DQN. arXiv. https://arxiv.org/abs/2407.15656

Pedro, R., Coimbra, M. E., Castro, D., Carreira, P., & Santos, N. (2025). Prompt-to-SQL injections in LLM-integrated web applications: Risks and defenses. In Proceedings of the 47th IEEE/ACM International Conference on Software Engineering (ICSE) (pp. 76–88). IEEE. https://doi.org/10.1109/ICSE55347.2025.00007

Alghawazi, M., Alghazzawi, D., & Alarifi, S. (2022). Detection of SQL injection attack using machine learning techniques: A systematic literature review. Journal of Cybersecurity and Privacy, 2(4), 764–777. https://doi.org/10.3390/jcp2040039

Irungu, J. N., Jebur, H. H., Ibrahim, R. W., & Arpnikanondt, C. (2023). Artificial intelligence techniques for SQL injection attack detection. In Proceedings of the 12th International Conference on Software and Computer Applications (pp. 138–143). ACM. https://doi.org/10.1145/3591569.3591576

Al Wahaibi, S. A., Foley, M., & Maffeis, S. (2023). SQIRL: Grey-box detection of SQL injection vulnerabilities using reinforcement learning. In Proceedings of the 32nd USENIX Security Symposium (pp. 6097–6114). USENIX. https://www.usenix.org/conference/usenixsecurity23

Yang, Y., Chen, L., Liu, S., Wang, L., Fu, H., & Liu, X. (2025). Behaviour-diverse automatic penetration testing: A coverage-based deep reinforcement learning approach. Frontiers of Computer Science, 19, Article 193309. https://doi.org/10.1007/s11704-024-3380-1

Li, M., Zhu, T., Yan, H., Chen, T., & Lv, M. (2025). HER-PT: An intelligent penetration testing framework with hindsight experience replay. Computers & Security, 152, 104357. https://doi.org/10.1016/j.cose.2025.104357

Downloads


Abstract views: 6

Published

2025-09-26

How to Cite

Vikulov, V., & Pyshnograiev, I. (2025). AUTOMATED DETECTION OF SQL INJECTION VULNERABILITIES IN CHATBOTS USING REINFORCEMENT LEARNING. Electronic Professional Scientific Journal «Cybersecurity: Education, Science, Technique», 1(29), 223–235. https://doi.org/10.28925/2663-4023.2025.29.873