新しい脆弱性が検出された場合の Slack 通知の作成
WebSphere Automation Swagger UI、Slack ブロック・キット・ビルダー、および Mustache 構文を使用して、Slack メッセージを生成する通知を Web フックに送信するプロセスを作成します。 この通知には、 WebSphere Automation が検出した新しい脆弱性の詳細が含まれます。
開始前に
変数や条件処理を実装する場合は、 Mustache の構文 に慣れていることを確認してください。
WebSphere Automation リソース通知の調査
このチュートリアルの予期される結果は、 WebSphere Automationで新しく作成されたリソース通知から渡された情報を含むメッセージが Slack に表示されることです。 このチュートリアルの場合、リソース通知には、管理対象サーバーで新しい脆弱性が検出されたときの新しい脆弱性レコードの作成に関する詳細が含まれています。 以下のリソース通知の例では、 type パラメーターの値は createです。作成されるオブジェクトは vulnerabilityです。
{
"type": "CREATE",
"vulnerability": {
"id": "70357d34-411d-3321-a60f-ede653897a55",
"name": "6557248 : server1@defected1.example.com",
"description": "Multiple vulnerabilities exist in the Apache Log4j (CVE-2022-23302, CVE-2022-23305, CVE-2022-23307) library used by IBM WebSphere Application Server in the Admin Console and UDDI Registry application. The same Apache library is also used by the IBM WebSphere Application Server Liberty for z/OS in features zosConnect-1.0 and zosConnect-1.2. All vulnerabilities have been addressed previously by removing all existing Apache Log4j versions.",
"assetId": "1a5d141a-3294-3ff3-9182-5ae1d4f3465d",
"securityBulletinId": "23c15e59-1ef9-3eb5-a175-0845597cdbc1",
"resolved": false,
"cves": [
{
"id": "CVE-2022-23302",
"description": "Apache Log4j could allow a remote authenticated attacker to execute arbitrary code on the system, caused by an unsafe deserialization in JMSSink. By sending specially-crafted JNDI requests using TopicConnectionFactoryBindingName configuration, an attacker could exploit this vulnerability to execute arbitrary code on the system.",
"cvssBaseScore": 8.8
},
{
"id": "CVE-2022-23305",
"description": "Apache Log4j is vulnerable to SQL injection. A remote attacker could send specially-crafted SQL statements to the JDBCAppender, which could allow the attacker to view, add, modify or delete information in the back-end database.",
"cvssBaseScore": 6.5
},
{
"id": "CVE-2022-23307",
"description": "Apache Log4j could allow a remote attacker to execute arbitrary code on the system, caused by an unsafe deserialization in the in Apache Chainsaw component. By sending specially-crafted input, an attacker could exploit this vulnerability to execute arbitrary code on the system.",
"cvssBaseScore": 9.8
}
],
"remediations": [
{
"startVersion": "9.0.0.0",
"endVersion": "9.0.5.10",
"operator": "OR",
"iFixes": [
"PH42762"
],
"fixPack": "9.0.5.11",
"additionalInstallationInstructions": "https://www.ibm.com/support/pages/node/6557248"
}
],
"links": {
"self": {
"rel": "self",
"href": "https://cpd-websphere-automation.apps.wsa-412.example.com/vulnerabilities/70357d34-411d-3321-a60f-ede653897a55",
"type": "application/json",
"title": "self"
},
"asset": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.wsa-412.example.com/assets/1a5d141a-3294-3ff3-9182-5ae1d4f3465d",
"type": "application/json",
"title": "asset"
},
"securityBulletin": {
"rel": "related",
"href": "https://cpd-websphere-automation.apps.wsa-412.example.com/bulletins/23c15e59-1ef9-3eb5-a175-0845597cdbc1",
"type": "application/json",
"title": "securityBulletin"
}
},
"created": "2023-05-17T10:10:29Z",
"createdBy": "vulnerability-manager",
"updated": "2023-05-17T10:10:29Z",
"updatedBy": "vulnerability-manager",
"secondsExposed": 1379
}
}
興味深い情報には、CVE ID、CVSS スコア、影響を受けるサーバー、脆弱性の説明、セキュリティ勧告URL などが含まれます。
プロセスと予期される結果の定義
その結果、Slack Webhook ターゲットが新しい重大度の高い CVE に関する情報を受け取り、その情報を新しい Slack メッセージに表示します。
- Web ブラウザーで Slack ブロック・キット・ビルダーを開きます。
https://app.slack.com/block-kit-builder/ - ブロック・キット・ビルダーを使用して、希望する形式でテキストを表示するメッセージを作成します。 この Slack メッセージは、以下の例を使用して構成されます。

{ "blocks": [ { "type": "section", "text": { "type": "mrkdwn", "text": ":alert1: WebSphere Automation detected a vulnerability for CVE <https://www.ibm.com/support/pages/node/6525706|CVE-2021-44228> (CVSS base score 10.0) on server *server1* on host *defected1.example.com*." } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "*CVE Information*\nApache Log4j could allow a remote attacker to execute arbitrary code on the system, caused by the failure to protect against attacker controlled LDAP and other JNDI related endpoints by JNDI features. By sending a specially crafted code string, an attacker could exploit this vulnerability to load arbitrary Java code on the server and take complete control of the system. Note: The vulnerability is also called Log4Shell or LogJam." } }, { "type": "divider" }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "View Bulletin", "emoji": true }, "value": "click_me", "url": "https://www.ibm.com/support/pages/node/6525706" }, { "type": "button", "text": { "type": "plain_text", "text": "View All server1 CVEs", "emoji": true }, "value": "click_me_123", "url": "https://cpd-websphere-automation.example.com/websphereauto/websphere/1a5d141a-3294-3ff3-9182-5ae1d4f3465d/vulnerabilities/cves" } ] } ] } - Slack メッセージが正しく構造化されたら、Mustache 構文を使用して変数を置換できます。 WebSphere Automation イベントから送信するパラメーターに対して、これらの置換を行います。
{ "channel": "<your_Slack_channel>", "blocks": [ { "type": "header", "text": { "type": "plain_text", "text": "Vulnerability Detected" } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "{{icon}} WebSphere Automation detected a vulnerability for CVE <{{bulletinUrl}}|{{cveId}}> (CVSS base score {{cvssBaseScore}}) on {{#isJdk}}JDK *{{productName}}*{{/isJdk}}{{^isJdk}}server *{{serverName}}*{{/isJdk}} on host *{{hostName}}*." } }, { "type": "divider" }, { "type": "section", "text": { "type": "mrkdwn", "text": "*CVE Information*\n{{{@wsa_eq_cveSummary}}}" } }, { "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "View Bulletin" }, "value": "click_me", "url": "{{bulletinUrl}}" }{{^isJdk}}, { "type": "button", "text": { "type": "plain_text", "text": "View All CVEs for {{serverName}}" }, "value": "click_me_123", "url": "https://cpd-websphere-automation.example.com/websphereauto/websphere/{{serverId}}/vulnerabilities/cves" } {{/isJdk}} ] }, { "type": "divider" } ] }
Webhook アクションのセットアップ
WebSphere Automation Swagger UI を使用して、Webhook アクションを作成します。 詳細については、 Webhookアクションの作成を参照してください。
body パラメーターで、Slack ブロック・キット・ビルダーで作成した JSON エレメントのコンマ区切りリストを作成します。 本体パラメーターの値の引用符は、円記号文字でエスケープする必要があります。 作成した変数名には Mustache 表記 (二重中括弧) を使用します。
{
"id": "74313a6b-a163-4f7d-833b-31bf4f12670a",
"name": "Vulnerability Slack Notification Action",
"description": "POSTs a notification to Slack when triggered",
"type": "webhook",
"enabled": true,
"configuration": {
"targetUrl": "https://hooks.slack.com/services/12345/12345/12345",
"method": "POST",
"contentType": "application/json",
"headers": [],
"body": "{ \"channel\": \"<your_Slack_channel>\", \"blocks\": [ { \"type\": \"header\", \"text\": { \"type\": \"plain_text\", \"text\": \"Vulnerability Detected\" } }, { \"type\": \"divider\" }, { \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"{{icon}} WebSphere Automation detected a vulnerability for CVE <{{bulletinUrl}}|{{cveId}}> (CVSS base score {{cvssBaseScore}}) on {{#isJdk}}JDK *{{productName}}*{{/isJdk}}{{^isJdk}}server *{{serverName}}*{{/isJdk}} on host *{{hostName}}*.\" } }, { \"type\": \"divider\" }, { \"type\": \"section\", \"text\": { \"type\": \"mrkdwn\", \"text\": \"*CVE Information*\\n{{{@wsa_eq_cveSummary}}}\" } }, { \"type\": \"actions\", \"elements\": [ { \"type\": \"button\", \"text\": { \"type\": \"plain_text\", \"text\": \"View Bulletin\" }, \"value\": \"click_me\", \"url\": \"{{bulletinUrl}}\" }{{^isJdk}}, { \"type\": \"button\", \"text\": { \"type\": \"plain_text\", \"text\": \"View All CVEs for {{serverName}}\" }, \"value\": \"click_me_123\", \"url\": \"https://cpd-websphere-automation.example.com/websphereauto/websphere/{{serverId}}/vulnerabilities/cves\" } {{/isJdk}} ] }, { \"type\": \"divider\" } ] }"
}
}
Webhook アクションのテスト
Webhook アクションをテストするには、 WebSphere Automation Swagger UI を開き、 PATCH /action/{actionId} コントロールを使用して、ハードコーディングされた値を Slack に渡します。 詳しくは、 アクションの作成をご覧ください。
actionId テキスト・フィールドにアクション ID を入力します。 Swagger UI が作成時にアクションに割り当てた actionId 値を使用します。
以下の JSON コードを 「要求本文」 フィールドに入力します。
{
"operation": "invoke-action",
"variables": {
"hostName": "example.com",
"cveSummary": "Example CVE summary",
"bulletinUrl": "https://www.ibm.com/support/pages/node/6525706",
"cveId": "CVE-2021-44228",
"icon": ":alert1:",
"serverName": "server1",
"cvssBaseScore": "10",
"isJdk": "false",
"serverId": "1a5d141a-3294-3ff3-9182-5ae1d4f3465d",
"productName": "WebSphere Application Server"
}
}
「実行」をクリックします。
サーバー応答コードの値が 200であることを確認してください。 成功した応答には以下も含まれます。"successful": true応答本体の中にあります。
Slack チャネルを開き、新規メッセージが作成されたことを確認します。
リソース・トリガーの作成
指示に従ってリソーストリガーを作成する。 以下のリソース・トリガーの例を参照してください。
actionId パラメーターの値を、Swagger UI によってアクションに割り当てられたアクション ID に設定します。
variableMappings セクションで、アクションおよびインシデント・テーブルで定義されている変数と一致する変数を作成します。 各変数について、JSONata式を作成します。 https://try.jsonata.org/ に評価される JSONata 式を作成します。
{
"id": "46e65c6e-8c9d-4fe9-90fb-ac5ca2303fae",
"name": "Vulnerability Created Trigger",
"description": "Triggers the Slack Notification action when a vulnerability with a CVE that has a CVSS base score greater than 9 is created.",
"actionId": "<your_Slack_Notification_action_id>",
"type": "resource",
"enabled": true,
"configuration": {
"resourceType": "vulnerability",
"operation": "create"
},
"variableMappings": {
"hostName": "$asset.hostName",
"cveSummary": "($maxCvssBaseScore := $max(vulnerability.cves.cvssBaseScore); vulnerability.cves[cvssBaseScore = $maxCvssBaseScore][0].description)",
"bulletinUrl": "$bulletin.url",
"cveId": "($maxCvssBaseScore := $max(vulnerability.cves.cvssBaseScore); vulnerability.cves[cvssBaseScore = $maxCvssBaseScore][0].id)",
"icon": "($maxCvssBaseScore := $max(vulnerability.cves.cvssBaseScore); $maxCvssBaseScore > 0 and $maxCvssBaseScore <= 3.9 ? ':warning:' : ($maxCvssBaseScore >= 4 and $maxCvssBaseScore <= 6.9 ? ':standup_ibm_status_major_warning_orange:' : ($maxCvssBaseScore >= 7 and $maxCvssBaseScore <= 8.9 ? ':ibm-warning-filled:' : ':alert1:')))",
"serverName": "$asset.serverName",
"cvssBaseScore": "$number($max(vulnerability.cves.cvssBaseScore))",
"isJdk": "$asset.type = 'jdk'",
"serverId": "$asset.id",
"productName": "$asset.productName"
}
}
各種 JSONata 式の説明は以下のとおりです。
- cveSummary: 最も高い CVSS スコアを持つリソース通知内の CVE の説明。
- cveId: 最も高い CVSS スコアを持つリソース通知内の CVE の CVE ID。
- icon: CVSS スコアが最も高い CVE の緊急度を示すアイコン。CVSS スコアが 3.9 以下の場合は警告シンボルが表示され、 4.0 から 6.9の場合は主要な警告が表示され、 7.0 より大きい場合はアラートが表示されます。
- cvssBaseScore: リソース通知内の CVE の最も高い CVSS スコア。
以下の変数はコンテキスト変数を使用します。 詳細はトリガーリソースを参照。
- isJDK: CVE が Java Developer Kit に影響を与えるように設定されている場合に
trueと評価されるブール値。 - productName: 脆弱性がある製品の名前。
- servername: 脆弱性があるサーバーの名前。
- hostname: 脆弱性のあるランタイムのホスト名。
- bulletinUrl:脆弱性に関するセキュリティ勧告URL。
Swagger UI を使用して JSON コードを実行することにより、リソース・トリガーを有効にします。 詳細については、 リソーストリガの作成を参照してください。