Deobfuscates malicious JavaScript found in phishing pages, web skimmers, and dropper scripts by reversing encoding layers, eval chains, string manipulation, and control-flow obfuscation to reveal the original malicious logic. Use when investigating a phishing page's obfuscated JavaScript, analyzing a Magecart-style web skimmer, or deobfuscating a JavaScript dropper that fetches second-stage malware.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Deobfuscates malicious JavaScript found in phishing pages, web skimmers, and dropper scripts by reversing encoding layers, eval chains, string manipulation, and control-flow obfuscation to reveal the original malicious logic. Use when investigating a phishing page's obfuscated JavaScript, analyzing a Magecart-style web skimmer, or deobfuscating a JavaScript dropper that fetches second-stage malware.
de4js or JStillery for automated JavaScript deobfuscation
Isolated analysis VM with no access to production systems or sensitive data
Workflow
Step 1: Safely Extract and Examine the Obfuscated Script
Isolate the malicious JavaScript without executing it:
# Extract JavaScript from HTML file
python3 << 'PYEOF'
from html.parser import HTMLParser
class ScriptExtractor(HTMLParser):
def __init__(self):
super().__init__()
self.in_script = False
self.scripts = []
self.current = ""
def handle_starttag(self, tag, attrs):
if tag == "script":
self.in_script = True
self.current = ""
def handle_endtag(self, tag):
if tag == "script":
self.in_script = False
if self.current.strip():
self.scripts.append(self.current)
def handle_data(self, data):
if self.in_script:
self.current += data
with open("malicious_page.html") as f:
parser = ScriptExtractor()
parser.feed(f.read())
for i, script in enumerate(parser.scripts):
with open(f, ) as f:
f.write(script)
(f)
PYEOF
npx js-beautify script_0.js -o script_0_pretty.js
Deobfuscated Malware Categories and IOC Extraction:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Credential Harvester:
- Form action URLs (exfiltration endpoints)
- XMLHttpRequest/fetch destinations
- Targeted input field names (username, password, cc_number)
Web Skimmer (Magecart):
- Payment form overlay injection
- Card data exfiltration URLs
- Keylogger event listeners (onkeypress, oninput)
Redirect Script:
- Destination URLs in location.href assignments
- Conditional redirects based on user-agent or referrer
- Cloaking logic (show benign content to bots)
Exploit Kit Landing:
- Browser/plugin version checks
- Exploit payload URLs
- Shellcode embedded as arrays or encoded strings
Key Concepts
Term
Definition
Eval Chain
Nested layers of eval(), Function(), or document.write() calls that each decode one layer of obfuscation before passing to the next
String Array Rotation
Obfuscation technique storing all strings in a shuffled array and accessing them by computed index to hide string literals
Dead Code Insertion
Adding non-functional code blocks that never execute to increase analysis complexity and confuse pattern matching
Opaque Predicate
Conditional expression whose outcome is predetermined but difficult to determine statically; used to obscure control flow
Anti-Debugging
JavaScript techniques to detect and thwart browser DevTools or debugger usage including debugger statements and timing checks
Web Skimmer
Malicious JavaScript injected into e-commerce sites to steal payment card data from checkout forms (Magecart attack)
Tools & Systems
CyberChef: GCHQ's web-based tool for encoding/decoding transformations useful for unwinding multi-layer obfuscation
de4js: Online JavaScript deobfuscator supporting common obfuscation tools (obfuscator.io, JScrambler)
Node.js VM Module: Sandboxed JavaScript execution environment for safely evaluating obfuscated code with intercepted APIs
Chrome DevTools: Browser developer tools for stepping through JavaScript execution with breakpoints and console access
JSDetox: JavaScript malware analysis tool providing execution emulation and deobfuscation
Common Scenarios
Scenario: Deobfuscating a Magecart Web Skimmer
Context: A compromised e-commerce site has obfuscated JavaScript injected into its checkout page. The script needs deobfuscation to identify the data exfiltration endpoint and determine what customer data was stolen.
Approach:
Extract the injected script from the page source (often appended to a legitimate JS file or loaded from an external domain)
Beautify the code and identify the obfuscation technique (typically string array + rotation + hex encoding)
Decode string encoding layers (hex -> Unicode -> base64) using the Python decoder script
Resolve the string array by evaluating the array definition and rotation function
Identify the form targeting logic (querySelector for payment form fields)
Extract the exfiltration URL from the XMLHttpRequest or fetch call
Document stolen data fields and exfiltration endpoint for incident response
Pitfalls:
Executing obfuscated scripts on a connected system (the script may phone home during analysis)
Not removing anti-debugging traps before using browser DevTools (infinite debugger loops)
Missing additional obfuscation layers loaded dynamically from external URLs
Overlooking base64-encoded inline images or data URIs that may contain additional scripts