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

<channel>
	<title>Mirai &#8211; @Forensicxs</title>
	<atom:link href="https://www.forensicxs.com/tag/mirai/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.forensicxs.com</link>
	<description>Ethical Hacking &#124; Cybersecurity</description>
	<lastBuildDate>Fri, 04 Feb 2022 18:54:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>Mirai : the &#8220;open source&#8221; Botnet</title>
		<link>https://www.forensicxs.com/mirai-the-open-source-botnet/</link>
					<comments>https://www.forensicxs.com/mirai-the-open-source-botnet/#respond</comments>
		
		<dc:creator><![CDATA[Forensicxs]]></dc:creator>
		<pubDate>Sun, 15 Mar 2020 19:19:44 +0000</pubDate>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[Anna-senpai]]></category>
		<category><![CDATA[Botnet]]></category>
		<category><![CDATA[Code review]]></category>
		<category><![CDATA[Daniel Kaye]]></category>
		<category><![CDATA[IoT security]]></category>
		<category><![CDATA[Mirai]]></category>
		<category><![CDATA[Paras Jha]]></category>
		<guid isPermaLink="false">https://www.forensicxs.com/?p=291</guid>

					<description><![CDATA[There has been many good articles about the Mirai Botnet since its first appearance in 2016. As the threat from Botnet is growing, and a good understanding of a typical Botnet is a must for risk mitigation, I have decided to publish an article with the goal to produce a synthesis, focused on the technical &#8230; <p class="link-more"><a href="https://www.forensicxs.com/mirai-the-open-source-botnet/" class="more-link">Continue reading<span class="screen-reader-text"> "Mirai : the &#8220;open source&#8221; Botnet"</span></a></p>]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66.png" alt="" class="wp-image-479" width="567" height="102" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66.png 992w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-300x54.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-768x138.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-830x149.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-230x41.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-350x63.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/capture-66-480x86.png 480w" sizes="(max-width: 567px) 100vw, 567px" /></figure>



<p>There has been many good articles about the <strong><span class="has-inline-color has-luminous-vivid-orange-color">Mirai Botnet</span></strong> since its first appearance in 2016. As the threat from Botnet is growing, and a good understanding of a typical Botnet is a must for risk mitigation, I have decided to publish an article with the goal to produce a synthesis, focused on the technical aspects but also the dire consequences for the creators of the Botnet. Since I&#8217;m explicitely using a bunch of data from security researchers and previously published articles, I&#8217;m refering to these sources at the end of my write-up. Thanks a lot to these guys for their production !</p>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">What is Mirai ?</span></strong></p>



<p>Mirai is a malware that hijacks and turns IoT devices into remotely controlled bots, that can be used as part of a botnet in large-scale network attacks such as DDoS attacks. Its primary purpose is to target IoT devices such as cameras, home routers, smart devices and so on</p>



<p>It is one of the most predominant <strong><span class="has-inline-color has-luminous-vivid-orange-color">DDoS-capable IoT malware</span></strong> of the last few years, and it changed the world perception of IoT devices security</p>



<p>What’s remarkable about these record-breaking attacks is that they were  carried out via small, innocuous IoT devices.  At its peak, Mirai  infected over 600,000 vulnerable IoT devices </p>



<p>Mirai identifies <strong><span class="has-inline-color has-luminous-vivid-orange-color">vulnerable IoT devices</span></strong> using a table of more than 60 common factory default usernames and passwords, and logs into them to infect them with the Mirai malware. Infected devices will continue to function normally, except for occasional sluggishness and an increased use of<a href="https://en.wikipedia.org/wiki/Bandwidth_(computing)"> </a>bandwidth. Upon infection Mirai will identify any &#8220;competing&#8221; malware, remove it from memory, and block remote administration ports</p>



<p>Victim IoT devices are identified by first entering a rapid scanning phase where it send TCP probes to pseudo-random IPv4 addresses on Telnet TCP ports 23 and 2323. If an IoT device responds to the probe, the attack then enters into a brute-force login phase. During this phase, the attacker tries to establish a Telnet connection using predetermined username and password pairs from a list of credentials. Most of these logins are default usernames and passwords from the IoT vendor. If the IoT device allows the Telnet access, the victim&#8217;s IP, along with the successfully used credential is sent to a collection server. </p>



<p>There are hundreds of thousands of IoT devices which use <strong><span class="has-inline-color has-luminous-vivid-orange-color">default settings</span></strong>, making them vulnerable to infection. Once infected, the device will monitor a command and control serve<a href="https://en.wikipedia.org/wiki/Botnet#Command_and_control">r</a> which indicates the target of an attack. One reason for the use of the large number of IoT devices is to bypass some anti-DDoS software which monitors the IP address of incoming requests and filters or sets up a block if it identifies an abnormal traffic pattern, for example, if too many requests come from a particular IP address </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture.png" alt="" class="wp-image-346" width="662" height="488" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture.png 962w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-300x221.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-768x567.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-830x613.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-230x170.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-350x258.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-480x354.png 480w" sizes="(max-width: 662px) 100vw, 662px" /></figure>



<p>The original Mirai malware has the following components :</p>



<div class="wp-block-group"><div class="wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow">
<ul><li><u>Bot</u> – infects and spreads to IoT devices through a brute-force  attack and contacts the command and control server (C2) to receive  commands from the botnet master/users to launch DoS attacks against  specified 
targets</li><li><u>Command and Control server</u> – used to control the infected IoT devices to launch DDoS attacks against specified targets</li><li><u>Report server</u> – listens for reports from an infected IoT device to  report a new potential victim IoT device. This report contains the  IP and login credentials of the new victim</li><li><u>Loader</u> – loads the bot to the new victim device</li></ul>
</div></div>



<p> </p>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Timeline of events</span></strong></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="271" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-1024x271.png" alt="" class="wp-image-299" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-1024x271.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-300x79.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-768x203.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-830x219.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-230x61.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-350x93.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline-480x127.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Timeline.png 1116w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>At its peak in September 2016, Mirai temporarily blocked several high-profile services such as OVH, Krebs on Secur<a rel="noreferrer noopener" href="https://krebsonsecurity.com/" target="_blank">i</a>ty and Dyn via massive DDoS. OVH reported that these attacks exceeded 1 Tbps—the largest on public record</p>



<p><u><strong><span class="has-inline-color has-vivid-red-color">OVH attack</span></strong></u> :  it seems that the attack lasted about a week and involved large, intermittent bursts of DDoS traffic</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/ovh.png" alt="" class="wp-image-316" width="205" height="158" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/ovh.png 601w, https://www.forensicxs.com/wp-content/uploads/2020/03/ovh-300x231.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/ovh-230x177.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/ovh-350x270.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/ovh-480x370.png 480w" sizes="(max-width: 205px) 100vw, 205px" /></figure>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Krebs on Security attack</span></strong></u> :  this is Brian Krebs’ blog. Krebs is a widely known independent journalist who  specializes in cyber-crime. Given Brian’s line of work, his blog has been targeted, unsurprisingly, by many DDoS attacks launched by the cyber-criminals he exposes. According to his telemetry, his blog suffered 269 DDOS attacks between July 2012  and September 2016. The Mirai assault was by  far the largest, topping out at 623 Gbps</p>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Source code release</span></strong></u> :  the leak of the source code was announced on the English-language hacking&nbsp;community <strong><a rel="noreferrer noopener" href="http://krebsonsecurity.com/?s=hackforums&amp;x=0&amp;y=0" target="_blank">Hackforums</a></strong>.  The Hackforums user who released the code, using&nbsp;the nickname&nbsp;“Anna-senpai,” told forum members the source code was being released in response to increased scrutiny from the security industry</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai.jpg" alt="" class="wp-image-331" width="515" height="630" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai.jpg 704w, https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai-245x300.jpg 245w, https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai-230x282.jpg 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai-350x429.jpg 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/anna-senpai-480x588.jpg 480w" sizes="(max-width: 515px) 100vw, 515px" /></figure>



<p>The source code can be found on GitHub : <a href="https://github.com/jgamblin/Mirai-Source-Code/tree/6a5941be681b839eeff8ece1de8b245bcd5ffb02/mirai" target="_blank" rel="noreferrer noopener" aria-label=" (opens in a new tab)">https://github.com/jgamblin/Mirai-Source-Code/tree/6a5941be681b839eeff8ece1de8b245bcd5ffb02/mirai</a></p>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-vivid-red-color"><u><strong>Dyn attack</strong></u> </mark>: on October 21, a Mirai attack targeted the popular DNS provider DYN. This event prevented Internet users from accessing many popular websites, including AirBnB, Amazon, Github, HBO, Netflix, Paypal, Reddit, and Twitter, by disturbing the DYN name-resolution service</p>



<p>According to an analysis from Cloudflare, this attack was linked to a larger set of  attacks against gaming platforms. They reached this conclusion by looking at the other targets of the DYN  variant which were are all gaming related, and consistent with the OVH attack as it was also targeted because it hosted specific game servers. All the prominent sites affected by the DYN attack were apparently just  the spectacular collateral damage of a war between gamers&#8230;!</p>



<p>Why is that ? For example, gamers playing Minecraft can build their own worlds by logging on to their favorite Minecraft server and play with  friends.  A large, successful Minecraft server with thousand players logging each day can easily earn the server’s owners huge amount of money, mainly from players renting space on the server to  build their Minecraft worlds, and purchasing in-game items and special  abilities</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-1024x715.png" alt="" class="wp-image-334" width="548" height="382" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-1024x715.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-300x210.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-768x536.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-830x580.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-230x161.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-350x244.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft-480x335.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/minecraft.png 1244w" sizes="(max-width: 548px) 100vw, 548px" /></figure>



<p>The Minecraft industry being competitive, Minecraft servers may be the target of DDoS attacks to attract players to other servers</p>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Liberia Lonestar attack</span></strong></u> : Lonestar Cell, one of the largest Liberian telecom operators started  to be targeted by Mirai on October 31. Over the next few months, it  suffered 616 attacks, the most of any Mirai victim. Cloudflare analyzed that they were orchestrated by a totally different actor than  the original author</p>



<p>This assessment was  confirmed when the author of one of the most aggressive Mirai variant &#8211; Daniel Kaye &#8211; confessed during his trial  that he was paid to takedown Lonestar. He acknowledged that an unnamed  Liberia’s ISP paid him $10,000 to take out its competitors</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia.jpg" alt="" class="wp-image-321" width="387" height="234" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia.jpg 860w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-300x181.jpg 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-768x464.jpg 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-830x502.jpg 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-230x139.jpg 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-350x212.jpg 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Liberia-480x290.jpg 480w" sizes="(max-width: 387px) 100vw, 387px" /></figure>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Deutsche Telekom attack</span></strong></u> : this outage was not due to yet another Mirai DDoS attack but instead due to a particularly innovative and buggy version of Mirai that knocked these devices offline while attempting to compromise them</p>



<p>What allowed this variant to infect so many routers was the addition  to its replication module of a router exploit targeting at the CPE WAN Management Protocol (CWMP).  The CWMP protocol is an HTTP-based protocol used by many Internet  providers to auto-configure and remotely manage home routers, modems,  and other customer-on-premises (CPE) equipment.</p>



<p>Beside its scale, this incident is significant because it  demonstrates how the weaponization of more complex IoT vulnerabilities  by hackers can lead to very potent botnets. This event should be a wake-up call and push toward making IoT auto-update  mandatory</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Import.png" alt="" class="wp-image-327" width="537" height="432" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Import.png 905w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-300x242.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-768x619.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-830x669.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-230x185.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-350x282.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Import-480x387.png 480w" sizes="(max-width: 537px) 100vw, 537px" /></figure>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Mirai author identified</span></strong></u> :  In the months following his website being taken offline, Brian Krebs  devoted hundreds of hours to investigating Anna-Senpai, the infamous Mirai author. In early January 2017, Brian announced that he believes Anna-senpai to be Paras Jha, a Rutgers student who apparently has been  involved in previous game-hacking related schemes</p>



<p>Brian also identified  Josia White as a person of interest. After being outed, Paras Jha and Josia White and another individual were questioned by authorities and plead guilty in federal court to a variety of charges, some including their activity related to Mirai</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Paras.png" alt="" class="wp-image-329" width="540" height="590" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Paras.png 783w, https://www.forensicxs.com/wp-content/uploads/2020/03/Paras-274x300.png 274w, https://www.forensicxs.com/wp-content/uploads/2020/03/Paras-768x841.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Paras-230x252.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Paras-350x383.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Paras-480x525.png 480w" sizes="(max-width: 540px) 100vw, 540px" /></figure>



<p>You should read the detailed story written by Brian Krebs about the identification of Mirai Botnet author here <a href="https://krebsonsecurity.com/2017/01/who-is-anna-senpai-the-mirai-worm-author/" target="_blank" rel="noreferrer noopener">https://krebsonsecurity.com/2017/01/who-is-anna-senpai-the-mirai-worm-author/</a>.  Krebs made a very good research work to link the numerous accounts, posts, messages from Paras Jha under multiple identities to track him down</p>



<p> It&#8217;s quite amazing to see : the greed, the competition between Botnet and DDoS software creators, botmasters trying to eliminate other IoT-based DDoS botnets that might compete for the same pool of vulnerable IoT devices, and also between DDoS protection companies as well as gaming serve providers, all this could lead to the rise &#8211; as a hacker &#8211; and fall of Paras Jha &#8211; as an individual. I find it&#8217;s quite a sad story at the end of the day&#8230;</p>



<p><u><strong><span class="has-inline-color has-vivid-red-color">Deutsche Telekom attacker identified</span></strong></u> : in November 2016, Daniel Kaye (aka BestBuy) the author of the Mirai  botnet variant that brought down Deutsche Telekom was arrested at the Luton airport</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye.jpg" alt="" class="wp-image-336" width="321" height="547" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye.jpg 495w, https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye-176x300.jpg 176w, https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye-230x392.jpg 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye-350x596.jpg 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Kaye-480x817.jpg 480w" sizes="(max-width: 321px) 100vw, 321px" /></figure>



<p>In July 2017 a few months after being extradited to Germany Daniel Kaye plead guilty and was sentenced to a one year and a half imprisonment with  suspension. During the trial, Daniel admitted that he never intended for the routers to cease functioning. He only wanted to silently control  them so he can use them as part of a DDoS botnet to increase his botnet  firepower. He also confessed being paid by  competitors to takedown Lonestar.</p>



<p>In Aug 2017 Daniel was extradited back to the UK to face extortion charges  after attempting to blackmail Lloyds and Barclays banks. According to  press reports, he asked the Lloyds to pay about £75,000 in bitcoins for  the attack to be called off</p>



<p>Here again an excellent article from Brian Krebs who led to the identification of the hacker : <a href="https://krebsonsecurity.com/2017/07/who-is-the-govrat-author-and-mirai-botmaster-bestbuy/" target="_blank" rel="noreferrer noopener">https://krebsonsecurity.com/2017/07/who-is-the-govrat-author-and-mirai-botmaster-bestbuy/</a></p>



<figure class="wp-block-image size-large"><img decoding="async" width="1024" height="498" src="https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-1024x498.png" alt="" class="wp-image-343" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-1024x498.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-300x146.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-768x373.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-1536x747.png 1536w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-830x404.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-230x112.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-350x170.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap-480x233.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/mindmap.png 1674w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Source code analysis</span></strong></p>



<p>At first, please note the authenticity of the code cannot be guaranteed versus the original one used for the 2016 attacks !</p>



<p>The download on the GitHub page provides you with the following file structure </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/file.png" alt="" class="wp-image-349" width="502" height="352" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/file.png 969w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-300x210.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-768x538.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-830x582.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-230x161.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-350x245.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/file-480x336.png 480w" sizes="(max-width: 502px) 100vw, 502px" /></figure>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><u><strong>dlr directory</strong></u> </mark>:  this folder contains files necessary to implement the<em> echoloader</em>, a small binary file (~1 KB) that suffices as wget and is used to upload the Mirai malware binary on weak devices </p>



<p><em>Release</em> subdirectory contains echoloader binary files, compiled for different architectures </p>



<figure class="wp-block-image size-large"><img decoding="async" width="190" height="242" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-1.png" alt="" class="wp-image-352"/></figure>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><u><strong>Mirai directory</strong></u> </mark>: this directory contains files necessary to implement the Mirai worm, the Reporting Server, and the CNC Server</p>



<p><em><strong><span class="has-inline-color has-vivid-red-color">bot</span></strong></em> subdirectory contains C source code files, which implement the Mirai worm that is executed on each bot.  In this subsection, the most relevant source code files of the folder are analyzed </p>



<figure class="wp-block-image size-large"><img decoding="async" width="233" height="483" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-2.png" alt="" class="wp-image-354" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-2.png 233w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-2-145x300.png 145w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-2-230x477.png 230w" sizes="(max-width: 233px) 100vw, 233px" /></figure>



<p><em><span class="has-inline-color has-vivid-red-color"><strong>./table.c~./table.h</strong></span></em> : the configuration of each bot is related to values stored in the<em> table</em> defined by .<em>/table.h</em>. Some of the most relevant entries in this table are the ones associated with the following index:</p>



<p>(i)<em>TABLE_CNC_DOMAIN</em>: domain name of the CNC Server (default =<em> cnc.changeme.com</em>)</p>



<p>(ii)<em>TABLE_CNC_PORT</em>: port number to connect to CNC Server (default =<em> 23</em>)</p>



<p>(iii)<em>TABLE_SCAN_CB_DOMAIN</em>: domain name of the Reporting Server (default =<em> report.changeme.com</em>)</p>



<p>(iv)<em>TABLE_SCAN_CB_PORT</em>: port number to connect to Reporting Server (default =<em> 48101</em>) </p>



<p> This table is initialized and accessed through functions defined in  .<em>/table.c</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-1024x118.png" alt="" class="wp-image-406" width="894" height="102" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-1024x118.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-300x34.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-768x88.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-830x95.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-230x26.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-350x40.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28-480x55.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-28.png 1411w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>Noteworthy is the initialization function<em> table_init( )</em> which has the aim of populating the table with obfuscated values, manually hard-coded using the output given by the tool<em> mirai/tools/enc.c</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27.png" alt="" class="wp-image-405" width="390" height="312" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27.png 622w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27-300x240.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27-230x184.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27-350x280.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-27-480x384.png 480w" sizes="(max-width: 390px) 100vw, 390px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./main.c</span></strong></em>. This is the entry point of the Mirai worm source code. The most relevant function is<em> main( )</em>, which performs the main tasks of the bot</p>



<p>First  of all, it prevents the watchdog (a Linux daemon used to monitor the  system and possibly reset it if /dev/watchdog is not closed correctly)  from rebooting the infected device, in order to avoid Mirai worm to be wiped off memory</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-29.png" alt="" class="wp-image-408" width="328" height="146" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-29.png 469w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-29-300x134.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-29-230x102.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-29-350x156.png 350w" sizes="(max-width: 328px) 100vw, 328px" /></figure>



<p>Subsequently, it invokes the function<em> ensure_single_instance( )</em>  defined in the same C file. This function has the aim of ensuring that  only a single instance of Mirai is in execution at the same time</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-1024x485.png" alt="" class="wp-image-410" width="663" height="314" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-1024x485.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-300x142.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-768x363.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-830x393.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-230x109.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-350x166.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30-480x227.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-30.png 1048w" sizes="(max-width: 663px) 100vw, 663px" /></figure>



<p class="has-text-align-left">The  behaviour of this function is based on a control port (named S<em>INGLE_INSTANCE_PORT</em> and setted to 48101 in .<em>/includes.h</em>) and can be explained as follows : the function tries to bind to the control port<em> (SINGLE_INSTANCE_PORT)</em>.  If the binding fails, most likely there is another instance of Mirai already running on the same device; thus, it tries to request the  process termination by connecting to that port. Anyway, it waits for a  while (5 seconds); then it forces the termination of the process bound to the control port invoking the function<em> killer_kill_by_port( )</em> (defined in .<em>/killer.c</em>)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64.png" alt="" class="wp-image-476" width="381" height="146" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64.png 522w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64-300x115.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64-230x88.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64-350x134.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-64-480x184.png 480w" sizes="(max-width: 381px) 100vw, 381px" /></figure>



<p>Finally, it recursively runs<em> ensure_single_instance( )</em> in order to successfully bind to the control port </p>



<p>Then, after performing some operations to hide its process from the system, the main function invokes<em> attack_init( )</em> (defined in .<em>/attack.c</em>) to initialize data structures used to perform attacks,<em> killer_init( )</em> (defined in .<em>/killer.c</em>) to start a background killer process, and<em> scanner_init( )</em> (defined in .<em>/scanner.c</em>) to start a background scanner process. Further details related to these functions are given below</p>



<p> At this point, the main function enters in an undefined loop and performs the following tasks :</p>



<p>It invokes the function<em> establish_connection( )</em> (defined in the same C file) that establishes the connection to the CNC Server on the port<em> TABLE_CNC_PORT</em> (whose value is stored in the bot table). In order to connect to it, first the CNC domain<em> TABLE_CNC_DOMAIN</em> (whose value is stored in the bot table) has to be resolved using the function<em> resolve_cnc_addr( )</em> defined in the same C file. This function basically invokes functions defined in .<em>/resolv.c</em> (in particular<em> resolv_lookup( )</em>) in order to perform a DNS request for the CNC domain to the Google DNS  Server (8.8.8.8) and to return then the corresponding IPv4 address back</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31.png" alt="" class="wp-image-412" width="511" height="312" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31.png 771w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31-300x184.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31-768x470.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31-230x141.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31-350x214.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-31-480x294.png 480w" sizes="(max-width: 511px) 100vw, 511px" /></figure>



<p>At this point, the main function loop waits for incoming messages from both the CNC Server and the control port<em> (SINGLE_INSTANCE_PORT)</em>. If a message from the control port is received, it kills itself by invoking:<em> scanner_kill( )</em> (defined in  .<em>/scanner.c</em>) to kill the scanner process,<em> killer_kill( )</em> (defined in .<em>/killer.c</em>) to terminate the killer process,<em> attack_kill_all( )</em> (defined in .<em>/attack.c</em>) to stop each ongoing attack (<em>does it actually work?</em> look at<em> attack.c</em> paragraph for further details) and finally<em> exit(0)</em>  to terminate the main process. On the other side, if a message from the CNC Server is received, it is processed by invoking the function<em> attack_parse( )</em> (defined in .<em>/attack.c</em>) </p>



<p><em><strong><span class="has-inline-color has-vivid-red-color">killer.c</span></strong> </em>: this C file contains all the functions used to kill  competing processes, eventually running on the infected system. For instance, the function<em> killer_kill_by_port( )</em> is used to terminate any process listening on the port given as input parameter</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32.png" alt="" class="wp-image-415" width="524" height="190" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32.png 807w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32-300x109.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32-768x278.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32-230x83.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32-350x127.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-32-480x174.png 480w" sizes="(max-width: 524px) 100vw, 524px" /></figure>



<p>Noteworthy is the function<em> killer_init( )</em>, which is invoked from<em> main( )</em>  in order to start the background killer process. In particular, it kills telnet (port 23), SSH (port 22), and HTTP (port 80) services by invoking<em> killer_kill_by_port( )</em> for each port number. Afterwards, it binds to ports 23, 22, and 80 preventing killed processes to  restart</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-33.png" alt="" class="wp-image-417" width="338" height="60" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-33.png 460w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-33-300x53.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-33-230x41.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-33-350x62.png 350w" sizes="(max-width: 338px) 100vw, 338px" /></figure>



<p>Subsequently, this function scans memory to find other known malwares, eventually in execution on the same device. If a malware is found, this function kills it, by directly invoking the Linux function<em> kill( )</em>. Mirai also lists existing processes and inspects their memory to look for potential traces of know viruses, and will kill corresponding processes (example below for Qbot)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65.png" alt="" class="wp-image-477" width="510" height="646" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65.png 699w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65-237x300.png 237w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65-230x292.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65-350x444.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-65-480x608.png 480w" sizes="(max-width: 510px) 100vw, 510px" /></figure>



<p><em><span class="has-inline-color has-vivid-red-color"><strong>scanner.c</strong></span></em> : this C file contains all the functions used by the scanner process to find new vulnerable IoT devices and report them to the Reporting Server. The most relevant function is<em> scanner_init( )</em> that is invoked from<em> main( )</em>, in order to start the scanning process in background. Its behaviour is articulated; hence, it is neatly analyzed below</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-34.png" alt="" class="wp-image-421" width="274" height="100" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-34.png 389w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-34-300x110.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-34-230x84.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-34-350x128.png 350w" sizes="(max-width: 274px) 100vw, 274px" /></figure>



<p>First  of all, the initialization function creates all the data structures needed in the scanning phase (such as raw socket, TPC header, and IPv4  header)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35.png" alt="" class="wp-image-422" width="482" height="554" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35.png 746w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35-261x300.png 261w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35-230x264.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35-350x402.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-35-480x551.png 480w" sizes="(max-width: 482px) 100vw, 482px" /></figure>



<p>Between them, extremely relevant is the<em> auth_table</em> which contains 62 pairs of default username and password, which will be used  to perform the dictionary attack. It is populated through the function<em> add_auth_entry( )</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-1024x561.png" alt="" class="wp-image-424" width="755" height="413" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-1024x561.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-300x164.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-768x421.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-830x455.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-230x126.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-350x192.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36-480x263.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-36.png 1265w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>The  pairs of default username and password are made of encoded strings which can be easily decoded with the cypher DEADBEEF</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-62.png" alt="" class="wp-image-471" width="242" height="248" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-62.png 383w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-62-293x300.png 293w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-62-230x235.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-62-350x358.png 350w" sizes="(max-width: 242px) 100vw, 242px" /></figure>



<p>Secondly, the function<em> scanner_init( )</em> enters in its main loop in which the main tasks are continuously performed</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37.png" alt="" class="wp-image-426" width="441" height="152" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37.png 705w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37-300x103.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37-230x79.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37-350x121.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-37-480x165.png 480w" sizes="(max-width: 441px) 100vw, 441px" /></figure>



<p>It sends a TPC SYN message to the port 23 of a random IP address obtained by invoking the function<em> get_random_ip( )</em>  (defined in the same C file)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-1024x662.png" alt="" class="wp-image-427" width="708" height="458" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-1024x662.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-300x194.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-768x496.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-830x536.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-230x149.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-350x226.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38-480x310.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-38.png 1139w" sizes="(max-width: 708px) 100vw, 708px" /></figure>



<p>If a SYN+ACK response is received, an attempt to establish the connection is performed</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39.png" alt="" class="wp-image-429" width="467" height="633" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39.png 660w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39-221x300.png 221w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39-230x312.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39-350x475.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-39-480x651.png 480w" sizes="(max-width: 467px) 100vw, 467px" /></figure>



<p>Once connected, the  scanner tries to remotely control the device gaining access to it. That is achieved through a kind of “state machine” ((implemented by a<em> switch</em> statement)) that properly reacts to each request received from the target and uses the dictionary of well-known credentials stored in the<em> auth_table</em>  to try to log in successfully</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40.png" alt="" class="wp-image-430" width="532" height="504" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40.png 814w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40-300x285.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40-768x729.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40-230x218.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40-350x332.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-40-480x456.png 480w" sizes="(max-width: 532px) 100vw, 532px" /></figure>



<p>If the authentication is successfully executed, the vulnerability result (IP address, port, username, and  password) is sent back to the Reporting Server by invoking<em> report_working( )</em>. The function<em> report_working( )</em> (defined in the same C file) firstly resolves the Reporting Server domain name<em> (TABLE_SCAN_CB_DOMAIN)</em> obtaining the corresponding IP address and secondly establishes the connection to it on the port<em> TABLE_SCAN_CB_PORT</em> and then sends the scan result to it</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41.png" alt="" class="wp-image-431" width="498" height="355" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41.png 760w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41-300x214.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41-230x164.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41-350x250.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-41-480x342.png 480w" sizes="(max-width: 498px) 100vw, 498px" /></figure>



<p> It is interesting to highlight that the function<em> get_random_ip( )</em>  (that returns a random IP address to be scanned) has an hard-coded list of addresses which are not allowed to be targeted</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-1024x422.png" alt="" class="wp-image-432" width="895" height="368" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-1024x422.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-300x124.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-768x317.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-830x342.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-230x95.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-350x144.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42-480x198.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-42.png 1458w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">attack.c</span></strong></em> : this C file contains functions used to parse, start, and abort attack commands received from the CNC Server.</p>



<p>The function<em> attack_init( )</em>, invoked from<em> main( )</em>, initializes a data structure with the list of attacks that the bot can perform. In particular, it contains a list of pairs (<em>ATTACK_VECTOR</em>,<em> ATTACK_FUNC</em>), where<em> ATTACK_VECTOR</em> is an integer that identifies the type of DDoS attack and<em> ATTACK_FUNC</em>  is a pointer to the function that implements the attack</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43.png" alt="" class="wp-image-435" width="432" height="300" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43.png 595w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43-300x208.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43-230x160.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43-350x243.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-43-480x333.png 480w" sizes="(max-width: 432px) 100vw, 432px" /></figure>



<p>Every time the CNC Server commands an attack with a given attack vector, the bot invokes the corresponding attack function. All the functions that implement the different types of DDoS attacks are defined in the corresponding file, named<em> attack_&lt;protocol_name&gt;.c</em>. For instance, the DDoS attack TCP SYN is identified by the vector<em> ATK_VEC_SYN</em> and it is implemented by the function<em> attack_tcp_syn( )</em> defined in the file<em> attack_tcp.c</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44.png" alt="" class="wp-image-436" width="679" height="250" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44.png 1022w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-300x110.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-768x283.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-830x305.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-230x85.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-350x129.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-44-480x177.png 480w" sizes="(max-width: 679px) 100vw, 679px" /></figure>



<p>The types of DDoS attacks that the Mirai bot implements by default are the ones whose ID is defined in<em> attack.h</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45.png" alt="" class="wp-image-437" width="585" height="188" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45.png 869w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-300x97.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-768x247.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-830x267.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-230x74.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-350x113.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-45-480x155.png 480w" sizes="(max-width: 585px) 100vw, 585px" /></figure>



<p>The function<em> attack_parse( )</em> is invoked from<em> main( )</em>  once the bot receives an attack command from the CNC Server. This function parses the attack command and checks if it is properly formatted and if the parsing is completed successfully, the function<em> attack_start( )</em>  is invoked. Finally, all the attack information (attack duration,  attack vector, targets, and options) is sent as input parameters</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-46.png" alt="" class="wp-image-438" width="270" height="392" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-46.png 391w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-46-207x300.png 207w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-46-230x334.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-46-350x508.png 350w" sizes="(max-width: 270px) 100vw, 270px" /></figure>



<p>The function<em> attack_start( )</em> actually starts the attack. It performs a lookup in the data structure initialized by<em> attack_init( )</em>,  in order to retrieve the pointer to the function that implements the requested attack, which is invoked with all the aforementioned attack  information as input parameters</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-1024x558.png" alt="" class="wp-image-439" width="754" height="411" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-1024x558.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-300x163.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-768x418.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-830x452.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-230x125.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-350x191.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47-480x261.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-47.png 1318w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>Interesting is the function<em> attack_kill_all( )</em>.  Apparently this function should scroll all the ongoing attacks and stop them if they are executing. Nevertheless, the list<em> attack_ongoing</em> is initialized with all zeros and never filled. Thus, it seems that this function does not actually stop any ongoing attack</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48.png" alt="" class="wp-image-440" width="338" height="259" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48.png 494w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48-300x230.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48-230x176.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48-350x268.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-48-480x367.png 480w" sizes="(max-width: 338px) 100vw, 338px" /></figure>



<p>A peculiarity related to Mirai bot attacks is that each bot uses common headers and standard user agents to perform HTTP DDoS attacks. This  allows emulating legitimate traffic, making it more difficult to reveal and filter botnet malicious packets. Moreover, the malware is able to recognize some simple DDoS protection solutions against HTTP DDoS  attacks (such as the ones offered by CloudFare and DOSArrest) and adapt the attack consequently</p>



<p><em><strong><span class="has-inline-color has-vivid-red-color">cnc</span></strong></em> subdirectory contains GO source code files, used to implement the CNC Server. It is the component of the Mirai infrastructure that is used by admins and users to control the botnet and to command bots </p>



<figure class="wp-block-image size-large"><img decoding="async" width="228" height="182" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-3.png" alt="" class="wp-image-355"/></figure>



<p>The most relevant source files stored in<em> cnc</em> folder are here thoroughly analyzed :</p>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./database.go</span></strong></em> : this file implements the API to access the database. For instance, it implements functions to check user credentials<em> (TryLogin( ))</em>, to create a new user<em> (CreateUser( ))</em>, to check if an attack is addressed to a target in the whitelist<em> (ContainsWhitelistedTargets( ))</em>, and so forth</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-1024x598.png" alt="" class="wp-image-368" width="641" height="373" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-1024x598.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-300x175.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-768x448.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-230x134.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-350x204.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9-480x280.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-9.png 1096w" sizes="(max-width: 641px) 100vw, 641px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./main.go</span></strong> :</em> this is the entry point of the CNC Server. It contains hard-coded strings that represent the information needed to access the  SQL database. It also initializes a global<em> ClientList</em> variable that is extremely relevant for the whole CNC Server</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11.png" alt="" class="wp-image-371" width="389" height="92" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11.png 598w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11-300x71.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11-230x54.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11-350x83.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-11-480x113.png 480w" sizes="(max-width: 389px) 100vw, 389px" /></figure>



<p>The most relevant function of this file is<em> main( )</em>, which initializes and starts the server. In particular, it sets the CNC Server listening on both TCP ports<strong> 23</strong> and<strong> 101</strong> of the local machine IP address</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12.png" alt="" class="wp-image-373" width="368" height="183" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12.png 569w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12-300x149.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12-230x114.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12-350x174.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-12-480x239.png 480w" sizes="(max-width: 368px) 100vw, 368px" /></figure>



<p>If a connection is received on port 23, the function<em> initialHandler( )</em> (defined in the same GO file) is invoked. The function<em> initialHandler( )</em> handles all connections received on TCP port<em> 23</em>.  In particular, depending on the first bytes received from the  connection, it distinguishes between bot and admin/user clients. If the first 3 bytes received are the hexadecimal sequence 0x<em>000000</em>, it is identified as bot connection and a new<em> bot</em> struct is created invoking the function<em> Handle( )</em> (defined in  .<em>/bot.go</em>) on it. Otherwise, an admin connection is recognized and a new<em> admin</em> struct is created calling the function<em> Handle( )</em> (defined in .<em>/admin.go</em>) on it </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13.png" alt="" class="wp-image-374" width="428" height="442" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13.png 754w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13-290x300.png 290w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13-230x238.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13-350x362.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-13-480x497.png 480w" sizes="(max-width: 428px) 100vw, 428px" /></figure>



<p>If a connection is received on port 101, the function<em> apiHandler( )</em> (defined in  .<em>/api.go</em>) is called.  The function<em> apiHandler( )</em> handles all connections received on TCP port<em> 101</em>. It is extremely simple because it just creates a new<em> api</em> struct and invokes the function<em> Handle( )</em> (defined in  .<em>/api.go</em>) on it</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-14.png" alt="" class="wp-image-375" width="243" height="80" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-14.png 394w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-14-300x99.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-14-230x76.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-14-350x115.png 350w" sizes="(max-width: 243px) 100vw, 243px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./admin.go</span></strong> </em>: this file contains all the functions related to the<em> admin</em> struct. The most relevant one is<em> Handle( )</em> which is invoked from<em> main( )</em>  each time a new admin/user connection is established on port 23 of the  CNC Server. It basically provides a command line interface that can be  used to perform several actions, such as creating a new user and  scheduling a new attack</p>



<p>First of all, this function prints some messages to the client as well as the content of the file<em> root/mirai/prompt.txt</em>.  This file is supposed to contain a server header that is shown every  time a new admin/user establishes a connection with the server. It is worth highlighting that both the code and the<em> prompt</em> file contain some Russian Unicode strings</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-1024x316.png" alt="" class="wp-image-378" width="671" height="206" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-1024x316.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-300x93.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-768x237.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-830x256.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-230x71.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-350x108.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15-480x148.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-15.png 1141w" sizes="(max-width: 671px) 100vw, 671px" /></figure>



<p> Subsequently, the<em> Handle( )</em> function asks the client to send the  login credentials (username and password). Once received, it checks them through the function<em> TryLogin( )</em> defined in  .<em>/dabatase.go</em>.  What is interesting here is that, if the authentication is completed  successfully, the server gives to the client the allusion of performing  some “security” operations, but it actually sends only some strings back  to the customer without performing any operation apart idling for a  while</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16.png" alt="" class="wp-image-380" width="590" height="191" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16.png 1005w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-300x97.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-768x249.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-830x269.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-230x75.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-350x114.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-16-480x156.png 480w" sizes="(max-width: 590px) 100vw, 590px" /></figure>



<p> At this point, the function enters in its main loop and repeatedly  processes commands received from the authenticated client. The supported commands are different between users and admins. An admin can add a new  user (sending the command<em> “adduser”</em>) or request the count of available bots (sending the command<em> “botcount”</em>). Both users and admins can close the connection (through command<em> “exit”</em> or<em> “quit”</em>) or schedule a new attack</p>



<p> Once an attack command is received, it is parsed invoking the function<em> NewAttack( )</em> (defined in  .<em>/attack.go</em>) which creates a new<em> attack</em> struct</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/image.png" alt="" class="wp-image-382" width="372" height="89" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/image.png 605w, https://www.forensicxs.com/wp-content/uploads/2020/03/image-300x71.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/image-230x55.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/image-350x83.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/image-480x114.png 480w" sizes="(max-width: 372px) 100vw, 372px" /></figure>



<p>Then the function<em> Build( )</em> (defined in  .<em>/attack.go</em>) is called on the struct, in order to prepare the sequence of bytes that has to be sent to each bot to perform the attack </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17.png" alt="" class="wp-image-383" width="327" height="56" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17.png 508w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17-300x51.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17-230x39.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17-350x60.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-17-480x82.png 480w" sizes="(max-width: 327px) 100vw, 327px" /></figure>



<p> Subsequently, the function<em> CanLaunchAttack( )</em> (defined in  .<em>/database.go</em>) is invoked, to check if the client is allowed to schedule the attack</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-1024x97.png" alt="" class="wp-image-385" width="818" height="77" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-1024x97.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-300x29.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-768x73.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-830x79.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-230x22.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-350x33.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18-480x46.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-18.png 1503w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>If the control is passed, the attack is inserted in the<em> history</em> table of the database </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-1024x42.png" alt="" class="wp-image-387" width="813" height="33" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-1024x42.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-300x12.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-768x32.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-830x34.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-230x9.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-350x14.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19-480x20.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-19.png 1482w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>and it is also queued in the<em> atkQueue</em> of the global<em> ClientList</em> variable (initialized in  .<em>/main.go</em>) by invoking the function<em> QueueBuf( )</em> (defined in  .<em>/clientList.go</em>). Once the attack is in the<em> atkQueue</em>, it is ready to be performed and it will start as soon as possible</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20.png" alt="" class="wp-image-388" width="507" height="63" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20.png 798w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20-300x37.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20-768x95.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20-230x29.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20-350x43.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-20-480x60.png 480w" sizes="(max-width: 507px) 100vw, 507px" /></figure>



<p><em> <strong><span class="has-inline-color has-vivid-red-color">./api.go</span></strong> </em>: this file contains all the functions related to the<em> api</em> struct. The most relevant one is the<em> Handle( )</em> function that is invoked from<em> main( )</em> each time a new connection is established on port 101 of the CNC Server. This function is very similar to<em> Handle( )</em> defined in  .<em>/admin.go</em>,  but in this case a complete command line interface is not provided.  Basically this function is in charge of processing a single request  received with a syntax where the<em> apiKey</em>  is a code assigned to a specific user/admin, in order to let him  schedule a new attack without logging in, while the other parameters are  as the ones already seen in  .<em>/admin.go</em>.</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-21.png" alt="" class="wp-image-390" width="237" height="175" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-21.png 383w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-21-300x222.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-21-230x170.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-21-350x259.png 350w" sizes="(max-width: 237px) 100vw, 237px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./bot.go</span></strong></em> : This file contains all the functions related to the<em> bot</em> struct. The most relevant one is the<em> Handle( )</em> function that is invoked from<em> main( )</em> each time a new bot connection is established on port 23 of the CNC Server. As soon as it starts, the function adds the bot to the<em> addQueue</em> of the global<em> ClientList</em> variable (initialized in .<em>/main.go</em>) by invoking the function<em> AddClient( )</em> (defined in .<em>/clientList.go</em>)  on it</p>



<p>Then it works as an echo server, continuously receiving from and  sending back to the bot a message of 2 bytes. If a problem with the endless interaction comes out, the bot is removed from the list of  available bots, by invoking the function<em> DelClient( )</em> (defined in .<em>/clientList.go</em>) on the global<em> ClientList</em> variable (initialized in .<em>/main.go</em>)  and the function ends</p>



<p>The behaviour implemented in this function is very simple but extremely relevant, since it ensures that each bot in the<em> clients</em> map of the global<em> ClientList</em> variable (initialized in .<em>/main.go</em>) is actually alive and connected to the CNC Server, ready to receive an attack command </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22.png" alt="" class="wp-image-392" width="452" height="204" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22.png 766w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22-300x136.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22-230x104.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22-350x158.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-22-480x217.png 480w" sizes="(max-width: 452px) 100vw, 452px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./attack.go</span></strong> </em>: this file contains functions and structs useful to handle attack information. Noteworthy are the maps<em> flagInfoLookup</em> and<em> attackInfo Lookup</em>.<em> flagInfoLookup</em> contains all flags that can be setted when an attack is commanded, in order to perform a fine-grained tuning of the attack.<em> attackInfoLookup</em>  contains the list of available DDoS attacks. Both these maps are checked when an attack command is parsed (i.e., in the function<em> NewAttack( )</em>)</p>



<p>The function<em> NewAttack( )</em> is invoked from<em> Handle( )</em> functions (defined in both .<em>/admin.go</em> and .<em>/api.go</em>)  when an attack command is received and it has to be parsed. This  function receives an attack command as input parameter and parses it. It  checks the syntax of the command and other logical constraints, for  example, if the requested attack is available (i.e., if it is defined in<em> attackInfoLookup</em>), if the targets are not in the whitelist, and if the specified flags are valid (i.e., if they are defined in<em> flagInfoLookup</em>). If all controls are passed, a struct containing all the information related to the attack is returned</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23.png" alt="" class="wp-image-394" width="540" height="84" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23.png 770w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23-300x47.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23-768x120.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23-230x36.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23-350x55.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-23-480x75.png 480w" sizes="(max-width: 540px) 100vw, 540px" /></figure>



<p>The function<em> Build( )</em> is usually invoked on the<em> attack</em> struct returned by<em> NewAttack( )</em>.  It is in charge of formatting all the information of the attack in a  proper sequence of bytes, which will be later sent directly to the bots.  Therefore, this function basically uses the attack information to  create the command that will be sent to the bots, in order to start the  attack</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24.png" alt="" class="wp-image-395" width="359" height="58" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24.png 511w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24-300x49.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24-230x37.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24-350x57.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-24-480x78.png 480w" sizes="(max-width: 359px) 100vw, 359px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./clientList.go</span></strong></em> : This file defines all the functions related to<em> ClientList</em>,  which is an extremely relevant struct for the proper working of the  whole CNC Server. It contains variables, needed to monitor bots and to  keep track of all data necessary to execute attacks, and a global variable of this type is initialized in  .<em>/main.go</em> as soon as the server runs</p>



<p>Noteworthy are the variables<em> clients</em> and<em> atkQueue</em> contained in the struct.<em> Clients</em> is a map that stores references to all bots available in the botnet and waiting for commands;<em> atkQueue</em> is the list of scheduled attacks that need to be performed as soon as possible</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-25.png" alt="" class="wp-image-398" width="224" height="174" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-25.png 388w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-25-300x234.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-25-230x179.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-25-350x272.png 350w" sizes="(max-width: 224px) 100vw, 224px" /></figure>



<p>The most relevant function in this file is<em> worker( )</em>, which basically is the executing core of the CNC Server. It is in charge of handling the different queues of the<em> ClientList</em>  struct and performing the proper operation for each element contained in these queues. This function consists in a single main loop that waits for any queue to be filled and as soon as a queue receives an element, the element is processed</p>



<p>For instance, if a bot is added to the<em> addQueue</em>, this function is in charge of adding it to the<em> clients</em> map, consequently updating all other variables. Similar but opposite operations are performed if a bot is added to the<em> delQueue</em>, because it has to be removed from the<em> clients</em> map</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-26.png" alt="" class="wp-image-400" width="305" height="46" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-26.png 465w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-26-300x45.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-26-230x35.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-26-350x53.png 350w" sizes="(max-width: 305px) 100vw, 305px" /></figure>



<p>Relevant is also the function<em> QueueBuf( )</em>, which adds the attack given as input parameter to the<em> atkQueue</em>. This function is invoked from<em> Handle( )</em> functions (defined in both  .<em>/admin.go</em> and  .<em>/api.go</em>) every time a new attack has been successfully requested by a user/admin, and it has to be added to the<em> atkQueue</em> in order to be performed</p>



<p>When a new attack is added to the<em> atkQueue</em>, the function<em> worker( )</em>  is in charge of processing it and commanding the attack. It checks the  number of bots that are required for the attack and invokes the function<em> QueueBuf( )</em> (defined in  .<em>/bot.go</em>) on several available bots, until either the maximum or the requested number of bots is reached</p>



<p>The input parameter of<em> QueueBuf( )</em> is the attack command, previously formatted in a proper sequence of bytes, and is sent directly to the bots throught<em> QueueBuf( )</em>. This is the way every DDoS attack is commanded within the Mirai botnet</p>



<p><strong><span class="has-inline-color has-vivid-red-color">t<em>ools</em></span></strong> subdirectory contains some utilities designed to support the  deployment and operation of the Mirai botnet which includes a C tool<em> (enc.c)</em> to encrypt strings for inclusion into the bot source code and a GO source file<em> (scanListen.go)</em>, which basically implements the Reporting Server</p>



<figure class="wp-block-image size-large"><img decoding="async" width="209" height="182" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-4.png" alt="" class="wp-image-356"/></figure>



<p>The Reporting Server is the component of the Mirai botnet that is in  charge of receiving vulnerability results from bots and forwarding them  to the Loader Server. This component is implemented by few functions defined in a single GO file :<em> mirai/tools/scanListen.go</em></p>



<p>The entry point of the file is the function<em> main( )</em>, which initializes and starts the server. It sets the Reporting Server listening on TCP port<strong> </strong>48101 of the local machine IP address and, when a connection is received on that port, the function<em> handleConnection( )</em> is invoked to consume the connection</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-49.png" alt="" class="wp-image-442" width="292" height="192" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-49.png 450w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-49-300x197.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-49-230x151.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-49-350x230.png 350w" sizes="(max-width: 292px) 100vw, 292px" /></figure>



<p>The function<em> handleConnection( )</em>  performs the main task of the server. It reads vulnerability results  received from the connection (IP address, port, username, and password)  and it should send them to the Loader Server</p>



<p>Actually, the implementation of the Reporting Server available on the GitHub repository shows that the vulnerability credentials received from bots are not sent somewhere else, but just printed on the standard output in the  format<em> IP:port user:pass</em></p>



<p>Thus, we can presume that another mechanism for distributing results from  the Reporting to the Loader Server was used in the actual Mirai botnet implementation. For instance, it is possible that the two servers were running on the same physical machine and a simple mechanism that redirects the standard output of the Reporting Server to the standard  input of the Loading Server was implemented. This hypothesis is further aided by the implementation of the Loader Server, which reads the  vulnerability results from standard input, as will be shown in the next subsection</p>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><u><strong>Loader directory</strong></u> </mark>: this folder contains files necessary to implement and execute the Loader Server</p>



<p>The Loader Server is in charge of receiving vulnerabilities results from the Reporting Server and using them to upload the malicious code on weak devices, infecting them. The Mirai worm binary files compiled for the different architectures vulnerable by Mirai worm are stored in the folder<em> /loader/bins/</em></p>



<figure class="wp-block-image size-large"><img decoding="async" width="248" height="202" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-6.png" alt="" class="wp-image-360" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-6.png 248w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-6-230x187.png 230w" sizes="(max-width: 248px) 100vw, 248px" /></figure>



<p>Meanwhile, the logic of the Loader Server is implemented by the C source code files contained in<em> /loader/src/</em> </p>



<figure class="wp-block-image size-large"><img decoding="async" width="234" height="324" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-5.png" alt="" class="wp-image-358" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-5.png 234w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-5-217x300.png 217w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-5-230x318.png 230w" sizes="(max-width: 234px) 100vw, 234px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./main.c</span></strong> </em>: this is the entry point of the Loader Server. The most relevant function is<em> main( )</em>, which is in charge of actually creating the server and continuously forwarding vulnerability results to it</p>



<p>In  detail, the main function initializes all relevant data structures for  the server</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-50.png" alt="" class="wp-image-446" width="245" height="160" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-50.png 353w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-50-300x195.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-50-230x150.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-50-350x228.png 350w" sizes="(max-width: 245px) 100vw, 245px" /></figure>



<p>and then creates the server by invoking the function<em> server_create( )</em> (defined in .<em>/server.c</em>). The latter accepts as input parameters both IP address and port to listen for<em> wget</em>  connections (default: 100.200.100.100:80), as an IP address alone (port  number is not needed since tftp service uses well-known port number 69) for<em> tftp</em> connections (default: 100.200.100.100:69)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-1024x268.png" alt="" class="wp-image-448" width="807" height="210" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-1024x268.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-300x79.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-768x201.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-230x60.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-350x92.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-51-480x126.png 480w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>Once the server is created, another thread is started by invoking the Linux function<em> pthread_create( )</em>. The function executed by this new thread is<em> stats_thread( )</em> and it has the aim of continuously printing statistics related to the Loader Server</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-1024x232.png" alt="" class="wp-image-450" width="809" height="183" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-1024x232.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-300x68.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-768x174.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-830x188.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-230x52.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-350x79.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52-480x109.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-52.png 1349w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p>At this point, the function<em> main( )</em>  enters in its main loop. It performs the basic task of reading vulnerability results and sending them to the server, in order to be processed. As previously stated, the data about vulnerabilities are simply read from standard input through the standard C function<em> fgets( )</em>, and that is what lets us suppose a simple mechanism for distributing  results between Reporting and Loader Server, in the actual Mirai botnet.  When received, vulnerability results are parsed by invoking the function<em> util_trim( )</em> (defined in  .<em>/util.c</em>) </p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-53.png" alt="" class="wp-image-452" width="233" height="221" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-53.png 384w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-53-300x285.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-53-230x219.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-53-350x333.png 350w" sizes="(max-width: 233px) 100vw, 233px" /></figure>



<p>and then sent to the Loader Server through the function<em> server_queue_telnet( )</em> (defined in .<em>/server.c</em>)</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54.png" alt="" class="wp-image-454" width="394" height="163" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54.png 632w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54-300x124.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54-230x95.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54-350x145.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-54-480x198.png 480w" sizes="(max-width: 394px) 100vw, 394px" /></figure>



<p><em><strong><span class="has-inline-color has-vivid-red-color">./server.c</span></strong> </em>: this is the C file that actually implements the Loader Server. It contains several functions worth to review</p>



<p><em>server_create( )</em> is the function invoked from<em> main( )</em> (defined in  .<em>/main.c</em>)  at startup and it basically initializes the server. It allocates all the data structures needed during the execution and stores them in a<em> server</em> struct (defined in .<em>/headers/server.h</em>) that is then returned when the function terminates</p>



<p>Extremely relevant is the variable<em> workers</em>, which represents the list of worker threads in charge of processing each vulnerability result, uploading the malicious code to the corresponding insecure device. Each worker runs the function<em> worker( )</em> and it is identified by the struct<em> server_worker</em> (defined in  .<em>/headers/server.h</em>). It has an epoll (a Linux I/O event notification facility, with the aim of monitoring multiple file descriptors to see if I/O is possible on any  of them) associated with it which will contain an event for each weak  device the worker has to infect</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-1024x513.png" alt="" class="wp-image-456" width="759" height="380" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-1024x513.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-300x150.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-768x385.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-830x416.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-230x115.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-350x175.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55-480x241.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-55.png 1215w" sizes="(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px" /></figure>



<p>More details about<em> worker( )</em> and<em> epoll</em> follow :</p>



<p><em>worker( )</em> is the main function executed by each worker thread. It is composed of a single main loop, which monitors the<em> epoll</em> associated with the current worker waiting for new events. When an event is added to the<em> epoll</em>, the function<em> handle_event( )</em> is invoked giving both the<em> server_worker</em> struct and the event as input parameters</p>



<p><em>server_queue_telnet( )</em> is the function invoked from<em> main( )</em> (defined in .<em>/main.c</em>) when a new vulnerability result is received. It checks that the maximum number of connections, stored in the attribute<em> max_open</em> of the<em> server</em> struct, has not been reached yet and potentially invokes<em> server_telnet_probe( )</em> to establish a new connection</p>



<p><em>server_telnet_probe( )</em>  sets a connection up with the remote device using information (IP  address, port, user, and password) obtained from the vulnerability  result. Once the connection is established, a new event is added to the<em> epoll</em>  of a worker cyclically selected (by sequentially and circularly  scrolling the list, using an incremental index and the modulo operation)  between the available ones. Then, as soon as the selected worker is  free, it will process the event executing the function<em> handle_event( )</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56.png" alt="" class="wp-image-458" width="691" height="124" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56.png 942w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-300x54.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-768x138.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-830x149.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-230x41.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-350x63.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-56-480x86.png 480w" sizes="(max-width: 691px) 100vw, 691px" /></figure>



<p><em>handle_event( )</em> is executed from a worker thread when an event is queued in its<em> epoll</em>  and is the core function of the Loader Server, since it uploads the  malicious code on vulnerable devices. First of all, it checks if the  connection (opened by<em> server_telnet_probe( )</em>) is still available  and working</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57.png" alt="" class="wp-image-460" width="507" height="327" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57.png 792w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57-300x194.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57-768x496.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57-230x148.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57-350x226.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-57-480x310.png 480w" sizes="(max-width: 507px) 100vw, 507px" /></figure>



<p>Subsequently, it enters in an undefined loop and interacts with the remote device through a simple<em> switch</em> statement that performs different actions depending on the answer received. Each action  is accomplished through a function named<em> connection_consume_&lt;action&gt;( )</em> and defined in .<em>/connection.c</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58.png" alt="" class="wp-image-461" width="568" height="422" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58.png 929w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-300x223.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-768x571.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-830x617.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-230x171.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-350x260.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-58-480x357.png 480w" sizes="(max-width: 568px) 100vw, 568px" /></figure>



<p>The full list of actions is available in .<em>/headers/connection.h</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59.png" alt="" class="wp-image-463" width="485" height="238" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59.png 695w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59-300x147.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59-230x113.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59-350x172.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-59-480x236.png 480w" sizes="(max-width: 485px) 100vw, 485px" /></figure>



<p> Simplifying the operations performed by the “state machine” in order to infect the weak device can be summarized as follows:</p>



<p>(i)<em>Login:</em> using the credentials stored in the vulnerability result, in order to log in and gain shell access to the remote device</p>



<p>(ii)<em>Architecture type:</em> finding out the target device architecture. This information is relevant when an executable binary file is uploaded</p>



<p>(iii)<em>Uploading methods</em>: detecting if either<em> wget</em> or<em> tftp</em> services are available. If not,<em> “echoloader”</em> will be used, uploading the binary file through the Linux<em> echo</em> command and then executing it</p>



<p>(iv)<em>Uploading</em>: an upload method (<em>wget</em>,<em> tftp,</em> or<em> echoloader</em>) is used to transfer the worm binary file, compiled for the target architecture type. Then, execution privileges are granted</p>



<p>(v)<em>Executing</em>: executing the uploaded binary file, which contains the Mirai bot code</p>



<p>(vi)<em>Cleaning up</em>: overriding the section of memory used, aiming to cover the worm and avoid detection</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-1024x266.png" alt="" class="wp-image-473" width="823" height="213" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-1024x266.png 1024w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-300x78.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-768x199.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-830x216.png 830w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-230x60.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-350x91.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63-480x125.png 480w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-63.png 1371w" sizes="(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px" /></figure>



<p> A note about /bin/busybox :  it&#8217;s the call to the Swiss Army Knife of Embedded Linux ! Have a look here if you don&#8217;t know <a href="https://busybox.net/downloads/BusyBox">https://busybox.net/downloads/BusyBox</a></p>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><u><strong>Scripts directory</strong></u> </mark>: this folder contains useful scripts necessary to compile and set up the Mirai infrastructure. In order to perform its duties, the CNC Server interacts with a SQL database, whose structure is defined in<em> </em>db.sql </p>



<figure class="wp-block-image size-large"><img decoding="async" width="238" height="100" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-7.png" alt="" class="wp-image-362" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-7.png 238w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-7-230x97.png 230w" sizes="(max-width: 238px) 100vw, 238px" /></figure>



<p>The most relevant script file is undoubtedly<em> /mirai/build.sh</em>.  It is a Bash script that provides basic functionalities such as  cleaning up artifacts, enabling compiler flags, and building binaries.  In particular, it builds the servers GO files and compiles the bot C source code for multiple platforms (i.e., processors and associated  instruction sets) running Linux operating system, which is the most  common one in the IoT environment. The full list of architectures  “supported” by Mirai worm is shown below and can be summarized as follows:<em> ARM</em>,<em> Motorola 68020</em> (m68k),<em> MIPS</em>,<em> PowerPC</em> (ppc),<em> SPARC</em>,<em> SuperH</em> (sh4), and<em> x86</em>.  What is interesting here is that, even if IoT devices are the main  target, the Mirai worm can potentially infect general purpose machines  based on x86 architecture</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60.png" alt="" class="wp-image-465" width="438" height="293" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60.png 609w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60-300x201.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60-230x154.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60-350x234.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-60-480x322.png 480w" sizes="(max-width: 438px) 100vw, 438px" /></figure>



<p>The script<em> build.sh</em> supports different input parameters which can be specified in order to tune the compiling phase. Its usage can be  described as follows :  ./build.sh &lt;debug ∣ release&gt;  &lt;telnet ∣ ssh&gt;</p>



<p> The first parameter defines the behaviour of the bot code and the second one the protocol exploited. In detail, the former works as  follows :</p>



<p>(i)The<em> debug</em> compile option generates bot binaries, which are not daemons, and that print out information about the execution</p>



<p>(ii)The<em> release</em>  compile option produces the actual worm binaries which are stripped,  small (about 60 KB), and ready to be loaded onto vulnerable devices</p>



<p>As far as the latter is concerned, the<em> telnet</em> option is a forced choice, since the implementation of the<em> ssh</em> one is missing </p>



<p>The file<em> /scripts/cross-compile.sh</em> is a Bash script in charge of setting the cross-compiler up. It has to be used before running the<em> /mirai/build.sh</em> script and, after<em> cross-compile.sh</em> execution, a system reboot is required for changes to take effect</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61.png" alt="" class="wp-image-469" width="425" height="224" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61.png 567w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61-300x158.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61-230x121.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61-350x185.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-61-480x253.png 480w" sizes="(max-width: 425px) 100vw, 425px" /></figure>



<p>The files<em> /loader/build.debug.sh</em> and<em> /loader/build.sh</em>  are Bash scripts that compile the Loader Server C code, respectively, in debug and final-stage-ready mode. The Loader Server is not built from the<em> /mirai/build.sh</em> script</p>



<p>The SQL database is basically composed of three tables :</p>



<p><em>History</em> : it is a table that contains the list of DDoS attacks perpetrated by the botnet</p>



<p><em>Users</em> :  it is a table that contains all information related to users and admins. The only difference between a user and an admin is the attribute<em> “admin”</em> which is<em> “1”</em> for admins and<em> “0”</em> otherwise. Relevant is also the attribute<em> “api_key”</em> that can be optionally assigned to a user/admin</p>



<p><em>Whitelist</em> : it is a table that contains a list of IP addresses which cannot be attacked by the Mirai botnet</p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8.png" alt="" class="wp-image-365" width="333" height="474" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8.png 532w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8-211x300.png 211w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8-230x327.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8-350x498.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-8-480x683.png 480w" sizes="(max-width: 333px) 100vw, 333px" /></figure>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Mirai process summary</span></strong></p>



<p>I provide here below the links to excellent summary workflows (worm infection, C&amp;C)</p>



<p><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Here the workflow for the Mirai worm infection process</strong></mark> <em>:</em></p>



<p><a href="https://blog.apnic.net/wp-content/uploads/2017/03/Figure-2-%E2%80%93-Mirai-bot-life-cycle-and-the-action-it-takes-when-it-goes-live.jpg" target="_blank" rel="noreferrer noopener">https://blog.apnic.net/wp-content/uploads/2017/03/Figure-2-%E2%80%93-Mirai-bot-life-cycle-and-the-action-it-takes-when-it-goes-live.jpg</a></p>



<p><strong><span class="has-inline-color has-luminous-vivid-orange-color">Here the workflow for the Mirai C&amp;C botnet process</span></strong> :</p>



<p><a href="https://blog.apnic.net/wp-content/uploads/2017/03/Figure-1-Workflow-for-a-Mirai-C2-instance.jpg" target="_blank" rel="noreferrer noopener">https://blog.apnic.net/wp-content/uploads/2017/03/Figure-1-Workflow-for-a-Mirai-C2-instance.jpg</a></p>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">How to run Mirai</span></strong> (<em>for security education purpose only !</em>)</p>



<p>There&#8217;s a good Github page here to install Mirai : <a href="https://github.com/ruCyberPoison/-Mirai-Iot-BotNet/blob/master/TUTORIAL.txt" target="_blank" rel="noreferrer noopener">https://github.com/ruCyberPoison/-Mirai-Iot-BotNet/blob/master/TUTORIAL.txt</a></p>



<p>If you are successfull going through all the steps, I provide a few screenshots of the Mirai console, this is what you should get :</p>



<p><em>Establishing the connection to the botnet</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69.png" alt="" class="wp-image-490" width="407" height="321" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69.png 786w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69-300x237.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69-768x607.png 768w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69-230x182.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69-350x277.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-69-480x379.png 480w" sizes="(max-width: 407px) 100vw, 407px" /></figure>



<p><em>Adding a new user</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-67.png" alt="" class="wp-image-487" width="322" height="193" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-67.png 423w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-67-300x179.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-67-230x138.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-67-350x209.png 350w" sizes="(max-width: 322px) 100vw, 322px" /></figure>



<p><em>SYN attack (TCP protocol)</em></p>



<figure class="wp-block-image size-large is-resized"><img decoding="async" src="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68.png" alt="" class="wp-image-488" width="398" height="240" srcset="https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68.png 493w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68-300x181.png 300w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68-230x139.png 230w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68-350x212.png 350w, https://www.forensicxs.com/wp-content/uploads/2020/03/Capture-68-480x290.png 480w" sizes="(max-width: 398px) 100vw, 398px" /></figure>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Botnet vulnerabilities</span></strong></p>



<p>Like any software, the botnet may have code vulnerabilities, which could be exploited to block the malware in some manner, by using some typical vulnerabilities such as buffer overflow. In particular, the C language is known to be prone to vulnerabilites, if the coding is not done according to secure coding principles (C is a powerfull low-level language, but really prone to issues if you don&#8217;t pay attention)</p>



<p>Here is a PoC how to &#8220;exploit&#8221; a vulnerability in Mirai code (stack buffer overflow vulnerability in the HTTP flood attack code) ; <a href="https://www.twosixlabs.com/killing-mirai-active-defense-against-an-iot-botnet-part-1/" target="_blank" rel="noreferrer noopener">https://www.twosixlabs.com/killing-mirai-active-defense-against-an-iot-botnet-part-1/</a></p>



<p>This simple “exploit” is an example of active defense that could be used by any DDoS mitigation service to defend against a Mirai-based HTTP flood attack in real-time. While it can’t be  used to remove the bot from the IoT device, it can be used to halt the  attack originating from that particular device (it’s  specific to the HTTP flood attack&#8230;)</p>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Conclusion</span></strong></p>



<p>Writing this article, I have been amazed by the engineering that has been put in Mirai. The coders have spent a lot of their time working on this botnet, abusing efficiently blatant security weaknesses in the targeted IoT devices. They have been seeking to launch DDoS attacks using this botnet to wipe out competitor servers in the gaming industry (Minecraft), greedy to earn money</p>



<p>Their identification and indictment has not been an easy task, but OSINT techniques, combined with insider knowledge, led to their identification and arrest, confirming that &#8220;you cannot hide&#8221; on the Internet</p>



<p>This story should be a wake-up call to the IoT security industry. It&#8217;s high time to stop pushing to the market weak devices, with a standard password and without firmware security updates !</p>



<p><strong><span class="has-inline-color has-vivid-cyan-blue-color">Key sources used for this article</span></strong></p>



<p>GitHub : <a href="https://github.com/jgamblin/Mirai-Source-Code" target="_blank" rel="noreferrer noopener">https://github.com/jgamblin/Mirai-Source-Code</a></p>



<p>cdxy.me : <a href="https://www.cdxy.me/?p=746" target="_blank" rel="noreferrer noopener">https://www.cdxy.me/?p=746</a></p>



<p>MISC : <a href="https://boutique.ed-diamond.com/les-hors-series/1247-misc-hs-15.html" target="_blank" rel="noreferrer noopener">https://boutique.ed-diamond.com/les-hors-series/1247-misc-hs-15.html</a></p>



<p>Radware : <a href="https://www.radware.com/iot-attack-ebook" target="_blank" rel="noreferrer noopener">https://www.radware.com/iot-attack-ebook</a></p>



<p>Fortinet : <a href="https://www.fortinet.com/blog/threat-research/searching-for-the-reuse-of-mirai-code--hide--n-seek-bot.html" target="_blank" rel="noreferrer noopener">https://www.fortinet.com/blog/threat-research/searching-for-the-reuse-of-mirai-code&#8211;hide&#8211;n-seek-bot.html</a></p>



<p>Hindawi : <a href="https://www.hindawi.com/journals/scn/2018/7178164/" target="_blank" rel="noreferrer noopener">https://www.hindawi.com/journals/scn/2018/7178164/</a></p>



<p>Avast : <a href="https://blog.avast.com/fr/7-nouvelles-variantes-de-mirai-et-le-cybercriminel-en-herbe-qui-se-cache-derriere" target="_blank" rel="noreferrer noopener">https://blog.avast.com/fr/7-nouvelles-variantes-de-mirai-et-le-cybercriminel-en-herbe-qui-se-cache-derriere</a></p>



<p>twosixLABS : <a href="https://www.twosixlabs.com/killing-mirai-active-defense-against-an-iot-botnet-part-1/" target="_blank" rel="noreferrer noopener">https://www.twosixlabs.com/killing-mirai-active-defense-against-an-iot-botnet-part-1/</a></p>



<p>APNIC : <a href="https://blog.apnic.net/2017/03/21/questions-answered-mirai-botnet/" target="_blank" rel="noreferrer noopener">https://blog.apnic.net/2017/03/21/questions-answered-mirai-botnet/</a></p>



<p>Cloudflare : <a href="https://blog.cloudflare.com/inside-mirai-the-infamous-iot-botnet-a-retrospective-analysis/" target="_blank" rel="noreferrer noopener">https://blog.cloudflare.com/inside-mirai-the-infamous-iot-botnet-a-retrospective-analysis/</a></p>



<p></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.forensicxs.com/mirai-the-open-source-botnet/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Database Caching 21/48 queries in 0.019 seconds using Disk

Served from: www.forensicxs.com @ 2025-12-29 02:41:00 by W3 Total Cache
-->