运行示例 Web Risk 应用
了解如何从 GitHub 安装示例 Web Risk Go 应用,以及如何在 Go 环境中运行示例应用来检测恶意网址。
如需在 Google Cloud 控制台中直接遵循有关此任务的分步指导,请点击操作演示:
准备工作
- 登录您的 Google Cloud 账号。如果您是 Google Cloud新手, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Web Risk API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
Enable the Web Risk API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.- 创建新的 API 密钥以进行身份验证:
- 在 Google Cloud 控制台的导航菜单中,依次点击 API 和服务> 凭据。
- 在凭据 页面上,点击 创建凭据 然后选择 API 密钥。
- 在已创建的 API 密钥 对话框中,点击 复制密钥 以复制该密钥。关闭对话框,妥善保管您复制的密钥以便将来使用。
- 设置环境:
-
在 Google Cloud 控制台中,点击 激活 Cloud Shell
以打开终端窗口。
Cloud Shell 终端可能需要几秒钟才能完全加载。
- 导出您复制的 API 密钥。
export APIKEY=API_KEY
-
安装并运行示例 Web Risk 应用
示例 Web Risk 应用具有以下二进制文件,这些二进制文件可用于检测 网址是恶意网址还是安全网址:
wrserver服务器:此二进制文件会运行 Web Risk API 查找代理,让您可以检查网址。wrlookup命令行:此二进制文件会过滤掉通过 STDIN 传送的不安全网址。
本快速入门文档介绍了如何使用
wrserver 服务器和 wrlookup 命令行二进制文件检测网址是恶意网址还是安全网址。
使用 wrserver 服务器二进制文件检查网址
- 在 Cloud Shell 终端中,安装
wrserver:go install github.com/google/webrisk/cmd/wrserver@latest
- 使用您的 API 密钥运行
wrserver:wrserver -apikey=$APIKEY
如果您看到 Starting server at localhost:8080 (即将在 localhost:8080 启动服务器)消息,则表示
wrserver已在localhost:8080启动。 - 如需在 localhost(本地主机)上预览应用,请点击
网页预览 ,然后选择 在端口 8080 上预览。
Cloud Shell 会在新的浏览器窗口中打开其代理服务的预览网址(端口 8080)。 预览网址浏览器窗口会显示 404 page not found(404 未找到页面)消息。
- 在预览网址窗口中,检查以下网址。
如需检查网址,请将本地服务器的预览网址后面的查询字符串替换为您希望检查的网址,格式如下:
PREVIEW_URL/r?url=URL_TO_BE_CHECKED.如果网址不安全,系统会根据 Web Risk 的建议显示插页式警告页面。 如果网址安全,客户端会自动重定向到目标。
假冒的恶意软件网址:
http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/
安全网址:
http://www.google.com/ - 要停止服务器,请按
Control+C。
您已成功使用 wrserver 服务器二进制文件验证了网址。
使用 wrlookup 命令行二进制文件检查网址
- 在 Cloud Shell 终端中,安装
wrlookup命令行二进制文件:go install github.com/google/webrisk/cmd/wrlookup@latest
- 使用 API 密钥检查网址。
假冒的恶意软件网址:
echo "http://testsafebrowsing.appspot.com/apiv4/ANY_PLATFORM/MALWARE/URL/" | wrlookup -apikey=$APIKEY
以下输出是恶意软件网址的简略输出:
...... Unsafe URL: [MALWARE]
安全网址:
echo "http://www.google.com/" | wrlookup -apikey=$APIKEY
以下输出是安全网址的简略输出:
...... Safe URL: http://google.com
您已经使用 wrlookup 命令行二进制文件成功验证了网址。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
删除项目时,请注意以下事项:
- 删除项目会删除相应项目中的所有资源。
- 您无法重复使用已删除项目的自定义项目 ID。
如果您打算探索多个教程和快速入门,重复使用项目可以帮助您避免超出项目配额上限。
如需删除项目,请执行以下操作:
- 在 Google Cloud 控制台的导航菜单中,依次点击 IAM 和管理 > 设置。
- 确认项目名称是您要删除的项目名称。
如果不是,请从 项目选择器中选择要删除的项目。
- 点击关机 。
- 在对话框中输入项目 ID,然后点击关停 以删除项目。
后续步骤
- 详细了解 Web Risk。
- 详细了解 Web Risk GitHub 项目中的 Web Risk 应用。