
Toolkit di rilevamento a livello di organizzazione AWS per CVE-2025-55182 e CVE-2025-66478 (vulnerabilità RCE di React Server Components / Next.js)
Kit di rilevamento a livello di organizzazione AWS per CVE-2025-55182 e CVE-2025-66478
⚠️ DISCLAIMER IMPORTANTE - LEGGERE PRIMA DELL'USO
Questo kit non è stato testato in un ambiente AWS di produzione.
A causa di vincoli infrastrutturali, questo progetto è stato sviluppato e validato solo tramite revisione del codice, analisi statica e verifica della documentazione. Non è stato distribuito o testato in un ambiente AWS live con servizi GuardDuty, WAF, EventBridge o CloudTrail attivi.
Cosa significa per te:
| Componente | Stato |
|---|
| Logica dello scanner Python | ✅ Codice revisionato, convalidato da Snyk |
| Sintassi Terraform | ✅ Convalidata, non applicata |
| | Criteri IAM | ⚠️ Potrebbero richiedere modifiche per il tuo ambiente |
| Regole EventBridge | ⚠️ Pattern di rilevamento basati sulla documentazione AWS | | Regole WAF | ⚠️ Pattern regex non testati su traffico reale | | Query Athena | ⚠️ Le ipotesi sugli schema potrebbero necessitare di modifiche |
Raccomandazioni:
- Distribuisci prima su un account non di produzione - Testa tutti i componenti in un ambiente sandbox
- Esamina attentamente i criteri IAM - Modifica le autorizzazioni per soddisfare i requisiti della tua organizzazione
- Valida i piani Terraform - Esegui
terraform plane verifica prima di applicare- Testa i pattern EventBridge - Verifica che le stringhe dei tipi di rilevamento corrispondano all'output di GuardDuty
- Monitora i log di CloudWatch - Controlla la presenza di errori dopo la distribuzione
Responsabilità:
Questo software è fornito "AS IS" senza alcuna garanzia. Gli autori non si assumono alcuna responsabilità per danni, incidenti di sicurezza o costi AWS derivanti dall'uso di questo kit. Usalo a tuo rischio e pericolo.
Se riesci a distribuire e testare con successo questo kit, considera di contribuire con i tuoi risultati per migliorarlo per la community.
Un kit di sicurezza completo per rilevare tentativi di sfruttamento di React2Shell in ambienti AWS. Questo kit fornisce rilevamento in tempo reale, capacità di threat hunting e risposta automatizzata per la vulnerabilità critica di RCE dei React Server Components.
__proto__:then consente l'esecuzione arbitraria di codice tramite process.mainModule.require('child_process').execSync()---
## Prerequisiti
### Permessi richiesti```
# Minimum IAM permissions for the detection script
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"cloudtrail:LookupEvents",
"logs:StartQuery",
"logs:GetQueryResults",
"guardduty:ListDetectors",
"guardduty:ListFindings",
"guardduty:GetFindings",
"guardduty:CreateThreatIntelSet",
"guardduty:UpdateThreatIntelSet",
"guardduty:ListThreatIntelSets",
"guardduty:GetThreatIntelSet",
"s3:PutObject",
"s3:GetObject",
"sts:GetCallerIdentity",
"sts:AssumeRole"
],
"Resource": "*"
}
]
}
# For Security Hub integration, add:
"securityhub:BatchImportFindings"
# For SNS alerting, add:
"sns:Publish"
# For organization-wide scanning, add:
"organizations:ListAccounts"
| Software | Versione | Scopo |
|---|---|---|
| Python | 3.9+ | Runtime dello script di rilevamento |
| Terraform | 1.0+ | Distribuzione dell'infrastruttura |
| AWS CLI | 2.x | Autenticazione AWS |
| boto3 | 1.34+ | SDK AWS per Python |
cd React2Shell_Hunter
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
### Passo 2: Configurare le credenziali AWS```bash
# Option A: Use AWS CLI profile
aws configure --profile security-scanner
# Option B: Export environment variables
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-east-1"
# Option C: Use IAM role (recommended for EC2/Lambda)
# Attach appropriate IAM role to your compute resource
aws sts get-caller-identity
python -c "import boto3, yaml; print('Dependencies OK')"
python -c " import yaml with open('config/iocs.yaml') as f: iocs = yaml.safe_load(f) print(f'Loaded {len(iocs["network_iocs"]["malicious_ips"])} malicious IPs') "
## Avvio rapido
### Scansiona account corrente (Ultime 24 ore)```bash
python src/react2shell_detector.py --hours 24
Output previsto:``` 2025-12-06 10:00:00 - React2ShellDetector - INFO - ============================================================ 2025-12-06 10:00:00 - React2ShellDetector - INFO - React2Shell IOC Detection Script 2025-12-06 10:00:00 - React2ShellDetector - INFO - CVE-2025-55182 & CVE-2025-66478 2025-12-06 10:00:00 - React2ShellDetector - INFO - ============================================================ 2025-12-06 10:00:00 - React2ShellDetector - INFO - Starting single account scan... 2025-12-06 10:00:00 - React2ShellDetector - INFO - Analyzing CloudTrail logs... 2025-12-06 10:00:05 - React2ShellDetector - INFO - Checking GuardDuty findings...
Total findings: 0 CRITICAL: 0 HIGH: 0 MEDIUM: 0
### Scansione completa di produzione```bash
python src/react2shell_detector.py \
--organization \
--role-name SecurityAuditRole \
--security-hub \
--guardduty-bucket my-threat-intel-bucket-12345 \
--vpc-log-group /aws/vpc/flowlogs \
--waf-log-group aws-waf-logs-react2shell \
--sns-topic arn:aws:sns:us-east-1:123456789012:security-alerts \
--output json \
--output-file findings-$(date +%Y%m%d).json \
--hours 72
NON PUOI CREARE REGOLE DI RILEVAMENTO PERSONALIZZATE IN GUARDDUTY.
GuardDuty utilizza modelli ML e intelligence sulle minacce per generare risultati. Per rilevare React2Shell:
MaliciousIPCaller.Custom### Pattern di regole EventBridge
Il Terraform crea 7 regole specifiche di EventBridge:
| Regola | Pattern del tipo di rilevamento | Gravità |
|------|---------------------|----------|
| `react2shell-malicious-ip-caller` | `MaliciousIPCaller.Custom` | CRITICAL |
| `react2shell-credential-exfiltration` | `InstanceCredentialExfiltration.*` | CRITICAL |
| `react2shell-dns-exfiltration` | `DNSDataExfiltration` | HIGH |
| `react2shell-cryptocurrency-mining` | `CryptoCurrency:*` | HIGH |
| `react2shell-unusual-network-ports` | `NetworkPortUnusual` | MEDIUM |
| `react2shell-malicious-domain` | `MaliciousDomainRequest.*` | HIGH |
| `react2shell-high-severity-catchall` | Severity >= 7 | VARIES |
### Livelli di protezione WAF
Il WebACL WAF implementa 9 regole in ordine di priorità:
| Priorità | Regola | Azione | Cosa rileva |
|----------|------|--------|-----------------|
| 1 | Blocca IP dannosi | BLOCK | Connessioni da 9 IP C2 noti |
| 2 | Valori dell'header Next-Action | BLOCK | header `next-action` contenente pattern `$ACTION` o `__proto__` |
| 3 | Valori dell'header RSC-Action-ID | BLOCK | header `rsc-action-id` contenente pattern `$ACTION` o `__proto__` |
| 4 | Inquinamento del prototipo | BLOCK | `__proto__` o `constructor.prototype` nel corpo |
| 5 | Pattern RCE | BLOCK | `process.mainModule.require`, `child_process`, `execSync` |
| 6 | Parametro ACTION | BLOCK | `$ACTION_0:0` o `$ACTION_REF` nel corpo POST |
| 7 | User-Agent sospetti | COUNT | `Go-http-client`, `Assetnote`, `python-requests` |
| 8 | Input dannosi noti AWS | INHERIT | Gruppo di regole gestito AWS |
| 9 | Set di regole comuni AWS | INHERIT | Gruppo di regole gestito AWS |
> **Nota**: Le regole 2 e 3 utilizzano `or_statement` con più controlli `byte_match_statement` per rilevare VALORI di header dannosi (non solo la presenza dell'header). AWS WAF non supporta le regex nel matching degli header, quindi ogni pattern richiede un'istruzione separata. I nomi degli header sono in minuscolo come richiesto da WAF.
---
## Riferimento ai componenti
### Struttura del progetto```
React2Shell_Hunter/
├── config/
│ └── iocs.yaml # IOC database (IPs, domains, patterns) - 452 lines
├── src/
│ └── react2shell_detector.py # Main detection script - 1141 lines
├── terraform/
│ ├── guardduty.tf # GuardDuty + ThreatIntelSet + S3 - 405 lines
│ ├── eventbridge_rules.tf # 7 EventBridge rules - 533 lines
│ └── waf_rules.tf # WAF WebACL with 9 rules - 681 lines
├── lambda/
│ └── ioc_scanner/
│ └── handler.py # Real-time Lambda scanner - 381 lines
├── athena_queries/
│ └── detection_queries.sql # 18 threat hunting queries - 483 lines
├── tests/
│ ├── __init__.py # Test package init
│ ├── conftest.py # Pytest fixtures (project_root, ioc_config, etc.)
│ ├── test_ioc_matching.py # IOC pattern validation tests
│ ├── test_terraform.py # Terraform configuration validation
│ └── test_waf_patterns.py # WAF regex pattern tests
├── docs/
│ ├── THREAT_INTELLIGENCE_REPORT.md
│ └── GUARDDUTY_EVENTBRIDGE_SETUP_GUIDE.md
├── requirements.txt # Python dependencies (boto3, pyyaml, pytest, python-hcl2)
├── README.md
└── CLAUDE.md
| Classe | Scopo | Metodi Principali |
|---|---|---|
IOCLoader | Carica IOCs da YAML | get_malicious_ips(), get_suspicious_ports(), get_malicious_domains() |
CloudTrailAnalyzer | Rileva IOCs basati su API | analyze_recent_events(hours) |
VPCFlowLogAnalyzer | Rileva IOCs di rete | analyze_flow_logs(log_group, hours) |
GuardDutyManager | Gestisci threat intelligence | create_threat_intel_set(bucket), get_relevant_findings(hours) |
WAFLogAnalyzer | Rileva IOCs HTTP | analyze_waf_logs(log_group, hours) |
OrganizationScanner | Scansione multi-account | scan_organization(hours, role_name) |
SecurityHubReporter | Importa risultati | import_findings(findings) |
SNSAlerter | Invia avvisi | send_alert(findings) |
| Argomento | Tipo | Predefinito | Descrizione |
|---|---|---|---|
--config | string | config/iocs.yaml | Percorso del file di configurazione IOC |
--hours | int | 24 | Ore di log da analizzare |
--organization | flag | false | Scansiona l'intera organizzazione AWS |
--role-name | string | OrganizationAccountAccessRole | Ruolo da assumere negli account membri |
--sns-topic | string | none | ARN del topic SNS per gli avvisi |
--security-hub | flag | false | Importa risultati in Security Hub |
--guardduty-bucket | string | none | Bucket S3 per threat intelligence di GuardDuty |
--vpc-log-group | string | none | Gruppo di log CloudWatch per VPC Flow Logs |
--waf-log-group | string | none | Gruppo di log CloudWatch per WAF logs |
--output | enum | text | Formato di output: json, text, csv |
--output-file | string | none | Percorso del file di output |
--debug | flag | false | Abilita logging di debug |
cd terraform
terraform init
terraform plan
-var="threat_intel_bucket=react2shell-threat-intel-$(aws sts get-caller-identity --query Account --output text)"
-var="enable_guardduty=true"
-var="enable_waf=true"
-var="waf_scope=REGIONAL"
terraform apply
-var="threat_intel_bucket=react2shell-threat-intel-$(aws sts get-caller-identity --query Account --output text)"
**Variabili Terraform:**
| Variabile | Obbligatorio | Predefinito | Descrizione |
|----------|----------|---------|-------------|
| `threat_intel_bucket` | SÌ | - | Nome del bucket S3 per i file di threat intelligence |
| `enable_guardduty` | no | true | Abilita il rilevatore GuardDuty |
| `enable_waf` | no | true | Crea WebACL WAF |
| `waf_scope` | no | REGIONAL | `REGIONAL` o `CLOUDFRONT` |
| `block_mode` | no | BLOCK | `BLOCK` o `COUNT` |
| `enable_lambda_automation` | no | false | Abilita Lambda per risposta automatica |
### Step 2: Associa WAF alle risorse
Il WAF WebACL deve essere associato alle tue risorse:```bash
# Associate with ALB
aws wafv2 associate-web-acl \
--web-acl-arn $(terraform output -raw web_acl_arn) \
--resource-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-alb/1234567890
# Associate with API Gateway
aws wafv2 associate-web-acl \
--web-acl-arn $(terraform output -raw web_acl_arn) \
--resource-arn arn:aws:apigateway:us-east-1::/restapis/abc123/stages/prod
SNS_TOPIC=$(terraform output -raw sns_topic_arn)
aws sns subscribe
--topic-arn $SNS_TOPIC
--protocol email
--notification-endpoint [email protected]
aws sns subscribe
--topic-arn $SNS_TOPIC
--protocol lambda
--notification-endpoint arn:aws:lambda:us-east-1:123456789012:function:slack-notifier
### Passo 4: Crea tabelle Athena```bash
# Open Athena console or use AWS CLI
# Run the CREATE TABLE statements from athena_queries/detection_queries.sql
# CloudTrail table
aws athena start-query-execution \
--query-string "CREATE EXTERNAL TABLE cloudtrail_logs ..." \
--work-group primary \
--query-execution-context Database=default
| Indirizzo IP | Porta | Confidenza | Contesto | Fonte |
|---|---|---|---|---|
| 93.123.109.247 | 8000 | HIGH | Server C2 primario | Datadog |
| 45.77.33.136 | 8080 | HIGH | Server C2 primario | Datadog |
| 194.246.84.13 | 2045 | HIGH | Server C2 primario | Datadog |
| 141.11.240.103 | 45178 | HIGH | Server C2 primario | Datadog |
| 23.235.188.3 | 652 | HIGH | Stager PowerShell | GreyNoise |
| 46.36.37.85 | 12000 | HIGH | Staging payload | GreyNoise |
| 144.202.115.234 | 80 | MEDIUM | Hosting payload | Datadog |
| 162.215.170.26 | 3000 | MEDIUM | Payload secondario | GreyNoise |
| 45.32.158.54 | - | MEDIUM | Scanner | GreyNoise |
| Dominio | Categoria | Confidenza |
|---|---|---|
| ceye.io | Esfiltrazione DNS | HIGH |
| dnslog.cn | Esfiltrazione DNS | HIGH |
| *.oastify.com | Collaborator Burp | MEDIUM |
| sapo.shk0x.net | C2 | HIGH |
| xwpoogfunv.zaza.eu.org | C2 | HIGH |
| *.c3pool.com | Cryptomining | HIGH |
| Porta | Utilizzo |
|---|---|
| 652 | Stager PowerShell |
| 2045 | C2 personalizzato |
| 8000, 8080 | C2 HTTP alternativo |
| 12000, 45178 | C2 personalizzato |
| 3333, 5555, 14433, 14444 | Cryptomining |
| Pattern | Severità | Descrizione |
|---|---|---|
next-action: * | CRITICAL | Intestazione di sfruttamento RSC (minuscolo in WAF) |
rsc-action-id: * | CRITICAL | Identificativo azione RSC (minuscolo in WAF) |
$ACTION_0:0 | CRITICAL | Parametro azione RSC |
__proto__:then | CRITICAL | Inquinamento del prototipo |
process.mainModule.require | CRITICAL | RCE Node.js |
child_process | CRITICAL | Esecuzione di comandi |
Go-http-client/1.1 | MEDIUM | User agent scanner |
aws guardduty list-detectors
aws guardduty create-detector --enable
terraform apply -var="enable_guardduty=true"
#### "Impossibile assumere il ruolo nell'account membro"```bash
# Verify role exists in target account
aws iam get-role --role-name SecurityAuditRole
# Verify trust policy allows your account
aws iam get-role --role-name SecurityAuditRole --query 'Role.AssumeRolePolicyDocument'
# Test role assumption
aws sts assume-role \
--role-arn arn:aws:iam::TARGET_ACCOUNT:role/SecurityAuditRole \
--role-session-name test
DETECTOR_ID=$(aws guardduty list-detectors --query 'DetectorIds[0]' --output text) aws guardduty list-threat-intel-sets --detector-id $DETECTOR_ID
aws s3api get-bucket-policy --bucket your-threat-intel-bucket
aws s3 cp s3://your-bucket/threat-intel/react2shell-ips.txt -
#### "Regola WAF non bloccante"```bash
# Check if WebACL is associated
aws wafv2 list-resources-for-web-acl \
--web-acl-arn $(terraform output -raw web_acl_arn)
# Check sampled requests
aws wafv2 get-sampled-requests \
--web-acl-arn $(terraform output -raw web_acl_arn) \
--rule-metric-name React2Shell-Malicious-IP-Blocked \
--scope REGIONAL \
--time-window StartTime=2025-12-06T00:00:00Z,EndTime=2025-12-06T23:59:59Z \
--max-items 10
DETECTOR_ID=$(aws guardduty list-detectors --query 'DetectorIds[0]' --output text)
aws guardduty create-sample-findings
--detector-id $DETECTOR_ID
--finding-types "UnauthorizedAccess:IAMUser/MaliciousIPCaller.Custom"
aws cloudwatch get-metric-statistics
--namespace AWS/Events
--metric-name Invocations
--dimensions Name=RuleName,Value=react2shell-malicious-ip-caller
--start-time $(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)
--end-time $(date -u +%Y-%m-%dT%H:%M:%SZ)
--period 300
--statistics Sum
---
## FAQ
### D: Questo sostituisce il patching?
**NO.** Questo è un toolkit di rilevamento, non una soluzione di prevenzione. Devi ASSOLUTAMENTE applicare le patch:
- React: 19.0.1, 19.1.2 o 19.2.1
- Next.js: 15.0.5, 15.1.9, 15.2.6, 15.3.6, 15.4.8, 15.5.7 o 16.0.7
### D: Questo rileverà tutti gli attacchi React2Shell?
**Nessun rilevamento è al 100%.** Questo toolkit rileva:
- Connessioni a indirizzi IP C2 noti (se l'attaccante usa nuovi IP, non verrà rilevato)
- Pattern di payload noti (se l'attaccante offusca, potrebbe eludere il WAF)
- Comportamento post-exploitation (furto di credenziali, movimento laterale)
### D: Con quale frequenza dovrei eseguire lo scanner?
Programma consigliato:
- **Continuo**: GuardDuty + EventBridge (in tempo reale)
- **Ogni ora**: Script Python con `--hours 1`
- **Ogni giorno**: Query complete di threat hunting su Athena
### D: Come posso aggiungere nuovi IOC?
Modifica `config/iocs.yaml` e aggiungi alle sezioni appropriate:```yaml
network_iocs:
malicious_ips:
- ip: "NEW.IP.ADDRESS.HERE"
port: 8080
context: "Description"
confidence: high
source: "Your source"
Quindi aggiorna ThreatIntelSet:```bash python src/react2shell_detector.py --guardduty-bucket your-bucket
---
## Esecuzione dei Test```bash
# Install test dependencies
pip install -r requirements.txt
# Run all tests
pytest tests/ -v
# Run specific test categories
pytest tests/test_terraform.py -v # Terraform validation
pytest tests/test_ioc_matching.py -v # IOC pattern tests
pytest tests/test_waf_patterns.py -v # WAF regex tests
# Run with coverage
pytest tests/ --cov=src --cov-report=html
Disclaimer: Questo toolkit è destinato esclusivamente a scopi di sicurezza difensiva. Assicurati di avere la corretta autorizzazione prima di eseguire scansioni sui sistemi.