HMS Core安全檢測服務如何幫助大學新生防範電信詐騙?

HMSCore發表於2022-07-14

一年一度的高考結束了,很多學生即將離開父母,一個人踏入大學生活,但由於人生閱歷較少,容易被不法分子盯上。

每年開學季也是大一新生遭受詐騙的高峰期,以下是一些常見的案例。有的騙子會讓新生下載註冊一些惡意金融應用這些應用可能包含有病毒、木馬等程式,也可能是仿冒某些知名軟體的應用,犯罪分子通過惡意應用便可盜取手機裡的銀行卡等個人敏感資料。還有詐騙人員以贈送小禮物或優惠券作為誘餌,引導學生掃碼填寫個人資訊,大一新生往往警覺性較低,不知不覺中就將電話、住址等資訊洩露出去,隨之而來的便是狂轟濫炸的垃圾電話和簡訊,若是掃描了含有釣魚網站連結的二維碼,可能會進一步造成隱私資料洩露。更有的犯罪分子打著助學金的名號,讓貧困學生登入釣魚網站填寫銀行卡密碼等,直接造成學生的財產損失。

面對層出不窮的騙術,App需要及時檢測出釣魚網站、惡意應用、風險網路環境等,通過應用內提示引起使用者的重視,保障使用者的資訊保安。那麼,有沒有什麼辦法能夠多維度增強應用安全能力呢?作為App的開發者,可以為應用整合華為HMS Core 安全檢測服務,快速構建應用安全能力,保護學生的個人資訊和財產安全,為大一新生步入高校之旅保駕護航。

HMS Core的安全檢測服務應用安全檢測能力可以幫助App開發者獲取所執行裝置上的惡意應用列表。對於攜帶病毒的應用,檢測率高達99%,同時還擁有基於行為檢測未知威脅的能力。App可根據檢測結果,決定是否限制使用者在App內支付等操作。

HMS Core的安全檢測服務惡意URL檢測能力可以判斷使用者訪問的URL是否為惡意網址,對於惡意網址,選擇提示或攔截使用者的訪問風險。

HMS Core的安全檢測服務惡意Wi-Fi檢測能力檢測嘗試連線的Wi-Fi及路由器特徵,分析當前嘗試訪問的網路情況,實時反饋Wi-Fi檢測結果,當應用獲取嘗試連線的Wi-Fi存在ARP攻擊、中間人攻擊、DNS劫持等攻擊時,可以阻斷操作或者進一步讓使用者認證確認,幫助防範來自惡意Wi-Fi的惡意行為攻擊。

HMS Core安全檢測服務還擁有系統完整性檢測、虛假使用者檢測能力,能夠幫助開發者快速提升應用安全性,整合過程簡單高效,下面是詳細的接入教程。

Demo演示

應用安全檢測

惡意URL檢測

惡意Wi-Fi檢測

開發步驟

1 開發準備

詳細準備步驟可參考華為開發者聯盟官網

2 應用安全檢測API

2.1 呼叫AppsCheck API

您可直接呼叫SafetyDetectClientgetMaliciousAppsList獲取惡意應用列表:

private void invokeGetMaliciousApps() {
        SafetyDetectClient appsCheckClient = SafetyDetect.getClient(MainActivity.this);
        Task task = appsCheckClient.getMaliciousAppsList();
        task.addOnSuccessListener(new OnSuccessListener<MaliciousAppsListResp>() {
            @Override
            public void onSuccess(MaliciousAppsListResp maliciousAppsListResp) {
                // Indicates that communication with the service was successful.
                // Use resp.getMaliciousApps() to get malicious apps data.
                List<MaliciousAppsData> appsDataList = maliciousAppsListResp.getMaliciousAppsList();
                // Indicates get malicious apps was successful.
                if(maliciousAppsListResp.getRtnCode() == CommonCode.OK) {
                    if (appsDataList.isEmpty()) {
                        // Indicates there are no known malicious apps.
                        Log.i(TAG, "There are no known potentially malicious apps installed.");
                    } else {
                        Log.i(TAG, "Potentially malicious apps are installed!");
                        for (MaliciousAppsData maliciousApp : appsDataList) {
                            Log.i(TAG, "Information about a malicious app:");
                            // Use getApkPackageName() to get APK name of malicious app.
                            Log.i(TAG, "APK: " + maliciousApp.getApkPackageName());
                            // Use getApkSha256() to get APK sha256 of malicious app.
                            Log.i(TAG, "SHA-256: " + maliciousApp.getApkSha256());
                            // Use getApkCategory() to get category of malicious app.
                            // Categories are defined in AppsCheckConstants
                            Log.i(TAG, "Category: " + maliciousApp.getApkCategory());
                        }
                    }
                }else{
                    Log.e(TAG,"getMaliciousAppsList failed: "+maliciousAppsListResp.getErrorReason());
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                // An error occurred while communicating with the service.
                if (e instanceof ApiException) {
                    // An error with the HMS API contains some
                    // additional details.
                    ApiException apiException = (ApiException) e;
                    // You can retrieve the status code using the apiException.getStatusCode() method.
                    Log.e(TAG, "Error: " +  SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": " + apiException.getStatusMessage());
                } else {
                    // A different, unknown type of error occurred.
                    Log.e(TAG, "ERROR: " + e.getMessage());
                }
            }
        });
    }

3 惡意URL檢測API

3.1 初始化URLCheck API

在使用URLCheck API前,必須呼叫initUrlCheck方法進行介面初始化,並且需要等待初始化完成後再進行接下來的介面呼叫,示例程式碼如下:

SafetyDetectClient client = SafetyDetect.getClient(getActivity());
client.initUrlCheck();

3.2 請求網址檢測

指定關注的威脅型別,您可以將關注的威脅型別作為網址檢測API的引數。其中,UrlCheckThreat類中的常量包含了當前支援的威脅型別:

public class UrlCheckThreat {
    //此型別URL被標記為包含潛在有害應用的頁面的URL(篡改首頁、網頁掛馬、惡意應用下載連結等)
    public static final int MALWARE = 1;
    // 這種型別的URL被標記為釣魚、欺詐網站
    public static final int PHISHING = 3;
}

發起網址檢測請求,待檢測的URL包含協議、主機、路徑,不包含查詢引數。呼叫API示例程式碼如下:

String url = "https://developer.huawei.com/consumer/cn/";
SafetyDetect.getClient(this).urlCheck(url, appId, UrlCheckThreat.MALWARE, UrlCheckThreat.PHISHING).addOnSuccessListener(this, new OnSuccessListener<UrlCheckResponse >(){
    @Override
    public void onSuccess(UrlCheckResponse urlResponse) {
        if (urlResponse.getUrlCheckResponse().isEmpty()) {
        // 無威脅
        } else {
        // 存在威脅!
        }
    }
}).addOnFailureListener(this, new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {
        // 與服務通訊發生錯誤.
        if (e instanceof ApiException) {
            // HMS發生錯誤的狀態碼及對應的錯誤詳情.
            ApiException apiException = (ApiException) e;
            Log.d(TAG, "Error: " + CommonStatusCodes.getStatusCodeString(apiException.getStatusCode()));
        // 注意:如果狀態碼是SafetyDetectStatusCode.CHECK_WITHOUT_INIT,
        // 這意味著您未呼叫initUrlCheck()或者呼叫未完成就發起了網址檢測請求,
        // 或者在初始化過程中發生了內部錯誤需要重新進行初始化,需要重新呼叫initUrlCheck()
        } else {
            // 發生未知型別的異常.
            Log.d(TAG, "Error: " + e.getMessage());
        }
    }
});

獲取網址檢測的響應,呼叫返回物件UrlCheckResponsegetUrlCheckResponse方法,返回List,包含檢測到的URL威脅型別。若該列表為空,則表示未檢測到威脅,否則,可呼叫UrlCheckThreat中的getUrlCheckResult取得具體的威脅程式碼。示例程式碼如下:

final EditText testRes = getActivity().findViewById(R.id.fg_call_urlResult);
List<UrlCheckThreat> list = urlCheckResponse.getUrlCheckResponse();
if (list.isEmpty()) {
        testRes.setText("ok");
    }
else{
        for (UrlCheckThreat threat : list) {
            int type = threat.getUrlCheckResult();
        }
    }

3.3 關閉網址檢測會話

如果您的應用不再使用或長時間不再呼叫網址檢測介面,請呼叫shutdownUrlCheck方法關閉網址檢測會話,釋放資源。

SafetyDetect.getClient(this).shutdownUrlCheck();

4 惡意Wi-Fi檢測API

4.1 呼叫WifiDetect API

private void invokeGetWifiDetectStatus() {
        Log.i(TAG, "Start to getWifiDetectStatus!");
        SafetyDetectClient wifidetectClient = SafetyDetect.getClient(MainActivity.this);
        Task task = wifidetectClient.getWifiDetectStatus();
        task.addOnSuccessListener(new OnSuccessListener<WifiDetectResponse>() {
            @Override
            public void onSuccess(WifiDetectResponse wifiDetectResponse) {
                int wifiDetectStatus = wifiDetectResponse.getWifiDetectStatus();
                Log.i(TAG, "\n-1 :獲取Wi-Fi狀態失敗\n" + "0 :未連線Wi-Fi\n" + "1 :當前連線的Wi-Fi安全\n" + "2 :當前連線的Wi-Fi不安全.");
                Log.i(TAG, "wifiDetectStatus is: " + wifiDetectStatus);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                if (e instanceof ApiException) {
                    ApiException apiException = (ApiException) e;
                    Log.e(TAG,
                        "Error: " + apiException.getStatusCode() + ":"
                            + SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": "
                            + apiException.getStatusMessage());
                } else {
                    Log.e(TAG, "ERROR! " + e.getMessage());
                }
            }
        });
    }
        Log.i(TAG, "Start to getWifiDetectStatus!");
        SafetyDetectClient wifidetectClient = SafetyDetect.getClient(MainActivity.this);
        Task task = wifidetectClient.getWifiDetectStatus();
        task.addOnSuccessListener(new OnSuccessListener<WifiDetectResponse>() {
            @Override
            public void onSuccess(WifiDetectResponse wifiDetectResponse) {
                int wifiDetectStatus = wifiDetectResponse.getWifiDetectStatus();
                Log.i(TAG, "\n-1 :獲取Wi-Fi狀態失敗\n" + "0 :未連線Wi-Fi\n" + "1 :當前連線的Wi-Fi安全\n" + "2 :當前連線的Wi-Fi不安全.");
                Log.i(TAG, "wifiDetectStatus is: " + wifiDetectStatus);
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(Exception e) {
                if (e instanceof ApiException) {
                    ApiException apiException = (ApiException) e;
                    Log.e(TAG,
                        "Error: " + apiException.getStatusCode() + ":"
                            + SafetyDetectStatusCodes.getStatusCodeString(apiException.getStatusCode()) + ": "
                            + apiException.getStatusMessage());
                } else {
                    Log.e(TAG, "ERROR! " + e.getMessage());
                }
            }
        });
    }

瞭解更多詳情>>

訪問華為開發者聯盟官網
獲取開發指導文件
華為移動服務開源倉庫地址:GitHubGitee

關注我們,第一時間瞭解 HMS Core 最新技術資訊~

相關文章