Showing posts with label ActiveX Vulnerabilities. Show all posts
Showing posts with label ActiveX Vulnerabilities. Show all posts

Saturday, March 5, 2011

Exploiting Structured Exception Handler

Somethings kept me busy lately which was why there weren't much of a update in here. But I thought of just putting this across in spite of it being a very old topic. This blog will discuss about a buffer overflow vulnerability in the ActiveX control of AOL IWinampActiveX.

The vulnerable method within the control is the ConvertFile(). It takes 6 parameters out which the 1st parameter is prone to buffer overflow. When a overwhelming data is passed to the first parameters it results in overwriting the SEH handlers. It's a classic exploit which first creates an exception and when the exception returns to the SEH handler it will branch to the address that we have already overwritten. We craft the 1st element to contain 1400 bytes of 0xFF's and then a 1000 of 0xOC's. This is done because the first 0xFF will help us in making the exception and when the exception occurs the control would return to the already overwritten SEH handler address with 0x0C's. Without further delay I will walk you through debugging this vulnerability.


bof=string(1400,unescape("%ff")) + string(1000,unescape("%0c"))
IWinAmpActiveX.ConvertFile bof,1,1,1,1,1



The above code when executed overwrites the buffer with 1400 0xFF's followed by 0x0C's. When this is done, at some point in the code the data from the buffer is loaded into [EAX] and is compared with 9 - which is where the exception occurs. As the data in the buffer is flooded with 0xFF's EAX was also loaded with 0xFFFFFFFF. When comparing [EAX] which is [FFFFFFFF] an exception occurs. We can witness this in the debugger.


We can also see that the address of the SEH has been overwritten.


Structured exception handling is best explained here. In my own words when there's an error in the program the control of the program would be passed to a flow where it tries to rectify the error or terminate the program gracefully. In our case when there's an exception that occurred in our program it tries to find the SEH and jump to that location for the exception to be handled.

The exception in this case is handled by the OS. So when windows found the exception it calls the exception routine that handles the exception. As you have guessed it right the SEH was earlier overwritten with 0x0C0C0C0C the control of the program is transferred to that address. From below we can see that the SEH is being pushed into the stack. We earlier saw that SEH is at address 0013E574. As we have even overwritten data base 0013E574, [EBX+4] also has the value 0x0C0C0C0C.


Later down the line the address that was pused into the stack is popped into ECX and it been called. This ultimately changes the flow of the program which leads into the heap. We have already sprayed the heap with our shellcode, so everything went right in our case which results in the execution of the shellcode.


Thus the "call ecx" statement will take us to the heap resulting in shellcode execution ;)

Sunday, September 26, 2010

Buffer overflow ActiveX - JCOMOBJMGR2

Continuing from the last post of ActiveX vulnerability this post will walk through another ActiveX vulnerability within the JCom Obj Mgr2 control. This control is prone to a buffer overflow vulnerability which can be remotely exploited by a malicious user. The vulnerable method within the control is the "RemoveBandFile" method. This method takes one argument as the input and deletes the specified file that is provided from the system32 directory. That itself is a bit of worry because there is no checks that are implemented to verify what file the method is deleting.

Quickly we load Internet explorer into Ollydbg and pass the html exploit file as the argument. There are lot of POCs available on the internet for this particular vulnerable version of Jcom. Hence this post stays away from exploiting the vulnerability but will expose the actual code that is responsible for this vulnerability. Below is the sample html file which is crafted and fed as an argument to Ollydbg.


arg1=String(500, "A")
target.RemoveBandFile arg1

We pass excessive lengths string as argument to the vulnerable function to trigger the vulnerability. The length of arg1 argument is read by the control. As seen in the figure below the argument length can be seen returned in the EAX register. 500 dec = 1F4 hex


 The program flow then gets onto the vulnerable part where the strcat function is called. As an overwhelmingly large amount of input was provided the stack is overflown and parts of the stack is overwritten by the value that we have provided as argument. In this case 41414141.


As shown in the figure you can see that the argument that is passed to the method was initially concatenated with the System Directory path and then the resultant data is passed onto the DeleteFile function to delete the file. Malicious users can take advantage of this and can overwrite the stack with the address of their choice to redirect the control of the program to their liking.

When the program tries to return from that particular function it will pop the top of stack to EIP thereby redirecting the flow of the program.



binaryhax0r

Wednesday, September 8, 2010

UfPBCtrl ActiveX Remote Code Execution

An advisory has been posted on most of the security sites regarding the Trendmicro's Internet Security Pro 2010 product. It is on the subject of a vulnerability in the ActiveX control UfPBCtrl's function extSetOwner. This particular function takes one argument as the input and treats that a pointer to memory location. This causes the vulnerability as there are no prior checks that are done before the program starts using the pointer that has been passed to it. Malicious users can take advantage of this and can pass their own pointers which they have already allocated elsewhere in the memory. This can basically be achieved by the means of heap spraying. All the malicious user does is spray the memory with huge chunks of nop slide followed by the shellcode and then reference a memory address that points to the address of the shellcode (pass the memory address as argument to the function). More on the vulnerability in this advisory by Abysssec here. This blog post assumes that the reader is aware of basic Heap Spraying techniques.

As detailed in the advisory the vulnerable portion of the control is as below.


The parameter that is passed to the vulnerable method is taken into EAX register and is added by 4. After which the content of the EAX register [EAX] (EAX should actually contain certain valid memory address) is moved into ECX. It is visible in the third instruction of the screenshot that ECX is being called without any proper checking. So the vulnerable method would be called like,

exploit.extSetOwner(unescape(%u7190%u8979))

where the argument that is passed to the function is a valid address that inturn refers to the address in the memory where our shellcode is already heap sprayed. In order for this exploit to work the malicious user has to find himself a pattern within the memory that references the heap sprayed portion in the memory. As with the exploit that is available publicly a large nop slide + shellcode is sprayed to memory. Directing the execution to the nopslide + shellcode is fairly simple. Quickly if we search using ollydbg (for patterns) in memory we can find a memory location 7DD148F3. That belongs to MSHTML's address space. So if we have to pass this address to the vulnerable function we will have to modify the exploit a little bit. If we pass the argument as unescape('%u48F3%u7DD1') our exploit will work promptly. This is because the address that we have just passed will refer to 0A0A0A06 as seen in the screenshot below.


But the code says that EAX will be added by 4 and then the content of EAX will be moved to ECX register. So we will have to subtract 4 from our address which will make it to be 7DD148EF. Hence the final exploit code will turn into unescape('%u48EF%u7DD1'). Now when content of EAX is moved into ECX the register will take the figures as shown below.


As you can see here that the content of the EAX+4 (7DD148F3) is moved into ECX. ECX now holds the little endian format of 0A0A0A06. When we follow the memory location referenced by ECX we can see the nop slide clearly followed by the shell code.


And now when the program slides into CALL ECX instruction the nop slide will be executed followed by the shellcode which we can see clearly in stack that the shellcode simply calls CALC.EXE.


That clearly is a very serious vulnerability. The vendor has provided a hotfix for the this vulnerability. To keep yourself safe either set the killbit for this control or apply the hotfix provided by the vendor. The latter is the best option.

binaryhax0r