SAWD: Structural-Aware Webshell Detection System with Control Flow Graph

Junmin Zhu, Yizhao Yao, Xianwen Deng, Yaoguang Yong, Yanhao Wang, Libo Chen, Zhi Xue, Ruijie ZhaoSEKE 2023

Abstract

Webshells are malicious scripts that grant attackers remote control over web servers, often bypassing traditional defenses through sophisticated obfuscation and encryption. This paper introduces SAWD (Structural-Aware Webshell Detection), a system that identifies malicious PHP backdoors by converting source code into Control Flow Graphs (CFGs). By combining Graph Convolutional Networks (GCNs) with specialized graph pooling (MinCutPool), SAWD captures the structural logic of a script, making it significantly more resilient to the techniques that typically evade sequence-based or signature-based detectors.

Introduction

Webshells serve as the "skeleton keys" of cyberattacks, allowing remote administrative control. Detecting them is notoriously difficult because attackers frequently use obfuscation—scrambling code—and encryption to hide their intent.

Current detection methods generally suffer from three primary flaws:

  1. Traffic/Log-based: Often too slow or reactive, detecting attacks only after compromise.
  2. Traditional File-based: Rely on signatures or simple statistics (like high entropy), which fail against novel or disguised code.
  3. Deep Learning (Sequence-based): These treat code like natural language sentences. However, they often ignore operands and lose the complex logical structure—the "if-this-then-that" flow—that defines actual program behavior.

Methodology

SAWD shifts the paradigm by treating code not as a sequence, but as a graph. The system follows a multi-step pipeline to build and analyze these representations.

Overview of the SAWD system architecture, illustrating the transition from PHP source code to graph-based analysis and final classification.

Graph Construction and Feature Extraction

Using the PHP-CFG tool, SAWD parses PHP source code into an Abstract Syntax Tree (AST) and groups related operations into "basic blocks." These blocks are connected by edges representing execution flow (jumps, loops, and conditions), creating a Control Flow Graph (CFG).

Instead of raw opcodes, SAWD extracts features based on "key events" within each block. This includes high-risk function calls (e.g., eval), global variables (e.g., $_POST), and common literal types. Research indicated that simple keyword counting outperformed complex word embeddings like Word2Vec in this specific security context, as the presence of "power words" is a stronger signal than semantic context.

Structural-Aware Modeling

The core of SAWD’s analysis lies in two components:

  • Graph Convolutional Network (GCN): This allows the model to "pass messages" between connected blocks, learning how different parts of the script interact.
  • MinCutPool: This specialized pooling layer clusters similar functional blocks together. This is critical because webshells vary wildly in size—from massive "Big Trojans" to tiny "One-word Trojans." MinCutPool helps the model generalize across different coding styles and script lengths while preventing "over-smoothing," where nodes in a deep network become indistinguishable.

Evaluation and Results

To evaluate SAWD, the authors curated a dataset of 2,751 malicious webshells from GitHub and clean PHP code from popular projects like WordPress and ThinkPHP. SAWD was tested against several state-of-the-art (SOTA) methods, including traditional machine learning (SVM, Random Forest) and deep learning approaches like MSDetector.

Performance comparison of SAWD against traditional and deep learning-based detection methods, highlighting its superior accuracy and low miss rate.

As shown in the results, SAWD achieved a top-tier accuracy of 94.5% and an F1-score of 94.1%. Most notably, it achieved a miss rate of only 3.4%, significantly outperforming traditional statistical methods which typically hover between 8% and 14%. Ablation studies confirmed that both the GCN message-passing and the MinCutPool clustering are essential for maintaining this high level of performance against sophisticated threats.

Conclusion

SAWD demonstrates that focusing on the "skeleton" or logical flow of code is a more robust defense than analyzing surface-level sequences. While currently tailored to PHP and limited by the constraints of static analysis (which may struggle with code generated entirely at runtime), the structural-aware approach provides a powerful framework for the next generation of malware detection. Future work will explore expanding these graph-based techniques to other languages like Python and ASP.NET.

Summary updated

BibTeX
@inproceedings{zhu2023sawd,
  author = {Junmin Zhu and Yizhao Yao and Xianwen Deng and Yaoguang Yong and Yanhao Wang and Libo Chen and Zhi Xue and Ruijie Zhao},
  title = {{SAWD: Structural-Aware Webshell Detection System with Control Flow Graph}},
  booktitle = {SEKE},
  year = {2023},
  url = {https://openreview.net/forum?id=T9dm1KMdcn},
}
Figure