getlogin vulnerabile

3

Leggevo " Una tassonomia degli errori di codifica " e ho un dubbio sul punto citato in C / C ++ > > Abuso di API > > Spesso utilizzato in modo errato: autenticazione (getlogin).

Non riesco a capire il vettore di attacco menzionato qui. Per citare una dichiarazione -

The getlogin() function is supposed to return a string containing the name of the user currently logged in at the terminal, but an attacker can cause getlogin() to return the name of any user logged in to the machine.

Come funziona?

    
posta AviD 15.03.2012 - 19:23
fonte

2 risposte

6

getlogin() funziona controllando una proprietà di stdin. Tuttavia, un malintenzionato può avviare il tuo programma con lo stdin reindirizzato ad un altro terminale di controllo di un altro utente, e questo ingannare getlogin() .

Non utilizzare getlogin() a scopo di sicurezza. Ti consigliamo di esaminare getuid() , geteuid() , getpwuid() e metodi simili.

    
risposta data 15.03.2012 - 19:41
fonte
5

Il primo problema è che non è protetto da thread e il buffer delle stringhe utilizzato non contiene un valore attendibile; Ad esempio, non puoi essere sicuro che il valore che ottieni non vada bene. US-CERT entra nei dettagli.

The results of getlogin() should not be trusted.

The getlogin() function returns a pointer to a string that contains the name of the user associated with the calling process. The function is not reentrant, meaning that if it is called from another process, the contents are not locked out and the value of the string can be changed by another process. This makes it very risky to use because the username can be changed by other processes, so the results of the function cannot be trusted.

US-CERT ha ulteriori dettagli sul problema . Un'alternativa è utilizzare la versione thread-safe getlogin_r () o utilizzare altri meccanismi.

Il secondo problema è che t qui è un difetto noto in SSH che consente agli aggressori per spoofare in modo specifico il risultato di getlogin () :

On platforms relying on getlogin() (mainly the different BSD variants) malicious users can at least send misleading messages to syslog and others applications (getlogin() call will return "root").

Rapid7 ha anche altri dettagli .

    
risposta data 15.03.2012 - 19:42
fonte

Leggi altre domande sui tag