Skip to main content

Boteraser | Website and Server Security Solutions

🛡️ CVE-2023-37897 — grav

🟠 CVSS 8.0 — High ✅ No Known Exploit CWE-393 NVD
8.0
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

grav Server-side Template Injection (SSTI) mitigation bypass

Summary

The fix for SSTI using |map, |filter and |reduce twigs implemented in the commit [71bbed1](https://github.com/getgrav/grav/commit/71bbed12f950de8335006d7f91112263d8504f1b) introduces bypass of the denylist due to incorrect return value from isDangerousFunction(), which allows to execute the payload prepending double backslash (\\)

Details

The isDangerousFunction() check in version 1.7.42 and onwards retuns false value instead of true when the \ symbol is found in the $name.

```php

...

if (strpos($name, "\\") !== false) {

return false;

}

if (in_array($name, $commandExecutionFunctions)) {

return true;

}

...

```

Based on the code where the function is used, it is expected that any dangerous condition would return true

```php

/**

  • @param Environment $env
  • @param array $array
  • @param callable|string $arrow
  • @return array|CallbackFilterIterator
  • @throws RuntimeError

*/

function mapFunc(Environment $env, $array, $arrow)

{

if (!$arrow instanceof \Closure && !is_string($arrow) || Utils::isDangerousFunction($arrow)) {

throw new RuntimeError('Twig |map("' . $arrow . '") is not allowed.');

}

```

when |map('\system') is used in the malicious payload, the single backslash is dropped prior to reaching strpos($name, '\\') check, thus $name variable already has no backslash, and the command is blacklisted because it reaches the if (in_array($name, $commandExecutionFunctions)) { validation step.

However if |map('\\system') is used (i.e. double backslash), then the strpos($name, "\\") !== false takes effect, and isDangerousFunction() returns false , in which case the RuntimeError is not generated, and blacklist is bypassed leading to code execution.

Exploit Conditions

This vulnerability can be exploited if the attacker has access to:

1. an Administrator account, or

2. a non-administrator, user account that has Admin panel access and Create/Update page permissions

Steps to reproduce

1. Log in to Grav Admin using an administrator account.

2. Navigate to Accounts > Add, and ensure that the following permissions are assigned when creating a new low-privileged user:

  • Login to Admin - Allowed
  • Page Update - Allowed

3. Log out of Grav Admin

4. Login using the account created in step 2.

5. Choose Pages -> Home

6. Click the Advanced tab and select the checkbox beside Twig to ensure that Twig processing is enabled for the modified webpage.

7. Under the Content tab, insert the following payload within the editor:

``{{ ['id'] | map('\\system') | join() }}``

8. Click the Preview button. Observe that the output of the id shell command is returned in the preview.

Mitigation

```diff

diff --git a/system/src/Grav/Common/Utils.php b/system/src/Grav/Common/Utils.php

index 2f121bbe3..7b267cd0f 100644

--- a/system/src/Grav/Common/Utils.php

+++ b/system/src/Grav/Common/Utils.php

@@ -2069,7 +2069,7 @@ abstract class Utils

}

if (strpos($name, "\\") !== false) {

  • return false;

+ return true;

}

if (in_array($name, $commandExecutionFunctions)) {

```

How this vulnerability can be exploited

This issue can be reached over the network, attack complexity is low, an attacker needs administrative privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality high, integrity high, availability high.

CVSS metrics in full

The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H

  • Attack vector: Network — reachable from anywhere that can route to the service.
  • Attack complexity: Low — the attack works reliably, with no preparation.
  • Privileges required: High — administrative rights are needed first.
  • User interaction: None — nobody has to be tricked into anything.
  • Scope: Unchanged — the damage stays inside the vulnerable component.
  • Confidentiality impact: High — total loss, or loss the attacker controls.
  • Integrity impact: High — total loss, or loss the attacker controls.
  • Availability impact: High — total loss, or loss the attacker controls.

Weakness class

CVE-2023-37897 is classified as CWE-393: Return of Wrong Status Code. A function or operation returns an incorrect return value or status code that does not indicate the true result of execution, causing the product to modify its behavior based on the incorrect result.

Affected software

CVE-2023-37897 is recorded against 2 packages.

  • getgrav/grav (fixed in 1.7.42.2)
  • grav

Timeline and source

Published on 19 July 2023 and last revised on 16 February 2024. No public exploit is currently recorded for this entry. A vendor advisory or fix has been published. Record sourced from NVD.

References

github.com (Web)
nvd.nist.gov (Advisory)
github.com (Web)
github.com (Web)
github.com (Package)

Other advisories for this package

getgrav/grav has other advisories on record. If you are patching this one, these are worth checking on the same host:

Same weakness in other software

These advisories are the same class of weakness (CWE-393: Return of Wrong Status Code) in other software:

Details

Severity HIGH
CVSS Score 8.0
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:H/I:H/A:H
CWE CWE-393
Public Exploit ✅ No
Source NVD
Published 2023-07-19
Updated 2026-08-20
Modified 2024-02-16

Affected Packages

Software From version Fixed in
getgrav/grav 1.7.42.2
grav

Similar Threats

Site Security Check

Is grav part of your stack?

CVE-2023-37897 is rated CVSS 8.0 High. BotEraser scans your installation against known CVE records and tells you whether this vulnerability applies to the versions you actually run.

Scan My Site Free →

No credit card required  ·  Results in minutes

ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.

Browse related advisories

All advisoriesCVECVE 2023