<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>SpellBook</title>
    <link>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/</link>
    <description>Recent content on SpellBook</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <atom:link href="https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title></title>
      <link>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/cookie-manipulation/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/cookie-manipulation/</guid>
      <description>&lt;h2 id=&#34;cookie-manipulation&#34;&gt;Cookie Manipulation&lt;a class=&#34;anchor&#34; href=&#34;#cookie-manipulation&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;Cookie manipulation may not have impact on its own. However, it could be a crucial part of an exploit chain.&lt;/p&gt;&#xA;&lt;p&gt;Cookie manipulation allow attackers to manipulate data they don&amp;rsquo;t typically have control of. This makes &lt;code&gt;document.cookie&lt;/code&gt; a potential source for later exploit chain&lt;/p&gt;&#xA;&lt;h3 id=&#34;example&#34;&gt;Example&lt;a class=&#34;anchor&#34; href=&#34;#example&#34;&gt;#&lt;/a&gt;&lt;/h3&gt;&#xA;&lt;p&gt;Consider this code:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;current_location&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;location&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;pathname&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Extract existing history from cookie&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;match&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;/history=([^;]*)/&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;exec&lt;/span&gt;(document.&lt;span style=&#34;color:#a6e22e&#34;&gt;cookie&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;history&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;match&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;?&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;match&lt;/span&gt;[&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;].&lt;span style=&#34;color:#a6e22e&#34;&gt;split&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;:&lt;/span&gt; [];&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Prepend current location, keep max 5&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;history&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;unshift&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;current_location&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;const&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;trimmed&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;history&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;slice&lt;/span&gt;(&lt;span style=&#34;color:#ae81ff&#34;&gt;0&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Write back to cookie&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;document.&lt;span style=&#34;color:#a6e22e&#34;&gt;cookie&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;history=&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;trimmed&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;join&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;,&amp;#39;&lt;/span&gt;);&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#75715e&#34;&gt;// Render to DOM&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;document.&lt;span style=&#34;color:#a6e22e&#34;&gt;write&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;h3&amp;gt;History&amp;lt;/h3&amp;gt;&amp;lt;ul&amp;gt;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;trimmed&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;map&lt;/span&gt;(&lt;span style=&#34;color:#a6e22e&#34;&gt;p&lt;/span&gt; =&amp;gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;li&amp;gt;&amp;#39;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;p&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;/li&amp;gt;&amp;#39;&lt;/span&gt;).&lt;span style=&#34;color:#a6e22e&#34;&gt;join&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;#39;&lt;/span&gt;) &lt;span style=&#34;color:#f92672&#34;&gt;+&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;&amp;lt;/ul&amp;gt;&amp;#39;&lt;/span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code will keep recent visiting paths inside a cookie &lt;code&gt;history&lt;/code&gt;, then write it onto the page.&lt;/p&gt;</description>
    </item>
    <item>
      <title></title>
      <link>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/dom-clobbering/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/dom-clobbering/</guid>
      <description>&lt;h2 id=&#34;dom-clobbering&#34;&gt;DOM clobbering&lt;a class=&#34;anchor&#34; href=&#34;#dom-clobbering&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;DOM clobbering is a &lt;strong&gt;client-side&lt;/strong&gt; attack. It might result in XSS.&lt;/p&gt;&#xA;&lt;p&gt;The way this works is, you inject HTML that when parsed by browser, might result in overwriting global variables or objects in JavaScript context&lt;/p&gt;&#xA;&lt;p&gt;This attack &lt;strong&gt;requires&lt;/strong&gt; you to already have a way to inject HTML, but can&amp;rsquo;t execute JavaScript. DOM clobbering is how you might escalate to XSS&lt;/p&gt;&#xA;&lt;p&gt;Most of this page is what i understand from &lt;a href=&#34;https://hacktricks.wiki/en/pentesting-web/xss-cross-site-scripting/dom-clobbering.html&#34;&gt;HackTricks&lt;/a&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title></title>
      <link>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/open-redirect/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/open-redirect/</guid>
      <description>&lt;h2 id=&#34;open-redirect&#34;&gt;Open Redirect&lt;a class=&#34;anchor&#34; href=&#34;#open-redirect&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;DOM-based open-redirection vulnerabilities arise when a script writes attacker-controllable data into a sink that can trigger cross-domain navigation&lt;/p&gt;&#xA;&lt;h3 id=&#34;example-1&#34;&gt;Example 1&lt;a class=&#34;anchor&#34; href=&#34;#example-1&#34;&gt;#&lt;/a&gt;&lt;/h3&gt;&#xA;&lt;p&gt;Consider the following code:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;goto&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;location&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;hash&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;slice&lt;/span&gt;(&lt;span style=&#34;color:#ae81ff&#34;&gt;1&lt;/span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;if&lt;/span&gt; (&lt;span style=&#34;color:#66d9ef&#34;&gt;goto&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;startsWith&lt;/span&gt;(&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;https:&amp;#39;&lt;/span&gt;)) {&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;  &lt;span style=&#34;color:#a6e22e&#34;&gt;location&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;goto&lt;/span&gt;;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This code takes the string after the hash fragment &lt;code&gt;#&lt;/code&gt;, and if it starts with &lt;code&gt;https&lt;/code&gt;, it will pass the URL into &lt;code&gt;location&lt;/code&gt;, which will redirect the browser to that URL.&lt;/p&gt;&#xA;&lt;p&gt;So, this code uses a sink that attacker can control &lt;code&gt;location.hash&lt;/code&gt;, and a sink that do redirection &lt;code&gt;location&lt;/code&gt;. This vulnerability is &lt;strong&gt;open redirect&lt;/strong&gt;, and could be exploited for a phishing attack&lt;/p&gt;</description>
    </item>
    <item>
      <title></title>
      <link>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/web-messages-vulnerabilities/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/dom-based-attacks/web-messages-vulnerabilities/</guid>
      <description>&lt;h2 id=&#34;web-messages&#34;&gt;Web messages&lt;a class=&#34;anchor&#34; href=&#34;#web-messages&#34;&gt;#&lt;/a&gt;&lt;/h2&gt;&#xA;&lt;p&gt;&lt;strong&gt;Web Messages&lt;/strong&gt; (the &lt;code&gt;postMessage&lt;/code&gt; API) is a browser mechanism that allows communication between different browsing contexts, like between a page and an &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt;, or between a page and a Web Worker, or even across different origins.&lt;/p&gt;&#xA;&lt;p&gt;Normally, the &lt;a href=&#34;https://ag2s.ca/spellbook/2.-web-pentesting/2.2-common-attacks/xss---cross-site-scripting/same-origin-policy/&#34;&gt;Same-Origin Policy&lt;/a&gt; blocks scripts from different origins from accessing each other&amp;rsquo;s data. &lt;code&gt;postMessage&lt;/code&gt; provides a controlled, safe channel to pass data across that boundary.&lt;/p&gt;&#xA;&lt;p&gt;If a page handles incoming web messages in an unsafe way, for example, not verify the origin of incoming messages correctly, we can pass our controlled message to the functions or properties that consume the message&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
