{"componentChunkName":"component---src-templates-post-template-js","path":"/hackthebox-linux-mirai-en","result":{"data":{"markdownRemark":{"id":"ad950202-77e2-54f7-b98a-79b355314908","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/hackthebox-linux-mirai\">original page</a>.</p>\n</blockquote>\n<p>I am studying security using “Hack The Box,” a penetration testing learning platform.\nMy Hack The Box rank at the time of writing is ProHacker.</p>\n<img src=\"http://www.hackthebox.eu/badge/image/327080\" alt=\"Hack The Box\">\n<p>In this article, I summarize what I learned about attacks against IoT devices and countermeasures for improving security, through the HackTheBox machine “Mirai.”</p>\n<!-- omit in toc -->\n<h2 id=\"about-this-article\" style=\"position:relative;\"><a href=\"#about-this-article\" aria-label=\"about this article permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>About This Article</h2>\n<p><strong>The content of this article is not intended to promote acts that violate social order.</strong></p>\n<p>Please be aware in advance that attempting to attack environments other than your own or environments for which you have permission may violate the “Act on Prohibition of Unauthorized Computer Access” (Unauthorized Access Prohibition Act).</p>\n<p>All opinions expressed are my own and do not represent those of any organization I belong to.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of Contents</h2>\n<ul>\n<li><a href=\"#machine-overview\">Machine Overview</a></li>\n<li><a href=\"#new-things-learned-while-solving-this-machine\">New Things Learned While Solving This Machine</a></li>\n<li>\n<p><a href=\"#enumeration\">Enumeration</a></p>\n<ul>\n<li><a href=\"#what-is-pi-hole\">What is Pi-hole?</a></li>\n</ul>\n</li>\n<li>\n<p><a href=\"#foothold\">Foothold</a></p>\n<ul>\n<li><a href=\"#vulnerability-research\">Vulnerability Research</a></li>\n<li><a href=\"#obtaining-credentials\">Obtaining Credentials</a></li>\n<li><a href=\"#what-is-mirai\">What is Mirai?</a></li>\n<li><a href=\"#countermeasures-against-mirai-and-other-iot-malware\">Countermeasures Against Mirai and Other IoT Malware</a></li>\n</ul>\n</li>\n<li><a href=\"#actually-getting-in\">Actually Getting In</a></li>\n<li><a href=\"#internal-enumeration\">Internal Enumeration</a></li>\n<li><a href=\"#privilege-escalation\">Privilege Escalation</a></li>\n<li>\n<p><a href=\"#another-round-of-internal-enumeration\">Another Round of Internal Enumeration</a></p>\n<ul>\n<li><a href=\"#how-linux-device-mounting-works\">How Linux Device Mounting Works</a></li>\n</ul>\n</li>\n<li><a href=\"#obtaining-the-root-flag\">Obtaining the Root Flag</a></li>\n<li><a href=\"#summary\">Summary</a></li>\n</ul>\n<h2 id=\"machine-overview\" style=\"position:relative;\"><a href=\"#machine-overview\" aria-label=\"machine overview permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Machine Overview</h2>\n<ul>\n<li>Platform: Linux</li>\n<li>Difficulty: Easy (quite easy, even for an Easy machine)</li>\n<li>\n<p>Required Techniques / Knowledge</p>\n<ul>\n<li>Enumeration using nmap / gobuster, etc.</li>\n<li>IoT malware attack techniques</li>\n<li>Internal enumeration techniques for privilege escalation</li>\n<li>Linux device management</li>\n</ul>\n</li>\n</ul>\n<h2 id=\"new-things-learned-while-solving-this-machine\" style=\"position:relative;\"><a href=\"#new-things-learned-while-solving-this-machine\" aria-label=\"new things learned while solving this machine permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>New Things Learned While Solving This Machine</h2>\n<ul>\n<li>Overview and attack techniques of IoT malware</li>\n<li>Linux device files</li>\n<li>Methods to salvage deleted data from flash memory</li>\n</ul>\n<h2 id=\"enumeration\" style=\"position:relative;\"><a href=\"#enumeration\" aria-label=\"enumeration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Enumeration</h2>\n<p>Let’s get started on the machine.\nAs usual, I begin with a port scan.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:console\"><pre class=\"language-bash:console\"><code class=\"language-bash:console\">TARGET=10.10.10.48 &amp;&amp; expose TARGET\nnmap -sV -sC -T4 $TARGET| tee nmap1.txt</code></pre></div>\n<p>This command produced the following output:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 757px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/ec45743e4c678dab0438bb79b78b122c/1fbe8/aa.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 48.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAKCAYAAAC0VX7mAAAACXBIWXMAAAsTAAALEwEAmpwYAAABpklEQVQoz2WS2XKrMBBE+Y8kjjH7LnaEAOO18p7//5bOzMSkuHUfpiQh1DrdIyvR3yi6JzKzIltvKK4PVI8vKJonE3273NHON3TthKoeUZYDiqJH0xgkSUXzDkr18LwMx2MIy4xnrOsTy3TDbK5YzA0qa+G7KezPAM4xwsmO5efTKZY6HDypT9rnOhx82bftCFahBujxitFcUNOt8/JAQzS+nyOKKwRhgZjGMFRSQZAjiTO4ji8C+xLCfjhD6wuyrJGDGdGxhTRtkJMdXpel/rOWpjU8l8gdptrEwj9Ra9ArDNulnBaiM2R7nh9Ud6K+0vqCabpjoIuX5YkzxeM6HpyTtxPbCWp9Frst2WSrXTdL4Bx+FJVClCQ1zZU4yPOWGpDAPgY7uzvBvl8oQ8rv1UFeszgLuNSY93cXHx8elS/ztzf31YTovwxfhCuJEOXIlLPMJ4qASTk7znbLjtdVpYV4a8I2bmWxPe6uUoMEz5R1bX5t02EeO6Jm8oKEt4Yx/Sb4DyHb45v5IAffvh4wkzAljyy8/cdiQVAIsbyEvPt9AfTY+ZIf6942BsCuJ9MAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/ec45743e4c678dab0438bb79b78b122c/8ac56/aa.webp 240w,\n/static/ec45743e4c678dab0438bb79b78b122c/d3be9/aa.webp 480w,\n/static/ec45743e4c678dab0438bb79b78b122c/4578a/aa.webp 757w\"\n              sizes=\"(max-width: 757px) 100vw, 757px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/ec45743e4c678dab0438bb79b78b122c/8ff5a/aa.png 240w,\n/static/ec45743e4c678dab0438bb79b78b122c/e85cb/aa.png 480w,\n/static/ec45743e4c678dab0438bb79b78b122c/1fbe8/aa.png 757w\"\n            sizes=\"(max-width: 757px) 100vw, 757px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/ec45743e4c678dab0438bb79b78b122c/1fbe8/aa.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Port 80 is open, so I try accessing it in a browser.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0d2f5b1a606b0d48597654f06b791636/0b533/bb.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 55.41666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAARlAAAEZQAGA43XUAAABCklEQVQoz62P3U6DQBBGeQgVQ3GDGExvfGWfo7alrBZN38SaQIMgQvaHz90NpNiC7YWTnMyyzJydsZwbF8S7B/GnuHI8kNsp7oIHOG5gsCc+Lmx3lMtrAtvx4al+lwSwZrM5whUFfYkRPa/xtAgN82XUssIijEZZqt6Ixnh924DSNSz8c1hlWUJKCS4EhIJxDsYYOBcKPohoa4ew6ro25qZpTK6qClmW/TlFVzs44aFQT5DnOfTkRVGYs87dd7++6+k/cCTU6yZJijTdKVJ1TlpSbLcfJjPGj6SjQp31nZ50bN295ITw8Gd310fHeybxGNf4/D5j5SHJb2EDJhrsviSEPEN4Koa26McPAnYiDtUiot4AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/0d2f5b1a606b0d48597654f06b791636/8ac56/bb.webp 240w,\n/static/0d2f5b1a606b0d48597654f06b791636/d3be9/bb.webp 480w,\n/static/0d2f5b1a606b0d48597654f06b791636/b0a15/bb.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/0d2f5b1a606b0d48597654f06b791636/8ff5a/bb.png 240w,\n/static/0d2f5b1a606b0d48597654f06b791636/e85cb/bb.png 480w,\n/static/0d2f5b1a606b0d48597654f06b791636/0b533/bb.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/0d2f5b1a606b0d48597654f06b791636/0b533/bb.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>A 404 was returned, so I run enumeration against this web page.\nBefore running gobuster, I tried a few common paths:</p>\n<blockquote>\n<p>/robots.txt\n/admin\n/login</p>\n</blockquote>\n<p>It looks like <code class=\"language-text\">/admin</code> was a hit, and a management console page for an application called Pi-hole opened.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/4db5f75df9f7c1b3cecb205325cac96f/0b533/cc.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 91.25000000000001%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAARlAAAEZQAGA43XUAAADgUlEQVQ4y43Ta1CUVRzH8eeFvbcZDRhYYBfYBUQWJYMyywFZbsul0E0xBm/MlBPL1Ewv4mJDgXIXNZoJMWjkvqsshiuZ0mVKC5BSkLAyRoRdxA2ooSjE+XZ2wcRIxhef+T/nPOf85pzznEfy9vZCqQrA23c17nIlSmUAKn81XqpAPLxW4Sb3Reblh4tMwROuclw8fHAS1cnVEyc3Bc4yb1zcfcR8MV6uQlKm5BK6t5Rn08sIfrWMxNzjJORUE5N51CE2s2quZlXNEW1t1rzsY8TvqyZB2JH3IfGZHyCFhz1NiFaH4qkonteloeux4d85wZrOcYJEXYpajFF/O+4Yq/zcSurFIaTnPNwIXKfG08ePjZoowr6bZOWlaeQ90zh3T7O8608e7xa6Hm6FGL/s3C22XBCB7sGhKILWstzdg5DISF7vNBH7ZSUbzx0i7PyRR7Kp4z1C20t444tGpIAn16NSr8NF7seG6HhCzuTymGEPUvMupPqUR9OQilSVyCZTHpL3qmDsXOT+hIvAK18V0Hs+g37zDnrP7BR2zdeH62vfTZdpK90dhUievkEo/Nc4AsOi4phpfwFOKKFRBk2uUL9CWLm0RmdsFcv4xahDkjsC184HJjDcUMxYTQ7WozmMlOuxHEqfU76EwxncKEzjh7ryBYEKEaiJY/C1NIaSE7meGMFAqD8D6wMZeGb1kq5tCOKCSsbXe9MWrtCP8JhERrsuMtXzDVOXu/mr/zKzP15l9lofd+4Z6F1kZqCPu6Jarnx/P9DZ048I7YuMTf6GueMzao1GjjcbqDUYqTOeoP5kC40tJppaTwmtNJnua5yvl3qvPhio0SYxarFSVVnJ/vx89mVnk6HXszM1lS1JScRpY4nUaIgSosWdjYmOQhsbI/q1jr5mg2HxCm+P3cZgaOajmhoa6uuFOupqa6mpqeb9igqKiwrJzspCn55O2p7dpLy8ne3Jybyk09EiVr8g0BdN3GYso6McPHyEdw4UkF9Y9K/9RcUUlJRRVHaQwtIyDpSU8va7ebz5ViavpOvZvHUbRrHtBwIjROCN4WFMp820/J82MyfbTjvY263mdj7+5KxD29lP6f/p58Vf+fepP5gFZpZw5z/tv4W7gnV8/F6g+FPEGdov9pDlFlZxjvatj9lsjE9M8uvEhIP92SYm3RS7sL+/OTLiMGK1OtrXBwf5B+Wbli8HbvUWAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/4db5f75df9f7c1b3cecb205325cac96f/8ac56/cc.webp 240w,\n/static/4db5f75df9f7c1b3cecb205325cac96f/d3be9/cc.webp 480w,\n/static/4db5f75df9f7c1b3cecb205325cac96f/b0a15/cc.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/4db5f75df9f7c1b3cecb205325cac96f/8ff5a/cc.png 240w,\n/static/4db5f75df9f7c1b3cecb205325cac96f/e85cb/cc.png 480w,\n/static/4db5f75df9f7c1b3cecb205325cac96f/0b533/cc.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/4db5f75df9f7c1b3cecb205325cac96f/0b533/cc.png\"\n            alt=\"pihle\"\n            title=\"pihle\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h3 id=\"what-is-pi-hole\" style=\"position:relative;\"><a href=\"#what-is-pi-hole\" aria-label=\"what is pi hole permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Pi-hole?</h3>\n<p>This was my first time seeing Pi-hole, so I glanced at the documentation.</p>\n<blockquote>\n<p>The Pi-hole® is a DNS sinkhole that protects your devices from unwanted content, without installing any client-side software.\n<a href=\"https://docs.pi-hole.net/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Overview of Pi-hole - Pi-hole documentation</a></p>\n</blockquote>\n<p>As stated, Pi-hole is an application that can be used as a DNS sinkhole to protect devices from unwanted content. (A DNS sinkhole is a DNS that intentionally returns incorrect responses to queries.)</p>\n<p>Despite the name, Pi-hole can be deployed not only on Raspberry Pi but also on various platforms such as Debian and Docker containers.</p>\n<p>From the documentation, I was able to identify the technologies used by Pi-hole:</p>\n<blockquote>\n<p>Pi-hole being a advertising-aware DNS/Web server,\nmakes use of the following technologies:  </p>\n</blockquote>\n<ul>\n<li>dnsmasq - a lightweight DNS and DHCP server</li>\n<li>curl - A command-line tool for transferring data with URL syntax</li>\n<li>lighttpd - web server designed and optimized for high performance</li>\n<li>php - a popular general-purpose web scripting language</li>\n<li>AdminLTE Dashboard - premium admin control panel based on Bootstrap 3.x</li>\n<li>sqlite3 - SQL Database engine\n<a href=\"https://docs.pi-hole.net/main/origins/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Pi-hole Origins - Pi-hole documentation</a></li>\n</ul>\n<p>There were a few things of interest, but since it’s implemented in PHP — notorious for having a large number of reported vulnerabilities — I decided to investigate this as a potential entry point.</p>\n<h2 id=\"foothold\" style=\"position:relative;\"><a href=\"#foothold\" aria-label=\"foothold permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Foothold</h2>\n<h3 id=\"vulnerability-research\" style=\"position:relative;\"><a href=\"#vulnerability-research\" aria-label=\"vulnerability research permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Vulnerability Research</h3>\n<p>Now I search for entry points into the machine via Pi-hole vulnerabilities.\nFirst, I confirmed from the admin console that the Pi-hole version is <code class=\"language-text\">Pi-hole Version v3.1.4</code>.</p>\n<p>Searching for vulnerabilities affecting this version, I found these two that looked promising — but unfortunately, both required obtaining valid credentials for the admin console first.\n(A meta note: since this machine was created in 2017, CVE-2020-xxx is almost certainly not the intended solution.)</p>\n<blockquote>\n</blockquote>\n<ul>\n<li>\n<p><a href=\"https://www.exploit-db.com/exploits/48442\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">CVE-2020-11108</a></p>\n<ul>\n<li>Requires authentication</li>\n<li>RCE via blocklist vulnerability</li>\n</ul>\n</li>\n<li>\n<p><a href=\"https://nvd.nist.gov/vuln/detail/CVE-2020-8816\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">CVE-2020-8816</a></p>\n<ul>\n<li>Requires authentication</li>\n<li>RCE via a crafted DHCP static lease</li>\n</ul>\n</li>\n</ul>\n<h3 id=\"obtaining-credentials\" style=\"position:relative;\"><a href=\"#obtaining-credentials\" aria-label=\"obtaining credentials permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Obtaining Credentials</h3>\n<p>I tried a Google search for <code class=\"language-text\">Pi-hole Password</code> and similar terms.\nI found that you can reset the Pi-hole password by logging into the local environment and running the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash\"><pre class=\"language-bash:bash\"><code class=\"language-bash:bash\">sudo pihole -a -p</code></pre></div>\n<p>Also, reading several articles on setting up Pi-hole, I noticed instructions saying to log into the Raspberry Pi running Pi-hole using the default password <code class=\"language-text\">raspberry</code>.</p>\n<p>At this point I finally noticed that the machine’s name is <code class=\"language-text\">Mirai</code>. 😄</p>\n<h3 id=\"what-is-mirai\" style=\"position:relative;\"><a href=\"#what-is-mirai\" aria-label=\"what is mirai permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>What is Mirai?</h3>\n<p>Mirai is a malware that infects IoT devices and forms a massive botnet.\nIt scans networks and infiltrates discovered IoT devices.</p>\n<p>Mirai spread widely — including many variants — due to a combination of factors: how easily it could infect IoT devices that still had default credentials, and the fact that its source code was readily obtainable.\nMirai is known for carrying out DDoS attacks exceeding 100 Gbps multiple times in 2016, causing US DNS services to go down and affecting services like Twitter.</p>\n<p>When an IoT device is infected — for example by abusing default credentials — it can be remotely controlled by the attacker’s C&#x26;C server and used as a bot to spread the malware further or to carry out DDoS attacks.</p>\n<ul>\n<li><a href=\"https://www.ipa.go.jp/files/000059579.pdf\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">IPA: Emerging IoT Security Threats and Countermeasures</a></li>\n<li><a href=\"https://www.itmedia.co.jp/news/articles/1802/21/news034.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">The Worst-Ever DDoS Attack — Why Did Mirai Spread? (1/4) - ITmedia NEWS</a></li>\n<li><a href=\"https://www.trendmicro.com/jp/iot-security/news/3056\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Background of Mirai’s Spread: Root Cause is “Default Settings on IoT Devices” | IoT Security News</a></li>\n<li><a href=\"https://www.atmarkit.co.jp/ait/articles/1611/08/news028.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Deep Dive into Mirai Source Code — Understanding Its Mechanisms and Defenses (1/4) - @IT</a></li>\n</ul>\n<p>Reading the Mirai scanner source code is also very interesting: it has hardcoded credentials for IoT devices’ default settings, including what appear to be credentials targeting Toshiba network cameras and Panasonic printers.</p>\n<p>There are also multiple confirmed IoT malware variants that target Raspberry Pi specifically (not Mirai itself). Linux.MulDrop.14 is one such example, targeting the default credentials of Raspbian, the official OS for Raspberry Pi.</p>\n<blockquote>\n<p>Raspberry Pi’s official distribution “Raspbian,” right after setup, allows SSH login with username “pi” and password “raspberry.”\n<a href=\"https://news.livedoor.com/article/detail/13202811/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">A New IoT Virus “Linux.MulDrop.14” That Targets Raspberry Pis with Default Passwords and Mines Cryptocurrency After Infection - Livedoor News</a></p>\n</blockquote>\n<h3 id=\"countermeasures-against-mirai-and-other-iot-malware\" style=\"position:relative;\"><a href=\"#countermeasures-against-mirai-and-other-iot-malware\" aria-label=\"countermeasures against mirai and other iot malware permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Countermeasures Against Mirai and Other IoT Malware</h3>\n<p>Since I study machine exploitation from a defensive security perspective to understand attacker thinking, let me briefly consider countermeasures against these IoT malware threats.\n(※ These are entirely personal opinions.)</p>\n<p>The most obvious countermeasure is <code class=\"language-text\">not leaving IoT device passwords at factory defaults</code>. Raspberry Pi itself officially recommends changing the default credentials.</p>\n<p>That said, how many people actually set sufficiently strong passwords is questionable.\nI think it might be better if the OS were designed from the start to require setting credentials on first boot.\nIn fact, when you install Ubuntu for Raspberry Pi, you are required to set credentials on startup.</p>\n<p>Another obvious but essential measure is <code class=\"language-text\">not exposing unnecessary devices or ports to the network</code>.\nMany Mirai-like malware pieces seem to target network camera devices in particular.</p>\n<p>There are apparently quite a few cases where home users open ports so they can monitor camera footage remotely while away. Personally, I really wouldn’t want my home network accessible from the outside…</p>\n<p>Other measures include <code class=\"language-text\">keeping IoT devices updated to address vulnerabilities</code> and <code class=\"language-text\">as an egress control, configuring devices to only send information to specific destinations</code>. However, I’ve seen cases where manufacturers don’t release patches even after vulnerabilities are disclosed, so I’m somewhat skeptical of whether upgrades alone constitute sufficient protection.</p>\n<h2 id=\"actually-getting-in\" style=\"position:relative;\"><a href=\"#actually-getting-in\" aria-label=\"actually getting in permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Actually Getting In</h2>\n<p>Let me get back to the machine.</p>\n<p>Since Pi-hole is running, the environment might be Raspberry Pi.\n(And the machine’s challenge name is Mirai…)</p>\n<p>So I try SSH with Raspbian’s default password.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash\"><pre class=\"language-bash:bash\"><code class=\"language-bash:bash\">ssh pi@10.10.10.48 # Enter &quot;raspberry&quot; as password</code></pre></div>\n<p>Logged in!\nIt really was a Raspberry Pi!</p>\n<p>Checking the system:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:console\"><pre class=\"language-bash:console\"><code class=\"language-bash:console\">pi@raspberrypi:~ $ uname -a\nLinux raspberrypi 3.16.0-4-686-pae #1 SMP Debian 3.16.36-1+deb8u2 (2016-10-19) i686 GNU/Linux</code></pre></div>\n<p>Anyway, I’ve obtained the user flag.</p>\n<h2 id=\"internal-enumeration\" style=\"position:relative;\"><a href=\"#internal-enumeration\" aria-label=\"internal enumeration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Internal Enumeration</h2>\n<p>Next, I look for privilege escalation opportunities.\nFirst, I transfer the Linpeas enumeration script to the machine via SCP and retrieve the results locally.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash(local)\"><pre class=\"language-bash:bash(local)\"><code class=\"language-bash:bash(local)\">scp /home/kali/Hacking/Knowledge/Exploits/linPEAS/linpeas.sh  pi@$TARGET:~/</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash(machine)\"><pre class=\"language-bash:bash(machine)\"><code class=\"language-bash:bash(machine)\">sh linpeas.sh | tee linpeas_result.txt</code></pre></div>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash(local)\"><pre class=\"language-bash:bash(local)\"><code class=\"language-bash:bash(local)\">scp pi@$TARGET:~/linpeas_result.txt ./</code></pre></div>\n<p>Looking at the output, I see the following:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 647px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/7934cb7bffceea8b489e25c7c5f1052c/ca12d/dd.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 18.75%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAsUlEQVQY022PUQ6DIBBEuYSKgiQqy4eoBZV6/5NNWWyaNunHy+wAu8OKGHfsx4EQAuZ5xrZt2e9Y1xUxBjzCjXMEay2maSpopVBVFeq6/kHEGJHSWZqv60LIPoQHzvPEMyUsywLvfQljZc81kcMwDBjH8QN7wakM0Z3OF5YIlM+MMflnDqbvIaVE27ZvJLqug8oUVayq1MLnNF75yGvyYJVX0VoX+AErD2mapgz91n+8AOt0cIuPiisEAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/7934cb7bffceea8b489e25c7c5f1052c/8ac56/dd.webp 240w,\n/static/7934cb7bffceea8b489e25c7c5f1052c/d3be9/dd.webp 480w,\n/static/7934cb7bffceea8b489e25c7c5f1052c/8f3a3/dd.webp 647w\"\n              sizes=\"(max-width: 647px) 100vw, 647px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/7934cb7bffceea8b489e25c7c5f1052c/8ff5a/dd.png 240w,\n/static/7934cb7bffceea8b489e25c7c5f1052c/e85cb/dd.png 480w,\n/static/7934cb7bffceea8b489e25c7c5f1052c/ca12d/dd.png 647w\"\n            sizes=\"(max-width: 647px) 100vw, 647px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/7934cb7bffceea8b489e25c7c5f1052c/ca12d/dd.png\"\n            alt=\"image.png\"\n            title=\"image.png\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Extremely permissive.\nWhen <code class=\"language-text\">sudo -l</code> shows output like this, the user can run <code class=\"language-text\">sudo &lt;command></code> without a password.</p>\n<ul>\n<li><a href=\"https://qiita.com/RyodoTanaka/items/e9b15d579d17651650b7\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">How to use sudo without entering a password - Qiita</a></li>\n</ul>\n<p>A quick check confirms that Raspbian indeed has no password configured for sudo by default.\nIn other words, a default Raspbian setup allows both SSH login and unlimited privilege escalation.</p>\n<p>If you plan to use Raspbian as a server, you’ll need to be careful about this.</p>\n<ul>\n<li><a href=\"https://qiita.com/R-STYLE/items/b481ba2d695ddf8bcee4\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Notes on initial setup when using RaspberryPi with Raspbian (adding a user) - Qiita</a></li>\n</ul>\n<h2 id=\"privilege-escalation\" style=\"position:relative;\"><a href=\"#privilege-escalation\" aria-label=\"privilege escalation permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Privilege Escalation</h2>\n<p>So I can get root privileges quickly.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash\"><pre class=\"language-bash:bash\"><code class=\"language-bash:bash\">sudo su</code></pre></div>\n<p>Finished! …or so I thought, but there’s a little more to do.</p>\n<p>Opening root.txt reveals not a flag but the following text.\nIt seems the real root.txt has been lost.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">root@raspberrypi:~# cd /root/\nroot@raspberrypi:~# cat root.txt \nI lost my original root.txt! I think I may have a backup on my USB stick...</code></pre></div>\n<p>Don’t worry though.\nApparently a backup was saved on a USB stick.</p>\n<h2 id=\"another-round-of-internal-enumeration\" style=\"position:relative;\"><a href=\"#another-round-of-internal-enumeration\" aria-label=\"another round of internal enumeration permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Another Round of Internal Enumeration</h2>\n<p>From here, I need to enumerate again to retrieve the backed-up data.</p>\n<p>Finding the USB stick is straightforward.\nAnyone who has ever connected a USB to Linux should know that it’s often mounted under <code class=\"language-text\">/media</code>.</p>\n<p>Looking inside, there it is.\nHowever, it seems the data was accidentally deleted…</p>\n<p>James is quite careless.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">root@raspberrypi:~# cd /media\nroot@raspberrypi:/media# ls\nusbstick\nroot@raspberrypi:/media# cd usbstick/\nroot@raspberrypi:/media/usbstick# ls\ndamnit.txt  lost+found\nroot@raspberrypi:/media/usbstick# cat damnit.txt \nDamnit! Sorry man I accidentally deleted your files off the USB stick.\nDo you know if there is any way to get them back?\n-James</code></pre></div>\n<p>To fix — or rather help — clumsy James, I need to somehow salvage the lost flag from root.txt.</p>\n<p>But what clue can I use?</p>\n<p>The key here is understanding “how Linux device mounting works.”\nAs a side note, this book is a great beginner’s reference for how the Linux kernel behaves:</p>\n<p><a href=\"https://amzn.to/2LyGD35\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Linux Kernel for Beginners: Learning While Doing from Scratch</a></p>\n<h3 id=\"how-linux-device-mounting-works\" style=\"position:relative;\"><a href=\"#how-linux-device-mounting-works\" aria-label=\"how linux device mounting works permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>How Linux Device Mounting Works</h3>\n<p>Linux (and Unix-like systems in general) abstracts and manages all connected devices as “device files.”\nReference: <a href=\"https://wa3.i-3-i.info/word11689.html\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">What is a device file? — IT Dictionary for the Almost-Understood</a></p>\n<p>Device drivers are abstracted by the Linux kernel as “device files,” given conventional names (sda, sdb, etc.), and stored under <code class=\"language-text\">/dev</code>.\nApplications on the OS interact with hardware such as hard disks, USB drives, and mice by referencing these “device files.”</p>\n<p>Device files are mainly classified as “character type” or “block type,” and fixed-length data like hard disks is stored as “block type.”\nReference: <a href=\"https://qiita.com/angel_p_57/items/1faafa275525469788b4\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Linux File Types - Qiita</a></p>\n<h2 id=\"obtaining-the-root-flag\" style=\"position:relative;\"><a href=\"#obtaining-the-root-flag\" aria-label=\"obtaining the root flag permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Obtaining the Root Flag</h2>\n<p>The USB in this challenge should also be stored as a “block type” device file.\nBlock devices available to the OS can be listed with <code class=\"language-text\">lsblk</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:\"><pre class=\"language-bash:\"><code class=\"language-bash:\">root@raspberrypi:~# lsblk\nNAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT\nsda      8:0    0   10G  0 disk \nsda1   8:1    0  1.3G  0 part /lib/live/mount/persistence/sda1\nsda2   8:2    0  8.7G  0 part /lib/live/mount/persistence/sda2\nsdb      8:16   0   10M  0 disk /media/usbstick\nsr0     11:0    1 1024M  0 rom  \nloop0    7:0    0  1.2G  1 loop /lib/live/mount/rootfs/filesystem.squashfs</code></pre></div>\n<p>We can see that <code class=\"language-text\">/media/usbstick</code>, which holds the flag, is handled as the device file <code class=\"language-text\">sdb</code>.\nFinally, I extract data from it.</p>\n<p>Since HackTheBox flags are stored as text, simply running <code class=\"language-text\">strings /dev/sdb</code> would easily retrieve it.\nBut that’s not very interesting, so let me look inside <code class=\"language-text\">/dev/sdb</code>.</p>\n<p>From <code class=\"language-text\">lsblk</code>, the size of <code class=\"language-text\">/dev/sdb</code> is 10MB, so the end address is <code class=\"language-text\">0xa00000</code>.\nI output it with <code class=\"language-text\">hexdump</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash:bash\"><pre class=\"language-bash:bash\"><code class=\"language-bash:bash\">root@raspberrypi:~# hexdump -C /dev/sdb \n00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n*\n0005b800  02 00 00 00 0c 00 01 02  2e 00 00 00 02 00 00 00  |................|\n0005b810  0c 00 02 02 2e 2e 00 00  0b 00 00 00 24 00 0a 02  |............$...|\n0005b820  6c 6f 73 74 2b 66 6f 75  6e 64 00 00 0c 00 00 00  |lost+found......|\n0005b830  10 00 08 01 72 6f 6f 74  2e 74 78 74 0d 00 00 00  |....root.txt....|\n0005b840  c4 03 0a 01 64 61 6d 6e  69 74 2e 74 78 74 00 00  |....damnit.txt..|\n0005b850  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n*\n\n* Flag\n0080a800  33 64 33 65 34 38 33 31  34 33 66 66 31 32 65 63  |xxxxxxxxxxxxxxxx|\n0080a810  35 30 35 64 30 32 36 66  61 31 33 65 30 32 30 62  |xxxxxxxxxxxxxxxx|\n0080a820  0a 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n0080a830  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n*\n0080ac00  44 61 6d 6e 69 74 21 20  53 6f 72 72 79 20 6d 61  |Damnit! Sorry ma|\n0080ac10  6e 20 49 20 61 63 63 69  64 65 6e 74 61 6c 6c 79  |n I accidentally|\n0080ac20  20 64 65 6c 65 74 65 64  20 79 6f 75 72 20 66 69  | deleted your fi|\n0080ac30  6c 65 73 20 6f 66 66 20  74 68 65 20 55 53 42 20  |les off the USB |\n0080ac40  73 74 69 63 6b 2e 0a 44  6f 20 79 6f 75 20 6b 6e  |stick..Do you kn|\n0080ac50  6f 77 20 69 66 20 74 68  65 72 65 20 69 73 20 61  |ow if there is a|\n0080ac60  6e 79 20 77 61 79 20 74  6f 20 67 65 74 20 74 68  |ny way to get th|\n0080ac70  65 6d 20 62 61 63 6b 3f  0a 0a 2d 4a 61 6d 65 73  |em back?..-James|\n0080ac80  0a 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n0080ac90  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|\n*\n00a00000</code></pre></div>\n<p>I’m admittedly not well-versed in the address map of flash storage like USB memory, but it’s clear that the actual data is stored in the latter blocks.</p>\n<p>In other words, when James deleted root.txt from the USB, only the reference information pointing to root.txt was removed; the actual data remained at that address until it was overwritten by other data. That’s the key to obtaining root on this machine.</p>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>With this, I successfully completed the Mirai machine!\nThe defensive insights gained through this machine include:</p>\n<ul>\n<li>Default credentials are targeted</li>\n<li>Restrict sudo permissions</li>\n<li>Prevent external SSH access (use private key auth instead of password when exposing SSH)</li>\n<li>When deleting data from media devices, use overwrite deletion</li>\n</ul>\n<p>WriteUps are useful for organizing what I’ve learned, so I’d like to keep writing them.\nSee you next time.</p>","fields":{"slug":"/hackthebox-linux-mirai-en","tagSlugs":["/tag/hack-the-box-en/","/tag/linux-en/","/tag/easy-box-en/","/tag/english/"]},"frontmatter":{"date":"2021-10-04","description":"A writeup of the retired HackTheBox machine 'Mirai', covering IoT malware attack techniques and defenses.","tags":["HackTheBox (en)","Linux (en)","EasyBox (en)","English"],"title":"HackTheBox Writeup: Mirai (Easy/Linux)","socialImage":{"publicURL":"/static/dc4d8b7f8795f3c3d3489d9957d155f2/no-image.png"}}}},"pageContext":{"slug":"/hackthebox-linux-mirai-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}