# Detecting Web-Based Attacks with SHAP and Tree Ensemble Machine Learning Methods
## 3 Proposed Method
### Preprocessing
#### 3.1.2 Sample JS Attack Codes
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model** & **Recall** & **Precision** & **F1** \\ \hline SHAP & 0.9989 \(\pm\) 0.0004 & 0.9832 \(\pm\) 0.0024 & 0.9909 \(\pm\) 0.0014 \\ Boruta & 0.9983 \(\pm\) 0.0008 & 0.9698 \(\pm\) 0.0033 & 0.9839 \(\pm\) 0.0019 \\ ELI5 & 0.9982 \(\pm\) 0.0008 & 0.9699 \(\pm\) 0.0033 & 0.9839 \(\pm\) 0.0019 \\ RandomForest & 0.9984 \(\pm\) 0.0007 & 0.9698 \(\pm\) 0.0032 & 0.9839 \(\pm\) 0.0018 \\ SelectKBest & 0.9982 \(\pm\) 0.0007 & 0.9687 \(\pm\) 0.0034 & 0.9832 \(\pm\) 0.0019 \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Performance comparison of SHAP and other feature selection methods. they used manually engineered features unique to the type of attack they intended to identify. Such approaches have challenges in that they cannot be generalized to other attack types. Our premise is that features selected using SHAP values can overcome such challenges, as the analyst can easily identify which features significantly impact the overall model performance. Figure 6 shows SHAP interaction values with combinations of AST-JS features shown using _Feature_* - _Feature_ patterns. Using SHAP interaction values, it is easier to tell which AST-JS feature combinations or interactions contribute more toward the model's detection performance and in which direction. Some of these interactions are directly interpretable as attack types present in the dataset. Therefore, our proposed approach does not focus on specific categories of web-based attacks or threats. ## 6 Conclusions

Web-based attacks remain a significant challenge, as evasion techniques are continuously evolving. An equally adaptive strategy is required to detect such attacks effectively. This study proposes AST-JS feature selection using SHAP values and tree ensemble methods to detect these attacks. We also investigated how often AST-JS nodes appear together in benign and malicious JS codes using association rule mining. One expectation was that this approach would result in fully representative features that generalize well to other attacks. We used AST-JS nodes to represent the JS code structure and their SHAP values for feature selection. We experimented with features selected using AST-JS nodes, association rule mining, and SHAP values. We compared the performances of different machine learning classifiers in malicious JS code detection and achieved good detection performance with the tree ensemble methods. Additionally, we compared the performance of SHAP-selected features with the performances of those selected by other feature selection methods: Boruta, ELI5, RandomForest, and SelectKBest. The proposed web-based attack detection method outperformed the other feature selection methods in all three evaluation metrics. AST-JS nodes are resistant to perturbation in JS codes, and this ensures that the model is applicable in various JS code contexts, and therefore, to different JS-based attacks. We can extend this study to investigate malicious URL features in future work. Figure 6: SHAP interaction values. * represents AST-JS feature combinations. **Author Contributions:** Conceptualization, S.N., S.K. and S.O. ; methodology, S.N., S.K., S.O., T.B. and T.T. ; software, S.N. ; validation, S.K., S.O., T.B., T.T. and D.I. ; formal analysis, S.N. ; investigation, S.N. ; resources, S.O. and D.I. ; data curation, S.N. ; writing--original draft preparation, S.N. ; writing--review and editing, S.N., S.K., S.O., T.B., T.T. and D.I. ; visualization, S.N. ; supervision, S.K., S.O., T.B., T.T. and D.I. ; funding acquisition, D.I. All authors have read and agreed to the published version of the manuscript. **Funding:** This research was funded by the Ministry of Education, Science, Sports, and Culture, Japan, grant number (B) 16H02874, and the Commissioned Research of the National Institute of Information and Communications Technology (NICT), Japan, grant number 190. **Institutional Review Board Statement:** Not applicable. **Informed Consent Statement:** Not applicable. **Data Availability Statement:** Not applicable.