Cloudflare Zero Trust の DLP で HTTP リクエストの Forensic Copy をログ保管する

# Cloudflare Zero Trust の DLP とは
以前、こちらの記事にまとめた内容があるので、参照ください。

https://qiita.com/khayama/items/89891e5e2160c9e2eecd

# DLP Forensic Copy
2024年11月1日に、新しく DLP Forensic Copy が取得できるようになりました。

パターンマッチングによる部分的なロギングではなく、リクエスト丸ごとを対象にしてログとして記録できることで、何かあったときのセキュリティ上の調査に役立てられます。

https://developers.cloudflare.com/cloudflare-one/changelog/dlp/#2024-11-01

>**Send entire HTTP requests to a Logpush destination**
In addition to [logging the payload](https://developers.cloudflare.com/cloudflare-one/policies/data-loss-prevention/dlp-policies/logging-options/#log-the-payload-of-matched-rules) from HTTP requests that matched a DLP policy in Cloudflare Logs, Enterprise users can now configure a [Logpush job](https://developers.cloudflare.com/cloudflare-one/policies/data-loss-prevention/dlp-policies/logging-options/#send-http-requests-to-logpush-destination) to send the entire HTTP request that triggered a DLP match to a storage destination. This allows long-term storage of full requests for use in forensic investigation.

# HTTP POST テスト
[HTTPS Post - DLP Test](https://dlptest.com/https-post/) を使って、以下のようなセットアップでテストします。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/06cd20f5-4068-fbfc-6831-ed4857e860e0.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/b8ac5927-e975-2d12-bd71-48e8b0006f89.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/16181192-ff05-3a87-512f-c83794fa4e85.png)

## ログ
以下のようなログが出力されます。

```json:dlp_forensic_copies.json
{
  "AccountID": "xx",
  "Datetime": "2024-12-16T15:53:53Z",
  "ForensicCopyID": "f5d7a6aaa12f41dda029e6f903bb2ab7",
  "GatewayRequestID": "2471c6212f0000fd4aa64d5400000001",
  "Headers": {
    "content-type": "multipart/form-data; boundary=----WebKitFormBoundary7zFbehQbTITWJA9M"
  },
  "Payload": "LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5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Iml0ZW1fbWV0YVs2XSINCg0K44GK44Gv44KI44GG44GU44GW44GE44G+44GZ44CB44GT44KT44Gr44Gh44Gv44CB44GT44KT44Gw44KT44GvDQrjgojjgo3jgZfjgY/jgYrpoZjjgYTjgZfjgb7jgZnjgIINCi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeTd6RmJlaFFiVElUV0pBOU0NCkNvbnRlbnQtRGlzcG9zaXRpb246IGZvcm0tZGF0YTsgbmFtZT0iaXRlbV9rZXkiDQoNCg0KLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5N3pGYmVoUWJUSVRXSkE5TQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmcm1fXzY1M2Q1YjAzMjY0YjAiDQoNCg0KLS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5N3pGYmVoUWJUSVRXSkE5TQ0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJmcm1fc3RhdGUiDQoNCkl4d092L0taUThoelkxcmd0Mi9rUGQveWpJWlRSYnk1OVhidStoOW1tQkE9DQotLS0tLS1XZWJLaXRGb3JtQm91bmRhcnk3ekZiZWhRYlRJVFdKQTlNLS0NCg==",
  "Phase": "request",
  "TriggeredRuleID": "7a8e0617-0153-420b-b87c-f9a58f5474ad"
}
```

## Payload デコード
Payload を確認するには `base64` デコードする必要があります。

https://developers.cloudflare.com/logs/reference/log-fields/account/dlp_forensic_copies/

>**Payload**
Type: string
Captured request/response data, base64-encoded.

`base64 -D` でデコードすることで、POST した全ての文字列がログから確認できました。

```shell
% cat dlp_forensic_copies.json | jq -r .Payload | base64 -D
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="frm_action"

create
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="form_id"

2
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="frm_hide_fields_2"


------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="form_key"

ndqoj
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="item_meta[0]"


------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="frm_submit_entry_2"

2f1ec90bd4
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="_wp_http_referer"

/https-post/
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="item_meta[6]"

おはようございます、こんにちは、こんばんは
よろしくお願いします。
------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="item_key"


------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="frm__653d5b03264b0"


------WebKitFormBoundary7zFbehQbTITWJA9M
Content-Disposition: form-data; name="frm_state"

IxwOv/KZQ8hzY1rgt2/kPd/yjIZTRby59Xbu+h9mmBA=
------WebKitFormBoundary7zFbehQbTITWJA9M--
```

# PDF アップロードテスト
[HTTPS Post - DLP Test](https://dlptest.com/https-post/) を使って、以下のようなPDF アップロードをテストします。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/6930f20c-8edb-1042-d5fa-60bf384b1600.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/86e981a0-2d88-9c93-4384-929d94d31e7f.png)


## ログ
以下のようなログが出力されます。

```json:dlp_forensic_copies_2.json
{
  "AccountID": "xxx",
  "Datetime": "2024-12-16T16:11:10Z",
  "ForensicCopyID": "925a21f813be4b209d7ea18d26646229",
  "GatewayRequestID": "2471d5f76d0000fd4aa886e400000001",
  "Headers": {
    "content-type": "multipart/form-data; boundary=----WebKitFormBoundaryaQM7tBA1Sdw8Dejt"
  },
  "Payload": "LS0tLS0tV2ViS2l0Rm9ybUJvdW5kYXJ5YVFNN3RCQTFTZHc4RGVqdA0KQ29udGVudC1EaXNwb3NpdGlvbjogZm9ybS1kYXRhOyBuYW1lPSJhY3Rpb24i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MDAwIG4gCjAwMDAwMDc0MDAgMDAwMDAgbiAKMDAwMDAwMDEzNSAwMDAwMCBuIAowMDAwMDAwODM5IDAwMDAwIG4gCjAwMDAwMDA4OTQgMDAwMDAgbiAKMDAwMDAwMTAxMSAwMDAwMCBuIAowMDAwMDA2MzA4IDAwMDAwIG4gCjAwMDAwMDY1NDEgMDAwMDAgbiAKMDAwMDAwNjk5NSAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgMTIKL1Jvb3QgNyAwIFIKL0luZm8gMSAwIFI+PgpzdGFydHhyZWYKNzU0MgolJUVPRgoNCi0tLS0tLVdlYktpdEZvcm1Cb3VuZGFyeWFRTTd0QkExU2R3OERlanQtLQ0K",
  "Phase": "request",
  "TriggeredRuleID": "7a8e0617-0153-420b-b87c-f9a58f5474ad"
}
```

## Payload デコード
オンラインで Base64 から PDF に変換できるサイトはいくつかあります。

https://base64.guru/converter/decode/pdf

ローカルでデコードしたい場合は、以下のように `base64` から PDF ファイルに変換する Javascript を作成します。

https://stackoverflow.com/questions/56483097/decoding-base64-pdf-giving-broken-file

https://stackoverflow.com/questions/16349706/how-to-pipe-node-js-scripts-together-using-the-unix-pipe-on-the-command-line

```javascript:base64_to_pdf.js
#!/usr/bin/env node

var stdin = process.openStdin();

var data = "";

stdin.on('data', function(chunk) {
  data += chunk;
});

stdin.on('end', function() {
  console.log("DATA:\n" + data + "\nEND DATA");
  var bin = atob(data);
  const fs = require('fs');
  fs.writeFile('dlp_forensic_copies.pdf', bin, 'binary', error => {
    if (error) {
        throw error;
    } else {
        console.log('dlp_forensic_copies.pdf saved!');
    }
  });
});
```

その後、以下のコマンドでログの Payload から元の PDF ファイルに変換できます。

```shell:
cat dlp_forensic_copies_2.json | jq -r .Payload | ./base64_to_pdf.js
open dlp_forensic_copies.pdf  
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/101361/d7a53963-d7b5-8349-28c8-9b4c9e266232.png)

# まとめ

Cloudflare Zero Trust の DLP を使うことで、企業の中で従業員が使うデータのやり取りをログ保管できることを確認できました。

HTTP リクエストの属性データやマッチングによる部分的な把握だけでなく、使ったデータやファイルをそのままの形でログに残せるため、将来の調査や監査要件を満たすことができます。

すべての証跡を残したい要件では、このように Enterprise Plan の DLP Forensic Copy を活用できることがわかります。

ただし、こういった添付ファイルに相当するデータがすべて保管されていくことを考えると、通常のログに比べて大きな容量を確保する必要があるでしょう。