使用 Web Risk 偵測惡意網址
事前準備
建立 Google Cloud 專案。瞭解如何建立 Google Cloud 專案。
Make sure that billing is enabled for your Google Cloud project.
設定驗證並啟用 Web Risk API
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Web Risk API:
gcloud services enable webrisk.googleapis.com
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Web Risk API:
gcloud services enable webrisk.googleapis.com
- 使用 LookUp API
- 基本更新 API 用戶端
- 使用差異更新 API 用戶端
- 使用 RICE 壓縮差異更新 API 用戶端
使用 API
使用 Web Risk API 時,請務必詳閱 Web Risk 的服務水準協議和使用限制。
如要開始使用 Web Risk,請參閱下列主題:
哪種 API 適合我?要查詢還是更新?
Web Risk 提供兩種不同的 API,您可以整合這些 API。這些 API 包括 Lookup API 和 Update API。這兩個 API 都提供相同的資訊。也就是網址是否已遭判定為惡意。最容易使用的就是 Lookup API。使用 Lookup API 時,您會查詢要檢查的每個網址的 Web Risk。
Update API 較為複雜,但有一些優點。使用 Update API 維護本機資料庫。這個資料庫可用於檢查網址是否含有惡意內容。這個資料庫會做為 Bloom 篩選器。也就是說,系統可能會誤判網址為惡意網址,但不會誤判惡意網址為非惡意網址。因此,系統很少會與 Web Risk 伺服器連線,只有在確認相符項目和消除誤報時才會連線。在大多數情況下,使用 Update API 檢查網址時,完全不需要與 Web Risk 伺服器聯絡。您應該只在更新本機資料庫和確認網址有害時,才與 Web Risk 伺服器聯絡。
總而言之,如果您想快速輕鬆地完成設定,請使用 Lookup API。 如需縮短網址檢查的延遲時間,請使用 Update API。
選擇合適的用戶端功能
如果您選擇使用 Update API,可能不需要實作整個規格。有些功能是專為廣泛發布的用戶端 (例如網頁瀏覽器) 設計,但在許多企業案例中,這些功能過度最佳化。
為方便整合,系統可能會忽略部分功能。
以下是 Web Risk 整合解決方案,依複雜度排序
使用 Lookup API
使用 Lookup API 的複雜度最低。只要有可疑網址,只要使用該網址呼叫 Lookup API,即可查看判定結果。網址的標準化和格式設定作業由 Web Risk 伺服器處理。除非平均延遲時間超出需求,否則這個解決方案應適用於大多數用戶端。
基本更新 API 用戶端
Update API 需要額外複雜的作業,才能在查詢前管理本機資料庫和正規化網址。
在與 Web Risk 整合的典型用戶端中,用戶端會套用資料庫差異,以確保資料保持最新狀態。正確實作差異應用程式邏輯可能需要一些時間,因此在最簡單的情況下,建議用戶端忽略差異,並在每個週期向 Web Risk 要求完整的新資料庫。這個資料庫仍會儲存在記憶體中,以利查詢。如要要求完整重設資料庫,請在 threatLists.computeDiff
要求中將 versionToken
欄位留空。除非頻寬或資料庫同步延遲超出需求,否則這項解決方案應適用於用戶端。
使用 Update API 並要求差異更新
這項解決方案的複雜度較高,因為必須將差異邏輯套用至本機資料庫。詳情請參閱「資料庫差異」。與每個週期都要求新資料庫相比,使用差異會減少頻寬,但會增加複雜度。完整更新資料庫可能需要幾 MB 的資料。這個解決方案應足以滿足大多數企業客戶的需求。
使用 Update API 並要求 RICE 編碼的差異更新
這是最有效率的用戶端整合方式。RICE 編碼可壓縮 DIFF 大小,進一步減少更新頻寬。這項解決方案適用於頻寬最受限的客戶。舉例來說,如果手機應用程式內建 Web Risk 查詢功能,使用者透過手機資料更新資料庫時,一定會很感謝有頻寬較低的解決方案。詳情請參閱「壓縮」。