<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>RedTeam - RiskInsight</title>
	<atom:link href="https://www.riskinsight-wavestone.com/en/tag/redteam-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.riskinsight-wavestone.com/en/tag/redteam-2/</link>
	<description>The cybersecurity &#38; digital trust blog by Wavestone&#039;s consultants</description>
	<lastBuildDate>Thu, 25 Jul 2024 13:19:47 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://www.riskinsight-wavestone.com/wp-content/uploads/2024/02/Blogs-2024_RI-39x39.png</url>
	<title>RedTeam - RiskInsight</title>
	<link>https://www.riskinsight-wavestone.com/en/tag/redteam-2/</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>DataScience for RedTeam: Extend your attack surface</title>
		<link>https://www.riskinsight-wavestone.com/en/2024/07/datascience-for-redteam-extend-your-attack-surface/</link>
					<comments>https://www.riskinsight-wavestone.com/en/2024/07/datascience-for-redteam-extend-your-attack-surface/#respond</comments>
		
		<dc:creator><![CDATA[Yoann DEQUEKER]]></dc:creator>
		<pubDate>Thu, 25 Jul 2024 13:19:45 +0000</pubDate>
				<category><![CDATA[Deep-dive]]></category>
		<category><![CDATA[Ethical Hacking & Incident Response]]></category>
		<category><![CDATA[DataScience]]></category>
		<category><![CDATA[RedTeam]]></category>
		<guid isPermaLink="false">https://www.riskinsight-wavestone.com/?p=23640</guid>

					<description><![CDATA[<p>1. Overview In an information system, applications are not equal. Some of them can be used as an entry point in the information system, others are used as compromise accelerators, and some are saved for post-exploitation. These applications are called...</p>
<p>Cet article <a href="https://www.riskinsight-wavestone.com/en/2024/07/datascience-for-redteam-extend-your-attack-surface/">DataScience for RedTeam: Extend your attack surface</a> est apparu en premier sur <a href="https://www.riskinsight-wavestone.com/en/">RiskInsight</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h1><span style="color: #451dc7;">1. Overview</span></h1>
<p>In an information system, applications are not equal. Some of them can be used as an entry point in the information system, <span style="color: #451dc7;"><strong>others are used as compromise accelerators</strong></span>, and some are saved for post-exploitation. These applications are called high-value targets.</p>
<p>For example, during a standard attack, the in-house developed web application will be targeted first as they offer an important attack surface and often allow remote code execution on a domain join servers. The <span style="color: #250f6b;"><em>CICD</em></span> infrastructures are exploited to easily rebound on the internal network through the infection of <span style="color: #250f6b;"><em>CICD</em></span> pipeline or the discovery of additional secrets. The <span style="color: #250f6b;"><em>ADCS</em></span> is highly leveraged to speed up the domain compromise through the set of <span style="color: #250f6b;"><em>ESCXX</em></span> vulnerabilities.</p>
<p><span style="color: #451dc7;"><strong>The typology of applications in each category has quietly been the same for several years </strong></span>even if some new challengers have appeared over the years such as the <span style="color: #250f6b;"><em>SCCM</em> </span>application, the <span style="color: #250f6b;"><em>EDR</em> </span>console, etc. But because the same techniques are used for several years now, <span style="color: #451dc7;"><strong>companies started securing these elements making their compromise and exploitation more difficult</strong></span><em>. </em></p>
<p>It is <span style="color: #451dc7;"><strong>time to explore new horizons </strong></span>and renew this old stuff with a new set of applications.</p>
<p>In this article,<span style="color: #451dc7;"><strong> we will look at the DataScience application</strong></span>. With the rise of <span style="color: #250f6b;"><em>BigData</em></span>, more and more companies are integrating <span style="color: #250f6b;"><em>DataScience</em></span> infrastructure on their information system. We will see how these applications can be exploited to:</p>
<ul>
<li><em>Achieve remote code execution</em></li>
<li><em>Move laterally on the internal network</em></li>
<li><em>Spread malware among users</em></li>
<li><em>Ease access persistence</em></li>
<li><em>Exploit datalake for datamining</em></li>
</ul>
<h1><span style="color: #451dc7;">2. Initial Access on the DataScience Application</span></h1>
<p>There are a lot of different <span style="color: #250f6b;"><em>DataScience</em> </span>applications. In this article we will mainly focus on the <span style="color: #250f6b;"><em>Spotfire</em></span> and the <span style="color: #250f6b;"><em>Dataiku</em></span> applications as they are either the most popular or with the wind in their sails.</p>
<p>As <span style="color: #250f6b;"><em>DataScience</em></span> is still new in companies, these applications are often deployed and maintained by the business and not by the <span style="color: #250f6b;"><em>IT</em> </span>department.</p>
<p>Having an application out of the standard <span style="color: #250f6b;"><em>IT</em></span> process (<span style="color: #250f6b;"><em>Shadow IT</em></span>) is often interesting for an attacker. Indeed, when an application is set up out of the standard <em><span style="color: #250f6b;">IT</span> </em>process, it often does not implement the standard security rules enforced by the company. So, you will surely see:</p>
<ul>
<li>Application exposed directly on the internet without additional protection</li>
<li>Application not set up in a specific <span style="color: #250f6b;"><em>DMZ</em> </span>with a direct access to the internal network</li>
<li>Application with a local authentication instead of the global company authentication mechanism</li>
<li>Lack of hardening in the deployment process and lack of security patch deployment</li>
</ul>
<p>These points can seem irrelevant, but the accumulation leads to the possibility to access to these applications directly from the <span style="color: #250f6b;"><em>Internet</em> </span>with unsecured or default credentials still valid or through an authentication bypass fixed few years ago but never patched cause the business doesn&#8217;t know or even care…</p>
<h1><span style="color: #451dc7;">3. DataScience is RCE as a service</span></h1>
<h2><span style="color: #451dc7;">3.1. Why using datascience application</span></h2>
<p>Before getting to the heart of the matter, let’s take some time to discuss the interest and use case of <span style="color: #250f6b;"><em>datascience</em> </span>application.</p>
<p>Let’s take as an example a company that sell several types of products such as <span style="color: #250f6b;"><em>Amazon</em></span> or any marketplace. This company wants to see in real time the trending products depending on some user characteristic collected by their website analytics.</p>
<p>They can use an <span style="color: #250f6b;"><em>Excel</em></span> file and try using the <span style="color: #250f6b;"><em>Excel VBA</em> </span>features to create graphs and trends, but it would be very painful to manually import all data in the <span style="color: #250f6b;"><em>Excel</em></span> file and for a company with millions of customers, the <span style="color: #250f6b;"><em>Excel</em></span> will likely crash every time some sneeze nearby.</p>
<p>To solve this problem, the company started storing its analytics data in a database that will be called a <span style="color: #250f6b;"><em>datalake</em></span>. Then, when someone wants to create a nice report, he creates a <span style="color: #250f6b;"><em>python</em></span> script that connects to the database, fetch the relevant data, process it through <span style="color: #250f6b;"><em>numpy</em></span> or <span style="color: #250f6b;"><em>panda</em></span> and use <span style="color: #250f6b;"><em>matplotlib</em></span> to draw the graph and trends. This is much better, the application can scale up, is more stable but it asks for technical scripting skills so the business cannot use it by itself.</p>
<p>So, the company decides to develop a nice front-end to wrap all the <span style="color: #250f6b;"><em>python</em></span> script behind a nice <span style="color: #250f6b;"><em>UI</em></span> anyone can use. Users can connect to the application, choose the data to import, process it and draw graph without writing a single line of code.</p>
<p>They just created their first <span style="color: #250f6b;"><em>datascience</em></span> application.</p>
<p>Today, companies will not likely invest several months of development on this type of setup. They prefer to buy an all-in-one commercial application. Among these applications there are <span style="color: #250f6b;"><em>Spotfire</em></span> and <span style="color: #250f6b;"><em>Dataiku</em></span>.</p>
<h2><span style="color: #451dc7;">3.2. Where is my RCE?</span></h2>
<p><span style="color: #250f6b;"><em>Datascience</em></span> application can be summarized as a simple frontend for data processing scripts. And sometimes, the built-in functions are not enough so they expose access to their script engine to allow developers to create custom script that can be fully integrated to the environment and used by the business.</p>
<h3><span style="color: #451dc7;">3.2.1. Spotfire</span></h3>
<p><span style="text-decoration: underline;"><strong>Basic Spotfire infrastructure</strong></span></p>
<p>When deployed as-is, the <span style="color: #250f6b;"><em>Spotfire</em></span> infrastructure looks like the following figure:</p>
<p><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-23661" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_01.png" alt="" width="949" height="488" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_01.png 949w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_01-371x191.png 371w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_01-71x37.png 71w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_01-768x395.png 768w" sizes="(max-width: 949px) 100vw, 949px" /></p>
<p style="text-align: center;"><em>Figure 1: Basic Spotfire infrastructure</em></p>
<p>The user connects to a <span style="color: #250f6b;"><em>WebUI</em></span> exposed by the <span style="color: #250f6b;"><em>Spotfire WebPlayer</em> </span>or through a dedicated <span style="color: #250f6b;"><em>Spotfire</em></span> thick client directly from their workstation and access to their report stored in the <span style="color: #250f6b;"><em>Spotfire</em></span> server. Once the reports are opened, they contact the Spotfire Server to retrieve the data and execute the data cleaning script.</p>
<p><strong><span style="text-decoration: underline;">Remote Code Execution</span></strong></p>
<p>The Spotfire allows by design the execution of <span style="color: #250f6b;"><em>R</em></span> script but execution of <span style="color: #250f6b;"><em>Python</em></span> script can be easily enabled by loading the <span style="color: #250f6b;"><em>IronPython</em></span> scripting module.</p>
<p>In any case, users are able to execute scripts directly from the <em><span style="color: #250f6b;">Spotfire WebPlayer</span> </em>or the thick client. However, they are only able to modify or create script from the <span style="color: #250f6b;"><em>Spotfire</em> </span>thick client.</p>
<p>From the thick client, it is possible to create a new project. Inside the project, it is possible to create a <span style="color: #250f6b;"><em>UI</em></span>. Let’s create a webshell <span style="color: #250f6b;"><em>Spotfire</em></span>.</p>
<p>First, we will create the <em><span style="color: #250f6b;">UI</span></em>. It will consist of a <span style="color: #250f6b;"><em>textarea</em> </span>to type the command, another <span style="color: #250f6b;"><em>textarea</em> </span>to display the command result and a button to send the command:</p>
<p><img decoding="async" class="aligncenter size-full wp-image-23663" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_02.jpg" alt="" width="1196" height="758" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_02.jpg 1196w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_02-301x191.jpg 301w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_02-62x39.jpg 62w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_02-768x487.jpg 768w" sizes="(max-width: 1196px) 100vw, 1196px" /></p>
<p style="text-align: center;"><em>Figure 2: Final webshell UI</em></p>
<p>Once the project has been created, we create a new empty page. When an empty page is created, <span style="color: #250f6b;"><em>Spotfire</em></span> asks if we want to start with data, visualization or other:</p>
<p><img decoding="async" class="aligncenter size-full wp-image-23665" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_03.jpg" alt="" width="848" height="524" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_03.jpg 848w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_03-309x191.jpg 309w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_03-63x39.jpg 63w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_03-768x475.jpg 768w" sizes="(max-width: 848px) 100vw, 848px" /></p>
<p style="text-align: center;"><em>Figure 3: Spotfire new page</em></p>
<p>We will choose “<span style="color: #250f6b;"><em>Start from Visualizations</em></span>” and choose the “<em><span style="color: #250f6b;">Text area</span></em>” visualization type. This should show a full blank page:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23667" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_04.jpg" alt="" width="840" height="532" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_04.jpg 840w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_04-302x191.jpg 302w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_04-62x39.jpg 62w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_04-768x486.jpg 768w" sizes="auto, (max-width: 840px) 100vw, 840px" /></p>
<p style="text-align: center;"><em>Figure 4: Spotfire new textarea</em></p>
<p>This <span style="color: #250f6b;"><em>textarea</em> </span>will contain the whole webshell input control. Let’s create another <span style="color: #250f6b;"><em>textarea</em> </span>for the result:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23669" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_05.jpg" alt="" width="953" height="597" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_05.jpg 953w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_05-305x191.jpg 305w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_05-62x39.jpg 62w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_05-768x481.jpg 768w" sizes="auto, (max-width: 953px) 100vw, 953px" /></p>
<p style="text-align: center;"><em>Figure 5: Spotfire second textarea</em></p>
<p>So now, we can click on “<span style="color: #250f6b;"><em>Edit Text Area</em></span>” at the top of the first text area. This will allow the customization of the text area content.</p>
<p>First let’s add an input control that will be used to type the command to send to the server:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23671" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06.jpg" alt="" width="1140" height="666" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06.jpg 1140w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06-327x191.jpg 327w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06-67x39.jpg 67w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06-120x70.jpg 120w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_06-768x449.jpg 768w" sizes="auto, (max-width: 1140px) 100vw, 1140px" /></p>
<p style="text-align: center;"><em>Figure 6: Text area modification</em></p>
<p>We will bind the control value to a document property to be able to use it with our future python script. We can create a new property called <span style="color: #250f6b;"><em>Input</em> </span>with the data type <span style="color: #250f6b;"><em>String</em></span>:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23673" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_07.jpg" alt="" width="629" height="792" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_07.jpg 629w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_07-152x191.jpg 152w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_07-31x39.jpg 31w" sizes="auto, (max-width: 629px) 100vw, 629px" /></p>
<p style="text-align: center;"><em>Figure 7: Bind control to input field</em></p>
<p>Then, let’s create an action control by clicking on the “<span style="color: #250f6b;"><em>Insert Action Control</em></span>” button at the top of the <em><span style="color: #250f6b;">Edit Text Area</span> </em>window. We click on Script and choose the Control type Button. Then we can create a new <span style="color: #250f6b;"><em>IronPython</em> </span>script:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23675" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_08.jpg" alt="" width="826" height="770" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_08.jpg 826w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_08-205x191.jpg 205w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_08-42x39.jpg 42w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_08-768x716.jpg 768w" sizes="auto, (max-width: 826px) 100vw, 826px" /></p>
<p style="text-align: center;"><em>Figure 8: Add button</em></p>
<p>Fill the script content with the following code:</p>
<pre><br /><code>from Spotfire.Dxp.Application.Visuals import *</code><br /><code>from System.IO import *</code><br /><code>from System.Drawing import *</code><br /><code>from System.Drawing.Imaging import *</code><br /><code>from System.Text.RegularExpressions import *</code><br /><code>import subprocess</code><br /><code>vis=visual.As[HtmlTextArea]()</code><br /><code>if 'clean!' in com:</code><br /><code>    vis.HtmlContent = ''</code><br /><code>else:</code><br /><code>    try:</code><br /><code>        vis.HtmlContent = "Executing {}".format(com)</code><br /><code>        process = subprocess.Popen(com.split(" "), stdout=subprocess.PIPE)</code><br /><code>        output, _ = process.communicate()</code><br /><code>        vis.HtmlContent='&lt;br&gt;'.join(output.split('\n'))</code><br /><code>    except Exception as e:</code><br /><code>        vis.HtmlContent="{}".format(e)</code></pre>
<p>This code loads a bunch of <span style="color: #250f6b;"><em>Spotfire</em></span> libraries that are used to communicate with the <span style="color: #250f6b;"><em>UI</em></span>. The “<span style="color: #250f6b;"><em>visual</em></span>” variable represents the text area used to display the result. The “<span style="color: #250f6b;"><em>com</em></span>” variable contains the value of the property bond to our input field created.</p>
<p>The script executes the command stored in the “<span style="color: #250f6b;"><em>com</em></span>” and write the result on the <span style="color: #250f6b;"><em>UI</em></span> element pointed by the “<span style="color: #250f6b;"><em>visual</em></span>” variable.</p>
<p>Now, we have to bind the “<span style="color: #250f6b;"><em>visual</em></span>” and “<span style="color: #250f6b;"><em>com</em></span>” variable to the different project element. In the “<span style="color: #250f6b;"><em>Script parameters</em></span>” table, add a new parameter:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23677" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_09.jpg" alt="" width="532" height="539" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_09.jpg 532w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_09-189x191.jpg 189w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_09-38x39.jpg 38w" sizes="auto, (max-width: 532px) 100vw, 532px" /></p>
<p style="text-align: center;"><em>Figure 9: Bind visual parameter</em></p>
<p>Do the same for the com parameter:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23679" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_10.jpg" alt="" width="623" height="637" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_10.jpg 623w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_10-187x191.jpg 187w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_10-38x39.jpg 38w" sizes="auto, (max-width: 623px) 100vw, 623px" /></p>
<p style="text-align: center;"><em>Figure 10: Bind com parameter</em></p>
<p>So now, when the script is executed, it will automatically bind the visual parameter to the <span style="color: #250f6b;"><em>textarea</em></span> panel used to display the result and the com parameter to the content of the <span style="color: #250f6b;"><em>Input</em> </span>property created when defining the input field.</p>
<p>Let’s save all of this. Congratulations, we have a working webshell:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23681" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_11.jpg" alt="" width="809" height="261" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_11.jpg 809w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_11-437x141.jpg 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_11-71x23.jpg 71w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_11-768x248.jpg 768w" sizes="auto, (max-width: 809px) 100vw, 809px" /></p>
<p style="text-align: center;"><em>Figure 11: Final webshell</em></p>
<p>If executed directly from the thick client, the code will only be executed in local, so this is not really interesting. However, if the code is executed directly from the <span style="color: #250f6b;"><em>Spotfire Webplayer</em></span>, it will be executed on the <span style="color: #250f6b;"><em>Spotfire</em></span> server, leading to a remote code execution on the server.</p>
<p> </p>
<h3><span style="color: #451dc7;">3.2.2. Dataiku</span></h3>
<p>The remote code execution on <span style="color: #250f6b;"><em>Dataiku</em></span> is more straight forward. Indeed, <span style="color: #250f6b;"><em>Dataiku</em></span> directly embeds a <span style="color: #250f6b;"><em>Jupyter</em></span> notebook like features.</p>
<p>By creating a new <span style="color: #250f6b;"><em>Jupyter</em></span> project, it is possible to directly execute command on the server as shown in the following figure:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23683" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_12.png" alt="" width="526" height="228" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_12.png 526w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_12-437x189.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_12-71x31.png 71w" sizes="auto, (max-width: 526px) 100vw, 526px" /></p>
<p style="text-align: center;"><em>Figure 12: Code execution with Dataiku</em></p>
<h3><span style="color: #451dc7;">3.2.3. OPSEC consideration</span></h3>
<p>One can say that spawning python process as a child process for <span style="color: #250f6b;"><em>Spotfire</em></span> or <span style="color: #250f6b;"><em>Dataiku</em></span> will lead to hard detection by <span style="color: #250f6b;"><em>EDR</em></span>. However, we have to keep in mind that spawning a python process is a legit behavior for the <span style="color: #250f6b;"><em>Spotfire</em></span> or <span style="color: #250f6b;"><em>Dataiku</em></span> process.</p>
<p>However, if you start to spawn cmd.exe directly from the python script, yes, this could lead to hard detection. But <span style="color: #250f6b;"><em>python</em></span> is known to be suspicious by default and <span style="color: #250f6b;"><em>EDR</em></span> are a little more relaxed about the actions performed by a python process due to several false positive.</p>
<p>So, in a nutshell, spawning the python process should not lead to any specific detection, but you should be careful on the script you will execute from it.</p>
<h1><span style="color: #451dc7;">4. Credentials harvesting</span></h1>
<p>Having <span style="color: #250f6b;"><em>RCE</em></span> on a server is always nice, but it is better to know what we can do with it. First of all, if you achieved <span style="color: #250f6b;"><em>RCE</em></span> on a domain join computer, you have an authenticated access to the domain, and when you are coming directly from the internet this is the cherry on the cake.</p>
<p>The specificity of <span style="color: #250f6b;"><em>datascience</em></span> applications is that they are connected to <span style="color: #250f6b;"><em>datalake</em></span>. These connections can be standard <span style="color: #250f6b;"><em>SQL</em></span> connection, but they can also be connection to cloud <span style="color: #250f6b;"><em>datalake</em></span> such as <span style="color: #250f6b;"><em>AWS</em></span>.</p>
<p>With an <span style="color: #250f6b;"><em>RCE</em></span> on the server, you can usually access to all the credentials stored in the application.</p>
<h2><span style="color: #451dc7;">4.1. Example with Dataiku</span></h2>
<p>On <span style="color: #250f6b;"><em>Dataiku</em></span>, the secrets are stored in the <span style="color: #250f6b;"><em>DATA_DIR/config directory</em></span>:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23685" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_13.png" alt="" width="607" height="203" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_13.png 607w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_13-437x146.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_13-71x24.png 71w" sizes="auto, (max-width: 607px) 100vw, 607px" /></p>
<p style="text-align: center;"><em>Figure 13: Configuration file for dataiku</em></p>
<p>The <span style="color: #250f6b;"><em>users.json</em> </span>contains the user database for <span style="color: #250f6b;"><em>dataiku</em></span>. You can use it to create a new administrator user and keep persistence on the environment.</p>
<p>The <span style="color: #250f6b;"><em>connections.json</em> </span>file contains all the credentials to access to the <span style="color: #250f6b;"><em>datalakes</em></span>. However, the passwords are stored encrypted:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23687" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_14.png" alt="" width="488" height="209" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_14.png 488w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_14-437x187.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_14-71x30.png 71w" sizes="auto, (max-width: 488px) 100vw, 488px" /></p>
<p style="text-align: center;"><em>Figure 14: Password stored encrypted</em></p>
<p>Hopefully, <span style="color: #250f6b;"><em>Dataiku</em></span> provides a tool to decrypt these credentials:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23689" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_15.png" alt="" width="575" height="76" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_15.png 575w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_15-437x58.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_15-71x9.png 71w" sizes="auto, (max-width: 575px) 100vw, 575px" /></p>
<p style="text-align: center;"><em>Figure 15: Password decryption on Dataiku</em></p>
<p>You can now use these credentials to jump on the remote database or directly on the cloud if they use <span style="color: #250f6b;"><em>AWS Datalake</em> </span>or <span style="color: #250f6b;"><em>AWS</em></span> stored databases.</p>
<p>Finally, the <span style="color: #250f6b;"><em>dataiku</em></span> account that is used to run the <span style="color: #250f6b;"><em>Dataiku</em></span> instance has all privileges on the <span style="color: #250f6b;"><em>Dataiku</em></span> instance data. You can then just retrieve all project data.</p>
<p> </p>
<h1><span style="color: #451dc7;">5. Spread among the users</span></h1>
<p>This part only applies to <span style="color: #250f6b;"><em>Spotfire</em></span> as <span style="color: #250f6b;"><em>Dataiku</em></span> does not provides thick client and this exploitation relies on the fact that user will execute code on their workstation and not on the remote server.</p>
<p> </p>
<h2><span style="color: #451dc7;">5.1. Infect other users</span></h2>
<p>Scripts embedded in analysis must be trusted in order to be executed by other users. This trust process is performed through <span style="color: #250f6b;"><em>Spotfire</em></span> users with specific rights. With remote code execution on the Spotfire instance, it is possible to directly create a new administrator user. However, due to the unsecured management on users by the business teams, all users usually have the privileges to trust the scripts.</p>
<p>In order to compromise the users, the <span style="color: #250f6b;"><em>Spotfire</em></span> application can be <strong><span style="color: #451dc7;">weaponized as a command-and-control infrastructure</span></strong><em>.</em></p>
<p>When the user opens an analysis file from his thick client, the file is locally downloaded, and all scripts contained on the project are executed locally on the user workstation.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23691" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_16.png" alt="" width="947" height="725" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_16.png 947w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_16-249x191.png 249w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_16-51x39.png 51w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_16-768x588.png 768w" sizes="auto, (max-width: 947px) 100vw, 947px" /></p>
<p style="text-align: center;"><em>Figure 16: Macro view of the Spotfire C2 infrastructure</em></p>
<p>This analysis sheet has been <span style="color: #451dc7;"><strong>weaponized through a JS script</strong></span>. When opened by the user, the <span style="color: #250f6b;"><em>JavaScript</em></span> code will be executed leading to the execution of a final python script containing the <span style="color: #250f6b;"><em>C2</em></span> beacon.</p>
<p>This can be done by adding in any page of the project a new button that will trigger the <span style="color: #250f6b;">C2</span> python runtime. The button can be configured to have a <span style="color: #250f6b;"><em>1px</em></span> size, making it invisible. Then a <span style="color: #250f6b;"><em>JS</em></span> script can be added to automatically click on the button on a regular basis (every <span style="color: #250f6b;"><em>30</em></span> seconds for example).</p>
<p>As long as the analysis file is opened, the <span style="color: #250f6b;"><em>JavaScript</em></span> code will call the <span style="color: #250f6b;"><em>C2</em></span> python script every <span style="color: #250f6b;"><em>30</em></span> seconds allowing execution of<span style="color: #451dc7;"><strong> arbitrary python script and OS command on the user computer</strong></span><em>.</em></p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23693" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_17.png" alt="" width="947" height="693" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_17.png 947w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_17-261x191.png 261w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_17-53x39.png 53w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_17-768x562.png 768w" sizes="auto, (max-width: 947px) 100vw, 947px" /></p>
<p style="text-align: center;"><em>Figure 17: Low-level view of the infected analysis file</em></p>
<p>The only limitation is that the <span style="color: #250f6b;"><em>JS</em></span> will only be triggered if the user opens the specific infected page. This can be bypassed<span style="color: #451dc7;"><strong> by redirecting the user to the malicious analysis page </strong></span>when he opens it.</p>
<p>When the user opens the infected analysis, it <span style="color: #451dc7;"><strong>will automatically trigger a data function (which is different from a script)</strong></span>.</p>
<p>The <span style="color: #250f6b;"><em>datafunction</em></span> are functions executed when the project is opened. However, their subset of features is limited. They cannot run important <span style="color: #250f6b;"><em>python</em></span> script on a regular basis.</p>
<p>This data function is configured to <span style="color: #451dc7;"><strong>update a random document property</strong></span>. <span style="color: #250f6b;"><em>Spotfire</em> </span>allows setting up some script hook on properties changed. So, when the property is changed by the data function, <span style="color: #451dc7;"><strong>it will trigger an IronPython script that will display a specific analysis sheet to the user</strong></span><em>. </em></p>
<p> </p>
<p>Once the infected analysis sheet is focused, it will start the python <span style="color: #250f6b;"><em>C2</em></span> beacon on a regular basis through the <span style="color: #250f6b;">JS</span> script as explained before:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23695" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_18.png" alt="" width="947" height="693" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_18.png 947w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_18-261x191.png 261w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_18-53x39.png 53w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_18-768x562.png 768w" sizes="auto, (max-width: 947px) 100vw, 947px" /></p>
<p style="text-align: center;"><em>Figure 18: C2 auto run process</em></p>
<p>When this <span style="color: #250f6b;"><em>C2</em></span> is deployed, it <span style="color: #451dc7;"><strong>will stay alive as long as the infected analysis stay open </strong></span>on the user’s workstation.</p>
<p>The following figure shows the compromise of a user workstation and the execution of a remote python script fetched by the python beacon:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23697" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_19.png" alt="" width="964" height="429" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_19.png 964w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_19-429x191.png 429w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_19-71x32.png 71w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_19-768x342.png 768w" sizes="auto, (max-width: 964px) 100vw, 964px" /></p>
<p style="text-align: center;"><em>Figure 19: Command execution on the user workstation</em></p>
<p>In order to compromise as many users as possible, it is possible to infect several projects and wait that users click on them.</p>
<p>Usually, companies have specific project templates store somewhere on the Spotfire server. If you find them, you will automatically infect all project based on this template.</p>
<h2><span style="color: #451dc7;">5.2. Extend compromise time</span></h2>
<p>This <span style="color: #250f6b;"><em>C2</em></span> process is interesting but <span style="color: #451dc7;"><strong>ends when the user closes the infected analysis</strong></span><em>.</em> In order to have a more persistent access to the user computer, the <span style="color: #250f6b;"><em>C2</em> </span>process is <span style="color: #451dc7;"><strong>migrated from Spotfire to another python instance </strong></span>on the user computer.</p>
<p>Indeed, when <span style="color: #250f6b;"><em>Spotfire</em></span> is installed, it also installs a raw <span style="color: #250f6b;"><em>python</em></span> interpreter. Through the initial <span style="color: #250f6b;"><em>C2</em></span>, it is possible, through <span style="color: #250f6b;"><em>OS</em></span> command execution, to write another <span style="color: #250f6b;"><em>C2</em></span> beacon on the user filesystem and <strong><span style="color: #451dc7;">trigger its execution by the raw python interpreter</span></strong>.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23699" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_20.png" alt="" width="947" height="520" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_20.png 947w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_20-348x191.png 348w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_20-71x39.png 71w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_20-768x422.png 768w" sizes="auto, (max-width: 947px) 100vw, 947px" /></p>
<p style="text-align: center;"><em>Figure 20: C2 without Spotfire restrictions</em></p>
<p>This time, even if the infected analysis is closed, <span style="color: #451dc7;"><strong>the python process will not be killed</strong> </span>as it is not related to <span style="color: #250f6b;"><em>Spotfire</em></span> anymore, <span style="color: #451dc7;"><strong>granting the attacker persistent access to the user computer </strong></span>as long as no reboot is performed.</p>
<p> </p>
<h2><span style="color: #451dc7;">5.3. Access persistency</span></h2>
<h3><span style="color: #451dc7;">5.3.1. DLL Hijacking</span></h3>
<p>Through the <span style="color: #250f6b;"><em>C2</em></span> beacon it is possible to spawn an <span style="color: #250f6b;"><em>SSH</em></span> reverse socks. The reverse <span style="color: #250f6b;"><em>SSH</em></span> socks is enough to access to the internal network, however, it <strong><span style="color: #451dc7;">will be killed when the user computer is shut down </span></strong>and will not be remounted until the user re-open an infected analysis and trigger again the <span style="color: #250f6b;"><em>C2</em></span> beacon execution.</p>
<p>In order to <span style="color: #451dc7;"><strong>get persistence and ensure that the socks will be remounted </strong></span>even if the user computer is rebooted, some <span style="color: #451dc7;"><strong>modification on application files can be performed </strong></span>on the user workstation.</p>
<p>The users compromised through the <span style="color: #250f6b;"><em>Spotfire</em></span> beacon are data analysts and <span style="color: #250f6b;"><em>Spotfire</em></span> is their main tools and more likely <em>the </em><span style="color: #451dc7;"><strong>first application they run when they turn on their computer</strong></span>.</p>
<p>The <span style="color: #250f6b;"><em>Spotfire</em></span> thick client is developed in <span style="color: #250f6b;">C#</span>. Its <span style="color: #250f6b;"><em>DLLs</em> </span>can be easily reversed, and they are stored in the user <em><span style="color: #250f6b;">APPDATA</span> </em>folder. Thus, with a simple access to the user session, it is possible to modify these <span style="color: #250f6b;"><em>DLL</em> </span>without needing specific privilege escalation. Using the <span style="color: #250f6b;"><em>SysInternals</em> <em>Procmon.exe</em></span>, the list of <span style="color: #250f6b;"><em>DLL</em> </span>loaded by <span style="color: #250f6b;"><em>Spotfire</em></span> is found. Then, one of this <span style="color: #250f6b;"><em>DLL</em></span> is reversed engineered and infected as shown in the following figure:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23701" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_21.png" alt="" width="576" height="290" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_21.png 576w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_21-379x191.png 379w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_21-71x36.png 71w" sizes="auto, (max-width: 576px) 100vw, 576px" /></p>
<p style="text-align: center;"><em>Figure 21: DNSpy showing the modified DLL</em></p>
<p>The malicious code injected will <span style="color: #451dc7;"><strong>create a new SSH process mounting a new SSH reverse socks </strong></span>when Spotfire is started.</p>
<p>The <span style="color: #250f6b;"><em>DLL</em></span> is recompiled and uploaded on every compromised user workstation and the <span style="color: #250f6b;"><em>C2</em></span> beacon is modified to execute this action when it detects a new user callback.</p>
<h3><span style="color: #451dc7;">5.3.2. OPSEC consideration</span></h3>
<p>While looking like <span style="color: #250f6b;"><em>DLL</em></span> hijacking, this technique is hardly detectable by an <span style="color: #250f6b;"><em>EDR</em> </span>as the original <span style="color: #250f6b;"><em>DLL</em> </span>has not been swapped by a malicious one as in <span style="color: #250f6b;"><em>DLL</em> <em>Hijacking</em></span> or <span style="color: #250f6b;"><em>DLL</em> <em>Proxying</em></span>. The <span style="color: #250f6b;"><em>DLL</em></span> executed by <span style="color: #250f6b;"><em>Spotfire</em></span> is the original one re-compiled with an additional code spawning a new process.</p>
<p>As the original <span style="color: #250f6b;"><em>Spotfire</em> <em>DLL</em> </span>is not signed, the <span style="color: #250f6b;"><em>EDR</em> </span>cannot detect the modification.</p>
<h3><span style="color: #451dc7;">5.3.3. Resiliency</span></h3>
<p>To avoid being blocked through a firewall rule if the socks <span style="color: #250f6b;"><em>IP</em> </span>is blacklisted, the malicious code implanted in the <span style="color: #250f6b;"><em>Spotfire DLL</em> </span>does not contain a hardcoded remote <span style="color: #250f6b;"><em>IP</em></span>, port and <span style="color: #250f6b;"><em>SSH</em> </span>key, instead, each time it fetches this information from a different remote server.</p>
<p>So even if the <span style="color: #250f6b;"><em>SOC</em> </span>blacklist the <span style="color: #250f6b;"><em>SOCKS IP</em></span>, it is possible to remotely change the <span style="color: #250f6b;"><em>SOCKS </em></span>destination <span style="color: #250f6b;"><em>IP</em> </span>without needing direct access to the compromised users’ computers.</p>
<h1><span style="color: #451dc7;">6. Hide in plain sight</span></h1>
<p>The <em><span style="color: #250f6b;">Dataiku</span> </em>application can be used to masquerade malicious command execution and make it look like performed by another user.</p>
<h2><span style="color: #451dc7;">6.1. Jupyter integration in Dataiku</span></h2>
<p>As said before, the <span style="color: #250f6b;"><em>Dataiku</em></span> exposes a <span style="color: #250f6b;"><em>Jupyter</em></span>-like application. Looking at the <span style="color: #250f6b;"><em>Dataiku</em></span> code and the different process run by the <span style="color: #250f6b;"><em>DSS</em></span> instance, it shows that <span style="color: #250f6b;"><em>Dataiku</em></span> didn’t redevelop a <span style="color: #250f6b;"><em>Jupyter</em></span> like applications <span style="color: #451dc7;"><strong>but simply run a full Jupyter Notebook instance in the background</strong></span>:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23703" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_22.png" alt="" width="599" height="248" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_22.png 599w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_22-437x181.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_22-71x29.png 71w" sizes="auto, (max-width: 599px) 100vw, 599px" /></p>
<p style="text-align: center;"><em>Figure 22: Jupyter server running on port 11002</em></p>
<p>Using a simple port forwarding grant access to the <span style="color: #250f6b;"><em>Jupyter</em></span> instance:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23705" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_23.png" alt="" width="545" height="161" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_23.png 545w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_23-437x129.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_23-71x21.png 71w" sizes="auto, (max-width: 545px) 100vw, 545px" /></p>
<p style="text-align: center;"><em>Figure 23: Jupyter instance</em></p>
<p>When executing a <span style="color: #250f6b;"><em>Jupyter</em></span> cell, it is possible, by performing a network capture, to see the <span style="color: #250f6b;"><em>TCP</em></span> communication between the Dataiku instance and the <span style="color: #250f6b;"><em>Jupyter</em></span> backend:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23707" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_24.png" alt="" width="873" height="204" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_24.png 873w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_24-437x102.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_24-71x17.png 71w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_24-768x179.png 768w" sizes="auto, (max-width: 873px) 100vw, 873px" /></p>
<p style="text-align: center;"><em>Figure 24: TCP packet</em></p>
<p>This shows that the Dataiku instance fully exposes the <span style="color: #250f6b;"><em>Jupyter kernel</em> </span>and additional investigation shows that the <span style="color: #250f6b;"><em>API TOKEN</em> </span>used by <span style="color: #250f6b;"><em>Dataiku</em></span> to communicate with the <span style="color: #250f6b;"><em>Jupyter</em></span> backend is the same whatever the <span style="color: #250f6b;"><em>Jupyter Notebook</em> </span>loaded.</p>
<p>Thus, any user with access to the <span style="color: #250f6b;"><em>Jupyter Notebook</em> </span>feature <span style="color: #451dc7;"><strong>is able to execute code on any Jupyter Kernel loaded</strong> </span>as long as it has the <span style="color: #250f6b;"><em>kernel ID</em></span>. Hopefully, the kernels ids are shown in the process command lines. Thus, the following code can be used to retrieve all kernel id:</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-23709" src="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_25.png" alt="" width="645" height="115" srcset="https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_25.png 645w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_25-437x78.png 437w, https://www.riskinsight-wavestone.com/wp-content/uploads/2024/07/Figure_25-71x13.png 71w" sizes="auto, (max-width: 645px) 100vw, 645px" /></p>
<p style="text-align: center;"><em>Figure 25: Kernel ID retrieval</em></p>
<p> </p>
<h2>6.2. Hide request execution</h2>
<p>Once the kernel id is retrieved, it is <span style="color: #451dc7;"><strong>possible to create a session on the kernel</strong></span>:</p>
<pre><code>GET /jupyter/api/kernels/0ab25b8f-1714-4bc9-8449-c09faf5c2e29/channels?session_id=c8c6a227ea3c465c82e39c403ba705a18 HTTP/1.1</code><br /><code>Host: 10.125.3.111:11000</code><br /><code>&lt;SNIP&gt;</code><br /><code>Origin: http://10.125.3.111:11000</code><br /><code>Sec-WebSocket-Key: obLqAtXNc/KxMJOp27qxIQ==</code><br /><code>Connection: keep-alive, Upgrade</code><br /><code>Cookie: &lt;SNIP&gt;</code><br /><code>Pragma: no-cache</code><br /><code>Cache-Control: no-cache</code><br /><code>Upgrade: websocket</code></pre>
<p>This request will create a websocket to communicate with the <em>Jupyter</em> kernel. <strong><span style="color: #451dc7;">No specific access control is performed on this endpoint</span></strong>. As long as you are authorized to execute any <span style="color: #250f6b;"><em>Jupyter</em> </span>notebook, you can connect to any <span style="color: #250f6b;"><em>Jupyter</em></span> kernel even if you cannot access to the notebook using the <span style="color: #250f6b;"><em>UI</em></span> interface.</p>
<p>It is then possible to use the websocket to send command to execute to the python kernel:</p>
<pre><code>{</code><br /><code>  "header": {</code><br /><code>    "msg_id": "ef46ce660d49457c890ce550420ed921",</code><br /><code>    "username": "username",</code><br /><code>    "session": "f4fe997b336f4a019c4c6837df699d30",</code><br /><code>    "msg_type": "execute_request",</code><br /><code>    "version": "5.2"</code><br /><code>  },</code><br /><code>  "metadata": {},</code><br /><code>  "content": {</code><br /><code>    "code": "print('test')",</code><br /><code>    "silent": false,</code><br /><code>    "store_history": true,</code><br /><code>    "user_expressions": {},</code><br /><code>    "allow_stdin": true,</code><br /><code>    "stop_on_error": true</code><br /><code>  },</code><br /><code>  "buffers": [],</code><br /><code>  "parent_header": {},</code><br /><code>  "channel": "shell"</code><br /><code>}</code></pre>
<p>What is interesting is that the command is executed, <strong><span style="color: #451dc7;">but not saved in any Jupyter cell leading to invisible command execution </span></strong>as long as the kernel is alive.</p>
<p>Moreover, if you modify the value of a specific variable, it will be persistent. So, if you send the python command:</p>
<pre><code>def hijacked_print(value):</code><br /><code>    import sys</code><br /><code>    process = subprocess.Popen(‘YOUR BEACON’, stdout=subprocess.PIPE, shell=False)</code><br /><code>    sys.stdout.write('hijacked print: {}'.format(value))</code><br /><br /><code>print = hijacked_print</code></pre>
<p>The beacon will be executed when a user uses the print command and because the previous python execution didn’t let any trace behind, good luck to detect it and find which user has been compromised.</p>
<h1><span style="color: #451dc7;">7. Conclusion</span></h1>
<p>The datascience applications <span style="color: #451dc7;"><strong>are useful in any step of the killchain</strong></span>. For a remote attacker, they can be used as an initial entry point on the information system, they can be leveraged to find insecurely stored credentials to rebound on the information system, their scripting capabilities can be used to <span style="color: #451dc7;"><strong>spread malicious beacon among several users </strong></span>and the data they contain can be easily stolen and exfiltrated.</p>
<p>These applications <span style="color: #451dc7;"><strong>are undercut by either attackers or IT department</strong></span>. A simple compromise of one of these applications can lead to a huge impact on the whole information system.</p>
<p>It is time to for the infosec to start integrating buzzword as BigData and machine learning in the killchain, attacker already did it&#8230;</p>
<p>Cet article <a href="https://www.riskinsight-wavestone.com/en/2024/07/datascience-for-redteam-extend-your-attack-surface/">DataScience for RedTeam: Extend your attack surface</a> est apparu en premier sur <a href="https://www.riskinsight-wavestone.com/en/">RiskInsight</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.riskinsight-wavestone.com/en/2024/07/datascience-for-redteam-extend-your-attack-surface/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
