Re script deob

From dslsdzc/rev-skills · View interactive version

Re script deob is an AI agent skill from the GitHub repository dslsdzc/rev-skills. 脚本/宏去混淆:PowerShell、VBA、JavaScript。触发词:PowerShell混淆、VBA宏、JS去混淆、脚本解密、恶意脚本

How to use this skill

Skill file

脚本/宏去混淆(PowerShell / VBA / JavaScript)

何时使用 / 何时不用

工具准备

参考 [[re-analyze/platform-tips]]——本技能静态解码为主,免沙箱;执行链跟踪中需要运行时(跑脚本/开宏)的步骤按最高原则进沙箱。

python3(解码主力)

oletools(VBA 宏提取/解码,可选但强烈建议)

xxd / sed(十六进制与文本处理)

PowerShell(Windows 内置)/ pwsh(Linux/macOS)

js-beautify(JS 美化,可选)

操作步骤

按顺序执行;每层还原结果存档编号(layer_01.ps1 → layer_02.ps1 …),执行链跟踪中"运行脚本拿下一层"的步骤一律在沙箱内。

  1. 识别脚本类型与混淆风格:

```sh

file sample.ps1 && head -c 512 sample.ps1

grep -oiE 'IEX|Invoke-Expression|-EncodedCommand|FromBase64String|eval\(|unescape|fromCharCode|Chr\(|StrReverse|Document_Open|AutoOpen' sample.ps1

```

  1. 逐层还原(先解码,再跟执行链):
  1. PowerShell(-enc 解码、IEX 链):

```sh

pwsh -NoProfile -Command '$d=[Convert]::FromBase64String("BASE64"); [Text.Encoding]::Unicode.GetString($d)'

```

```powershell

$ast = [System.Management.Automation.Language.Parser]::ParseFile('layer_01.ps1', [ref]$null, [ref]$null)

$ast.FindAll({ $args[0] -is [System.Management.Automation.Language.StringConstantExpressionAst] }, $true) | % { $_.Value }

```

  1. VBA(olevba 提取宏 + 还原):

```sh

olevba -c sample.docm > macro.txt # 提取宏源码

olevba --decode -c sample.docm > macro_decoded.txt # 自动解常见字符串混淆(--decode 自 oletools 0.24/2015 起就有,无版本门槛)

```

  1. JS(去混淆/解编码):

具体去混淆链配方

承接步骤 1 的混淆风格分类,按配方执行(方法为核心,工具可替换):

eval / 执行函数替换:把 eval / IEX / Invoke-Expression / bash 替换为输出语句(JS 中 eval = console.log;PowerShell 中把 IEX(...) 换成打印),运行后打印底层代码;解一层、看一层、再解下一层,每层存档(layer_01.ps1 → layer_02.ps1 …)。

JS 常见编码函数(看到即解码目标):unescape()(URL 解码 %XX)、String.fromCharCode()(字符码数组)、atob()(Base64);十六进制 \xHH / Unicode \uHHHH 批量转义解码(python3 -c "import sys; print(sys.argv[1].encode().decode('unicode_escape').decode(errors='replace'))" '<串>');document.write 换成打印。

PowerShell -enc / IEX 链:-EncodedCommand 后的 base64 解码注意 UTF-16LE:

[System.Text.Encoding]::Unicode.GetString([System.Convert]::FromBase64String($encoded))

垃圾代码检测(识别特征五条):

真实逻辑形如 junk, junk, junk, CALL target, junk, junk——提取所有真实调用目标、忽略周围噪音(可用脚本按 call 指令 + 垃圾目标过滤实现)。

Hex 编码载荷:hex 转字节后先试常见变换:逐字节减 1、XOR 单字节密钥(0x01 起递增试)。

常见解码链模式:base64 decode → gzip decode → reverse → base64 decode;每层输出用 file 判断类型并验证可读性;验证失败说明层序或编码判断错,回退一层重试。

高级混淆对抗(商业混淆器)

JScrambler 类商业混淆器的手法与对抗:

跨域联合

常见坑与陷阱

(来源:reverse-skill field-journal,MIT)

(来源:hermes-decomp(SymbioticSec),MIT)

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.