Poster: Long PHP webshell files detection based on sliding window attention

Zhiqiang Wang, Haoyu Wang, Lu HaoarXiv 2025 · DOI · arXiv

Abstract

Detecting malicious PHP webshells in long, obfuscated files remains a significant challenge for traditional security tools. This paper presents a high-precision detection method that leverages Opcode Double-Tuples (ODTs) and a sliding window attention mechanism. By combining deep semantic insights from CodeBert with opcode-specific features from FastText, the proposed model achieves a 99.2% detection accuracy, significantly outperforming existing industry standards.

Introduction

Webshells are malicious scripts uploaded to web servers to provide attackers with remote administrative control. Given that PHP powers over 75% of the web, it is the primary target for such attacks. Traditional detection methods, primarily based on pattern matching and static signatures, are increasingly ineffective against modern webshells that utilize encryption, dynamic loading, and complex obfuscation.

The Challenges of Modern Webshell Detection

Deep learning approaches have emerged as a promising alternative, but they face two critical hurdles:

  1. The "Long Text" Problem: Transformer-based models have limited context windows. Large scripts often exceed these limits, causing models to lose context or fail due to memory constraints.
  2. Information Loss: Many methods simplify code into Opcode Single-Tuples (OSTs), focusing only on instructions (e.g., ASSIGN) while ignoring the operands (the data). This omission hides the low-level nuances necessary for identifying sophisticated attacks.

Proposed Methodology

The researchers developed a multi-stage pipeline designed to address these limitations by preserving context and data-level information.

Figure 1: The overall detection pipeline, from PHP source code to final classification.

Opcode Double-Tuples (ODTs)

To prevent information loss, the system converts PHP code into ODTs. Unlike standard opcodes, ODTs pair each instruction with its associated operand. This approach includes a decoding step for Base64 or URL-encoded strings, effectively unmasking the original malicious intent hidden by obfuscation.

Figure 5: Example of Opcode Double-Tuples (ODTs) capturing both instructions and operands.

Feature Fusion and Sliding Window Attention

The model employs a hybrid embedding strategy using CodeBert to capture deep semantic and syntactic structures, and FastText to enhance the representation of specific opcode features.

To handle long files, a sliding window attention mechanism is implemented. The opcode sequence is divided into overlapping windows. Self-attention is calculated independently within each window, and the results are averaged. This ensures a continuous "flow" of information across the entire file, preventing the fragmentation of malicious signatures that might occur with simple sample slicing.

Evaluation and Results

The study utilized a new dataset of 5,001 webshell samples and 5,936 benign PHP files. In comparative testing, the proposed method significantly outperformed existing tools:

  • Proposed Method: 99.2% Accuracy / 99.1% F1 Score
  • MSDetector: 97.2% Accuracy
  • PHP Malware Finder (PMF): 83.4% Accuracy
  • ShellPub: 77.3% Accuracy

The results demonstrate that the transition from Single-Tuples (OSTs) to Double-Tuples (ODTs) provided a 4.6% boost in accuracy, highlighting the importance of operand data in threat detection.

Conclusion

By integrating ODTs with a sliding window attention mechanism, this research provides a robust solution for detecting long and obfuscated PHP webshells. Future work will focus on extending this mechanism to multi-language detection, covering backdoors in Python, ASP.NET, and Java, and optimizing the computational overhead for real-time environments.

Summary updated

BibTeX
@misc{wang2025poster,
  author = {Zhiqiang Wang and Haoyu Wang and Lu Hao},
  title = {{Poster: Long PHP webshell files detection based on sliding window attention}},
  year = {2025},
  eprint = {2502.19257},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.19257},
}
Figure