{"id":562,"date":"2017-04-29T15:04:27","date_gmt":"2017-04-29T23:04:27","guid":{"rendered":"https:\/\/www.pnfsoftware.com\/blog\/?p=562"},"modified":"2017-05-01T09:23:24","modified_gmt":"2017-05-01T17:23:24","slug":"analyzing-mips-iot-malware-with-jeb","status":"publish","type":"post","link":"https:\/\/www.pnfsoftware.com\/blog\/analyzing-mips-iot-malware-with-jeb\/","title":{"rendered":"Analyzing a New MIPS IoT Malware With JEB"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Over the last few months, several major vulnerabilities in a certain brand of IP cameras have been publicly released. One vulnerability allows <a href=\"https:\/\/pierrekim.github.io\/blog\/2017-03-08-camera-goahead-0day.html\">remote code execution<\/a>, while another permits the retrieval of the <a href=\"http:\/\/www.palada.net\/index.php\/2017\/03\/09\/news-716\/\">administrator\u2019s credentials<\/a>. The situation is made worse by the fact that many of these cameras are reachable on the Internet (around 185,000 according to one of the <a href=\"https:\/\/pierrekim.github.io\/blog\/2017-03-08-camera-goahead-0day.html\">researcher<\/a>). <\/span><\/p>\n<p><span style=\"font-weight: 400;\">It did not take long for miscreants to abuse this discovery, and a novel malicious software <sup class='footnote'><a href='#fn-562-1' id='fnref-562-1' onclick='return fdfootnote_show(562)'>1<\/a><\/sup>\u00a0was recently propagated through the vulnerable cameras, as described in <a href=\"http:\/\/blog.netlab.360.com\/a-new-threat-an-iot-botnet-scanning-internet-on-port-81-en\/\">a 360.cn blog post<\/a>. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">This malicious software\u00a0comes with MIPS and ARM versions, so we decided to quickly analyze it using <a href=\"https:\/\/www.pnfsoftware.com\/jeb\/mips\">our brand new MIPS decompiler<\/a>. This blog post describes our findings.<\/span><\/p>\n<p><i><span style=\"font-weight: 400;\">Note: JEB MIPS decompiler being in beta mode, the decompiled output presented in this blog post should be considered with caution; we provide it mainly to allow the reader to get an idea of JEB capabilities. As we are constantly refining the decompiler, the produced code will strongly evolve in the next few months.<\/span><\/i><\/p>\n<h1><span style=\"font-weight: 400;\">Recon<\/span><\/h1>\n<p><span style=\"font-weight: 400;\">The sample we will be analyzing is the following:<\/span><\/p>\n<pre>7A0485E52AA09F63D41E471FD736584C06C3DAB6: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped<\/pre>\n<p>After opening it in JEB, our disassembler found 526\u00a0routines. To give the reader an idea, here is what it looks like at the program entry point:<\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/871820eb75332e41845ac5c040e9f51e.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/871820eb75332e41845ac5c040e9f51e.png\" alt=\"\" width=\"1617\" height=\"672\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">We can see here the disassembled MIPS code, which can be a hard language to read to say the least. Hopefully JEB is able to decompile it, as shown below (names are our own): <\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/26ff4a6eb50b69763f8a34db45583374.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/26ff4a6eb50b69763f8a34db45583374.png\" alt=\"\" width=\"709\" height=\"129\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">The <\/span><em><span style=\"font-weight: 400;\">main()<\/span><\/em><span style=\"font-weight: 400;\"> routine is where the malware logic lies, and will be described below.<\/span><\/p>\n<p><em><span style=\"font-weight: 400;\">The interested reader might have noticed the comments in the assembly code. Those comments are the result of what we call the \u201cadvanced analysis\u201d step, which can be roughly described as an emulation of the native code (based on JEB custom intermediate representation). This allows to find the actual values manipulated by the code, when those values are the result of previous computations. The advanced analysis will be properly described in a separate blog post.<\/span><\/em><\/p>\n<p><span style=\"font-weight: 400;\">But before going on with the analysis, one might want to take a look at the strings used by the malware, to get a sense of its abilities:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/eee9057291ce1d9bf5c838621bc015b9.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/eee9057291ce1d9bf5c838621bc015b9.png\" alt=\"\" width=\"739\" height=\"567\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">We can observe some likely C&amp;C server information, and various strings related to the malware network abilities. Interestingly, an Arabic string clearly stands out\u00a0from the others; it can be translated to <strong>\u201cLoading Version 1\u201d<\/strong>.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A final preparation step is to look at the system calls made by the malicious software, as it allows to easily understand some routines behavior. JEB automatically renames such syscalls &#8212; rather than just showing the system call number resulting from the advanced analysis phase, and displays them in a separate panel:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/beb7d021eda3c6290f5b402264433b7f.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/beb7d021eda3c6290f5b402264433b7f.png\" alt=\"\" width=\"380\" height=\"280\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">The user can then jump to these syscall references, and rename them appropriately, as done in the following example:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f30cace077f483ceef1e0f03ef2e9ae0.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f30cace077f483ceef1e0f03ef2e9ae0.png\" alt=\"\" width=\"638\" height=\"216\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Through this process we renamed around 60 routines that are simply wrappers for syscalls.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Our reconnaissance step being done, we can now dig into the malware core logic!<\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Workflow <\/span><\/h1>\n<p><span style=\"font-weight: 400;\">We start at the <\/span><em><span style=\"font-weight: 400;\">main()<\/span><\/em><span style=\"font-weight: 400;\"> routine previously mentioned, and describe here the main steps of this malicious software. As we will see, part of this malware code is borrowed from the infamous Mirai malware, whose source code was <a href=\"https:\/\/krebsonsecurity.com\/2016\/10\/source-code-for-iot-botnet-mirai-released\/\">made public<\/a> in September 2016.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Initialization<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">At startup the malware does a few initialization steps, most of them being directly copy-pasted from Mirai. There is one original action though, which can be seen in the following image:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/cd81d00894379c776bc7efce1a95af0b.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/cd81d00894379c776bc7efce1a95af0b.png\" alt=\"\" width=\"405\" height=\"75\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">The files <\/span><em><span style=\"font-weight: 400;\">\/tmp\/ftpupdate.sh<\/span><\/em><span style=\"font-weight: 400;\"> and <\/span><em><span style=\"font-weight: 400;\">\/tmp\/ftpupload.sh<\/span><\/em><span style=\"font-weight: 400;\"> are first removed, then linked to <\/span><em><span style=\"font-weight: 400;\">\/dev\/null<\/span><\/em><span style=\"font-weight: 400;\">. These two files are used by various exploits against these IP cameras, and hence the malware makes sure a newly infected device can not be infected again.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">C&amp;C Commands<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">The malware then enters in a loop to fetch 1-byte commands from the C&amp;C server (whose domain name is hardcoded). We counted 8 different commands, some of them having subcommands. We will now describe the most interesting ones.<\/span><\/p>\n<h3><span style=\"font-weight: 400;\">Infection<\/span><\/h3>\n<p><span style=\"font-weight: 400;\">As previously explained, this malware propagates by infecting vulnerable IP cameras connected to the Internet. To do so, it first scans the Internet for these devices, by re-using the TCP SYN scanner of the Mirai malware. To illustrate that, here is the scanner initialization loop, as seen in the released <a href=\"https:\/\/github.com\/jgamblin\/Mirai-Source-Code\">Mirai source code<\/a><\/span><span style=\"font-weight: 400;\">\u00a0and in the decompiled code of our malware:<\/span><\/p>\n<p><b>Scanner code, as seen in Mirai source code&#8230;<\/b><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/030ca4a38ddc8bd881152bf462055785.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/030ca4a38ddc8bd881152bf462055785.png\" alt=\"\" width=\"928\" height=\"542\" \/><\/a><\/p>\n<p><b>&#8230; versus the new malware code decompiled by JEB<\/b><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f3012393531f71699b6bde5ad00371bc.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f3012393531f71699b6bde5ad00371bc.png\" alt=\"\" width=\"446\" height=\"334\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">The only major difference is that the TCP destination port is fixed to 81 in our malicious software, rather than alternate between port 23 and 2323 in Mirai. It is worth noting than even the loop counter has the same value (<\/span><em><span style=\"font-weight: 400;\">SCANNER_RAW_PPS<\/span><\/em><span style=\"font-weight: 400;\"> is set to 160 in Mirai source code).<\/span><\/p>\n<p><span style=\"font-weight: 400;\">If the malware finds a device with an opened port 81, it then launches the actual exploit, which is built from a combination of publicly known vulnerabilities in the IP camera web server:<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Extract the device administrator\u2019s credentials by sending an HTTP request for the file <\/span><em><span style=\"font-weight: 400;\">login.cgi<\/span><\/em><span style=\"font-weight: 400;\"> and then parsing the answer for the administrator login and password (documented <a href=\"http:\/\/www.palada.net\/index.php\/2017\/03\/09\/news-716\/\">here<\/a>).<br \/>\n<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Send two specially crafted HTTP requests to first plant a connect-back payload on the device, and then execute it (documented <a href=\"https:\/\/pierrekim.github.io\/blog\/2017-03-08-camera-goahead-0day.html\">here<\/a>). The sending of this first request is shown below, as seen in JEB:<br \/>\n<a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/2390c3509dabde4ffafec809ae8b0907.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/2390c3509dabde4ffafec809ae8b0907.png\" alt=\"\" width=\"919\" height=\"255\" \/><\/a><br \/>\n<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Once the connection has been established with the miscreants\u2019 server thanks to the connect-back payload, the newly infected device is asked to download and run the malicious software, as described in the <a href=\"http:\/\/blog.netlab.360.com\/a-new-threat-an-iot-botnet-scanning-internet-on-port-81-en\/\">360.cn blog post<\/a>.<\/span><\/p>\n<h4><span style=\"font-weight: 400;\">Attack Routers<br \/>\n<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">Another action possibly ordered by the C&amp;C server is to scan for UPnP enabled devices, in order to add a port forwarding entry to them. Such UPnP devices typically include home routers.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">To do so, the malicious software starts to repeatedly send UPnP discovery messages to random IP addresses:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f6dd189d797365bc56aff2674b27e33a.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/f6dd189d797365bc56aff2674b27e33a.png\" alt=\"\" width=\"1167\" height=\"333\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">Once a UPnP enabled device has been found, a SOAP request is forged to add a new port forwarding entry in its configuration:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/cce256c48194b87154e5345285cc09fd.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/cce256c48194b87154e5345285cc09fd.png\" alt=\"\" width=\"971\" height=\"308\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">As mentioned in another <a href=\"http:\/\/blog.netlab.360.com\/http-81-botnet-the-comparison-against-mirai-and-new-findings-en\/\">360.cn blog post<\/a>, this code may be used to exploit the <a href=\"http:\/\/www.zerodayinitiative.com\/advisories\/ZDI-15-155\/\">CVE-2014-8361<\/a>\u00a0vulnerability, which allows to execute system commands with root privileges through the <em>&lt;NewInternalClient&gt;<\/em> SOAP tag. Also, notice the <\/span><em><span style=\"font-weight: 400;\">&lt;NewPortMappingDescription&gt;<\/span><\/em><span style=\"font-weight: 400;\"> tag set to <\/span><em><span style=\"font-weight: 400;\">Skype <\/span><\/em><span style=\"font-weight: 400;\">to attempt hiding\u00a0the request<\/span><span style=\"font-weight: 400;\">. <\/span><\/p>\n<h4><span style=\"font-weight: 400;\">UDP DDoS<\/span><\/h4>\n<p><span style=\"font-weight: 400;\">As documented in the 360.cn blog, the malicious software can launch a denial of service attack over UDP. The packets are built from the SSDP discovery message, which may also serve as a preparation step for a <a href=\"https:\/\/www.akamai.com\/uk\/en\/multimedia\/documents\/state-of-the-internet\/ssdp-reflection-ddos-attacks-threat-advisory.pdf\">SSDP reflection attack<\/a>, though it appears the code for that is not present in the binary.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Interestingly, there is another denial of service attack implemented, using a 25-byte payload shown below:<\/span><\/p>\n<p><a href=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/627ecd04368bfc47a67d3f08d6c9b991.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/www.pnfsoftware.com\/blog\/wp-content\/uploads\/2017\/04\/627ecd04368bfc47a67d3f08d6c9b991.png\" alt=\"\" width=\"427\" height=\"42\" \/><\/a><\/p>\n<p><span style=\"font-weight: 400;\">This payload is used in amplification attacks through <a href=\"http:\/\/grehack.org\/files\/2013\/talks\/talk_3_5-nolla-ddos_amplification_attacks_with_game_servers-grehack.pdf\">Valve Source Engine servers<\/a>.<\/span><\/p>\n<h1><span style=\"font-weight: 400;\">Conclusion <\/span><\/h1>\n<p><span style=\"font-weight: 400;\">We hope the readers enjoyed this quick analysis; feel free to ask questions in the comments section below. <\/span><\/p>\n<p><i><span style=\"font-weight: 400;\"><a href=\"https:\/\/www.pnfsoftware.com\/jeb\/mips\">JEB MIPS decompiler<\/a> is currently in beta mode, and a demo version can be <a href=\"https:\/\/www.pnfsoftware.com\/jeb\/demo\">downloaded on our website<\/a>.<\/span><\/i><\/p>\n<h1><\/h1>\n<div class='footnotes' id='footnotes-562'>\n<div class='footnotedivider'><\/div>\n<ol>\n<li id='fn-562-1'> This malware was named <em>http81<\/em> by 360, <em>Persirai<\/em> by ESET, or is simply recognized as a variant of <em>Mirai<\/em> by other vendors. <span class='footnotereverse'><a href='#fnref-562-1'>&#8617;<\/a><\/span><\/li>\n<\/ol>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Over the last few months, several major vulnerabilities in a certain brand of IP cameras have been publicly released. One vulnerability allows remote code execution, while another permits the retrieval of the administrator\u2019s credentials. The situation is made worse by the fact that many of these cameras are reachable on the Internet (around 185,000 according &hellip; <a href=\"https:\/\/www.pnfsoftware.com\/blog\/analyzing-mips-iot-malware-with-jeb\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Analyzing a New MIPS IoT Malware With JEB<\/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-562","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\/562","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=562"}],"version-history":[{"count":0,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/posts\/562\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/media?parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/categories?post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pnfsoftware.com\/blog\/wp-json\/wp\/v2\/tags?post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}