New Threat: ZHtrap botnet implements honeypot to facilitate finding more victims
<!--kg-card-begin: markdown--><h2 id="overview">Overview</h2>
<p>In the security community, when people talk about honeypot, by default we would assume this is one of the most used toolkits for security researchers to <code>lure the bad guys</code>. But recently we came across a botnet <strong>uses honeypot to harvest other infected devices</strong>, which is quite interesting.<br>
From February 28, 2021, our BotMon system started to see one IP (<code>107.189.30.190</code>) continuously spreading a batch of unknown ELF samples. After analysis, we confirmed that these samples belonged to a new botnet family, we named it <code>ZHtrap</code>, and it has the following characters.</p>
<ul>
<li>ZHtrap's propagation uses 4 Nday vulnerabilities, the main function is DDoS and scanning, while integrating some backdoor features.</li>
<li>Zhtrap sets up honeypot on the infected device.</li>
<li>Zhtrap takes snapshots for the victim devices, and disables the running of new commands based on the snapshot, thus achieving exclusivity over the device.</li>
<li>For C2 communication, ZHtrap takes a cue from the <a href="__GHOST_URL__/matryosh-botnet-is-spreading/"><strong>Matryosh</strong></a> botnet we previous reported, using Tor and cloud-based configuration.</li>
</ul>
<h2 id="zhtrapfullintroduction">ZHtrap Full Introduction</h2>
<p>ZHtrap's code is based on Mirai and supports x86, ARM, MIPS and other major CPU architectures. However, compared to Mirai, ZHtrap has changed a lot, which is reflected in the following aspects.</p>
<ul>
<li>In terms of instructions, a checksum mechanism has been added</li>
<li>In terms of scanning propagation, <code>the distinction between real devices and honeypots has been added</code>.</li>
<li>In terms of encryption algorithm, a set of multiple XOR encryption algorithm has been redesigned.</li>
<li>In terms of host behavior, it can turn the compromised device into a simple honeypot and implement a set of process control mechanisms</li>
<li>In terms of network architecture, it borrows some implementations of our previously exposed Matryosh botnet</li>
</ul>
<p>The basic process is shown in the following diagram.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_brief.png" width="860px"  /><br>
In terms of functionality, in addition to DDoS attacks and scanning, ZHtrap also implements backdoor functionality, which increases the harmfulness of the family. specific functions of ZHtrap include</p>
<ul>
<li>Process control</li>
<li>Reversing Shell</li>
<li>DDoS attacks</li>
<li>Telnet scanning</li>
<li>Exploit propagation</li>
<li>Turn infected devices into honeypot</li>
<li>Download and execute Payload</li>
</ul>
<p>The ZHtrap samples we have captured so far can be divided into 3 versions according to their functions: v1, v2 and v3.</p>
<ul>
<li>v2 is based on v1 with the addition of vulnerability exploitation.</li>
<li>v3 is based on v2 with the deletion of the network infrastructure.</li>
</ul>
<p>Their relationship is shown in the figure below, and the analysis in this paper is based on the most fully functional v2 version.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_version-2.png"  width="860px" /></p>
<p>Compared to other botnets we have analyzed before, the most interesting part of ZHtrap is its ability to <strong>turn infected devices into honeypot</strong>. Honeypots are usually used by security researchers as a tool to capture attacks, such as collecting scans, exploits, and samples. But this time around, we found that ZHtrap uses a similar technique by integrating a scanning IP collection module, and the collected IPs are used as targets in its own scanning module, with the basic process shown below.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_trap.png" width="860px"  /></p>
<p>ZHtrap will listen to 23 designated ports (as shown in the above figure), and if it finds an IP connecting to these ports it will record it as a scanner IP, and all the recorded IPs will be scanned in its own scanningmodule, so that the target addresses used in the ZHtrap scanning process will have 2 sources.</p>
<ul>
<li>Randomly generated IPs.</li>
<li>Scanner IPs captured by the above module.</li>
</ul>
<p>More details on this can be found in the sample analysis section below.</p>
<h2 id="samplereverseanalysis">Sample Reverse Analysis</h2>
<p>Here we pick ZHtrap v2's X86 CPU architecture sample for analysis, with the following basic information.</p>
<blockquote>
<p>MD5：5370e0b9484cb25fb3d5a4b648b5c203<br>
ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped<br>
Packer：None</p>
</blockquote>
<p>After ZHtrap successfully infects the device, it creates a single instanceby binding local port, then decrypts the encrypted resource information and renames the process to <code>/bin/ZoneSec</code>, and then prints out the following message in the Console<code>ZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.] com/ZoneHax</code>. Next, a network request is made to get the address of the resource server for the scanning &amp; propagation phase. Then listen to 23 pre-de-fined ports to turn the device into a &quot;honeypot&quot;, waiting for other compromised devices to hit the port.It uses 4 Nday vulnerability to achieve worm-like propagation. Fi-nally, it communicates with the TOR C2 and waits for the execution of the commands issued by the C2.</p>
<h3 id="0x0encryptionalgorithm">0x0 Encryption algorithm</h3>
<p>ZHtrap uses a relatively rare multiple xor encryption algorithm to hide resource information.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_xor.png" width="860px"  /><br>
The equivalent python implementation is shown below.</p>
<pre><code>xor_key_lst = [0x51, 0x6A, 0x66, 0x6A, 0x78, 0x53, 0x52, 0x44, 0x46, 0x47, 0x53, 0x46, 0x44, 0x64, 0x66] #QjfjxSRDFGSFDdf
xor_key = 0xD00DBAAF

def decode(content):
		desc_lst = []
		plaintext=&quot;&quot;
 		xor_key_lst_idx = 1
		for idx in range(0, len(content)):
			desc_lst.append(chr(content[idx] ^ (xor_key % 0xFF) ^ xor_key_lst[xor_key_lst_idx - 1] ^ (xor_key_lst_idx + idx)))
			xor_key_lst_idx += 1
			if xor_key_lst_idx &gt;= len(xor_key_lst):
				xor_key_lst_idx = 0
		else:
			print(&quot;&quot;.join(desc_lst))
</code></pre>
<p>Take the following ciphertext as an example</p>
<pre><code>cipher =[

  0x42, 0x69, 0x0B, 0x4C, 0x57, 0x76, 0x72, 0x60, 0x6B, 0x79, 
  0x6A, 0x39, 0x6C, 0x58, 0x55, 0x7B, 0x10, 0x49, 0x5C, 0x41, 
  0x75, 0x2A, 0x32, 0x43, 0x48, 0x4C, 0x5B, 0x45, 0x61, 0x56, 
  0x26, 0x6E, 0x68, 0x27, 0x78, 0x5C, 0x11, 0x45, 0x48, 0x4D, 
  0x4B, 0x54, 0x49, 0x71, 0x22, 0x43, 0x7D, 0x3C, 0x75, 0x69, 
  0x4E, 0x50, 0x51, 0x42, 0x2A, 0x79, 0x2B, 0x39, 0x17, 0x70, 
  0x50, 0x6E, 0x4F, 0x49, 0x51, 0x2E, 0x36, 0x2E, 0x28, 0x2F, 
  0x69, 0x6D, 0x69, 0x42, 0x51, 0x7C, 0x40, 0x5E, 0x02, 0x01, 
  0x3E, 0x27, 0x37, 0x20, 0x32, 0x13, 0x09, 0x1A, 0x39, 0x57, 
  0x2A, 0x12, 0x04, 0x63, 0x27, 0x09, 0x14, 0x11, 0x11, 0x07, 
  0x06, 0x51, 0x1C, 0x36, 0x2B, 0x5C, 0x14, 0x2F, 0x3C, 0x27, 
  0x27, 0x0D, 0x0C
]
</code></pre>
<p>After decryption, we get the following plaintext, which is exactly the in the Console prompt</p>
<pre><code>ZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.]com/ZoneHax
</code></pre>
<p>There are 3 encrypted messages in the current sample, and the decrypted message is shown below, where <code>/proc/</code> and <code>/stat</code> are used in the next section on process control.</p>
<table>
<thead>
<tr>
<th>index</th>
<th>plaintext</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>/stat</td>
</tr>
<tr>
<td>1</td>
<td>/proc/</td>
</tr>
<tr>
<td>0</td>
<td>ZH infected your shit.....</td>
</tr>
</tbody>
</table>
<h3 id="0x1processcontrol">0x1 Process Control</h3>
<p>ZHtrap realizes process control through the whitelist and snapshot mechanism to aceive the exclusivity of the device. A process whose executable path contains the following path is considered a whitelisted process. After ZHtrap is started, it will first obtain the current process list, and then terminate the non-whitelisted processes through kill -9. So it is clear that ZHtrap does not want to destroy the normal operation of the system.</p>
<pre><code>/bin
/sbin
/user/bin
/user/sbin
</code></pre>
<p>Next, a snapshot of the processes is created for the system, after which the newly created processes are compared with the snapshot and those that do not meet the requirements are removed. In this way the whole system remains under ZHtrap's control, and even if the administrator finds a problem with the device, many system management tools are no longer working properly, making maintenance a difficult task.</p>
<h6 id="cleanupnonwhitelistedprocesses">Clean up non-whitelisted processes</h6>
<p>When ZHtrap runs, it iterates through the current processes on the system and reads the value of starttime, item 22 in &quot;/proc/pid/stat&quot;. This value is divided by <code>_SC_CLK_TCK</code> to get how long the process was started after the kernel started. The value of _SC_CLK_TCK is usually equal to 100, <code>10000/_SC_CLK_TCK</code> results in 100 seconds.So all processes started after 100 seconds of kernel startup will be checked, and if the process path is not in the whitelist, the process will be killed.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_procwhite.png" width="860px"  /></p>
<h6 id="createasnapshotoftheprocessesandcleanupanynewprocessesthatarentonthemark">Create a snapshot of the processes and clean up any new processes that aren't on the mark.</h6>
<p>After cleaning the non-whitelisted processes, ZHtrap considers the sys-tem to be in a &quot;pure state&quot; and creates a process snapshot for the system first.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_procsnap.png" width="860px"  /><br>
After that, all newly created processes will be compared with the process snapshot, and any processes that do not meet the requirements will be directly killed.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_proctest.png"   /></p>
<h2 id="0x2getresourceserver">0x2 Get resource server</h2>
<p>ZHtrap uses the following code snippet to get the address of the resource server (ResServ), this process can be divided into two steps, thefirst step is to establish communication with the Tor domain, the sec-ond step sends &quot;GET /sfkjdkfdj.txt&quot; request.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_rescode.png" width="860px"  /></p>
<h6 id="establishcommunicationwiththetordomain">Establish communication with the Tor domain</h6>
<p>ZHtrap takes a cue from the Matryosh botnet, first requesting a DNS TXT record from the remote host <code>0xdeadbeef.tw</code> to get the list of Tor proxies in the figure below.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_torproxy.png" width="860px"  /><br>
It will pick one proxy and send <code>domain:port</code>, if the proxy returns<code>05 00 00 01 00 00 00 00 00 00 00</code>, that means the communication has been successfully established. Then send a subsequent GET request to get the resource server address (107.189.30.190), and the network traffic in the following figure clearly reflects this process.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_respkg.png" width="860px"  /></p>
<h6 id="theroleofresourceserver">The role of Resource server</h6>
<img src="__GHOST_URL__/content/images/2021/03/zh_respopu.png" width="860px"  />
As can be seen by the IDA cross-reference in the above figure, the ResServ has two functions.
<ul>
<li>Acting as Reporter Server, providing information upload service for the Telnet scanning process</li>
<li>Acting as Downloader Server, to provide sample download services for the process of vulnerability propagation</li>
</ul>
<h2 id="0x3honeypot">0x3 Honeypot</h2>
<p>ZHtrap first creates two pipes for information transfer, and then implements a simple honeypot listening on the following 23 ports<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_honcode.png" width="860px"  /><br>
The actual effect is as follows.</p>
<img src="__GHOST_URL__/content/images/2021/03/zh_honshow.png" width="860px"  />
When these ports of the device are accessed, ZHtrap passes the IP address of the visitor through the pipe for its own telnet scanning & vul-nerability scanning module to use.
<h6 id="whydoesitdothis">Why does it do this?</h6>
<p>We speculate that ZHtrap's authors had this in mind.</p>
<blockquote>
<p>Many botnets implement worm-like scan propagation, and when ZHtrap's honeypot port is accessed, its source is most likely a device that has been infected by another botnet. This device can be infected, there must be flaws, I can use my scanning mechanism to scan again.This could be a good chance that I can implant my bot  samples, and then with the process control function, I can have total control, is’t  that <strong>awesome</strong>?</p>
</blockquote>
<h2 id="0x4telnetscan">0x4 Telnet scan</h2>
<p>ZHtrap uses Telnet scanning to collect devices that use weak passwords. The sources of the scanned objects are of the following 2 types.</p>
<ul>
<li>Randomly generated IPs</li>
<li>Passively received IPs delivered by the above mentioned honeypot</li>
</ul>
<p>And these two group of IPs get to treat differently.</p>
<p>For <code>category 1</code> IPs, SYN port probing is used.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_tela.png" width="860px"  /><br>
For <code>category 2</code> IPs, use the <code>connect</code> function directly.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_telb.png" width="860px"  /><br>
When the target's port 23 is found to be open, try to log in using the hardcoded credentials list, and pass the following code back to the resource server for the IP, port, account, password, etc. that can successfully log in.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_telrep.png" width="860px"  /><br>
During the login attempt, ZHtrap will ask the scanned device to execute the following command:</p>
<pre><code>enable
linuxshell
system
bash
ls /home
ps aux
/bin/busybox ZONESEC

</code></pre>
<p>The device type is then determined based on the returned information,and the device will be regarded as a honeypot when it contains the following string.</p>
<table>
<thead>
<tr>
<th>string</th>
<th>honeypot</th>
</tr>
</thead>
<tbody>
<tr>
<td>Jun22</td>
<td><a href="https://github.com/cowrie/cowrie">cowrie</a></td>
</tr>
<tr>
<td>Jun23</td>
<td>cowrie</td>
</tr>
<tr>
<td>phil</td>
<td>cowrie</td>
</tr>
<tr>
<td>sshd:</td>
<td>cowrie</td>
</tr>
<tr>
<td>richard</td>
<td>cowrie</td>
</tr>
<tr>
<td>@LocalHost:]</td>
<td>cowrie</td>
</tr>
<tr>
<td>Welcome to EmbyLinux 3.13.0-24-generic</td>
<td><a href="https://github.com/Phype/telnet-iot-honeypot">telnet-iot-honeypot</a></td>
</tr>
<tr>
<td>If it is a honeypot, the device information will be reported to the resource server via port 2231.</td>
<td></td>
</tr>
<tr>
<td><img src="__GHOST_URL__/content/images/2021/03/zh_telrpa.png" alt="zh_ddos" loading="lazy"></td>
<td></td>
</tr>
</tbody>
</table>
<p>If it is a real device, the device information will be reported to the resource server on port 1282<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_telrpb.png" alt="zh_ddos" loading="lazy"></p>
<h2 id="0x5vulnerabilityscanningpropagation">0x5 Vulnerability scanning &amp; propagation</h2>
<p>ZHtrap uses the following 4 samples of Nday vulnerability propagation</p>
<ul>
<li><a href="https://www.exploit-db.com/exploits/41471/">JAWS_DVR_RCE</a></li>
<li><a href="https://www.exploit-db.com/exploits/43055">NETGEAR</a></li>
<li><a href="https://www.exploit-db.com/exploits/39596/">CCTV_DVR_RCE</a></li>
<li><a href="https://www.exploit-db.com/exploits/37169/">CVE-2014-8361</a></li>
</ul>
<p>First construct a SYN packet to probe whether the device's port is open, and the list of supported ports (exp_port) is shown below</p>
<table>
<thead>
<tr>
<th>80</th>
<th>8080</th>
<th>8081</th>
<th>8083</th>
<th>5500</th>
</tr>
</thead>
<tbody>
<tr>
<td>60001</td>
<td>52869</td>
<td>8089</td>
<td>8090</td>
<td>8000</td>
</tr>
<tr>
<td>81</td>
<td>82</td>
<td>83</td>
<td>84</td>
<td>85</td>
</tr>
<tr>
<td>8888</td>
<td>8181</td>
<td>8443</td>
<td>5555</td>
<td></td>
</tr>
<tr>
<td>Then a &quot;GET /&quot; request is sent to obtain information about the service running on the port.</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><img src="__GHOST_URL__/content/images/2021/03/zh_expreq.png" width="860px"  /></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td>The following code snippet is then used to determine whether the banner information returned by the service is the target device.</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td><img src="__GHOST_URL__/content/images/2021/03/zh_expresp.png" width="860px"  /></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>Finally, according to the banner information, select the corresponding vulnerability, and ResServ to assemble a valid payload to try to implant.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_expsend.png" width="860px"  /></p>
<p>As with the telnet scanning process, the sources of the scanned objectsare of the following two types.</p>
<ul>
<li>Active randomly generated IP</li>
<li>Passively receive IPs delivered by the honeypot</li>
</ul>
<p>For the first category of IPs, an exp_port is randomly selected for probing, and the relationship between IPs and exp_ports is 1 to 1.<br>
For the second category of IPs, all exp_ports are probed, and the relationship between IPs and exp_ports is 1 to N. The network traffic in the following figure illustrates this situation visually.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_exppkg.png" width="860px"  /></p>
<h2 id="0x6c2communication">0x6 C2 communication</h2>
<p>ZHtrap uses Tor C2 and therefore has to communicate with C2 with the help of a proxy. This process is described in section above and will not be repeated here. The network traffic shown in the figure below indicates that the connection with C2 has been successfully established.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_torconne.png" width="860px"  /><br>
Next, the following code snippet is used to send a registration message to C2<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_reg.png" alt="zh_ddos" loading="lazy"><br>
The actual network traffic generated is as follows.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_regpkg.png" width="860px"  /></p>
<p>The command packet of ZHtrap consists of two packets, the first packet is the header and the second packet is the body, where the format of the header is</p>
<pre><code>//5 bytes ,big endian
struct header
{

	uint16	body_len;
	uint8	cmd_type;		 
	uint16	checksum;
}
</code></pre>
<p>Take the above registration packet traffic as an example, the meaning of each field is as follows.</p>
<pre><code>header:	
	00 07        				-- length of body
	e5			 				-- hardcode,cmd type,&quot;e5&quot;,
	1a fa		 				-- tcp/ip checksum of (&quot;00 07 e5 00 00&quot;)
body:
	5a 6f 6e 65 53 65 53		-- body string,&quot;ZoneSec&quot; 
</code></pre>
<p>After sending the registration packet, bot starts to wait for C2 to send the command, and when the header of the command packet successfully passes the check, it selects the corresponding processing flow based on the command type specified by the third byte in the header.<br>
<img src="__GHOST_URL__/content/images/2021/03/zh_func.png" width="860px"  /><br>
It can be seen that a total of five kinds of commands are supported at present, and the correspondence between command codes and functions is shown in the following table.</p>
<table>
<thead>
<tr>
<th>Value</th>
<th>Function</th>
</tr>
</thead>
<tbody>
<tr>
<td>0x22</td>
<td>heartbeat</td>
</tr>
<tr>
<td>0x45</td>
<td>exit</td>
</tr>
<tr>
<td>0x89</td>
<td>download&amp;exec payload</td>
</tr>
<tr>
<td>0xF5</td>
<td>reverse shell</td>
</tr>
<tr>
<td>0xFE</td>
<td>DDoS</td>
</tr>
<tr>
<td>Taking heartbeat as an example, the heartbeat packet network flow in the following figure verifies our analysis.</td>
<td></td>
</tr>
<tr>
<td><img src="__GHOST_URL__/content/images/2021/03/zh_heart.png" width="860px"  /></td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="contactus">Contact us</h2>
<p>Readers are always welcomed to reach us on <a href="https://twitter.com/360Netlab">twitter</a>, or email to netlabat 360dot cn.</p>
<h2 id="ioc">IOC</h2>
<p>Sample MD5</p>
<pre><code>5370e0b9484cb25fb3d5a4b648b5c203
6c7cfbe0277e2ca0cbe7157cad7c663e
f1f70dc1274112ae5287ceb06f096d0e
9dded61f7de47409bc00e74c0a12210e
7b593fbbd6f81a3e9a2043a46949879d
ba17282481acca9636c5d01f5c2dd069
</code></pre>
<p>URL</p>
<pre><code>0xdeadbeef.tw
h5vwy6o32sdcsa5xurde35dqw5sf3cdsoeewqqxmhoyzsvar4u6ooead.onion:8080
</code></pre>
<p>C2</p>
<pre><code>oemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:3000
</code></pre>
<p>Reporter</p>
<pre><code>107.189.30.190:1282
107.189.30.190:2231
</code></pre>
<p>Proxy Ip</p>
<pre><code>51.178.54.234:9095
51.79.157.89:9095
167.114.185.33:9095
147.135.208.44:9095
198.245.53.58:9095
142.93.247.244:9050
66.70.188.235:9095
139.99.134.95:9095
144.217.243.21:9095
46.101.61.9:9050
</code></pre>
<p>Downloader</p>
<pre><code>x86 arm5 arm6 arm7 mips
hxxp://107.189.30.190/bins/z.{CPU_ARCH}
oemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:8080/z.{CPU_ARCH}
</code></pre>
<!--kg-card-end: markdown-->
Overview


In the security community, when people talk about honeypot, by default we would assume this is one of the most used toolkits for security researchers to lure the bad guys. But recently we came across a botnet uses honeypot to harvest other infected devices, which is quite interesting.

From February 28, 2021, our BotMon system started to see one IP (107.189.30.190) continuously spreading a batch of unknown ELF samples. After analysis, we confirmed that these samples belonged to a new botnet family, we named it ZHtrap, and it has the following characters.


 * ZHtrap's propagation uses 4 Nday vulnerabilities, the main function is DDoS and scanning, while integrating some backdoor features.
 * Zhtrap sets up honeypot on the infected device.
 * Zhtrap takes snapshots for the victim devices, and disables the running of new commands based on the snapshot, thus achieving exclusivity over the device.
 * For C2 communication, ZHtrap takes a cue from the Matryosh botnet we previous reported, using Tor and cloud-based configuration.



ZHtrap Full Introduction


ZHtrap's code is based on Mirai and supports x86, ARM, MIPS and other major CPU architectures. However, compared to Mirai, ZHtrap has changed a lot, which is reflected in the following aspects.


 * In terms of instructions, a checksum mechanism has been added
 * In terms of scanning propagation, the distinction between real devices and honeypots has been added.
 * In terms of encryption algorithm, a set of multiple XOR encryption algorithm has been redesigned.
 * In terms of host behavior, it can turn the compromised device into a simple honeypot and implement a set of process control mechanisms
 * In terms of network architecture, it borrows some implementations of our previously exposed Matryosh botnet


The basic process is shown in the following diagram.



In terms of functionality, in addition to DDoS attacks and scanning, ZHtrap also implements backdoor functionality, which increases the harmfulness of the family. specific functions of ZHtrap include


 * Process control
 * Reversing Shell
 * DDoS attacks
 * Telnet scanning
 * Exploit propagation
 * Turn infected devices into honeypot
 * Download and execute Payload


The ZHtrap samples we have captured so far can be divided into 3 versions according to their functions: v1, v2 and v3.


 * v2 is based on v1 with the addition of vulnerability exploitation.
 * v3 is based on v2 with the deletion of the network infrastructure.


Their relationship is shown in the figure below, and the analysis in this paper is based on the most fully functional v2 version.




Compared to other botnets we have analyzed before, the most interesting part of ZHtrap is its ability to turn infected devices into honeypot. Honeypots are usually used by security researchers as a tool to capture attacks, such as collecting scans, exploits, and samples. But this time around, we found that ZHtrap uses a similar technique by integrating a scanning IP collection module, and the collected IPs are used as targets in its own scanning module, with the basic process shown below.




ZHtrap will listen to 23 designated ports (as shown in the above figure), and if it finds an IP connecting to these ports it will record it as a scanner IP, and all the recorded IPs will be scanned in its own scanningmodule, so that the target addresses used in the ZHtrap scanning process will have 2 sources.


 * Randomly generated IPs.
 * Scanner IPs captured by the above module.


More details on this can be found in the sample analysis section below.



Sample Reverse Analysis


Here we pick ZHtrap v2's X86 CPU architecture sample for analysis, with the following basic information.





MD5：5370e0b9484cb25fb3d5a4b648b5c203

ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped

Packer：None



After ZHtrap successfully infects the device, it creates a single instanceby binding local port, then decrypts the encrypted resource information and renames the process to /bin/ZoneSec, and then prints out the following message in the ConsoleZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.] com/ZoneHax. Next, a network request is made to get the address of the resource server for the scanning & propagation phase. Then listen to 23 pre-de-fined ports to turn the device into a "honeypot", waiting for other compromised devices to hit the port.It uses 4 Nday vulnerability to achieve worm-like propagation. Fi-nally, it communicates with the TOR C2 and waits for the execution of the commands issued by the C2.



0x0 Encryption algorithm


ZHtrap uses a relatively rare multiple xor encryption algorithm to hide resource information.



The equivalent python implementation is shown below.


xor_key_lst = [0x51, 0x6A, 0x66, 0x6A, 0x78, 0x53, 0x52, 0x44, 0x46, 0x47, 0x53, 0x46, 0x44, 0x64, 0x66] #QjfjxSRDFGSFDdf
xor_key = 0xD00DBAAF

def decode(content):
		desc_lst = []
		plaintext=""
 		xor_key_lst_idx = 1
		for idx in range(0, len(content)):
			desc_lst.append(chr(content[idx] ^ (xor_key % 0xFF) ^ xor_key_lst[xor_key_lst_idx - 1] ^ (xor_key_lst_idx + idx)))
			xor_key_lst_idx += 1
			if xor_key_lst_idx >= len(xor_key_lst):
				xor_key_lst_idx = 0
		else:
			print("".join(desc_lst))



Take the following ciphertext as an example


cipher =[

  0x42, 0x69, 0x0B, 0x4C, 0x57, 0x76, 0x72, 0x60, 0x6B, 0x79, 
  0x6A, 0x39, 0x6C, 0x58, 0x55, 0x7B, 0x10, 0x49, 0x5C, 0x41, 
  0x75, 0x2A, 0x32, 0x43, 0x48, 0x4C, 0x5B, 0x45, 0x61, 0x56, 
  0x26, 0x6E, 0x68, 0x27, 0x78, 0x5C, 0x11, 0x45, 0x48, 0x4D, 
  0x4B, 0x54, 0x49, 0x71, 0x22, 0x43, 0x7D, 0x3C, 0x75, 0x69, 
  0x4E, 0x50, 0x51, 0x42, 0x2A, 0x79, 0x2B, 0x39, 0x17, 0x70, 
  0x50, 0x6E, 0x4F, 0x49, 0x51, 0x2E, 0x36, 0x2E, 0x28, 0x2F, 
  0x69, 0x6D, 0x69, 0x42, 0x51, 0x7C, 0x40, 0x5E, 0x02, 0x01, 
  0x3E, 0x27, 0x37, 0x20, 0x32, 0x13, 0x09, 0x1A, 0x39, 0x57, 
  0x2A, 0x12, 0x04, 0x63, 0x27, 0x09, 0x14, 0x11, 0x11, 0x07, 
  0x06, 0x51, 0x1C, 0x36, 0x2B, 0x5C, 0x14, 0x2F, 0x3C, 0x27, 
  0x27, 0x0D, 0x0C
]



After decryption, we get the following plaintext, which is exactly the in the Console prompt


ZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.]com/ZoneHax



There are 3 encrypted messages in the current sample, and the decrypted message is shown below, where /proc/ and /stat are used in the next section on process control.





index
plaintext




2
/stat


1
/proc/


0
ZH infected your shit.....






0x1 Process Control


ZHtrap realizes process control through the whitelist and snapshot mechanism to aceive the exclusivity of the device. A process whose executable path contains the following path is considered a whitelisted process. After ZHtrap is started, it will first obtain the current process list, and then terminate the non-whitelisted processes through kill -9. So it is clear that ZHtrap does not want to destroy the normal operation of the system.


/bin
/sbin
/user/bin
/user/sbin



Next, a snapshot of the processes is created for the system, after which the newly created processes are compared with the snapshot and those that do not meet the requirements are removed. In this way the whole system remains under ZHtrap's control, and even if the administrator finds a problem with the device, many system management tools are no longer working properly, making maintenance a difficult task.


Clean up non-whitelisted processes


When ZHtrap runs, it iterates through the current processes on the system and reads the value of starttime, item 22 in "/proc/pid/stat". This value is divided by _SC_CLK_TCK to get how long the process was started after the kernel started. The value of _SC_CLK_TCK is usually equal to 100, 10000/_SC_CLK_TCK results in 100 seconds.So all processes started after 100 seconds of kernel startup will be checked, and if the process path is not in the whitelist, the process will be killed.




Create a snapshot of the processes and clean up any new processes that aren't on the mark.


After cleaning the non-whitelisted processes, ZHtrap considers the sys-tem to be in a "pure state" and creates a process snapshot for the system first.



After that, all newly created processes will be compared with the process snapshot, and any processes that do not meet the requirements will be directly killed.





0x2 Get resource server


ZHtrap uses the following code snippet to get the address of the resource server (ResServ), this process can be divided into two steps, thefirst step is to establish communication with the Tor domain, the sec-ond step sends "GET /sfkjdkfdj.txt" request.




Establish communication with the Tor domain


ZHtrap takes a cue from the Matryosh botnet, first requesting a DNS TXT record from the remote host 0xdeadbeef.tw to get the list of Tor proxies in the figure below.



It will pick one proxy and send domain:port, if the proxy returns05 00 00 01 00 00 00 00 00 00 00, that means the communication has been successfully established. Then send a subsequent GET request to get the resource server address (107.189.30.190), and the network traffic in the following figure clearly reflects this process.




The role of Resource server



As can be seen by the IDA cross-reference in the above figure, the ResServ has two functions.

 * Acting as Reporter Server, providing information upload service for the Telnet scanning process
 * Acting as Downloader Server, to provide sample download services for the process of vulnerability propagation



0x3 Honeypot


ZHtrap first creates two pipes for information transfer, and then implements a simple honeypot listening on the following 23 ports



The actual effect is as follows.



When these ports of the device are accessed, ZHtrap passes the IP address of the visitor through the pipe for its own telnet scanning & vul-nerability scanning module to use.


Why does it do this?


We speculate that ZHtrap's authors had this in mind.





Many botnets implement worm-like scan propagation, and when ZHtrap's honeypot port is accessed, its source is most likely a device that has been infected by another botnet. This device can be infected, there must be flaws, I can use my scanning mechanism to scan again.This could be a good chance that I can implant my bot samples, and then with the process control function, I can have total control, is’t that awesome?




0x4 Telnet scan


ZHtrap uses Telnet scanning to collect devices that use weak passwords. The sources of the scanned objects are of the following 2 types.


 * Randomly generated IPs
 * Passively received IPs delivered by the above mentioned honeypot


And these two group of IPs get to treat differently.


For category 1 IPs, SYN port probing is used.



For category 2 IPs, use the connect function directly.



When the target's port 23 is found to be open, try to log in using the hardcoded credentials list, and pass the following code back to the resource server for the IP, port, account, password, etc. that can successfully log in.



During the login attempt, ZHtrap will ask the scanned device to execute the following command:


enable
linuxshell
system
bash
ls /home
ps aux
/bin/busybox ZONESEC




The device type is then determined based on the returned information,and the device will be regarded as a honeypot when it contains the following string.





string
honeypot




Jun22
cowrie


Jun23
cowrie


phil
cowrie


sshd:
cowrie


richard
cowrie


@LocalHost:]
cowrie


Welcome to EmbyLinux 3.13.0-24-generic
telnet-iot-honeypot


If it is a honeypot, the device information will be reported to the resource server via port 2231.










If it is a real device, the device information will be reported to the resource server on port 1282





0x5 Vulnerability scanning & propagation


ZHtrap uses the following 4 samples of Nday vulnerability propagation


 * JAWS_DVR_RCE
 * NETGEAR
 * CCTV_DVR_RCE
 * CVE-2014-8361


First construct a SYN packet to probe whether the device's port is open, and the list of supported ports (exp_port) is shown below





80
8080
8081
8083
5500




60001
52869
8089
8090
8000


81
82
83
84
85


8888
8181
8443
5555



Then a "GET /" request is sent to obtain information about the service running on the port.













The following code snippet is then used to determine whether the banner information returned by the service is the target device.
















Finally, according to the banner information, select the corresponding vulnerability, and ResServ to assemble a valid payload to try to implant.




As with the telnet scanning process, the sources of the scanned objectsare of the following two types.


 * Active randomly generated IP
 * Passively receive IPs delivered by the honeypot


For the first category of IPs, an exp_port is randomly selected for probing, and the relationship between IPs and exp_ports is 1 to 1.

For the second category of IPs, all exp_ports are probed, and the relationship between IPs and exp_ports is 1 to N. The network traffic in the following figure illustrates this situation visually.





0x6 C2 communication


ZHtrap uses Tor C2 and therefore has to communicate with C2 with the help of a proxy. This process is described in section above and will not be repeated here. The network traffic shown in the figure below indicates that the connection with C2 has been successfully established.



Next, the following code snippet is used to send a registration message to C2



The actual network traffic generated is as follows.




The command packet of ZHtrap consists of two packets, the first packet is the header and the second packet is the body, where the format of the header is


//5 bytes ,big endian
struct header
{

	uint16	body_len;
	uint8	cmd_type;		 
	uint16	checksum;
}



Take the above registration packet traffic as an example, the meaning of each field is as follows.


header:	
	00 07        				-- length of body
	e5			 				-- hardcode,cmd type,"e5",
	1a fa		 				-- tcp/ip checksum of ("00 07 e5 00 00")
body:
	5a 6f 6e 65 53 65 53		-- body string,"ZoneSec" 



After sending the registration packet, bot starts to wait for C2 to send the command, and when the header of the command packet successfully passes the check, it selects the corresponding processing flow based on the command type specified by the third byte in the header.



It can be seen that a total of five kinds of commands are supported at present, and the correspondence between command codes and functions is shown in the following table.





Value
Function




0x22
heartbeat


0x45
exit


0x89
download&exec payload


0xF5
reverse shell


0xFE
DDoS


Taking heartbeat as an example, the heartbeat packet network flow in the following figure verifies our analysis.











Contact us


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



IOC


Sample MD5


5370e0b9484cb25fb3d5a4b648b5c203
6c7cfbe0277e2ca0cbe7157cad7c663e
f1f70dc1274112ae5287ceb06f096d0e
9dded61f7de47409bc00e74c0a12210e
7b593fbbd6f81a3e9a2043a46949879d
ba17282481acca9636c5d01f5c2dd069



URL


0xdeadbeef.tw
h5vwy6o32sdcsa5xurde35dqw5sf3cdsoeewqqxmhoyzsvar4u6ooead.onion:8080



C2


oemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:3000



Reporter


107.189.30.190:1282
107.189.30.190:2231



Proxy Ip


51.178.54.234:9095
51.79.157.89:9095
167.114.185.33:9095
147.135.208.44:9095
198.245.53.58:9095
142.93.247.244:9050
66.70.188.235:9095
139.99.134.95:9095
144.217.243.21:9095
46.101.61.9:9050



Downloader


x86 arm5 arm6 arm7 mips
hxxp://107.189.30.190/bins/z.{CPU_ARCH}
oemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:8080/z.{CPU_ARCH}


{"version":"0.3.1","atoms":[],"cards":[["markdown",{"markdown":"## Overview\nIn the security community, when people talk about honeypot, by default we would assume this is one of the most used toolkits for security researchers to ```lure the bad guys```. But recently we came across a botnet **uses honeypot to harvest other infected devices**, which is quite interesting. \nFrom February 28, 2021, our BotMon system started to see one IP (```107.189.30.190```) continuously spreading a batch of unknown ELF samples. After analysis, we confirmed that these samples belonged to a new botnet family, we named it ``ZHtrap``, and it has the following characters.\n- ZHtrap's propagation uses 4 Nday vulnerabilities, the main function is DDoS and scanning, while integrating some backdoor features.\n- Zhtrap sets up honeypot on the infected device.\n- Zhtrap takes snapshots for the victim devices, and disables the running of new commands based on the snapshot, thus achieving exclusivity over the device.\n- For C2 communication, ZHtrap takes a cue from the [**Matryosh**](__GHOST_URL__/matryosh-botnet-is-spreading/) botnet we previous reported, using Tor and cloud-based configuration.\n## ZHtrap Full Introduction\nZHtrap's code is based on Mirai and supports x86, ARM, MIPS and other major CPU architectures. However, compared to Mirai, ZHtrap has changed a lot, which is reflected in the following aspects.\n- In terms of instructions, a checksum mechanism has been added\n- In terms of scanning propagation, ```the distinction between real devices and honeypots has been added```.\n- In terms of encryption algorithm, a set of multiple XOR encryption algorithm has been redesigned.\n- In terms of host behavior, it can turn the compromised device into a simple honeypot and implement a set of process control mechanisms\n- In terms of network architecture, it borrows some implementations of our previously exposed Matryosh botnet\n\nThe basic process is shown in the following diagram.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_brief.png\" width=\"860px\"  />\nIn terms of functionality, in addition to DDoS attacks and scanning, ZHtrap also implements backdoor functionality, which increases the harmfulness of the family. specific functions of ZHtrap include\n- Process control\n- Reversing Shell\n- DDoS attacks\n- Telnet scanning\n- Exploit propagation\n- Turn infected devices into honeypot\n- Download and execute Payload\n\nThe ZHtrap samples we have captured so far can be divided into 3 versions according to their functions: v1, v2 and v3. \n- v2 is based on v1 with the addition of vulnerability exploitation.\n- v3 is based on v2 with the deletion of the network infrastructure. \n\nTheir relationship is shown in the figure below, and the analysis in this paper is based on the most fully functional v2 version.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_version-2.png\"  width=\"860px\" />\n\nCompared to other botnets we have analyzed before, the most interesting part of ZHtrap is its ability to **turn infected devices into honeypot**. Honeypots are usually used by security researchers as a tool to capture attacks, such as collecting scans, exploits, and samples. But this time around, we found that ZHtrap uses a similar technique by integrating a scanning IP collection module, and the collected IPs are used as targets in its own scanning module, with the basic process shown below.\n <img src=\"__GHOST_URL__/content/images/2021/03/zh_trap.png\" width=\"860px\"  />\n\nZHtrap will listen to 23 designated ports (as shown in the above figure), and if it finds an IP connecting to these ports it will record it as a scanner IP, and all the recorded IPs will be scanned in its own scanningmodule, so that the target addresses used in the ZHtrap scanning process will have 2 sources.\n- Randomly generated IPs.\n- Scanner IPs captured by the above module.\n\nMore details on this can be found in the sample analysis section below.\n\n## Sample Reverse Analysis\nHere we pick ZHtrap v2's X86 CPU architecture sample for analysis, with the following basic information.\n> MD5：5370e0b9484cb25fb3d5a4b648b5c203 \n> ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped  \n> Packer：None\n\n\nAfter ZHtrap successfully infects the device, it creates a single instanceby binding local port, then decrypts the encrypted resource information and renames the process to ```/bin/ZoneSec```, and then prints out the following message in the Console```ZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.] com/ZoneHax```. Next, a network request is made to get the address of the resource server for the scanning & propagation phase. Then listen to 23 pre-de-fined ports to turn the device into a \"honeypot\", waiting for other compromised devices to hit the port.It uses 4 Nday vulnerability to achieve worm-like propagation. Fi-nally, it communicates with the TOR C2 and waits for the execution of the commands issued by the C2.\n\n### 0x0 Encryption algorithm\nZHtrap uses a relatively rare multiple xor encryption algorithm to hide resource information.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_xor.png\" width=\"860px\"  />\nThe equivalent python implementation is shown below.\n```\nxor_key_lst = [0x51, 0x6A, 0x66, 0x6A, 0x78, 0x53, 0x52, 0x44, 0x46, 0x47, 0x53, 0x46, 0x44, 0x64, 0x66] #QjfjxSRDFGSFDdf\nxor_key = 0xD00DBAAF\n\ndef decode(content):\n\t\tdesc_lst = []\n\t\tplaintext=\"\"\n \t\txor_key_lst_idx = 1\n\t\tfor idx in range(0, len(content)):\n\t\t\tdesc_lst.append(chr(content[idx] ^ (xor_key % 0xFF) ^ xor_key_lst[xor_key_lst_idx - 1] ^ (xor_key_lst_idx + idx)))\n\t\t\txor_key_lst_idx += 1\n\t\t\tif xor_key_lst_idx >= len(xor_key_lst):\n\t\t\t\txor_key_lst_idx = 0\n\t\telse:\n\t\t\tprint(\"\".join(desc_lst))\n```\nTake the following ciphertext as an example\n```\ncipher =[\n\n  0x42, 0x69, 0x0B, 0x4C, 0x57, 0x76, 0x72, 0x60, 0x6B, 0x79, \n  0x6A, 0x39, 0x6C, 0x58, 0x55, 0x7B, 0x10, 0x49, 0x5C, 0x41, \n  0x75, 0x2A, 0x32, 0x43, 0x48, 0x4C, 0x5B, 0x45, 0x61, 0x56, \n  0x26, 0x6E, 0x68, 0x27, 0x78, 0x5C, 0x11, 0x45, 0x48, 0x4D, \n  0x4B, 0x54, 0x49, 0x71, 0x22, 0x43, 0x7D, 0x3C, 0x75, 0x69, \n  0x4E, 0x50, 0x51, 0x42, 0x2A, 0x79, 0x2B, 0x39, 0x17, 0x70, \n  0x50, 0x6E, 0x4F, 0x49, 0x51, 0x2E, 0x36, 0x2E, 0x28, 0x2F, \n  0x69, 0x6D, 0x69, 0x42, 0x51, 0x7C, 0x40, 0x5E, 0x02, 0x01, \n  0x3E, 0x27, 0x37, 0x20, 0x32, 0x13, 0x09, 0x1A, 0x39, 0x57, \n  0x2A, 0x12, 0x04, 0x63, 0x27, 0x09, 0x14, 0x11, 0x11, 0x07, \n  0x06, 0x51, 0x1C, 0x36, 0x2B, 0x5C, 0x14, 0x2F, 0x3C, 0x27, \n  0x27, 0x0D, 0x0C\n]\n```\nAfter decryption, we get the following plaintext, which is exactly the in the Console prompt\n```\nZH infected your shit, message me on discord to compare assets ($reiko#0095), researchers hmu twitter[.]com/ZoneHax\n```\nThere are 3 encrypted messages in the current sample, and the decrypted message is shown below, where ```/proc/``` and ```/stat``` are used in the next section on process control.\n| index | plaintext                                                    |\n| ----- | ------------------------------------------------------------ |\n| 2     | /stat                                                        |\n| 1     | /proc/                                                       |\n| 0     | ZH infected your shit.....|\n\n### 0x1 Process Control\n\nZHtrap realizes process control through the whitelist and snapshot mechanism to aceive the exclusivity of the device. A process whose executable path contains the following path is considered a whitelisted process. After ZHtrap is started, it will first obtain the current process list, and then terminate the non-whitelisted processes through kill -9. So it is clear that ZHtrap does not want to destroy the normal operation of the system.\n```\n/bin\n/sbin\n/user/bin\n/user/sbin\n```\nNext, a snapshot of the processes is created for the system, after which the newly created processes are compared with the snapshot and those that do not meet the requirements are removed. In this way the whole system remains under ZHtrap's control, and even if the administrator finds a problem with the device, many system management tools are no longer working properly, making maintenance a difficult task.\n\n###### Clean up non-whitelisted processes\nWhen ZHtrap runs, it iterates through the current processes on the system and reads the value of starttime, item 22 in \"/proc/pid/stat\". This value is divided by ```_SC_CLK_TCK``` to get how long the process was started after the kernel started. The value of _SC_CLK_TCK is usually equal to 100, ```10000/_SC_CLK_TCK``` results in 100 seconds.So all processes started after 100 seconds of kernel startup will be checked, and if the process path is not in the whitelist, the process will be killed.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_procwhite.png\" width=\"860px\"  />\n\n###### Create a snapshot of the processes and clean up any new processes that aren't on the mark.\nAfter cleaning the non-whitelisted processes, ZHtrap considers the sys-tem to be in a \"pure state\" and creates a process snapshot for the system first.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_procsnap.png\" width=\"860px\"  />\nAfter that, all newly created processes will be compared with the process snapshot, and any processes that do not meet the requirements will be directly killed.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_proctest.png\"   />\n## 0x2 Get resource server\nZHtrap uses the following code snippet to get the address of the resource server (ResServ), this process can be divided into two steps, thefirst step is to establish communication with the Tor domain, the sec-ond step sends \"GET /sfkjdkfdj.txt\" request.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_rescode.png\" width=\"860px\"  />\n###### Establish communication with the Tor domain\nZHtrap takes a cue from the Matryosh botnet, first requesting a DNS TXT record from the remote host ```0xdeadbeef.tw``` to get the list of Tor proxies in the figure below.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_torproxy.png\" width=\"860px\"  />\nIt will pick one proxy and send ```domain:port```, if the proxy returns```05 00 00 01 00 00 00 00 00 00 00```, that means the communication has been successfully established. Then send a subsequent GET request to get the resource server address (107.189.30.190), and the network traffic in the following figure clearly reflects this process.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_respkg.png\" width=\"860px\"  />\n###### The role of Resource server\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_respopu.png\" width=\"860px\"  />\nAs can be seen by the IDA cross-reference in the above figure, the ResServ has two functions.\n\n- Acting as Reporter Server, providing information upload service for the Telnet scanning process\n- Acting as Downloader Server, to provide sample download services for the process of vulnerability propagation\n\n## 0x3 Honeypot\nZHtrap first creates two pipes for information transfer, and then implements a simple honeypot listening on the following 23 ports\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_honcode.png\" width=\"860px\"  />\nThe actual effect is as follows.\n\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_honshow.png\" width=\"860px\"  />\nWhen these ports of the device are accessed, ZHtrap passes the IP address of the visitor through the pipe for its own telnet scanning & vul-nerability scanning module to use.\n\n###### Why does it do this?\nWe speculate that ZHtrap's authors had this in mind.\n> Many botnets implement worm-like scan propagation, and when ZHtrap's honeypot port is accessed, its source is most likely a device that has been infected by another botnet. This device can be infected, there must be flaws, I can use my scanning mechanism to scan again.This could be a good chance that I can implant my bot  samples, and then with the process control function, I can have total control, is’t  that **awesome**?\n\n## 0x4 Telnet scan\nZHtrap uses Telnet scanning to collect devices that use weak passwords. The sources of the scanned objects are of the following 2 types.\n- Randomly generated IPs\n- Passively received IPs delivered by the above mentioned honeypot\n\n\nAnd these two group of IPs get to treat differently.\n\nFor ```category 1``` IPs, SYN port probing is used.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_tela.png\" width=\"860px\"  />\nFor ```category 2``` IPs, use the ```connect``` function directly.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_telb.png\" width=\"860px\"  />\nWhen the target's port 23 is found to be open, try to log in using the hardcoded credentials list, and pass the following code back to the resource server for the IP, port, account, password, etc. that can successfully log in.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_telrep.png\" width=\"860px\"  />\nDuring the login attempt, ZHtrap will ask the scanned device to execute the following command:\n```\nenable\nlinuxshell\nsystem\nbash\nls /home\nps aux\n/bin/busybox ZONESEC\n\n```\nThe device type is then determined based on the returned information,and the device will be regarded as a honeypot when it contains the following string.\n| string                                 | honeypot                                                     |\n| -------------------------------------- | ------------------------------------------------------------ |\n| Jun22                                  | [cowrie](https://github.com/cowrie/cowrie)                   |\n| Jun23                                  | cowrie                                                       |\n| phil                                   | cowrie                                                       |\n| sshd:                                  | cowrie                                                       |\n| richard                                | cowrie                                                       |\n| @LocalHost:]                           | cowrie                                                       |\n| Welcome to EmbyLinux 3.13.0-24-generic | [telnet-iot-honeypot](https://github.com/Phype/telnet-iot-honeypot) |\nIf it is a honeypot, the device information will be reported to the resource server via port 2231.\n![zh_ddos](__GHOST_URL__/content/images/2021/03/zh_telrpa.png)\n\nIf it is a real device, the device information will be reported to the resource server on port 1282\n![zh_ddos](__GHOST_URL__/content/images/2021/03/zh_telrpb.png)\n\n## 0x5 Vulnerability scanning & propagation\nZHtrap uses the following 4 samples of Nday vulnerability propagation\n- [JAWS_DVR_RCE](https://www.exploit-db.com/exploits/41471/)    \n- [NETGEAR]( https://www.exploit-db.com/exploits/43055 ) \n- [CCTV_DVR_RCE]( https://www.exploit-db.com/exploits/39596/)\n- [CVE-2014-8361](https://www.exploit-db.com/exploits/37169/)\n\n\n\nFirst construct a SYN packet to probe whether the device's port is open, and the list of supported ports (exp_port) is shown below\n| 80    | 8080  | 8081 | 8083 | 5500 |\n| ----- | ----- | ---- | ---- | ---- |\n| 60001 | 52869 | 8089 | 8090 | 8000 |\n| 81    | 82    | 83   | 84   | 85   |\n| 8888  | 8181  | 8443 | 5555 |      |\nThen a \"GET /\" request is sent to obtain information about the service running on the port.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_expreq.png\" width=\"860px\"  />\nThe following code snippet is then used to determine whether the banner information returned by the service is the target device.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_expresp.png\" width=\"860px\"  />\n\nFinally, according to the banner information, select the corresponding vulnerability, and ResServ to assemble a valid payload to try to implant.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_expsend.png\" width=\"860px\"  />\n\nAs with the telnet scanning process, the sources of the scanned objectsare of the following two types.\n- Active randomly generated IP\n- Passively receive IPs delivered by the honeypot\n\nFor the first category of IPs, an exp_port is randomly selected for probing, and the relationship between IPs and exp_ports is 1 to 1.\nFor the second category of IPs, all exp_ports are probed, and the relationship between IPs and exp_ports is 1 to N. The network traffic in the following figure illustrates this situation visually.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_exppkg.png\" width=\"860px\"  />\n\n## 0x6 C2 communication\nZHtrap uses Tor C2 and therefore has to communicate with C2 with the help of a proxy. This process is described in section above and will not be repeated here. The network traffic shown in the figure below indicates that the connection with C2 has been successfully established.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_torconne.png\" width=\"860px\"  />\nNext, the following code snippet is used to send a registration message to C2\n![zh_ddos](__GHOST_URL__/content/images/2021/03/zh_reg.png)\nThe actual network traffic generated is as follows.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_regpkg.png\" width=\"860px\"  />\n\nThe command packet of ZHtrap consists of two packets, the first packet is the header and the second packet is the body, where the format of the header is \n\n```\n//5 bytes ,big endian\nstruct header\n{\n\n\tuint16\tbody_len;\n\tuint8\tcmd_type;\t\t \n\tuint16\tchecksum;\n}\n```\n\nTake the above registration packet traffic as an example, the meaning of each field is as follows.\n```\nheader:\t\n\t00 07        \t\t\t\t-- length of body\n\te5\t\t\t \t\t\t\t-- hardcode,cmd type,\"e5\",\n\t1a fa\t\t \t\t\t\t-- tcp/ip checksum of (\"00 07 e5 00 00\")\nbody:\n\t5a 6f 6e 65 53 65 53\t\t-- body string,\"ZoneSec\" \n```\nAfter sending the registration packet, bot starts to wait for C2 to send the command, and when the header of the command packet successfully passes the check, it selects the corresponding processing flow based on the command type specified by the third byte in the header.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_func.png\" width=\"860px\"  />\nIt can be seen that a total of five kinds of commands are supported at present, and the correspondence between command codes and functions is shown in the following table.\n| Value | Function              |\n| ----- | --------------------- |\n| 0x22  | heartbeat             |\n| 0x45  | exit                  |\n| 0x89  | download&exec payload |\n| 0xF5  | reverse shell         |\n| 0xFE  | DDoS                  |\nTaking heartbeat as an example, the heartbeat packet network flow in the following figure verifies our analysis.\n<img src=\"__GHOST_URL__/content/images/2021/03/zh_heart.png\" width=\"860px\"  />\n## Contact us\nReaders are always welcomed to reach us on [twitter](https://twitter.com/360Netlab), or email to netlabat 360dot cn.\n## IOC\nSample MD5\n```\n5370e0b9484cb25fb3d5a4b648b5c203\n6c7cfbe0277e2ca0cbe7157cad7c663e\nf1f70dc1274112ae5287ceb06f096d0e\n9dded61f7de47409bc00e74c0a12210e\n7b593fbbd6f81a3e9a2043a46949879d\nba17282481acca9636c5d01f5c2dd069\n```\n\nURL\n```\n0xdeadbeef.tw\nh5vwy6o32sdcsa5xurde35dqw5sf3cdsoeewqqxmhoyzsvar4u6ooead.onion:8080\n```\nC2\n```\noemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:3000\n```\n\nReporter\n```\n107.189.30.190:1282\n107.189.30.190:2231\n```\n\nProxy Ip\n```\n51.178.54.234:9095\n51.79.157.89:9095\n167.114.185.33:9095\n147.135.208.44:9095\n198.245.53.58:9095\n142.93.247.244:9050\n66.70.188.235:9095\n139.99.134.95:9095\n144.217.243.21:9095\n46.101.61.9:9050\n```\n\nDownloader\n```\nx86 arm5 arm6 arm7 mips\nhxxp://107.189.30.190/bins/z.{CPU_ARCH}\noemojwe5loscudytzfo273nkdvalf7mumctwcm42zyutoo6tpfjsphyd.onion:8080/z.{CPU_ARCH}\n```"}]],"markups":[],"sections":[[10,0],[1,"p",[]]],"ghostVersion":"3.0"}