<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Pentagrid AG (Posts about Encryption)</title><link>https://www.pentagrid.ch/</link><description></description><atom:link href="https://www.pentagrid.ch/en/categories/encryption.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2026 Pentagrid AG </copyright><lastBuildDate>Wed, 17 Jun 2026 19:14:51 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Nothing new, still broken, insecure by default since then: Python's e-mail libraries and certificate verification</title><link>https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/</link><dc:creator>Pentagrid AG</dc:creator><description>&lt;figure&gt;&lt;img src="https://www.pentagrid.ch/images/default_preview_image.jpeg"&gt;&lt;/figure&gt; &lt;p&gt;Today, basically every e-mail provider supports TLS for their services and programmatically accessing e-mail services with Python code using TLS-wrapped clients is common. Python offers three libraries shipped with a standard installation for handling e-mail transfer. These modules are smtplib, imaplib, and poplib. While Python programming is usually straightforward, using these Python libraries require passing a magic parameter in the right way to use secure communication. If one has just read the summary on Stackoverflow, read a tutorial that does not mention security settings, or asked ChatGPT not specifically enough, it results in programs that do not defeat active attackers in a machine-in-the-middle (MITM) position. Our journey started, when &lt;a class="reference external" href="https://github.com/pentagridsec/icinga_check_mail_loop"&gt;we wrote an e-mail monitoring plugin&lt;/a&gt; in Python and ended for the time being with the notification of various open source projects.&lt;/p&gt;
&lt;!-- TEASER_END --&gt;
&lt;section id="insecure-past"&gt;
&lt;h2&gt;Insecure past&lt;/h2&gt;
&lt;p&gt;There was a time, when fetching e-mail via clear-text channels was the standard and there was no real alternative to that. SMTP is 40 years old. The encryption program PGP is 31 years old and can be understood as tool that originated from the desire for reasonably useful end-to-end privacy, at a time where the underlying foundation was based on clear-text. In the mid-nineties, the first crypto-protocols for regular users were developed, such as SSH for shell access and SSL mainly for web browsing. For e-mail, STARTTLS was an improvement to upgrade from an insecure communication to a crypto-channel that preserves integrity and confidentiality as long as an active attacker did not prevent STARTTLS. The pre-Snowden era is not that long ago, where websites usually relied on cleartext-HTTP. These old times influenced how things are nowadays. Nevertheless, times are changing, techniques too, and expectations anyway.&lt;/p&gt;
&lt;p&gt;The same reasoning applies to libraries with protocol implementations. It is not different with Python. So, everything here is an old hat. It is a "known" problem. It is more or less documented in the corresponding Python documentation. There is a Python Enhancement Proposal, a PEP, which is the Python community's way of coming to decisions. It is &lt;a class="reference external" href="https://peps.python.org/pep-0476/"&gt;PEP 476 – Enabling certificate verification by default for stdlib HTTP clients&lt;/a&gt; from 2014, because HTTP libraries had the same issue. They were insecure by default. PEP 476 suggests doing certificate checking for accessing resources via HTTPS and it also mentions that there are other Python libraries with the same issue. These other libraries are smtplib, imaplib, and poplib for mail handling and additional libraries for FTP and NNTP. The PEP explains that the mail libraries may still need insecure defaults for backward compatibility, for example because mail servers may have invalid certificates and therefore with e-mail this certificate verification could be a different thing compared to the PEP's aim at changing certificate verification for HTTP. And there is &lt;a class="reference external" href="https://github.com/python/cpython/issues/91826"&gt;the very same discussion already on Python's Github tracker&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Making things worse, while imaplib and poplib are mainly used in client to server communication (where you might have a chance to ask the user to do a security decision), SMTP is used for server to server communication as well. While security features are introduced to improve mail security (e.g. MTA-STS), the situation is still challenging. That's why we think projects should configure e-mail as secure as possible, where possible.&lt;/p&gt;
&lt;p&gt;Meanwhile it is 2023 and insecure defaults are a problem, especially when our infrastructure depends on many small building blocks. An insecurity here, a shared password there, an outdated component over there. Each vulnerability could be one too much to grant attackers the next level of access. So let us explain the problem.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="a-vulnerable-example"&gt;
&lt;h2&gt;A vulnerable example&lt;/h2&gt;
&lt;p&gt;Consider this example of Python script that is intended to connect to an IMAP server:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-1" name="rest_code_ce86a1de59834094ac50cd636e4da681-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-1"&gt;&lt;/a&gt;&lt;span class="ch"&gt;#!/usr/bin/env python3&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-2" name="rest_code_ce86a1de59834094ac50cd636e4da681-2" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-2"&gt;&lt;/a&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-3" name="rest_code_ce86a1de59834094ac50cd636e4da681-3" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-3"&gt;&lt;/a&gt;&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;imaplib&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-4" name="rest_code_ce86a1de59834094ac50cd636e4da681-4" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-4"&gt;&lt;/a&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-5" name="rest_code_ce86a1de59834094ac50cd636e4da681-5" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-5"&gt;&lt;/a&gt;&lt;span class="n"&gt;imap_host&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'outlook.office365.com'&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-6" name="rest_code_ce86a1de59834094ac50cd636e4da681-6" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-6"&gt;&lt;/a&gt;&lt;span class="n"&gt;imap_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'nonexisting@outlook.com'&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-7" name="rest_code_ce86a1de59834094ac50cd636e4da681-7" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-7"&gt;&lt;/a&gt;&lt;span class="n"&gt;imap_pass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'secret'&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-8" name="rest_code_ce86a1de59834094ac50cd636e4da681-8" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-8"&gt;&lt;/a&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-9" name="rest_code_ce86a1de59834094ac50cd636e4da681-9" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-9"&gt;&lt;/a&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"IMAP: Try to connect."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-10" name="rest_code_ce86a1de59834094ac50cd636e4da681-10" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-10"&gt;&lt;/a&gt;&lt;span class="n"&gt;server&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;imaplib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IMAP4_SSL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;imap_host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;993&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-11" name="rest_code_ce86a1de59834094ac50cd636e4da681-11" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-11"&gt;&lt;/a&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-12" name="rest_code_ce86a1de59834094ac50cd636e4da681-12" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-12"&gt;&lt;/a&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"IMAP: Try IMAP login, which is expected to fail with the data above."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_ce86a1de59834094ac50cd636e4da681-13" name="rest_code_ce86a1de59834094ac50cd636e4da681-13" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_ce86a1de59834094ac50cd636e4da681-13"&gt;&lt;/a&gt;&lt;span class="n"&gt;server&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;login&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;imap_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;imap_pass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;At first, the script looks like it should work, which it does. But if this script is used, it will not verify the peer's certificate, which can be tested by just adding an entry to &lt;code class="docutils literal"&gt;/etc/hosts&lt;/code&gt;, for example by associating an IP address from &lt;code class="docutils literal"&gt;imap.gmail.com&lt;/code&gt; with the hostname of  &lt;code class="docutils literal"&gt;outlook.office365.com&lt;/code&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_1809201f6f9d4c838072dc4b50752875-1" name="rest_code_1809201f6f9d4c838072dc4b50752875-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_1809201f6f9d4c838072dc4b50752875-1"&gt;&lt;/a&gt;173.194.76.109  outlook.office365.com
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If the script now connects to Microsoft's IMAP server, it will instead connect to the one from Google. The certificate will not match the hostname, but running the script now results in an authentication error and not in an &lt;code class="docutils literal"&gt;ssl.SSLCertVerificationError&lt;/code&gt;. As there was no certificate verification error, username and password were sent to the wrong server and the script did not prevent this.&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code text"&gt;&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-1" name="rest_code_5f1152e6d0da47e286b4295850426f8b-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-1"&gt;&lt;/a&gt;$ ./imaptest.py
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-2" name="rest_code_5f1152e6d0da47e286b4295850426f8b-2" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-2"&gt;&lt;/a&gt;IMAP: Try to connect.
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-3" name="rest_code_5f1152e6d0da47e286b4295850426f8b-3" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-3"&gt;&lt;/a&gt;IMAP: Try IMAP login, which is expected to fail with the data above.
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-4" name="rest_code_5f1152e6d0da47e286b4295850426f8b-4" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-4"&gt;&lt;/a&gt;Traceback (most recent call last):
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-5" name="rest_code_5f1152e6d0da47e286b4295850426f8b-5" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-5"&gt;&lt;/a&gt;  File "/tmp/./imaptest.py", line 13, in &amp;lt;module&amp;gt;
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-6" name="rest_code_5f1152e6d0da47e286b4295850426f8b-6" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-6"&gt;&lt;/a&gt;    server.login(imap_user, imap_pass)
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-7" name="rest_code_5f1152e6d0da47e286b4295850426f8b-7" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-7"&gt;&lt;/a&gt;  File "/usr/lib/python3.10/imaplib.py", line 612, in login
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-8" name="rest_code_5f1152e6d0da47e286b4295850426f8b-8" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-8"&gt;&lt;/a&gt;    raise self.error(dat[-1])
&lt;a id="rest_code_5f1152e6d0da47e286b4295850426f8b-9" name="rest_code_5f1152e6d0da47e286b4295850426f8b-9" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_5f1152e6d0da47e286b4295850426f8b-9"&gt;&lt;/a&gt;imaplib.IMAP4.error: b'[AUTHENTICATIONFAILED] Authentication failed.'
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Outch!&lt;/p&gt;
&lt;/section&gt;
&lt;section id="read-the-manual-first"&gt;
&lt;h2&gt;Read the manual first&lt;/h2&gt;
&lt;p&gt;This was just an example with accessing an IMAP server. Technically, it is the same with Python's smtplib and also poplib. This is more or less &lt;a class="reference external" href="https://docs.python.org/3/library/imaplib.html"&gt;documented behaviour&lt;/a&gt;. The &lt;code class="docutils literal"&gt;imaplib.IMAP4_SSL&lt;/code&gt; has an optional parameter &lt;code class="docutils literal"&gt;ssl_context&lt;/code&gt;, which is described as:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;ssl_context is a ssl.SSLContext object which allows bundling SSL configuration options, certificates and private keys into a single (potentially long-lived) structure. Please read Security considerations for best practices.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The &lt;code class="docutils literal"&gt;ssl_context&lt;/code&gt; parameter was added in Python 3.3 released in 2012. Following the &lt;a class="reference external" href="https://docs.python.org/3/library/ssl.html#ssl-security"&gt;link to the security best practices&lt;/a&gt;, the Python documentation further explains:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;For client use, if you don’t have any special requirements for your security policy, it is highly recommended that you use the create_default_context() function to create your SSL context. It will load the system’s trusted CA certificates, enable certificate validation and hostname checking, and try to choose reasonably secure protocol and cipher settings.&lt;/em&gt;
[...]&lt;/p&gt;
&lt;p&gt;&lt;em&gt;By contrast, if you create the SSL context by calling the SSLContext constructor yourself, it will not have certificate validation nor hostname checking enabled by default. If you do so, please read the paragraphs below to achieve a good security level.&lt;/em&gt;
[...]&lt;/p&gt;
&lt;p&gt;&lt;em&gt;When calling the SSLContext constructor directly, CERT_NONE is the default. Since it does not authenticate the other peer, it can be insecure, especially in client mode where most of time you would like to ensure the authenticity of the server you’re talking to. Therefore, when in client mode, it is highly recommended to use CERT_REQUIRED. However, it is in itself not sufficient; you also have to check that the server certificate, which can be obtained by calling SSLSocket.getpeercert(), matches the desired service. For many protocols and applications, the service can be identified by the hostname; in this case, the match_hostname() function can be used. This common check is automatically performed when SSLContext.check_hostname is enabled.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Would you say that after reading this, everything is completely clear? Creating a default context to load CA certificates sounds good, but is the impact clear, when one skips this step and just does not pass the right SSL context, when calling the &lt;code class="docutils literal"&gt;IMAP4_SSL&lt;/code&gt; constructor? Does the code call the &lt;code class="docutils literal"&gt;SSLContext&lt;/code&gt; contructor somehow, when you completely ignore the &lt;code class="docutils literal"&gt;IMAP4_SSL&lt;/code&gt; constructor's &lt;code class="docutils literal"&gt;ssl_context&lt;/code&gt; parameter? The Python documentation links the corresponding source code. So one can check, what happens &lt;a class="reference external" href="https://github.com/python/cpython/blob/3.11/Lib/imaplib.py"&gt;starting from the constructor imaplib.IMAP4_SSL&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-1" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-1"&gt;&lt;/a&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;IMAP4_SSL_PORT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-2" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-2" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-2"&gt;&lt;/a&gt;             &lt;span class="n"&gt;certfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ssl_context&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-3" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-3" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-3"&gt;&lt;/a&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-4" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-4" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-4"&gt;&lt;/a&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-5" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-5" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-5"&gt;&lt;/a&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;ssl_context&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-6" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-6" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-6"&gt;&lt;/a&gt;        &lt;span class="n"&gt;ssl_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_create_stdlib_context&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;certfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;certfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-7" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-7" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-7"&gt;&lt;/a&gt;                                                 &lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-8" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-8" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-8"&gt;&lt;/a&gt;    &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ssl_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ssl_context&lt;/span&gt;
&lt;a id="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-9" name="rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-9" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_c7339aace9fe4c74a43d96e3f5a5eda8-9"&gt;&lt;/a&gt;    &lt;span class="n"&gt;IMAP4&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="fm"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;There, the &lt;code class="docutils literal"&gt;ssl_context&lt;/code&gt; parameter is initialized with &lt;code class="docutils literal"&gt;None&lt;/code&gt;. If no specific value is passed via &lt;code class="docutils literal"&gt;ssl_context&lt;/code&gt;, then &lt;code class="docutils literal"&gt;_create_stdlib_context&lt;/code&gt; is called. The function &lt;code class="docutils literal"&gt;ssl._create_stdlib_context&lt;/code&gt; &lt;a class="reference external" href="https://github.com/python/cpython/blob/3.11/Lib/ssl.py"&gt;is defined as&lt;/a&gt;:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_93ee3966cc3e49c69e34817272999a4c-1" name="rest_code_93ee3966cc3e49c69e34817272999a4c-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_93ee3966cc3e49c69e34817272999a4c-1"&gt;&lt;/a&gt;&lt;span class="n"&gt;_create_stdlib_context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_create_unverified_context&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Unverified context does not sound good. The corresponding code is shown below.  The function &lt;code class="docutils literal"&gt;_create_unverified_context&lt;/code&gt; disables &lt;code class="docutils literal"&gt;check_hostname&lt;/code&gt; and does not load a default trust chain, if not instructed to do this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-1" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-1"&gt;&lt;/a&gt;&lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;_create_unverified_context&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cert_reqs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;CERT_NONE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-2" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-2" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-2"&gt;&lt;/a&gt;                           &lt;span class="n"&gt;check_hostname&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;purpose&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;Purpose&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SERVER_AUTH&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-3" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-3" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-3"&gt;&lt;/a&gt;                           &lt;span class="n"&gt;certfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-4" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-4" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-4"&gt;&lt;/a&gt;                           &lt;span class="n"&gt;cafile&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cadata&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-5" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-5" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-5"&gt;&lt;/a&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-6" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-6" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-6"&gt;&lt;/a&gt;    &lt;span class="n"&gt;context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;SSLContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-7" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-7" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-7"&gt;&lt;/a&gt;    &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;check_hostname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;check_hostname&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-8" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-8" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-8"&gt;&lt;/a&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cert_reqs&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="kc"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-9" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-9" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-9"&gt;&lt;/a&gt;        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verify_mode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cert_reqs&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-10" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-10" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-10"&gt;&lt;/a&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;check_hostname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-11" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-11" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-11"&gt;&lt;/a&gt;        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;check_hostname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-12" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-12" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-12"&gt;&lt;/a&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-13" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-13" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-13"&gt;&lt;/a&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;certfile&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-14" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-14" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-14"&gt;&lt;/a&gt;        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load_cert_chain&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;certfile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;keyfile&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-15" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-15" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-15"&gt;&lt;/a&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-16" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-16" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-16"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# load CA root certs&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-17" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-17" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-17"&gt;&lt;/a&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;cafile&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;capath&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;cadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-18" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-18" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-18"&gt;&lt;/a&gt;        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load_verify_locations&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cafile&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;capath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cadata&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-19" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-19" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-19"&gt;&lt;/a&gt;    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;verify_mode&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;CERT_NONE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-20" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-20" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-20"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# no explicit cafile, capath or cadata but the verify mode is&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-21" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-21" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-21"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# CERT_OPTIONAL or CERT_REQUIRED. Let's try to load default system&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-22" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-22" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-22"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# root CA certificates for the given purpose. This may fail silently.&lt;/span&gt;
&lt;a id="rest_code_af6d706f474c4de7bf1c4e1df45f9663-23" name="rest_code_af6d706f474c4de7bf1c4e1df45f9663-23" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_af6d706f474c4de7bf1c4e1df45f9663-23"&gt;&lt;/a&gt;        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;load_default_certs&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;purpose&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Not checking certificates explains why the vulnerable example client in the beginning just continued connecting and sent credentials to another mail server or to the entity that pretends to be one.&lt;/p&gt;
&lt;p&gt;How could that be avoided? Just create an SSL context and pass it to the constructor as an additional parameter (examples for each library):&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_77092f9e161f4323a6a7b7625555ddc0-1" name="rest_code_77092f9e161f4323a6a7b7625555ddc0-1" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_77092f9e161f4323a6a7b7625555ddc0-1"&gt;&lt;/a&gt;&lt;span class="n"&gt;imaplib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;IMAP4_SSL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ssl_context&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_default_context&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;a id="rest_code_77092f9e161f4323a6a7b7625555ddc0-2" name="rest_code_77092f9e161f4323a6a7b7625555ddc0-2" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_77092f9e161f4323a6a7b7625555ddc0-2"&gt;&lt;/a&gt;&lt;span class="n"&gt;smtplib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SMTP_SSL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_default_context&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;a id="rest_code_77092f9e161f4323a6a7b7625555ddc0-3" name="rest_code_77092f9e161f4323a6a7b7625555ddc0-3" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#rest_code_77092f9e161f4323a6a7b7625555ddc0-3"&gt;&lt;/a&gt;&lt;span class="n"&gt;poplib&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;POP3_SSL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;ssl&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create_default_context&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;By the way, did you noticed the different parameter names for the SSL context?&lt;/p&gt;
&lt;/section&gt;
&lt;section id="implications"&gt;
&lt;h2&gt;Implications&lt;/h2&gt;
&lt;p&gt;The direct consequence is that a vulnerable Python program that uses the libraries in a vulnerable way may leak credentials for an IMAP or SMTP account (or POP3) to an active attacker in a MITM position. A script may only use SMTP, but often SMTP and IMAP credentials are identical and therefore may result in IMAP being accessed, too. Furthermore, if an e-mail is sent via SMTP, mail contents may leak or could be modified during transit. Due to the flexibility of IMAP, not only mail contents may be retrieved, but also modified or deleted before another, legitimate user can access it. Since a library is affected here, the exact impact depends on the use case of the software that uses the library and it will depend on the type of data being processed via e-mail. Another impact is that with access to e-mail infrastructure, the reachable attack surface increases for the attacker. Access to e-mail infrastructure may be abused for phishing attacks and spamming, for example.&lt;/p&gt;
&lt;p&gt;If there is the need to create an &lt;code class="docutils literal"&gt;SSLContext&lt;/code&gt; to enable certificate verification, will everyone have read the documentation? Sadly, there are even tutorials not mentioning the SSL context and ChatGPT won’t tell the full story until one asks... erm... demonstrates prompt engineering skills.&lt;/p&gt;
&lt;p&gt;We can use code search engines such as &lt;a class="reference external" href="https://grep.app/"&gt;grep.app&lt;/a&gt;, &lt;a class="reference external" href="https://searchcode.com/"&gt;search code&lt;/a&gt;, and &lt;a class="reference external" href="https://codesearch.debian.net/"&gt;Debian Code Search&lt;/a&gt;, looking for constructor calls to &lt;code class="docutils literal"&gt;imaplib.IMAP4_SSL&lt;/code&gt; and &lt;code class="docutils literal"&gt;smtplib.SMTP_SSL&lt;/code&gt; and skim through the source code. Skipping testing code, inactive and some personal code repositories, it is possible to find quite some vulnerable uses. A curated list is given at the end of this article.&lt;/p&gt;
&lt;p&gt;We found vulnerabilities in code that is covered by bug bounty programs. For example, we found a vulnerability in an &lt;a class="reference external" href="https://github.com/google/gmail-oauth2-tools/blob/876a8bd965752e1f6f2a97a7005da6a23c18d5b5/python/oauth2.py"&gt;OAuth2 Python script by Google&lt;/a&gt;, where a connection to an SMTP/IMAP server is made to test if authentication tokens are valid. We &lt;a class="reference external" href="https://bughunters.google.com/reports/vrp/Fed1oa3Ar/report"&gt;reported this&lt;/a&gt; to the Google and Alphabet Vulnerability Reward Program (VRP). They rewarded us with a small bounty. &lt;a class="brackets" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#footnote-1" id="footnote-reference-1" role="doc-noteref"&gt;&lt;span class="fn-bracket"&gt;[&lt;/span&gt;1&lt;span class="fn-bracket"&gt;]&lt;/span&gt;&lt;/a&gt; We also filed vulnerability reports at Hackerone for Spotify and Mozilla, but they &lt;a class="brackets" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#footnote-2" id="footnote-reference-2" role="doc-noteref"&gt;&lt;span class="fn-bracket"&gt;[&lt;/span&gt;2&lt;span class="fn-bracket"&gt;]&lt;/span&gt;&lt;/a&gt; don't see a problem with not checking server certificates and closed the tickets. The vulnerability in Spotify's Luigi project &lt;a class="reference external" href="https://github.com/python/cpython/issues/91826#issuecomment-1106693852"&gt;has been found before&lt;/a&gt;, but was likely not reported back then. We were able to report the vulnerability in Mozilla's Bugbot via another channel and it was fixed.&lt;/p&gt;
&lt;p&gt;We tried to contact most of the projects, where it was somehow possible to find (security) contact data. Some of them were very happy to receive the report and immediately provided a fix.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="necessary-conclusion-to-draw"&gt;
&lt;h2&gt;Necessary conclusion to draw&lt;/h2&gt;
&lt;p&gt;It is understandable to prefer not to break existing functionality. We all know ecosystems in software engineering, where things break every now and then. But keeping insecure defaults is not a value that makes sense to get preserved. It is a vulnerability. If a security issue is only documented in the fine print, developers will miss it and will write vulnerable code. RTFM is not an excuse. You don't build unavoidable trip traps and urge caution.&lt;/p&gt;
&lt;p&gt;Over a year ago, &lt;a class="reference external" href="https://github.com/python/cpython/issues/91826"&gt;a ticket was opened in the Cpython project&lt;/a&gt; to change the default behaviour of these e-mail libraries, in other words to be secure by default. We are really looking forward to the ticket being implemented and closed.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="a-few-affected-tools-and-frameworks"&gt;
&lt;h2&gt;A few affected tools and frameworks&lt;/h2&gt;
&lt;p&gt;Infrastructure:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/ceph/ceph/blob/b111d8c6ba2142c5b1051876dd01c5d0453df762/src/pybind/mgr/alerts/module.py"&gt;Ceph: Ceph is a distributed object, block, and file storage platform&lt;/a&gt; – &lt;a class="reference external" href="https://github.com/ceph/ceph/security/advisories/GHSA-xj9f-7g59-m4jx"&gt;CVE-2024-31884 was assigned&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/saltstack/salt/blob/4d4901324709e49ad81f3903e86904f3855aec5e/salt/modules/smtp.py"&gt;Saltstack: Software to automate the management and configuration of any infrastructure or application at scale&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/ansible-collections/community.general/blob/13e9e4b1960f0a09c954bfb6a64a4b4ac0358fd7/plugins/modules/mail.py"&gt;Ansible collections: This repository contains the community.general Ansible Collection. The collection is a part of the Ansible package and includes many modules and plugins supported by Ansible community which are not part of more specialized community collections.&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/Kraken-CI/kraken/blob/550cba67b48a61694299265ebfc84b708ba145c0/server/kraken/server/notify.py"&gt;Kraken CI is a continuous integration and testing system,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/matrix-org/sydent/blob/3c05e11933f2d7a0b6d1a828ba6bb2780eda2ebe/sydent/util/emailutils.py"&gt;Sydent is an identity server for the Matrix communications protocol. It allows Matrix users to prove that they own an email address or phone number, and allows other Matrix users to look them up using that email address or phone number.&lt;/a&gt;. – CVE-2023-38686 was assigned. It is fixed and we made it to the &lt;a class="reference external" href="https://matrix.org/security-hall-of-fame/"&gt;Security Hall of Fame&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/openstack/zaqar/blob/2abe46ae21fe0fa83587328ffb2f44075d3a44fc/zaqar/notification/tasks/mailto.py"&gt;Openstack-Zaqar is a multi-tenant cloud messaging and notification service for web and mobile developers.&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/nagios-plugins/nagios-plugins/blob/f1710b882b53bf7a334f231817f57c43e89d2ff6/plugins-python/check_imap_login.in"&gt;Nagios plugin check_imap_login,&lt;/a&gt;, &lt;a class="reference external" href="https://github.com/linnea-s/check_imap_login/blob/master/check_imap_login"&gt;but there is an improved version that can be used with a context&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Frameworks:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/frappe/frappe/blob/927cd647e414c7e730eb050382b67f07bcadf6a4/frappe/email/doctype/email_domain/email_domain.py"&gt;Frappe: Low code web framework for real world applications, in Python and Javascript,&lt;/a&gt;, &lt;a class="reference external" href="https://github.com/frappe/frappe/blob/347902ba96d52c3d472257d0ead57ab9dfc8fba8/frappe/email/receive.py"&gt;at several places&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/apache/arrow/blob/6cfd143d344e536978a8721f726415783322bb17/dev/archery/archery/crossbow/reports.py"&gt;Apache Arrow is a multi-language toolbox for accelerated data interchange and in-memory processing,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apache Airflow - A platform to programmatically author, schedule, and monitor workflows, affected components are &lt;a class="reference external" href="https://github.com/apache/airflow/blob/e45bee884068399e7265421511e17fed106ce5b4/airflow/providers/smtp/hooks/smtp.py"&gt;smtp.py&lt;/a&gt;, &lt;a class="reference external" href="https://github.com/apache/airflow/blob/9d0006fb9ee9c1b4742613fa3c1e82064eda6ba8/airflow/utils/email.py"&gt;email.py&lt;/a&gt; and &lt;a class="reference external" href="https://github.com/apache/airflow/blob/1240dcc167c4b47331db81deff61fc688df118c2/airflow/providers/imap/hooks/imap.py"&gt;imap.py&lt;/a&gt;. – Code is fixed and released with 2.7.0. CVE-2023-39441 was assigned to this.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/zvtvz/zvt/blob/5391df8d74bd9a71863eaeaa77aebd373e33d773/src/zvt/informer/informer.py"&gt;zvt: modular quant framework&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/ikvk/imap_tools/blob/a7c03737a61bf49542aa8b517956285e2e3a388b/imap_tools/mailbox.py"&gt;Python library imap_tools: Work with email by IMAP&lt;/a&gt;. – The library itself provides an option to pass a SSL context to MailBoxTls(), but if this parameter is not used, it is also insecure by default. &lt;a class="reference external" href="https://github.com/paperless-ngx/paperless-ngx/blob/b715e4d426f598694d50b46e3e60108d24649eda/src/paperless_mail/mail.py"&gt;This made Paperless-NGX vulnerable&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/pallets-eco/flask-mail/blob/f4dfa2a8a22d39caae08d571859233fed931935b/src/flask_mail/__init__.py"&gt;Flask-Mail: Flask-Mail adds SMTP mail sending to your Flask applications&lt;/a&gt;. – We made a &lt;a class="reference external" href="https://github.com/pallets-eco/flask-mail/pull/241"&gt;pull request to fix the problem&lt;/a&gt;, but it was not accepted yet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/spotify/luigi/blob/ff7b57622feafa4615bd945daee04b9a70125933/luigi/notifications.py"&gt;Luigi is a Python module that helps you build complex pipelines of batch jobs. It handles dependency resolution, workflow management, visualization etc. It also comes with Hadoop support built in.&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Security:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/LinOTP/LinOTP/blob/1aa6184b9260583d76ec353f159ce8a7ae1474fb/linotp/provider/smsprovider/SmtpSMSProvider.py"&gt;LinOTP: The open source solution for two factor authentication,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/rsmusllp/king-phisher/blob/2fdc70e2bafff44418e8507c0c4a4f847c76a81e/king_phisher/client/mailer.py"&gt;King phisher: Phishing Campaign Toolkit,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/secureworks/squarephish/blob/9fe299faeb9994982cadf58e3d8e1b4d765a06b0/squarephish/modules/emailer.py"&gt;SquarePhish is an advanced phishing tool that uses a technique combining the OAuth Device code authentication flow and QR codes.&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/CIRCL/AIL-framework/blob/9b2e8718d7c366210038502d9e1c66cf62040c1b/bin/exporter/MailExporter.py"&gt;AIL Project is an open source project to collect and analyse data to produce security intelligence,&lt;/a&gt; – It is fixed now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/fortra/impacket/blob/8799a1a2c42ad74423841d21ed5f4193ea54f3d5/impacket/examples/ntlmrelayx/clients/imaprelayclient.py"&gt;Impacket:&lt;/a&gt; – This could also be a feature to be insecure.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Community:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/readthedocs/readthedocs.org/blob/3cb03add2a2b8d743d206d4f5ffe5b8fc6aa2bbe/readthedocs/core/backends.py"&gt;The source code that powers readthedocs.org,&lt;/a&gt; – According to the project, this is dead code. It was removed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/mozilla/bugbot/blob/c71bf4c19dd44a4740545dd2013ebada7af27f1e/bugbot/mail.py"&gt;A Mozilla release management tool to send reminders to Firefox developers and improve Bugzilla metadata,&lt;/a&gt; – It is &lt;a class="reference external" href="https://github.com/mozilla/bugbot/commit/a031475c10ad1f7179755cc1592a1d2be158b3fa"&gt;fixed now&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;End-user tools:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/LibreOffice/core/blob/cd973e75fa55e3b2703757b1901e9ce644881be9/scripting/source/pyprov/mailmerge.py"&gt;LibreOffice: mailmerge script&lt;/a&gt; – Fixed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/awdeorio/mailmerge/blob/ac7c89d2bb90fdf766ce9010177e1b34310be0b4/mailmerge/sendmail_client.py"&gt;Mailmerge: A simple, command line mail merge tool.&lt;/a&gt; – Fixed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/janeczku/calibre-web/blob/43ee85fbb5d05340a792ab8de467381009ce80a7/cps/tasks/mail.py"&gt;Calibre-Web: Web app for browsing, reading and downloading eBooks stored in a Calibre database,&lt;/a&gt; – Fixed now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/vertexproject/synapse/blob/ab07d7c1b36c8c590d14226a38d9e25b37441776/synapse/lib/stormlib/imap.py"&gt;Synapse is a versatile central intelligence system created to support analyst teams in every stage of the intelligence life cycle,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/django-helpdesk/django-helpdesk/blob/c23c8e5be6d5be498cd7877b0e0e29072461c49d/helpdesk/email.py"&gt;Django Helpdesk: A Django application to manage tickets for an internal helpdesk. Formerly known as Jutda Helpdesk,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;OAuth2 clients:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/google/gmail-oauth2-tools/blob/876a8bd965752e1f6f2a97a7005da6a23c18d5b5/python/oauth2.py"&gt;Google OAuth2 python client,&lt;/a&gt;, &lt;a class="reference external" href="https://github.com/imapsync/imapsync/blob/master/oauth2/oauth2_google.py"&gt;for example used in&lt;/a&gt; – Pentagrid filed a bug report for this in the Google and Alphabet Vulnerability Reward Program (VRP) as described above. It is fixed now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://gitlab.com/muttmua/mutt/-/blob/7c4fa47888d0dee4529f3a521bec76420528776e/contrib/mutt_oauth2.py"&gt;A contributed script to the Mutt mail client,&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://github.com/joestump/python-oauth2/blob/master/oauth2/clients/imap.py"&gt;python-oauth2: A fully tested, abstract interface to creating OAuth clients and servers.&lt;/a&gt; – Listed here, but it is an unmaintained project.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;aside class="footnote-list brackets"&gt;
&lt;aside class="footnote brackets" id="footnote-1" role="doc-footnote"&gt;
&lt;span class="label"&gt;&lt;span class="fn-bracket"&gt;[&lt;/span&gt;&lt;a role="doc-backlink" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#footnote-reference-1"&gt;1&lt;/a&gt;&lt;span class="fn-bracket"&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;p&gt;While submitting a vulnerability report to the Google Vulnerability Reward Program (VRP) felt like the most clear and straightforward process ever invented, it drastically changed afterwards, when it came to coordinating the publication or the payout. There was no to no clear communication afterwards how and when the publication happens. The process just stuck. The reported issue was fixed on 24 July 2023 in the source code. Update 2025-06: Finally, the report was made public and the bounty paid.&lt;/p&gt;
&lt;/aside&gt;
&lt;aside class="footnote brackets" id="footnote-2" role="doc-footnote"&gt;
&lt;span class="label"&gt;&lt;span class="fn-bracket"&gt;[&lt;/span&gt;&lt;a role="doc-backlink" href="https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/#footnote-reference-2"&gt;2&lt;/a&gt;&lt;span class="fn-bracket"&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;p&gt;Technically, it was the Hackerone triage team, but they act for their customers and they represent their clients towards the vulnerability submitters. When the triage team decides there is no risk – possibly under the context that they are trained to close as many non-reports as possible – then their client won't see the risk, too. That is one of the &lt;a class="reference external" href="https://www.pentagrid.ch/en/blog/interview-about-penetration-testing-vs-bug-bounty-programs/"&gt;drawbacks of bug bounty programs compared to penetration testing&lt;/a&gt;.&lt;/p&gt;
&lt;/aside&gt;
&lt;/aside&gt;
&lt;/section&gt;</description><category>API</category><category>Bug Bounty</category><category>Certificate Verification</category><category>Encryption</category><category>Operational Security</category><category>Python</category><category>Vulnerability</category><guid>https://www.pentagrid.ch/en/blog/python-mail-libraries-certificate-verification/</guid><pubDate>Tue, 14 Nov 2023 09:23:00 GMT</pubDate></item><item><title>Teaching Burp a new HTTP Transport Encoding</title><link>https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/</link><dc:creator>Pentagrid AG</dc:creator><description>&lt;p&gt;Today we would like to talk about Burp Suite Professional and extensions again. In this blog post we explain how we can teach Burp Suite to handle a custom Transport Encoding that is spoken between an HTTP client and a server by using Burp extensions.&lt;/p&gt;
&lt;!-- TEASER_END --&gt;
&lt;section id="introduction"&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Burp has many nice features, but sometimes it lacks a feature we would like to have or our target application is customized so that it is necessary to teach Burp new things. More specifically:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;Burp has &lt;a class="reference external" href="https://forum.portswigger.net/thread/brotli-compression-is-not-supported-988bf33f"&gt;no support for the standard HTTP brotli Transport-Encoding&lt;/a&gt;, but all modern browsers do. This problem is handled by Burp by removing brotli from the Accept-Encoding request header (see Proxy - Options - Miscellaneous - Remove unsupported encodings from Accept-Encoding headers in incoming requests), which works for modern browsers. However, we encountered situations during tests where a non-browser HTTP client software required brotli and refused to talk to the server when brotli encoding is missing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Java fat clients sometimes zlib-encode the entire HTTP body when talking to a server and vice-versa. They also often refuse to speak non-zlib and do not signal it at all in an HTTP header, therefore it is necessary to implement zlib-decoding and encoding to be able to use Burp properly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If a website uses JavaScript to encrypt all HTTP bodies when talking to a server and vice-versa, we also would like to implement a decryption and encryption routing to use the Burp tools. We also encountered the same situation with other HTTP clients that used additional transport encryption, such as mobile banking apps.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The biggest issue for us was to figure out how we approach these situations consistently and we show our approach in this blog post.&lt;/p&gt;
&lt;p&gt;In this blog post we often refer to "encoding" or "encrypting", which obviously is not the same, but both operations have to be done at the same place inside Burp. Encryption or encoding is merely an implementation detail in this blog post. Also "cleartext" is used to indicate decoded or decrypted content.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="why-are-you-doing-all-of-this"&gt;
&lt;h2&gt;Why are you doing all of this?&lt;/h2&gt;
&lt;p&gt;If Burp is not seeing decoded messages for one of the reasons above, it won't work properly. Tools such as Burp Scanner, Repeater, Intruder and other extensions will often fail to interpret the encoded HTTP content and will for sure fail with encrypted content. It won't matter if you use the scanner or not, in many cases it won't do anything useful if you don't implement this custom decoder/encoder. On the contrary, very often a tester's task is to make their tools work. This might be rewarded in the end by simply pressing the active scan button in Burp and then finding security issues. To us, this is a huge difference between a good and a bad security analysis.&lt;/p&gt;
&lt;p&gt;Usually we would suggest to solve this problem with features or extensions that are already present, for example the Hackvertor extension would be a good candidate. However, Hackvertor won't modify responses, so this isn't an option here.&lt;/p&gt;
&lt;/section&gt;
&lt;section id="burp-s-api-for-extensions"&gt;
&lt;h2&gt;Burp's API for extensions&lt;/h2&gt;
&lt;p&gt;Burp provides several &lt;a class="reference external" href="https://portswigger.net/burp/extender/api/"&gt;APIs an extension can use&lt;/a&gt;. The API code didn't get much love in the last few years, but this is hopefully changing when Burp releases the &lt;a class="reference external" href="https://portswigger.net/blog/burp-suite-roadmap-for-2022"&gt;New API and multi-language extensibility&lt;/a&gt;. Let's hope for the best, but for now we're stuck with the API we have. There are two main API hooks that matter in the situation of a missing Transport Encoding. We'll use the name of the function name in the rest of this blog post, but the interfaces that provide the functionality are called:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://portswigger.net/burp/extender/api/burp/IProxyListener.html"&gt;IProxyListener&lt;/a&gt;, which means you have to implement the function &lt;code class="docutils literal"&gt;processProxyMessage&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a class="reference external" href="https://portswigger.net/burp/extender/api/burp/IHttpListener.html"&gt;IHttpListener&lt;/a&gt;, which means you have to implement the function &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;While both interfaces sound similar, the proxy listener will only see requests and responses going through the proxy (e.g. from the browser), whereas the HTTP listener will see the requests and responses of all tools (Proxy, Crawler, Scanner, Repeater, Intruder, other extensions, etc.). However, there's one little detail that is important to mention: If you want to change messages going throught the proxy, you have to do that in the &lt;code class="docutils literal"&gt;processProxyMessage&lt;/code&gt; function and you can't do that in the &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt;. It's just a Burp API limitation that you can't modify messages from TOOL_PROXY in the &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt;. That means we have to get around this limitation by choosing the correct API.&lt;/p&gt;
&lt;p&gt;While we think it is better to use Kotlin to write large Burp extensions nowadays, rapid prototyping is still quicker with Python. Therefore we use Python (or rather, Jython 2.7 in Burp) in this blog post.&lt;/p&gt;
&lt;p&gt;Here's a little Python sample extension that handles the API confusion of &lt;code class="docutils literal"&gt;processProxyMessage&lt;/code&gt; and &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt;, so we don't need to care about it anymore and can just modify messages in the newly created &lt;code class="docutils literal"&gt;processMessage&lt;/code&gt; function:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_773268b73f2b497380611e55069e938d-1" name="rest_code_773268b73f2b497380611e55069e938d-1" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-1"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtender&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-2" name="rest_code_773268b73f2b497380611e55069e938d-2" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-2"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-3" name="rest_code_773268b73f2b497380611e55069e938d-3" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-3"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-4" name="rest_code_773268b73f2b497380611e55069e938d-4" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-4"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-5" name="rest_code_773268b73f2b497380611e55069e938d-5" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-5"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-6" name="rest_code_773268b73f2b497380611e55069e938d-6" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-6"&gt;&lt;/a&gt;&lt;span class="n"&gt;NAME&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Pentagrid Extension Template"&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-7" name="rest_code_773268b73f2b497380611e55069e938d-7" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-8" name="rest_code_773268b73f2b497380611e55069e938d-8" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-8"&gt;&lt;/a&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BurpExtender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-9" name="rest_code_773268b73f2b497380611e55069e938d-9" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-9"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-10" name="rest_code_773268b73f2b497380611e55069e938d-10" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-10"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;registerExtenderCallbacks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-11" name="rest_code_773268b73f2b497380611e55069e938d-11" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-11"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# keep a reference to our callbacks object&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-12" name="rest_code_773268b73f2b497380611e55069e938d-12" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-12"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_callbacks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-13" name="rest_code_773268b73f2b497380611e55069e938d-13" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-13"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-14" name="rest_code_773268b73f2b497380611e55069e938d-14" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-14"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# set our extension name&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-15" name="rest_code_773268b73f2b497380611e55069e938d-15" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-15"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setExtensionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-16" name="rest_code_773268b73f2b497380611e55069e938d-16" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-16"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-17" name="rest_code_773268b73f2b497380611e55069e938d-17" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-17"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# register ourselves as an Proxy listener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-18" name="rest_code_773268b73f2b497380611e55069e938d-18" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-18"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerProxyListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-19" name="rest_code_773268b73f2b497380611e55069e938d-19" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-19"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-20" name="rest_code_773268b73f2b497380611e55069e938d-20" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-20"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# register ourselves as an HTTP listener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-21" name="rest_code_773268b73f2b497380611e55069e938d-21" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-21"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerHttpListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-22" name="rest_code_773268b73f2b497380611e55069e938d-22" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-22"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-23" name="rest_code_773268b73f2b497380611e55069e938d-23" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-23"&gt;&lt;/a&gt;        &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Loaded "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;" successfully!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-24" name="rest_code_773268b73f2b497380611e55069e938d-24" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-24"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-25" name="rest_code_773268b73f2b497380611e55069e938d-25" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-25"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-26" name="rest_code_773268b73f2b497380611e55069e938d-26" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-26"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IHttpListener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-27" name="rest_code_773268b73f2b497380611e55069e938d-27" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-27"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-28" name="rest_code_773268b73f2b497380611e55069e938d-28" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-28"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-29" name="rest_code_773268b73f2b497380611e55069e938d-29" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-29"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processHttpMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-30" name="rest_code_773268b73f2b497380611e55069e938d-30" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-30"&gt;&lt;/a&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-31" name="rest_code_773268b73f2b497380611e55069e938d-31" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-31"&gt;&lt;/a&gt;            &lt;span class="c1"&gt;# DONT'T DO ANYTHING HERE&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-32" name="rest_code_773268b73f2b497380611e55069e938d-32" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-32"&gt;&lt;/a&gt;            &lt;span class="c1"&gt;# Instead, use processProxyMessage below&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-33" name="rest_code_773268b73f2b497380611e55069e938d-33" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-33"&gt;&lt;/a&gt;            &lt;span class="c1"&gt;# https://github.com/nccgroup/BurpSuiteLoggerPlusPlus/issues/42&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-34" name="rest_code_773268b73f2b497380611e55069e938d-34" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-34"&gt;&lt;/a&gt;            &lt;span class="k"&gt;return&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-35" name="rest_code_773268b73f2b497380611e55069e938d-35" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-35"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;processMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-36" name="rest_code_773268b73f2b497380611e55069e938d-36" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-36"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-37" name="rest_code_773268b73f2b497380611e55069e938d-37" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-37"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-38" name="rest_code_773268b73f2b497380611e55069e938d-38" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-38"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IProxyListener&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-39" name="rest_code_773268b73f2b497380611e55069e938d-39" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-39"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-40" name="rest_code_773268b73f2b497380611e55069e938d-40" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-40"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processProxyMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-41" name="rest_code_773268b73f2b497380611e55069e938d-41" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-41"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;processMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getMessageInfo&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-42" name="rest_code_773268b73f2b497380611e55069e938d-42" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-42"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-43" name="rest_code_773268b73f2b497380611e55069e938d-43" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-43"&gt;&lt;/a&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-44" name="rest_code_773268b73f2b497380611e55069e938d-44" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-44"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-45" name="rest_code_773268b73f2b497380611e55069e938d-45" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-45"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# TODO: Implement whatever you would like to do&lt;/span&gt;
&lt;a id="rest_code_773268b73f2b497380611e55069e938d-46" name="rest_code_773268b73f2b497380611e55069e938d-46" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_773268b73f2b497380611e55069e938d-46"&gt;&lt;/a&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;As a bonus, the Burp UI will show the "Edited request" or "Edited response" option in the Proxy tool whenever we change a proxy message. However, for &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt; we are partially blind, the request and responses will simply be changed, but depending on where we measure we might see them in a different state in the UI (discussed in the next section).&lt;/p&gt;
&lt;/section&gt;
&lt;section id="burp-s-hooking-locations"&gt;
&lt;h2&gt;Burp's hooking locations&lt;/h2&gt;
&lt;p&gt;We would like to hook as early as possible and as late as possible. We would like to make sure that we decode or decrypt early, so that all other Burp tools can work with readable non-compressed HTTP requests and responses. We also want to encode or encrypt as late as possible, just before the request leaves Burp for the same reason. The problem here is that &lt;code class="docutils literal"&gt;processProxyMessage&lt;/code&gt; is called before &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt; for requests, but for responses &lt;code class="docutils literal"&gt;processHttpMessage&lt;/code&gt; is called before &lt;code class="docutils literal"&gt;processProxyMessage&lt;/code&gt;. When analysing the exact behavior, we saw it's a non-trivial setup. For example, the built-in Burp Logger is a tab in the Burp UI showing all requests/responses that flow through Burp. But the question is, where does the Burp Logger hook the API itself? Moreover, users who have advanced knowledge of Burp also know that the extension order in the loaded extension list matters. So where should we put our decoder or decrypter and where should we put our encoder or encrypter? This is not easy to explain and it took us a little trial and error, but we figured out that this diagram should be accurate:&lt;/p&gt;
&lt;figure class="align-center"&gt;
&lt;a class="reference external image-reference" href="https://www.pentagrid.ch/images/202204_burp_handling_of_messages.png"&gt;
&lt;img alt="Diagram showing how requests and responses are processed inside Burp when we load our Burp extensions. Green is for cleartext (decoded or decrypted) traffic, red for encoded or encrypted traffic." src="https://www.pentagrid.ch/images/202204_burp_handling_of_messages.thumbnail.png"&gt;
&lt;/a&gt;
&lt;figcaption&gt;
&lt;p&gt;Diagram showing how requests and responses are processed inside Burp when we load our Burp extensions. Green is for cleartext (decoded or decrypted) traffic, red for encoded or encrypted traffic.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;This diagram shows several interesting details:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;We achieve what we want: Target, Intruder, Repeater, Scanner and other extensions can deal with "cleartext" requests. However, we can't make it work with Proxy match/replace rules for requests (they are applied to the encoded content).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Burp's built-in Logger is not last in the chain for responses, it's possible that Burp extensions modify the responses. This means you don't necessarily see what was delivered to the client/server in Logger. You should better use Logger++ and put it last in the extension list to see which requests are sent to the server and which responses are returned after processing in Burp. Of course it depends on what you want to see, but that's what is the most logical setup.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Our extension we would like to write for our purpose has to be first &lt;em&gt;and&lt;/em&gt; last (well, second-last before Logger++) to make sure it does its job well. This means we need to write two extensions, an early-decoder that is first in the list for requests (see DECRYPTER top left in the diagram) and responses (see DECRYPTER bottom right) and a late-reencoder that is last in the list for requests (see ENCRYPTER bottom left) and responses (see ENCRYPTER top right). So the order of the extensions has to be like in the following image:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class="align-center"&gt;
&lt;a class="reference external image-reference" href="https://www.pentagrid.ch/images/202204_burp_extension_order.png"&gt;
&lt;img alt="Extension order is important to make sure all extensions see the correct traffic. Early decoder as the first extension, late encoder as the second-last." src="https://www.pentagrid.ch/images/202204_burp_extension_order.thumbnail.png"&gt;
&lt;/a&gt;
&lt;figcaption&gt;
&lt;p&gt;Extension order is important to make sure all extensions see the correct traffic. Early decoder as the first extension, late encoder as the second-last.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/figure&gt;
&lt;p&gt;Now that we know we need two extensions, how would the Python extensions look like? Here's the early decoder:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-1" name="rest_code_dfe7432a4980464381e3ff25cfac818b-1" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-1"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtender&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-2" name="rest_code_dfe7432a4980464381e3ff25cfac818b-2" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-2"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-3" name="rest_code_dfe7432a4980464381e3ff25cfac818b-3" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-3"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-4" name="rest_code_dfe7432a4980464381e3ff25cfac818b-4" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-4"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-5" name="rest_code_dfe7432a4980464381e3ff25cfac818b-5" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-5"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-6" name="rest_code_dfe7432a4980464381e3ff25cfac818b-6" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-6"&gt;&lt;/a&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pentagrid early decoder"&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-7" name="rest_code_dfe7432a4980464381e3ff25cfac818b-7" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-8" name="rest_code_dfe7432a4980464381e3ff25cfac818b-8" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-8"&gt;&lt;/a&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BurpExtender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-9" name="rest_code_dfe7432a4980464381e3ff25cfac818b-9" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-9"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-10" name="rest_code_dfe7432a4980464381e3ff25cfac818b-10" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-10"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;registerExtenderCallbacks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-11" name="rest_code_dfe7432a4980464381e3ff25cfac818b-11" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-11"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-12" name="rest_code_dfe7432a4980464381e3ff25cfac818b-12" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-12"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# keep a reference to our callbacks object&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-13" name="rest_code_dfe7432a4980464381e3ff25cfac818b-13" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-13"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_callbacks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-14" name="rest_code_dfe7432a4980464381e3ff25cfac818b-14" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-14"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-15" name="rest_code_dfe7432a4980464381e3ff25cfac818b-15" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-15"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# obtain an extension helpers object&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-16" name="rest_code_dfe7432a4980464381e3ff25cfac818b-16" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-16"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_helpers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getHelpers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-17" name="rest_code_dfe7432a4980464381e3ff25cfac818b-17" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-17"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-18" name="rest_code_dfe7432a4980464381e3ff25cfac818b-18" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-18"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# set our extension name&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-19" name="rest_code_dfe7432a4980464381e3ff25cfac818b-19" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-19"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setExtensionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-20" name="rest_code_dfe7432a4980464381e3ff25cfac818b-20" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-20"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-21" name="rest_code_dfe7432a4980464381e3ff25cfac818b-21" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-21"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# register ourselves as an HTTP listener&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-22" name="rest_code_dfe7432a4980464381e3ff25cfac818b-22" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-22"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerHttpListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-23" name="rest_code_dfe7432a4980464381e3ff25cfac818b-23" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-23"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerProxyListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-24" name="rest_code_dfe7432a4980464381e3ff25cfac818b-24" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-24"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-25" name="rest_code_dfe7432a4980464381e3ff25cfac818b-25" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-25"&gt;&lt;/a&gt;        &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Loaded "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;" successfully!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-26" name="rest_code_dfe7432a4980464381e3ff25cfac818b-26" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-26"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-27" name="rest_code_dfe7432a4980464381e3ff25cfac818b-27" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-27"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-28" name="rest_code_dfe7432a4980464381e3ff25cfac818b-28" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-28"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IHttpListener&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-29" name="rest_code_dfe7432a4980464381e3ff25cfac818b-29" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-29"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-30" name="rest_code_dfe7432a4980464381e3ff25cfac818b-30" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-30"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-31" name="rest_code_dfe7432a4980464381e3ff25cfac818b-31" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-31"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processHttpMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-32" name="rest_code_dfe7432a4980464381e3ff25cfac818b-32" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-32"&gt;&lt;/a&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-33" name="rest_code_dfe7432a4980464381e3ff25cfac818b-33" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-33"&gt;&lt;/a&gt;            &lt;span class="c1"&gt;# Already processed in processProxyMessage&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-34" name="rest_code_dfe7432a4980464381e3ff25cfac818b-34" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-34"&gt;&lt;/a&gt;            &lt;span class="k"&gt;return&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-35" name="rest_code_dfe7432a4980464381e3ff25cfac818b-35" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-35"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-36" name="rest_code_dfe7432a4980464381e3ff25cfac818b-36" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-36"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-37" name="rest_code_dfe7432a4980464381e3ff25cfac818b-37" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-37"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-38" name="rest_code_dfe7432a4980464381e3ff25cfac818b-38" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-38"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IProxyListener&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-39" name="rest_code_dfe7432a4980464381e3ff25cfac818b-39" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-39"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-40" name="rest_code_dfe7432a4980464381e3ff25cfac818b-40" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-40"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processProxyMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-41" name="rest_code_dfe7432a4980464381e3ff25cfac818b-41" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-41"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# Responses are handled as early as possible in processHttpMessage&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-42" name="rest_code_dfe7432a4980464381e3ff25cfac818b-42" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-42"&gt;&lt;/a&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-43" name="rest_code_dfe7432a4980464381e3ff25cfac818b-43" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-43"&gt;&lt;/a&gt;            &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getMessageInfo&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-44" name="rest_code_dfe7432a4980464381e3ff25cfac818b-44" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-44"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-45" name="rest_code_dfe7432a4980464381e3ff25cfac818b-45" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-45"&gt;&lt;/a&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-46" name="rest_code_dfe7432a4980464381e3ff25cfac818b-46" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-46"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-47" name="rest_code_dfe7432a4980464381e3ff25cfac818b-47" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-47"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# TODO: implement decoding&lt;/span&gt;
&lt;a id="rest_code_dfe7432a4980464381e3ff25cfac818b-48" name="rest_code_dfe7432a4980464381e3ff25cfac818b-48" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_dfe7432a4980464381e3ff25cfac818b-48"&gt;&lt;/a&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And here's the late encoder:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code python"&gt;&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-1" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-1" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-1"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtender&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-2" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-2" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-2"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-3" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-3" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-3"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-4" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-4" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-4"&gt;&lt;/a&gt;&lt;span class="kn"&gt;from&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nn"&gt;burp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-5" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-5" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-5"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-6" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-6" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-6"&gt;&lt;/a&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Pentagrid late encoder"&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-7" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-7" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-7"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-8" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-8" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-8"&gt;&lt;/a&gt;&lt;span class="k"&gt;class&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nc"&gt;BurpExtender&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IHttpListener&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;IProxyListener&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-9" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-9" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-9"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-10" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-10" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-10"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;registerExtenderCallbacks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-11" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-11" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-11"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-12" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-12" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-12"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# keep a reference to our callbacks object&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-13" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-13" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-13"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_callbacks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-14" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-14" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-14"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-15" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-15" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-15"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# obtain an extension helpers object&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-16" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-16" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-16"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_helpers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getHelpers&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-17" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-17" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-17"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-18" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-18" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-18"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# set our extension name&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-19" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-19" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-19"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;setExtensionName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-20" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-20" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-20"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-21" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-21" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-21"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# register ourselves as an HTTP listener&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-22" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-22" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-22"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerHttpListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-23" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-23" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-23"&gt;&lt;/a&gt;        &lt;span class="n"&gt;callbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;registerProxyListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-24" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-24" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-24"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-25" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-25" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-25"&gt;&lt;/a&gt;        &lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Loaded "&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="n"&gt;NAME&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="s2"&gt;" successfully!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-26" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-26" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-26"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-27" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-27" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-27"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-28" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-28" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-28"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IHttpListener&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-29" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-29" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-29"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-30" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-30" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-30"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-31" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-31" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-31"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processHttpMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-32" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-32" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-32"&gt;&lt;/a&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-33" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-33" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-33"&gt;&lt;/a&gt;            &lt;span class="c1"&gt;# Requests are handled as late as possible in processProxyMessage&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-34" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-34" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-34"&gt;&lt;/a&gt;            &lt;span class="k"&gt;return&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-35" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-35" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-35"&gt;&lt;/a&gt;        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-36" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-36" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-36"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-37" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-37" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-37"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-38" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-38" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-38"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;# implement IProxyListener&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-39" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-39" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-39"&gt;&lt;/a&gt;    &lt;span class="c1"&gt;#&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-40" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-40" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-40"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;processProxyMessage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-41" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-41" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-41"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# Responses are handled as late as possible in processHttpMessage&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-42" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-42" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-42"&gt;&lt;/a&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-43" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-43" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-43"&gt;&lt;/a&gt;            &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IBurpExtenderCallbacks&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;TOOL_PROXY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getMessageInfo&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-44" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-44" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-44"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-45" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-45" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-45"&gt;&lt;/a&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-46" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-46" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-46"&gt;&lt;/a&gt;    &lt;span class="k"&gt;def&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;filter_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;toolFlag&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageIsRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;messageInfo&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-47" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-47" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-47"&gt;&lt;/a&gt;        &lt;span class="c1"&gt;# TODO: implement encoding&lt;/span&gt;
&lt;a id="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-48" name="rest_code_a6988cdcaff644c6b73b98e3c1897e6e-48" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_a6988cdcaff644c6b73b98e3c1897e6e-48"&gt;&lt;/a&gt;        &lt;span class="k"&gt;pass&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;/section&gt;
&lt;section id="bonus"&gt;
&lt;h2&gt;Bonus&lt;/h2&gt;
&lt;p&gt;To make this a little more convenient for you, we've set up a &lt;a class="reference external" href="https://github.com/pentagridsec/PentagridBurpTransportEncoding"&gt;Github repository&lt;/a&gt; with all the examples from above (in the "minimal" subfolder). However, that's not all:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;p&gt;A fully working example for the zlib-body encoding/decoding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A template that has some more helpful functions if you want to implement your own decoding/encoding.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An additional extension that implements an IMessageEditorTabFactory, so if you encounter an encoded message in Burp you can click the message viewer option of the extension and will see it in decoded form.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/section&gt;
&lt;section id="more-advanced-examples"&gt;
&lt;h2&gt;More advanced examples&lt;/h2&gt;
&lt;p&gt;With the above examples it should be no problem for you to also create extensions that do decryption/encryption instead of decoding/encoding in more complicated setups. In one of our security analysis, we were able to implement the decryption/encryption and hardcoded the key at first. However, then we realised we could additionally inject a JavaScript tag into the HTML single-page response of the server to "steal" our own encryption key from our browser. This removed the requirement to hard-code the encryption key. We did this by replacing &lt;code class="docutils literal"&gt;&amp;lt;/body&amp;gt;&lt;/code&gt; with:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code html"&gt;&lt;a id="rest_code_7e2805ef1f8a40cdb3156ff57c596351-1" name="rest_code_7e2805ef1f8a40cdb3156ff57c596351-1" href="https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/#rest_code_7e2805ef1f8a40cdb3156ff57c596351-1"&gt;&lt;/a&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;lastKey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pentagrid&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nowKey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;encryptionKey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nowKey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nowKey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;!==&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;lastKey&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="nx"&gt;lastKey&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nowKey&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pentagrid2&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="ow"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;XMLHttpRequest&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pentagrid2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"GET"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/pentagridDiscloseKey="&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;nowKey&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;pentagrid2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);}};&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;setInterval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pentagrid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This JavaScript extracted the encryption key from the browser DOM and sent it through Burp, so we could catch it in our decrypter/encrypter extensions and therefore fully intercept cleartext traffic.&lt;/p&gt;
&lt;p&gt;Happy hacking!&lt;/p&gt;
&lt;/section&gt;</description><category>API</category><category>Burp</category><category>Encryption</category><category>Extensions</category><category>Pentesting</category><category>Portswigger</category><category>Transport Encoding</category><guid>https://www.pentagrid.ch/en/blog/teaching_burp_a_new_http_transport_encoding/</guid><pubDate>Wed, 13 Apr 2022 10:42:00 GMT</pubDate></item></channel></rss>