{"id":602,"date":"2017-06-18T09:03:33","date_gmt":"2017-06-18T17:03:33","guid":{"rendered":"https:\/\/www.pnfsoftware.com\/blog\/?p=602"},"modified":"2017-06-18T09:03:33","modified_gmt":"2017-06-18T17:03:33","slug":"automatic-identification-of-mirai-original-code","status":"publish","type":"post","link":"https:\/\/www.pnfsoftware.com\/blog\/automatic-identification-of-mirai-original-code\/","title":{"rendered":"Automatic Identification of Mirai Original Code"},"content":{"rendered":"<h1><span style=\"font-weight: 400;\">Context<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">One of the major threat on embedded devices &#8212; the so-called \u201cInternet of things\u201d &#8211;, is the infamous Mirai malicious software, whose source code was made <\/span><a href=\"https:\/\/krebsonsecurity.com\/2016\/10\/source-code-for-iot-botnet-mirai-released\/\"><span style=\"font-weight: 400;\">public<\/span><\/a><span style=\"font-weight: 400;\"> in September 2016. This malware has the ability to infect devices by brute-forcing Telnet credentials, and is primarily used to launch distributed denial-of-service attacks. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Since the source code release, numerous Mirai variants have been deployed in the wild by miscreants, like the one we documented in a recent <\/span><a href=\"https:\/\/www.pnfsoftware.com\/blog\/analyzing-mips-iot-malware-with-jeb\/\"><span style=\"font-weight: 400;\">post<\/span><\/a><span style=\"font-weight: 400;\">. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this blog we will first take a quick look at another Mirai-based malware, quite original in its own way, to then introduce our novel signature system that can identify Mirai original code in executables. <\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Yet Another Mirai Variant<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">On May 18th, ESET&#8217;s Michal Mal\u00edk mentioned on <\/span><a href=\"https:\/\/twitter.com\/michalmalik\/status\/865257088020336641\"><span style=\"font-weight: 400;\">Twitter<\/span><\/a><span style=\"font-weight: 400;\"> a Mirai-based sample for MIPS that grabbed our attention. Michal pointed out new functionalities like a custom update mechanism, and some strange debug routines, so we decided to take a look with our brand new MIPS decompiler. It should be noted that this sample comes with the debug symbols, which explains the names present in the decompiler output.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The malware logic starts in its <\/span><em><span style=\"font-weight: 400;\">main()<\/span><\/em><span style=\"font-weight: 400;\"> routine, which is shown below as decompiled by JEB. <\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/06\/68216c039bbeee563d58df2662577232.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Briefly summarized, this routine first sets up a few signal handlers, in particular to create a core file in case of segmentation fault. It then calls a homemade <\/span><em><span style=\"font-weight: 400;\">panic()<\/span><\/em><span style=\"font-weight: 400;\">\u00a0function &#8212; not to be confused with the standard Linux <\/span><em><a href=\"https:\/\/linux.die.net\/man\/3\/panic\"><span style=\"font-weight: 400;\">panic()<\/span><\/a><\/em><span style=\"font-weight: 400;\">\u00a0routine. The <\/span><em><span style=\"font-weight: 400;\">panic()<\/span><\/em><span style=\"font-weight: 400;\"> function code is shown below, as seen in JEB.<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/06\/e6d611c34514296f70195c5699dca594.png\" \/><\/p>\n<p><span style=\"font-weight: 400;\">While the routine native code &#8212; seen on the left side &#8212; can be pretty dry to read, the decompiled code on the right side is fairly straightforward: a file named <\/span><em><span style=\"font-weight: 400;\">file.txt<\/span><\/em><span style=\"font-weight: 400;\"> is opened and a given error message is written to it, accompanied by a custom system footprint built by the <\/span><em><span style=\"font-weight: 400;\">footprint12()<\/span><\/em><span style=\"font-weight: 400;\"> routine.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Finally, <\/span><em><span style=\"font-weight: 400;\">main()<\/span><\/em><span style=\"font-weight: 400;\"> calls the <\/span><em><span style=\"font-weight: 400;\">kill_run_mobile1()<\/span><\/em><span style=\"font-weight: 400;\"> function, which first kills any application listening on TCP port 18899 (likely others instances of the same malware), \u00a0and then creates a thread on the <\/span><em><span style=\"font-weight: 400;\">mobile_loop1()<\/span><\/em><span style=\"font-weight: 400;\"> function, which is shown below.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/06\/445c1ca823f442f9a6b471b71af17044.png\" width=\"351\" height=\"596\" \/><\/p>\n<p>The new thread will listen for incoming connections and process them through a custom command handler. As can be seen from the numerous debug messages in the decompiled code, the code is still in a development stage.<\/p>\n<p><span style=\"font-weight: 400;\">To summarize, this sample appears to be an attempt to repackage Mirai source code with a different update mechanism, and is still in development, as can be seen from the presence of debug routines, and the fact that plenty of code remains unused.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">While the technical quality of this sample is dubious, it illustrates one of the major consequence of Mirai source code public release: it has lowered the bar of entry for malicious software developers. In particular, we can expect the strain of Mirai-based malicious software to continue to grow in the following months. <\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Native Code Signatures<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">In a context where numerous Mirai-based malware are deployed in the wild, having the ability to identify original Mirai code becomes particularly useful, as it allows the analyst to focus only on the new functionalities in each sample. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Of course, most of Mirai-based samples do not come with symbols, and hence we need a proper mechanism to identify Mirai original code. That is the purpose of the native signature system released with JEB 2.3, which can actually identify code for all native architectures supported by JEB (x86, ARM, MIPS and the associated variants).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The objective of this signature system is to identify native routines with a <\/span><i><span style=\"font-weight: 400;\">minimal<\/span><\/i><span style=\"font-weight: 400;\"> number of false positives. In others words, we want to fully trust a successful identification, while we may miss some known routines.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To realize this low false positives goal, our signatures are primarily based on two <\/span><i><span style=\"font-weight: 400;\">features<\/span><\/i><span style=\"font-weight: 400;\">:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><b>A custom hash computed on the binary code of the unknown routine.<\/b><span style=\"font-weight: 400;\"> During this computation, we remove from the native instructions the addresses and offsets that may vary depending on where the routine is located in a binary. Hence the same routine located at a different place will have the same hash. Interestingly, as our algorithm uses the generic JEB interface on native instructions (<\/span><a href=\"https:\/\/www.pnfsoftware.com\/jeb\/apidoc\/reference\/reference\/com\/pnfsoftware\/jeb\/core\/units\/code\/IInstruction.html\"><span style=\"font-weight: 400;\">IInstruction<\/span><\/a><span style=\"font-weight: 400;\">), the hash computation is done on all architectures in the same way.<br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><b>The names of the routines called by the unknown routine,<\/b><span style=\"font-weight: 400;\"> e.g. API routines, system calls, or already identified routines.<\/span> <span style=\"font-weight: 400;\">This feature allows to distinguish wrappers that have exactly the same binary code but call a different routine. \u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">The whole signature process can be summarized in two steps &#8212; which will be described in details in a separate documentation:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><b>Signatures are generated from a reference file<\/b><span style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">. This file can be a native file with symbols, or a JEB database with some routines renamed by the user. For each named routine, a signature containing the routine features and information is created. Signatures are then grouped into packages for each platform.<\/span><\/span><\/li>\n<li style=\"font-weight: 400;\"><b>When JEB analyzes an unknown routine, it tries to match it with the signatures.<\/b><span style=\"font-weight: 400;\"> If there is a match, the information of the original routine are imported, e.g. the matched unknown routine is renamed as the original routine. <\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Due to its strict reliance on the binary code, this identification process does not offer a resistance to minor changes, like the ones introduced by compilation with a different compiler version or with different optimizations. We intend to develop others signature systems in JEB, which will be more resistant to such variations, in particular by using JEB intermediate representation.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Still, it is particularly suitable in the case of Mirai, where the public source code comes with compilation instructions, such that many samples are compiled in the same way and share the exact same binary code. Therefore, JEB 2.3 comes with a set of signatures created from a non-stripped executable created from Mirai public source code. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">These signatures are automatically applied when a MIPS binary is loaded in JEB. For example, here is an extract of the initial routines list after loading in JEB a <\/span><i><span style=\"font-weight: 400;\">stripped<\/span><\/i><span style=\"font-weight: 400;\"> Mirai sample deployed last year <em>(SHA1: 03ecd3b49aa19589599c64e4e7a51206a592b4ef)<\/em>. <\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/06\/9db16fc754c81d5cbd9fa307967c3dc8.png\" width=\"250\" height=\"666\" \/><\/p>\n<p><span style=\"font-weight: 400;\">On the 204 routines contained in the sample, 120 are automatically identified and renamed by JEB, allowing the user to focus on the unknown routines. It should be noticed that not all recognized routines belong to Mirai specific code, some of them belong to the C library used by Mirai (<\/span><a href=\"https:\/\/www.uclibc.org\/\"><span style=\"font-weight: 400;\">uClibc<\/span><\/a><span style=\"font-weight: 400;\">).<\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Conclusion<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">The JEB native signature system is still in development, but its results are encouraging and we provide a set of signatures for Mirai on MIPS platform, and for the standard C library shipped with Microsoft Visual Studio 2013 on the x86 platform. We encourage users to try it through our demo version, and report any comments to <a href=\"mailto:support@pnfsoftware.com\">support@pnfsoftware.com<\/a>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In the following weeks, not only will the number of signatures rapidly grow &#8212; through a specific update mechanism &#8211;, but we also intend to let users generate their own signatures with JEB public API.<\/span><\/p>\n<h1>Acknowledgement<\/h1>\n<p>The malicious software analysis presented in this post was done by our intern\u00a0Hugo Genesse.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Context One of the major threat on embedded devices &#8212; the so-called \u201cInternet of things\u201d &#8211;, is the infamous Mirai malicious software, whose source code was made public in September 2016. This malware has the ability to infect devices by brute-forcing Telnet credentials, and is primarily used to launch distributed denial-of-service attacks. Since the source &hellip; <a href=\"https:\/\/www.pnfsoftware.com\/blog\/automatic-identification-of-mirai-original-code\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Automatic Identification of Mirai Original Code<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-602","post","type-post","status-publish","format-standard","hentry","category-jeb2","category-malware"],"_links":{"self":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/602","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/comments?post=602"}],"version-history":[{"count":0,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/602\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/media?parent=602"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/categories?post=602"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/tags?post=602"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}