测试黑客

Android漏洞检测——模糊测试

2017-06-24  本文已影响745人  希格斯子
前言

Android在目前的市场上占有率很高,用户数量庞大,而在该平台下的应用程序开发成本低,开发难度低,发布容易,缺少监管和审查,导致大量低质量App流入市场,这些App由于开发者缺乏安全编程技能或缺乏测试和审查,可能存在着一些严重的漏洞,对用户的隐私以及财产安全造成巨大风险。因此,移动应用尤其是Android平台下的应用的开发应该对此引起高度重视。

Android常见漏洞
Android常见漏洞检测方法
模糊测试
模糊测试工具IntentFuzzer

本文将介绍一种模糊测试工具,IntentFuzzer。

主界面 应用列表 测试组件列表
    public static List<AppInfo> getPackageInfo(Context context, int type){
        List<AppInfo> pkgInfoList = new ArrayList<AppInfo>();
        List<PackageInfo> packages = context.getPackageManager().getInstalledPackages(
//              PackageManager.GET_DISABLED_COMPONENTS |
                        PackageManager.GET_ACTIVITIES
                | PackageManager.GET_RECEIVERS
                | PackageManager.GET_INSTRUMENTATION
                | PackageManager.GET_SERVICES); 
        
        for(int i=0;i<packages.size();i++) {   
            PackageInfo packageInfo = packages.get(i);
            if (type == SYSTEM_APPS) {
                if((packageInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 1) {
                    pkgInfoList.add(fillAppInfo(packageInfo, context));   
                }
            }else if(type == NONSYSTEM_APPS){
                if((packageInfo.applicationInfo.flags&ApplicationInfo.FLAG_SYSTEM) == 0) {
                    pkgInfoList.add(fillAppInfo(packageInfo, context));   
                }
            }else {
                pkgInfoList.add(fillAppInfo(packageInfo, context)); 
            }
        }

构建Intent

    private void initView(){
        typeSpinner = (Spinner) findViewById(R.id.type_select);
        cmpListView = (ListView) findViewById(R.id.cmp_listview);
        fuzzAllNullBtn = (Button) findViewById(R.id.fuzz_all_null);
        fuzzAllSeBtn = (Button) findViewById(R.id.fuzz_all_se);
        cmpListView.setOnItemClickListener(new OnItemClickListener(){

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    ComponentName toSend = null;
                    Intent intent = new Intent();
                    String className =  cmpAdapter.getItem(position).toString();
                    for (ComponentName cmpName : components) {
                        if (cmpName.getClassName().equals(className)) {
                            toSend = cmpName;
                            break;
                        }
                    }
                    intent.setComponent(toSend);
                    if (sendIntentByType(intent, currentType)) {
                        Toast.makeText(FuzzerActivity.this, "Sent Null " + intent, Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(FuzzerActivity.this, "Send " + intent + " Failed!", Toast.LENGTH_LONG).show();
                    }
                }
            
           });
        cmpListView.setOnItemLongClickListener(new OnItemLongClickListener(){

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO Auto-generated method stub
                ComponentName toSend = null;
                Intent intent = new Intent();
                String className =  cmpAdapter.getItem(position).toString();
                for (ComponentName cmpName : components) {
                    if (cmpName.getClassName().equals(className)) {
                        toSend = cmpName;
                        break;
                    }
                }
                intent.setComponent(toSend);
                intent.putExtra("test", new SerializableTest());
                if (sendIntentByType(intent, currentType)) {
                    Toast.makeText(FuzzerActivity.this, "Sent Serializeable " + intent, Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(FuzzerActivity.this, "Send " + intent + " Failed!", Toast.LENGTH_LONG).show();
                }
                return true;
            }
        
       });
        fuzzAllNullBtn.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                for(ComponentName cmpName : components){
                    Intent intent = new Intent();
                    intent.setComponent(cmpName);
                    if (sendIntentByType(intent, currentType)) {
                        Toast.makeText(FuzzerActivity.this, "Sent Null " + intent, Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(FuzzerActivity.this, R.string.send_faild, Toast.LENGTH_LONG).show();
                    }
                }
            }
            
        });
        fuzzAllSeBtn.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                for(ComponentName cmpName : components){
                    Intent intent = new Intent();
                    intent.setComponent(cmpName);
                    intent.putExtra("test", new SerializableTest());
                    if (sendIntentByType(intent, currentType)) {
                        Toast.makeText(FuzzerActivity.this, "Sent Serializeable " + intent, Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(FuzzerActivity.this, R.string.send_faild, Toast.LENGTH_LONG).show();
                    }
                }
            }
            
        });
    }

发送请求

    private boolean sendIntentByType(Intent intent, String type) {
        try {
                switch (ipcNamesToTypes.get(type)) {
                case Utils.ACTIVITIES:
                    startActivity(intent);
                    return true;
                case Utils.RECEIVERS:
                    sendBroadcast(intent);
                    return true;
                case Utils.SERVICES:
                    startService(intent); 
                    return true;
                default:
                    return true;
                }
        } catch (Exception e) {
            //e.printStackTrace();
            return false;
        }
        
    }
上一篇下一篇

猜你喜欢

热点阅读