Mirai_ptea Botnet is Exploiting Undisclosed KGUARD DVR Vulnerability
<!--kg-card-begin: markdown--><h1 id="overview">Overview</h1>
<p>On 2021-06-22 we detected a sample of a mirai variant that we named <code>mirai_ptea</code> propagating through a new vulnerability targeting <a href="https://www.kguard.com.tw/">KGUARD DVR</a>. Coincidently, a day later, on June 23, we received an inquiry from the security community asking if we had seen a new DDoS botnet, cross-referencing some data, it was exactly this botnet that we had just discovered.</p>
<h3 id="timeline">Timeline</h3>
<ul>
<li>2021-03-22 Our historical data indicates the first probe against this vulnerability</li>
<li>2021-06-22 We observed the <code>mirai_ptea</code> sample exploiting this vulnerability to spread</li>
<li>2021-06-23 We got a tip from the security community that this botnet was being used for ongoing DDoS attacks.</li>
<li>2021-06-25 <code>mirai_aurora</code>, another mirai variant, starts to use this vulnerability to propagate</li>
</ul>
<h1 id="vulnerabilityanalysis">Vulnerability analysis</h1>
<p>Given that we have not found public information on this vulnerability, we will hide some of the key information here to prevent the vulnerability from being further abused.</p>
<p>One program on the KGUARD DVR firmware listens on port <code>*****</code> at <code>0.0.0.0</code> to remotely execute system commands without authentication. The firmware released after 2017 seems to have this fixed by modifying the listening address to <code>127.0.0.1</code>. Some of the exploited payloads are as follows.<br>
<img src="__GHOST_URL__/content/images/2021/07/mirai_ptea_xx_exp_p.png" alt="mirai_ptea_xx_exp_p" loading="lazy"></p>
<h3 id="analysisofaffecteddevices">Analysis of affected devices</h3>
<p>We have discovered at least 3,000 or so online devices still have the vulnerability. The affected devices are as follows:</p>
<table>
<thead>
<tr>
<th>DeviceType</th>
<th>ProductType</th>
<th>HardVersion</th>
<th>DefDeviceName</th>
</tr>
</thead>
<tbody>
<tr>
<td>D1004NR</td>
<td>DVR4-1600</td>
<td>DM-268A</td>
<td>DVR4-1600</td>
</tr>
<tr>
<td>D1004NR</td>
<td>HY-DVR</td>
<td>DM-268</td>
<td>720P-HY04N</td>
</tr>
<tr>
<td>D1004NR</td>
<td>HY-DVR</td>
<td>DM-268A</td>
<td>720P-HY04N</td>
</tr>
<tr>
<td>D1004NR</td>
<td>HY-DVR</td>
<td>DM-274</td>
<td>720P-HY04N</td>
</tr>
<tr>
<td>D1004NR</td>
<td>HY-DVR</td>
<td>DM-274B</td>
<td>720P-HY04N</td>
</tr>
<tr>
<td>D1004NR</td>
<td>NHDR</td>
<td>DM-274</td>
<td>NHDR-3204AHD</td>
</tr>
<tr>
<td>D1004NR</td>
<td>RL-AHD4n</td>
<td>DM-268</td>
<td>720P-HY04N</td>
</tr>
<tr>
<td>D1008NR</td>
<td>1093/508N-DVRBM08H</td>
<td>DM-292</td>
<td>720P-HY08N</td>
</tr>
<tr>
<td>D1008NR</td>
<td>DVR8-1600</td>
<td>DM-298</td>
<td>DVR8-1600</td>
</tr>
<tr>
<td>D1008NR</td>
<td>DVR8-HDA10L</td>
<td>DM-292</td>
<td>DVR8-HDA10L</td>
</tr>
<tr>
<td>D1008NR</td>
<td>HD881</td>
<td>DM-292</td>
<td>HD881</td>
</tr>
<tr>
<td>D1008NR</td>
<td>HY-DVR</td>
<td>DM-292</td>
<td>720P-HY08N</td>
</tr>
<tr>
<td>D1008NR</td>
<td>HY-DVR</td>
<td>DM-298</td>
<td>720P-HY08N</td>
</tr>
<tr>
<td>D1008NR</td>
<td>NHDR</td>
<td>DM-298</td>
<td>NHDR-3208AHD</td>
</tr>
<tr>
<td>D1008NR</td>
<td>RL-AHD8n</td>
<td>DM-292</td>
<td>720P-HY08N</td>
</tr>
<tr>
<td>D1016NR</td>
<td>DVR16-HDA10L</td>
<td>DM-303</td>
<td>DVR16-HDA10L</td>
</tr>
<tr>
<td>D1016NR</td>
<td>HD1681</td>
<td>DM-303</td>
<td>HD1681</td>
</tr>
<tr>
<td>D1016NR</td>
<td>HY-DVR</td>
<td>DM-303A</td>
<td>720P-HY16N</td>
</tr>
<tr>
<td>D1016NR</td>
<td>HY-DVR</td>
<td>DM-310</td>
<td>720P-HY16N</td>
</tr>
<tr>
<td>D1016NR</td>
<td>HY-DVR</td>
<td>DM-310A</td>
<td>720P-HY16N</td>
</tr>
<tr>
<td>D1016NR</td>
<td>NHDR</td>
<td>DM-310</td>
<td>NHDR-3216AHD</td>
</tr>
<tr>
<td>D1016NR</td>
<td>RL-MHD16n(21A)</td>
<td>DM-310A</td>
<td>720P-HY16N</td>
</tr>
<tr>
<td>D1104</td>
<td>HY-DVR</td>
<td>DM-290A</td>
<td>1080P-HY04</td>
</tr>
<tr>
<td>D1104</td>
<td>NHDR</td>
<td>DM-307</td>
<td>NHDR-5304AHD</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HD1T4</td>
<td>DM-291A</td>
<td>1080P-04</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HD481</td>
<td>DM-291</td>
<td>HD481</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HRD-E430L</td>
<td>DM-291A</td>
<td>HRD-E430L</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HY-DVR</td>
<td>DM-284</td>
<td>1080P-HY04N</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HY-DVR</td>
<td>DM-291</td>
<td>&quot;Panda</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HY-DVR</td>
<td>DM-291</td>
<td>1080P-HY04N</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HY-DVR</td>
<td>DM-291A</td>
<td>1080P-HY04N</td>
</tr>
<tr>
<td>D1104NR</td>
<td>HY-DVR</td>
<td>DM-291C</td>
<td>LRA3040N</td>
</tr>
<tr>
<td>D1104NR</td>
<td>NHDR</td>
<td>DM-307</td>
<td>NHDR-5104AHD</td>
</tr>
<tr>
<td>D1104NR</td>
<td>SDR-B73303</td>
<td>DM-291A</td>
<td>SDR-B73303</td>
</tr>
<tr>
<td>D1104NR</td>
<td>SVR9204H</td>
<td>DM-291A</td>
<td>1080P-HY04N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>1093/538P</td>
<td>DM-290</td>
<td>1080P-HY08N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>DVR8-4575</td>
<td>DM-290</td>
<td>DVR8-4575</td>
</tr>
<tr>
<td>D1108NR</td>
<td>DVR8-HDA10P</td>
<td>DM-290</td>
<td>DVR8-HDA10P</td>
</tr>
<tr>
<td>D1108NR</td>
<td>HRD-E830L</td>
<td>DM-290A</td>
<td>HRD-E830L</td>
</tr>
<tr>
<td>D1108NR</td>
<td>HY-DVR</td>
<td>DM-290</td>
<td>1080P-HY08N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>HY-DVR</td>
<td>DM-290A</td>
<td>1080P-HY08N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>HY-DVR</td>
<td>DM-290A</td>
<td>LRA3080N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>NHDR</td>
<td>DM-307</td>
<td>NHDR-5108AHD</td>
</tr>
<tr>
<td>D1108NR</td>
<td>RL-AHD8p</td>
<td>DM-290</td>
<td>1080P-HY08N</td>
</tr>
<tr>
<td>D1108NR</td>
<td>SDR-B74301</td>
<td>DM-290A</td>
<td>SDR-B74301</td>
</tr>
<tr>
<td>D1108NR</td>
<td>SDR-B74303</td>
<td>DM-290A</td>
<td>SDR-B74303</td>
</tr>
<tr>
<td>D1116</td>
<td>HY-DVR</td>
<td>DM-300</td>
<td>EHR-5164</td>
</tr>
<tr>
<td>D1116NR</td>
<td>HRD-E1630L</td>
<td>DM-295</td>
<td>HRD-E1630L</td>
</tr>
<tr>
<td>D1116NR</td>
<td>HY-DVR</td>
<td>DM-295</td>
<td>1080P-HY16N</td>
</tr>
<tr>
<td>D1116NR</td>
<td>HY-DVR</td>
<td>DM-295</td>
<td>LRA3160N</td>
</tr>
<tr>
<td>D1116NR</td>
<td>HY-DVR</td>
<td>DM-299</td>
<td>1080P-HY16N</td>
</tr>
<tr>
<td>D1116NR</td>
<td>SDR-B75303</td>
<td>DM-295</td>
<td>SDR-B75303</td>
</tr>
<tr>
<td>D1132NR</td>
<td>HY-DVR</td>
<td>DM-300</td>
<td>1080P-HY32</td>
</tr>
<tr>
<td>D2116NR</td>
<td>SDR-B85300</td>
<td>DM-300</td>
<td>SDR-B85300</td>
</tr>
<tr>
<td>D973215U</td>
<td>F9-DVR32</td>
<td>DM-195</td>
<td>F9-DVR32</td>
</tr>
<tr>
<td>D9804AHD</td>
<td>DVR</td>
<td>DM-210</td>
<td>391115</td>
</tr>
<tr>
<td>D9804NAHD</td>
<td>AHD7-DVR4</td>
<td>DM-239</td>
<td>AHD7-DVR4</td>
</tr>
<tr>
<td>D9804NAHD</td>
<td>DVR</td>
<td>DM-239</td>
<td>720P-DVR04ND</td>
</tr>
<tr>
<td>D9804NAHD</td>
<td>NHDR</td>
<td>DM-239</td>
<td>NHDR-3104AHD-II</td>
</tr>
<tr>
<td>D9808NRAHD</td>
<td>AHD7-DVR8</td>
<td>DM-228</td>
<td>AHD7-DVR8</td>
</tr>
<tr>
<td>D9808NRAHD</td>
<td>DVR</td>
<td>DM-228</td>
<td></td>
</tr>
<tr>
<td>D9808NRAHD</td>
<td>DVR</td>
<td>DM-228</td>
<td>391116</td>
</tr>
<tr>
<td>D9808NRAHD</td>
<td>NHDR</td>
<td>DM-228</td>
<td>NHDR-3108AHD-II</td>
</tr>
<tr>
<td>D9808NRAHD</td>
<td>NHDR</td>
<td>DM-228</td>
<td>NHDR3108AHDII</td>
</tr>
<tr>
<td>D9816NAHD</td>
<td>DVR</td>
<td>DM-233</td>
<td>720P-DVR016N</td>
</tr>
<tr>
<td>D9816NAHD</td>
<td>NHDR</td>
<td>DM-233</td>
<td>NHDR3116AHDII</td>
</tr>
<tr>
<td>D9816NRAHD</td>
<td>AHD7-DVR16</td>
<td>DM-229</td>
<td>AHD7-DVR16</td>
</tr>
<tr>
<td>D9816NRAHD</td>
<td>DVR</td>
<td>DM-229</td>
<td>720P-DVR016NB</td>
</tr>
<tr>
<td>D9904</td>
<td>D9904</td>
<td>DM-237</td>
<td>1080P-DVR04</td>
</tr>
<tr>
<td>D9904</td>
<td>DVR</td>
<td>DM-237</td>
<td>1080P-DVR04</td>
</tr>
<tr>
<td>D9904</td>
<td>NHDR</td>
<td>DM-237</td>
<td>NHDR-5204AHD</td>
</tr>
<tr>
<td>D9904NR</td>
<td>DVR</td>
<td>DM-244</td>
<td>1080P-DVR04N</td>
</tr>
<tr>
<td>D9904NR</td>
<td>DVR</td>
<td>DM-244</td>
<td>BCS-VAVR0401M</td>
</tr>
<tr>
<td>D9904NR</td>
<td>HY-DVR</td>
<td>DM-244</td>
<td>CVD-AF04S</td>
</tr>
<tr>
<td>D9904NR</td>
<td>N420</td>
<td>DM-244</td>
<td>1080P-DVR04N</td>
</tr>
<tr>
<td>D9904NR</td>
<td>NHDR</td>
<td>DM-244</td>
<td>NHDR-5004AHD-II</td>
</tr>
<tr>
<td>D9904NR</td>
<td>NHDR</td>
<td>DM-244</td>
<td>NHDR5004AHDII</td>
</tr>
<tr>
<td>D9908</td>
<td>DVR</td>
<td>DM-245</td>
<td>BCS-VAVR0802Q</td>
</tr>
<tr>
<td>D9908</td>
<td>NHDR</td>
<td>DM-245</td>
<td>NHDR-5208AHD</td>
</tr>
<tr>
<td>D9908AHD</td>
<td>DVR</td>
<td>DM-246</td>
<td>1080P-DVR08A</td>
</tr>
<tr>
<td>D9908NR</td>
<td>AHD10-DVR8</td>
<td>DM-237</td>
<td>AHD10-DVR8</td>
</tr>
<tr>
<td>D9908NR</td>
<td>DVR</td>
<td>DM-237</td>
<td>1080P-DVR08N</td>
</tr>
<tr>
<td>D9908NR</td>
<td>DVR</td>
<td>DM-237</td>
<td>SVR9008ATHD/C</td>
</tr>
<tr>
<td>D9908NR</td>
<td>HY-DVR</td>
<td>DM-237</td>
<td>CVD-AF08S</td>
</tr>
<tr>
<td>D9908NR</td>
<td>N820</td>
<td>DM-237</td>
<td>1080P-DVR08N</td>
</tr>
<tr>
<td>D9908NR</td>
<td>NHDR</td>
<td>DM-237</td>
<td>NHDR-5008AHD-II</td>
</tr>
<tr>
<td>D9916NR</td>
<td>DVR</td>
<td>DM-245</td>
<td>1080P-DVR016NAT;UI</td>
</tr>
<tr>
<td>D9916NR</td>
<td>DVR</td>
<td>DM-245</td>
<td>HR-31-211620;UI</td>
</tr>
<tr>
<td>D9916NR</td>
<td>HY-DVR</td>
<td>DM-245</td>
<td>CVD-AF16S</td>
</tr>
<tr>
<td>D9916NR</td>
<td>NHDR</td>
<td>DM-245</td>
<td>NHDR-5016AHD-II</td>
</tr>
<tr>
<td>D9916NRAHD</td>
<td>DVR</td>
<td>DM-246</td>
<td>1080P-DVR016NA</td>
</tr>
<tr>
<td>D9916NRAHD</td>
<td>N1620</td>
<td>DM-246</td>
<td>1080P-DVR016NA</td>
</tr>
<tr>
<td>H1104W</td>
<td>SNR-73200W</td>
<td>DM-339</td>
<td>SNR-73200W</td>
</tr>
<tr>
<td>H1106W</td>
<td>LHB806</td>
<td>DM-291B</td>
<td>LHB806</td>
</tr>
<tr>
<td>H1106W</td>
<td>LHB906</td>
<td>DM-291B</td>
<td>LHB906</td>
</tr>
</tbody>
</table>
<h1 id="botscaleanalysis">Bot scale analysis</h1>
<p>We are able to see a portion of the infected bots, the following is a daily active trend：</p>
<p><img src="__GHOST_URL__/content/images/2021/06/Snip202110630_10.png" alt="Snip202110630_10" loading="lazy"></p>
<p>The geographic distribution of Bot source IPs is as follows, mainly concentrated in the United States, Korea and Brazi：<br>
<img src="__GHOST_URL__/content/images/2021/06/Snip20210629_1.png" alt="Snip20210629_1" loading="lazy"></p>
<h1 id="sampleanalysis">Sample Analysis</h1>
<p>Let’s take a look a the the following samples</p>
<pre><code>Verdict:mirai_ptea
MD5:c6ef442bc804fc5290d3617056492d4b
ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped 
Packer:No
Lib:uclibc
</code></pre>
<p><code>c6ef442bc804fc5290d3617056492d4b</code> is a variant of Mirai, which we call <code>Mirai_ptea</code> based on its use of Tor Proxy to communicate with C2 and the TEA algorithm (Tiny Encryption Algorithm) to hide sensitive resource information. When ptea runs, it prints out  in the Console: <code>come at me krebs rimasuta go BRRT</code>.</p>
<p>This sample is very similar to Mirai at the host behavior level, so we will not cover it here; At the network traffic level, Tor proxy is used, with a large number of proxy nodes embedded in the sample, and Tor-C2 is encrypted. In the following section we will focus on the encryption method and communication protocol.</p>
<h1 id="encryptionalgorithm">Encryption algorithm</h1>
<p><code>Mirai_ptea</code> encrypts all sensitive resource information and stores it in a certain order. The string information seen when the sample is opened in IDA is shown below, with almost no readable information.</p>
<p><img src="__GHOST_URL__/content/images/2021/06/ptea_strtab.png" alt="ptea_strtab" loading="lazy"></p>
<p>The following code snippet is from the decryption-related functions in the sample, which can be determined to use the TEA algorithm by the constants <code>0xC6EF3720 &amp; 0X61C88647</code>.</p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_tea.png"  width="860px" />
<p>The key is：</p>
<pre><code>0xC26F6A52 0x24AA0006 0x8E1BF2C5 0x4BA51F8C
</code></pre>
<p>We wrote a decryption script(<a href="#decrypt_str"><strong>see appendix</strong></a>), through which we can obtain all the decrypted sensitive resources and their table entry information, part of the resource information is shown below.</p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_decinfo.png"  width="860px" />
<p>Mirai_ptea has two ways of operation when using encrypted resources</p>
<ul>
<li><strong>The traditional Mirai way</strong>: Decrypt an encrypted item, take the value, re-encrypt the decrypted item, i.e. <code>var_unlock--&gt;var_get--&gt;var_lock</code>. For example, the console information is taken by this method.<br>
<img src="__GHOST_URL__/content/images/2021/06/ptea_var.png" alt="ptea_strtab" loading="lazy"></li>
</ul>
<p>The value of table entry 0x11 is exactly: <code>come at me krebs rimasuta go BRRT</code>.</p>
<ul>
<li><strong>Mirai_ptea’s way</strong>: Decrypt multiple encrypted items, taking the value, and re-encrypt the decrypted items, i.e. <code>rangeVar_unlock--&gt;var_get--&gt;rangeVar_lock</code>. For example, this method is used when getting the disguised process name.<br>
<img src="__GHOST_URL__/content/images/2021/06/ptea_rangevar.png" alt="ptea_strtab" loading="lazy"></li>
</ul>
<p>The values of the table entries 0x2c to 0x2c+10 shown below are the exact 11 pseudo-process names that can be chosen.</p>
<pre><code>index 0x2c, value = /bin/sh
index 0x2d, value = telnetd
index 0x2e, value = upnpc-static
index 0x2f, value = wsdd
index 0x30, value = proftpd
index 0x31, value = mini_httpd
index 0x32, value = udevd
index 0x33, value = /sbin/udhcpc
index 0x34, value = boa
index 0x35, value = /usr/sbin/inetd
index 0x36, value = dnsmasq
</code></pre>
<h1 id="communicationprotocol">Communication Protocol</h1>
<p>An overview of the network traffic in Mirai_ptea is provided below.</p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_network.png"  width="860px" />
<p>The whole process can be divided into 3 steps as follows.</p>
<p>1: Establishing a connection with the proxy node</p>
<p>2: Establishing a connection with Tor C2</p>
<p>3: Communicate with C2 via ptea's custom protocol to receive attack commands from C2.</p>
<h3 id="0x1establishingaconnectionwiththeproxy">0x1.Establishing a connection with the proxy</h3>
<p>The Mirai_ptea sample has two sets of proxies built into it, with table entries <code>0x2a and 0x2b</code> in the encrypted resource. When the Bot sample runs, one of the two sets of proxies is selected at random, and then one proxy node of the selected sets is connected by the following code snippet.</p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_proxy.png"  width="860px" />
<p>There are 38 proxy nodes in <code>0x2a</code> in the format of <code>ip:port</code></p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_0x2a.png"  width="860px" />
<p>And there are 334 proxy nodes in <code>0x2b</code>, in the format of <code>ip</code>, and the port of this group of proxies is fixed at <code>9050</code>.</p>
<img src="__GHOST_URL__/content/images/2021/06/ptea_0x2b.png"  width="860px" />
<p>See the appendix for a detailed list of proxies.</p>
<h3 id="0x2connectingtoc2viathetorproxyprotocol">0x2. Connecting to C2 via the Tor-Proxy protocol</h3>
<p><img src="__GHOST_URL__/content/images/2021/06/ptea_c2.png" alt="ptea_strtab" loading="lazy"></p>
<p>You can see that C2 has the table entry <code>0xD</code> in the encrypted resource, and after decrypting it, get the following string.</p>
<pre><code>rkz2f5u57cvs3kdt6amdku2uhly2esj7m2336dttvcygloivcgsmxjjnuickasbuatxajrovi4lvd2zjuejivzrb3vobuoezbc6z3gtu6b3r5tce.onion
</code></pre>
<p>Excluding the <code>.onion</code> at the end of the above string and splitting it by length 16, then splicing it with the <code>.onion</code> string at the end, we get the following 7 C2s.</p>
<pre><code>rkz2f5u57cvs3kdt.onion
6amdku2uhly2esj7.onion
m2336dttvcygloiv.onion
cgsmxjjnuickasbu.onion
atxajrovi4lvd2zj.onion
uejivzrb3vobuoez.onion
bc6z3gtu6b3r5tce.onion
</code></pre>
<h3 id="0x3communicatewiththec2sviacustomprotocolsforregistrationheartbeatandattackasfollows">0x3. Communicate with the C2s via custom protocols for registration, heartbeat, and attack as follows</h3>
<ul>
<li>Registration<br>
<img src="__GHOST_URL__/content/images/2021/06/ptea_reg.png"  width="860px" /></li>
</ul>
<pre><code>msg parsing
----------------------------------------------------------------
3e c7 e3 1e 37 47 61 20						-----&gt;hardcoded msg from Bot
b1 2f de ce cb 89 e1 a0						-----&gt;cmd from C2,ask Bot to upload info
3a 31 34 b5 02 00							-----&gt;hardcoded 6 bytes msg from Bot
b4 a3 e1 16									-----&gt;ip of infected device
04											-----&gt;group string length
74 65 73 74								    -----&gt;group string
79			                                -----&gt;padding
</code></pre>
<ul>
<li>Heartbeat<br>
<img src="__GHOST_URL__/content/images/2021/06/ptea_heart.png"  width="860px" /></li>
</ul>
<pre><code>msg parsing
----------------------------------------------------------------
2a 23						-----&gt; random 2 bytes msg from Bot
2a 23						-----&gt; random 2 bytes msg from C2
</code></pre>
<ul>
<li>Attack command The first 4 bytes of the attack command, <code>AD AF FE 7F</code> are fixed phantom numbers, and the rest of the attack command is similar to mirai's attack command format</li>
</ul>
<pre><code>00000000: AD AF FE 7F 1E 00 00 00  00 01 B9 98 42 65 20 00  ............Be .
00000010: 42 65 20 00     
</code></pre>
<h1 id="ddosattackactivity">DDoS attack activity</h1>
<p>This botnet has been busy launching DDoS attacks, the following figure shows some DDoS attack instructions of the botnet that we observed.<br>
<a href="__GHOST_URL__/content/images/2021/06/mirai_ptea_atk_cmd_4c.png"><img src="__GHOST_URL__/content/images/2021/06/mirai_ptea_atk_cmd_4.png" class="kg-image"/></a></p>
<h1 id="contactus">Contact us</h1>
<p>Readers are always welcomed to reach us on <a href="https://twitter.com/360Netlab">twitter</a> , or email to <code>netlabat[at]360.cn</code>.</p>
<h1 id="ioc">IoC</h1>
<h2 id="torc2">Tor-C2</h2>
<pre><code>bc6z3gtu6b3r5tce.onion:3742
cgsmxjjnuickasbu.onion:992
uejivzrb3vobuoez.onion:5353
rkz2f5u57cvs3kdt.onion:280
atxajrovi4lvd2zj.onion:110
6amdku2uhly2esj7.onion:513
m2336dttvcygloiv.onion:666
</code></pre>
<h2 id="samplemd5">Sample MD5</h2>
<pre><code>c6ef442bc804fc5290d3617056492d4b
f849fdd79d433e2828473f258ffddaab
</code></pre>
<h2 id="downloaderurl">Downloader URL</h2>
<pre><code>http://193[.177.182.221/boot
</code></pre>
<h2 id="scannerip">Scanner IP</h2>
<pre><code>205.185.117.21	AS53667|FranTech_Solutions	United_States|Nevada|Las_Vegas
205.185.114.55	AS53667|FranTech_Solutions	United_States|Nevada|Las_Vegas
68.183.109.6	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City
67.205.163.141	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City
165.227.88.215	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City
</code></pre>
<h2 id="proxys">Proxys</h2>
<pre><code>---------proxys at index 0x2a，count=38---------
149.202.9.7:9898
91.134.216.103:16358
84.32.188.34:1157
51.178.185.237:32
65.21.16.80:23560
149.202.9.14:19765
146.59.11.109:5089
195.189.96.61:29582
84.32.188.37:1454
51.195.209.80:26848
5.199.174.242:27931
95.179.158.147:22413
146.59.11.103:1701
185.150.117.10:29086
149.56.154.210:24709
135.148.11.151:3563
51.195.152.255:25107
45.79.193.124:7158
135.148.11.150:5560
185.150.117.41:20790
135.125.250.120:14498
172.106.70.135:692
195.189.96.60:9700
172.106.70.134:25054
149.56.154.211:21299
108.61.218.205:29240
51.178.185.236:21685
51.81.139.251:6255
51.255.237.164:963
51.81.139.249:32380
139.162.45.218:5165
65.21.16.94:28056
207.148.74.163:32389
172.104.100.78:1039
45.32.8.100:19759
141.164.46.133:2205
172.105.36.167:10843
172.105.180.239:19531

---------proxys at index 0x2b，count=334，port=9050---------
Too many, not list here, you can get them via the IDA script
</code></pre>
<h1 id="aiddecrypt_strappendixidadecryptscripta"><a id="decrypt_str">Appendix（IDA Decrypt script）</a></h1>
<pre><code># IDAPYTHON SCRIPT for md5 c6ef442bc804fc5290d3617056492d4b only.
# Tested at ida 7.0
from ctypes import *
import struct
print &quot;-------------------decryption start------------------------&quot;

key=[0xC26F6A52,0x24AA0006,0x8E1BF2C5,0x4BA51F8C]
def tea_dec(buf,key):
    rbuf=&quot;&quot;
    fmt = '&gt;' + str(len(buf)/4) + 'I'
    tbuf= struct.unpack_from(fmt,buf)
    j=0
    for i in range(0,len(tbuf)/2):
        
        v1=c_uint32(tbuf[i+j])
        v2=c_uint32(tbuf[i+1+j])

        sum=c_uint32(0xC6EF3720)
        while(sum.value):
            v2.value -= ((v1.value&gt;&gt;5)+key[3])    ^(v1.value+sum.value)^  ((v1.value&lt;&lt;4)+key[2])
            v1.value -= ((v2.value&gt;&gt;5)+key[1])   ^(v2.value+sum.value)^ ((v2.value&lt;&lt;4)+key[0])
            sum.value+=0x61C88647
        rbuf +=struct.pack(&quot;&gt;I&quot;,v1.value)+struct.pack(&quot;&gt;I&quot;,v2.value)
        j+=1
    return rbuf
def getbuff(addr):
    buf = &quot;&quot;
    while idc.get_bytes(addr, 2) != &quot;\x00\x00&quot;:
        buf += idc.get_bytes(addr, 1)
        addr += 1

    return buf



# pay attention to function at 0x0000D074
a=getbuff(idc.get_wide_dword(0x00019C9C))

    

buf=[]
#0x19c9c-0x199f0 --&gt; 684
for i in range(0,684,12):
    offset=idc.get_wide_word(0x000199F4+i)
    length=idc.get_wide_word(0x000199F4+i+2)

    buf.append(a[offset:offset+length])
    
c2=[]
#684/12 --&gt; 57
for i in range(57):
    decbuf=tea_dec(buf[i],key)

    if(&quot;.onion&quot; in decbuf):
        c2.append(decbuf)
    print &quot;index %x, value = %s&quot; %(i,decbuf)    
print &quot;-------------------decryption end---------------&quot;

proxya=tea_dec(buf[0x2a],key)
pacnt=struct.unpack(&quot;&lt;H&quot;,proxya[2:4])


proxy=[]
port=[]
tmp=proxya[4:4+6*(pacnt[0])]
print &quot;------------proxys at index 0x2A, count= %d------------&quot; %(pacnt[0])
for i in range(0,len(tmp),6):
    proxy.append(struct.unpack(&quot;&gt;I&quot;,tmp[i:i+4])[0])
    port.append(struct.unpack(&quot;&lt;H&quot;,tmp[i+4:i+6])[0])
for i in range(pacnt[0]):
    a=struct.pack(&quot;&gt;I&quot;,proxy[i])
    ip=&quot;&quot;
    for j in range(4):
        ip+=str(ord(a[j]))
        if j!=3:
            ip+=&quot;.&quot;
    
    print&quot;%s:%d&quot; %(ip,port[i])



proxyb=tea_dec(buf[0x2b],key)
pbcnt=struct.unpack(&quot;&lt;H&quot;,proxyb[2:4])
fmt = '&gt;' + str(pbcnt[0]) + 'I'
tmp=proxyb[4:4*(pbcnt[0]+1)]
print &quot;------------proxys at index 0x2B, count= %d------------&quot; %(pbcnt[0])
xxxxx=struct.unpack(fmt,tmp)
for i in xxxxx:
    a=struct.pack(&quot;&gt;I&quot;,i)
    ip=&quot;&quot;
    for i in range(4):
        ip+=str(ord(a[i]))
        if i!=3:
            ip+=&quot;.&quot;
    print ip


print &quot;-------------------------onion info--------------&quot;    
if len(c2)!=0:
    for i in c2:
        
        pos=i.find(&quot;.onion&quot;)

        for j in range(0,pos,16):
            print i[j:16+j]+&quot;.onion&quot;
else:
    print &quot;Don't find the onion c2&quot;
</code></pre>
<!--kg-card-end: markdown-->
Overview


On 2021-06-22 we detected a sample of a mirai variant that we named mirai_ptea propagating through a new vulnerability targeting KGUARD DVR. Coincidently, a day later, on June 23, we received an inquiry from the security community asking if we had seen a new DDoS botnet, cross-referencing some data, it was exactly this botnet that we had just discovered.



Timeline


 * 2021-03-22 Our historical data indicates the first probe against this vulnerability
 * 2021-06-22 We observed the mirai_ptea sample exploiting this vulnerability to spread
 * 2021-06-23 We got a tip from the security community that this botnet was being used for ongoing DDoS attacks.
 * 2021-06-25 mirai_aurora, another mirai variant, starts to use this vulnerability to propagate



Vulnerability analysis


Given that we have not found public information on this vulnerability, we will hide some of the key information here to prevent the vulnerability from being further abused.


One program on the KGUARD DVR firmware listens on port ***** at 0.0.0.0 to remotely execute system commands without authentication. The firmware released after 2017 seems to have this fixed by modifying the listening address to 127.0.0.1. Some of the exploited payloads are as follows.





Analysis of affected devices


We have discovered at least 3,000 or so online devices still have the vulnerability. The affected devices are as follows:





DeviceType
ProductType
HardVersion
DefDeviceName




D1004NR
DVR4-1600
DM-268A
DVR4-1600


D1004NR
HY-DVR
DM-268
720P-HY04N


D1004NR
HY-DVR
DM-268A
720P-HY04N


D1004NR
HY-DVR
DM-274
720P-HY04N


D1004NR
HY-DVR
DM-274B
720P-HY04N


D1004NR
NHDR
DM-274
NHDR-3204AHD


D1004NR
RL-AHD4n
DM-268
720P-HY04N


D1008NR
1093/508N-DVRBM08H
DM-292
720P-HY08N


D1008NR
DVR8-1600
DM-298
DVR8-1600


D1008NR
DVR8-HDA10L
DM-292
DVR8-HDA10L


D1008NR
HD881
DM-292
HD881


D1008NR
HY-DVR
DM-292
720P-HY08N


D1008NR
HY-DVR
DM-298
720P-HY08N


D1008NR
NHDR
DM-298
NHDR-3208AHD


D1008NR
RL-AHD8n
DM-292
720P-HY08N


D1016NR
DVR16-HDA10L
DM-303
DVR16-HDA10L


D1016NR
HD1681
DM-303
HD1681


D1016NR
HY-DVR
DM-303A
720P-HY16N


D1016NR
HY-DVR
DM-310
720P-HY16N


D1016NR
HY-DVR
DM-310A
720P-HY16N


D1016NR
NHDR
DM-310
NHDR-3216AHD


D1016NR
RL-MHD16n(21A)
DM-310A
720P-HY16N


D1104
HY-DVR
DM-290A
1080P-HY04


D1104
NHDR
DM-307
NHDR-5304AHD


D1104NR
HD1T4
DM-291A
1080P-04


D1104NR
HD481
DM-291
HD481


D1104NR
HRD-E430L
DM-291A
HRD-E430L


D1104NR
HY-DVR
DM-284
1080P-HY04N


D1104NR
HY-DVR
DM-291
"Panda


D1104NR
HY-DVR
DM-291
1080P-HY04N


D1104NR
HY-DVR
DM-291A
1080P-HY04N


D1104NR
HY-DVR
DM-291C
LRA3040N


D1104NR
NHDR
DM-307
NHDR-5104AHD


D1104NR
SDR-B73303
DM-291A
SDR-B73303


D1104NR
SVR9204H
DM-291A
1080P-HY04N


D1108NR
1093/538P
DM-290
1080P-HY08N


D1108NR
DVR8-4575
DM-290
DVR8-4575


D1108NR
DVR8-HDA10P
DM-290
DVR8-HDA10P


D1108NR
HRD-E830L
DM-290A
HRD-E830L


D1108NR
HY-DVR
DM-290
1080P-HY08N


D1108NR
HY-DVR
DM-290A
1080P-HY08N


D1108NR
HY-DVR
DM-290A
LRA3080N


D1108NR
NHDR
DM-307
NHDR-5108AHD


D1108NR
RL-AHD8p
DM-290
1080P-HY08N


D1108NR
SDR-B74301
DM-290A
SDR-B74301


D1108NR
SDR-B74303
DM-290A
SDR-B74303


D1116
HY-DVR
DM-300
EHR-5164


D1116NR
HRD-E1630L
DM-295
HRD-E1630L


D1116NR
HY-DVR
DM-295
1080P-HY16N


D1116NR
HY-DVR
DM-295
LRA3160N


D1116NR
HY-DVR
DM-299
1080P-HY16N


D1116NR
SDR-B75303
DM-295
SDR-B75303


D1132NR
HY-DVR
DM-300
1080P-HY32


D2116NR
SDR-B85300
DM-300
SDR-B85300


D973215U
F9-DVR32
DM-195
F9-DVR32


D9804AHD
DVR
DM-210
391115


D9804NAHD
AHD7-DVR4
DM-239
AHD7-DVR4


D9804NAHD
DVR
DM-239
720P-DVR04ND


D9804NAHD
NHDR
DM-239
NHDR-3104AHD-II


D9808NRAHD
AHD7-DVR8
DM-228
AHD7-DVR8


D9808NRAHD
DVR
DM-228



D9808NRAHD
DVR
DM-228
391116


D9808NRAHD
NHDR
DM-228
NHDR-3108AHD-II


D9808NRAHD
NHDR
DM-228
NHDR3108AHDII


D9816NAHD
DVR
DM-233
720P-DVR016N


D9816NAHD
NHDR
DM-233
NHDR3116AHDII


D9816NRAHD
AHD7-DVR16
DM-229
AHD7-DVR16


D9816NRAHD
DVR
DM-229
720P-DVR016NB


D9904
D9904
DM-237
1080P-DVR04


D9904
DVR
DM-237
1080P-DVR04


D9904
NHDR
DM-237
NHDR-5204AHD


D9904NR
DVR
DM-244
1080P-DVR04N


D9904NR
DVR
DM-244
BCS-VAVR0401M


D9904NR
HY-DVR
DM-244
CVD-AF04S


D9904NR
N420
DM-244
1080P-DVR04N


D9904NR
NHDR
DM-244
NHDR-5004AHD-II


D9904NR
NHDR
DM-244
NHDR5004AHDII


D9908
DVR
DM-245
BCS-VAVR0802Q


D9908
NHDR
DM-245
NHDR-5208AHD


D9908AHD
DVR
DM-246
1080P-DVR08A


D9908NR
AHD10-DVR8
DM-237
AHD10-DVR8


D9908NR
DVR
DM-237
1080P-DVR08N


D9908NR
DVR
DM-237
SVR9008ATHD/C


D9908NR
HY-DVR
DM-237
CVD-AF08S


D9908NR
N820
DM-237
1080P-DVR08N


D9908NR
NHDR
DM-237
NHDR-5008AHD-II


D9916NR
DVR
DM-245
1080P-DVR016NAT;UI


D9916NR
DVR
DM-245
HR-31-211620;UI


D9916NR
HY-DVR
DM-245
CVD-AF16S


D9916NR
NHDR
DM-245
NHDR-5016AHD-II


D9916NRAHD
DVR
DM-246
1080P-DVR016NA


D9916NRAHD
N1620
DM-246
1080P-DVR016NA


H1104W
SNR-73200W
DM-339
SNR-73200W


H1106W
LHB806
DM-291B
LHB806


H1106W
LHB906
DM-291B
LHB906






Bot scale analysis


We are able to see a portion of the infected bots, the following is a daily active trend：





The geographic distribution of Bot source IPs is as follows, mainly concentrated in the United States, Korea and Brazi：





Sample Analysis


Let’s take a look a the the following samples


Verdict:mirai_ptea
MD5:c6ef442bc804fc5290d3617056492d4b
ELF 32-bit LSB executable, ARM, version 1, statically linked, stripped 
Packer:No
Lib:uclibc



c6ef442bc804fc5290d3617056492d4b is a variant of Mirai, which we call Mirai_ptea based on its use of Tor Proxy to communicate with C2 and the TEA algorithm (Tiny Encryption Algorithm) to hide sensitive resource information. When ptea runs, it prints out in the Console: come at me krebs rimasuta go BRRT.


This sample is very similar to Mirai at the host behavior level, so we will not cover it here; At the network traffic level, Tor proxy is used, with a large number of proxy nodes embedded in the sample, and Tor-C2 is encrypted. In the following section we will focus on the encryption method and communication protocol.



Encryption algorithm


Mirai_ptea encrypts all sensitive resource information and stores it in a certain order. The string information seen when the sample is opened in IDA is shown below, with almost no readable information.





The following code snippet is from the decryption-related functions in the sample, which can be determined to use the TEA algorithm by the constants 0xC6EF3720 & 0X61C88647.



The key is：


0xC26F6A52 0x24AA0006 0x8E1BF2C5 0x4BA51F8C



We wrote a decryption script(see appendix), through which we can obtain all the decrypted sensitive resources and their table entry information, part of the resource information is shown below.



Mirai_ptea has two ways of operation when using encrypted resources


 * The traditional Mirai way: Decrypt an encrypted item, take the value, re-encrypt the decrypted item, i.e. var_unlock-->var_get-->var_lock. For example, the console information is taken by this method.
   
   


The value of table entry 0x11 is exactly: come at me krebs rimasuta go BRRT.


 * Mirai_ptea’s way: Decrypt multiple encrypted items, taking the value, and re-encrypt the decrypted items, i.e. rangeVar_unlock-->var_get-->rangeVar_lock. For example, this method is used when getting the disguised process name.
   
   


The values of the table entries 0x2c to 0x2c+10 shown below are the exact 11 pseudo-process names that can be chosen.


index 0x2c, value = /bin/sh
index 0x2d, value = telnetd
index 0x2e, value = upnpc-static
index 0x2f, value = wsdd
index 0x30, value = proftpd
index 0x31, value = mini_httpd
index 0x32, value = udevd
index 0x33, value = /sbin/udhcpc
index 0x34, value = boa
index 0x35, value = /usr/sbin/inetd
index 0x36, value = dnsmasq




Communication Protocol


An overview of the network traffic in Mirai_ptea is provided below.



The whole process can be divided into 3 steps as follows.


1: Establishing a connection with the proxy node


2: Establishing a connection with Tor C2


3: Communicate with C2 via ptea's custom protocol to receive attack commands from C2.



0x1.Establishing a connection with the proxy


The Mirai_ptea sample has two sets of proxies built into it, with table entries 0x2a and 0x2b in the encrypted resource. When the Bot sample runs, one of the two sets of proxies is selected at random, and then one proxy node of the selected sets is connected by the following code snippet.



There are 38 proxy nodes in 0x2a in the format of ip:port



And there are 334 proxy nodes in 0x2b, in the format of ip, and the port of this group of proxies is fixed at 9050.



See the appendix for a detailed list of proxies.



0x2. Connecting to C2 via the Tor-Proxy protocol





You can see that C2 has the table entry 0xD in the encrypted resource, and after decrypting it, get the following string.


rkz2f5u57cvs3kdt6amdku2uhly2esj7m2336dttvcygloivcgsmxjjnuickasbuatxajrovi4lvd2zjuejivzrb3vobuoezbc6z3gtu6b3r5tce.onion



Excluding the .onion at the end of the above string and splitting it by length 16, then splicing it with the .onion string at the end, we get the following 7 C2s.


rkz2f5u57cvs3kdt.onion
6amdku2uhly2esj7.onion
m2336dttvcygloiv.onion
cgsmxjjnuickasbu.onion
atxajrovi4lvd2zj.onion
uejivzrb3vobuoez.onion
bc6z3gtu6b3r5tce.onion




0x3. Communicate with the C2s via custom protocols for registration, heartbeat, and attack as follows


 * Registration
   
   


msg parsing
----------------------------------------------------------------
3e c7 e3 1e 37 47 61 20						----->hardcoded msg from Bot
b1 2f de ce cb 89 e1 a0						----->cmd from C2,ask Bot to upload info
3a 31 34 b5 02 00							----->hardcoded 6 bytes msg from Bot
b4 a3 e1 16									----->ip of infected device
04											----->group string length
74 65 73 74								    ----->group string
79			                                ----->padding



 * Heartbeat
   
   


msg parsing
----------------------------------------------------------------
2a 23						-----> random 2 bytes msg from Bot
2a 23						-----> random 2 bytes msg from C2



 * Attack command The first 4 bytes of the attack command, AD AF FE 7F are fixed phantom numbers, and the rest of the attack command is similar to mirai's attack command format


00000000: AD AF FE 7F 1E 00 00 00  00 01 B9 98 42 65 20 00  ............Be .
00000010: 42 65 20 00     




DDoS attack activity


This botnet has been busy launching DDoS attacks, the following figure shows some DDoS attack instructions of the botnet that we observed.





Contact us


Readers are always welcomed to reach us on twitter , or email to netlabat[at]360.cn.



IoC



Tor-C2


bc6z3gtu6b3r5tce.onion:3742
cgsmxjjnuickasbu.onion:992
uejivzrb3vobuoez.onion:5353
rkz2f5u57cvs3kdt.onion:280
atxajrovi4lvd2zj.onion:110
6amdku2uhly2esj7.onion:513
m2336dttvcygloiv.onion:666




Sample MD5


c6ef442bc804fc5290d3617056492d4b
f849fdd79d433e2828473f258ffddaab




Downloader URL


http://193[.177.182.221/boot




Scanner IP


205.185.117.21	AS53667|FranTech_Solutions	United_States|Nevada|Las_Vegas
205.185.114.55	AS53667|FranTech_Solutions	United_States|Nevada|Las_Vegas
68.183.109.6	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City
67.205.163.141	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City
165.227.88.215	AS14061|DigitalOcean,_LLC	United_States|New_York|New_York_City




Proxys


---------proxys at index 0x2a，count=38---------
149.202.9.7:9898
91.134.216.103:16358
84.32.188.34:1157
51.178.185.237:32
65.21.16.80:23560
149.202.9.14:19765
146.59.11.109:5089
195.189.96.61:29582
84.32.188.37:1454
51.195.209.80:26848
5.199.174.242:27931
95.179.158.147:22413
146.59.11.103:1701
185.150.117.10:29086
149.56.154.210:24709
135.148.11.151:3563
51.195.152.255:25107
45.79.193.124:7158
135.148.11.150:5560
185.150.117.41:20790
135.125.250.120:14498
172.106.70.135:692
195.189.96.60:9700
172.106.70.134:25054
149.56.154.211:21299
108.61.218.205:29240
51.178.185.236:21685
51.81.139.251:6255
51.255.237.164:963
51.81.139.249:32380
139.162.45.218:5165
65.21.16.94:28056
207.148.74.163:32389
172.104.100.78:1039
45.32.8.100:19759
141.164.46.133:2205
172.105.36.167:10843
172.105.180.239:19531

---------proxys at index 0x2b，count=334，port=9050---------
Too many, not list here, you can get them via the IDA script




Appendix（IDA Decrypt script）


# IDAPYTHON SCRIPT for md5 c6ef442bc804fc5290d3617056492d4b only.
# Tested at ida 7.0
from ctypes import *
import struct
print "-------------------decryption start------------------------"

key=[0xC26F6A52,0x24AA0006,0x8E1BF2C5,0x4BA51F8C]
def tea_dec(buf,key):
    rbuf=""
    fmt = '>' + str(len(buf)/4) + 'I'
    tbuf= struct.unpack_from(fmt,buf)
    j=0
    for i in range(0,len(tbuf)/2):
        
        v1=c_uint32(tbuf[i+j])
        v2=c_uint32(tbuf[i+1+j])

        sum=c_uint32(0xC6EF3720)
        while(sum.value):
            v2.value -= ((v1.value>>5)+key[3])    ^(v1.value+sum.value)^  ((v1.value<<4)+key[2])
            v1.value -= ((v2.value>>5)+key[1])   ^(v2.value+sum.value)^ ((v2.value<<4)+key[0])
            sum.value+=0x61C88647
        rbuf +=struct.pack(">I",v1.value)+struct.pack(">I",v2.value)
        j+=1
    return rbuf
def getbuff(addr):
    buf = ""
    while idc.get_bytes(addr, 2) != "\x00\x00":
        buf += idc.get_bytes(addr, 1)
        addr += 1

    return buf



# pay attention to function at 0x0000D074
a=getbuff(idc.get_wide_dword(0x00019C9C))

    

buf=[]
#0x19c9c-0x199f0 --> 684
for i in range(0,684,12):
    offset=idc.get_wide_word(0x000199F4+i)
    length=idc.get_wide_word(0x000199F4+i+2)

    buf.append(a[offset:offset+length])
    
c2=[]
#684/12 --> 57
for i in range(57):
    decbuf=tea_dec(buf[i],key)

    if(".onion" in decbuf):
        c2.append(decbuf)
    print "index %x, value = %s" %(i,decbuf)    
print "-------------------decryption end---------------"

proxya=tea_dec(buf[0x2a],key)
pacnt=struct.unpack("<H",proxya[2:4])


proxy=[]
port=[]
tmp=proxya[4:4+6*(pacnt[0])]
print "------------proxys at index 0x2A, count= %d------------" %(pacnt[0])
for i in range(0,len(tmp),6):
    proxy.append(struct.unpack(">I",tmp[i:i+4])[0])
    port.append(struct.unpack("<H",tmp[i+4:i+6])[0])
for i in range(pacnt[0]):
    a=struct.pack(">I",proxy[i])
    ip=""
    for j in range(4):
        ip+=str(ord(a[j]))
        if j!=3:
            ip+="."
    
    print"%s:%d" %(ip,port[i])



proxyb=tea_dec(buf[0x2b],key)
pbcnt=struct.unpack("<H",proxyb[2:4])
fmt = '>' + str(pbcnt[0]) + 'I'
tmp=proxyb[4:4*(pbcnt[0]+1)]
print "------------proxys at index 0x2B, count= %d------------" %(pbcnt[0])
xxxxx=struct.unpack(fmt,tmp)
for i in xxxxx:
    a=struct.pack(">I",i)
    ip=""
    for i in range(4):
        ip+=str(ord(a[i]))
        if i!=3:
            ip+="."
    print ip


print "-------------------------onion info--------------"    
if len(c2)!=0:
    for i in c2:
        
        pos=i.find(".onion")

        for j in range(0,pos,16):
            print i[j:16+j]+".onion"
else:
    print "Don't find the onion c2"


{"version":"0.3.1","atoms":[],"cards":[["markdown",{"markdown":"# Overview\n\nOn 2021-06-22 we detected a sample of a mirai variant that we named `mirai_ptea` propagating through a new vulnerability targeting [KGUARD DVR](https://www.kguard.com.tw/). Coincidently, a day later, on June 23, we received an inquiry from the security community asking if we had seen a new DDoS botnet, cross-referencing some data, it was exactly this botnet that we had just discovered.\n\n\n### Timeline\n\n- 2021-03-22 Our historical data indicates the first probe against this vulnerability\n- 2021-06-22 We observed the `mirai_ptea` sample exploiting this vulnerability to spread\n- 2021-06-23 We got a tip from the security community that this botnet was being used for ongoing DDoS attacks.\n- 2021-06-25 `mirai_aurora`, another mirai variant, starts to use this vulnerability to propagate\n\n# Vulnerability analysis\nGiven that we have not found public information on this vulnerability, we will hide some of the key information here to prevent the vulnerability from being further abused.\n\nOne program on the KGUARD DVR firmware listens on port `*****` at `0.0.0.0` to remotely execute system commands without authentication. The firmware released after 2017 seems to have this fixed by modifying the listening address to `127.0.0.1`. Some of the exploited payloads are as follows.\n![mirai_ptea_xx_exp_p](__GHOST_URL__/content/images/2021/07/mirai_ptea_xx_exp_p.png)\n\n### Analysis of affected devices\n\nWe have discovered at least 3,000 or so online devices still have the vulnerability. The affected devices are as follows:\n\n| DeviceType | ProductType | HardVersion | DefDeviceName |\n| ------------- | ---------------- | ------------- | ---------------- |\n| D1004NR | DVR4-1600 | DM-268A | DVR4-1600 |\n| D1004NR | HY-DVR | DM-268 | 720P-HY04N |\n| D1004NR | HY-DVR | DM-268A | 720P-HY04N |\n| D1004NR | HY-DVR | DM-274 | 720P-HY04N |\n| D1004NR | HY-DVR | DM-274B | 720P-HY04N |\n| D1004NR | NHDR | DM-274 | NHDR-3204AHD |\n| D1004NR | RL-AHD4n | DM-268 | 720P-HY04N |\n| D1008NR | 1093/508N-DVRBM08H | DM-292 | 720P-HY08N |\n| D1008NR | DVR8-1600 | DM-298 | DVR8-1600 |\n| D1008NR | DVR8-HDA10L | DM-292 | DVR8-HDA10L |\n| D1008NR | HD881 | DM-292 | HD881 |\n| D1008NR | HY-DVR | DM-292 | 720P-HY08N |\n| D1008NR | HY-DVR | DM-298 | 720P-HY08N |\n| D1008NR | NHDR | DM-298 | NHDR-3208AHD |\n| D1008NR | RL-AHD8n | DM-292 | 720P-HY08N |\n| D1016NR | DVR16-HDA10L | DM-303 | DVR16-HDA10L |\n| D1016NR | HD1681 | DM-303 | HD1681 |\n| D1016NR | HY-DVR | DM-303A | 720P-HY16N |\n| D1016NR | HY-DVR | DM-310 | 720P-HY16N |\n| D1016NR | HY-DVR | DM-310A | 720P-HY16N |\n| D1016NR | NHDR | DM-310 | NHDR-3216AHD |\n| D1016NR | RL-MHD16n(21A) | DM-310A | 720P-HY16N |\n| D1104 | HY-DVR | DM-290A | 1080P-HY04 |\n| D1104 | NHDR | DM-307 | NHDR-5304AHD |\n| D1104NR | HD1T4 | DM-291A | 1080P-04 |\n| D1104NR | HD481 | DM-291 | HD481 |\n| D1104NR | HRD-E430L | DM-291A | HRD-E430L |\n| D1104NR | HY-DVR | DM-284 | 1080P-HY04N |\n| D1104NR | HY-DVR | DM-291 | \"Panda |\n| D1104NR | HY-DVR | DM-291 | 1080P-HY04N |\n| D1104NR | HY-DVR | DM-291A | 1080P-HY04N |\n| D1104NR | HY-DVR | DM-291C | LRA3040N |\n| D1104NR | NHDR | DM-307 | NHDR-5104AHD |\n| D1104NR | SDR-B73303 | DM-291A | SDR-B73303 |\n| D1104NR | SVR9204H | DM-291A | 1080P-HY04N |\n| D1108NR | 1093/538P | DM-290 | 1080P-HY08N |\n| D1108NR | DVR8-4575 | DM-290 | DVR8-4575 |\n| D1108NR | DVR8-HDA10P | DM-290 | DVR8-HDA10P |\n| D1108NR | HRD-E830L | DM-290A | HRD-E830L |\n| D1108NR | HY-DVR | DM-290 | 1080P-HY08N |\n| D1108NR | HY-DVR | DM-290A | 1080P-HY08N |\n| D1108NR | HY-DVR | DM-290A | LRA3080N |\n| D1108NR | NHDR | DM-307 | NHDR-5108AHD |\n| D1108NR | RL-AHD8p | DM-290 | 1080P-HY08N |\n| D1108NR | SDR-B74301 | DM-290A | SDR-B74301 |\n| D1108NR | SDR-B74303 | DM-290A | SDR-B74303 |\n| D1116 | HY-DVR | DM-300 | EHR-5164 |\n| D1116NR | HRD-E1630L | DM-295 | HRD-E1630L |\n| D1116NR | HY-DVR | DM-295 | 1080P-HY16N |\n| D1116NR | HY-DVR | DM-295 | LRA3160N |\n| D1116NR | HY-DVR | DM-299 | 1080P-HY16N |\n| D1116NR | SDR-B75303 | DM-295 | SDR-B75303 |\n| D1132NR | HY-DVR | DM-300 | 1080P-HY32 |\n| D2116NR | SDR-B85300 | DM-300 | SDR-B85300 |\n| D973215U | F9-DVR32 | DM-195 | F9-DVR32 |\n| D9804AHD | DVR | DM-210 | 391115 |\n| D9804NAHD | AHD7-DVR4 | DM-239 | AHD7-DVR4 |\n| D9804NAHD | DVR | DM-239 | 720P-DVR04ND |\n| D9804NAHD | NHDR | DM-239 | NHDR-3104AHD-II |\n| D9808NRAHD | AHD7-DVR8 | DM-228 | AHD7-DVR8 |\n| D9808NRAHD | DVR | DM-228 |  |\n| D9808NRAHD | DVR | DM-228 | 391116 |\n| D9808NRAHD | NHDR | DM-228 | NHDR-3108AHD-II |\n| D9808NRAHD | NHDR | DM-228 | NHDR3108AHDII |\n| D9816NAHD | DVR | DM-233 | 720P-DVR016N |\n| D9816NAHD | NHDR | DM-233 | NHDR3116AHDII |\n| D9816NRAHD | AHD7-DVR16 | DM-229 | AHD7-DVR16 |\n| D9816NRAHD | DVR | DM-229 | 720P-DVR016NB |\n| D9904 | D9904 | DM-237 | 1080P-DVR04 |\n| D9904 | DVR | DM-237 | 1080P-DVR04 |\n| D9904 | NHDR | DM-237 | NHDR-5204AHD |\n| D9904NR | DVR | DM-244 | 1080P-DVR04N |\n| D9904NR | DVR | DM-244 | BCS-VAVR0401M |\n| D9904NR | HY-DVR | DM-244 | CVD-AF04S |\n| D9904NR | N420 | DM-244 | 1080P-DVR04N |\n| D9904NR | NHDR | DM-244 | NHDR-5004AHD-II |\n| D9904NR | NHDR | DM-244 | NHDR5004AHDII |\n| D9908 | DVR | DM-245 | BCS-VAVR0802Q |\n| D9908 | NHDR | DM-245 | NHDR-5208AHD |\n| D9908AHD | DVR | DM-246 | 1080P-DVR08A |\n| D9908NR | AHD10-DVR8 | DM-237 | AHD10-DVR8 |\n| D9908NR | DVR | DM-237 | 1080P-DVR08N |\n| D9908NR | DVR | DM-237 | SVR9008ATHD/C |\n| D9908NR | HY-DVR | DM-237 | CVD-AF08S |\n| D9908NR | N820 | DM-237 | 1080P-DVR08N |\n| D9908NR | NHDR | DM-237 | NHDR-5008AHD-II |\n| D9916NR | DVR | DM-245 | 1080P-DVR016NAT;UI |\n| D9916NR | DVR | DM-245 | HR-31-211620;UI |\n| D9916NR | HY-DVR | DM-245 | CVD-AF16S |\n| D9916NR | NHDR | DM-245 | NHDR-5016AHD-II |\n| D9916NRAHD | DVR | DM-246 | 1080P-DVR016NA |\n| D9916NRAHD | N1620 | DM-246 | 1080P-DVR016NA |\n| H1104W | SNR-73200W | DM-339 | SNR-73200W |\n| H1106W | LHB806 | DM-291B | LHB806 |\n| H1106W | LHB906 | DM-291B | LHB906 |\n\n\n# Bot scale analysis\nWe are able to see a portion of the infected bots, the following is a daily active trend：\n\n![Snip202110630_10](__GHOST_URL__/content/images/2021/06/Snip202110630_10.png)\n\nThe geographic distribution of Bot source IPs is as follows, mainly concentrated in the United States, Korea and Brazi：\n![Snip20210629_1](__GHOST_URL__/content/images/2021/06/Snip20210629_1.png)\n\n\n# Sample Analysis\n\nLet’s take a look a the the following samples\n\n```\nVerdict:mirai_ptea\nMD5:c6ef442bc804fc5290d3617056492d4b\nELF 32-bit LSB executable, ARM, version 1, statically linked, stripped \nPacker:No\nLib:uclibc\n```\n\n`c6ef442bc804fc5290d3617056492d4b` is a variant of Mirai, which we call `Mirai_ptea` based on its use of Tor Proxy to communicate with C2 and the TEA algorithm (Tiny Encryption Algorithm) to hide sensitive resource information. When ptea runs, it prints out  in the Console: `come at me krebs rimasuta go BRRT`.\n\nThis sample is very similar to Mirai at the host behavior level, so we will not cover it here; At the network traffic level, Tor proxy is used, with a large number of proxy nodes embedded in the sample, and Tor-C2 is encrypted. In the following section we will focus on the encryption method and communication protocol.\n\n\n# Encryption algorithm\n\n```Mirai_ptea``` encrypts all sensitive resource information and stores it in a certain order. The string information seen when the sample is opened in IDA is shown below, with almost no readable information.\n\n\n![ptea_strtab](__GHOST_URL__/content/images/2021/06/ptea_strtab.png)\n\nThe following code snippet is from the decryption-related functions in the sample, which can be determined to use the TEA algorithm by the constants ```0xC6EF3720 & 0X61C88647```.\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_tea.png\"  width=\"860px\" />\n\nThe key is：\n\n```\n0xC26F6A52 0x24AA0006 0x8E1BF2C5 0x4BA51F8C\n```\n\nWe wrote a decryption script([**see appendix**](#decrypt_str)), through which we can obtain all the decrypted sensitive resources and their table entry information, part of the resource information is shown below.\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_decinfo.png\"  width=\"860px\" />\n\nMirai_ptea has two ways of operation when using encrypted resources\n\n- **The traditional Mirai way**: Decrypt an encrypted item, take the value, re-encrypt the decrypted item, i.e. `var_unlock-->var_get-->var_lock`. For example, the console information is taken by this method. \n![ptea_strtab](__GHOST_URL__/content/images/2021/06/ptea_var.png)\n\n\nThe value of table entry 0x11 is exactly: `come at me krebs rimasuta go BRRT`.\n\n- **Mirai_ptea’s way**: Decrypt multiple encrypted items, taking the value, and re-encrypt the decrypted items, i.e. `rangeVar_unlock-->var_get-->rangeVar_lock`. For example, this method is used when getting the disguised process name.\n![ptea_strtab](__GHOST_URL__/content/images/2021/06/ptea_rangevar.png)\n\nThe values of the table entries 0x2c to 0x2c+10 shown below are the exact 11 pseudo-process names that can be chosen. \n\n```\nindex 0x2c, value = /bin/sh\nindex 0x2d, value = telnetd\nindex 0x2e, value = upnpc-static\nindex 0x2f, value = wsdd\nindex 0x30, value = proftpd\nindex 0x31, value = mini_httpd\nindex 0x32, value = udevd\nindex 0x33, value = /sbin/udhcpc\nindex 0x34, value = boa\nindex 0x35, value = /usr/sbin/inetd\nindex 0x36, value = dnsmasq\n```\n\n# Communication Protocol\n\nAn overview of the network traffic in Mirai_ptea is provided below.\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_network.png\"  width=\"860px\" />\n\nThe whole process can be divided into 3 steps as follows.\n\n1: Establishing a connection with the proxy node\n\n2: Establishing a connection with Tor C2\n\n3: Communicate with C2 via ptea's custom protocol to receive attack commands from C2.\n\n### 0x1.Establishing a connection with the proxy\n\nThe Mirai_ptea sample has two sets of proxies built into it, with table entries ```0x2a and 0x2b``` in the encrypted resource. When the Bot sample runs, one of the two sets of proxies is selected at random, and then one proxy node of the selected sets is connected by the following code snippet.\n\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_proxy.png\"  width=\"860px\" />\n\nThere are 38 proxy nodes in `0x2a` in the format of `ip:port`\n\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_0x2a.png\"  width=\"860px\" />\n\n\nAnd there are 334 proxy nodes in `0x2b`, in the format of `ip`, and the port of this group of proxies is fixed at `9050`.\n\n\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_0x2b.png\"  width=\"860px\" />\n\nSee the appendix for a detailed list of proxies.\n\n\n\n### 0x2. Connecting to C2 via the Tor-Proxy protocol\n\n\n![ptea_strtab](__GHOST_URL__/content/images/2021/06/ptea_c2.png)\n\nYou can see that C2 has the table entry `0xD` in the encrypted resource, and after decrypting it, get the following string.\n\n```\nrkz2f5u57cvs3kdt6amdku2uhly2esj7m2336dttvcygloivcgsmxjjnuickasbuatxajrovi4lvd2zjuejivzrb3vobuoezbc6z3gtu6b3r5tce.onion\n```\n\n\nExcluding the `.onion` at the end of the above string and splitting it by length 16, then splicing it with the `.onion` string at the end, we get the following 7 C2s.\n\n```\nrkz2f5u57cvs3kdt.onion\n6amdku2uhly2esj7.onion\nm2336dttvcygloiv.onion\ncgsmxjjnuickasbu.onion\natxajrovi4lvd2zj.onion\nuejivzrb3vobuoez.onion\nbc6z3gtu6b3r5tce.onion\n```\n\n### 0x3. Communicate with the C2s via custom protocols for registration, heartbeat, and attack as follows\n\n- Registration\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_reg.png\"  width=\"860px\" />\n\n```\nmsg parsing\n----------------------------------------------------------------\n3e c7 e3 1e 37 47 61 20\t\t\t\t\t\t----->hardcoded msg from Bot\nb1 2f de ce cb 89 e1 a0\t\t\t\t\t\t----->cmd from C2,ask Bot to upload info\n3a 31 34 b5 02 00\t\t\t\t\t\t\t----->hardcoded 6 bytes msg from Bot\nb4 a3 e1 16\t\t\t\t\t\t\t\t\t----->ip of infected device\n04\t\t\t\t\t\t\t\t\t\t\t----->group string length\n74 65 73 74\t\t\t\t\t\t\t\t    ----->group string\n79\t\t\t                                ----->padding\n```\n- Heartbeat\n<img src=\"__GHOST_URL__/content/images/2021/06/ptea_heart.png\"  width=\"860px\" />\n\n```\nmsg parsing\n----------------------------------------------------------------\n2a 23\t\t\t\t\t\t-----> random 2 bytes msg from Bot\n2a 23\t\t\t\t\t\t-----> random 2 bytes msg from C2\n```\n\n- Attack command The first 4 bytes of the attack command, `AD AF FE 7F` are fixed phantom numbers, and the rest of the attack command is similar to mirai's attack command format\n\n```\n00000000: AD AF FE 7F 1E 00 00 00  00 01 B9 98 42 65 20 00  ............Be .\n00000010: 42 65 20 00     \n```\n\n# DDoS attack activity\nThis botnet has been busy launching DDoS attacks, the following figure shows some DDoS attack instructions of the botnet that we observed.\n<a href=\"__GHOST_URL__/content/images/2021/06/mirai_ptea_atk_cmd_4c.png\"><img src=\"__GHOST_URL__/content/images/2021/06/mirai_ptea_atk_cmd_4.png\" class=\"kg-image\"/></a>\n\n\n# Contact us\nReaders are always welcomed to reach us on [twitter](https://twitter.com/360Netlab) , or email to `netlabat[at]360.cn`.\n# IoC\n\n## Tor-C2\n```\nbc6z3gtu6b3r5tce.onion:3742\ncgsmxjjnuickasbu.onion:992\nuejivzrb3vobuoez.onion:5353\nrkz2f5u57cvs3kdt.onion:280\natxajrovi4lvd2zj.onion:110\n6amdku2uhly2esj7.onion:513\nm2336dttvcygloiv.onion:666\n```\n\n## Sample MD5\n\n```\nc6ef442bc804fc5290d3617056492d4b\nf849fdd79d433e2828473f258ffddaab\n```\n\n## Downloader URL\n```\nhttp://193[.177.182.221/boot\n```\n\n## Scanner IP\n```\n205.185.117.21\tAS53667|FranTech_Solutions\tUnited_States|Nevada|Las_Vegas\n205.185.114.55\tAS53667|FranTech_Solutions\tUnited_States|Nevada|Las_Vegas\n68.183.109.6\tAS14061|DigitalOcean,_LLC\tUnited_States|New_York|New_York_City\n67.205.163.141\tAS14061|DigitalOcean,_LLC\tUnited_States|New_York|New_York_City\n165.227.88.215\tAS14061|DigitalOcean,_LLC\tUnited_States|New_York|New_York_City\n```\n\n## Proxys\n```\n---------proxys at index 0x2a，count=38---------\n149.202.9.7:9898\n91.134.216.103:16358\n84.32.188.34:1157\n51.178.185.237:32\n65.21.16.80:23560\n149.202.9.14:19765\n146.59.11.109:5089\n195.189.96.61:29582\n84.32.188.37:1454\n51.195.209.80:26848\n5.199.174.242:27931\n95.179.158.147:22413\n146.59.11.103:1701\n185.150.117.10:29086\n149.56.154.210:24709\n135.148.11.151:3563\n51.195.152.255:25107\n45.79.193.124:7158\n135.148.11.150:5560\n185.150.117.41:20790\n135.125.250.120:14498\n172.106.70.135:692\n195.189.96.60:9700\n172.106.70.134:25054\n149.56.154.211:21299\n108.61.218.205:29240\n51.178.185.236:21685\n51.81.139.251:6255\n51.255.237.164:963\n51.81.139.249:32380\n139.162.45.218:5165\n65.21.16.94:28056\n207.148.74.163:32389\n172.104.100.78:1039\n45.32.8.100:19759\n141.164.46.133:2205\n172.105.36.167:10843\n172.105.180.239:19531\n\n---------proxys at index 0x2b，count=334，port=9050---------\nToo many, not list here, you can get them via the IDA script\n```\n# <a id=\"decrypt_str\">Appendix（IDA Decrypt script）</a>\n```\n# IDAPYTHON SCRIPT for md5 c6ef442bc804fc5290d3617056492d4b only.\n# Tested at ida 7.0\nfrom ctypes import *\nimport struct\nprint \"-------------------decryption start------------------------\"\n\nkey=[0xC26F6A52,0x24AA0006,0x8E1BF2C5,0x4BA51F8C]\ndef tea_dec(buf,key):\n    rbuf=\"\"\n    fmt = '>' + str(len(buf)/4) + 'I'\n    tbuf= struct.unpack_from(fmt,buf)\n    j=0\n    for i in range(0,len(tbuf)/2):\n        \n        v1=c_uint32(tbuf[i+j])\n        v2=c_uint32(tbuf[i+1+j])\n\n        sum=c_uint32(0xC6EF3720)\n        while(sum.value):\n            v2.value -= ((v1.value>>5)+key[3])    ^(v1.value+sum.value)^  ((v1.value<<4)+key[2])\n            v1.value -= ((v2.value>>5)+key[1])   ^(v2.value+sum.value)^ ((v2.value<<4)+key[0])\n            sum.value+=0x61C88647\n        rbuf +=struct.pack(\">I\",v1.value)+struct.pack(\">I\",v2.value)\n        j+=1\n    return rbuf\ndef getbuff(addr):\n    buf = \"\"\n    while idc.get_bytes(addr, 2) != \"\\x00\\x00\":\n        buf += idc.get_bytes(addr, 1)\n        addr += 1\n\n    return buf\n\n\n\n# pay attention to function at 0x0000D074\na=getbuff(idc.get_wide_dword(0x00019C9C))\n\n    \n\nbuf=[]\n#0x19c9c-0x199f0 --> 684\nfor i in range(0,684,12):\n    offset=idc.get_wide_word(0x000199F4+i)\n    length=idc.get_wide_word(0x000199F4+i+2)\n\n    buf.append(a[offset:offset+length])\n    \nc2=[]\n#684/12 --> 57\nfor i in range(57):\n    decbuf=tea_dec(buf[i],key)\n\n    if(\".onion\" in decbuf):\n        c2.append(decbuf)\n    print \"index %x, value = %s\" %(i,decbuf)    \nprint \"-------------------decryption end---------------\"\n\nproxya=tea_dec(buf[0x2a],key)\npacnt=struct.unpack(\"<H\",proxya[2:4])\n\n\nproxy=[]\nport=[]\ntmp=proxya[4:4+6*(pacnt[0])]\nprint \"------------proxys at index 0x2A, count= %d------------\" %(pacnt[0])\nfor i in range(0,len(tmp),6):\n    proxy.append(struct.unpack(\">I\",tmp[i:i+4])[0])\n    port.append(struct.unpack(\"<H\",tmp[i+4:i+6])[0])\nfor i in range(pacnt[0]):\n    a=struct.pack(\">I\",proxy[i])\n    ip=\"\"\n    for j in range(4):\n        ip+=str(ord(a[j]))\n        if j!=3:\n            ip+=\".\"\n    \n    print\"%s:%d\" %(ip,port[i])\n\n\n\nproxyb=tea_dec(buf[0x2b],key)\npbcnt=struct.unpack(\"<H\",proxyb[2:4])\nfmt = '>' + str(pbcnt[0]) + 'I'\ntmp=proxyb[4:4*(pbcnt[0]+1)]\nprint \"------------proxys at index 0x2B, count= %d------------\" %(pbcnt[0])\nxxxxx=struct.unpack(fmt,tmp)\nfor i in xxxxx:\n    a=struct.pack(\">I\",i)\n    ip=\"\"\n    for i in range(4):\n        ip+=str(ord(a[i]))\n        if i!=3:\n            ip+=\".\"\n    print ip\n\n\nprint \"-------------------------onion info--------------\"    \nif len(c2)!=0:\n    for i in c2:\n        \n        pos=i.find(\".onion\")\n\n        for j in range(0,pos,16):\n            print i[j:16+j]+\".onion\"\nelse:\n    print \"Don't find the onion c2\"\n```"}]],"markups":[],"sections":[[10,0],[1,"p",[]]],"ghostVersion":"3.0"}