<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hacktify on Medium]]></title>
        <description><![CDATA[Stories by Hacktify on Medium]]></description>
        <link>https://medium.com/@hacktify?source=rss-e483c6c57dbf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*IfH1aLFKLnq9K6vW</url>
            <title>Stories by Hacktify on Medium</title>
            <link>https://medium.com/@hacktify?source=rss-e483c6c57dbf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 20:57:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hacktify/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[PHP2Shell: Fixing GHSA-w8hw-w9fx-j79w]]></title>
            <link>https://medium.com/@hacktify/php2shell-fixing-ghsa-w8hw-w9fx-j79w-8833fa74f3b9?source=rss-e483c6c57dbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/8833fa74f3b9</guid>
            <category><![CDATA[php2shell]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cve-2026-109618]]></category>
            <category><![CDATA[rce]]></category>
            <category><![CDATA[cve-2026-109619]]></category>
            <dc:creator><![CDATA[Hacktify]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 12:39:16 GMT</pubDate>
            <atom:updated>2026-10-22T12:39:16.290Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Web Exploitation | PHP | GHSA-w8hw-w9fx-j79w</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mxZ-gKQQ4CJuRQQkWtUXkw.png" /></figure><h3>The scenario</h3><p>SkillBit’s PHP2Shell challenge puts you in a familiar ops situation. A public exploit called php2shell targets the PHP build behind a fictional company’s website (Inkline Print Co.). The proper fix is upgrading to PHP 8.5.12, but that has to wait for the next maintenance window.</p><p>The task: apply the interim configuration from the PHP security advisory (GHSA-w8hw-w9fx-j79w, a multipart request parsing out-of-memory issue), reload Apache with reload-apache, and keep artwork uploads working. The flag appears on the site once the mitigation is live.</p><p>This is defense work, not exploitation. The skill being tested is applying a vendor workaround correctly under real constraints.</p><h3>Initial audit</h3><p>The lab ran Apache with mod_php (PHP 8.5.11) on 127.0.0.1:8080, with the config at /etc/php/apache2/php.ini. The relevant baseline values:</p><pre>max_multipart_body_parts = 110<br>memory_limit = 128M</pre><p>The Apache site config also set a request size cap:</p><pre>&lt;VirtualHost *:8080&gt;<br>    DocumentRoot /opt/lab/source<br>    LimitRequestBody 131072<br>&lt;/VirtualHost&gt;</pre><p>LimitRequestBody rejects anything over 128 KB with an HTTP 413 before PHP ever sees it. That’s a useful extra layer, but it doesn’t replace the advisory’s fix, since smaller multipart requests still reach the parser.</p><h3>The hurdle: sed -i fails</h3><p>The advisory change was a one-line edit to memory_limit, so I tried the obvious approach:</p><pre>sed -i &#39;s/^memory_limit.*/memory_limit = -1/&#39; /etc/php/apache2/php.ini<br># sed: couldn&#39;t open temporary file /etc/php/apache2/sed...: Permission denied</pre><p>The permissions explain why:</p><pre>ls -l /etc/php/apache2/php.ini<br># -rw-rw----. 1 root lab 70322 Oct 22 11:52 /etc/php/apache2/php.ini</pre><p>My user (group lab) can write to the file, but not to its parent directory. sed -i doesn’t edit in place. It writes a temporary file in the same directory and renames it over the original, so it fails when the directory isn’t writable.</p><h3>The fix</h3><p>Stage the edited copy in /tmp, then write it back into the existing file. Redirecting into the file only needs write access to the file itself, not the directory.</p><pre>cat /etc/php/apache2/php.ini | sed &#39;s/^memory_limit\s*=.*/memory_limit = -1/&#39; &gt; /tmp/php.ini<br>cat /tmp/php.ini &gt; /etc/php/apache2/php.ini</pre><p>Then reload Apache with the lab’s helper:</p><pre>reload-apache<br># {&quot;ok&quot;: true, &quot;message&quot;: &quot;Apache restarted.&quot;}</pre><p>And check the result with the challenge’s validation endpoint:</p><pre>curl -sS http://127.0.0.1:9000/result<br># {&quot;passed&quot;: true, &quot;flag&quot;: &quot;SkillBit{...}&quot;}</pre><p>The mitigation was accepted and uploads kept working.</p><h3>Takeaways</h3><ol><li><strong>Config-level workarounds buy time.</strong> When a full upgrade has to wait, a vendor-recommended setting can reduce exposure in the meantime. Track it as temporary and schedule the real upgrade.</li><li><strong>File permissions and directory permissions are different</strong>. Write access to a file lets you change its contents with redirection, even when sed -i fails because the parent directory is locked down.</li><li><strong>Layered controls help</strong>. Apache’s LimitRequestBody acts before PHP runs, so it blocks oversized requests early. It complements application-level fixes rather than replacing them.</li><li><strong>Verify after every change.</strong> Reload the service, then confirm the change actually took effect.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8833fa74f3b9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-Time Wazuh Alerts in Discord — A Complete Integration Guide]]></title>
            <link>https://medium.com/@hacktify/real-time-wazuh-alerts-in-discord-a-complete-integration-guide-e431bba0e0fc?source=rss-e483c6c57dbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e431bba0e0fc</guid>
            <category><![CDATA[siem]]></category>
            <category><![CDATA[discord]]></category>
            <category><![CDATA[wazuh-integration]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[discord-webhooks]]></category>
            <dc:creator><![CDATA[Hacktify]]></dc:creator>
            <pubDate>Thu, 09 Apr 2026 06:28:17 GMT</pubDate>
            <atom:updated>2026-04-09T06:28:17.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5R6aD3bhoQHM8DxpGzWCdA.png" /><figcaption>Real-time SIEM alerts via Discord Webhooks</figcaption></figure><p>If you’re running <strong>Wazuh</strong> as your SIEM, you already know how powerful it is for threat detection. But what’s the point of catching threats in real time if your team only sees the alert the next morning when they open the dashboard?</p><p>In this guide, we’ll connect Wazuh’s alert engine directly to a Discord channel using a custom integration. When a rule fires — a failed SSH login, a file integrity change, a suspicious process — your team gets an instant Discord notification with all the details.</p><p>No paid tools. No plugins. Just a bash wrapper, a Python script, a webhook URL, and a few lines of Wazuh config.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*JaqWXJFQQcEqLVHbWZVvog.png" /><figcaption>Wazuh to Discord: Automated Alert Pipeline</figcaption></figure><h3>Prerequisites</h3><ul><li>A running Wazuh manager (v4.x recommended)</li><li>Root or sudo access to the Wazuh server</li><li>A Discord server where you have “Manage Webhooks” permission</li><li>Python 3 and pip3 available on the Wazuh manager</li><li>Basic familiarity with Linux terminal and XML config</li></ul><h3>Step-by-Step Setup</h3><p>Before writing any scripts, make sure your system packages are up to date and Python’s package manager is available. SSH into your Wazuh manager and run:</p><pre># Refresh apt index and upgrade existing packages<br>sudo apt update &amp;&amp; sudo apt upgrade -y<br><br># Ensure pip3 is installed for Python package management<br>sudo apt install python3-pip -y<br><br># Install the requests library (used in our Python script)<br>pip3 install requests</pre><p>The requests library is not part of Python&#39;s standard library. It&#39;s needed to POST the alert payload to Discord&#39;s webhook endpoint over HTTPS.</p><h3>Create the bash wrapper — custom-discord</h3><p>Wazuh’s integration engine calls shell scripts from /var/ossec/integrations/. The shell script is just a launcher — it figures out where Wazuh is installed and calls the matching Python script. Create the file:</p><p>📄 /var/ossec/integrations/custom-discord</p><pre>#!/bin/sh<br># Wazuh integration launcher for Discord<br><br>WPYTHON_BIN=&quot;framework/python/bin/python3&quot;<br>SCRIPT_PATH_NAME=&quot;$0&quot;<br>DIR_NAME=&quot;$(cd &quot;$(dirname &quot;${SCRIPT_PATH_NAME}&quot;)&quot;; pwd -P)&quot;<br>SCRIPT_NAME=&quot;$(basename &quot;${SCRIPT_PATH_NAME}&quot;)&quot;<br><br>case ${DIR_NAME} in<br>    */active-response/bin | */wodles*)<br>        if [ -z &quot;${WAZUH_PATH}&quot; ]; then<br>            WAZUH_PATH=&quot;$(cd &quot;${DIR_NAME}/../..&quot;; pwd)&quot;<br>        fi<br>        PYTHON_SCRIPT=&quot;${DIR_NAME}/${SCRIPT_NAME}.py&quot;<br>    ;;<br>    */bin)<br>        if [ -z &quot;${WAZUH_PATH}&quot; ]; then<br>            WAZUH_PATH=&quot;$(cd &quot;${DIR_NAME}/..&quot;; pwd)&quot;<br>        fi<br>        PYTHON_SCRIPT=&quot;${WAZUH_PATH}/framework/scripts/$(echo &quot;${SCRIPT_NAME}&quot; \<br>            | sed &#39;s/\.sh$/.py/&#39;)&quot;<br>    ;;<br>    */integrations)<br>        if [ -z &quot;${WAZUH_PATH}&quot; ]; then<br>            WAZUH_PATH=&quot;$(cd &quot;${DIR_NAME}/..&quot;; pwd)&quot;<br>        fi<br>        PYTHON_SCRIPT=&quot;${DIR_NAME}/${SCRIPT_NAME}.py&quot;<br>    ;;<br>esac<br><br># Execute the Python script with all arguments passed through<br>exec &quot;${WAZUH_PATH}/${WPYTHON_BIN}&quot; &quot;${PYTHON_SCRIPT}&quot; &quot;$@&quot;</pre><p>Now set the correct permissions so Wazuh can execute it:</p><pre>sudo chmod 750 /var/ossec/integrations/custom-discord<br>sudo chown root:wazuh /var/ossec/integrations/custom-discord</pre><h3>Create the Python script — custom-discord.py</h3><p>This is the actual integration logic. It reads the Wazuh alert from a JSON file, formats it into a Discord embed message, and POSTs it to your webhook URL.</p><p>📄 /var/ossec/integrations/custom-discord.py</p><pre>#!/usr/bin/env python3<br><br>import sys<br>import requests<br>import json<br><br># Read configuration<br>alert_file = sys.argv[1]<br>user = sys.argv[2].split(&quot;:&quot;)[0]<br>hook_url = sys.argv[3]<br><br># Read alert file<br>with open(alert_file) as f:<br>    alert_json = json.loads(f.read())<br><br># Basic info<br>rule = alert_json.get(&quot;rule&quot;, {})<br>alert_level = rule.get(&quot;level&quot;, 0)<br>agent_ = alert_json.get(&quot;agent&quot;, {}).get(&quot;name&quot;, &quot;agentless&quot;)<br>#agent_ip = agent.get(&quot;ip&quot;) or alert_json.get(&quot;data&quot;, {}).get(&quot;srcip&quot;, &quot;N/A&quot;)<br># Color coding<br>if alert_level &lt; 5:<br>    color = 5763719<br>elif 5 &lt;= alert_level &lt;= 7:<br>    color = 16705372<br>else:<br>    color = 15548997<br><br># Start building fields<br>fields = [<br>    {&quot;name&quot;: &quot;Rule ID&quot;, &quot;value&quot;: str(rule.get(&quot;id&quot;, &quot;N/A&quot;)), &quot;inline&quot;: True},<br>    {&quot;name&quot;: &quot;Level&quot;, &quot;value&quot;: str(alert_level), &quot;inline&quot;: True},<br>    {&quot;name&quot;: &quot;Agent&quot;, &quot;value&quot;: agent_, &quot;inline&quot;: True},<br>    #{&quot;name&quot;: &quot;Agent IP&quot;, &quot;value&quot;: agent_ip, &quot;inline&quot;: True},<br>    {&quot;name&quot;: &quot;Description&quot;, &quot;value&quot;: rule.get(&quot;description&quot;, &quot;N/A&quot;), &quot;inline&quot;: F                                                                                                             alse},<br>    {&quot;name&quot;: &quot;Timestamp&quot;, &quot;value&quot;: alert_json.get(&quot;timestamp&quot;, &quot;N/A&quot;), &quot;inline&quot;:                                                                                                              False}<br>]<br><br># Dynamically add key fields from data<br>data = alert_json.get(&quot;data&quot;, {})<br>key_fields = [&quot;srcip&quot;, &quot;srcport&quot;, &quot;dstip&quot;, &quot;dstport&quot;, &quot;srccountry&quot;, &quot;dstcountry&quot;                                                                                                             ,<br>              &quot;action&quot;, &quot;app&quot;, &quot;url&quot;, &quot;user&quot;, &quot;protocol&quot;, &quot;eventtype&quot;, &quot;msg&quot;,&quot;ds                                                                                                             tuser&quot;,&quot;status&quot;,&quot;mitre.tactic&quot;]<br><br>for key in key_fields:<br>    if key in data:<br>        fields.append({<br>            &quot;name&quot;: key.replace(&quot;_&quot;, &quot; &quot;).title(),<br>            &quot;value&quot;: str(data[key]),<br>            &quot;inline&quot;: True if len(str(data[key])) &lt; 50 else False<br>        })<br><br># Add full_log (truncated for Discord limits)<br>full_log = alert_json.get(&quot;full_log&quot;, &quot;&quot;)<br>if full_log:<br>    fields.append({<br>        &quot;name&quot;: &quot;Full Log&quot;,<br>        &quot;value&quot;: f&quot;{full_log}&quot;,<br>        &quot;inline&quot;: False<br>    })<br><br># Build payload<br>payload = json.dumps({<br>    &quot;content&quot;: &quot;&quot;,<br>    &quot;embeds&quot;: [<br>        {<br>            &quot;title&quot;: f&quot;Wazuh Alert - Rule {rule.get(&#39;id&#39;, &#39;N/A&#39;)}&quot;,<br>            &quot;color&quot;: color,<br>            &quot;fields&quot;: fields<br>        }<br>    ]<br>})<br><br># Send to Discord<br>requests.post(hook_url, data=payload, headers={&quot;content-type&quot;: &quot;application/json                                                                                                             &quot;})<br>sys.exit(0)</pre><p>Set permissions on the Python file too:</p><pre>sudo chmod 750 /var/ossec/integrations/custom-discord.py<br>sudo chown root:wazuh /var/ossec/integrations/custom-discord.py</pre><h3>Create the Discord webhook</h3><p>Now let’s create the destination for our alerts inside Discord.</p><p>Open <strong>Discord</strong> → go to the channel where you want alerts → click the gear icon (Edit Channel) → go to <strong>Integrations</strong> → click <strong>Webhooks</strong> → click <strong>New Webhook</strong>.</p><p>Give it a name (e.g., <em>Wazuh Alerts</em>), optionally set an avatar, then click <strong>Copy Webhook URL</strong>. Save this URL — you’ll need it in the next step.</p><h3>Configure Wazuh to use the integration</h3><p>Open /var/ossec/etc/ossec.conf and add the following block inside the &lt;ossec_config&gt; section. Replace the placeholder values with your real webhook URL and desired rule IDs:</p><p>📄 /var/ossec/etc/ossec.conf — add inside &lt;ossec_config&gt;</p><pre>&lt;integration&gt;<br>  &lt;name&gt;custom-discord&lt;/name&gt;<br>  &lt;hook_url&gt;https://discord.com/api/webhooks/YOUR_WEBHOOK_URL&lt;/hook_url&gt;<br>  &lt;rule_id&gt;5710,5711,5712,87901,87902&lt;/rule_id&gt;<br>  &lt;alert_format&gt;json&lt;/alert_format&gt;<br>&lt;/integration&gt;</pre><p>The &lt;rule_id&gt; field accepts a comma-separated list of rule IDs. Use this to scope which alerts trigger Discord notifications — for example, SSH brute force (5710–5712), web attacks (31100+), or your own custom rules. To alert on ALL rules above a certain level, replace &lt;rule_id&gt; with &lt;level&gt;7&lt;/level&gt;.</p><h3>Common rule IDs worth notifying on</h3><pre># SSH authentication failures<br>5710, 5711, 5712<br><br># Sudo privilege escalation<br>5401, 5402<br><br># File integrity monitoring (FIM) changes<br>550, 554<br><br># Web server attacks (Apache/Nginx)<br>31100, 31108<br><br># Windows event log anomalies<br>60106, 60204</pre><h3>Restart Wazuh and verify</h3><p>Apply the configuration by restarting the Wazuh manager:</p><pre>sudo systemctl restart wazuh-manager<br><br># Watch the integration logs for errors<br>sudo tail -f /var/ossec/logs/integrations.log</pre><p>To test the integration without waiting for a real alert, you can trigger a test event. On any monitored agent, intentionally fail an SSH login a few times. Within seconds, you should see a formatted embed appear in your Discord channel.</p><p>If nothing appears, check the integration log above — common issues are wrong file permissions, a malformed webhook URL, or missing the requests library.</p><h3>Troubleshooting</h3><p>Here are the most common issues and how to fix them quickly:</p><pre># Re-check ownership and executable bit<br>ls -la /var/ossec/integrations/custom-discord*<br>sudo chown root:wazuh /var/ossec/integrations/custom-discord*<br>sudo chmod 750 /var/ossec/integrations/custom-discord*</pre><p>ModuleNotFoundError: No module named ‘requests’</p><pre># Install for Wazuh&#39;s embedded Python if pip3 install requests didn&#39;t help<br>sudo /var/ossec/framework/python/bin/pip3 install requests</pre><p>Discord returns HTTP 400 / payload too large</p><pre># Truncate long field values in custom-discord.py<br># e.g. limit description to 2000 chars (Discord embed limit)<br>&quot;description&quot;: rule.get(&quot;description&quot;, &quot;&quot;)[:2000]</pre><h3>Conclusion</h3><p>What you build:</p><p>A lightweight, self-hosted alert forwarding pipeline that sends Wazuh security events to Discord in real time — with severity color coding, agent info, timestamps, and MITRE ATT&amp;CK technique IDs, all in a clean embed format your team can act on immediately.</p><p>From here, you can extend this further: add a level filter in ossec.conf instead of individual rule IDs to catch all high-severity events, post to different Discord channels based on rule groups, or enrich the embed with GeoIP data on suspicious source IPs.</p><p>The integration pattern you’ve just implemented — a bash launcher + Python processor + webhook destination — is the same pattern used for all Wazuh custom integrations. The same approach works for Slack, Microsoft Teams, Telegram, or any service that accepts webhook payloads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e431bba0e0fc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Automate Daily Snapshot Monitoring for Wazuh with Email Alerts]]></title>
            <link>https://medium.com/@hacktify/how-to-automate-daily-snapshot-monitoring-for-wazuh-with-email-alerts-e53aa6cfc99f?source=rss-e483c6c57dbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/e53aa6cfc99f</guid>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[siem]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[snapshot]]></category>
            <dc:creator><![CDATA[Hacktify]]></dc:creator>
            <pubDate>Wed, 01 Apr 2026 12:06:57 GMT</pubDate>
            <atom:updated>2026-04-01T12:10:26.855Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ppt9nrhZ64HuZiDJ3JfIdw.png" /></figure><h3>Introduction</h3><p>If you’re using Wazuh (or any Elasticsearch-based SIEM), taking regular snapshots of your indices is crucial for disaster recovery. But how do you know if your daily snapshot actually completed successfully? Manually checking the snapshot status every day is tedious.</p><p>In this guide, I’ll walk you through setting up a fully automated monitoring solution that:</p><ul><li>Checks for the today’s snapshot</li><li>Sends an<strong> </strong>HTML email with a status table</li></ul><p>The script queries the Elasticsearch snapshot API, parses the JSON with jq, and sends the email using sendmail (or you can adapt it to your preferred mailer). We&#39;ll also schedule it via cron to run at 9:00 AM daily.</p><h3>Prerequisites</h3><ul><li>A running Wazuh/Elasticsearch cluster.</li><li>Access to the Elasticsearch API (default credentials admin:admin or your own).</li><li>The snapshot repository is named snapshot (adjustable).</li><li>Snapshot names follow the pattern daily-snapshot-YYYY-MM-DDtHH:MM:SS-XXXXX.</li><li>Linux server with:<br> → curl – to call the API<br> → jq – to parse JSON<br> → sendmail – to send HTML emails<br> → Cron — to schedule the script</li></ul><p>If jq is not installed, install it:</p><pre>sudo apt install jq          # Debian/Ubuntu<br>sudo yum install jq          # RHEL/CentOS</pre><h3>Step 1: Create the Script</h3><p>Create a file /usr/local/bin/wazuh_snapshot_notify.sh with the following content. Edit the configuration variables at the top: ES_USER, ES_PASS, EMAIL_RECIPIENT (comma-separated), and optionally SNAPSHOT_REPO if yours has a different name.</p><pre>#!/bin/bash<br><br># ===============================================<br># Wazuh Daily Snapshot Notification Script<br># ===============================================<br><br># --- Configuration ---<br>ES_HOST=&quot;localhost&quot;<br>ES_PORT=&quot;9200&quot;<br>ES_USER=&quot;admin&quot;<br>ES_PASS=&quot;admin&quot;<br>SNAPSHOT_REPO=&quot;snapshot&quot;<br>EMAIL_RECIPIENT=&quot;admin@example.com,backup@example.com&quot;<br>STATE_FILE=&quot;/tmp/last_snapshot_processed.txt&quot;<br><br># --- Function to send HTML email using sendmail ---<br>send_email() {<br>    local subject=&quot;$1&quot;<br>    local body=&quot;$2&quot;<br>    (<br>        echo &quot;MIME-Version: 1.0&quot;<br>        echo &quot;Content-Type: text/html; charset=UTF-8&quot;<br>        echo &quot;Subject: $subject&quot;<br>        echo &quot;To: $EMAIL_RECIPIENT&quot;<br>        echo<br>        echo &quot;$body&quot;<br>    ) | sendmail -t<br>}<br><br># --- Fetch all snapshots from Elasticsearch ---<br>snapshots_json=$(curl -k -s -u &quot;$ES_USER:$ES_PASS&quot; \<br>    &quot;https://$ES_HOST:$ES_PORT/_snapshot/$SNAPSHOT_REPO/_all?pretty&quot;)<br><br>if [ $? -ne 0 ] || [ -z &quot;$snapshots_json&quot; ]; then<br>    send_email &quot;google snapshot status : ERROR&quot; \<br>        &quot;&lt;html&gt;&lt;body&gt;Failed to retrieve snapshot list from Elasticsearch.&lt;/body&gt;&lt;/html&gt;&quot;<br>    exit 1<br>fi<br><br># --- Use yesterday&#39;s date (snapshot runs at 8:10 PM) ---<br>yesterday=$(date -d &quot;yesterday&quot; +&quot;%Y-%m-%d&quot;)<br><br># --- Extract snapshots from yesterday with final states ---<br>snapshots=$(echo &quot;$snapshots_json&quot; | jq -c --arg yesterday &quot;$yesterday&quot; &#39;<br>.snapshots[]? <br>| select(.snapshot | test(&quot;^daily-snapshot-&quot; + $yesterday + &quot;t.*&quot;))<br>| select(.state == &quot;SUCCESS&quot; or .state == &quot;PARTIAL&quot; or .state == &quot;FAILED&quot;)<br>| {snapshot: .snapshot, state: .state, start_time: .start_time, end_time: .end_time, duration_ms: .duration_in_millis, shards_total: .shards.total, shards_successful: .shards.successful, shards_failed: .shards.failed, indices_count: (.indices | length)}<br>&#39;)<br><br># If no matching snapshot found, exit silently<br>[ -z &quot;$snapshots&quot; ] &amp;&amp; exit 0<br><br># --- Load already processed snapshots ---<br>if [ -f &quot;$STATE_FILE&quot; ]; then<br>    processed=$(cat &quot;$STATE_FILE&quot;)<br>else<br>    processed=&quot;&quot;<br>fi<br><br># --- Helper: convert ISO date to &quot;DD Month YYYY&quot; ---<br>format_date() {<br>    local iso=&quot;$1&quot;<br>    date -d &quot;${iso%T*}&quot; +&quot;%d %B %Y&quot; 2&gt;/dev/null || echo &quot;${iso%T*}&quot;<br>}<br><br># --- Process each snapshot found ---<br>echo &quot;$snapshots&quot; | while read -r snap; do<br>    name=$(echo &quot;$snap&quot; | jq -r &#39;.snapshot&#39;)<br>    state=$(echo &quot;$snap&quot; | jq -r &#39;.state&#39;)<br>    start=$(echo &quot;$snap&quot; | jq -r &#39;.start_time&#39;)<br>    end=$(echo &quot;$snap&quot; | jq -r &#39;.end_time&#39;)<br>    duration_ms=$(echo &quot;$snap&quot; | jq -r &#39;.duration_ms&#39;)<br>    shards_total=$(echo &quot;$snap&quot; | jq -r &#39;.shards_total&#39;)<br>    shards_ok=$(echo &quot;$snap&quot; | jq -r &#39;.shards_successful&#39;)<br>    shards_failed=$(echo &quot;$snap&quot; | jq -r &#39;.shards_failed&#39;)<br>    indices_count=$(echo &quot;$snap&quot; | jq -r &#39;.indices_count&#39;)<br><br>    duration_sec=$((duration_ms / 1000))<br>    duration_min=$((duration_sec / 60))<br>    duration_sec_rem=$((duration_sec % 60))<br><br>    pretty_date=$(format_date &quot;$start&quot;)<br><br>    # Skip if already notified<br>    if echo &quot;$processed&quot; | grep -Fxq &quot;$name&quot;; then<br>        continue<br>    fi<br><br>    # Determine emoji and header color class<br>    case &quot;$state&quot; in<br>        SUCCESS)<br>            emoji=&quot;✅&quot;<br>            header_class=&quot;success&quot;<br>            ;;<br>        PARTIAL)<br>            emoji=&quot;⚠️&quot;<br>            header_class=&quot;partial&quot;<br>            ;;<br>        FAILED)<br>            emoji=&quot;❌&quot;<br>            header_class=&quot;failed&quot;<br>            ;;<br>        *)<br>            emoji=&quot;ℹ️&quot;<br>            header_class=&quot;&quot;<br>            ;;<br>    esac<br><br>    # Build HTML email body<br>    email_body=$(cat &lt;&lt;EOF<br>&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;title&gt;Wazuh Snapshot Status&lt;/title&gt;<br>    &lt;style&gt;<br>        body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 20px; }<br>        .container { max-width: 600px; margin: 0 auto; background-color: #ffffff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); overflow: hidden; }<br>        .header { color: white; padding: 20px; text-align: center; font-size: 20px; }<br>        .header.success { background-color: #4CAF50; }<br>        .header.partial { background-color: #ff9800; }<br>        .header.failed  { background-color: #f44336; }<br>        .content { padding: 20px; }<br>        table { width: 100%; border-collapse: collapse; margin-top: 15px; }<br>        th, td { border: 1px solid #ddd; padding: 12px; text-align: left; }<br>        th { background-color: #f2f2f2; width: 30%; }<br>        td { background-color: #fff; }<br>        .footer { background-color: #f9f9f9; padding: 12px; text-align: center; font-size: 12px; color: #777; border-top: 1px solid #eee; }<br>        .emoji { font-size: 24px; margin-right: 8px; vertical-align: middle; }<br>    &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;div class=&quot;container&quot;&gt;<br>    &lt;div class=&quot;header ${header_class}&quot;&gt;<br>        &lt;span class=&quot;emoji&quot;&gt;${emoji}&lt;/span&gt; Snapshot Status: ${state}<br>    &lt;/div&gt;<br>    &lt;div class=&quot;content&quot;&gt;<br>        &lt;table&gt;<br>            &lt;tr&gt;&lt;th&gt;Date&lt;/th&gt;&lt;td&gt;${pretty_date}&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;State&lt;/th&gt;&lt;td&gt;${state}&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;Start Time&lt;/th&gt;&lt;td&gt;${start}&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;End Time&lt;/th&gt;&lt;td&gt;${end}&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;Duration&lt;/th&gt;&lt;td&gt;${duration_min}m ${duration_sec_rem}s (${duration_ms} ms)&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;Indices&lt;/th&gt;&lt;td&gt;${indices_count}&lt;/td&gt;&lt;/tr&gt;<br>            &lt;tr&gt;&lt;th&gt;Shards&lt;/th&gt;&lt;td&gt;${shards_ok}/${shards_total} successful (${shards_failed} failed)&lt;/td&gt;&lt;/tr&gt;<br>        &lt;/table&gt;<br>    &lt;/div&gt;<br>    &lt;div class=&quot;footer&quot;&gt;Wazuh Snapshot Monitor&lt;/div&gt;<br>&lt;/div&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br>EOF<br>)<br><br>    # Send the email<br>    send_email &quot;Snapshot Status : ${state}&quot; &quot;$email_body&quot;<br><br>    # Record snapshot name to prevent duplicate emails<br>    echo &quot;$name&quot; &gt;&gt; &quot;$STATE_FILE&quot;<br>done</pre><p>Make the script executable:</p><pre>sudo chmod +x /usr/local/bin/wazuh_snapshot_notify.sh</pre><h3>Step 2: Understanding the Script</h3><p>Let’s break down the key parts:</p><ul><li><strong>Configuration</strong> — Set your Elasticsearch credentials, repository, and recipient(s).</li><li><strong>API call</strong> — Uses curl to get all snapshots from the repository.</li><li><strong>State filtering</strong> — We capture only final states: SUCCESSand FAILED.</li><li><strong>State file</strong> — /tmp/last_snapshot_processed.txt stores the names of snapshots that have already been reported, so you don’t get duplicate emails if the script runs more than once.</li></ul><h3>Step 3: Schedule the Script with Cron</h3><p>We want the script to run at <strong>9:00 AM</strong> every day, after the snapshot has completed. Open the root crontab:</p><pre>sudo crontab -e</pre><p>Add the following line:</p><pre>0 9 * * * /usr/local/bin/wazuh_snapshot_notify.sh</pre><p>Save and exit. Now the script will run daily at 9:00 AM.</p><h3>Step 4: Test the Script</h3><p>Before relying on cron, test manually. First, clear the state file (if any) to force an email:</p><pre>sudo rm /tmp/last_snapshot_processed.txt</pre><p>Then run the script:</p><pre>sudo /usr/local/bin/wazuh_snapshot_notify.sh</pre><p>Check your email inbox.</p><p>If no email arrives, check:</p><ul><li>The script’s permissions</li><li>Whether jq is installed</li><li>Whether the Elasticsearch credentials and URL are correct</li><li>The snapshot naming pattern — adjust the regex in the jq filter if needed</li></ul><h3>Troubleshooting</h3><h4>No email after manual run</h4><ul><li>Verify the snapshot API returns data:</li></ul><pre>curl -k -u admin:admin https://localhost:9200/_snapshot/snapshot/_all?pretty | jq &#39;.snapshots[].snapshot&#39;</pre><ul><li>Check that jq is installed and the filter is correct.</li><li>Look at the script’s output: run with bash -x to see what’s happening.</li></ul><h3>Conclusion</h3><p>With this automated monitoring script, you no longer need to manually check if your daily Wazuh snapshots succeeded. You’ll receive a colorful, informative email every morning, giving you peace of mind (or an early warning if something went wrong). The script is flexible — you can easily modify it to suit your snapshot naming, email addresses, and preferred mailer.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e53aa6cfc99f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Secured Wazuh Dashboard with 2FA Using Keycloak SSO + Google Authenticator]]></title>
            <link>https://medium.com/@hacktify/how-i-secured-wazuh-dashboard-with-2fa-using-keycloak-sso-google-authenticator-59eb4b3db41c?source=rss-e483c6c57dbf------2</link>
            <guid isPermaLink="false">https://medium.com/p/59eb4b3db41c</guid>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[2fa]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[siem]]></category>
            <dc:creator><![CDATA[Hacktify]]></dc:creator>
            <pubDate>Sat, 21 Mar 2026 06:17:40 GMT</pubDate>
            <atom:updated>2026-03-21T06:17:40.677Z</atom:updated>
            <content:encoded><![CDATA[<p>Why I Did This?</p><p>Wazuh is a powerful open-source SIEM platform. But by default, the dashboard is protected only by a username and password. For a security tool that monitors your entire infrastructure, that’s simply not enough.</p><p>I wanted:</p><ul><li><strong>Two-factor authentication (2FA)</strong> for every login</li><li><strong>Role-based access</strong> — admin users and read-only users</li><li><strong>Enterprise SSO</strong> via Keycloak</li><li><strong>Google Authenticator (TOTP)</strong> as the second factor</li></ul><p>Here’s exactly how I did it.</p><h3>Architecture</h3><p>Before we dive in, here’s how the pieces fit together:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tzZG6-4G02zke67oGVxDbw.png" /><figcaption>Wazuh-Keycloak OIDC Authentication Flow</figcaption></figure><p>What each component does:</p><ul><li><strong>Nginx</strong> — Terminates SSL on port 443 and proxies traffic to the Wazuh Dashboard</li><li><strong>Wazuh Dashboard</strong> — Provides the UI and delegates authentication to Keycloak via OIDC</li><li><strong>Keycloak</strong> — Acts as the identity provider, handling login and enforcing TOTP</li><li><strong>Wazuh Indexer</strong> — Validates tokens and maps users to roles</li><li><strong>Google Authenticator</strong> — Generates 6-digit TOTP codes on your phone</li></ul><h3>Prerequisites</h3><ul><li>Wazuh stack (Manager, Indexer, Dashboard) already installed</li><li>Ubuntu 22.04 or 24.04 LTS</li><li>Root or sudo access</li><li>Ports 443 and 80 accessible from client machines</li><li>Google Authenticator installed on your phone</li></ul><p>Step 1 — Install Required Packages</p><pre>sudo apt update<br>sudo apt install -y nginx apache2-utils openjdk-21-jdk<br><br># Verify Java<br>java -version</pre><p>Step 2 — Install Keycloak 26.x</p><pre>cd /opt<br>sudo wget https://github.com/keycloak/keycloak/releases/download/26.1.4/keycloak-26.1.4.tar.gz<br>sudo tar -xzf keycloak-26.1.4.tar.gz<br>sudo mv keycloak-26.1.4 keycloak<br>sudo rm keycloak-26.1.4.tar.gz<br><br># Create dedicated service user<br>sudo useradd -r -s /sbin/nologin keycloak<br>sudo chown -R keycloak:keycloak /opt/keycloak</pre><p>Step 3 — Configure Keycloak</p><pre>sudo tee /opt/keycloak/conf/keycloak.conf &lt;&lt; &#39;EOF&#39;<br>http-enabled=true<br>http-port=8080<br>hostname=YOUR_SERVER_IP<br>hostname-strict=false<br>hostname-strict-https=false<br>db=dev-file<br>proxy-headers=xforwarded<br>EOF<br><br># Replace YOUR_SERVER_IP with your actual server IP.</pre><p>Step 4 — Create Keycloak Systemd Service</p><pre>sudo tee /etc/systemd/system/keycloak.service &lt;&lt; &#39;EOF&#39;<br>[Unit]<br>Description=Keycloak SSO<br>After=network.target<br><br>[Service]<br>User=keycloak<br>Group=keycloak<br>ExecStart=/opt/keycloak/bin/kc.sh start-dev<br>Restart=on-failure<br>RestartSec=10<br>Environment=KEYCLOAK_ADMIN=admin<br>Environment=KEYCLOAK_ADMIN_PASSWORD=Admin@123<br>Environment=KC_HTTP_PORT=8080<br><br>[Install]<br>WantedBy=multi-user.target<br>EOF<br><br>sudo systemctl daemon-reload<br>sudo systemctl enable keycloak<br>sudo systemctl start keycloak<br><br># Wait ~60 seconds for startup<br>sleep 60 &amp;&amp; sudo systemctl status keycloak --no-pager | head -5</pre><h3>Step 5 — Move Wazuh Dashboard to Port 5601</h3><p>By default Wazuh Dashboard runs on port 443. We need to free that port for Nginx.</p><pre>sudo sed -i &#39;s/^server\.port:.*/server.port: 5601/&#39; \<br>  /etc/wazuh-dashboard/opensearch_dashboards.yml<br><br>sudo sed -i &#39;s/^server\.host:.*/server.host: &quot;127.0.0.1&quot;/&#39; \<br>  /etc/wazuh-dashboard/opensearch_dashboards.yml<br><br># Verify<br>sudo grep -E &quot;server.port|server.host&quot; /etc/wazuh-dashboard/opensearch_dashboards.yml<br><br>sudo systemctl restart wazuh-dashboard<br>sleep 15 &amp;&amp; sudo ss -tlnp | grep 5601<br># Expected: LISTEN 0 511 127.0.0.1:5601</pre><p>Step 6 — Generate SSL Certificate for Nginx</p><pre>sudo mkdir -p /etc/nginx/ssl<br><br>sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 \<br>  -keyout /etc/nginx/ssl/nginx.key \<br>  -out /etc/nginx/ssl/nginx.crt \<br>  -subj &quot;/C=IN/ST=Gujarat/O=Wazuh/CN=wazuh-dashboard&quot;</pre><p>Step 7 — Configure Nginx as Reverse Proxy</p><pre>sudo tee /etc/nginx/sites-available/wazuh-2fa &lt;&lt; &#39;EOF&#39;<br>server {<br>    listen 443 ssl;<br>    server_name YOUR_SERVER_IP;<br><br>    ssl_certificate     /etc/nginx/ssl/nginx.crt;<br>    ssl_certificate_key /etc/nginx/ssl/nginx.key;<br>    ssl_protocols       TLSv1.2 TLSv1.3;<br>    ssl_ciphers         HIGH:!aNULL:!MD5;<br><br>    location / {<br>        proxy_pass          https://127.0.0.1:5601;<br>        proxy_ssl_verify    off;<br>        proxy_set_header    Host              $host;<br>        proxy_set_header    X-Real-IP         $remote_addr;<br>        proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;<br>        proxy_set_header    X-Forwarded-Proto $scheme;<br>        proxy_http_version  1.1;<br>        proxy_set_header    Upgrade    $http_upgrade;<br>        proxy_set_header    Connection &quot;upgrade&quot;;<br>    }<br>}<br><br>server {<br>    listen 80;<br>    server_name YOUR_SERVER_IP;<br>    return 301 https://$host$request_uri;<br>}<br>EOF<br><br>sudo ln -s /etc/nginx/sites-available/wazuh-2fa /etc/nginx/sites-enabled/<br>sudo rm -f /etc/nginx/sites-enabled/default<br>sudo nginx -t &amp;&amp; sudo systemctl enable nginx &amp;&amp; sudo systemctl restart nginx</pre><h3>Step 8 — Configure Keycloak (CLI — No Browser Needed)</h3><p>This is the cleanest way if your server is behind a VPN or firewall.</p><pre># Login to Keycloak admin CLI<br>/opt/keycloak/bin/kcadm.sh config credentials \<br>  --server http://127.0.0.1:8080 \<br>  --realm master \<br>  --user admin \<br>  --password Admin@123<br><br># Create wazuh realm<br>/opt/keycloak/bin/kcadm.sh create realms \<br>  -s realm=wazuh \<br>  -s enabled=true<br><br># Enable TOTP as required action<br>/opt/keycloak/bin/kcadm.sh update authentication/required-actions/CONFIGURE_TOTP \<br>  -r wazuh \<br>  -s enabled=true \<br>  -s defaultAction=true<br><br># Create admin user<br>/opt/keycloak/bin/kcadm.sh create users \<br>  -r wazuh \<br>  -s username=admin \<br>  -s enabled=true<br><br>/opt/keycloak/bin/kcadm.sh set-password \<br>  -r wazuh \<br>  --username admin \<br>  --new-password &#39;YourAdminPassword&#39;<br><br># Create readonly user<br>/opt/keycloak/bin/kcadm.sh create users \<br>  -r wazuh \<br>  -s username=psy9 \<br>  -s enabled=true<br><br>/opt/keycloak/bin/kcadm.sh set-password \<br>  -r wazuh \<br>  --username psy9 \<br>  --new-password &#39;YourReadonlyPassword&#39;<br><br># Create OIDC client<br>/opt/keycloak/bin/kcadm.sh create clients \<br>  -r wazuh \<br>  -s clientId=wazuh-dashboard \<br>  -s enabled=true \<br>  -s clientAuthenticatorType=client-secret \<br>  -s &#39;redirectUris=[&quot;https://YOUR_SERVER_IP/*&quot;]&#39; \<br>  -s &#39;webOrigins=[&quot;https://YOUR_SERVER_IP&quot;]&#39; \<br>  -s publicClient=false<br><br># Get client ID and secret<br>CLIENT_ID=$(/opt/keycloak/bin/kcadm.sh get clients -r wazuh \<br>  -q clientId=wazuh-dashboard --fields id --format csv --noquotes)<br><br>/opt/keycloak/bin/kcadm.sh get clients/$CLIENT_ID/client-secret -r wazuh<br><br># Add roles mapper so Keycloak sends roles in token<br>/opt/keycloak/bin/kcadm.sh create clients/$CLIENT_ID/protocol-mappers/models \<br>  -r wazuh \<br>  -s name=roles \<br>  -s protocol=openid-connect \<br>  -s protocolMapper=oidc-usermodel-realm-role-mapper \<br>  -s &#39;config.&quot;claim.name&quot;=roles&#39; \<br>  -s &#39;config.&quot;jsonType.label&quot;=String&#39; \<br>  -s &#39;config.&quot;multivalued&quot;=true&#39; \<br>  -s &#39;config.&quot;userinfo.token.claim&quot;=true&#39; \<br>  -s &#39;config.&quot;id.token.claim&quot;=true&#39; \<br>  -s &#39;config.&quot;access.token.claim&quot;=true&#39;</pre><p>Copy the client secret from the output — you’ll need it next.</p><p>Step 9 — Configure Wazuh Dashboard for OIDC</p><pre>sudo tee -a /etc/wazuh-dashboard/opensearch_dashboards.yml &lt;&lt; EOF<br>opensearch_security.auth.type: &quot;openid&quot;<br>opensearch_security.openid.connect_url: &quot;http://YOUR_SERVER_IP:8080/realms/wazuh/.well-known/openid-configuration&quot;<br>opensearch_security.openid.client_id: &quot;wazuh-dashboard&quot;<br>opensearch_security.openid.client_secret: &quot;YOUR_CLIENT_SECRET&quot;<br>opensearch_security.openid.base_redirect_url: &quot;https://YOUR_SERVER_IP&quot;<br>opensearch_security.openid.verify_hostnames: false<br>EOF</pre><p>Step 10 — Add OpenID Auth Domain to Wazuh Indexer</p><pre># Backup first<br>sudo cp /etc/wazuh-indexer/opensearch-security/config.yml \<br>        /etc/wazuh-indexer/opensearch-security/config.yml.bak<br><br># Add openid_auth_domain block using Python<br>sudo python3 &lt;&lt; &#39;PYEOF&#39;<br>with open(&#39;/etc/wazuh-indexer/opensearch-security/config.yml&#39;,&#39;r&#39;) as f:<br>    content = f.read()<br><br>if &#39;openid_auth_domain&#39; in content:<br>    print(&quot;Already exists!&quot;)<br>else:<br>    block = (<br>        &quot;      openid_auth_domain:\n&quot;<br>        &quot;        description: &#39;Authenticate via Keycloak OIDC&#39;\n&quot;<br>        &quot;        http_enabled: true\n&quot;<br>        &quot;        transport_enabled: true\n&quot;<br>        &quot;        order: 0\n&quot;<br>        &quot;        http_authenticator:\n&quot;<br>        &quot;          type: openid\n&quot;<br>        &quot;          challenge: false\n&quot;<br>        &quot;          config:\n&quot;<br>        &quot;            subject_key: preferred_username\n&quot;<br>        &quot;            roles_key: roles\n&quot;<br>        &quot;            openid_connect_url: &#39;http://YOUR_SERVER_IP:8080/realms/wazuh/.well-known/openid-configuration&#39;\n&quot;<br>        &quot;        authentication_backend:\n&quot;<br>        &quot;          type: noop\n&quot;<br>    )<br>    new = content.replace(<br>        &#39;      kerberos_auth_domain:&#39;,<br>        block + &#39;      kerberos_auth_domain:&#39;,<br>        1<br>    )<br>    with open(&#39;/etc/wazuh-indexer/opensearch-security/config.yml&#39;,&#39;w&#39;) as f:<br>        f.write(new)<br>    print(&quot;Done!&quot;)<br>PYEOF<br><br># Validate YAML<br>sudo python3 -c &quot;import yaml; yaml.safe_load(open(&#39;/etc/wazuh-indexer/opensearch-security/config.yml&#39;))&quot; &amp;&amp; echo &quot;YAML OK!&quot;</pre><p>Step 11 — Map Users to Wazuh Roles</p><pre>sudo python3 &lt;&lt; &#39;PYEOF&#39;<br>with open(&#39;/etc/wazuh-indexer/opensearch-security/roles_mapping.yml&#39;,&#39;r&#39;) as f:<br>    content = f.read()<br><br># Map admin to all_access<br>content = content.replace(<br>    &#39;  users: []\n  and_backend_roles: []\n  description: &quot;Maps admin to all_access&quot;&#39;,<br>    &#39;  users:\n  - &quot;admin&quot;\n  and_backend_roles: []\n  description: &quot;Maps admin to all_access&quot;&#39;<br>)<br><br># Map psy9 to readall<br>content = content.replace(<br>    &#39;readall:\n  reserved: true\n  hidden: false\n  backend_roles:\n  - &quot;readall&quot;\n  hosts: []\n  users: []&#39;,<br>    &#39;readall:\n  reserved: true\n  hidden: false\n  backend_roles:\n  - &quot;readall&quot;\n  hosts: []\n  users:\n  - &quot;psy9&quot;&#39;<br>)<br><br># Map psy9 to kibana_user<br>content = content.replace(<br>    &#39;kibana_user:\n  reserved: false\n  hidden: false\n  backend_roles:\n  - &quot;kibanauser&quot;\n  hosts: []\n  users: []&#39;,<br>    &#39;kibana_user:\n  reserved: false\n  hidden: false\n  backend_roles:\n  - &quot;kibanauser&quot;\n  hosts: []\n  users:\n  - &quot;psy9&quot;&#39;<br>)<br><br>with open(&#39;/etc/wazuh-indexer/opensearch-security/roles_mapping.yml&#39;,&#39;w&#39;) as f:<br>    f.write(content)<br>print(&quot;Done!&quot;)<br>PYEOF</pre><p>Step 12 — Apply Security Configuration</p><pre>export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64<br><br>sudo /usr/share/wazuh-indexer/plugins/opensearch-security/tools/securityadmin.sh \<br>  -cd /etc/wazuh-indexer/opensearch-security/ \<br>  -icl -nhnv \<br>  -cacert /etc/wazuh-indexer/certs/root-ca.pem \<br>  -cert /etc/wazuh-indexer/certs/admin.pem \<br>  -key /etc/wazuh-indexer/certs/admin-key.pem</pre><p>Step 13 — Restart Everything and Set Firewall</p><pre>sudo systemctl restart wazuh-indexer<br>sudo systemctl restart wazuh-dashboard<br>sudo systemctl restart keycloak<br>sudo systemctl reload nginx<br><br># IMPORTANT: Allow SSH before enabling UFW!<br>sudo ufw allow 22/tcp<br>sudo ufw allow 443/tcp<br>sudo ufw allow 80/tcp<br>sudo ufw deny 5601<br>sudo ufw deny 8080<br>sudo ufw --force enable<br><br># Verify<br>sleep 20 &amp;&amp; sudo ss -tlnp | grep -E &quot;443|5601|8080|9200&quot;</pre><p>Step 14 — Test the Login Flow</p><p>Open your browser and go to:</p><pre>https://YOUR_SERVER_IP</pre><p>Here’s what happens:</p><ol><li>✅ Browser hits Nginx on port 443</li><li>✅ Nginx forwards to Wazuh Dashboard on port 5601</li><li>✅ Dashboard redirects to Keycloak login page</li><li>✅ Enter username and password</li><li>✅ Keycloak shows QR code — scan with Google Authenticator</li><li>✅ Enter 6-digit TOTP code</li><li>✅ Keycloak issues token, dashboard loads with correct permissions</li></ol><p>Troubleshooting:</p><ul><li><strong>502 Bad Gateway</strong> — Check sudo ss -tlnp | grep 5601 to ensure the dashboard is running</li><li><strong>401 Unauthorized</strong> — Verify that the client_secret in opensearch_dashboards.yml is correct</li><li><strong>Realm does not exist</strong> — Create the <em>wazuh</em> realm in Keycloak first</li><li><strong>Client not found</strong> — Create the <em>wazuh-dashboard</em> client with the exact same ID</li><li><strong>No permissions</strong> — Add the user to roles_mapping.yml and run securityadmin.sh</li><li><strong>TOTP not showing</strong> — Set defaultAction=true for CONFIGURE_TOTP in Keycloak</li><li><strong>SSH locked out</strong> — Always run sudo ufw allow 22/tcp before enabling UFW</li><li><strong>YAML error</strong> — Restore backup using sudo cp config.yml.bak config.yml</li></ul><h3>Key Lessons Learned</h3><ol><li><strong>Always allow SSH before enabling UFW</strong> — or you’ll lock yourself out</li><li><strong>Use Python scripts</strong> to edit YAML files — not tee or manual editing</li><li><strong>Keycloak realm must exist</strong> before starting Wazuh Dashboard with OIDC config</li><li><strong>proxy_pass must match</strong> — use https:// if Wazuh Dashboard uses HTTPS</li><li><strong>Case sensitivity matters</strong> — PSY9 and psy9 are different users</li><li><strong>VPN blocks ports</strong> — use SSH tunneling or CLI tools instead of browser</li></ol><h3>Final Result</h3><ul><li>✅ Wazuh Dashboard secured with 2FA</li><li>✅ Admin user with full access</li><li>✅ Read-only user with restricted access</li><li>✅ Google Authenticator TOTP on every login</li><li>✅ Keycloak as enterprise SSO provider</li><li>✅ Nginx handling SSL termination</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59eb4b3db41c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>