SSQLi: A Black-Box Adversarial Attack Method for SQL Injection Based on Reinforcement Learning
Abstract
:1. Introduction
- State-vector-representation algorithm: We investigated the features of SQL query statements and proposed an approach for converting SQL query statements into vectors that could capture the essential characteristics of the original statement and provide more comprehensive feature extraction.
- Attack strategy matrix: We examined the vulnerabilities of existing detectors and proposed an attack strategy matrix containing a total of 14 attack strategies based on their vulnerabilities. The 14 attack strategies were developed based on the reports from the open-source security intelligence team and information provided in the official MySQL manual. These strategies include three major categories: syntax transformation strategy, syntax analysis interference strategy, and semantic analysis interference strategy. The goal of these attack strategies was to conceal the attack characteristics of the SQL injection payload, and all the attack strategies in the matrix could be used in tandem, regardless of overlap, without changing the attack target of the original payload.
- SQL injection adversarial attack method: We proposed an adversarial attack method based on the soft actor–critic (SAC) algorithm, in which the agent adapted the attack strategy to generate adversarial examples based on the feedback from the detection model.
- We constructed eight machine- and deep-learning-based SQL injection detection models, according to mainstream detection frameworks. We tested our attack methods on these detection models and two open-source WAFs. SSQLi resulted in a significant reduction in the detection rate for all these detectors, with three of them showing a detection rate reduction of approximately 90%.
2. Related Work
3. Proposed Method
3.1. State-Vector-Representation Algorithm
3.1.1. Static State Vector
3.1.2. Dynamic State Vector
3.2. Strategy Matrix
3.2.1. Syntactic Transformation Strategy
- Delay function replacement: The benchmark function in MySQL was used to test the performance of SQL statements and cause a delay when executing complex functions multiple times, so that the benchmark function could replace the sleep function, which is commonly used in SQL injection attacks.
- Error function replacement: When strings and numbers were executed as parameters of the bin_to_uuid function, the error message of MySQL database printed the value of incoming parameters, so the bin_to_uuid function could replace common error-reporting functions, such as the “updateXML” in the SQL-injection-attack samples.
- Comment confusion: To reduce the rate of false alarms, some WAFs ignore the content of the annotations; therefore, this method could hide the attack characteristics in these WAFs.
- String-to-hex: Some detectors trigger alerts for SQL query statements accessing sensitive directories, in which case, converting strings to hexadecimals could evade the detection of sensitive directories.
- Equation conversion: To reduce the rate of false alarms, most WAFs only trigger alerts if the product has only keywords and equations presented together, so this approach could hide the attack signature.
- Table-name confusion: WAFs often use sensitive words, such as table names, to detect SQL injection attacks; therefore, this method could hide this attack feature.
- Replace spaces with comments: Some detectors are sensitive to space characters, so replacing them could reduce the likelihood of being detected.
- Redundant keyword omission: There are some keywords, including “as” in MySQL, that can be ignored when used but are easily detected as attacks, so we needed to eliminate these redundant keywords to avoid attacks.
- Keyword replacement: We could use special characters as substitutes for sensitive keywords: For example, we could replace “and” with “&&”.
- Special table-name substitution: In addition to table name interference, some built-in MySQL tables have functional equivalences, such as some tables in the system library that could replace information in the information_schema library and could hide the attack characteristics of common tables.
- ODBC-syntax interference: ODBC syntax is used to solve data-sharing problems between heterogeneous databases. This syntax places curly brackets around the execution of the shared content and then adds a string identifier that MySQL ignores when parsing and executing the shared content directly.
3.2.2. Syntactic Analysis Interference Strategy
- Scientific notation interference: When MySQL parsed a function, if the function’s arguments had used scientific notation, MySQL ignored the scientific notation characters and placed the arguments directly into the function for execution. For example, when MySQL executed , it was equivalent to executing . Since this feature does not exist in the libinjection library, this interference would result in a difference in the parsing outcomes and introduce vulnerability.
- Embedded execution of interference strategy: MySQL exists in a large number of distributions. To satisfy the requirements for backwards compatibility, MySQL can execute version-specific syntax based on the version content marked in the comments. For example, when executing , MySQL executed after adjusting the execution environment for MySQL5. However, the libinjection library would simply treat those characters as a comment and ignore them.
3.2.3. Semantic-Analysis-Interference Strategy
3.3. SAC Agent
Algorithm 1:SSQLi based on SAC. |
|
4. Experiment
4.1. Experimental Setup
- SAC: Our strategy selector contained hidden layer and used a softmax function as the activation function of the output layer. The critic model contained a hidden layer and used a softmax function as the activation function of the output layer. Furthermore, the size of experience buffer was 100,000. The optimal maximum step-size and the number of training iterations would be selected in the parameter setting experiment.
- DDQN: This model contained a hidden layer, a maximum iteration step-size set at 100, epochs set at 10, and a batch-size set at 256.
- WAF-A-Mole: WAF-A-Mole was the most recent adversarial attack model for SQL injection in the existing research to date. The model built a mutation strategy tree and would return to a previous node to choose another strategy when the current mutation method could not successfully bypass the detection model. To be consistent with the model setup in this paper, the maximum iterations of WAF-A-Mole was set at 100.
- SafeDog [31]: SafeDog is a mature WAF system based on rule-matching. The version used in this experiment was updated on 10 February 2022, and the detection rules and levels of this system were set to the default mode.
- ModSecurity [32]: ModSecurity is an open-source WAF system developed by the ModSecurity team. The system uses both a rule-matching method and a syntax-analysis method to prevent SQL injection. In this experiment, all parameters of the system were set to default.
4.2. Performance Comparison
4.2.1. Parameter Setting Experiment
4.2.2. Experiment of Attack Effect
4.3. Discussion
5. Conclusions
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- OWASP. OWASP Top Ten. Available online: https://owasp.org/ (accessed on 4 June 2022).
- Clay Keller. Vulnerability Dstribution of CVE Security Vulnerabilities by Types. Available online: https://www.cvedetails.com/vulnerabilities-by-types.php (accessed on 20 March 2021).
- Kasim, Ö. An ensemble classification-based approach to detect attack level of SQL injections. J. Inf. Secur. Appl. 2021, 59, 102852. [Google Scholar] [CrossRef]
- Kar, D.; Panigrahi, S.; Sundararajan, S. SQLiGoT: Detecting SQL injection attacks using graph of tokens and SVM. Comput. Secur. 2016, 60, 206–225. [Google Scholar] [CrossRef]
- Li, Q.; Wang, F.; Wang, J.; Li, W. LSTM-based SQL injection detection method for intelligent transportation system. IEEE Trans. Veh. Technol. 2019, 68, 4182–4191. [Google Scholar] [CrossRef]
- Qiu, S.; Liu, Q.; Zhou, S.; Wu, C. Review of artificial intelligence adversarial attack and defense technologies. Appl. Sci. 2019, 9, 909. [Google Scholar] [CrossRef] [Green Version]
- Zhang, X.; Zhou, Y.; Pei, S.; Zhuge, J.; Chen, J. Adversarial examples detection for XSS attacks based on generative adversarial networks. IEEE Access 2020, 8, 10989–10996. [Google Scholar] [CrossRef]
- Fang, Y.; Huang, C.; Xu, Y.; Li, Y. RLXSS: Optimizing XSS detection model to defend against adversarial attacks based on reinforcement learning. Future Int. 2019, 11, 177. [Google Scholar] [CrossRef] [Green Version]
- Wang, Q.; Yang, H.; Wu, G.; Choo, K.K.R.; Zhang, Z.; Miao, G.; Ren, Y. Black-box adversarial attacks on XSS attack detection model. Comput. Secur. 2022, 113, 102554. [Google Scholar] [CrossRef]
- Chen, L.; Tang, C.; He, J.; Zhao, H.; Lan, X.; Li, T. XSS Adversarial Example Attacks Based on Deep Reinforcement Learning. Comput. Secur. 2022, 120, 102831. [Google Scholar] [CrossRef]
- Liu, M.; Li, K.; Chen, T. DeepSQLi: Deep semantic learning for testing SQL injection. In Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis, Virtual Event, 18–22 July 2020; pp. 286–297. [Google Scholar]
- Demetrio, L.; Valenza, A.; Costa, G.; Lagorio, G. Waf-a-mole: Evading web application firewalls through adversarial machine learning. In Proceedings of the 35th Annual ACM Symposium on Applied Computing, Brno, Czech Republic, 30 March–3 April 2020; pp. 1745–1752. [Google Scholar]
- Hemmati, M.; Hadavi, M.A. Bypassing Web Application Firewalls Using Deep Reinforcement Learning. ISeCure 2022, 14, 131–145. [Google Scholar]
- Wang, X.; Han, H. Evading Web Application Firewalls with Reinforcement Learning. Available online: https://openreview.net/forum?id=m5AntlhJ7Z5 (accessed on 4 June 2022).
- Amouei, M.; Rezvani, M.; Fateh, M. RAT: Reinforcement-Learning-Driven and Adaptive Testing for Vulnerability Discovery in Web Application Firewalls. IEEE Trans. Dependable Secur. Comput. 2021, 19, 3371–3386. [Google Scholar] [CrossRef]
- Hemmati, M.; Hadavi, M.A. Using Deep Reinforcement Learning to Evade Web Application Firewalls. In Proceedings of the 2021 18th International ISC Conference on Information Security and Cryptology (ISCISC), Isfahan, Iran, 1–2 September 2021; pp. 35–41. [Google Scholar]
- Guo, C.; Gardner, J.; You, Y.; Wilson, A.G.; Weinberger, K. Simple black-box adversarial attacks. In Proceedings of the International Conference on Machine Learning, Long Beach, CA, USA, 18–23 January 2019; pp. 2484–2493. [Google Scholar]
- Goswami, G.; Ratha, N.; Agarwal, A.; Singh, R.; Vatsa, M. Unravelling robustness of deep learning based face recognition against adversarial attacks. In Proceedings of the AAAI Conference on Artificial Intelligence, New Orleans, LA, USA, 2–7 February 2018; Volume 32. [Google Scholar]
- Morris, J.X.; Lifland, E.; Yoo, J.Y.; Qi, Y. Textattack: A framework for adversarial attacks in natural language processing. arXiv 2020, arXiv:2005.05909. [Google Scholar]
- Zhang, X.; Chen, J.; Zhang, R.; Wang, C.; Liu, L. Attacking Recommender Systems With Plausible Profile. IEEE Trans. Inf. Forensics Secur. 2021, 16, 4788–4800. [Google Scholar] [CrossRef]
- Zhou, Y.; Wang, P. An ensemble learning approach for XSS attack detection with domain knowledge and threat intelligence. Comput. Secur. 2019, 82, 261–269. [Google Scholar] [CrossRef]
- Kumar, P.; Pateriya, R. A survey on SQL injection attacks, detection and prevention techniques. In Proceedings of the 2012 Third International Conference on Computing, Communication and Networking Technologies (ICCCNT’12), Coimbatore, India, 26–28 July 2012; pp. 1–5. [Google Scholar] [CrossRef]
- OWASP. The SQL injection Knowledge Base. Available online: https://www.websec.ca/kb/sql_injection (accessed on 22 March 2022).
- ORACLE. MySQL 8.0 Reference Manual. Available online: https://dev.mysql.com/doc/refman/8.0/en/ (accessed on 23 March 2022).
- Haarnoja, T. Acquiring Diverse Robot Skills via Maximum Entropy Deep Reinforcement Learning; University of California: Berkeley, CA, USA, 2018. [Google Scholar]
- Ziebart, B.D.; Maas, A.L.; Bagnell, J.A.; Dey, A.K. Maximum entropy inverse reinforcement learning. In Proceedings of the Aaai, Chicago, IL, USA, 13–17 July 2008; pp. 1433–1438. [Google Scholar]
- Haarnoja, T.; Zhou, A.; Abbeel, P.; Levine, S. Soft actor-critic: Off-policy maximum entropy deep reinforcement learning with a stochastic actor. In Proceedings of the International Conference on Machine Learning, Stockholm, Sweden, 10–15 July 2018; pp. 1861–1870. [Google Scholar]
- Christodoulou, P. Soft actor-critic for discrete action settings. arXiv 2019, arXiv:1910.07207. [Google Scholar]
- Luo, A.; Huang, W.; Fan, W. A CNN-based Approach to the Detection of SQL Injection Attacks. In Proceedings of the 2019 IEEE/ACIS 18th International Conference on Computer and Information Science (ICIS), Beijing, China, 17–19 June 2019; pp. 320–324. [Google Scholar]
- Hasselt, H.V.; Guez, A.; Silver, D. Deep Reinforcement Learning with Double Q-learning. In Proceedings of the Thirtieth AAAI Conference on Artificial Intelligence, Phoenix, AZ, USA, 12–17 February 2016. [Google Scholar]
- Safedog. Safedog WEB Firewall Application. Available online: http://free.safedog.cn/ (accessed on 2 December 2021).
- Martinhsv. SpiderLabs ModSecurity repository in github. Available online: https://github.com/SpiderLabs/ModSecurity (accessed on 29 January 2021).
- Fang, Y.; Peng, J.; Liu, L.; Huang, C. WOVSQLI: Detection of SQL Injection Behaviors Using Word Vector and LSTM. In Proceedings of the the 2nd International Conference, Guiyang, China, 16–19 March 2018. [Google Scholar]
- Mcwhirter, P.R.; Kifayat, K.; Qi, S.; Askwith, B. SQL Injection Attack classification through the feature extraction of SQL query strings using a Gap-Weighted String Subsequence Kernel. J. Inf. Secur. Appl. 2018, 40, 199–216. [Google Scholar] [CrossRef] [Green Version]
Index | Type | Description | Example |
---|---|---|---|
1 | Tautologies | If payload is a complete SQL statement. | ?id=1 or 1=1 |
2 | Union-based | If union query in payload. | ?id=1 union select 1, updatexml(0x7e, user(), 0x7e), 3, 4, 5 |
3 | Error-based | If common error functions in payload. | ?id=updatexml(0x7e, user(), 0x7e) |
4 | Boolean-based | If conditions statement in payload. | ?id=1 and 1=1 |
5 | Stack-based | If payload is multi-query statement. | ?id=1; select 1, version(), 3, 4, 5 |
6 | Time-based | If time delay functions in SQL statement. | ?id=if(1=1, sleep(5), 1) |
7 | Contain functions | If payload contains mysql function. | ?id=1 and ’root’ = user() |
8 | Contain keywords | If payload contains keywords. | ?id=1 and 1=1 |
9 | Contain subqueries | If payload contains subqueries. | ?id=1 and 1=(select 1) |
Index | Rule Name | Example |
---|---|---|
1 | Delay function replacement | sleep(5) → benchmark(500000, MD5(1)) |
2 | Error function replacement | Updatexml(0x7e, user(), 0x7e) → bin_to_uuid(user()) |
3 | Comment confusion | 1 and 1=1 → 1a/*a’ and 1=’a*/a’ |
4 | String-to-hex | Select ’abc’ → select 0x616263 |
5 | Equation conversion | 1 and 1=1 → 1 and 1 between 1 and 1 |
6 | Table-name confusion | Select user from mysql.user → select user from mysql/**/./**/user |
7 | Replace spaces with comments | Select 1,2,3 → select/**/1,2,3 |
8 | Redundant keywords omission | Select table_name as t1 → select table_name t1 |
9 | Keyword replacement | 1 and 1=1 → 1 && 1=1 |
10 | Special table-name substitution | select table_name from information_schema.tables → select table_name from sys.sechema_table_statistics_with_buffer |
11 | ODBC syntax interference | sleep(5) → {anyword sleep(5)} |
Number | Parameter Values | Frequency of Occurrence |
---|---|---|
1 | name | 3046 |
2 | duration | 2967 |
3 | subscribe | 2648 |
4 | startTime | 2116 |
5 | resource | 2104 |
Detection Model | Feature Extraction | Batch Size | Epoch |
---|---|---|---|
MLP | Word2Vec | 128 | 50 |
CNN | Word2Vec | 128 | 50 |
LSTM | Word2Vec | 128 | 50 |
SVM | 3-grams and TF-IDF | - | - |
AdaBoost | 3-grams and TF-IDF | - | - |
RandomForest | 3-grams and TF-IDF | - | - |
XGBoost | 3-grams and TF-IDF | - | - |
GradientBoost | 3-grams and TF-IDF | - | - |
50 | 75 | 100 | 125 | 150 | |
---|---|---|---|---|---|
ER | 50.69% | 56.96% | 62.94% | 62.54% | 63.87% |
Training time | 2540 s | 4038 s | 5714 s | 7161 s | 8766 s |
30 | 40 | 50 | 60 | 70 | |
---|---|---|---|---|---|
ER | 59.61% | 60.50% | 62.94% | 63.60% | 62.68% |
Training time | 3627 s | 4818 s | 5714 s | 6489 s | 7808 s |
Original Payload | Adversarial Example | |
---|---|---|
ER | ER | |
SafeDog | 15.27% | 94.96% |
Modesecurity | 0.10% | 62.94% |
Detection Model | Accuracy | Precision | Recall | F1 Score |
---|---|---|---|---|
LSTM | 99.97% | 99.99% | 99.96% | 99.97% |
CNN | 99.96% | 99.33% | 99.96% | 99.64% |
MLP | 99.93% | 99.91% | 99.96% | 99.93% |
SVM | 99.94% | 100% | 99.88% | 99.94% |
AdaBoost | 99.95% | 99.96% | 99.94% | 99.95% |
RandomForest | 99.97% | 100% | 99.93% | 99.97% |
XGBoost | 99.96% | 99.98% | 99.93% | 99.96% |
GradientBoost | 99.95% | 99.97% | 99.93% | 99.96% |
Original Performance | SSQLi-SAC | SSQLi-DDQN | WAF-A-MoLE | |
---|---|---|---|---|
ER | ER | ER | ER | |
SafeDog | 15.27% | 94.96% | 93.28% | 35.38% |
ModSecurity | 0.10% | 62.94% | 0.83% | 5.08% |
LSTM | 0.04% | 97.39% | 27.44% | 1.85% |
CNN | 0.04% | 56.53% | 4.07% | 1.96% |
MLP | 0.04% | 46.40% | 0.04% | 1.96% |
SVM | 0.12% | 96.37% | 84.20% | 2.64% |
AdaBoost | 0.06% | 44.03% | 0.37% | 2.33% |
RandomForest | 0.07% | 31.98% | 0.17% | 0.96% |
XGBoost | 0.07% | 34.36% | 2.59% | 2.09% |
GradientBoost | 0.07% | 37.20% | 0.07% | 2.66% |
SafeDog | ModSecurity | LSTM | CNN | MLP | SVM | AdaBoost | RandomForest | XGBoost | GradientBoost | |
---|---|---|---|---|---|---|---|---|---|---|
Training Time | 2149.74 s | 3536.26 s | 29,970.53 s | 34,843.29 s | 12,522.81 s | 2834.67 s | 47,894.34 s | 43,474.43 s | 43,463.45 s | 39,957.42 s |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2023 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Guan, Y.; He, J.; Li, T.; Zhao, H.; Ma, B. SSQLi: A Black-Box Adversarial Attack Method for SQL Injection Based on Reinforcement Learning. Future Internet 2023, 15, 133. https://doi.org/10.3390/fi15040133
Guan Y, He J, Li T, Zhao H, Ma B. SSQLi: A Black-Box Adversarial Attack Method for SQL Injection Based on Reinforcement Learning. Future Internet. 2023; 15(4):133. https://doi.org/10.3390/fi15040133
Chicago/Turabian StyleGuan, Yuting, Junjiang He, Tao Li, Hui Zhao, and Baoqiang Ma. 2023. "SSQLi: A Black-Box Adversarial Attack Method for SQL Injection Based on Reinforcement Learning" Future Internet 15, no. 4: 133. https://doi.org/10.3390/fi15040133
APA StyleGuan, Y., He, J., Li, T., Zhao, H., & Ma, B. (2023). SSQLi: A Black-Box Adversarial Attack Method for SQL Injection Based on Reinforcement Learning. Future Internet, 15(4), 133. https://doi.org/10.3390/fi15040133