HashR 允许你基于自己的数据源构建哈希集合。它是一款从输入源(例如原始磁盘镜像、GCE 磁盘镜像、ISO 文件、Windows 更新包、.tar.gz 文件等)中提取文件和哈希的工具。
HashR 由以下组件组成:
当前已实现的导入器:
文件被提取并计算哈希后,结果将传递给导出器。当前已实现的导出器:
你可以选择要运行的导入器,每个导入器有不同的要求。更多相关信息请参阅以下章节。
HashR 需要 Linux 操作系统才能运行,可以是物理机、虚拟机或云主机。以下是推荐的硬件配置要求:
HashR 或许可以在配置较低的机器上运行,但未经全面测试。
要构建 hashr 二进制文件,请运行以下命令:``` shell env GOOS=linux GOARCH=amd64 go build hashr.go
要运行核心 hashR 包的测试,你需要运行 Spanner 模拟器:``` shell
gcloud emulators spanner start
然后,要执行所有测试,请运行以下命令:``` shell go test -timeout 2m ./...
## 设置 HashR
### OSDFIR 基础设施中的 HashR
您可以将 HashR 部署为 [OSDFIR 基础设施项目](https://github.com/google/osdfir-infrastructure/tree/main/charts/hashr)。
此部署将以 kubernetes cronjobs 方式运行 HashR,并可轻松
与 Timesketch 集成。
### 使用 docker 运行 HashR
要在 docker 容器中运行 HashR,请参阅 [docker 专属指南](https://github.com/google/hashr/blob/HEAD/docker/README.md)
### 操作系统配置及所需的第三方工具
HashR 通过使用 Plaso 来处理繁重的工作(解析磁盘镜像、卷、文件系统)。您需要使用以下命令拉取 Plaso docker 容器:``` shell
docker pull log2timeline/plaso
我们还需要在运行 HashR 的机器上安装 7z,WSUS 导入器使用它来递归提取 Windows Update 包:``` shell sudo apt install p7zip-full
你需要允许运行 HashR 的用户通过 sudo 执行某些命令。假设你的用户是 `hashr`,请创建文件 `/etc/sudoers.d/hashr` 并写入:``` shell
hashr ALL = (root) NOPASSWD: /bin/mount,/bin/umount,/sbin/losetup,/bin/rm
运行 HashR 的用户还需要能够运行 docker。假设你的用户是 hashr,请将其添加到 docker 组,如下所示:``` shell
sudo usermod -aG docker hashr
### 为处理任务设置存储
HashR 需要存储有关已处理来源的信息。它还会存储有关处理任务的额外遥测数据:处理时间、提取的文件数等。你可以选择使用:
1. PostgreSQL
1. 云 (GCP) Spanner
#### 设置 PostgreSQL 存储
运行和维护 PostgreSQL 实例的方法有很多,最简单的方法之一是在 Docker 容器中运行它。按照以下步骤设置 PostgreSQL Docker 容器。
步骤 1:拉取 PostgreSQL Docker 镜像。``` shell
docker pull postgres
步骤 2:在后台初始化并运行 PostgreSQL 容器。确保调整密码。``` shell docker run -itd -e POSTGRES_DB=hashr -e POSTGRES_USER=hashr -e POSTGRES_PASSWORD=hashr -p 5432:5432 -v /data:/var/lib/postgresql/data --name hashr_postgresql postgres
步骤 3:创建一个用于存储处理作业的表。``` shell
cat scripts/CreateJobsTable.sql | docker exec -i hashr_postgresql psql -U hashr -d hashr
为了使用 PostgreSQL 存储处理任务的信息,你需要指定以下标志:-storage postgres -postgres_host <host> -postgres_port <port> -postgres_user <user> -postgres_password <pass> -postgres_db <db_name>
你可以选择将处理作业的数据存储在 Cloud Spanner 中。为此,你需要一个 Google Cloud 项目。这种设置的主要优势是,你可以使用 Google Data Studio 轻松创建仪表盘,并直接连接到 Cloud Spanner 实例,以便监控和调试,而无需针对 PostgreSQL 实例运行查询。
假设你的 gcloud 工具已针对目标 hashr GCP 项目完成配置,你需要按照以下步骤启用 Cloud Spanner。
创建 HashR 服务账号:``` shell gcloud iam service-accounts create hashr --description="HashR SA key." --display-name="hashr"
创建服务账号密钥并将其存储在你的主目录中。将 *<project_name>* 设置为你的项目名称。``` shell
gcloud iam service-accounts keys create ~/hashr-sa-private-key.json --iam-account=hashr-sa@<project_name>.iam.gserviceaccount.com
将 GOOGLE_APPLICATION_CREDENTIALS 环境变量指向您的服务账号密钥:``` shell export GOOGLE_APPLICATION_CREDENTIALS=/home/hashr/hashr-sa-private-key.json
创建 Spanner 实例,如有需要,请调整 config 和 processing-units 的值:``` shell
gcloud spanner instances create hashr --config=regional-us-central1 --description="hashr" --processing-units=100
创建 Spanner 数据库:``` shell gcloud spanner databases create hashr --instance=hashr
允许服务账号使用 Spanner 数据库,将 *<project_name>* 设置为你的项目名称:``` shell
gcloud spanner databases add-iam-policy-binding hashr --instance hashr --member="serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com" --role="roles/spanner.databaseUser"
更新 Spanner 数据库架构:``` shell gcloud spanner databases ddl update hashr --instance=hashr --ddl-file=scripts/CreateJobsTable.ddl
为了使用 Cloud Spanner 存储有关处理任务的信息,你需要指定以下标志:`-jobStorage cloudspanner -spannerDBPath <spanner_db_path>`
### 设置导入器
要指定要运行的导入器,应使用 `-importers` 标志。可选值:`GCP,targz,windows,wsus,deb,rpm,zip,gcr,iso9660`
#### GCP (Google Cloud Platform)```shell
-importers GCP
此导入器可从 GCP 磁盘映像中提取文件。具体步骤如下:
包含公共 GCP 映像的 GCP 项目列表可在此处找到。要使用此导入器,您需要拥有一个 GCP 项目并执行以下步骤:
步骤 1:创建 HashR 服务账号,如果在设置 Cloud Spanner 时已完成此操作,请跳至步骤 4。``` shell gcloud iam service-accounts create hashr-sa --description="HashR SA key." --display-name="hashr"
步骤 2: 创建服务账号密钥并将其存储在你的主目录中。请务必将 *<project_name>* 设置为你的项目名称:``` shell
gcloud iam service-accounts keys create ~/hashr-sa-private-key.json --iam-account=hashr-sa@<project_name>.iam.gserviceaccount.com
步骤 3:将 GOOGLE_APPLICATION_CREDENTIALS 环境变量指向您的服务账号密钥:``` shell export GOOGLE_APPLICATION_CREDENTIALS=~/hashr-sa-private-key.json
Step 4: 创建用于以 .tar.gz 格式存储磁盘镜像的 GCS bucket,将 *<project_name>* 设置为你的项目名称,将 *<gcs_bucket_name>* 设置为你的项目新 GCS bucket 名称:``` shell
gcloud storage buckets create gs://<gcs_bucket_name> --project=<project_name>
步骤 5:将此服务账号设为此存储桶的管理员:``` shell gcloud storage buckets add-iam-policy-binding gs://<gcs_bucket_name> --member="serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com" --role="roles/storage.objectAdmin"
步骤 6:启用 Compute API:``` shell
gcloud services enable compute.googleapis.com cloudbuild.googleapis.com
步骤 7:创建 IAM 角色并为其分配所需权限:``` shell gcloud iam roles create hashr --project=<project_name> --title=hashr --description="Permissions required to run hashR" --permissions compute.images.create,compute.images.delete,compute.globalOperations.get
步骤 8:将 IAM 角色绑定到服务账号:``` shell
gcloud projects add-iam-policy-binding <project_name> --member="serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com" --role="projects/<project_name>/roles/hashr"
步骤 9a: 启用 cloudbuild API``` shell gcloud services enable cloudbuild.googleapis.com --project <project_name>
步骤 9b:获取你的 project_number```shell
gcloud projects list --filter="mlegin-testing-things" --format="value(PROJECT_NUMBER)"
步骤 9c:为服务账号授予运行 Cloud Build 所需的访问权限,确保更改 <project_name> 和 <project_number> 的值:``` shell gcloud projects add-iam-policy-binding <project_name> --member='serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com' --role='roles/storage.admin'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com'
--role='roles/viewer'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com'
--role='roles/resourcemanager.projectIamAdmin'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com'
--role='roles/cloudbuild.builds.editor'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>@cloudbuild.gserviceaccount.com'
--role='roles/compute.admin'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>@cloudbuild.gserviceaccount.com'
--role='roles/iam.serviceAccountUser'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>@cloudbuild.gserviceaccount.com'
--role='roles/iam.serviceAccountTokenCreator'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>@cloudbuild.gserviceaccount.com'
--role='roles/compute.networkUser'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>[email protected]'
--role='roles/compute.storageAdmin'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>[email protected]'
--role='roles/storage.objectViewer'
gcloud projects add-iam-policy-binding <project_name>
--member='serviceAccount:<project_number>[email protected]'
--role='roles/storage.objectAdmin'
要使用此导入器,您需要指定以下标志:
1. `-gcp_projects`:一个逗号分隔的云项目列表,其中包含磁盘映像。如果您想导入公共映像,请查看[此处](https://cloud.google.com/compute/docs/images/os-details#general-info)
1. `-hashr_gcp_project`:用于存储磁盘映像副本以进行处理并运行 Cloud Build 的 GCP 项目
1. `-hashr_gcs_bucket`:用于存储 Cloud Build 输出(`.tar.gz` 格式的磁盘映像)的 GCS 存储桶
#### AWS
此导入器处理 Amazon 拥有的 AMI 并生成哈希。导入器至少需要一个 HashR 工作器(一个 EC2 实例)。
##### AWS HashR 工作器
AWS HashR 工作器是一个 EC2 实例,AMI 的卷会附加到该实例,创建磁盘归档,然后上传到 S3 存储桶。建议至少有两个 AWS HashR 工作器。如果您的设置使用单个 AWS 工作器,请使用 `-processing_worker_count 1`。
AWS HashR 工作器需要满足以下要求:
- EC2 实例必须具有标签 `InUse: false`。如果该值为 `true`,则不会使用该工作器进行处理。```shell
aws ec2 describe-instances --instance-id INSTANCE_ID | jq -r ‘.Reservations[].Instances[0].Tags’
运行 hashr 的系统必须能够使用以下方式 SSH 连接到 EC2 实例:
Keyname 中所述的 SSH 密钥。 ```shell
aws ec2 describe-instances --instance-id INSTANCE_ID | jq -r ‘.Reservations[].Instances[0].Keyname’解析为 PublicDnsName 中所述的 FQDN。 ```shell
aws ec2 describe-instances --instance-id INSTANCE_ID | jq -r ‘.Reservations[].Instances[0].PublicDnsName’
scripts/hashr-archive 必须复制到 AWS HashR worker 的 /usr/local/sbin/hashr-archive
具有上传文件到 HashR bucket 权限的 AWS 账户。AWS 配置和凭证应存储在 $HOME/.aws/ 目录中。```shell
aws configure
##### HashR 应用
在运行 `hashr` 的系统上,需要满足以下要求。
- 一个 AWS 账户,并具有调用以下 API 的权限:
- EC2
- AttachVolume
- CopyImage
- CreateTags
- CreateVolume
- DeleteVolume
- DescribeAvailabilityZones
- DescribeImages
- DescribeInstances
- DescribeSnapshots
- DescribeVolumes
- DetachVolume
- S3
- DeleteObject
- AWS 账户配置和凭证文件必须位于 `$HOME/.aws/` 目录中。
- 用于 AWS HashR 的 SSH 私钥必须位于 `$HOME/.ssh/` 目录中。它必须与 `Keyname` 的值匹配,如 `aws ec2 describe-instances --instance-id INSTANCE_ID | jq -r ‘.Reservations[].Instances[0].Keyname’` 所述。
##### 设置 AWS EC2 实例
本节介绍如何创建要用于 HashR 的 EC2 实例。理想情况下,我们需要两个 AWS 账户:`hashr.uploader` 和 `hashr.worker`。
`hashr.uploader` 用于 EC2 实例,需要具有将归档磁盘映像上传到 S3 存储桶的权限。`scripts/aws/AwsHashrUploaderPolicy.json` 包含针对 S3 存储桶 `hashr-bucket` 的示例策略。
`hashr.worker` 用于运行 HashR 命令的计算机。该账户需要 EC2 和 S3 权限。`scripts/aws/AwsHashrWorkerPolicy.json` 包含针对 `hashr.worker` 账户的示例策略。
`hashr_setup.sh` 是一个用于帮助创建 EC2 实例的脚本。编辑 `hashr_setup.sh`,并根据需要审查和更新以下字段:
- `AWS_PROFILE`
- `AWS_REGION`
- `SECURITY_SOURCE_CIDR`
- `WORKER_AWS_CONFIG_FILE`
**注意**:`WORKER_AWS_CONFIG_FILE` 指定的文件必须与 `hashr_setup.sh` 位于同一目录中。
**注意**:必须从 `hashr_setup.sh` 所在的目录执行 `hashr_setup.sh`。
运行以下命令来创建和设置 EC2 实例。```shell
$ git clone https://github.com/google/hashr
$ cd hashr/scripts/aws
$ aws configure
$ cp -r ~/.aws ./
$ tar -zcf hashr.uploader.tar.gz .aws
$ hash_setup.sh setup
AWS 导入器按以下高层步骤执行:
以下命令处理 debian-12 镜像并将其存储在 PostgreSQL 数据库中。```shell
hashr -storage postgres -exporters postgres -importers aws -aws_bucket aws-hashr-bucket -aws_os_filter debian-12
**注意**:在开发导入器时,使用的是 Amazon Linux (al2023-*) 作为工作节点。因此,`-aws_ssh_user` 的默认值设置为 `ec2-user`。如果使用其他发行版,默认 SSH 用户可能会不同,请使用 `-aws_ssh_user` 设置合适的 SSH 用户。
#### GCR(Google 容器注册中心)
此导入器从 GCR 仓库中存储的容器镜像中提取文件。要对其进行设置,请按照以下步骤操作:
步骤 1:创建 HashR 服务账号,如果在设置其他依赖 GCP 的组件时已完成此操作,请跳到步骤 4。``` shell
gcloud iam service-accounts create hashr-sa --description="HashR SA key." --display-name="hashr"
步骤 2:创建服务账号密钥并将其存储在你的主目录中。确保将 <project_name> 设置为你的项目名称:``` shell gcloud iam service-accounts keys create ~/hashr-sa-private-key.json --iam-account=hashr-sa@<project_name>.iam.gserviceaccount.com
步骤 3:将 GOOGLE_APPLICATION_CREDENTIALS 环境变量指向您的服务账号密钥:``` shell
export GOOGLE_APPLICATION_CREDENTIALS=~/hashr-sa-private-key.json
步骤 4:授予 hashR 服务账号密钥访问指定 GCR 仓库所需的权限。``` shell gcloud storage buckets add-iam-policy-binding gs://artifacts.<project_name_hosting_gcr_repo>.appspot.com --member="serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com" --role="roles/storage.objectViewer"
要使用此导入器,您需要指定以下标志:
1. `-gcr_repos`,它应包含以逗号分隔的 GCR 仓库列表,您希望从中导入容器镜像。
#### Windows
此导入器会从 ISO-13346 格式的官方 Windows 安装介质中提取文件,例如您可以从微软官方[网站](https://www.microsoft.com/en-gb/software-download/windows10ISO)下载的那些介质。
一个 ISO 文件可能包含多个 WIM 映像:
1. Windows10ProEducation
1. Windows10Education
1. Windows10EducationN
1. Windows10ProN
1. 等等。
此导入器将从 `install.wim` 文件中找到的所有映像中提取文件。
#### WSUS
此导入器使用 7z 递归提取 Windows Update 包的内容。它会在提供的 GCS 存储桶中查找 Windows Update 文件,要自动用新更新更新 GCS 存储桶,最简单的方法是执行以下操作:
1. 在 hashr GCP 项目中设置一台运行 Windows Server 的 GCE 虚拟机。
1. 为其配置 WSUS 角色,选择您想要处理的 Windows Update 包。
1. 配置 WSUS 以自动批准并将更新下载到本地存储。
1. 设置一个 Windows 任务,自动将本地存储的内容同步到 GCS 存储桶:`gcloud storage rsync --recursive D:/WSUS/WsusContent gs://hashr-wsus/`(记得调整路径)。
1. 如果您希望将更新包的文件名(通常包含 KB 编号)作为 ID(默认是 sha1,这就是 MS 存储 WSUS 更新的方式),并希望包含其描述,则可以从内部 WID WSUS 数据库中导出这些信息。您可以使用以下 Power Shell 脚本,并将其作为任务运行:```
#SQL Query
$delimiter = ";"
$SqlQuery = 'select DISTINCT CONVERT([varchar](https://github.com/google/hashr/blob/HEAD/512), tbfile.FileDigest, 2) as sha1, tbfile.[FileName], vu.[KnowledgebaseArticle], vu.[DefaultTitle] from [SUSDB].[dbo].[tbFile] tbfile
left join [SUSDB].[dbo].[tbFileForRevision] ffrev
on tbfile.FileDigest = ffrev.FileDigest
left join [SUSDB].[dbo].[tbRevision] rev
on ffrev.RevisionID = rev.RevisionID
left join [SUSDB].[dbo].[tbUpdate] u
on rev.LocalUpdateID = u.LocalUpdateID
left join [SUSDB].[PUBLIC_VIEWS].[vUpdate] vu
on u.UpdateID = vu.UpdateId'
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = 'server=\\.\pipe\MICROSOFT##WID\tsql\query;database=SUSDB;trusted_connection=true;'
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $SqlQuery
$SqlCmd.Connection = $SqlConnection
$SqlCmd.CommandTimeout = 0
$SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
$SqlAdapter.SelectCommand = $SqlCmd
#Creating Dataset
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
$DataSet.Tables[0] | export-csv -Delimiter $delimiter -Path "D:\WSUS\WsusContent\export.csv" -NoTypeInformation
gcloud storage rsync --recursive D:/WSUS/WsusContent gs://hashr-wsus/
This will dump the relevant information from WSUS DB, store it in the export.csv file and sync the contents of the WSUS folder with GCS bucket. WSUS importer will check if export.csv file is present in the root of the WSUS repo, if so it will use it.
这将从 WSUS 数据库中转储相关信息,将其存储在 export.csv 文件中,并将 WSUS 文件夹的内容与 GCS 存储桶同步。WSUS 导入器将检查 export.csv 文件是否存在于 WSUS 仓库的根目录中,如果是,它将使用它。
This is a simple importer that traverses repositories and looks for .tar.gz files. Once found it will hash the first and the last 10MB of the file to check if it was already processed. This is done to prevent hashing the whole file every time the repository is scanned for new sources. To use this importer you need to specify the following flag(s):
这是一个简单的导入器,它遍历仓库并查找 .tar.gz 文件。找到后,它会对文件的前 10MB 和最后 10MB 进行哈希,以检查是否已处理过。这样做是为了避免每次扫描仓库以查找新源时都对整个文件进行哈希计算。要使用此导入器,您需要指定以下标志:
-targz_repo_path which should point to the path on the local file system that contains .tar.gz files
-targz_repo_path,它应指向本地文件系统上包含 .tar.gz 文件的路径。
This is very similar to the TarGz importer except that it looks for .deb packages. Once found it will hash the first and the last 10MB of the file to check if it was already processed. This is done to prevent hashing the whole file every time the repository is scanned for new sources. To use this importer you need to specify the following flag(s):
这与 TarGz 导入器非常相似,只是它查找 .deb 包。找到后,它会对文件的前 10MB 和最后 10MB 进行哈希,以检查是否已处理过。这样做是为了避免每次扫描仓库以查找新源时都对整个文件进行哈希计算。要使用此导入器,您需要指定以下标志:
-deb_repo_path which should point to the path on the local file system that contains .deb files
-deb_repo_path,它应指向本地文件系统上包含 .deb 文件的路径。
This is very similar to the TarGz importer except that it looks for .rpm packages. Once found it will hash the first and the last 10MB of the file to check if it was already processed. This is done to prevent hashing the whole file every time the repository is scanned for new sources. To use this importer you need to specify the following flag(s):
这与 TarGz 导入器非常相似,只是它查找 .rpm 包。找到后,它会对文件的前 10MB 和最后 10MB 进行哈希,以检查是否已处理过。这样做是为了避免每次扫描仓库以查找新源时都对整个文件进行哈希计算。要使用此导入器,您需要指定以下标志:
-rpm_repo_path which should point to the path on the local file system that contains .rpm files
-rpm_repo_path,它应指向本地文件系统上包含 .rpm 文件的路径。
This is very similar to the TarGz importer except that it looks for .zip archives. Once found it will hash the first and the last 10MB of the file to check if it was already processed. This is done to prevent hashing the whole file every time the repository is scanned for new sources. To use this importer you need to specify the following flag(s):
这与 TarGz 导入器非常相似,只是它查找 .zip 归档文件。找到后,它会对文件的前 10MB 和最后 10MB 进行哈希,以检查是否已处理过。这样做是为了避免每次扫描仓库以查找新源时都对整个文件进行哈希计算。要使用此导入器,您需要指定以下标志:
-zip_repo_path which should point to the path on the local file system that contains .zip files
-zip_repo_path,它应指向本地文件系统上包含 .zip 文件的路径。
Optionally, you can also set the following flag(s):
可选地,您还可以设置以下标志:
-zip_file_exts comma-separated list of file extensions to treat as zip files, eg. "zip,whl,jar". Default: "zip"
-zip_file_exts 逗号分隔的文件扩展名列表,用于将文件按 zip 文件处理,例如 "zip,whl,jar"。默认值:"zip"
This is very similar to the TarGz importer except that it looks for .iso file. Once found it will hash the first and the last 10MB of the file to check if it was already processed. This is done to prevent hashing the whole file every time the repository is scanned for new sources. To use this importer you need to specify the following flag(s):
这与 TarGz 导入器非常相似,只是它查找 .iso 文件。找到后,它会对文件的前 10MB 和最后 10MB 进行哈希,以检查是否已处理过。这样做是为了避免每次扫描仓库以查找新源时都对整个文件进行哈希计算。要使用此导入器,您需要指定以下标志:
-iso_repo_path which should point to the path on the local file system that contains .iso files
-iso_repo_path,它应指向本地文件系统上包含 .iso 文件的路径。
Postgres exporter allows sending of hashes, file metadata and the actual content of the file to a PostgreSQL instance. For best performance it's advised to set it up on a separate and dedicated machine. If you did set up PostgreSQL while choosing the processing jobs storage you're almost good to go, just run the following command to create the required tables:
Postgres 导出器允许将哈希、文件元数据以及文件的实际内容发送到 PostgreSQL 实例。为了获得最佳性能,建议将其设置在单独的专用机器上。 如果您在选择处理作业存储时已设置 PostgreSQL,那么您几乎可以直接使用了,只需运行以下命令来创建所需的表:``` shell cat scripts/CreatePostgresExporterTables.sql | docker exec -i hashr_postgresql psql -U hashr -d hashr
如果你没有选择 Postgres 作为处理作业存储,请按照 [设置 PostgreSQL 存储](####setting-up-postgresql-storage) 部分中的步骤 1 和 2 操作。
目前这是默认导出器,你无需显式启用它。默认情况下,实际文件的内容不会上传到 PostgreSQL 数据库,如果你希望更改这一点,请使用 `-upload_payloads true` 标志。
为了让 Postgres 导出器正常工作,你需要设置以下标志:`-exporters postgres -postgresHost <host> -postgresPort <port> -postgresUser <user> -postgresPassword <pass> -postgresDBName <db_name>`
#### 设置 GCP 导出器
GCP 导出器允许将哈希、文件元数据发送到 GCP Spanner 实例。你也可以选择将提取的文件上传到 GCS 存储桶。如果你尚未设置 Cloud Spanner 来存储处理作业,请按照 [设置 Cloud Spanner](####setting-up-cloud-spanner) 中的步骤操作,而不是最后一步,运行以下命令来创建必要的表:``` shell
gcloud spanner databases ddl update hashr --instance=hashr --ddl-file=scripts/CreateCloudSpannerExporterTables.ddl
如果您已经设置了用于存储任务数据的 Cloud Spanner,只需运行上述命令即可准备就绪。
如果您想将提取的文件上传到 GCS,则需要创建 GCS 存储桶:
步骤 1:将此服务账号设为此存储桶的管理员:``` shell gcloud storage buckets create gs://<gcs_bucket_name> --project=project_name>
第 2 步:将此存储桶的服务账户设为管理员:``` shell
gcloud storage buckets add-iam-policy-binding gs://<gcs_bucket_name> --member="serviceAccount:hashr-sa@<project_name>.iam.gserviceaccount.com" --role="roles/storage.objectAdmin"
要使用此导出器,您需要提供以下标志:-exporters GCP -gcp_exporter_gcs_bucket <gcs_bucket_name>
-processing_worker_count:此标志控制并行处理工作线程的数量。处理过程会占用大量 CPU 和 I/O,在我的测试中,我发现使用 2 个工作线程是最优解决方案。-cache_dir:用于去重的本地缓存位置,建议将其从 /tmp 改为将要运行 hashr 的用户的 home 目录(例如)。-export:当设置为 false 时,hashr 会将结果保存到磁盘,绕过导出器。-export_path:如果 export 设置为 false,这是样本将被保存的文件夹。-reprocess:允许基于 jobs 表中存储的 sha256 值重新处理给定的源(例如在出错的情况下)。-upload_payloads:控制定义好的导出器是否会上传文件的实际内容。-gcp_exporter_worker_count:GCP 导出器将用于上传数据的工作线程/goroutine 数量。这不是 Google 官方支持的产品。