PSDissect: A CFG-Guided, Semantics-Preserving Interactive Deobfuscation Framework for PowerShell Scripts
Abstract
PowerShell is a widely used scripting language for system administration and task automation. Owing to its flexible execution model and support for fileless execution, attackers frequently abuse it for malicious activities and employ diverse obfuscation strategies to evade security detection. A key challenge is that existing deobfuscation approaches do not preserve runtime context dependencies. Multiple invocations of the same function or script block may therefore map individually correct values to the same source position, causing conflicts. In addition, existing approaches lack fine-grained execution control and mechanisms for exposing intermediate execution states for analyst inspection and intervention. Effective deobfuscation that fully accommodates PowerShell's dynamic execution characteristics remains challenging. In this paper, we present PSDissect. To the best of our knowledge, PSDissect is the first PowerShell deobfuscation framework that preserves execution context throughout dynamic deobfuscation by maintaining code-generation and invocation relationships together with runtime states such as variable bindings and aliases. PSDissect achieves this context preservation through a CFG-guided design. It first constructs a control-flow graph (CFG) that explicitly represents control-flow structures, dynamically generated code, and invocation behaviors. It then executes CFG nodes independently under a shared execution context, allowing execution behavior to be controlled at the granularity of individual CFG nodes. For each CFG node, PSDissect identifies potentially obfuscated script pieces, records and stringifies their execution results, replaces the corresponding obfuscated script pieces, and finally reconstructs a behavior-equivalent deobfuscated script. The same CFG representation also supports interactive replay and debugging, allowing analysts to inspect intermediate execution states, supply missing runtime context, and control individual reconstruction decisions. We evaluate PSDissect through two complementary experiments, both against state-of-the-art baselines. On a controlled dataset covering representative PowerShell obfuscation strategies, PSDissect achieves the best overall performance, with a 100% effective deobfuscation rate and 98% recovery accuracy; with interactive debugging, the recovery accuracy further improves to 100%. On two real-world malicious PowerShell datasets containing 381 and 4,263 samples, respectively, PSDissect consistently outperforms state-of-the-art baselines within a two-minute analysis budget in effective deobfuscation, sensitive data recovery, semantic consistency, and residual obfuscation-burden reduction. Beyond deobfuscation, PSDissect enables interpretable malicious script behavior analysis through CFG-driven structural exposure.