Skip to content

Commit

Permalink
Merge pull request #46 from nowsecure/feature/cpu_architecture
Browse files Browse the repository at this point in the history
Check architecture of device before running the test
  • Loading branch information
Fuzion24 committed Nov 9, 2015
2 parents bf0c95f + 452938b commit 66db826
Show file tree
Hide file tree
Showing 23 changed files with 151 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fuzion24.device.vulnerability.test.ui;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
Expand All @@ -13,6 +14,7 @@

import com.nowsecure.android.vts.R;

import java.lang.reflect.Method;
import java.util.List;

import fuzion24.device.vulnerability.test.ResultsCallback;
Expand All @@ -23,7 +25,7 @@

public class MainActivity extends AppCompatActivity {

private static final String LOG_TAG = "VULN_TEST";
private static final String TAG = "VULN_TEST";
private RecyclerView recyclerView;
private TextView emptyView;

Expand Down Expand Up @@ -67,13 +69,17 @@ public void onClick(View v) {
runTestsSuit();
}
});

}




private void runTestsSuit(){
new VulnerabilityTestRunner(MainActivity.this, true, new ResultsCallback() {
@Override
public void finished(List<VulnerabilityTestResult> results) {
Log.d(LOG_TAG, "Device Vulnerability callback, finished");
Log.d(TAG, "Device Vulnerability callback, finished");

emptyView.setVisibility(View.GONE);
recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
Expand Down
23 changes: 18 additions & 5 deletions app/src/main/java/fuzion24/device/vulnerability/util/CPUArch.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
package fuzion24.device.vulnerability.util;

public enum CPUArch {
ARM7,
ARM8,
X86,
X64,
ALL
ARM("armeabi"),
ARM7("armeabi-v7a"),
ARM8("arm64"),
X86("x86"),
X64("x64"),
MIPS("MIPS"),
ALL("ALL");

private final String arch;

public String getArch(){
return arch;
}

CPUArch(String archString){
arch = archString;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


import android.content.Context;
import android.util.Log;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import fuzion24.device.vulnerability.util.CPUArch;
import fuzion24.device.vulnerability.vulnerabilities.framework.graphics.GraphicBufferTest;
import fuzion24.device.vulnerability.vulnerabilities.framework.media.CVE_2015_6602;
import fuzion24.device.vulnerability.vulnerabilities.framework.media.StageFright;
Expand All @@ -22,26 +25,104 @@

public class VulnerabilityOrganizer {

private static final String TAG = "VulnerabilityOrganizer";

//TODO: Maybe add dates to each of these and sort chronologically
public static List<VulnerabilityTest> getTests(Context ctx){
List<VulnerabilityTest> tests = new ArrayList<VulnerabilityTest>();
tests.add(new ZipBug9950697());
tests.add(new ZipBug8219321());
tests.add(new ZipBug9695860());
// tests.add(new JarBug13678484());
tests.add(new CVE_2013_6123());
tests.add(new CVE_2011_1149());
tests.add(new CVE_2014_3153());
tests.add(new CVE_2014_4943());
List<VulnerabilityTest> allTests = new ArrayList<VulnerabilityTest>();
allTests.add(new ZipBug9950697());
allTests.add(new ZipBug8219321());
allTests.add(new ZipBug9695860());
// allTests.add(new JarBug13678484());
allTests.add(new CVE_2013_6123());
allTests.add(new CVE_2011_1149());
allTests.add(new CVE_2014_3153());
allTests.add(new CVE_2014_4943());
//tests.add(new StumpRoot());
//tests.add(new WeakSauce());
tests.add(new GraphicBufferTest());
tests.addAll(StageFright.getTests(ctx));
tests.add(new CVE_2015_6602());
tests.add(new OpenSSLTransientBug());
tests.add(new CVE_2015_3636());
allTests.add(new GraphicBufferTest());
allTests.addAll(StageFright.getTests(ctx));
allTests.add(new CVE_2015_6602());
allTests.add(new OpenSSLTransientBug());
allTests.add(new CVE_2015_3636());
//tests.add(new ZergRush()); // Hide super old bugs?
tests.add(new SamsungCREDzip());
return tests;
allTests.add(new SamsungCREDzip());

List<VulnerabilityTest> filteredTest = new ArrayList<VulnerabilityTest>();
String cpuArch1 = get(ctx, "ro.product.cpu.abi");
String cpuArch2 = get(ctx, "ro.product.cpu.abi2");


for(VulnerabilityTest vt : allTests){

if(vt.getSupportedArchitectures() == null) {
Log.d(TAG, "architectures is null for : " + vt.getName());
}

if(vt.getSupportedArchitectures().contains(CPUArch.ALL)){
filteredTest.add(vt);
} else {
if(isArchitectureSupported(vt, cpuArch1) &&
isArchitectureSupported(vt, cpuArch2)){
filteredTest.add(vt);
}
}
}
return filteredTest;
}


private static boolean isArchitectureSupported(VulnerabilityTest vt, String architecture){
if(architecture == null) return true;

for(CPUArch arch : vt.getSupportedArchitectures()){
if(arch.getArch().equals(architecture)){
return true;
}
}

return false;
}


//https://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties
/**
* Get the value for the given key.
* @return an empty string if the key isn't found
* @throws IllegalArgumentException if the key exceeds 32 characters
*/
public static String get(Context context, String key) throws IllegalArgumentException {

String ret= "";

try{

ClassLoader cl = context.getClassLoader();
@SuppressWarnings("rawtypes")
Class SystemProperties = cl.loadClass("android.os.SystemProperties");

//Parameters Types
@SuppressWarnings("rawtypes")
Class[] paramTypes= new Class[1];
paramTypes[0]= String.class;

Method get = SystemProperties.getMethod("get", paramTypes);

//Parameters
Object[] params= new Object[1];
params[0]= new String(key);

ret= (String) get.invoke(SystemProperties, params);

}catch( IllegalArgumentException iAE ){
throw iAE;
}catch( Exception e ){
ret= "";
//TODO
}

return ret;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public String getName() {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}

private native int checkGraphicsBuffer(int ver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class JarBug13678484 implements VulnerabilityTest {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public CVE_2015_6602() {}
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM7);
return null;
archs.add(CPUArch.ARM);
return archs;
}


@Override
public String getName() {
return "StageFright: cve-2015-6602";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ public String getName() {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String getName() {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public String getName() {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public String getName() {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ZipBug8219321 implements VulnerabilityTest {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}

public String getName(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String getName() {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}

private long getCRC(byte[]data){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public String getName(){
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}

public boolean isVulnerable(Context context) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ public class CVE_2011_1149 implements VulnerabilityTest {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class CVE_2013_6123 implements VulnerabilityTest {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}


@Override
public String getName() {
return "CVE-2013-6123/put/get_user";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class CVE_2014_3153 implements VulnerabilityTest {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ public class CVE_2014_4943 implements VulnerabilityTest {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public String getName() {
@Override
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ARM);
archs.add(CPUArch.ARM7);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class SamsungCREDzip implements VulnerabilityTest {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class StumpRoot implements VulnerabilityTest {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class WeakSauce implements VulnerabilityTest {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public String getName() {
public List<CPUArch> getSupportedArchitectures() {
ArrayList<CPUArch> archs = new ArrayList<CPUArch>();
archs.add(CPUArch.ALL);
return null;
return archs;
}


Expand Down
Binary file added screenshots/v.3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 66db826

Please sign in to comment.