Temi


🐲 Strategia di attacco


1. Analisi permessi file

Analizzando i permessi del file /opt/protostar/bin/stack5, si nota che il bit SETUID è attivo e l’utente owner è root. Analizzando inoltre il codice sorgente, si nota che non vi è traccia di abbassamento dei privilegi (privilege drop).

1. Analisi codice sorgente

Analizzando il codice sorgente della challenge:

int main(int argc, char **argv)
{
  char buffer[64];
  gets(buffer);
}

Viene riempito un buffer di 64 caratteri, con dati letti da terminale tramite la chiamata di sistema gets(). L’input non è controllato.

2. Studio approfondito del sistema

Prima di tutto si studia la funzione gets().

apropos gets # si scopre che si trova nella sezione 3 del manuale
man 3 gets

Leggendo la documentazione si scopre che:

<aside> 📑

gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF, which it replaces with '\0'. No check for buffer overrun is performed (see BUGS below).

</aside>

Non vengono fatti controlli sulla lunghezza del buffer. Nella sezione BUGS troviamo anche:

<aside> 📑

Never use gets(). Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

</aside>