LoginSignup
0

More than 1 year has passed since last update.

リンクにマルウェアまたはフィッシングが仕込まれたか検出する方法

Posted at

利用ライブラリ

Safety Detect

対応端末

すべてのAndroid端末

対応OS

  • Android 4.4

実装手順

前準備

(1) Huaweu Developerを登録します。

(2) AppGallery Connectでアプリのプロジェクトを登録します。
スクリーンショット 2020-10-01 155726.png
スクリーンショット 2020-10-01 155747.png
スクリーンショット 2020-10-01 155822.png
スクリーンショット 2020-10-01 155911.png
スクリーンショット 2020-10-01 155946.png

(3) keytoolで生成したSHA256をAppGallery Connectのアプリプロジェクトに登録します。
スクリーンショット 2020-10-01 160111.png

(4) agconnect-services.jsonをダウンロードし、appフォルダに配置します。
スクリーンショット 2020-10-01 161111.png
スクリーンショット 2020-10-01 162011.png

(5) Safety Detectを有効にします。
スクリーンショット 2020-10-01 160111.png

HMS SDKを導入

(1) プロジェクトのbuild.gradleを開き、mavenとclasspathを追加します。
スクリーンショット 2020-10-01 162820.png

build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()

        // こちらの行を追加
        maven {url 'http://developer.huawei.com/repo/'}
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.0.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files

        // こちらの行を追加
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
    }
}

allprojects {
    repositories {
        google()
        jcenter()

        // こちらの行を追加
        maven { url 'http://developer.huawei.com/repo/' }
    }
}

(2) モジュールのbuild.gradleを開き、次のようにを追加します。
スクリーンショット 2020-10-01 162842.png

build.gradle
plugins {
    id 'com.android.application'
    id 'kotlin-android'

    // こちらの行を追加
    id 'com.huawei.agconnect'
}

android {
    // signingConfigsを追加
    signingConfigs {
        debug {
            storePassword 'My password'
            keyAlias 'My keyAlias'
            keyPassword 'My password'
            storeFile file('My keystore file.jks')
            v1SigningEnabled true
            v2SigningEnabled true
        }
        release {
            storePassword 'My password'
            keyAlias 'My keyAlias'
            keyPassword 'My password'
            storeFile file('My keystore file.jks')
            v1SigningEnabled true
            v2SigningEnabled true
        }
    }

    buildTypes {
        release {
            // signingConfigを追加
            signingConfig signingConfigs.release

            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }

        debug {
            // signingConfigを追加
            signingConfig signingConfigs.debug

            debuggable true
        }
    }

    buildFeatures {
        dataBinding true
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.6.0'
    implementation 'androidx.appcompat:appcompat:1.3.1'
    implementation 'com.google.android.material:material:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // こちらの1行を追加
    implementation 'com.huawei.hms:safetydetect:6.3.0.301'
}

(3) proguard-rules.proを開き、次のようにを追加します。
スクリーンショット 2020-10-01 162901.png

proguard-rules.pro
-ignorewarnings
-keepattributes *Annotation*
-keepattributes Exceptions
-keepattributes InnerClasses
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-keep class com.huawei.hianalytics.**{*;}
-keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;}

ライブラリの使用

SafetyDetect.getClient(activity)
.initUrlCheck()
.urlCheck(
    {Your url},
    AGConnectServicesConfig.fromContext(requireContext()).getString("client/app_id"),
    UrlCheckThreat.MALWARE,
    UrlCheckThreat.PHISHING
).addOnSuccessListener { urlCheckResponse ->
    if (urlCheckResponse.urlCheckResponse.isEmpty()) {
        // 問題なし
    } else {
        urlCheckResponse.urlCheckResponse.forEach { urlCheckThreat ->
            when (urlCheckThreat.urlCheckResult) {
                UrlCheckThreat.MALWARE -> {
                    // マルウェア
                }
                UrlCheckThreat.PHISHING -> {
                    // フィッシング
                }
            }
        }
    }
}.addOnFailureListener { exception ->
    exception?.printStackTrace()
}

GitHub

https://github.com/Rei2020GitHub/MyPublicProject/tree/master/SafetyDetectDemo

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0