<?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 Arasy Dafa Sulistya Kurniawan on Medium]]></title>
        <description><![CDATA[Stories by Arasy Dafa Sulistya Kurniawan on Medium]]></description>
        <link>https://medium.com/@arasydafa?source=rss-c1ddee6ca906------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*9BVjOqETpJAjuFoqc9-bug.png</url>
            <title>Stories by Arasy Dafa Sulistya Kurniawan on Medium</title>
            <link>https://medium.com/@arasydafa?source=rss-c1ddee6ca906------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 10:12:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arasydafa/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[How I route SSH inside the kernel with SOCKMAP]]></title>
            <link>https://medium.com/@arasydafa/how-i-route-ssh-inside-the-kernel-with-sockmap-4d102aade0e3?source=rss-c1ddee6ca906------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d102aade0e3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[ebpf]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Arasy Dafa Sulistya Kurniawan]]></dc:creator>
            <pubDate>Fri, 09 Oct 2026 04:12:50 GMT</pubDate>
            <atom:updated>2026-10-09T04:14:53.790Z</atom:updated>
            <content:encoded><![CDATA[<p>I wanted port 22 to sort clients by banner before userspace woke up</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HUuRYR3_2SyTHeXYPFbYYA.jpeg" /><figcaption>In-kernel SSH routing with SOCKMAP</figcaption></figure><p>02:14 on a Tuesday. I was tailing logs on a test box running 5.15.0–91. The same lines kept scrolling.</p><pre>SSH-2.0-Hydra v9.5<br>SSH-2.0-libssh_0.10.6<br>SSH-2.0-Go<br>SSH-2.0-OpenSSH_9.3p1<br>SSH-2.0-PuTTY_Release_0.78</pre><p>One port got dialed hundreds of times per hour with different strings. I had a proxy that could split them, it worked but I did not like it. Each packet took two trips through userspace for a call that only needed the first 15 bytes.</p><h3>1. What port 22 looks like when you watch it</h3><p>Leave :22 open and the pattern shows fast. Some strings come from automated tools. Some come from interactive clients people use daily. Some are old strings humans rarely run now but still show up in scans.</p><p>The banner is cleartext. RFC 4253 says both sides send SSH-2.0-&lt;client&gt; before key exchange. I only read that hello, but the backend behind still does the real handshake. I decrypt nothing.</p><p>In my setup :22 is only the entry. The final call follows a policy file in userspace. That file can change without reloading the BPF program. Admin access lives on a separate port the filter never sees. I locked myself out once and I keep that backdoor now.</p><h3>2. Why the proxy and XDP did not fit</h3><p>My first version was Python, accept on :22, peek with MSG_PEEK. Dial the matching backend, then splice until close.</p><p>It passed tests. But TCP state doubled for each session. The extra hop lived as long as the session lived. During a scan burst the proxy burned CPU moving bytes it had already judged.</p><p>I tried XDP next because examples are everywhere. It runs too early. You get raw packets before TCP reassembly. To find SSH-2.0- you have to handle retransmits and order yourself. I wrote half of that and deleted it.</p><p>TC clsact can see payload after the stack. But moving to another local socket means manual header rewrites. That felt fragile for work that should be one call.</p><p>SK_SKB with SOCKMAP fit. It runs after TCP has built the stream. You get stream bytes. You return a verdict. Call bpf_sk_redirect_map and the kernel hands the stream to another socket with no copy. TCP stays valid, encryption stays valid, and you never break the connection.</p><p>I use two slots. Slot 0 points at backend A, while slot 1 points at backend B. Fixed targets take fixed indexes.</p><h3>3. The two programs I load</h3><p>SK_SKB always comes as a pair. That confused me for a week.</p><p>The parser answers one question. How many bytes should pile up before I get called back.</p><pre>SEC(&quot;sk_skb/stream_parser&quot;)<br>int ssh_parser(struct __sk_buff *skb) {<br>    return skb-&gt;len;<br>}</pre><p>I ask for everything. The kernel buffers across segments. If the banner arrives split in two packets the verdict still sees one full line. I thought about scanning to newline to save bytes. I kept it simple.</p><p>The verdict does the work.</p><pre>SEC(&quot;sk_skb/stream_verdict&quot;)<br>int ssh_router(struct __sk_buff *skb) {<br>    __u8 banner[15];<br>    if (bpf_skb_load_bytes(skb, 0, banner, 15) &lt; 0)<br>        return SK_PASS;<br>    if (banner[0] != &#39;S&#39; || banner[1] != &#39;S&#39; || banner[2] != &#39;H&#39; ||<br>        banner[3] != &#39;-&#39; || banner[4] != &#39;2&#39; || banner[5] != &#39;.&#39; ||<br>        banner[6] != &#39;0&#39; || banner[7] != &#39;-&#39;)<br>        return SK_PASS;<br>    int verdict = classify_client(banner + 8, 7);<br>    __u32 idx = (__u32)verdict;<br>    return bpf_sk_redirect_map(skb, &amp;sock_map, idx, 0);<br>}</pre><p>Here you have to use bpf_skb_load_bytes. Direct access does not work. If the read fails I pass. If the magic is missing I pass. Random probes and health checks should fall through. Only SSH gets steered. The plus 8 skips the constant part so classification sees only the client id.</p><h3>4. How I match banners with no regex</h3><p>BPF has no string lib. I keep policy in a map and keep code dumb.</p><p>One SOCKMAP with 2 entries. One HASH with 32 entries for prefix to action. One ARRAY with 1 entry for the default.</p><p>The classifier tries long to short. It checks 7 bytes, then 6, down to 1. First hit wins. Misses follow the default. If that was never set it follows slot 0. I chose fail closed so unknown connects do not slip through quietly.</p><p>My policy file format is plain. Prefix, action, description. The loader parses that file then fills the HASH with bpf_map_update_elem. A new string needs no BPF reload. That split saved a lot of time.</p><p>For version edge cases I do not trust exact prefix alone. Some clients share a prefix with very different versions. I added a small version check in kernel and in the Python fallback. The result still follows the action from policy. So the target is not hardcoded in code.</p><p>The loader builds the object with clang, creates the two backend sockets and puts their fds into the map, fills the HASH, sets the default, then attaches both programs to :22. After that the fast path stays in kernel. Python only tails logs.</p><p>I test with netcat before real clients.</p><pre>nc -l 2201 &amp;<br>nc -l 2202 &amp;<br>echo &quot;SSH-2.0-EXAMPLE_test&quot; | nc 127.0.0.1 22</pre><p>You see it change slots without breaking. Then I move to real ssh tests.</p><h3>5. How the verifier said no and what I kept</h3><p>Three rejections I remember.</p><p>My map key had stack garbage left in it. Load refused. Now I zero each key on declaration and I clear it each loop.</p><p>My loop bound was a variable. The verifier could not prove it ends. I rewrote it as a fixed 16 iteration loop with a guard inside. That loaded.</p><p>I forgot memlock rlimit and got EPERM with nothing useful on stdout. Dmesg held the real error. Now I set RLIMIT_MEMLOCK to infinity at startup and I check uname -r first. You want 5.10 or newer for full redirect support. I run 5.15.</p><p>Decision cost sits under a microsecond per new connect in my tests. Steady state is close to nothing. After redirect the bytes move socket to socket without waking the loader. Memory is three small maps.</p><p>What I dislike. Exact prefix cannot do fuzzy matches. Spoofing a string is easy. Banner routing is triage. It is not auth. Keep rate limits and normal sshd hardening in place.</p><p>I log timestamp, source IP and port, first 32 bytes of banner, verdict. I graph verdict counts. Spikes line up with scan waves. The first week gave me 5 strings I had never seen. I added them to the file.</p><p>If you build this, start narrow. One box. Clang 14 or newer. Pin maps under /sys/fs/bpf so restarts keep policy. Keep the policy file in git. Code is about 250 lines with headers. The change that mattered most for me was moving the hook to where TCP already hands me a stream instead of fighting packets too early.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d102aade0e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[File Integrity Monitoring Best Practices with Wazuh: A Theoretical Perspective]]></title>
            <link>https://medium.com/@arasydafa/file-integrity-monitoring-best-practices-with-wazuh-a-theoretical-perspective-b74fe577f1f7?source=rss-c1ddee6ca906------2</link>
            <guid isPermaLink="false">https://medium.com/p/b74fe577f1f7</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[file-integrity-monitoring]]></category>
            <dc:creator><![CDATA[Arasy Dafa Sulistya Kurniawan]]></dc:creator>
            <pubDate>Wed, 12 Nov 2025 04:16:17 GMT</pubDate>
            <atom:updated>2026-10-09T04:17:02.856Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33F61NVu9hLFOQ1dPGbFUQ.jpeg" /><figcaption>An abstract representation of securing digital assets and maintaining compliance baselines</figcaption></figure><p>Have you ever wondered how something as simple as keeping an eye on your files could become a game changer in cybersecurity? In an era where data breaches make headlines every other week, File Integrity Monitoring (FIM) isn’t just a feature, it’s like having a quiet guardian that notices when something feels off.</p><p>As we step deeper into 2025, with threats evolving faster than ever, understanding how FIM fits into modern security feels more critical than ever. In this piece, we’ll explore the theoretical side of FIM, how it connects to real-world practices, and how open source platforms like Wazuh bring it to life, especially in today’s dynamic environments like cloud and containers.</p><p>Picture this, cyberattacks are spiking, and organizations are constantly playing catch-up. The FIM market alone is expected to jump from about $1.2 billion in 2025 to $3.8 billion by 203, growing at a steady 13.6% CAGR. Why that big? Because FIM isn’t just about detecting changes, it’s about weaving trust into your operations, building visibility where it matters most.</p><p>This article takes a theoretical approach, connecting timeless FIM principles to modern movements like AI driven DevSecOps and evolving standards such as PCI DSS 4.0. No setup commands or YAML files here, just the “why” and “how” behind what makes FIM so essential.</p><h3>What is File Integrity Monitoring (FIM)?</h3><p>Let’s keep it straightforward. FIM is a security mechanism that monitors changes to files and directories, notifying you when any unexpected changes occur. It operates by assessing the existing status of a file against a reliable baseline, looking at hashes, permissions, timestamps, even file sizes.</p><p>It’s not about observing every file on your system, it’s about concentrating on those that are most important. Consider configuration files that regulate system functions or databases that could turn into treasure troves for hackers.</p><p>In the current hybrid, remote first environment, FIM has expanded beyond merely being an isolated control. It has become an essential element of the DevSecOps framework, assisting teams in incorporating integrity checks into CI/CD processes. It has also turned into a vital aspect of governance and compliance, particularly with the introduction of PCI DSS 4.0, which enhances the requirement for ongoing monitoring and integrity verification.</p><p>FIM endorses both aspects, ensuring every file modification adheres to policy and aids in demonstrating compliance during audits. In containerized environments, it also aids in checking image integrity and runtime stability without slowing down your setup.</p><p>Wazuh, as an open source solution with flexibility, enhances this concept. It eases the process of monitoring endpoints and servers, allowing you to uphold baselines and receive alerts without significant effort. Envision detecting an unforeseen configuration change before it escalates into a major incident, this is where FIM demonstrates its worth</p><h3>Conceptual Workflow of FIM in Wazuh</h3><p>If you’ve ever installed a home security system, you understand the basic idea. You define what “<strong><em>normal</em></strong>” looks like and then observe for any anomalies that may arise.</p><p>FIM works the same way. It starts with a baseline scan that captures file attributes like checksums, permissions, and ownership. From there, it continuously compares the live state against that baseline, in real time or on a schedule. Any changes triggers an alert with details about what changed, when, and by whom.</p><p>Nonetheless, modern arrangements exhibit increased intricacy. Criteria evolve. They are not static images but rather adaptable references that evolve as systems update or settings change. In a DevSecOps setting, FIM can integrate smoothly into CI/CD pipelines, automatically adjusting baselines after authorized deployments.</p><p>From a governance sight, policies define how these standards are maintained, who evaluates them, how often reviews occur, and the procedure for handling exceptions. Compliance frameworks like PCI DSS 4.0 emphasize the need for continuous visibility, underscoring that every change must be monitored and justified.</p><p>FIM adapts to temporary environments for containers, maintaining image integrity and monitoring runtime without burdening you with excessive noise. Wazuh handles this skillfully, aligning agent data with its main manager and efficiently preserving metadata for quick searches and correlations.</p><p>The result? When a change takes place, you’re not just informed, but you also obtain enriched context that links the event to user activities, vulnerability details, and identified threat trends.</p><h3>Theoretical Best Practices for FIM in Wazuh</h3><p>To make the most out of FIM in Wazuh, it helps to follow a few guiding principles, not strict rules, but frameworks to adapt to your setup.</p><h4>1. Prioritize Critical Assets</h4><p>Concentrate your observation on what matters. Begin with system configurations, credentials, and sensitive data. Link this to governance policies that categorize assets according to their business influence. Wazuh allows you to adjust paths and depth levels, optimizing efficiency while preserving visibility.</p><h4>2. Establish and Maintain Baselines</h4><p>Your baseline establishes what is normal. Maintain freshness and review it frequently. In the evolving threat landscape of 2025, baselines need to adapt via DevSecOps automation, refined as trusted modifications are implemented. Wazuh’s database synchronization facilitates this process seamlessly, even in containerized settings.</p><h4>3. Balance Monitoring Modes and Frequency</h4><p>Not every file requires immediate verification. Integrate real time oversight for essential systems with planned evaluations for less risky zones. Establish policies according to risk tolerance and regulatory obligations. Wazuh’s adaptable settings assist in achieving the ideal balance between alertness and efficiency.</p><h4>4. Integrate Responsibility and Detail</h4><p>Understanding what changed is only part of the narrative, recognizing who made the change completes it. Wazuh’s who-data functionality records user and process information for each change, aiding in forensic investigation and detection of insider threats.</p><h4>5. Manage Alert Relevance and Reduce False Positives</h4><p>Nothing kills a security team’s motivation faster than noise. Tune your rules to ignore expected system changes while flagging anomalies that matter. Wazuh’s custom rules make this straightforward, even in container heavy environments where transient activity is common.</p><h4>6. Integrate with Larger Ecosystems</h4><p>FIM should feed your entire security ecosystem. Connect it to your SIEM, threat intelligence, or vulnerability management platforms. Wazuh’s correlation engine connects the dots automatically, giving you the full story instead of isolated events.</p><h4>7. Coordinate with Compliance and Change Management</h4><p>Each monitored change can act as evidence of oversight for evaluations. Align FIM data with frameworks such as PCI DSS 4.0 and ISO 27001, enhancing compliance and accountability.</p><h4>8. Optimize Performance and Scalability</h4><p>As your infrastructure expands, so must your FIM strategy. Wazuh’s tuning options let you scale efficiently, maintaining speed and reliability even across large, distributed environments.</p><h4>9. Apply FIM to Containerized Environments</h4><p>Finally, bring FIM into the container world. Use it to validate image integrity and detect runtime drift. Wazuh adapts smoothly here, giving visibility into short-lived resources without adding unnecessary friction.</p><h3>Conclusion</h3><p>FIM might not be the flashiest part of your security stack, but it’s one of the most foundational. In a world where every file could be a potential entry point, having continuous integrity validation isn’t optional, it’s essential.</p><p>As DevSecOps matures and governance becomes more data driven, tools like Wazuh bridge the gap between theory and practice. They turn the idea of “<strong><em>trust but verify</em></strong>” into something actionable and scalable.</p><p>If this ignited thoughts for your own arrangement, explore deeper, create, evaluate, and improve. Security in 2025 is not focused on quick solutions, but it’s about creating systems that adapt as rapidly as the threats they encounter</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b74fe577f1f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Wazuh Processes Logs: From Decoder to Rule Matching — Part 2]]></title>
            <link>https://medium.com/@arasydafa/how-wazuh-processes-logs-from-decoder-to-rule-matching-part-2-f971a9a750ec?source=rss-c1ddee6ca906------2</link>
            <guid isPermaLink="false">https://medium.com/p/f971a9a750ec</guid>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[detection-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Arasy Dafa Sulistya Kurniawan]]></dc:creator>
            <pubDate>Fri, 31 Oct 2025 11:41:34 GMT</pubDate>
            <atom:updated>2026-10-09T04:22:44.327Z</atom:updated>
            <content:encoded><![CDATA[<h3>How Wazuh Processes Logs: From Decoder to Rule Matching — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3g4KIlRqdNcM5C5lJ--UJQ.png" /></figure><h3>Picking Up Where We Left Off</h3><p>In <a href="https://medium.com/@arasydafa/how-wazuh-processes-logs-from-decoder-to-rule-matching-6c40d4dc1b21">Part 1</a>, we went under the hood of Wazuh to explore its architecture, the daemons that make up its engine room and how raw logs are decoded and matched against rules.</p><p>Now, in this second part, we’re going practical:</p><ol><li><strong>Follow a single log</strong> as it travels through the entire Wazuh pipeline, from collection, decoding, and rule matching to the final alert you see in the dashboard.</li><li><strong>Write your own decoder and rule</strong> for a custom internal application, so Wazuh can detect suspicious behavior unique to your environment.</li></ol><p>If Part 1 was about understanding the <em>theory</em>, Part 2 is about seeing it <em>in action</em>.</p><h3>A Real Log Journey: From Input to Alert</h3><p>To make all the concepts from Part 1 tangible, let’s trace one log through Wazuh, step by step from the moment it’s generated on a server to the alert you see in the dashboard.</p><h4>Scenario</h4><p>You’re monitoring a Linux server (webserver-1) with the Wazuh agent installed. Suddenly, someone tries to brute-force SSH access using invalid credentials. How does Wazuh pick this up and escalate it?</p><h4>Raw Log Appears</h4><p>The server writes this to /var/log/auth.log:</p><pre>Jul 2 09:50:15 database-server sshd[12345]: Failed password for invalid user admin from 192.168.1.10 port 41001 ssh2</pre><p><strong>Step 1 — </strong>Collected by wazuh-logcollector</p><ul><li>The Wazuh agent’s wazuh-logcollector notices a new line in /var/log/auth.log.</li><li>It reads the log and forwards it to the Wazuh manager’s wazuh-analysisd.</li></ul><blockquote><em>Daemon in play:</em> wazuh-logcollector (agent)</blockquote><p><strong>Step 2— </strong>Decoded by wazuh-analysisd</p><ul><li>On the Wazuh manager, wazuh-analysisd runs the sshd decoder.</li><li>Extracted fields:<br>- program: sshd<br>- action: Failed password<br>- user: admin<br>- srcip: 192.168.1.10</li></ul><blockquote><em>Daemon in play:</em> wazuh-analysisd (manager)</blockquote><p><strong>Step 3 — </strong>Rule Matching</p><ul><li>Rule 1005 (single SSH failure) matches → alert level 5.</li><li>Wazuh manager writes this to alerts.json.</li></ul><blockquote><em>Daemon in play:</em> wazuh-analysisd</blockquote><p><strong>Step 4 — </strong>Chained Rule Fires</p><ul><li>Within 60 seconds, the same IP fails 6 times.</li><li>Rule 5710 (multiple failures) triggers:<br>- Group: brute_force<br>- Alert level: 10<br>- Optional: triggers wazuh-execd to block the IP</li></ul><blockquote><em>Daemons in play:</em> wazuh-analysisd, wazuh-execd</blockquote><p><strong>Step 5 — </strong>Alert Output</p><p>Final alert in json format:</p><pre>{<br>  ...<br>  &quot;data&quot;: {<br>    &quot;srcip&quot;: &quot;192.168.1.10&quot;,<br>    &quot;dstuser&quot;: &quot;admin&quot;,<br>    &quot;srcport&quot;: &quot;41001&quot;<br>  }<br>  &quot;rule&quot;: {<br>    &quot;level&quot;: 10,<br>    &quot;id&quot;: 5710,<br>    &quot;description&quot;: &quot;sshd: authentication failed.&quot;,<br>    &quot;groups&quot;: [<br>        &quot;syslog&quot;,<br>        &quot;sshd&quot;,<br>        &quot;authentication_failed&quot;<br>      ]<br>  },<br>  &quot;agent&quot;: {<br>    &quot;name&quot;: &quot;database-server&quot;,<br>    &quot;id&quot;: &quot;004&quot;<br>  },<br>  &quot;full_log&quot;: &quot;Jul 2 09:50:15 database-server sshd[12345]: Failed password for invalid user admin from 192.168.1.10 port 41001 ssh2&quot;<br>  ...<br>}</pre><ul><li>Saved in /var/ossec/logs/alerts/alerts.json .</li><li>Forwarded via Filebeat to the Wazuh Indexer and dashboard.</li></ul><blockquote><em>Daemons in play:</em> filebeat, wazuh-indexer</blockquote><p><strong>Step 6 — </strong>Visualized</p><p>The alert now shows up in the Wazuh dashboard under “Security Events.” If you’ve integrated Slack, TheHive, or SIEM tools, wazuh-integratord forwards it there too.</p><p><strong>Step 7 — </strong>Archives</p><p>All raw logs (even ones that didn’t trigger a rule) are stored in:</p><pre>/var/ossec/logs/archives/archives.json</pre><p>Compressed, signed, and ready for forensic review.</p><p><em>At this point, we’ve gone through the full lifecycle of a log inside Wazuh, from raw input to actionable alert.</em></p><h3>Writing Custom Rules &amp; Decoders: Tailoring Wazuh to Your Environment</h3><p>So far, we’ve seen how Wazuh handles system logs like SSH failures. But what if you have a <strong>custom application</strong> that logs important events you want to monitor?</p><p>Here’s how you can make Wazuh understand and alert on them.</p><h4>Scenario: Internal App Login Failures</h4><p>Imagine an internal web app emits logs like this:</p><pre>{<br>  &quot;event&quot;: &quot;login_attempt&quot;,<br>  &quot;status&quot;: &quot;failed&quot;,<br>  &quot;user&quot;: &quot;john.doe&quot;,<br>  &quot;ip&quot;: &quot;10.0.0.5&quot;,<br>  &quot;timestamp&quot;: &quot;2025-07-01T10:15:30Z&quot;<br>}</pre><p>You want Wazuh to detect <strong>multiple failed login attempts</strong> and alert your security team.</p><p><strong>Step 1 — </strong>Create a Custom Decoder</p><ul><li>Create a new file in:</li></ul><pre>/var/ossec/etc/decoders/local_decoder.xml</pre><ul><li>Add a JSON decoder for your app:</li></ul><pre>&lt;decoder name=&quot;json&quot;&gt;<br>    &lt;prematch&gt;^{\s*&quot;&lt;/prematch&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;plugin_decoder&gt;JSON_Decoder&lt;/plugin_decoder&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;regex type=&quot;pcre2&quot;&gt;&quot;event&quot;:&quot;([^&quot;]+)&quot;&lt;/regex&gt;<br>    &lt;order&gt;event&lt;/order&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;regex type=&quot;pcre2&quot;&gt;&quot;status&quot;:&quot;([^&quot;]+)&quot;&lt;/regex&gt;<br>    &lt;order&gt;status&lt;/order&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;regex type=&quot;pcre2&quot;&gt;&quot;user&quot;:&quot;([^&quot;]+)&quot;&lt;/regex&gt;<br>    &lt;order&gt;user&lt;/order&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;regex type=&quot;pcre2&quot;&gt;&quot;ip&quot;:&quot;([^&quot;]+)&quot;&lt;/regex&gt;<br>    &lt;order&gt;ip&lt;/order&gt;<br>&lt;/decoder&gt;<br><br>&lt;decoder name=&quot;custom-login-json&quot;&gt;<br>    &lt;parent&gt;json&lt;/parent&gt;<br>    &lt;regex type=&quot;pcre2&quot;&gt;&quot;timestamp&quot;:&quot;([^&quot;]+)&quot;&lt;/regex&gt;<br>    &lt;order&gt;timestamp&lt;/order&gt;<br>&lt;/decoder&gt;</pre><ul><li>Each &lt;regex&gt; extracts a field from the JSON log.</li><li>order defines the key used in rules.</li></ul><p><strong>Step 2— </strong>Create a Custom Rule</p><ul><li>Create a new file in:</li></ul><pre>/var/ossec/etc/rules/local_rules.xml</pre><ul><li>Add a custom rule for your app:</li></ul><pre>&lt;group name=&quot;custom_app, login_failure&quot;&gt;<br>  &lt;!-- single failed login --&gt;<br>  &lt;rule id=&quot;100100&quot; level=&quot;5&quot;&gt;<br>    &lt;decoded_as&gt;custom-login-json&lt;/decoded_as&gt;<br>    &lt;match&gt;failed&lt;/match&gt;<br>    &lt;description&gt;Failed login attempt in internal app&lt;/description&gt;<br>  &lt;/rule&gt;<br><br>  &lt;!-- multiple failed logins from same IP --&gt;<br>  &lt;rule id=&quot;100101&quot; level=&quot;10&quot; timeframe=&quot;120&quot; ignore=&quot;30&quot; frequency=&quot;5&quot;&gt;<br>    &lt;if_sid&gt;100100&lt;/if_sid&gt;<br>    &lt;description&gt;Multiple failed login attempts from same IP&lt;/description&gt;<br>  &lt;/rule&gt;<br>&lt;/group&gt;</pre><ul><li>Rule 100100 matches <strong>any single failed login</strong>.</li><li>Rule 100101 triggers when <strong>5 failures occur within 2 minutes</strong>, producing a high-level alert. To prevent floods, it is <strong>ignored for 30 seconds</strong> after triggering.</li></ul><p><strong>Step 3 — </strong>Test Your Custom Decoder and Rule</p><p>Use wazuh-logtest to verify:</p><pre>cat app_log.json | /var/ossec/bin/wazuh-logtest</pre><ul><li>Check which decoder matched.</li><li>Confirm the rule fired as expected.</li><li>Fix any regex or mapping issues before deploying.</li></ul><p><strong>Step 4 — </strong>Watch Alerts in Action</p><ul><li>Alerts appear in /var/ossec/logs/alerts/alerts.json.</li><li>Forwarded via Filebeat to Wazuh Indexer and displayed on the dashboard.</li></ul><blockquote>Optional: integrate with wazuh-integratord to push alerts to Slack, TheHive, Discord, or your SIEM.</blockquote><h4>Tips</h4><ul><li>Keep decoder and rule names clear and consistent.</li><li>Start simple, then add chaining/frequency rules.</li><li>Test with wazuh-logtest for accuracy.</li><li>Consider Active Responses for high-risk log types.</li></ul><h3>Wrapping Up</h3><p>In this second part, we traced a log from its creation on a server to a completely actionable alert in Wazuh. We also examined ways to enhance Wazuh’s functionality by developing custom decoders and rules for your specific applications, allowing for detection customized to your setting.</p><p>With this knowledge, you can not only understand what happens behind the scenes for every alert and also take initiative to develop new detections for the events that are most significant to your organization.</p><p>It’s your turn now: try out custom rules, evaluate them with wazuh-logtest, and begin developing more intelligent alerts for your infrastructure.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f971a9a750ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Wazuh Processes Logs: From Decoder to Rule Matching — Part 1]]></title>
            <link>https://medium.com/@arasydafa/how-wazuh-processes-logs-from-decoder-to-rule-matching-6c40d4dc1b21?source=rss-c1ddee6ca906------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c40d4dc1b21</guid>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[detection-engineering]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Arasy Dafa Sulistya Kurniawan]]></dc:creator>
            <pubDate>Tue, 08 Jul 2025 05:59:56 GMT</pubDate>
            <atom:updated>2026-10-09T04:22:22.169Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3g4KIlRqdNcM5C5lJ--UJQ.png" /></figure><p>If you’ve spent any time with Wazuh, you’ve probably seen those alerts lighting up your dashboard, maybe a suspicious login attempt, a file that suddenly changed, or even early signs of malware. They look polished and helpful on the surface, but have you ever wondered how does Wazuh actually know something’s wrong?</p><p>Each of those alerts comes from a behind-the-scenes process that’s surprisingly sophisticated. Wazuh doesn’t just magically understand logs, it runs them through a pipeline that transforms raw, messy log data into something structured and actionable. And understanding how that transformation works isn’t just nerdy curiosity, it’s genuinely useful. It helps you debug issues faster, write smarter detection rules, and cut down on noisy false positives.</p><p>In this article, we’re going to take a different approach. Instead of jumping straight into theory, we’ll follow a single log from the moment it enters Wazuh. We’ll trace how it flows through the system, through different daemons, decoders, and rule engines, until it either triggers an alert or gets silently discarded.</p><p>Along the way, we’ll break down Wazuh’s architecture, explain what each component is responsible for, and walk through a real-world use case to make it all more concrete.</p><p>Ready? Let’s go under the hood.</p><h3><strong>From Agents to Alerts: The Big Picture</strong></h3><p>Before diving into the inner workings of each component, it helps to first understand the big picture, the full journey of a log message inside Wazuh. At its core, Wazuh works like this:</p><ol><li>A log is generated by an endpoint, server, or network device.</li><li>The Wazuh agent (or agentless collector) picks up the log and sends it to the Wazuh server.</li><li>The server decodes the log to turn it into structured data.</li><li>Rules are applied to see if the log matches any known threat patterns or behaviors.</li><li>If matched, an alert is generated and stored or forwarded for visualization.</li></ol><p>Here’s a simplified version of that pipeline.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*zcjJF9mjrVuE4mJn9fmwtQ.png" /></figure><p>But that’s just scratching the surface. Depending on your setup, logs can came from:</p><ul><li>Wazuh agents running on endpoints</li><li>Agentless sources like firewalls or switches</li><li>Cloud, containers, or even vulnerability scans</li></ul><p>Once collected, the logs go through decoding, enrichment, and rule matching, handled by a series of Wazuh daemons each with a specific job in the pipeline.</p><p>Some logs may not trigger any alerts. Assuming you have enabled the archiving option in ossec.conf and filebeat.yml on your Wazuh server, they are quietly stored in an archive (archives.json) for reference.. Others may match known malicious behaviors or policy violations, and those will be turned into structured alerts (alerts.json) that you’ll see in your Wazuh dashboard.</p><p>In larger deployments, alerts are sent via Filebeat using TLS encryption to the Wazuh Indexer (based on OpenSearch/Elasticsearch), where they can be queried, visualized, and used to trigger automated responses.</p><p>This entire process is highly modular, secure, and surprisingly customizable. And to fully understand it, we need to get to know the daemons that make it all happen.</p><h3>Meet the Daemons: Inside the Wazuh Engine Room</h3><p>Wazuh isn’t a single monolithic service, it’s a symphony of lightweight daemons, each playing a specialized role in the background. Together, they form the foundation of Wazuh’s log analysis pipeline. Knowing what each one does will not only help you troubleshoot issues faster but also give you more confidence when tuning or customizing the platform.</p><p>Let’s walk through the key daemons involved in log processing, grouped by their main responsibility.</p><h3>Log Collection &amp; Analysis Daemons</h3><h4>wazuh-logcollector – The Eyes</h4><p>This daemon is responsible for collecting log data from various sources: files, commands, syslog streams, container, and even more. Think of it as Wazuh’s eyes, constantly watching your systems for any new activity.</p><ul><li><strong>Runs on</strong>: Both agents and managers</li><li><strong>Typical input</strong>: /var/log/auth.log, journalctl, /var/log/audit/audit.logor custom paths</li><li><strong>Forwarded to</strong>: wazuh-analysisd for further processing</li></ul><blockquote>Use case:<em> If a Linux server writes an SSH login failure to </em><em>/var/log/secure, </em><em>logcollector will see it and pass it downstream.</em></blockquote><h4>wazuh-analysisd – The Brain</h4><p>This is the heart of Wazuh. Every log collected flows through analysisd, where decoding and rule matching happen. It parses logs into structured fields and checks them against a library of rules to determine whether they represent a potential threat.</p><ul><li><strong>Runs on</strong>: Manager only</li><li><strong>Functions</strong>: Decoding, rule evaluation, and alert generation</li><li><strong>Output</strong>: Logs to archives.json (everything) and alerts.json (only rule-matched)</li></ul><blockquote>Fun fact:<em> It can process thousands of events per second. If something feels “off” in your alerting, this is the first daemon to investigate.</em></blockquote><h4>wazuh-execd – The Enforcer</h4><p>Once an alert is triggered, sometimes you want more than just a notification, you want action. That’s where execd comes in. It handles <strong>Active Responses</strong>, like blocking an IP via firewall or running a script.</p><ul><li><strong>Runs on</strong>: Both agents and managers</li><li><strong>Triggered by</strong>: analysisd when a rule &lt;active-response&gt;</li><li><strong>Actions</strong>: Bash commands, system scripts, or even remote API calls</li></ul><h3>Enrichment &amp; System Intelligence</h3><h4>wazuh-modulesd – The Intelligence Layer</h4><p>This daemon manages internal modules that enrich your security visibility. Examples include vulnerability detection, rootkit checks, and CIS compliance scans.</p><ul><li><strong>Runs on</strong>: Both agents and managers</li><li><strong>Works with</strong>: System inventory, package versions, configuration files</li><li><strong>Feeds data to</strong>: wazuh-db, which stores enrichment context</li></ul><blockquote>Use case:<em> It periodically scans installed packages and cross-references them with CVE databases to alert on known vulnerabilities.</em></blockquote><h4>wazuh-db – The Memory Bank</h4><p>This internal database caches system details — like OS version, installed apps, vulnerabilities — and helps other daemons with quick lookups.</p><ul><li><strong>Runs on</strong>: Manager only</li><li><strong>Critical for</strong>: Enrichment, policy checks, and reporting modules</li></ul><h4>wazuh-reportd – The Reporter</h4><p>For compliance or periodic overviews, reportd lets you generate <strong>reports</strong> based on Wazuh alerts.</p><ul><li><strong>Output</strong>: Customizable reports via CSV, JSON, or other formats</li><li><strong>Ideal for</strong>: PCI-DSS, ISO 27001, or internal audits</li></ul><h3>Communication &amp; Integration</h3><h4>wazuh-agentd – The Local Spokesperson</h4><p>This runs on every endpoint (agent) and handles secure communication back to the Wazuh manager. It batches and forwards events, responds to requests, and ensures the agent is “alive”.</p><ul><li><strong>Runs on</strong>: Agent only</li><li><strong>Talks to</strong>: wazuh-remoted on the manager (usually via TCP 1514)</li></ul><h4>wazuh-authd – The Gatekeeper</h4><p>This daemon facilitates agent registration and key exchange. Without this, your agents can’t securely enroll with the Wazuh manager.</p><ul><li><strong>Listens on</strong>: Port 1515 by default</li><li><strong>Supports</strong>: Automatic registration</li></ul><h4>wazuh-remoted – The Listener</h4><p>This daemon sits on the manager and listens for incoming logs from agents. It’s the first stop for all external log traffic.</p><ul><li><strong>Decrypts and validates</strong>: Agent messages</li><li><strong>Forwards to</strong>: wazuh-analysisd</li></ul><h4>wazuh-clusterd – The Sync Master</h4><p>In multi-node deployments, clusterd syncs configurations, rules, agents, and logs between manager nodes.</p><ul><li><strong>Useful for</strong>: HA environments, load balancing, and backup managers</li><li><strong>Communicates via</strong>: Port 1516/TCP</li></ul><h4>wazuh-integratord – The Bridge</h4><p>This handles external integrations — such as pushing alerts to Slack, Jira, TheHive, and more.</p><ul><li><strong>Triggered by</strong>: Alert conditions</li><li><strong>Pluggable</strong>: You can create your own integration scripts</li></ul><h3>Alert Forwarding</h3><h4>wazuh-csyslogd &amp; wazuh-maild</h4><p>These daemons are for legacy or supplementary alert delivery.</p><ul><li>csyslogd: Sends alerts to a syslog receiver</li><li>maild: Sends alerts via email</li></ul><p>These are optional, as most production deployments prefer <strong>Filebeat → Indexer</strong> pipelines for alert delivery and storage.</p><h3>The Decoder Layer: From Chaos to Structure</h3><p>Logs are messy. They come in all shapes and formats, some are structured, some are free text, and others are weird hybrids written by software engineers in a hurry. For any security platform, parsing these logs into something usable is the first big challenge.</p><p>In Wazuh, this job falls to <strong>decoders</strong>.</p><h4>What’s a Decoder?</h4><p>A decoder is a set of instructions that tells Wazuh how to interpret a specific type of log. Think of it as a log translator: it takes an unstructured string and extracts key fields like srcip, user, program, action, and more.</p><p>Wazuh has hundreds of built-in decoders to handle common logs, SSH, sudo, Windows Event Logs, web servers, firewall logs, etc. You can find these in /var/ossec/etc/decoders .</p><p>Each decoder is typically a combination of regular expressions (for raw text) or JSON mappings (for structured logs).</p><h4>How Decoding Works (Under the Hood)</h4><p>Here’s a simplified view of what happens when a new log comes in:</p><ol><li><strong>The raw log</strong> is picked up by wazuh-logcollector.</li><li>It’s passed to wazuh-analysisd.</li><li>analysisd checks the log against all available decoders in order.</li><li>The <strong>first matching decoder wins</strong>.</li><li>If matched, extracted fields are saved for use by the rule engine.</li><li>If no decoder matches, the log is stored anyway (in archives.json), but no rule can trigger on it.</li></ol><h4>Example: SSH Failed Login</h4><p>Let’s walk through a real-world example. Say a server generates this log:</p><pre>Jul 2 09:50:15 database-server sshd[12345]: Failed password for invalid user admin from 192.168.1.10 port 41001 ssh2</pre><p>What happens next?</p><ol><li>Wazuh’s sshd decoder kicks in. It uses a regex to extract:</li></ol><ul><li>user: admin</li><li>srcip: 192.168.1.10</li><li>action: Failed password</li><li>port: 4455</li></ul><ol><li>These extracted fields are passed to the next stage, rule matching.</li><li>Now Wazuh can understand this log semantically, not just as a string.</li></ol><blockquote>Bonus:<em> You can test any decoder using </em><em>wazuh-logtest. It’s a CLI tool that simulates log parsing and tells you what decoder (if any) matched your input</em></blockquote><h4>Why This Matters</h4><p>Without a decoder, Wazuh sees your log as just a blob of text. It can’t analyze it, correlate it, or trigger any rule. That’s why good decoding is essential and why, if you’re working with custom applications or obscure log formats, you may need to write your own.</p><p>In fact, Wazuh supports:</p><ul><li><strong>Regex-based decoders</strong>: for plain text logs</li><li><strong>JSON decoders</strong>: for structured JSON logs (common with modern apps)</li><li><strong>Nested decoders</strong>: to handle logs that go through multiple layers (e.g., syslog → app → service)</li></ul><h3>Rule Matching: When Logs Meet Intelligence</h3><p>So now your log is decoded it’s no longer a jumble of text, but a structured event with fields like srcip, user, action, and program. What’s next?</p><p>This is where <strong>Wazuh’s rule engine</strong> kicks in.</p><p>Rules are Wazuh’s knowledge base. They define what “suspicious” looks like. From brute-force attempts and malware activity to privilege abuse or policy violations, rules allow Wazuh to match real-world threats against your decoded logs.</p><h4>What Is a Rule?</h4><p>A rule is a set of conditions that tells Wazuh:</p><blockquote><em>“If a decoded log matches this pattern, at this frequency, under these circumstances… raise an alert.”</em></blockquote><p>Each rule has a structure like this:</p><pre>&lt;rule id=&quot;5712&quot; level=&quot;10&quot; frequency=&quot;8&quot; timeframe=&quot;120&quot; ignore=&quot;60&quot;&gt;<br>    &lt;if_matched_sid&gt;5710&lt;/if_matched_sid&gt;<br>    &lt;description&gt;sshd: brute force trying to get access to &lt;/description&gt;<br>    &lt;description&gt;the system.&lt;/description&gt;<br>    &lt;mitre&gt;<br>      &lt;id&gt;T1110&lt;/id&gt;<br>    &lt;/mitre&gt;<br>    &lt;same_source_ip /&gt;<br>    &lt;group&gt;authentication_failures,pci_dss_11.4,pci_dss_10.2.4,pci_dss_10.2.5,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_SI.4,nist_800_53_AU.14,nist_800_53_AC.7,tsc_CC6.1,tsc_CC6.8,tsc_CC7.2,tsc_CC7.3,&lt;/group&gt;<br>  &lt;/rule&gt;</pre><p>This rule means:</p><ul><li>If we’ve already seen a log that matches rule 5710 .</li><li>And this happens <strong>8 times within 120 seconds, but it is ignored for 60 seconds after triggering</strong>.</li><li>Then raise alert 5712 with level 10.</li></ul><h4>Rule Chaining (The Power of if_sid)</h4><p>One of Wazuh’s secret weapons is <strong>rule chaining, </strong>using if_sid to link rules together into a sequence.</p><p>Here’s an example chain:</p><ul><li>11452: vsftpd: Multiple FTP connection attempts from same source IP → level 10</li><li>5710: sshd: Attempt to login using a non-existent user → level 5</li><li>5501: PAM: Login session opened → level 3</li></ul><p>This approach reduces noise: you don’t want an alert every time someone fat-fingers their password. But if it keeps happening in rapid succession? Then it’s worth knowing.</p><blockquote>Pro tip:<em> You can think of Wazuh rules like a decision tree, each layer filters and enriches the event until it meets criteria serious enough to alert on.</em></blockquote><h4>Rule Levels: Prioritizing Risk</h4><p>Every rule has a level between 0–15. The higher the number, the more severe the alert.</p><ul><li><strong>Level 0</strong>: No alert generated</li><li><strong>Level 1–2</strong>: Informational</li><li><strong>Level 4–6</strong>: Low priority (noise filters)</li><li><strong>Level 7–10</strong>: Suspicious or abnormal activity</li><li><strong>Level 11–15</strong>: Confirmed threat, needs attention</li></ul><h4>Matching Logic: Behind the Scenes</h4><p>When a log is processed:</p><ol><li>Wazuh checks each decoded field (like srcip, action, program) against rule conditions.</li><li>It looks for:</li></ol><ul><li>&lt;match&gt;: basic string match</li><li>&lt;regex&gt;: pattern match</li><li>&lt;field name=&quot;srcip&quot;&gt;192.168.1.10&lt;/field&gt;: field specific match</li></ul><ol><li>It tracks frequency and time windows if defined (frequency, timeframe).</li><li>If a rule matches, it:</li></ol><ul><li>Adds metadata (rule ID, description, groups)</li><li>Sends the event to alerts.json</li><li>Triggers active responses (if defined)</li></ul><h4>Example in Action</h4><p>Let’s revisit the SSH failed login log:</p><pre>Jul 2 09:50:15 database-server sshd[12345]: Failed password for invalid user admin from 192.168.1.10 port 41001 ssh2</pre><p>Here’s how Wazuh processes it:</p><ol><li>It matches decoder for sshd.</li><li>Rule 5710 is matched: illegal user or invalid user.</li><li>After 8 attempts within 120 seconds → rule 5712 fires (brute force pattern).</li><li>An alert with level 10 is generated and logged.</li></ol><p>You can see the exact matched rule ID and group in the final alert JSON:</p><pre>{<br>  &quot;rule&quot;: {<br>    &quot;id&quot;: 5710,<br>    &quot;level&quot;: 5,<br>    &quot;description&quot;: &quot;shd: Attempt to login using a non-existent user&quot;,<br>    &quot;groups&quot;: [&quot;syslog&quot;,&quot;sshd&quot;,&quot;authentication_failed&quot;,&quot;invalid_login&quot;]<br>  },<br>  &quot;agent&quot;: { &quot;ip&quot;: &quot;192.168.5.1&quot;, &quot;name&quot;: &quot;webserver-1&quot; &quot;id&quot;: &quot;003&quot;,},<br>  &quot;srcip&quot;: &quot;192.168.1.10&quot;,<br>  &quot;full_log&quot;: &quot;Jul 2 09:50:15 database-server sshd[12345]: Failed password for invalid user admin from 192.168.1.10 port 41001 ssh2&quot;<br>}</pre><h4>Want to Test a Rule?</h4><p>Use wazuh-logtest, a CLI tool where you paste in a sample log, and Wazuh shows you:</p><ul><li>which decoder was matched,</li><li>which rule(s) triggered,</li><li>the alert level and output.</li></ul><p>Great for debugging or writing custom rules.</p><h3>Wrapping Up (for Now)</h3><p>At this point, we’ve unpacked the key components of how Wazuh processes logs, from the big-picture architecture, to the roles of individual daemons, down to how raw logs are decoded and matched against detection rules. Hopefully, this deep dive has helped demystify what’s happening under the hood every time you see an alert in your dashboard.</p><p>But we’re not done yet.</p><p>In the next post, we’ll trace a real log through the entire pipeline, step by step, and then go hands on by creating custom decoders and detection rules tailored for internal applications or unique behaviors. If you’ve ever wanted to make Wazuh work more intelligently for your environment, you won’t want to miss it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c40d4dc1b21" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>