|
| 1 | +package fuzion24.device.vulnerability.vulnerabilities.framework.media; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.os.Build; |
| 5 | +import android.util.Log; |
| 6 | + |
| 7 | +import java.io.ByteArrayOutputStream; |
| 8 | +import java.io.File; |
| 9 | +import java.io.FileInputStream; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import fuzion24.device.vulnerability.util.CPUArch; |
| 14 | +import fuzion24.device.vulnerability.vulnerabilities.VulnerabilityTest; |
| 15 | +import fuzion24.device.vulnerability.vulnerabilities.helper.BinaryAssets; |
| 16 | +import fuzion24.device.vulnerability.vulnerabilities.helper.KMPMatch; |
| 17 | +import fuzion24.device.vulnerability.vulnerabilities.helper.SystemUtils; |
| 18 | + |
| 19 | +/** |
| 20 | + * Created by fuzion24 on 11/16/15. |
| 21 | + */ |
| 22 | + |
| 23 | + |
| 24 | +/* |
| 25 | +https://android.googlesource.com/platform/external/tremolo/+/3830d0b585ada64ee75dea6da267505b19c622fd%5E%21/#F1 |
| 26 | +https://android.googlesource.com/platform/frameworks/av/+/c6a2815eadfce62702d58b3fa3887f24c49e1864%5E%21/#F0 |
| 27 | +
|
| 28 | +2|shell@flounder_lte:/ $ grep -F "b/23881715" /system/lib/libstagefright.so |
| 29 | +1|shell@flounder_lte:/ $ grep -F "b/23881715" /system/lib64/libstagefright.so |
| 30 | +*/ |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +public class CVE_2015_6608 implements VulnerabilityTest { |
| 35 | + |
| 36 | + private static final String TAG = "CVE-2015-6608"; |
| 37 | + |
| 38 | + @Override |
| 39 | + public String getCVEorID() { |
| 40 | + return "CVE-2015-6608"; |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean isVulnerable(Context context) throws Exception { |
| 45 | + /* |
| 46 | + The patch includes logging messages for when the vulnerable code paths are hit. |
| 47 | + We can simply look for the inclusion of the strings in the libraries to determine |
| 48 | + whether or not the device has a patched libstagefright.so |
| 49 | + */ |
| 50 | + |
| 51 | + File stagefrightlib = new File("/system/lib/libstagefright.so"); |
| 52 | + File stagefrightlib64 = new File("/system/lib64/libstagefright.so"); |
| 53 | + |
| 54 | + File softAAClib = new File("/system/lib/libstagefright_soft_aacdec.so"); |
| 55 | + |
| 56 | + File libvorbisidec = new File("/system/lib/libvorbisidec.so"); |
| 57 | + |
| 58 | + if(!stagefrightlib.exists() || !stagefrightlib.isFile()){ |
| 59 | + throw new Exception("libstagefright.so doesn't exist or is not a file"); |
| 60 | + } |
| 61 | + |
| 62 | + if(!softAAClib.exists()){ |
| 63 | + throw new Exception("libstagefright_soft_aacdec.so does not exist"); |
| 64 | + } |
| 65 | + |
| 66 | + if(!libvorbisidec.exists()){ |
| 67 | + throw new Exception("libvorbisidec.so does not exist"); |
| 68 | + } |
| 69 | + |
| 70 | + |
| 71 | + ByteArrayOutputStream libStageFrightBAOS = new ByteArrayOutputStream((int)stagefrightlib.length()); |
| 72 | + BinaryAssets.copy(new FileInputStream(stagefrightlib), libStageFrightBAOS); |
| 73 | + byte[] libstagefrightSO = libStageFrightBAOS.toByteArray(); |
| 74 | + |
| 75 | + |
| 76 | + ByteArrayOutputStream libaacdecBAOS = new ByteArrayOutputStream((int)softAAClib.length()); |
| 77 | + BinaryAssets.copy(new FileInputStream(softAAClib), libaacdecBAOS); |
| 78 | + byte[] libaacdecSO = libaacdecBAOS.toByteArray(); |
| 79 | + |
| 80 | + ByteArrayOutputStream libvorbisidecBAOS = new ByteArrayOutputStream((int)libvorbisidec.length()); |
| 81 | + BinaryAssets.copy(new FileInputStream(libvorbisidec), libvorbisidecBAOS); |
| 82 | + byte[] libvorbisidecSO = libvorbisidecBAOS.toByteArray(); |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + KMPMatch binMatcher = new KMPMatch(); |
| 87 | + |
| 88 | + int indexOf = binMatcher.indexOf(libstagefrightSO, "b/23680780".getBytes()); |
| 89 | + boolean libstagefrightVulnerableToBug23680780 = indexOf == -1; |
| 90 | + indexOf = binMatcher.indexOf(libvorbisidecSO, "b/23881715".getBytes()); |
| 91 | + boolean libstagefrightvulnerableToBug23881715 = indexOf == -1; |
| 92 | + indexOf = binMatcher.indexOf(libaacdecSO, "b/23876444".getBytes()); |
| 93 | + boolean libstagefrightVulnerableToBug23876444 = indexOf == -1; |
| 94 | + |
| 95 | + |
| 96 | + Log.d(TAG, "libstagefrightVulnerableToBug23680780: " + libstagefrightVulnerableToBug23680780); |
| 97 | + Log.d(TAG, "libstagefrightvulnerableToBug23881715: " + libstagefrightvulnerableToBug23881715); |
| 98 | + Log.d(TAG, "libstagefrightVulnerableToBug23876444: " + libstagefrightVulnerableToBug23876444); |
| 99 | + |
| 100 | + //Only affects L and M |
| 101 | + if(Build.VERSION.SDK_INT != Build.VERSION_CODES.M && Build.VERSION.SDK_INT != Build.VERSION_CODES.LOLLIPOP){ |
| 102 | + return false; |
| 103 | + } |
| 104 | + |
| 105 | + return libstagefrightVulnerableToBug23680780 || |
| 106 | + libstagefrightvulnerableToBug23881715 || |
| 107 | + libstagefrightVulnerableToBug23876444; |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | + @Override |
| 112 | + public List<CPUArch> getSupportedArchitectures() { |
| 113 | + List<CPUArch> supportedArchs = new ArrayList<CPUArch>(); |
| 114 | + supportedArchs.add(CPUArch.ARM7); |
| 115 | + supportedArchs.add(CPUArch.ARM8); |
| 116 | + supportedArchs.add(CPUArch.X86); |
| 117 | + return supportedArchs; |
| 118 | + } |
| 119 | +} |
0 commit comments