Detection of SQL Injection Attack Using Machine Learning Based On Natural Language Processing

(1) Joko Triloka Mail (Institut Informatika dan Bisnis Darmajaya, Indonesia)
(2) * Hartono Hartono Mail (Institut Informatika dan Bisnis Darmajaya, Indonesia)
(3) Sutedi Sutedi Mail (Institut Informatika dan Bisnis Darmajaya, Indonesia)
*corresponding author


There has been a significant increase in the number of cyberattacks. This is not only happening in Indonesia, but also in many countries.  Thus, the issue of cyber attacks should receive attention and be interesting to study.  Regarding the explored security vulnerabilities, the Open Web Application Security Project has published the Top-10 website vulnerabilities. SQL Injection is still become one of the website vulnerabiliteis which is often exploited by attacker. This research has implemented and tested five algorithms. They are Naïve Bayes, Logistic Regression, Gradient Boosting, K-Nearest Neighbor, and Support Vector Machine. In addition, this study also uses natural language processing to increase the level of detection accuracy, as a part of text processing. Therefore, the main dataset was converted to corpus to make it easier to be analyzed. This process was carried out on feature enginering stage. This study used two datasets of SQL Injection. The first dataset was used to train the classifier, and the second dataset was used to test the performance of classifier. Based on the tests that have been carried out, the Support Vector Machine get the highest level of accuracy detection. The accuracy of detection is 0.9977 with 0,00100 micro seconds per query time of process. In performance testing, Support Vector Machine classifier can detect 99,37% of second dataset. Not only Support Vector Machine, the study have also revealed the detection accuracy level of further tested algorithms: K-Nearest Neighbor (0,9970), Logistic Refression (0,9960), Gradient Boosting (0,99477), and Naïve Bayes (0,9754).


Cyber Security; Machine Learning; Support Vector Machine; SVM Based NLP; Multi-Layer Security



Article metrics

10.29099/ijair.v6i2.355 Abstract views : 137 | PDF views : 43




Full Text



“Cybersecurity Statistics for 2021,” Packetlabs, Aug. 03, 2021. (accessed Nov. 05, 2021).

“Protecting against cyber threats during COVID-19 and beyond,” Google Cloud Blog. (accessed Nov. 05, 2021).

“How Many Cyber Attacks Happen Per Day? [2021 Stats and Facts],” TechJury, Jul. 15, 2020. (accessed Nov. 05, 2021).

“2021 Cyber Security Statistics Trends & Data,” PurpleSec, Nov. 08, 2020. (accessed Nov. 05, 2021).

A. Yusuf, Laporan Tahunan 2020 Honeynet Project BSSN - IHP. Badan Siber dan Sandi Negara, 2020.

B. Akhgar, A. Staniforth, and F. Bosco, “Cyber Crime and Cyber Terrorism Investigator’s Handbook,” p. 399.

OWASP, “A04 Insecure Design - OWASP Top 10:2021.” (accessed Nov. 18, 2021).

M. Akbar and M. A. F. Ridha, “SQL Injection and Cross Site Scripting Prevention Using OWASP Web Application Firewall,” p. 7.

A. Marchand-Melsom and D. B. Nguyen Mai, “Automatic repair of OWASP Top 10 security vulnerabilities: A survey,” in Proceedings of the IEEE/ACM 42nd International Conference on Software Engineering Workshops, Seoul Republic of Korea, Jun. 2020, pp. 23–30. doi: 10.1145/3387940.3392200.

K. Odayan, “Artificial Intelligence controlling Cyber Security,” p. 190.

F. Cleary and M. Felici, Eds., Cyber Security and Privacy, vol. 530. Cham: Springer International Publishing, 2015. doi: 10.1007/978-3-319-25360-2.

S. Dua and X. Du, Data Mining and Machine Learning in Cybersecurity. 2016. Accessed: Nov. 16, 2021. [Online]. Available:

D. Cherry, “Securing SQL Server: Protecting Your Database from Attacker 3rd Edition,” in Securing SQL Server, Elsevier, 2015, p. iii. doi: 10.1016/B978-0-12-801275-8.00016-6.

N. Y. Xuan, J. Juremi, and N. H. M. Saad, “Securing e-commerce against SQL injection, cross site scripting and broken authentication,” vol. 5, no. 2, p. 5, 2021.

M. N. Kavitha, V. Vennila, G. Padmapriya, and A. R. Kannan, “Prevention Of Sql Injection Attack Using Unsupervised Machine Learning Approach,” vol. 12, no. 03, p. 12, 2021.

K. Ahmad and M. Karim, “A Method to Prevent SQL Injection Attack using an Improved Parameterized Stored Procedure,” Int. J. Adv. Comput. Sci. Appl., vol. 12, no. 6, 2021, doi: 10.14569/IJACSA.2021.0120636.

A. F. B. Dr, “INTERNATIONAL ADVISORY BOARD,” vol. 10, p. 95, 2022.

F. Deriba, “Development of a Compressive Framework Using Machine Learning Approaches for SQL Injection Attacks,” PRZEGLĄD ELEKTROTECHNICZNY, vol. 1, no. 7, pp. 183–189, Jul. 2022, doi: 10.15199/48.2022.07.30.

S. S. A. Krishnan, A. N. Sabu, P. P. Sajan, and A. L. Sreedeep, “SQL Injection Detection Using Machine Learning,” vol. 11, no. 3, p. 11, 2021.

A. Falor, M. Hirani, H. Vedant, P. Mehta, and D. Krishnan, “A Deep Learning Approach for Detection of SQL Injection Attacks Using Convolutional Neural Networks,” in Proceedings of Data Analytics and Management, vol. 91, D. Gupta, Z. Polkowski, A. Khanna, S. Bhattacharyya, and O. Castillo, Eds. Singapore: Springer Singapore, 2022, pp. 293–304. doi: 10.1007/978-981-16-6285-0_24.

P. Roy, R. Kumar, and P. Rani, “SQL Injection Attack Detection by Machine Learning Classifier,” in 2022 International Conference on Applied Artificial Intelligence and Computing (ICAAIC), May 2022, pp. 394–400. doi: 10.1109/ICAAIC53929.2022.9792964.

I. Hashem, M. Islam, S. M. Haque, Z. I. Jabed, and N. Sakib, “A Proposed Technique for Simultaneously Detecting DDoS and SQL Injection Attacks,” Int. J. Comput. Appl., vol. 183, no. 11, pp. 50–57, Jun. 2021, doi: 10.5120/ijca2021921428.

I. Jemal, O. Cheikhrouhou, H. Hamam, and A. Mahfoudhi, “SQL Injection Attack Detection and Prevention Techniques Using Machine Learning,” vol. 15, no. 6, p. 12, 2020.

M. Hasan, Z. Balbahaith, and M. Tarique, “Detection of SQL Injection Attacks: A Machine Learning Approach,” in 2019 International Conference on Electrical and Computing Technologies and Applications (ICECTA), Ras Al Khaimah, United Arab Emirates, Nov. 2019, pp. 1–6. doi: 10.1109/ICECTA48151.2019.8959617.

B. Kranthikumar and R. L. Velusamy, “SQL injection detection using REGEX classifier,” p. 10, 2020.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


International Journal Of Artificial Intelligence Research

Organized by: Departemen Teknik Informatika STMIK Dharma Wacana
Published by: STMIK Dharma Wacana
Jl. Kenanga No.03 Mulyojati 16C Metro Barat Kota Metro Lampung
phone. +62725-7850671
Fax. +62725-7850671
Email: |

View IJAIR Statcounter

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.