Materiale

Per andare a svolgere le diverse challenge di questo corso, oltre al materiale del professore sto usando una guida youtube →https://www.youtube.com/watch?v=wZJqD93WPwk e altro materiale che trovo in rrete e che linkero’ qui. Buona lettura.

Level00

This level requires you to find a Set User ID program that will run as the “flag00” account. You could also find this by carefully looking in top level directories in / for suspicious looking directories. Alternatively, look at the find man page. To access this level, log in as level00 with the password of level00.

Per andare a svolgere questa prima challange e’ necessario utilizzare il comando find per trovare file che abbiamo il setuserid settato. Si consiglia quindi il seguente comando:

find / -perm -4000 -executable 2>/dev/null

In questo modo troviamo che uno dei primi risultati sia /bin/…/flag00 e andando ad analizzare il file col comando

ls -l

si scopre che effettivamente abbia impostato il setuserid: rwsr-x--- 1 flag00 level00 7358 2011-11-20 21:22 flag00

Level01

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 level01 account with the password level01. Files for this level can be found in /home/flag01.

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

The geteuid() function returns the effective user ID of the calling process. The effective user ID gives the process various permissions during execution of “set-user-ID” mode processes which use getuid() to determine the real user ID of the process that invoked them.

The getgid() function returns the real group ID of the calling process.

The setresuid() system call sets the real, effective and saved user IDs of the current process. The analogous setresgid() sets the real, effective and saved group IDs. Privileged processes may set these IDs to arbitrary values. Unprivileged processes are restricted in that each of the new IDs must match one of the current IDs.

Da https://docs.oracle.com/cd/E86824_01/html/E54765/getegid-2.html

Quale sarebbe l’idea in questo contesto: io sto lanciando un programma che ha settato setuserid. Questo programma ottiene gli id dell’effettive user e del real group con le prime due funzioni di sistema e successivamente setto real, effective, saved con i valori che ho ottenuto dall’effective user id precedente e group id.

A questo punto viene invocato echo attraverso un path che praticamente scandaglia tutti i possibili path che possiamo avere e lancia il primo echo che trova. Questo stampa and now what. Chiama echo essendo root (in questo caso flag01). Come possiamo fare in modo che anziche’ eseguire echo il mio programma vada ad eseguire getflag da utente flag01?

Una prima idea potrebbe essere: aggiungiamo al path un percorso per andare a cercare echo che possiamo controllare noi, ovvero la nostra home.

export PATH=/home/level01/:$PATH

A questo punto creiamo un link simbolico di getflag ad un link che chiamiamo echo e che posizioniamo all’interno della nostra home.