Nebula Shell Exploits (Solutions 00-09)
Shell-based exploit exercises
Published on 22 June 2012Overview
Nebula is a series of “capture the flag” exercises from Exploit Exercises. I’ve been reading Hacking: The Art of Exploitation 2e – this was a good supplement.
The provided Ubuntu VM has 20 levels (00 - 19). The goal of each level is to run the getflag
command on a target account, either by exploiting a suid program or obtaining the password.
Solutions
To keep things shorter, a link to the full description is provided with each level. The full description contains relevant source code.
There’s no copy paste for Ubuntu Server VMs, but I included the output when it supplemented the solution.
Level 0
Description (full): Find a file with setuid permissions.
Search the root directory for files based on permissions. The file /bin/.../flag00
looks suspicious.
Level 1
Description (full): Given a program that calls /usr/bin/env echo and now what?
, execute an arbitrary program.
env
looks in the PATH
variable to find a program to run. Adding an executable named echo
to an earlier directory in the path will execute the program.
Level 2
Description (full): Given a program that calls /bin/echo $USER
, execute an arbitrary program.
Level 3
Description (full): There is a cron
job that runs occasionally. In the home directory, there is a writable.sh
and a writable.d/
.
Since cron jobs don’t write output to stdout
, the output should be logged in a file.
Level 4
Description (full): The program flag04
dumps the contents of a file to stdout, unless there is a substring match with the string "token"
. Examine the file /home/flag04/token/
.
token
contains the password to the flag04
account. su flag04
and capture the flag.
Level 5
Description (full): Exploit the directory permissions in /home/flag05/
.
The -C
flag for tar
switches directories before unarchiving. We then ssh to our own machine, but this time as flag05
.
Level 6
Description (full): The flag06
account credentials are from a legacy UNIX system.
Account credentials points toward /etc/passwd
:
According to the Internet, older UNIX systems stored the salted, hashed passwords in /etc/passwd
. Now, these are placed in the no-read /etc/shadow/
(or a variant). The flag06
is a one way hash, but John the Ripper can crack it. No special permissions are required to use it.
Level 7
Description (full): A Perl CGI script attempts to ping a given host.
If we run the script with perl
, getflag
still runs as the level07
user. The vulnerability exists in thttpd.conf
, which runs commands as flag07
(user=flag07
). Capturing the flag requires using thttpd.conf
.
ps aux
shows that a web server using thttpd is running. Using wget localhost:7007/index.cgi
, the parameter is passed in as the flag07
user.
Level 8
Description (full): Examine a capture.pcap
file to see what flag08
was doing.
After mucking around with tcpdump
in ASCII mode, however, it’s clear that the output is still unintelligible. The Internet (broadly speaking) suggests Wireshark (and its command line counterpart, tshark
) to examine packets, but the virtual machine doesn’t have these. However, a program named tcpflow
is available.
After the Password:
prompt, the flag08
user typed “backdoor…00Rm8.ate”. A few tries for su flag08
with backdoor
and backdoor...00Rm8.ate
are unsuccessful. But if we believe that:
- the password is based on words
- each packet represents a key press to the server
“Backdoor mate” could be
backdoorm8
,backd00Rm8
, etc. If the period represents deletion, then the password isbackd00Rmate
.
Level 9
Description (full): Exploit a C wrapper for a PHP script. The PHP script uses one argument but accepts a second, unused one – $useme
.
This exploits PHP’s “variable of variables.” Executing flag09 ~/foo system
also works.