{"componentChunkName":"component---src-templates-post-template-js","path":"/hackthebox-linux-teacher-en","result":{"data":{"markdownRemark":{"id":"94fdd6ff-bca3-5397-b419-ec94ec1157af","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/hackthebox-linux-teacher\">original page</a>.</p>\n</blockquote>\n<p>I use the penetration-testing learning platform “Hack The Box” to study security.\nAt the time of writing, my rank on Hack The Box is ProHacker.</p>\n<span class=\"gatsby-resp-image-wrapper\" style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 220px; \">\n      <a class=\"gatsby-resp-image-link\" href=\"/static/d9f5b0f1c00cf5945d5d103c87b24897/c8042/327080.png\" style=\"display: block\" target=\"_blank\" rel=\"noopener\">\n    <span class=\"gatsby-resp-image-background-image\" style=\"padding-bottom: 22.727272727272727%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsTAAALEwEAmpwYAAABXUlEQVQY0zWPTU8TURSG51+4Z6MbCXQotJ17h7md29Kp/UjpOKVDWmimgiFUwcqCVop87FzpwrgyLk3csuAn+Kvu463GxZs3Ocl5znOcj7MplxdvzPXsLclej/puj0a3RzvZp5sOSQ/H1DsJIqyhak22tjUqauGFEbJSR+iIvCzjeoGxwfn148o8/PzE78fv3CymZCdnTC/nHE/Omby7YH5zx3B8jGruEg9G9mBCtz9gfPSKveGIQXZEIagsgWyI0DiL2xafv8zMt6933C/e00oO2R+9tjZtfN0kTjOU7Y1WSk53WA8aSF1meiAQwTYV7bNWVLgladYKLk67t2Ky04gP8wOyUUwYezT6imosiPolXqQS3RF4VZ/qyyKy7tvlMptSWSNl37VmXsh6yUUnT4zzPPfUDp4ZP9gkLySlivgXLfF2llnCJIWyj6zZVkugNfL+J/gLzhWlWc27/AF2msC3VU1XuAAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"></span>\n  <picture>\n          <source srcset=\"/static/d9f5b0f1c00cf5945d5d103c87b24897/b5458/327080.webp 220w\" sizes=\"(max-width: 220px) 100vw, 220px\" type=\"image/webp\">\n          <source srcset=\"/static/d9f5b0f1c00cf5945d5d103c87b24897/c8042/327080.png 220w\" sizes=\"(max-width: 220px) 100vw, 220px\" type=\"image/png\">\n          <img class=\"gatsby-resp-image-image\" src=\"/static/d9f5b0f1c00cf5945d5d103c87b24897/c8042/327080.png\" alt=\"Hack The Box\" title=\"Hack The Box\" loading=\"lazy\" style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\">\n        </picture>\n  </a>\n    </span>\n<p>This time I am writing up the retired HackTheBox machine “Teacher”.</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 encourage acts that are contrary to social order.</strong></p>\n<p>Please note that attempting attacks against environments other than those you own or are authorized to use may violate the Act on the Prohibition of Unauthorized Computer Access (the Unauthorized Access Prohibition Act).</p>\n<p>All statements here are my own and do not represent 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=\"#enumeration\">Enumeration</a></li>\n<li><a href=\"#gaining-a-shell\">Gaining a Shell</a></li>\n<li><a href=\"#getting-a-user\">Getting a User</a></li>\n<li><a href=\"#privilege-escalation\">Privilege Escalation</a></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>As usual, I started with a port scan.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ <span class=\"token function\">sudo</span> <span class=\"token function\">sed</span> -i <span class=\"token string\">'s/^[0-9].*$RHOST/10.10.10.153  $RHOST/g'</span> /etc/hosts\n\n$ nmap -sV -sC -Pn -T4 <span class=\"token variable\">$RHOST</span><span class=\"token operator\">|</span> <span class=\"token function\">tee</span> nmap1.txt\nNmap scan report <span class=\"token keyword\">for</span> <span class=\"token variable\">$RHOST</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10.10</span>.10.153<span class=\"token punctuation\">)</span>\nHost is up.\nAll <span class=\"token number\">1000</span> scanned ports on <span class=\"token variable\">$RHOST</span> <span class=\"token punctuation\">(</span><span class=\"token number\">10.10</span>.10.153<span class=\"token punctuation\">)</span> are <span class=\"token keyword\">in</span> ignored states.\nNot shown: <span class=\"token number\">1000</span> filtered tcp ports <span class=\"token punctuation\">(</span>no-response<span class=\"token punctuation\">)</span>\n\n$ nmap -p- <span class=\"token variable\">$RHOST</span> -Pn -sC -sV -A  <span class=\"token operator\">|</span> <span class=\"token function\">tee</span> nmap_max.txt</code></pre></div>\n<p>It looked like all ports in the fast scan were being filtered.</p>\n<p>With everything filtered, it was impossible to tell whether any ports were actually open.</p>\n<p>I also tried scanning all ports, but unfortunately those were filtered as well.</p>\n<p>I thought I was completely stuck, but it turned out to be a silly mistake — I simply was not connected to the VPN.</p>\n<p>After connecting to the VPN, I found the following open ports:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">PORT      STATE    SERVICE         VERSION\n<span class=\"token number\">80</span>/tcp    <span class=\"token function\">open</span>     http            Apache httpd <span class=\"token number\">2.4</span>.25 <span class=\"token variable\"><span class=\"token punctuation\">((</span>Debian<span class=\"token punctuation\">))</span></span>\n<span class=\"token operator\">|</span>_http-title: Blackhat highschool\n<span class=\"token operator\">|</span>_http-server-header: Apache/2.4.25 <span class=\"token punctuation\">(</span>Debian<span class=\"token punctuation\">)</span>\n<span class=\"token number\">1069</span>/tcp  filtered cognex-insight\n<span class=\"token number\">1084</span>/tcp  filtered ansoft-lm-2\n<span class=\"token number\">1085</span>/tcp  filtered webobjects\n<span class=\"token number\">1434</span>/tcp  filtered ms-sql-m\n<span class=\"token number\">2222</span>/tcp  filtered EtherNetIP-1\n<span class=\"token number\">3766</span>/tcp  filtered sitewatch-s\n<span class=\"token number\">5544</span>/tcp  filtered unknown\n<span class=\"token number\">5815</span>/tcp  filtered unknown\n<span class=\"token number\">6004</span>/tcp  filtered X11:4\n<span class=\"token number\">7402</span>/tcp  filtered rtps-dd-mt\n<span class=\"token number\">8087</span>/tcp  filtered simplifymedia\n<span class=\"token number\">8181</span>/tcp  filtered intermapper\n<span class=\"token number\">9071</span>/tcp  filtered unknown\n<span class=\"token number\">9099</span>/tcp  filtered unknown\n<span class=\"token number\">9415</span>/tcp  filtered unknown\n<span class=\"token number\">9929</span>/tcp  filtered nping-echo\n<span class=\"token number\">15004</span>/tcp filtered unknown\n<span class=\"token number\">32776</span>/tcp filtered sometimes-rpc15\n<span class=\"token number\">32782</span>/tcp filtered unknown\n<span class=\"token number\">49167</span>/tcp filtered unknown\n<span class=\"token number\">65000</span>/tcp filtered unknown</code></pre></div>\n<p>For now, I connected to the open port 80 and continued enumeration.</p>\n<p>Port 80 appeared to be running some kind of CMS site.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/180a173c121a6ac27fc79804d75ad238/62da8/image-20220806185608094.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: 57.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAMCAYAAABiDJ37AAAACXBIWXMAAAsTAAALEwEAmpwYAAADCUlEQVQoz2WS60/TVxzGf3/EzEiWqBHjEJRprARocaxiC7SUWltKocil9gLl3juNlIvVsMWIYiwZ0CkqumWZLFmUO6XFhVfGt1v2Qt8sS/ZHfHZ+RxNf7MWT55zv7/k9ec5zjnKi9CznKmo4eVpD8ZflHC0+yaGiI3z2uYDkw59QdOR/OPRFsdAf5tjxEoqOaVD29vLs778mny9I3t7JsbObY2NzW6x32RH7QmFfIpfLs7a+KWebWzvs5ffJF16jehwcHLCxvo5yO/Mjc0sv+OH5Bg9/2mLp2RrZ5+ssrrzifnaVF2u/89e7f1hZzYn5hvyW/ahd/nlb6haeviTz6DdWftlGKdW5qagPUGUKojH4qDb3o7MMytkZfQ+1tlGMrji65mGqLUNoBXTWYS62xNA7olQJvcbo5yu9B6c3hWJwRjB3JGlwxdCa+zC2RjG0hKls8KM19cp9e+8NOgJT+EZm8AzewuWdwN51HXv3OJa2OI3OMLp6H+7eSZSqxgAm9xiWzuvS2NqVorF9jDpHiLP6bi40BWkOfktzLEPr+CKX4/OYQ3MYh+5iCj3AHBYI3aey5ybugZsfDFWDepFQNVET1znCXLSPUqJto7bBhya8iLfwN42rfxDIvce3+x7jr3/SufVOrtNv/6Vy+Q3OyD0U9UfVxOCMSq69PMTX1kHOG65RUu2itqmPGt8MJ6KPOD66REk4S1l8mdLEE06PPaE8+ZRTiceURx/iic2iqB1davmQqOlqUhqfN3gp1boo07VRYxnApGosQeqEud4UwNoWwyG0NndCsr1jDLvgQOT2J0M1nTMwLXpMUCaOWn6hQ3TYRYXRh1WU3+KfwuZJ0SouyBO+gzcyS+fwd9iuTWH3p2numSSYuIuit4fQNfXLDq94p3H40lwSt3auzsOZb7plWrM7+bGOYXmCK8JEhc0zhVUYWXsmMF8dxx+5g+IRT2EgOUf0xgLx9JLgRRK3soykHshn4Oqdpr1/hr7EPUZTGUbGM0SmFyTCk9+L2TyhiXmhnyc9+5j/AMFxIiClw0qsAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/180a173c121a6ac27fc79804d75ad238/8ac56/image-20220806185608094.webp 240w,\n/static/180a173c121a6ac27fc79804d75ad238/d3be9/image-20220806185608094.webp 480w,\n/static/180a173c121a6ac27fc79804d75ad238/e46b2/image-20220806185608094.webp 960w,\n/static/180a173c121a6ac27fc79804d75ad238/24091/image-20220806185608094.webp 1262w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/180a173c121a6ac27fc79804d75ad238/8ff5a/image-20220806185608094.png 240w,\n/static/180a173c121a6ac27fc79804d75ad238/e85cb/image-20220806185608094.png 480w,\n/static/180a173c121a6ac27fc79804d75ad238/d9199/image-20220806185608094.png 960w,\n/static/180a173c121a6ac27fc79804d75ad238/62da8/image-20220806185608094.png 1262w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/180a173c121a6ac27fc79804d75ad238/d9199/image-20220806185608094.png\"\n            alt=\"image-20220806185608094\"\n            title=\"image-20220806185608094\"\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>Since there were no obvious clues, I ran feroxbuster, which revealed a redirect when accessing the <code class=\"language-text\">/moodle</code> path.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ feroxbuster -u http://<span class=\"token variable\">$RHOST</span>/ -x php -w /usr/share/wordlists/raft-medium-directories.txt --no-recursion <span class=\"token operator\">|</span> <span class=\"token function\">tee</span> feroxbuster.txt\n\n<span class=\"token number\">301</span>      GET        9l       28w      317c http://<span class=\"token variable\">$RHOST</span>/moodle <span class=\"token operator\">=</span><span class=\"token operator\">></span> http://<span class=\"token variable\">$RHOST</span>/moodle/</code></pre></div>\n<p>Opening that address in a browser redirected to <code class=\"language-text\">http://teacher.htb/moodle/</code>, so I updated the hosts file and accessed the page.</p>\n<p>This connected me to what appeared to be a Moodle administration site.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0dcea626dd2c44f8462f58dd95bd0a6e/690c6/image-20220806213248955.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: 37.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAICAYAAAD5nd/tAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA/ElEQVQoz63Pe0rDQBDH8b2BYmy1NlYqwfqgXso/vEZPYfGZWvpAsVdSqFgaTGw0D2h2k6/biCCKSNWBDywzsz8YYW1a7O3sUqnWKK5U2NquY9X2KZlWrrC6wYJRYtFY+2q5jFE0WSqYlNerFCt1xGGjyUHjjMHNgE7vOtftXdHu9LFbHezLLq1vzGYnpxccNY+x2339PkcMJwm3T5L/qCSRiPHoHtcZIaXSpG4mc3n7I0lTheM4iDAICDTf9wnDcO7Amel0ilIK99FF3D04DMceL88+URz96WTP8xCTIMaLFLHM8maWZb+SB7o6MMtSfX+K0t4HH5d+qs+Br2qAK8MgcExgAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/0dcea626dd2c44f8462f58dd95bd0a6e/8ac56/image-20220806213248955.webp 240w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/d3be9/image-20220806213248955.webp 480w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/e46b2/image-20220806213248955.webp 960w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/3718f/image-20220806213248955.webp 1201w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/0dcea626dd2c44f8462f58dd95bd0a6e/8ff5a/image-20220806213248955.png 240w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/e85cb/image-20220806213248955.png 480w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/d9199/image-20220806213248955.png 960w,\n/static/0dcea626dd2c44f8462f58dd95bd0a6e/690c6/image-20220806213248955.png 1201w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/0dcea626dd2c44f8462f58dd95bd0a6e/d9199/image-20220806213248955.png\"\n            alt=\"image-20220806213248955\"\n            title=\"image-20220806213248955\"\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>I wanted to look for exploits from here, but it turned out that the Moodle version can only be viewed by accounts with teacher-level privileges or higher.</p>\n<p>Reference: <a href=\"https://www.exploit-db.com/exploits/49114\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Moodle 3.8 - Unrestricted File Upload - PHP webapps Exploit</a></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/438ea25de35e23815727bb3b472b1e08/f2d92/image-20220806232551041.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: 17.916666666666668%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAECAYAAACOXx+WAAAACXBIWXMAAAsTAAALEwEAmpwYAAAApklEQVQY063KQQ6CMBAF0F7CCGiBKmpkozcQCoWUQtAY738BYAddfkvFjWsneZn8P0NoECFgB4TsiNWawnEpqM+w9SNjj/nueiG8DfvkpXO8ALsoxim+Li4I92cQLiqo9gXZPJEKhbK6Q9YP8KJGXjbIzOZipmxXyBbCyIoGNy6R5AqpkWTK/pG+72ENg9V1HYZl287c5vztxnGE1tqapumHBsGf5w01idxmPkV/FQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/438ea25de35e23815727bb3b472b1e08/8ac56/image-20220806232551041.webp 240w,\n/static/438ea25de35e23815727bb3b472b1e08/d3be9/image-20220806232551041.webp 480w,\n/static/438ea25de35e23815727bb3b472b1e08/e46b2/image-20220806232551041.webp 960w,\n/static/438ea25de35e23815727bb3b472b1e08/25665/image-20220806232551041.webp 1027w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/438ea25de35e23815727bb3b472b1e08/8ff5a/image-20220806232551041.png 240w,\n/static/438ea25de35e23815727bb3b472b1e08/e85cb/image-20220806232551041.png 480w,\n/static/438ea25de35e23815727bb3b472b1e08/d9199/image-20220806232551041.png 960w,\n/static/438ea25de35e23815727bb3b472b1e08/f2d92/image-20220806232551041.png 1027w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/438ea25de35e23815727bb3b472b1e08/d9199/image-20220806232551041.png\"\n            alt=\"image-20220806232551041\"\n            title=\"image-20220806232551041\"\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>I spent a while trying various exploits from here, but none of them landed.</p>\n<p>Going back to enumeration, I noticed that the file <code class=\"language-text\">images/5.png</code> in the gallery appeared as blank space, which caught my attention.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/58b8ee77dfba21d0f49be20bd5fae8e0/d7ba6/image-20220807110613844.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: 44.583333333333336%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAJCAYAAAAywQxIAAAACXBIWXMAAAsTAAALEwEAmpwYAAACHklEQVQoz0WS20tUYRTFz5/VS489FvUHlBAE4UvSmw9KZHYRIqSUMEslhdDsJkYzWr4UVopm3nLKFJ3xMmfObeZ8537m154ZxhYsNh/svfba+9va/OIaPzd2WFr9w/rWLg+evKKjZ4SV9W1+CJdWf7O4kmMvX6DkFDk0C5iug+2WUYGLF3qoUBEnMdVqFc1xHOI4rjNNE2FKkiTyjoiiiCYsy6JU1DFtgzgKSYKonltDTagJzTAt/CAUBijPxylXcJXCk4KyW+uc1gsMw8QxxJmhoxxF6P1v1kC14VBJcROFosGnzBTZobsUCnu8GRum7cplZjMfRNDALSuswzx2QafiuIQyQRAGBGImTRsuNdd1TyzvyEjDD2/yur+byel3dLS10tt+lZGnA5REsFZk6wbl4jHOkYlrCy0HZbtEfkgsU4lD98Rh7sii4/ksbaNrPPu4zYveTr5n+1leyaIfl+o5XsWjfCxudZtKsVSPnuXW6YuwplsV9nNrWKbJ5/kFZjLvmZyY4PHwEOOjfQz23WNgTByKkxqi2m5FSBmyexnbs5VERaQCQmmmrW7kmHvUyebiAt/mpjmY6mZz/Dad7a1cPHeKG5cucLblPH+P8qRxgud56Ie6fJBJ4ItIGBIGzRii7S594Vf2LfvLX5nJZpnovsbWy/v03Oqi5cxpBruu0zN4h/zBDlW5kkTuzRchp9TYny+XEPhC5RPIlfwDgpqGcIrAEX0AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/58b8ee77dfba21d0f49be20bd5fae8e0/8ac56/image-20220807110613844.webp 240w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/d3be9/image-20220807110613844.webp 480w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/e46b2/image-20220807110613844.webp 960w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/83eb4/image-20220807110613844.webp 1107w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/58b8ee77dfba21d0f49be20bd5fae8e0/8ff5a/image-20220807110613844.png 240w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/e85cb/image-20220807110613844.png 480w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/d9199/image-20220807110613844.png 960w,\n/static/58b8ee77dfba21d0f49be20bd5fae8e0/d7ba6/image-20220807110613844.png 1107w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/58b8ee77dfba21d0f49be20bd5fae8e0/d9199/image-20220807110613844.png\"\n            alt=\"image-20220807110613844\"\n            title=\"image-20220807110613844\"\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<h2 id=\"gaining-a-shell\" style=\"position:relative;\"><a href=\"#gaining-a-shell\" aria-label=\"gaining a shell 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>Gaining a Shell</h2>\n<p>After exploring the console, researching vulnerabilities, and trying many approaches, the following exploit finally worked.</p>\n<p>Reference: <a href=\"https://www.exploit-db.com/exploits/46551\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Moodle 3.4.1 - Remote Code Execution - PHP webapps Exploit</a></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 628px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/574753d84ece616506ab1425ae70f295/3d84d/image-20220807224459952.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: 28.750000000000004%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA/0lEQVQY022QWU7EMBBEcxtAMHwQb9nsOPueEO5/lqLdzAxIzMdTVbetUtmRLDyM6+H6Dd1yop2/UHYzTJ5iWWfs+4rjc8NxrOzPc8dOPszrttBuwUH7cR6gtUbk6wq2LOCrEtM8YllGOGeZJEn4UmIMeQOlFKP1TTWrofNA8FFhc+jUIM0SdF2LcepJGzRNdddxGrhR37do2pr3LRHmuvZUxqOiQkpJRN3QwrocHyKmVg55nsH7krG24KZl6ZgQbq3ls5pe5r1DlqaQUv60l9QwPFVqgdfLG4QQkEKyPiKO/8xXfwuT8hoYK4Gnl2dc3i/3P/pFPtj9J4RyMAV+A0lJzWLOiat3AAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/574753d84ece616506ab1425ae70f295/8ac56/image-20220807224459952.webp 240w,\n/static/574753d84ece616506ab1425ae70f295/d3be9/image-20220807224459952.webp 480w,\n/static/574753d84ece616506ab1425ae70f295/724e7/image-20220807224459952.webp 628w\"\n              sizes=\"(max-width: 628px) 100vw, 628px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/574753d84ece616506ab1425ae70f295/8ff5a/image-20220807224459952.png 240w,\n/static/574753d84ece616506ab1425ae70f295/e85cb/image-20220807224459952.png 480w,\n/static/574753d84ece616506ab1425ae70f295/3d84d/image-20220807224459952.png 628w\"\n            sizes=\"(max-width: 628px) 100vw, 628px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/574753d84ece616506ab1425ae70f295/3d84d/image-20220807224459952.png\"\n            alt=\"image-20220807224459952\"\n            title=\"image-20220807224459952\"\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>This gave me a shell, but the privileges were still low, so I continued enumeration from here.</p>\n<h2 id=\"getting-a-user\" style=\"position:relative;\"><a href=\"#getting-a-user\" aria-label=\"getting a user 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>Getting a User</h2>\n<p>Browsing around, I found DB credentials embedded in a file called <code class=\"language-text\">config.php</code>.</p>\n<p>I extracted a database dump with the following command:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">$ mysqldump -u <span class=\"token string\">'root'</span> -p -h <span class=\"token string\">'localhost'</span> <span class=\"token string\">'moodle'</span> <span class=\"token operator\">></span> /tmp/output.txt</code></pre></div>\n<p>Going through the DB contents, I found that in addition to Giovanni (whose credentials I had obtained), there was an Admin user, and password hashes were stored in the DB.</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\">Admin <span class=\"token variable\">$2y</span><span class=\"token variable\">$10</span><span class=\"token variable\">$7VPsdU9</span>/9y2J4Mynlt6vM.a4coqHRXsNTOq/1aA6wCWTsF2wtrDO2\ngiovanni <span class=\"token variable\">$2y</span><span class=\"token variable\">$10</span><span class=\"token variable\">$38V6kI7LNudORa7lBAT0q</span>.vsQsv4PemY7rf/M1Zkj/i1VqLO0FSYO</code></pre></div>\n<p>I spent a while trying to crack the Admin hash, but on closer inspection I noticed there was another user registered called <code class=\"language-text\">Giovannibak</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 898px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/649fc37c19bfc441a3cf6c3ca3538921/84cc5/image-20220808115139623.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: 27.083333333333332%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAFCAYAAABFA8wzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAA5klEQVQY02VQW46DMBDjQFsFkRICeUChlEcCbXfvfxY3M61Qpf2wPJlkHI8z5yyMqWGdgfcWTVPDpZrYtw5932FZJnRde6BtPeq6/oeqqpCpSqEsz4eQlJLFjWlQFAV0euScS/cN94i/a/M5W2uhtUYmhDhE8lzg53RKDiyG6wVt53EdeyzrjBhXzMnptgXse8Saevd7RNxW5nm+QSmFjFyQQxomh0LkLBbCjPE2MP/+PfB87iwWwsLDUwJFMU0j98ZxeAvS3lqrhIoFKU+lSv5EniWv1l3euVF+xhjOiyL6zo/WJq0X9XOr3pN4fS8AAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/649fc37c19bfc441a3cf6c3ca3538921/8ac56/image-20220808115139623.webp 240w,\n/static/649fc37c19bfc441a3cf6c3ca3538921/d3be9/image-20220808115139623.webp 480w,\n/static/649fc37c19bfc441a3cf6c3ca3538921/005c4/image-20220808115139623.webp 898w\"\n              sizes=\"(max-width: 898px) 100vw, 898px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/649fc37c19bfc441a3cf6c3ca3538921/8ff5a/image-20220808115139623.png 240w,\n/static/649fc37c19bfc441a3cf6c3ca3538921/e85cb/image-20220808115139623.png 480w,\n/static/649fc37c19bfc441a3cf6c3ca3538921/84cc5/image-20220808115139623.png 898w\"\n            sizes=\"(max-width: 898px) 100vw, 898px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/649fc37c19bfc441a3cf6c3ca3538921/84cc5/image-20220808115139623.png\"\n            alt=\"image-20220808115139623\"\n            title=\"image-20220808115139623\"\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>The Giovannibak hash cracked instantly, and using that password I was able to obtain the User flag.</p>\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>Inside the user’s home directory there are several <code class=\"language-text\">answersAlgebra</code> files. The directory owner in the backup was <code class=\"language-text\">giovanni</code>, but the folders placed inside the directory were owned by <code class=\"language-text\">root</code>.</p>\n<blockquote>\n<p>giovanni@teacher:/tmp/courses/algebra$ strings answersAlgebra\nPoint a = 3\nPoint b = 5\nPoint c = ?\n3 * 3 = 9\n5 * 5 = 25\n---+\nv34 = 5,83\nPoint c = 5,83\nscore: 1/2</p>\n</blockquote>\n<p>Another observation: only the backup files were owned by root, and their modification timestamps were changing frequently.</p>\n<p>This suggested that root was periodically compressing the courses folder into a backup archive — making it a good entry point for privilege escalation.</p>\n<p>I used <code class=\"language-text\">pspy</code> to check running tasks and found that a script called <code class=\"language-text\">backup.sh</code> was being called.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 960px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/8ef9bbdda5ffebeebf1651d772501d19/587b0/image-20220808141218071.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: 13.333333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAADCAIAAAAcOLh5AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAmklEQVQI1z2NSw6CMBQAOY26YCX0T997LbQFIUUUJTHx/tewK5NZzWKmIkKwxg2Jxh3j2grjby+uLNMAce36WVrPDbWyYwpaaRuumSKmSdihcp6IwIcJpyfG3Ajd548bN2FcaRk3+fkd798i/XIUeeW6tJh2EkKFBBY67BOkB4TccOXmA2JmCt2022GBtCkMXGM513V9OZ/+/AAr+iwxOvQhqQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/8ef9bbdda5ffebeebf1651d772501d19/8ac56/image-20220808141218071.webp 240w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/d3be9/image-20220808141218071.webp 480w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/e46b2/image-20220808141218071.webp 960w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/dbca2/image-20220808141218071.webp 970w\"\n              sizes=\"(max-width: 960px) 100vw, 960px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/8ef9bbdda5ffebeebf1651d772501d19/8ff5a/image-20220808141218071.png 240w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/e85cb/image-20220808141218071.png 480w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/d9199/image-20220808141218071.png 960w,\n/static/8ef9bbdda5ffebeebf1651d772501d19/587b0/image-20220808141218071.png 970w\"\n            sizes=\"(max-width: 960px) 100vw, 960px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/8ef9bbdda5ffebeebf1651d772501d19/d9199/image-20220808141218071.png\"\n            alt=\"image-20220808141218071\"\n            title=\"image-20220808141218071\"\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>The script looked like this:</p>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre class=\"language-bash\"><code class=\"language-bash\"><span class=\"token shebang important\">#!/bin/bash</span>\n<span class=\"token builtin class-name\">cd</span> /home/giovanni/work<span class=\"token punctuation\">;</span>\n<span class=\"token function\">tar</span> -czvf tmp/backup_courses.tar.gz courses/*<span class=\"token punctuation\">;</span>\n<span class=\"token builtin class-name\">cd</span> tmp<span class=\"token punctuation\">;</span>\n<span class=\"token function\">tar</span> -xf backup_courses.tar.gz<span class=\"token punctuation\">;</span>\n<span class=\"token function\">chmod</span> <span class=\"token number\">777</span> * -R<span class=\"token punctuation\">;</span></code></pre></div>\n<p>The key observation: after moving to the <code class=\"language-text\">tmp</code> directory, <code class=\"language-text\">chmod 777 * -R</code> recursively changes permissions on everything there.</p>\n<p>This means that by removing the <code class=\"language-text\">tmp</code> directory and replacing it with an arbitrary symbolic link, I could cause <code class=\"language-text\">chmod 777 -R</code> to apply to every file in any target directory.</p>\n<p>Any directory would work, but since I wanted to get a shell from <code class=\"language-text\">backup.sh</code> running as root, I set the symlink as <code class=\"language-text\">ln -s /usr/bin tmp</code>.</p>\n<p>This let me overwrite <code class=\"language-text\">backup.sh</code> and obtain a root shell.</p>","fields":{"slug":"/hackthebox-linux-teacher-en","tagSlugs":["/tag/hack-the-box-en/","/tag/linux-en/","/tag/easy-box-en/","/tag/english/"]},"frontmatter":{"date":"2022-08-06","description":"A writeup of the retired HackTheBox machine 'Teacher'.","tags":["HackTheBox (en)","Linux (en)","EasyBox (en)","English"],"title":"HackTheBox Writeup: Teacher (Easy/Linux)","socialImage":{"publicURL":"/static/dc4d8b7f8795f3c3d3489d9957d155f2/no-image.png"}}}},"pageContext":{"slug":"/hackthebox-linux-teacher-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}