<?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 Aditya Devani on Medium]]></title>
        <description><![CDATA[Stories by Aditya Devani on Medium]]></description>
        <link>https://medium.com/@adevani20045?source=rss-53635efa97f6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aWlns33Vz7B2rjcy</url>
            <title>Stories by Aditya Devani on Medium</title>
            <link>https://medium.com/@adevani20045?source=rss-53635efa97f6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 18:33:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adevani20045/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[BUILDING A SNORT-3 IDS FROM ZERO TO LIVE ALERTS]]></title>
            <link>https://medium.com/@adevani20045/building-a-snort-3-ids-from-zero-to-live-alerts-5063898eb973?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5063898eb973</guid>
            <category><![CDATA[cyber-kill-chain]]></category>
            <category><![CDATA[threat-detection]]></category>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[security-operations]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Wed, 27 May 2026 11:06:43 GMT</pubDate>
            <atom:updated>2026-05-27T11:06:43.861Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong><em>Part-3 — Unleashing a Five-Phase Attack and Watching Snort Catch It All.</em></strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*75mrYp0bocwteId6c0YkRA.png" /></figure><h3>1. Introduction and Why This Lab Matters</h3><p>In the first two parts of this series you built a sensor and you taught it what to look for. What you have not done yet is point a real attack at it and watch the whole thing unfold from start to finish. That is what Lab 4 is for.</p><p>Up to now every test was a single isolated command. You ran one ping, you confirmed one alert. You ran one curl, you confirmed one alert. That is the unit test of detection engineering, and it proves each rule works in isolation. But a real attacker does not send you one packet and stop. A real attacker moves through a sequence of stages, each one building on the last, and the alerts your sensor produces should read like a story when you put them in order.</p><p><strong>Lab 4 </strong>is the integration test. You will run a complete multi-phase attack against the Sensor, beginning with reconnaissance, escalating into service enumeration and credential access, pivoting into web application exploitation, and finishing with command-and-control and data exfiltration over a covert channel. You will not run scattered commands. You will run them in the deliberate order an intruder would, and you will sit beside a live alert tail and watch Snort detect every single phase as it happens. At the end you will run a triage report that turns thousands of raw alert lines into a clear picture of the entire intrusion.</p><p>This is Part 3 of the series. It covers Lab 4 only. The reference run for this lab produced roughly <strong>21,400 total alerts</strong>, every one of the 10 custom rules from Lab 3 firing, and more than a dozen community rules firing on top of them.</p><h4>1.1 What Part 1 Covered (Labs 1 and 2)</h4><p>Part 1 built the foundation. In Lab 1 you launched two EC2 instances inside one private AWS VPC, a Sensor on xxx.xxx.xx.x and an Attacker on xxx.xxx.xx.x, both sitting in the xxx.xxx.xx.x/xx subnet. You compiled <strong>libDAQ 3.0.17</strong> and Snort 3.3.7.0 from source on the Sensor, wrote the master <strong>snort.lua</strong> configuration that declares HOME_NET and every port list the community rules expect, downloaded the Talos community rule set of roughly 4,646 rules, and registered Snort as a <strong>systemd </strong>service so it starts on boot and restarts on crash. You then added four simple verification rules in <strong>local.rules</strong> using SIDs 1000001 to 1000004, generated traffic from the Attacker, and watched your first alerts appear in real time.</p><p>In Lab 2 you became an operator. You generated five distinct traffic types, captured live packets to a PCAP file with <strong>tcpdump</strong>, replayed that PCAP back through Snort offline, and learned the triage pipeline that every SOC analyst relies on. That pipeline is the combination of tail for live monitoring, the grep, awk, sort, and <strong>uniq</strong> chain for filtering, and jq for slicing the structured alert_json.txt file by any field you want. You also <strong>memorised</strong> the layout of a single alert_fast.txt line, which is the timestamp, then the GID:SID:REV triple, then the rule message, then the priority, then the protocol marker, then the source and destination address pair.</p><h4>1.2 What Part 2 Covered (Lab 3)</h4><p>Part 2 turned you from a Snort user into a Snort author. In Lab 3 you wrote 10 custom detection rules in a dedicated file called lab3.rules, using SIDs 1000101 to 1000110 so they could never collide with the Lab 1 rules. Those 10 rules map onto the attack stages you are about to run in Lab 4. They cover a ping sweep, a TCP SYN port scan, an SSH brute force, a SQL injection using UNION SELECT, a SQL injection using OR 1=1, a cross-site scripting script tag, a directory traversal attempt, a <strong>pentest </strong>tool user-agent, a suspicious DNS query, and a large ICMP payload.</p><p>Lab 3 also taught the rule-writing lessons that make Lab 4 possible. You learned that custom rules must use the any to any direction, because the Attacker lives inside HOME_NET and an external-to-home rule would never match it. You learned that content modifiers like <strong>nocase</strong> must be comma-attached to the content directive in Snort 3, not separated by a semicolon as in Snort 2. You learned that HTTP rules need a real listener on port 80 before any payload can travel, which is why Apache was installed on the Sensor. You learned that the DNS rule needs the <strong>pkt_data</strong> keyword and traffic sourced from the Attacker, because a lookup from the Sensor itself goes through <strong>systemd</strong>-resolved on the loopback interface and never crosses the ens5 interface that Snort is sniffing. Finally you built a one-line verification script that confirms every SID has fired at least once.</p><p>With both halves of the foundation in place, Lab 4 is where you see all of it work together.</p><blockquote><strong>NOTE</strong></blockquote><blockquote>Prerequisites before you start.</blockquote><blockquote>Lab 3 must be complete with all 10 rules confirmed firing. Snort must be running in passive IDS mode as the <strong>systemd</strong> service. Apache must still be listening on port 80 of the Sensor. Both EC2 instances must be running and reachable over SSH. If any of these is not true, go back and finish Lab 3 before continuing.</blockquote><h3>2. The Cyber Kill Chain Mapped to This Lab</h3><p>Before running anything, it helps to see the destination. The Cyber Kill Chain is a model that breaks an intrusion into ordered stages. Real attackers rarely skip stages, because each one feeds the next. You cannot brute force a service you have not discovered, and you cannot discover it without first finding the host. Lab 4 walks five of those stages in sequence, and each stage has been designed to trigger specific rules you already wrote.</p><p>The five phases of this lab map as follows. Phase 1 is Reconnaissance, performed with an ICMP sweep and a TCP SYN scan. Phase 2 is Service Enumeration, performed with an <strong>nmap</strong> version and operating system probe. Phase 3 is Credential Access, performed with an SSH brute force. Phase 4 is Web Application Exploitation, performed with SQL injection, cross-site scripting, directory traversal, and a vulnerability scanner. Phase 5 is Command-and-Control and Exfiltration, performed with suspicious DNS lookups and oversized ICMP packets.</p><p>The point of running them in order is the narrative. When you read the final alert log top to bottom, you should be able to see the attacker discover the host, find its open ports, try to log in, attack the web application, and finally attempt to smuggle data out. The alert stream becomes the timeline of the intrusion.</p><h3>3. Pre-Flight Checks</h3><p>Every phase assumes the detection pipeline is alive and the log files are clean. This section is the setup that guarantees both. Run all of these on the Sensor.</p><p><strong>Step 1. Confirm Snort is running.</strong></p><blockquote>sudo systemctl status snort3 — no-pager | head -3</blockquote><p>This prints the first three lines of the Snort service status. You are looking for the words active (running) in green. If it says inactive (dead), start the service with sudo systemctl start snort3 before going any further. There is no point generating attacks if the sensor is not listening.</p><p><strong>Step 2. Clear the old alert files so the Lab 4 results are clean.</strong></p><blockquote>sudo truncate -s 0 /var/log/snort/alert_fast.txt</blockquote><blockquote>sudo truncate -s 0 /var/log/snort/alert_json.txt</blockquote><p>The truncate -s 0 command sets the size of a file to zero bytes without deleting the file itself. This matters because Snort already has those files open for writing, and deleting them would break that file handle. Truncating empties the file while keeping the handle valid, so Snort keeps logging into a fresh, empty file. After this step every alert you see belongs to Lab 4 and nothing carries over from Lab 3, which makes the final triage report accurate.</p><p><strong>Step 3. Start the HTTP listener for the Phase 4 web attacks.</strong></p><blockquote>sudo nohup python3 -m http.server 80 &gt; /tmp/httpd.log 2&gt;&amp;1 &amp;</blockquote><p>This is the listener that lets the Phase 4 web attacks deliver their payloads. The <strong>nohup</strong> prefix detaches the process from your SSH session so it survives if the terminal closes. The python3 -m <strong>http.server</strong> 80 part starts a minimal web server on port 80. The &gt; /tmp/httpd.log 2&gt;&amp;1 redirects both normal output and error output into a log file. The trailing ampersand pushes the whole thing into the background so your shell stays usable.</p><p>There is an important detail here that the reference run shows clearly. On a Sensor where Apache is already installed and running, as it was after Lab 3, this command immediately exits with the message [1]+ Exit 1. The reason is that port 80 is a singleton, meaning only one process can bind to it at a time, and Apache already owns it. This is not a failure. Apache itself is a perfectly good HTTP listener and it serves the same purpose. If you check the listening sockets with<strong> sudo ss -tlnp grep on port 80 </strong>you will see Apache holding the port. Either listener works for Lab 4. The web attack rules fire either way, because what they match on is the request payload, and that payload travels as soon as any server completes the TCP handshake.</p><p><strong>Step 4. Open a live alert tail in a second Sensor window.</strong></p><blockquote>sudo tail -f /var/log/snort/alert_fast.txt</blockquote><p>The tail -f command prints the end of a file and then keeps following it, showing every new line the moment it is written. With Snort writing alerts into alert_fast.txt in real time, this window becomes your live monitor. Leave it open and visible for the entire lab. As you run each attack phase from the Attacker, new alert lines will scroll past here within milliseconds. The sudo is required because the alert file is mode 0640 and a normal user cannot read it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpIiz-0a72GPPyoACsTumw.png" /></figure><blockquote><strong>CHECKPOINT</strong></blockquote><blockquote>Pipeline ready.</blockquote><blockquote>Snort is running, both log files are empty, an HTTP listener is bound to port 80, and a live tail is following the alert file. You now have one Sensor window showing alerts and one Attacker window ready to generate traffic. Every phase below is run from the Attacker unless the step says otherwise.</blockquote><h3>4. Phase 1 — Reconnaissance</h3><p>Reconnaissance is how an intrusion begins. Before an attacker can do anything useful they need to know the target is alive and which of its ports are open. This phase produces exactly that behaviour, and it is designed to trigger your ping sweep rule (SID 1000101) and your TCP SYN port scan rule (SID 1000102).</p><blockquote><strong>WARNING</strong></blockquote><blockquote>Aim all reconnaissance at the Sensor.</blockquote><blockquote>Snort on the Sensor only sees packets that are transmitted on or destined to its own ens5 interface. If you ping scattered subnet addresses like .1, .50, or .100, those packets travel elsewhere on the network and never reach Snort, so the per-source threshold in SID 1000101 is never met. Direct every reconnaissance packet straight at xxx.xxx.xx.x.</blockquote><p><strong>Step 1. Run a focused ping flood at the Sensor.</strong></p><blockquote>ping -c 30 -i 0.05 xxx.xxx.xx.x</blockquote><p>This sends 30 ICMP echo requests at the Sensor. The -c 30 flag sets the count to exactly 30 packets so the command stops on its own. The -i 0.05 flag sets the interval between packets to 0.05 seconds, which means all 30 pings finish in about 1.5 seconds. That speed is deliberate. Your ping sweep rule fires only after it sees 10 echo requests from the same source within a 5 second window, so 30 pings in 1.5 seconds clears that threshold easily. In the live tail you will see a burst of LOCAL Ping Sweep Detected lines beginning after the tenth packet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/427/1*ypyeIqSsmCHdc7UGf_1ugg.png" /></figure><p><strong>Step 2. Run an aggressive SYN scan against the Sensor.</strong></p><blockquote>sudo nmap -sS -T4 — top-ports 100 xxx.xxx.xx.x</blockquote><p>This is a port scan that probes the 100 most common ports on the Sensor. The -sS flag selects a half-open SYN scan, in which <strong>nmap</strong> sends a SYN packet, waits for a SYN-ACK reply, and then resets the connection without completing the handshake. The -T4 flag selects the aggressive timing template, which makes the scan fast at the cost of being noisy. The — top-ports 100 flag tells nmap to test only the 100 ports most likely to be open rather than all 65,535. The<strong> sudo</strong> is required because a raw SYN scan needs privileged access to craft packets directly. Each SYN packet nmap sends fires your TCP SYN port scan rule, and because there are dozens of them in a couple of seconds you will see a heavy burst of LOCAL TCP SYN Port Scan lines. In the reference run this single scan produced more than 800 hits on SID 1000102. The scan also reports its findings, and on this Sensor it confirms that port 22 (SSH) and port 80 (HTTP) are open.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JjK_mug1CqbWJdmcbP5dQQ.png" /></figure><blockquote><strong>NOTE</strong></blockquote><blockquote>What just happened in the alert stream.</blockquote><blockquote>Within one or two seconds of running these two commands, the live tail showed two distinct bursts: LOCAL Ping Sweep Detected from the ICMP flood, and LOCAL TCP SYN Port Scan from the nmap scan. That is the signature of reconnaissance, a fast burst of probes from a single source. The attacker now knows the host is alive and which ports to attack next.</blockquote><h3>5. Phase 2 — Service Enumeration</h3><p>Reconnaissance told the attacker that ports 22 and 80 are open. Enumeration is the next logical step, where the attacker asks each open port what software it is running and what version. Version information is what lets an attacker look up known vulnerabilities, so this phase is the bridge between finding a service and exploiting it.</p><p><strong>Step 1. Run a service version scan against the known open ports.</strong></p><blockquote>sudo nmap -sV -p 22,80,443 xxx.xxx.xx.x</blockquote><p>This probe identifies the exact software behind each port. The -sV flag enables service and version detection, which means nmap completes a full TCP handshake and reads the banner that the service sends back, rather than just noting that the port is open. The -p 22,80,443 flag restricts the scan to those three specific ports, which is faster and quieter than scanning everything. In the reference run this scan revealed OpenSSH 8.9p1 on port 22, Apache httpd 2.4.52 on port 80, and a closed state on port 443. Because -sV completes real handshakes and exchanges real protocol data, Snort sees genuine SSH and HTTP traffic, which triggers your SSH Connection Attempt and HTTP Traffic Detected rules from Lab 1 as well as several community PROTOCOL rules.</p><p><strong>Step 2. Run an operating system fingerprint scan.</strong></p><blockquote>sudo nmap -O xxx.xxx.xx.x</blockquote><p>This probe tries to identify the operating system itself. The -O flag enables OS detection, where nmap sends a series of specially crafted packets and studies tiny differences in how the target TCP/IP stack responds. Those differences form a fingerprint that nmap compares against a database of known systems. This is a more aggressive probe than a version scan, and it generates unusual packet patterns that community anomaly rules notice. In the reference run nmap could not find an exact OS match and printed the raw TCP/IP fingerprint instead, which is a common and harmless outcome on cloud instances. The value for the lab is the extra alerts the unusual probe packets create.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zIFpmpLu6jBIVanrOMrNyQ.png" /></figure><blockquote><strong>NOTE</strong></blockquote><blockquote>What just happened in the alert stream.</blockquote><blockquote>Enumeration looks different from reconnaissance in the alert tail. Instead of one fast uniform burst you see a mix of SSH, HTTP, and PROTOCOL anomaly alerts, because the attacker is now interacting with services rather than just probing for open ports. The intrusion has moved one stage deeper.</blockquote><h3>6. Phase 3 — Credential Access</h3><p>The attacker now knows that SSH is open on port 22. The natural next move is to try to log in. Credential access is the phase where an attacker attempts to guess or crack a valid username and password. This phase is designed to trigger your SSH brute force rule (SID 1000103), which fires after it sees five connection attempts from the same source within 30 seconds.</p><p><strong>Step 1. Build a small password list.</strong></p><blockquote>echo -e “admin\npassword\nroot\ntest\nubuntu\n123456” &gt; /tmp/pwlist.txt</blockquote><p>This creates the wordlist that the brute force tool will try. The echo -e command enables interpretation of escape sequences, so each backslash-n becomes a real newline. The result is a file with six common passwords, one per line. The greater-than sign redirects that output into the file /tmp/pwlist.txt. A real attacker would use a wordlist of millions of entries, but six is enough to generate the repeated connection pattern the rule looks for.</p><p><strong>Step 2. Run the brute force with hydra.</strong></p><blockquote>hydra -l ubuntu -P /tmp/pwlist.txt ssh://xxx.xxx.xx.x -t 4 -f 2&gt;/dev/null || true</blockquote><p>Hydra is a legitimate, well-known brute force tool used by penetration testers. The -l ubuntu flag sets a single username to try, which is ubuntu. The -P /tmp/pwlist.txt flag points hydra at the password file you just created, so it tries every password in that file. The ssh://xxx.xxx.xx.x part tells hydra to attack the SSH service on the Sensor. The -t 4 flag runs four parallel tasks to speed the attempt up. The -f flag tells hydra to stop as soon as it finds one working pair. The 2&gt;/dev/null discards error output to keep the screen clean, and the || true ensures the command line reports success even if hydra exits with a non-zero status, which keeps a scripted run from halting here. Every login attempt hydra makes is a fresh connection to port 22, and that stream of connections is what your brute force rule counts.</p><p><strong>Step 3. Run a second brute force pattern with a plain SSH loop.</strong></p><blockquote>for i in {1..15}; do</blockquote><blockquote>ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no -o BatchMode=yes \</blockquote><blockquote>ubuntu@xxx.xxx.xx.x exit 2&gt;/dev/null</blockquote><blockquote>done</blockquote><p>This loop achieves the same effect as hydra using only the standard ssh client, and it always works even if hydra is unavailable. The for i in {1..15} part repeats the body 15 times. Inside the loop, the ssh command connects to the Sensor and immediately runs exit. Three options make the loop reliable. The -o ConnectTimeout=2 option gives up after two seconds so a slow attempt cannot stall the loop. The -o StrictHostKeyChecking=no option skips the interactive prompt that asks you to trust a new host key. The -o BatchMode=yes option is the most important one, because it disables password prompts entirely, so each attempt fails fast instead of hanging and waiting for you to type. Fifteen connections in quick succession comfortably exceeds the rule threshold of five connections in 30 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aNb20u11SVtM9OnlgH2TMw.png" /></figure><blockquote><strong>NOTE</strong></blockquote><blockquote>What just happened in the alert stream.</blockquote><blockquote>After the fifth connection inside the threshold window, LOCAL SSH Brute Force starts firing, and it keeps firing for every connection after that. In the reference run SID 1000103 ended Lab 4 with several hundred hits between the hydra run and the loop. The attacker has now tried to force a way in.</blockquote><h3>7. Phase 4 — Web Application Exploitation</h3><p>The enumeration phase confirmed Apache is running on port 80. Web application exploitation is the phase where an attacker attacks the application itself rather than the network around it. This is the richest phase of the lab, because it exercises five separate rules at once: SQL injection by UNION SELECT (SID 1000104), SQL injection by OR 1=1 (SID 1000105), cross-site scripting (SID 1000106), directory traversal (SID 1000107), and the <strong>pentest</strong> tool user-agent (SID 1000108).</p><p>Every command here is a single HTTP request sent with curl. The curl tool is a command line HTTP client, and each request below carries a malicious payload in either its URL or its body. The HTTP listener you confirmed in the pre-flight section accepts the connection so the payload actually travels across ens5, where Snort inspects it.</p><p><strong>Step 1. Send a SQL injection using a URL parameter.</strong></p><blockquote>curl “http://xxx.xxx.xx.x/login.php?user=admin&amp;pass=&#39; OR ‘1’=’1”</blockquote><p>This request attempts the classic authentication bypass. The payload is the OR 1=1 fragment in the pass parameter, which is designed to make a poorly written SQL login query always evaluate to true. The double quotes around the whole URL are required so the shell treats the spaces and special characters as part of the address. Note an important real-world detail visible in the reference run. When a URL contains raw spaces, as the words in this payload do, curl can reject it with the message curl: (3) URL using bad/illegal format or missing URL. To send this payload reliably you either keep it inside quotes as shown or replace spaces with the URL-encoded form. The OR 1=1 rule still fires whenever the literal text reaches the wire.</p><p><strong>Step 2. Send a SQL injection using UNION SELECT.</strong></p><blockquote>curl “http://xxx.xxx.xx.x/products?id=1 UNION SELECT username,password FROM users”</blockquote><p>This request attempts to extract data rather than bypass a login. A UNION SELECT injection appends an attacker-controlled query onto the original one, which can pull back columns like usernames and passwords from another table. Your UNION SELECT rule requires both the word UNION and the word SELECT to appear in the same packet, which is what makes it specific enough to avoid false positives. As with Step 1, the spaces in this URL must stay quoted, and the reference run shows that an unquoted version is rejected by curl before it ever leaves the Attacker.</p><p><strong>Step 3. Send a SQL injection in a POST body.</strong></p><blockquote>curl -X POST — data “u=admin&amp;p=’ or 1=1 — “ <a href="http://192.168.10.9/auth">http://xxx.xxx.xx.x/auth</a></blockquote><p>This sends the same style of attack but inside the body of a POST request rather than the URL. The -X POST flag changes the HTTP method from the default GET to POST. The — data flag supplies the request body, which here carries the or 1=1 payload. The trailing double dash is a SQL comment marker that tells the database to ignore whatever follows, which an attacker uses to discard the rest of the original query. This request triggers the OR 1=1 rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*oa4kjK66MfIgqyyM-k_O4w.png" /></figure><p><strong>Step 4. Send two cross-site scripting requests.</strong></p><blockquote>curl “http://xxx.xxx.xx.x/?msg=&lt;script&gt;alert(&#39;XSS&#39;)&lt;/script&gt;&quot;</blockquote><blockquote>curl “http://xxx.xxx.xx.x/comment?text=&lt;script&gt;document.cookie&lt;/script&gt;&quot;</blockquote><p>Cross-site scripting, or XSS, is an attack that injects JavaScript into a web page so it runs in the browser of another user. Both requests carry a script tag, which is exactly what your XSS rule matches on. The first payload uses alert(‘XSS’), the harmless proof-of-concept that simply pops a browser dialog. The second uses document.cookie, which represents the more dangerous goal of stealing a victim session cookie. Each request fires SID 1000106.</p><p><strong>Step 5. Send two directory traversal requests.</strong></p><blockquote>curl “http://xxx.xxx.xx.x/page?file=../../../etc/passwd&quot;</blockquote><blockquote>curl “http://xxx.xxx.xx.x/download?path=../../etc/shadow&quot;</blockquote><p>Directory traversal is an attack that escapes the web server intended folder to read files elsewhere on the disk. The dot-dot-slash sequence means go up one directory, and chaining several of them walks up to the filesystem root. From there the payload reaches into /etc/passwd, the user account file, and /etc/shadow, the password hash file. Your traversal rule matches on the literal dot-dot-slash sequence, and notice that this rule deliberately does not use nocase, because a slash has no upper or lower case. Both requests fire SID 1000107.</p><p><strong>Step 6. Run a full web vulnerability scanner.</strong></p><blockquote>nikto -h <a href="http://192.168.10.9/">http://xxx.xxx.xx.</a>x -maxtime 60s</blockquote><p>Nikto is an automated web server scanner that checks a target against thousands of known issues. The -h flag sets the host to scan. The -maxtime 60s flag caps the scan at 60 seconds so it does not run indefinitely. The reason this command matters for the lab is the user-agent. Like most pentest tools, nikto announces itself in the HTTP User-Agent header of every request it sends, and your pentest tool rule matches on the word Nikto in that header. Because nikto sends thousands of requests in its 60 second window, SID 1000108 will record by far the highest hit count of any rule in the lab. In the reference run it produced more than 6,000 hits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWTv1xR7tVk38gVlwsf2rA.png" /></figure><blockquote><strong>NOTE</strong></blockquote><blockquote>What just happened in the alert stream.</blockquote><blockquote>Phase 4 lights up the alert tail more than any other phase. In the space of one minute you see SQLi, XSS, traversal, and pentest tool alerts interleaved, dominated by the flood from nikto. Even though many of the curl requests hit paths that do not exist and return a 404 from Apache, the rules still fire, because Snort matches on the request payload as it crosses the wire, not on whether the server had a matching page. Detection does not depend on the attack succeeding.</blockquote><h3>8. Phase 5 — Command-and-Control and Exfiltration</h3><p>The final phase of an intrusion is what the attacker does once inside: contacting a remote server for instructions, which is called command-and-control or C2, and smuggling stolen data out, which is called exfiltration. This phase triggers your suspicious DNS query rule (SID 1000109) and your large ICMP payload rule (SID 1000110).</p><p><strong>Step 1. Generate suspicious DNS lookups.</strong></p><p>The lab guide presents this phase with nslookup commands run on the Sensor:</p><blockquote>for d in malware.c2.tk payload.evil.com malware-update.io c2.malware-server.net; do</blockquote><blockquote>nslookup $d 8.8.8.8 || true</blockquote><blockquote>done</blockquote><p>This loop walks a list of four domain names that look like malware infrastructure and resolves each one. The for d in part iterates over the four names, and nslookup $d 8.8.8.8 resolves each name using the Google public DNS server at 8.8.8.8. The || true keeps the loop going even if a lookup fails.</p><p>There is a reliability point here that you already learned in Lab 3 and that the actual Lab 4 run applied. A DNS lookup run from the Sensor itself is handled by systemd-resolved on the loopback address 127.0.0.53, so the query may never travel across the ens5 interface that Snort is watching. The dependable way to fire SID 1000109, and the method the reference run used, is to source the traffic from the Attacker and aim it at the Sensor, so it is guaranteed to cross ens5:</p><blockquote>for i in 1 2 3 4 5; do</blockquote><blockquote>echo “malware-c2-payload-$i” | nc -u -w1 xxx.xxx.xx.x 53</blockquote><blockquote>done</blockquote><p>This loop runs five times. Each pass uses echo to produce a short string containing the word malware, then pipes it into nc, the netcat utility. The -u flag tells netcat to send a UDP packet rather than open a TCP connection, which matches the UDP port 53 that DNS uses. The -w1 flag sets a one second timeout. The destination is the Sensor on port 53. The Sensor runs no DNS service, so its kernel rejects the packet, but Snort libpcap captures the packet before that rejection happens. Because your rule uses the pkt_data keyword, it searches the raw payload, finds the word malware, and fires.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*nNRU10EF_QYcNtK0sA8RBw.png" /></figure><p><strong>Step 2. Simulate ICMP-based exfiltration with oversized pings.</strong></p><blockquote>sudo ping -c 10 -s 1200 8.8.8.8</blockquote><blockquote>sudo ping -c 5 -s 1400 xxx.xxx.xx.x</blockquote><p>A normal ping carries a 56 byte payload. An attacker using ICMP as a covert channel hides stolen data inside much larger ping packets, because ICMP echo traffic is often allowed straight through firewalls without inspection. The -s 1200 and -s 1400 flags set the payload size to 1200 and 1400 bytes, both well above the 800 byte threshold in your large ICMP payload rule, so SID 1000110 fires on every one of these packets. The -c flag sets the packet count as before.</p><p>The reference run shows a useful detail in these two commands. The first ping, aimed at the external address 8.8.8.8, completed with 0 percent packet loss. The second ping, aimed at the Attacker at xxx.xxx.xx.x, came back with 100 percent packet loss. That is expected and correct. The Attacker security group only allows inbound SSH on port 22, so it drops inbound ICMP from the Sensor at the AWS firewall. The packets still leave the Sensor ens5 interface, which is all Snort needs to see them and fire the rule, so the rule still works even though the pings themselves are dropped before reaching the Attacker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/484/1*eWhiBTtIhAXCm4BHLzW28Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*B1deua_PsYrKmkJEd4dEtA.png" /></figure><blockquote><strong>NOTE</strong></blockquote><blockquote>What just happened in the alert stream.</blockquote><blockquote>Phase 5 closes the story. LOCAL Suspicious DNS Query and LOCAL Large ICMP Payload appear in the tail, representing an attacker calling home and trying to carry data out. With this phase done, every one of the five kill chain stages has been executed and detected.</blockquote><h3>9. The Final Triage Report</h3><p>Running the attack is only half of Lab 4. The other half is reading what Snort recorded and turning thousands of raw lines into a clear summary. This is the same triage work a SOC analyst does after an incident. Run all of these on the Sensor.</p><p><strong>Step 1. Stop the HTTP listener and clean up.</strong></p><blockquote>sudo pkill -f “python3 -m http.server”</blockquote><p>The pkill -f command finds and kills any process whose full command line matches the text you give it. This shuts down the Python HTTP listener now that Phase 4 is finished. If Apache was serving as the listener instead, you can leave Apache running, since it is a normal service.</p><p><strong>Step 2. Count the total alerts captured during the lab.</strong></p><blockquote>sudo wc -l /var/log/snort/alert_fast.txt</blockquote><p>The wc -l command counts the number of lines in a file. Because every alert is exactly one line in alert_fast.txt, this single number is the total alert count for the whole lab. In the reference run this number was 21,403, which closely matches the expected figure of roughly 21,400.</p><p><strong>Step 3. Break the alerts down by rule.</strong></p><blockquote>sudo awk -F’”’ ‘{print $2}’ /var/log/snort/alert_fast.txt | \</blockquote><blockquote>sort | uniq -c | sort -rn | head -20</blockquote><p>This pipeline produces a ranked table of which rules fired most. It works in stages. The awk -F part splits each line on the double-quote character and prints the second field, which is the rule message. The first sort groups identical messages together. The uniq -c collapses each group into a single line prefixed with its count. The final sort -rn orders those lines by count, highest first, and head -20 shows the top 20. In the reference run the top entries were HTTP Traffic Detected with about 7,000 hits, LOCAL Pentest Tool User-Agent with about 6,300, and SSH Connection Attempt and LOCAL SSH Brute Force close behind.</p><p><strong>Step 4. Rank the attacker IP addresses.</strong></p><blockquote>sudo grep -oE ‘[0–9]+\.[0–9]+\.[0–9]+\.[0–9]+ -&gt;’ /var/log/snort/alert_fast.txt | \</blockquote><blockquote>sort | uniq -c | sort -rn | head</blockquote><p>This pipeline answers the question of who attacked the most. The grep -oE part uses an extended regular expression to find every source IP address followed by the arrow marker, and the -o flag prints only the matched text rather than the whole line. The same sort, uniq -c, sort -rn chain then counts and ranks those addresses. In a clean lab run the Attacker at 192.168.10.7 sits at the top of this list, which confirms the source of the intrusion.</p><p><strong>Step 5. Bracket the attack timeline.</strong></p><blockquote>sudo head -1 /var/log/snort/alert_fast.txt</blockquote><blockquote>sudo tail -1 /var/log/snort/alert_fast.txt</blockquote><p>The head -1 command prints the first line of the file and tail -1 prints the last. Because alert_fast.txt is written in time order, the first line is the timestamp of the very first alert and the last line is the timestamp of the final alert. Together they bracket the entire attack from start to finish, which gives you the duration of the incident at a glance.</p><p><strong>Step 6. Confirm every custom rule fired.</strong></p><blockquote>sudo bash -c ‘for sid in $(seq 1000101 1000110); do</blockquote><blockquote>count=$(grep -c “\[1:${sid}:” /var/log/snort/alert_fast.txt)</blockquote><blockquote>printf “SID %d hits=%d\n” “$sid” “$count”</blockquote><blockquote>done’</blockquote><p>This is the verification script from Lab 3, used here as the final proof of Lab 4. The whole thing runs inside sudo bash -c because the alert file is only readable with elevated permission. The for <strong>sid</strong> in <strong>seq</strong> 1000101 1000110 loop walks every custom SID from 1000101 to 1000110. For each one, grep -c counts how many alert lines belong to that SID, where the backslashes escape the square brackets so grep treats them as literal characters. The printf then prints the SID next to its hit count. A successful Lab 4 shows every one of the 10 SIDs with a hit count greater than zero. In the reference run all 10 fired, ranging from a single hit on the OR 1=1 rule up to thousands on the pentest tool rule.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGow0Wf-lSf7JjLmtpRdNQ.png" /></figure><blockquote><strong>CHECKPOINT</strong></blockquote><blockquote>Lab 4 Complete.</blockquote><blockquote>Five kill chain phases were executed in order, from reconnaissance to exfiltration. Every phase was detected by Snort in real time in the live alert tail. The reference run captured roughly 21,400 total alerts. All 10 custom SIDs from Lab 3 were confirmed firing, along with more than a dozen community rules. The Attacker IP was correctly ranked at the top of the source list, and the full attack was bracketed end to end by the first and last alert timestamps.</blockquote><h3>10. What You Actually Just Learned</h3><p>The commands in Lab 4 are not the lesson. You already had every rule from Lab 3. The lesson is what happens when you stop testing rules one at a time and instead run them against an attack that moves the way a real attack moves.</p><p>Three ideas are worth carrying forward. The first is that an intrusion is a sequence, not an event. Each phase you ran depended on the one before it, and the alert log, read in order, told that story. Learning to read an alert stream as a narrative rather than a pile of lines is a core SOC skill. The second idea is that detection does not depend on the attack succeeding. Many of the Phase 4 requests hit pages that did not exist and many of the Phase 5 pings were dropped before reaching their target, yet every rule still fired, because Snort inspects traffic on the wire regardless of outcome. The third idea is triage. Twenty-one thousand alert lines are useless until you compress them, and the grep, awk, sort, and <strong>uniq</strong> pipeline turned that flood into a short, readable report of what happened, which rules fired most, who the attacker was, and how long the incident lasted.</p><h3>11. What Is Next in the Final Lab</h3><p>So far Snort has only watched. Across four labs it has detected reconnaissance, enumeration, brute force, web exploitation, and exfiltration, and it has told you in detail what happened. But it has never once stopped any of it. Every malicious packet in Lab 4 still reached its destination, and Snort simply wrote a line about it afterward.</p><p>The final lab changes that. You will convert Snort from a passive intrusion detection system into an inline intrusion prevention system using the NFQ data acquisition module and iptables. Instead of alert rules you will write drop rules, and Snort will sit directly in the path of traffic and discard malicious packets before they ever arrive. The same OR 1=1 payload that fired SID 1000105 in this lab will, in the next one, never reach the application at all. Detection becomes prevention, and the sensor you have built across this series finally gets to fight back.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5063898eb973" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BUILDING A SNORT-3 IDS FROM ZERO TO LIVE ALERTS]]></title>
            <link>https://medium.com/@adevani20045/building-a-snort-3-ids-from-zero-to-live-alerts-14b2a3b4372a?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/14b2a3b4372a</guid>
            <category><![CDATA[apache]]></category>
            <category><![CDATA[web-application-attack]]></category>
            <category><![CDATA[curl]]></category>
            <category><![CDATA[ping]]></category>
            <category><![CDATA[reconnaissance]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Mon, 18 May 2026 11:30:12 GMT</pubDate>
            <atom:updated>2026-05-18T11:30:12.735Z</atom:updated>
            <content:encoded><![CDATA[<p>Part-2 — <em>Writing Rules That Catch Real Attackers</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1pGv2iOmzXFeK2X7JIIiWA.png" /></figure><h3>1. Introduction &amp; Why Custom Rules Matter</h3><p>At the end of Part 1 you had roughly 4,646 rules loaded and alerts streaming into a terminal. That feels like victory until you read those rules carefully and realise something quietly inconvenient about them. They are written for everyone, not for you. They catch generic CVE shellcode, well known malware C2 domains, decade old worm signatures. They do not know your network, your attackers, or the specific shapes of trouble you actually care about. The community rule set is a fence around the property. Custom rules are the cameras pointed at the doors.</p><p>This is Part 2 of the series. It covers Lab 3, the lab where you stop being a Snort user and start being a Snort author. By the end of this blog you will have written 10 custom detection rules covering reconnaissance, brute force, web application attacks, and covert channels, generated matching attack traffic for every single one, and built a one liner verification script that confirms each SID has fired at least once.</p><h4>1.1 What Changes Between Lab 2 and Lab 3</h4><p>Lab 2 taught you how to read alerts. Lab 3 teaches you how to create them. The mental flip is bigger than it sounds. Reading is reactive: an alert appears, you decide whether it matters. Writing is proactive: you decide in advance what matters, encode it as a pattern, and trust the engine to find it in real traffic. Every commercial SIEM, every SOC playbook, every red team detection engineering job in the world ultimately reduces to that one skill.</p><h4>1.2 The Six Traps That Kill Lab 3</h4><p>Before the code, the wisdom. Every one of these is a silent failure mode. The rule loads, Snort runs, no error appears, and yet the SID never fires. Read each of these with the rule it ruins, so when the verification script reports hits=0, you know exactly which trap caught you.</p><p><strong>1.2.1 Trap 1 — SID Collisions</strong></p><p>Lab 1’s<strong> local.rules</strong> already uses SIDs 1000001 to 1000004 for the verification rules. If you naively reuse 1000001 to 1000010 for Lab 3, Snort’s rule loader silently drops the duplicates and keeps only one. There is no warning, no error, just rules that look loaded but never fire.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>Use SIDs 1000101 to 1000110 in a separate file lab3.rules. Numbering by hundreds (instead of incrementing one at a time) gives you headroom for future labs without ever colliding again.</blockquote><p><strong>1.2.2 Trap 2 — Wrong Direction</strong></p><p>A common instinct is to write Lab 3 rules as <strong>$EXTERNAL_NET -&gt; $HOME_NET</strong>. That sounds right, internet attackers hitting your internal hosts, but it is wrong for <em>this</em> lab. Our Attacker (192.xxx.xx.x) lives inside HOME_NET (192.xxx.xx.x/xx). Traffic from inside <strong>HOME_NET</strong> to inside HOME_NET never matches an $EXTERNAL_NET -&gt; $HOME_NET rule because the source IP is by definition in HOME_NET, not in !$HOME_NET.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>All Lab 3 rules use any -&gt; any direction. In production with real external attackers you would tighten this back to $EXTERNAL_NET -&gt; $HOME_NET, but for a self contained lab any -&gt; any is correct.</blockquote><p><strong>1.2.3 Trap 3 — Content Modifier Syntax</strong></p><p>In Snort 3, content modifiers like nocase, offset, depth, distance, and within must be comma attached to the content: directive, not separated by semicolons:</p><blockquote>content:”UNION”,nocase; # correct Snort 3 syntax</blockquote><p>Use the wrong syntax and Snort either fails to load the rule with a confusing error, or worse, loads it but never matches anything. The options threshold:, dns_query, and http_user_agent also need attention since they have specific Snort 3 requirements.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>Use detection_filter: for rate based thresholding. Use simple content:”X”,nocase; matching at the TCP/UDP level rather than HTTP buffer specific selectors like http_uri or http_header (which require their own setup). For HTTP traffic we just match content against the raw TCP payload, port 80 is selector enough.</blockquote><p><strong>1.2.4 Trap 4 — HTTP Rules Need Something Listening on Port 80</strong></p><p>This is the most painful trap because it looks obvious in hindsight and is invisible in foresight. Rules 4 to 8 all match on HTTP payload patterns (UNION SELECT, OR 1=1, &lt;script, ../, Nikto). For Snort to see the payload, the TCP handshake has to complete and the HTTP request has to actually be sent. But the Sensor VM has nothing listening on port 80 by default. When curl or nikto tries to connect, the Sensor’s kernel rejects the SYN with a TCP RST, the handshake never completes, and curl reports “Connection refused” before any payload bytes ever travel.</p><p>The payload Snort needs to match on never appears on the wire. No payload, no content match, no alert.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>Install Apache on the Sensor before running the HTTP test block. It accepts the TCP handshake, the HTTP request payload flows, Snort sees it, the rules fire. A one liner Python HTTP server (python3 -m http.server 80) also works, but only when nothing else is bound to port 80. We use Apache here because it is closer to a real web server and survives reboots.</blockquote><p><strong>1.2.5 Trap 5 — DNS Rules Need pkt_data AND Attacker Sourced Traffic</strong></p><p>Two compounding issues, both invisible:</p><p><strong>(a) </strong>Snort 3’s DNS inspector pre-parses DNS packets into typed buffers <strong>(dns_query, dns_resp,</strong> etc.) before rule evaluation. A plain <strong>content:”malware”</strong> directive may get scoped to one of those inspector buffers rather than the raw packet payload, and silently match nothing.</p><p><strong>(b) </strong>When the Sensor itself runs<strong> nslookup</strong> malware.example.com, the query is sent to 127.0.0.53 (systemd-resolved on the loopback interface), not out through ens5. Snort is sniffing ens5, so it literally cannot see the packet. The query happens, the response comes back, and Snort never registers the event.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>(a) Prepend <strong>pkt_data;</strong> to the rule to force the content search against the raw packet payload. (b) Generate the test traffic from the Attacker to the Sensor’s IP using nc -u -w1 192.168.10.9 53. UDP/53 from Attacker to Sensor crosses ens5, where Snort is listening. The Sensor has no DNS service on port 53, so the kernel will reject the packet, but Snort’s<strong> libpcap</strong> captures it <em>before</em> the kernel rejection.</blockquote><p><strong>1.2.6 Trap 6 — Log Permissions Silently Hide Alerts</strong></p><p>/var/log/snort/alert_fast.txt is owned by ubuntu with mode 0640. A grep without sudo returns nothing. Not “permission denied”, not an error, just a silent empty result. You spend an hour debugging a rule that was firing perfectly all along.</p><blockquote><strong>✓ Fix</strong></blockquote><blockquote>Always run verification commands with sudo, or wrap them in sudo bash -c ‘…’. This is also why the verification script in section 8 starts with sudo bash -c.</blockquote><blockquote><strong>📌 Read these six again before you write the rules</strong></blockquote><blockquote>Every one of them is a silent failure. The rules will load, Snort will run, the alert file will exist, and yet specific SIDs will report hits=0. The fixes are tiny (single words, single flags) but the symptoms are identical to “the rule is broken.” The traps are the lab.</blockquote><h4>1.3 The 10 Rules at a Glance</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*EeaWbfpmUMYN3xHVbTt4WA.png" /></figure><h3>2. Recap &amp; Mental Model</h3><p>Before we write a single rule, picture where they go and how Snort finds them.</p><h4>2.1 Where lab3.rules Lives in the Load Chain</h4><p>In Lab 1 your snort.lua already had this block:</p><blockquote>ips = {</blockquote><blockquote>enable_builtin_rules = true,</blockquote><blockquote>variables = default_variables,</blockquote><blockquote>rules = [[</blockquote><blockquote>include /usr/local/etc/snort/rules/local.rules</blockquote><blockquote>include /usr/local/etc/snort/rules/snort3-community.rules</blockquote><blockquote>]]</blockquote><blockquote>}</blockquote><p><strong>local.rules</strong> already holds the four verification rules from Lab 1 (SIDs 1000001 to 1000004). We are going to add a third file, <strong>lab3.rules</strong>, with SIDs 1000101 to 1000110, and include it from the same block. Keeping the two files separate is not cosmetic, it is a survival decision. Snort’s rule loader silently drops duplicates when two rules share a SID, so collision proof numbering is the difference between alerts firing and alerts vanishing.</p><h4>2.2 Anatomy of a Snort 3 Rule</h4><p>Every rule, no matter how complex, has the same shape:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcCU_mdHbfJFp-7sZg_hJA.png" /></figure><p>The options block is where the intelligence lives. These are the eleven options Lab 3 actually uses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*sY58-bMwFxxnG0noUiuJ7A.png" /></figure><h4>2.3 Confirm Snort 3 Is Still Running From Lab 1</h4><p>Before we touch anything, prove the Lab 1 stack is still up. If the Sensor was stopped, start it before continuing.</p><blockquote>sudo systemctl status snort3 — no-pager</blockquote><blockquote>ip -br addr</blockquote><blockquote>ls -l /var/log/snort/alert_fast.txt</blockquote><p>You should see <strong>Active: active (running) </strong>for<strong> snort3.service</strong>, your <strong>ens5</strong> interface listed as UP with its private IP, and an <strong>alert_fast.txt</strong> that has been growing since Lab 2.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V8DzYTxvnLKPPzKVmLwNHA.png" /></figure><h3>3. Install Apache on the Sensor (HTTP Listener)</h3><p>Before writing any rules, set up the HTTP listener. Rules 4 to 8 all need a working webserver on the Sensor so the payload actually travels.</p><blockquote># On the Sensor VM</blockquote><blockquote>sudo apt update</blockquote><blockquote>sudo apt install -y apache2</blockquote><blockquote>sudo systemctl enable — now apache2</blockquote><blockquote># Verify Apache is listening on port 80</blockquote><blockquote>curl -I <a href="http://localhost/">http://localhost</a></blockquote><p>You should get back an <strong>HTTP/1.1 200 OK</strong> with<strong> Server: Apache/2.4.52</strong> (Ubuntu). That confirms Apache is bound to <strong>port 80</strong> and ready to accept the test traffic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4dKouVvXypL5hAIE3DAxrw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*8GCN6Xw_mU9745OqEOd9KA.png" /></figure><h3>4. The 10 Rules, Grouped By Attack Phase</h3><p>The rules are not random. They map to the cyber kill chain. Reconnaissance first, then access, then exploitation, then exfiltration. Reading them in that order makes their structure obvious.</p><h4>4.1 Reconnaissance (Rules 1 &amp; 2)</h4><p>These rules use <strong>detection_filter</strong> because a single ping or a single SYN is not an attack, it is a normal packet. What makes it reconnaissance is <em>rate</em>: many of them, from one source, in a short window. <strong>detection_filter:track by_src, count N, seconds T </strong>says “only fire after seeing N matches from the same source IP within T seconds.” This is one of the most powerful primitives in the Snort 3 language.</p><blockquote># Rule 1, Ping Sweep</blockquote><blockquote>alert icmp any any -&gt; any any (msg:”LOCAL Ping Sweep Detected”; itype:8; \</blockquote><blockquote>detection_filter:track by_src, count 10, seconds 5; sid:1000101; rev:1;)</blockquote><blockquote># Rule 2, TCP SYN Port Scan</blockquote><blockquote>alert tcp any any -&gt; any any (msg:”LOCAL TCP SYN Port Scan”; flags:S; \</blockquote><blockquote>detection_filter:track by_src, count 50, seconds 5; sid:1000102; rev:1;)</blockquote><p><strong>itype:8 </strong>matches ICMP echo requests (pings). <strong>flags:S </strong>matches a bare SYN packet, the hallmark of a half-open scan. The thresholds (10 pings in 5 sec, 50 SYNs in 5 sec) are tuned for the test workload. In production you would raise them to reduce noise.</p><h4>4.2 Credential Access (Rule 3)</h4><blockquote># Rule 3, SSH Brute Force</blockquote><blockquote>alert tcp any any -&gt; any 22 (msg:”LOCAL SSH Brute Force”; \</blockquote><blockquote>detection_filter:track by_src, count 5, seconds 30; sid:1000103; rev:1;)</blockquote><p>Same<strong> detection_filter</strong> pattern, lower count and longer window because real SSH brute force is slower than a port scan. Five attempts in 30 seconds is below most failed login lockout thresholds. That is why we monitor it. A patient attacker stays below the OS level lockout but above the IDS threshold.</p><h4>4.3 Web Application Attacks (Rules 4 to 8)</h4><p>The five HTTP rules are the heart of Lab 3. Each one matches a payload pattern that almost certainly indicates malicious intent, even in isolation.</p><blockquote># Rule 4, SQLi UNION SELECT (both keywords in same packet)</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL SQLi UNION SELECT”; \</blockquote><blockquote>content:”UNION”,nocase; content:”SELECT”,nocase; sid:1000104; rev:1;)</blockquote><blockquote># Rule 5, SQLi OR 1=1 (classic auth bypass)</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL SQLi OR 1=1 Injection”; \</blockquote><blockquote>content:”or 1=1&quot;,nocase; sid:1000105; rev:1;)</blockquote><blockquote># Rule 6, XSS Script Tag</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL XSS Script Tag”; \</blockquote><blockquote>content:”&lt;script”,nocase; sid:1000106; rev:1;)</blockquote><blockquote># Rule 7, Directory Traversal</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL Directory Traversal Attempt”; \</blockquote><blockquote>content:”../”; sid:1000107; rev:1;)</blockquote><blockquote># Rule 8, Pentest Tool User-Agent (Nikto)</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL Pentest Tool User-Agent”; \</blockquote><blockquote>content:”Nikto”,nocase; sid:1000108; rev:1;)</blockquote><p>A few things to notice:</p><p>• <strong>Rule 4 chains two </strong>content:<strong> directives. </strong>Both keywords must appear in the same packet for the rule to fire. That dramatically cuts false positives. The word “UNION” alone is far too common in legitimate web traffic.</p><p>• <strong>Rule 7 omits </strong>nocase<strong> because </strong>../ is symbolic, not alphabetic. Case insensitivity has no meaning for a slash.</p><p>• <strong>Rule 8 catches Nikto by user agent. </strong>Most pentest tools advertise themselves in the User-Agent header. Sophisticated attackers spoof the UA. Lazy ones do not. Catching the lazy ones is still worth it.</p><blockquote><strong>⚠ Comma, not semicolon</strong></blockquote><blockquote>Look closely at every <strong>content:”X”,nocase;</strong>. The comma between <strong>“X”</strong> and <strong>nocase</strong> is what Snort 3 requires. Get this wrong and either the rule fails to load, or it loads silently broken. This is the single most common reason Lab 3 rules don’t fire on the first try.</blockquote><h4>4.4 Reconnaissance &amp; Exfiltration (Rules 9 &amp; 10)</h4><blockquote># Rule 9, Suspicious DNS Query (pkt_data; is mandatory)</blockquote><blockquote>alert udp any any -&gt; any 53 (msg:”LOCAL Suspicious DNS Query”; \</blockquote><blockquote>pkt_data; content:”malware”,nocase; sid:1000109; rev:1;)</blockquote><blockquote># Rule 10, Large ICMP Payload (covert channel / data exfil indicator)</blockquote><blockquote>alert icmp any any -&gt; any any (msg:”LOCAL Large ICMP Payload”; \</blockquote><blockquote>itype:8; dsize:&gt;800; sid:1000110; rev:1;)</blockquote><p>Rule 9 is the one most students get wrong. The<strong> pkt_data;</strong> directive is the magic word that forces content matching against the raw payload rather than DNS inspector buffers. Without it, the rule loads cleanly but matches nothing. I will show you exactly that failure later in the screenshots of section 7.</p><p>Rule 10 detects the “ping data exfiltration” pattern. A normal <strong>ping</strong> carries 56 bytes of payload. A <strong>ping -s 1000</strong> carries 1000 bytes. Real users do not need 1000 byte pings. Attackers using ICMP as a covert channel often do. The <strong>dsize:&gt;800</strong> threshold splits the two cleanly.</p><h3>5. Writing lab3.rules</h3><p>Now the actual command. Drop the entire rule set into <strong>/usr/local/etc/snort/rules/lab3.rules</strong> in one heredoc:</p><blockquote>sudo tee /usr/local/etc/snort/rules/lab3.rules &gt; /dev/null &lt;&lt; ‘EOF’</blockquote><blockquote># Lab 3, 10 custom rules (SIDs 1000101 to 1000110)</blockquote><blockquote># Direction is any -&gt; any to match Attacker traffic from inside HOME_NET</blockquote><blockquote># 1. Ping Sweep</blockquote><blockquote>alert icmp any any -&gt; any any (msg:”LOCAL Ping Sweep Detected”; itype:8; \</blockquote><blockquote>detection_filter:track by_src, count 10, seconds 5; sid:1000101; rev:1;)</blockquote><blockquote># 2. TCP SYN Port Scan</blockquote><blockquote>alert tcp any any -&gt; any any (msg:”LOCAL TCP SYN Port Scan”; flags:S; \</blockquote><blockquote>detection_filter:track by_src, count 50, seconds 5; sid:1000102; rev:1;)</blockquote><blockquote># 3. SSH Brute Force</blockquote><blockquote>alert tcp any any -&gt; any 22 (msg:”LOCAL SSH Brute Force”; \</blockquote><blockquote>detection_filter:track by_src, count 5, seconds 30; sid:1000103; rev:1;)</blockquote><blockquote># 4. SQLi UNION SELECT</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL SQLi UNION SELECT”; \</blockquote><blockquote>content:”UNION”,nocase; content:”SELECT”,nocase; sid:1000104; rev:1;)</blockquote><blockquote># 5. SQLi OR 1=1</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL SQLi OR 1=1 Injection”; \</blockquote><blockquote>content:”or 1=1&quot;,nocase; sid:1000105; rev:1;)</blockquote><blockquote># 6. XSS Script Tag</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL XSS Script Tag”; \</blockquote><blockquote>content:”&lt;script”,nocase; sid:1000106; rev:1;)</blockquote><blockquote># 7. Directory Traversal</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL Directory Traversal Attempt”; \</blockquote><blockquote>content:”../”; sid:1000107; rev:1;)</blockquote><blockquote># 8. Pentest Tool User-Agent (Nikto)</blockquote><blockquote>alert tcp any any -&gt; any 80 (msg:”LOCAL Pentest Tool User-Agent”; \</blockquote><blockquote>content:”Nikto”,nocase; sid:1000108; rev:1;)</blockquote><blockquote># 9. Suspicious DNS Query</blockquote><blockquote>alert udp any any -&gt; any 53 (msg:”LOCAL Suspicious DNS Query”; \</blockquote><blockquote>pkt_data; content:”malware”,nocase; sid:1000109; rev:1;)</blockquote><blockquote># 10. Large ICMP Payload</blockquote><blockquote>alert icmp any any -&gt; any any (msg:”LOCAL Large ICMP Payload”; \</blockquote><blockquote>itype:8; dsize:&gt;800; sid:1000110; rev:1;)</blockquote><blockquote>EOF</blockquote><p>Now wire the new file into <strong>snort.lua.</strong> A one liner with<strong> sed </strong>adds the new include right after the existing <strong>local.rules</strong> line:</p><blockquote>sudo sed -i ‘s|include /usr/local/etc/snort/rules/local.rules|include /usr/local/etc/snort/rules/local.rules\n include /usr/local/etc/snort/rules/lab3.rules|’ /usr/local/etc/snort/snort.lua</blockquote><blockquote># Confirm both includes are now present</blockquote><blockquote>grep “rules” /usr/local/etc/snort/snort.lua</blockquote><p>You should see three include lines: local.rules, lab3.rules, and snort3-community.rules.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WoMcuMwyHwiuCr6s2SAmig.png" /></figure><p>Validate the config, then restart Snort so the new rules load:</p><blockquote>sudo snort -c /usr/local/etc/snort/snort.lua -T 2&gt;&amp;1 | grep -iE “error|fatal|warning|successfully” | tail -10</blockquote><blockquote># Look for: “Snort successfully validated the configuration (with 0 warnings).”</blockquote><blockquote>sudo systemctl restart snort3</blockquote><blockquote>sleep 2 &amp;&amp; sudo systemctl status snort3 — no-pager | head -3</blockquote><blockquote># Expect: Active: active (running)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ngdWjcFVdxw2nlV1lUjQOg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*8qnMahHazv_BwmBKEnFrZA.png" /></figure><blockquote><strong>✓ Rules loaded</strong></blockquote><blockquote>If <strong>snort -T</strong> exits with “0 warnings” and <strong>systemctl</strong> shows <strong>active (running)</strong>, all 10 rules are in the engine. They will not fire until matching traffic appears, and that is the next section.</blockquote><h3>6. Testing Every Single Rule</h3><p>Open two SSH windows on the Sensor. Window A keeps a live tail on the alert file. Window B is your shell. Then a third window on the Attacker generates the traffic.</p><blockquote># WINDOW A (Sensor), live alert monitor</blockquote><blockquote>sudo tail -f /var/log/snort/alert_fast.txt</blockquote><h4>6.1 Install the Attack Toolkit on the Attacker</h4><blockquote># On the Attacker VM</blockquote><blockquote>sudo apt update &amp;&amp; sudo apt install -y nmap hydra nikto sqlmap hping3 dnsutils curl</blockquote><p>If your Attacker is brand new, this pulls roughly 24 MB. Most of these <strong>(nmap, hydra, sqlmap, nikto, hping3) </strong>come pre installed on the Ubuntu image we used, so the install is mostly a no op except for <strong>dnsutils</strong> (which gives us <strong>nslookup</strong> if we want it for debugging).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*awuB8MKKyK5VpZvgChgCwg.png" /></figure><h4>6.2 A Quick Aside — Why python3 -m http.server Fails Here</h4><p>If you tried to start a Python HTTP server on the Sensor after installing Apache, you would see this:</p><blockquote>sudo nohup python3 -m http.server 80 &gt; /tmp/httpd.log 2&gt;&amp;1 &amp;</blockquote><blockquote>sleep 1 &amp;&amp; sudo ss -tlnp | grep ‘:80 ‘</blockquote><blockquote># [1]+ Exit 1 sudo nohup python3 -m http.server 80 &gt; /tmp/httpd.log 2&gt;&amp;1</blockquote><blockquote># LISTEN 0 511 *:80 *:* users:((“apache2”,pid=…))</blockquote><p>Apache already owns port 80, so Python exits immediately with [1]+ Exit 1. This is not a failure of either tool. It is a reminder that port 80 is a singleton. Apache is the listener for the rest of this lab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsDPIaHpNhgsJFds_eAB-w.png" /></figure><h4>6.3 Run the Eight Attack Tests From the Attacker</h4><blockquote># Test 1, Ping Sweep (SID 1000101)</blockquote><blockquote>ping -c 30 -i 0.05 192.168.10.9</blockquote><blockquote># Test 2, TCP SYN Port Scan (SID 1000102)</blockquote><blockquote>sudo nmap -sS -T4 -p 1–1000 192.168.10.9</blockquote><blockquote># Test 3, SSH Brute Force (SID 1000103)</blockquote><blockquote>for i in {1..10}; do</blockquote><blockquote>ssh -o ConnectTimeout=2 -o StrictHostKeyChecking=no -o BatchMode=yes \</blockquote><blockquote>ubuntu@192.168.10.9 exit 2&gt;/dev/null</blockquote><blockquote>done</blockquote><blockquote># Test 4, SQLi UNION SELECT (SID 1000104)</blockquote><blockquote>curl “http://192.168.10.9/index.php?id=1+UNION+SELECT+username,password+FROM+users--&quot;</blockquote><blockquote># Test 5, SQLi OR 1=1 POST (SID 1000105)</blockquote><blockquote>curl -X POST -d “username=admin&amp;password=’ or 1=1 — “ “http://192.168.10.9/login&quot;</blockquote><blockquote># Test 6, XSS (SID 1000106)</blockquote><blockquote>curl “http://192.168.10.9/search?q=&lt;script&gt;alert(1)&lt;/script&gt;&quot;</blockquote><blockquote># Test 7, Directory Traversal (SID 1000107)</blockquote><blockquote>curl “http://192.168.10.9/files?file=../../../etc/passwd&quot;</blockquote><blockquote># Test 8, Pentest Tool User-Agent (SID 1000108)</blockquote><blockquote>nikto -h <a href="http://192.168.10.9/">http://192.168.10.9</a></blockquote><p><strong>BatchMode=yes</strong> in the SSH loop is critical. It prevents SSH from prompting for a password, so all ten attempts finish in seconds instead of hanging on the first prompt.<strong> nikto</strong> alone generates thousands of HTTP requests, which is why its hit count will be the highest in the verification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*BYLQ7ubuswvHxItYHAhj1Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vCyJNXX_qWMOLKl4ptqW5w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qO6oThoQGjaSjAAjHsl0lw.png" /></figure><h4>6.4 The Large ICMP Test (Run From the Sensor)</h4><p>Rule 10 wants ICMP echo requests with a payload larger than 800 bytes. The -s 1000 flag tells ping to send 1000 byte payloads:</p><blockquote># Test 10, Large ICMP Payload (SID 1000110), run on Sensor</blockquote><blockquote>sudo ping -c 5 -s 1000 8.8.8.8</blockquote><p>The destination (8.8.8.8) does not matter. What matters is that the ICMP packet leaves the Sensor’s <strong>ens5</strong> interface, where Snort sees it. Default <strong>ping</strong> payload is 56 bytes, well below the 800 byte threshold, so accidentally generated ICMP traffic from monitoring tools will not trigger false positives.</p><h4>6.5 First Verification Run — and the One That Comes Up Zero</h4><p>Run the verification script (the one liner from section 8). Pay close attention to SID 1000109:</p><blockquote>sudo bash -c ‘for sid in $(seq 1000101 1000110); do</blockquote><blockquote>count=$(grep -c “\[1:${sid}:” /var/log/snort/alert_fast.txt)</blockquote><blockquote>msg=$(grep “\[1:${sid}:” /var/log/snort/alert_fast.txt | tail -1 | \</blockquote><blockquote>sed -E ‘“‘“‘s/.*\[\*\*\] “([^”]+)”.*/\1/’”’”’)</blockquote><blockquote>printf “SID %d hits=%-5d %s\n” “$sid” “$count” “$msg”</blockquote><blockquote>done’</blockquote><p>On a first run where you tried nslookup malware.c2.tk from the Sensor (the obvious instinct), you will see this:</p><blockquote>SID 1000101 hits=40 LOCAL Ping Sweep Detected</blockquote><blockquote>SID 1000102 hits=1698 LOCAL TCP SYN Port Scan</blockquote><blockquote>SID 1000103 hits=220 LOCAL SSH Brute Force</blockquote><blockquote>SID 1000104 hits=6 LOCAL SQLi UNION SELECT</blockquote><blockquote>SID 1000105 hits=1 LOCAL SQLi OR 1=1 Injection</blockquote><blockquote>SID 1000106 hits=254 LOCAL XSS Script Tag</blockquote><blockquote>SID 1000107 hits=205 LOCAL Directory Traversal Attempt</blockquote><blockquote>SID 1000108 hits=6295 LOCAL Pentest Tool User-Agent</blockquote><blockquote>SID 1000109 hits=0</blockquote><blockquote>SID 1000110 hits=15 LOCAL Large ICMP Payload</blockquote><p>Nine out of ten rules fired. SID 1000109 is silently dead. This is exactly Trap 5 from section 3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MXz7eRit7-LHiZ_uhjW_oQ.png" /></figure><h4>6.6 Fix Rule 9, Then Generate DNS Traffic the Right Way</h4><p>The rule itself needs pkt_data; to escape the DNS inspector buffer, and the test traffic needs to come from the Attacker so it crosses ens5. Do both:</p><blockquote># Patch rule 9 in place on the Sensor, bump revision to 2</blockquote><blockquote>sudo sed -i ‘/sid:1000109/c\alert udp any any -&gt; any 53 (msg:”LOCAL Suspicious DNS Query”; pkt_data; content:”malware”,nocase; sid:1000109; rev:2;)’ /usr/local/etc/snort/rules/lab3.rules</blockquote><blockquote># Validate and restart Snort to load rev:2</blockquote><blockquote>sudo snort -c /usr/local/etc/snort/snort.lua -T 2&gt;&amp;1 | grep -iE “error|fatal|successfully” | tail -5</blockquote><blockquote>sudo systemctl restart snort3</blockquote><blockquote>sleep 2 &amp;&amp; sudo systemctl status snort3 — no-pager | head -3</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pINACf90kwatAf-AVuwtjw.png" /></figure><p>Now generate the DNS test traffic from the Attacker with nc. UDP/53 from Attacker to Sensor crosses ens5, where Snort is listening. The Sensor has no service on port 53, so the kernel rejects the UDP packet, but Snort’s libpcap captures it before the kernel rejection. That is the secret of how this rule fires against a host with no DNS server running.</p><blockquote># Test 9, Suspicious DNS Query (SID 1000109), RUN ON ATTACKER</blockquote><blockquote>for i in 1 2 3 4 5; do</blockquote><blockquote>echo “malware-c2-suspicious-dns-query-$i” | nc -u -w1 192.168.10.9 53</blockquote><blockquote>done</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/529/1*GCyZA6vSOltiNF8nMdpcPA.png" /></figure><blockquote><strong>ℹ Fallback if nc is not on the Attacker</strong></blockquote><blockquote>Use the Python equivalent:</blockquote><blockquote>python3 -c “ import socket s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) for i in range(5): s.sendto(b’malware suspicious dns lookup test ‘ + str(i).encode(), (‘192.168.10.9’, 53)) “</blockquote><h4>6.7 Re-run the Verification</h4><blockquote>sudo bash -c ‘for sid in $(seq 1000101 1000110); do</blockquote><blockquote>count=$(grep -c “\[1:${sid}:” /var/log/snort/alert_fast.txt)</blockquote><blockquote>msg=$(grep “\[1:${sid}:” /var/log/snort/alert_fast.txt | tail -1 | \</blockquote><blockquote>sed -E ‘“‘“‘s/.*\[\*\*\] “([^”]+)”.*/\1/’”’”’)</blockquote><blockquote>printf “SID %d hits=%-5d %s\n” “$sid” “$count” “$msg”</blockquote><blockquote>done’</blockquote><p>This time:</p><blockquote>SID 1000101 hits=40 LOCAL Ping Sweep Detected</blockquote><blockquote>SID 1000102 hits=1698 LOCAL TCP SYN Port Scan</blockquote><blockquote>SID 1000103 hits=349 LOCAL SSH Brute Force</blockquote><blockquote>SID 1000104 hits=6 LOCAL SQLi UNION SELECT</blockquote><blockquote>SID 1000105 hits=1 LOCAL SQLi OR 1=1 Injection</blockquote><blockquote>SID 1000106 hits=254 LOCAL XSS Script Tag</blockquote><blockquote>SID 1000107 hits=205 LOCAL Directory Traversal Attempt</blockquote><blockquote>SID 1000108 hits=6295 LOCAL Pentest Tool User-Agent</blockquote><blockquote>SID 1000109 hits=5 LOCAL Suspicious DNS Query</blockquote><blockquote>SID 1000110 hits=15 LOCAL Large ICMP Payload</blockquote><p>Every SID has hits greater than zero. Lab 3 is done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emRXQmDBikr4uJMMMyNl9g.png" /></figure><h3>7. Troubleshooting — If Any SID Still Shows Zero</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*2ye3qh7hPua_Cijy2uZo5w.png" /></figure><p>The fixes are almost always one of two shapes: either a piece of traffic was never generated (no listener, no sudo, wrong source VM), or a rule directive is in the wrong syntax (missing comma, missing pkt_data;). Reread section 3 if you are stuck.</p><blockquote><strong>✅ Lab 3 Complete</strong></blockquote><blockquote>✓ 10 custom rules written to a dedicated lab3.rules file with collision proof SIDs</blockquote><blockquote>✓ Apache installed as the HTTP listener so payloads actually reach Snort</blockquote><blockquote>✓ All rules syntax validated by snort -T with zero warnings</blockquote><blockquote>✓ Snort 3 service restarted with the new rules live</blockquote><blockquote>✓ Eight attack types generated from the Attacker, one from the Sensor</blockquote><blockquote>✓ DNS rule debugged and patched live with pkt_data; and rev:2</blockquote><blockquote>✓ Verification script proves every SID fired with hits greater than zero</blockquote><blockquote>✓ All six classic Lab 3 traps avoided</blockquote><h3>8. What You Actually Just Learned</h3><p>The 10 rules are not the lesson. The lesson is the <em>structure of detection thinking</em>. Look back at what you did:</p><p>1. You decided what bad behaviour looks like (a fast burst of pings, a UA string of “Nikto”, a 1000 byte ICMP payload).</p><p>2. You encoded the behaviour as a pattern in a domain specific language.</p><p>3. You generated the bad behaviour in a controlled environment.</p><p>4. You verified that your pattern caught your behaviour.</p><p>5. You debugged the gap between intent and execution when the pattern did not fire.</p><p>Every detection engineer at every SOC on earth does exactly that loop, every day. The tools change (Splunk, Sigma, YARA, Suricata, Elastic, Sentinel), but the loop is identical. Lab 3 is the first time you ran the loop end to end on real traffic. The next time you read a Threat Intelligence report and someone says “indicators include the user agent string XYZ”, you will know exactly how to turn that sentence into a rule and prove it works.</p><h3>9. What’s Next in Part 3</h3><p>Writing one rule at a time and proving it fires is the <em>unit test</em> of detection engineering. The next blog steps up to the <em>integration test</em>. In Part 3 you will run a complete multi phase attack simulation against the Sensor, starting with reconnaissance, escalating through enumeration and credential access, pivoting into a web application exploit, and ending in data exfiltration over a covert channel. You will not run isolated commands. You will run a script that chains them together the way a real attacker would. Then you will sit beside your alert tail and watch Snort detect the entire kill chain in real time, one phase after another, and you will see the alert stream itself become a narrative of an attack in progress.</p><p>After that, in the final blog of the series, we flip Snort from <em>seeing</em> attacks to <em>stopping</em> them. The same engine you have built over four labs becomes an inline IPS using NFQ DAQ and iptables, and you will write <strong>drop</strong> rules that not only alert but actively block matching packets in flight. The same<strong> or 1=1</strong> payload that fired SID 1000105 will, in IPS mode, never reach the application at all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14b2a3b4372a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[BUILDING A SNORT -3 IDS, FROM ZERO TO LIVE ALERTS]]></title>
            <link>https://medium.com/@adevani20045/building-a-snort-3-ids-from-zero-to-live-alerts-ebfea7b079ce?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebfea7b079ce</guid>
            <category><![CDATA[snort3]]></category>
            <category><![CDATA[attack-tool]]></category>
            <category><![CDATA[intrusion-detectionsystem]]></category>
            <category><![CDATA[network-defense]]></category>
            <category><![CDATA[packet-inspection]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Sat, 02 May 2026 18:51:53 GMT</pubDate>
            <atom:updated>2026-05-02T18:51:53.089Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Part -1</strong></p><h3>1. Introduction &amp; Why This Matters</h3><p>Every packet that crosses a network is a story. Most are routine, a DNS query, a TLS handshake, an HTTP GET. But hidden in the noise are the dangerous ones. The SYN scan probing for open ports, the SQL injection sliding through a URL parameter, the brute-force loop hammering port 22. A network intrusion detection system (IDS) is the eye that watches every packet and shouts the moment something dangerous appears. In this two-lab blog, we build that eye from scratch on AWS using Snort 3, the world’s most widely deployed open-source IDS, and prove it works by attacking ourselves and watching it scream.</p><p>This is Part 1 of the series. It covers the two foundation labs: getting the entire stack built and running (Lab 1), then learning to capture, read, and filter the alerts it produces (Lab 2).</p><h4>1.1 What is Snort 3?</h4><p>Snort is a free, open-source network IDS/IPS originally written by Martin Roesch in 1998 and now maintained by the Cisco Talos Intelligence Group. Snort 3, released in 2021, is a complete rewrite of the engine, with multithreaded packet processing, Lua-based configuration, and built-in protocol inspectors for HTTP, TLS, DNS, SMTP, FTP, and more. It reads every packet arriving on a network interface, compares each one against a rule set (tens of thousands of community-maintained signatures plus any custom rules you write), and fires an alert when a packet matches. In passive IDS mode it only watches and reports; in inline IPS mode it can drop the offending packet before it reaches its destination.</p><h4>1.2 Why Build It Yourself on AWS?</h4><p>You can read about Snort for hours and learn nothing. The moment you build it from source, fight a libDAQ version mismatch, watch make take twelve minutes, and finally see your first alert appear in a tail -f window, that’s when the concepts stick. AWS is ideal for this because:</p><p>• <strong>Isolated</strong>: a private VPC with a /24 CIDR means your attacks never leak onto a real network.</p><p>• <strong>Disposable</strong>: when the lab is over you stop both EC2s and pay nothing.</p><p>• <strong>Reproducible</strong>: every step in this blog runs identically on a fresh Ubuntu 22.04 AMI.</p><p>• <strong>Realistic</strong>: real Linux, real ens5 NIC, real packets, not a simulator.</p><h4>1.3 Skills You Will Walk Away With</h4><p>• Designing a small VPC, subnet, and security-group architecture for a security lab.</p><p>• Compiling Snort 3 and libDAQ from source on Ubuntu 22.04, including resolving the dependency dance that bites every first-time builder.</p><p>• Writing a complete snort.lua configuration with HOME_NET, port lists, protocol inspectors, and dual file outputs (alert_fast for humans, alert_json for machines).</p><p>• Running Snort as a systemd service that survives reboots.</p><p>• Generating and recognising real attack traffic with nmap, hping3, hydra, sqlmap, nikto, and curl.</p><p>• Reading Snort alerts the way SOC analysts read them, tail -f for live, grep/awk/sort/uniq for triage, jq for full JSON detail, and offline PCAP replay for forensic review.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gfDCTKInEmvpiojQQQKYQQ.png" /></figure><h3>2. AWS Setup</h3><p>Everything that follows depends on getting the AWS layer right. Two EC2 instances inside one VPC, each with its own security group, both in the same /28 subnet. The screenshots below are taken from the live console after the build was complete and verified, what you should see in your own account once each step is finished.</p><h4>2.1 Create the VPC (snort-lab-vpc)</h4><p>Open the AWS Console → VPC service → Create VPC. Choose “VPC and more” instead of “VPC only” so the wizard scaffolds the subnet, route table, and internet gateway for us. Use a name tag of snort-lab and IPv4 CIDR xxx.xxx.xx.x/24. We pick this private RFC-1918 range deliberately because it does not collide with most home and office networks.</p><p>Disable IPv6 (we don’t need it for the lab) and leave Tenancy at Default. Click Create VPC. AWS scaffolds the VPC, one public subnet, an Internet Gateway, and a route table that points 0.0.0.0/0 at the IGW, all in about ten seconds.</p><p><strong>Verify your VPC exists</strong></p><p>Open VPC service → Your VPCs. You should see two entries: the AWS default VPC and your snort-lab-vpc with CIDR 192.168.10.0/24 in state Available. Confirm the CIDR is exactly what you typed during creation, a wrong /24 will silently break Snort’s HOME_NET later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UosksnoXR9MAQ4oPzF_oVQ.png" /></figure><p><strong>Verify the resource map</strong></p><p>Click into snort-lab-vpc and open the Resource map tab. This is the single best diagnostic in the AWS console, it draws every resource attached to the VPC and the relationships between them. Confirm you see four panels: VPC → Subnets (1) → Route tables (2) → Network Connections (1: snort-lab-igw). The two route tables are normal, one is the main RT auto-created with the VPC, the other is the subnet’s explicit RT pointing 0.0.0.0/0 at the Internet Gateway.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O1cJNwsJxUzfd1Q1YJPUgQ.png" /></figure><p><strong>Verify the VPC details</strong></p><p>A second look at the VPC’s Details tab shows all the housekeeping fields: DNS resolution Enabled, Tenancy default, IPv4 CIDR xxx.xxx.xx.x/24, the main route table ID, the main network ACL, and the DHCP option set. None of these need editing for our lab, they exist mainly to be inspected when something goes wrong (a missing DHCP option set, for example, will silently break instance hostname resolution).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vJmtvO28vyXuUb_-7VhPWA.png" /></figure><h4>2.2 Subnet, Route Table, Internet Gateway</h4><p>In the same wizard, set Number of Availability Zones to 1, Number of public subnets to 1, and Number of private subnets to 0. We do not need a NAT gateway for this lab (it would cost money). The wizard also offers a single S3 Gateway VPC endpoint, leave it on, it’s free.</p><p>Once the wizard runs, AWS creates one public subnet (snort-lab-subnet-public1-ap-south-1a) carved out of the /24 as a /28, that’s 11 usable IPs, plenty for a 2-VM lab.</p><p><strong>Verify the subnet</strong></p><p>• <strong>IPv4 CIDR</strong>: 192.168.10.0/28, a /28 carved from the VPC’s /24, giving 11 usable IPs</p><p>• <strong>Availability Zone</strong>: ap-south-1a, both VMs must end up in the same AZ to share the subnet</p><p>• <strong>Auto-assign public IPv4 address</strong>: No, we use Elastic IPs instead for stable addressing</p><p>• <strong>Route table</strong>: snort-lab-rtb-public, the explicit RT that points 0.0.0.0/0 at the Internet Gateway</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LXR-xYu17hiy3dDPRSZRyA.png" /></figure><h4>2.3 Launch the Snort Sensor EC2</h4><p>Now go to EC2 → Launch instances. The recipe:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*W2wOJPkzVyA3cbK5CAUHrw.png" /></figure><p><strong>Verify the Sensor instance summary</strong></p><p>Once the instance reaches the Running state, click into it. The Instance summary page is the single most important verification view for an EC2, it shows everything that defines the VM in one screen. Confirm the highlighted fields:</p><p>• <strong>Instance state</strong>: Running (green)</p><p>• <strong>Public IPv4</strong>: &lt;SENSOR_PUBLIC_IP&gt; (yours will differ, this is what you SSH into)</p><p>• <strong>Private IPv4</strong>: xxx.xxx.xx.x, must be in xxx.xxx.xx.x/24</p><p>• <strong>Instance type</strong>: t3.large</p><p>• <strong>VPC ID</strong>: vpc-xxxxxxxxxxxxxxxxx (snort-lab-vpc)</p><p>• <strong>Subnet ID</strong>: snort-lab-subnet-public1-ap-south-1a</p><p>• <strong>AMI</strong>: Ubuntu jammy-22.04-amd64-server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tmkDkL04P4aGPclP9Jl_WA.png" /></figure><h4>2.4 Configure Security Group for the Sensor</h4><p>This is the most important screen for keeping your lab safe and the most important screen for letting Snort actually see traffic. The Sensor security group needs three inbound rules:</p><p>• <strong>TCP 22 from your IP/32</strong>: so you can SSH in to manage Snort</p><p>• <strong>ICMP from xxx.xxx.xx.x/24</strong>: so the Attacker can ping the Sensor and trigger ICMP rules</p><p>• <strong>All traffic from xxx.xxx.xx.x/24</strong>: so Snort can sniff every protocol the Attacker throws at it, TCP scans, HTTP, DNS, the lot</p><p>Outbound stays at the default, All traffic to 0.0.0.0/0, so apt and wget work for the Snort build.</p><blockquote><strong>⚠ Why never 0.0.0.0/0 on port 22 in production</strong></blockquote><blockquote>A security group with SSH open to the world will see thousands of brute-force login attempts within hours of being created. Bots scan all of AWS continuously. For real deployments, restrict SSH source to your /32 only. During the active lab run we widened it briefly for convenience, narrow it back the moment you’re done.</blockquote><p><strong>Verify the Sensor security group</strong></p><p>Click Security tab in Sensor VM. Three inbound rules should be visible: ICMP from xxx.xxx.xx.x/24, TCP 22 (with whichever source you chose), and All traffic from xxx.xxx.xx.x/24. The “All traffic from /24” rule is what lets Snort’s passive sniffing actually work, without it the AWS hypervisor filters everything before it reaches your NIC.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QP54eytNTxyCHQcLrNRJhQ.png" /></figure><p><strong>Verify the Sensor networking layout</strong></p><p>The Networking tab confirms the layer-3 reality of the VM: the ENI ID, the Public IPv4, the Private IPv4 (must be xxx.xxx.xx.x), the Public DNS name, and the Elastic IP allocation. If the Elastic Network Interface is missing or the Private IPv4 is in the wrong /24, the VM is in the wrong subnet, terminate it and relaunch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*SWLI-v9icT-JAk-AzpIwPA.png" /></figure><h4>2.5 Launch the Attacker EC2</h4><p>Repeat the launch flow with three changes: Name tag = Attacker VM, Instance type = t3.medium, and create a separate security group snort-attacker-sg (single inbound rule TCP 22 from your IP). Keep the Attacker in the same VPC and same subnet as the Sensor, that is what gives both VMs private IPs in the same /28 and lets them talk on .7/.9 without any routing.</p><h4>Verify the Attacker instance summary</h4><p>Same VPC, same subnet, same AMI as the Sensor, only the instance type (t3.medium), the private IP (xxx.xxx.xx.x) and the public IP differ.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-jd62Mx8slHcfLsgZNGgog.png" /></figure><h4>Verify the Attacker security group</h4><p>Now switch to the Attacker → Security tab. The combined view shows: instance ID i-xxxxxxxxxxxxxxxxx, t3.medium, Security group sg-xxxxxxxxxxxxxxxxx (snort-attacker-sg), and a single inbound rule TCP 22 from 0.0.0.0/0 with description “MY IP SSH for snort lab”. This is the Attacker’s isolated SG, the Attacker only needs SSH for you to drive it; it does not need to accept any traffic from the Sensor because Snort is listening, not connecting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*1oQk8ENBrIhsJeK1WtaSbA.png" /></figure><p><strong>Verify the Attacker networking</strong></p><p>Final verification view, Attacker’s Networking tab. ENI eni-xxxxxxxxxxxxxxxxx, Public IPv4 &lt;ATTACKER_PUBLIC_IP&gt;, Private IPv4 xxx.xxx.xx.x, attached to the same VPC and subnet as the Sensor, with its own SNORT ATTACKER VM Elastic IP. Both VMs now sit on the same /28 with private IPs .X and .Y, exactly the configuration our snort.lua HOME_NET = xxx.xxx.xx.x/24 expects.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*T_spdT2Nl9ag713W2tokAQ.png" /></figure><h4>2.6 Verify Both VMs Running, Then SSH In</h4><p>Before opening any terminal, do a final cross-check from EC2 → Instances. Both VMs should be in state Running, both in availability zone ap-south-1a. The public IPv4 column shows the addresses AWS assigned, note these down, you will SSH to them in the next step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KHC8ATd2yVE_W0VEBIUxFw.png" /></figure><p><strong>Allocate Elastic IPs (recommended)</strong></p><p>Public IPs assigned by EC2 change every time you stop the VM. If you want a stable address you can always SSH to, and avoid having to update commands every time you restart the lab, allocate an Elastic IP from EC2 → Elastic IPs and associate it with each instance. Allocating EIPs is free while they’re associated with a running instance; you only pay if they’re sitting idle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*33dXILZHoo8WyCFWLlYOYQ.png" /></figure><p><strong>SSH into both VMs</strong></p><p>On Windows, open PowerShell. On macOS/Linux, open Terminal. The .pem key needs strict permissions, Windows uses icacls, Linux/macOS uses chmod 400.</p><blockquote># Windows (PowerShell), lock down the .pem</blockquote><blockquote>icacls SNORT_SENSOR.pem /inheritance:r</blockquote><blockquote>icacls SNORT_SENSOR.pem /grant:r “$($env:USERNAME):(R)”</blockquote><blockquote># macOS / Linux</blockquote><blockquote>chmod 400 SNORT_SENSOR.pem</blockquote><blockquote># Then SSH in to the Sensor (use the EIP you just allocated)</blockquote><blockquote>ssh -i SNORT_SENSOR.pem ubuntu@&lt;SENSOR_PUBLIC_IP&gt;</blockquote><blockquote># In a second window, SSH into the Attacker</blockquote><blockquote>ssh -i SNORT_ATTACKER.pem ubuntu@&lt;ATTACKER_PUBLIC_IP&gt;</blockquote><p>First connection prompts you to verify the host key fingerprint, type yes. You land in /home/ubuntu on a fresh Ubuntu 22.04 system. Confirm the network interface name (almost always ens5 on AWS Ubuntu, not eth0):</p><blockquote>hostname &amp;&amp; ip a | grep “inet 192”</blockquote><blockquote># Expected output:</blockquote><blockquote># ip-xxx–xxx–xx–x</blockquote><blockquote># inet xxx.xxx.xx.x/28 … scope global dynamic ens5</blockquote><p>First connection prompts you to verify the host key fingerprint, type yes. You land in /home/ubuntu on a fresh Ubuntu 22.04 system. Confirm the network interface name (almost always ens5 on AWS Ubuntu, not eth0):</p><blockquote>hostname &amp;&amp; ip a | grep “inet 192”</blockquote><blockquote># Expected output:</blockquote><blockquote># ip-xxx–xxx–xx–x</blockquote><blockquote># inet xxx.xxx.xx.x/28 … scope global dynamic ens5</blockquote><blockquote><strong>Two SSH sessions, side by side</strong></blockquote><blockquote>Open one terminal window for the Sensor and a second for the Attacker right away. We will need both, often simultaneously, from this point forward. Snap them to the left and right halves of your screen with Win+Left and Win+Right (Windows) or use tmux split panes.</blockquote><blockquote><strong>✓ Cloud foundation verified</strong></blockquote><blockquote>Two EC2 instances running in the same /28 subnet of a custom VPC, each with its own security group, each with an Elastic IP, both reachable over SSH from your laptop. The cloud layer is now done, every command from Lab 1 onwards happens inside these VMs.</blockquote><h3>3. Environment &amp; Architecture</h3><p>You have the cloud foundation in place. Now picture the shape of what you just built and what you’re going to put on top of it. Two virtual machines, one VPC, one direction of attack, two log files. That’s the whole lab.</p><h4>3.1 Full Stack Architecture Diagram</h4><p>Two EC2 instances live inside a single private subnet (xxx.xxx.xx.x/24) in the AWS Mumbai region (ap-south-1). The Attacker generates network traffic, pings, port scans, brute-force attempts, malicious HTTP requests. The Sensor sits in the same subnet running Snort 3 on the ens5 interface in passive mode, inspecting every packet. When a packet matches a rule, Snort writes a line to alert_fast.txt for humans and a JSON record to alert_json.txt for machines. We read both with standard Linux tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t4zeaIeuAgF_2atzMd3ZLA.png" /></figure><h4>3.2 How Each Component Fits Together</h4><p>A clean mental model of the lab makes every later step obvious. Here is what each piece does and why it matters:</p><p>• <strong>VPC (snort-lab-vpc, xxx.xxx.xx.x/24)</strong>: A private network slice inside AWS. Both VMs sit on the same /24, so traffic between them is true Layer-2 network traffic that Snort can sniff with a libpcap-style DAQ, exactly like a switch span port in a real corporate network.</p><p>• <strong>Sensor VM</strong>: The brain. Runs Snort 3 as a long-lived systemd service, loads ~50,000 rules, watches the ens5 interface 24/7, and writes alerts to disk. Sized t3.large (2 vCPU, 8 GB RAM) because rule compilation and packet capture both want memory.</p><p>• <strong>Attacker VM</strong>: The traffic source. Sized smaller (t3.medium) because nmap and hydra are lightweight. Keeping the attacker on a separate VM is what lets us simulate “external” attacks against the sensor, even though both VMs are in the same VPC, from Snort’s perspective the attacker is just another IP throwing packets at it.</p><p>• <strong>Security Groups</strong>: AWS’s built-in stateful firewall. We allow SSH (port 22) from only your home/office public IP, never from 0.0.0.0/0, so the world cannot brute-force into your lab while it sits idle. All other inbound is denied; all outbound is allowed so apt can fetch packages.</p><p>• <strong>Snort’s ens5 interface</strong>: On AWS Ubuntu, the primary NIC is named ens5 (not eth0, this trips up almost everyone the first time). Snort sniffs this NIC in promiscuous mode.</p><p>• <strong>alert_fast.txt vs alert_json.txt</strong>: Two output files for two audiences. The first is one-line-per-alert plain text that’s perfect for tail -f and grep. The second is structured JSON (one alert per line) that jq can slice into any field.</p><h4>3.3 Hardware Specifications</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*stCr8hax6evvDDCbnhPnkQ.jpeg" /></figure><h4>3.4 Snort Operating Modes</h4><p>Snort can run in three different modes. This blog uses Sniffer briefly and IDS mode throughout. Future Part 2 / Part 3 blogs will introduce IPS mode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*DAUXpRND1Vk73KkzYh8MSg.png" /></figure><blockquote><strong>⚠ ETHICAL USE &amp; COST</strong></blockquote><blockquote>These labs are for educational use inside your own isolated AWS VPC. Never run nmap, hydra, sqlmap or any attack tool against systems you do not own or have written permission to test. Doing so is a crime in most jurisdictions.</blockquote><blockquote>Cost estimate: t3.large + t3.medium ≈ $0.107/hr running. Stop both instances when not in use. Total for completing all labs in the series: roughly $5–10 USD.</blockquote><h3>4. LAB -1 -&gt; Snort 3 Installation</h3><p>Goal of this lab: by the time you finish, you should have Snort 3.3.7.0 running as a systemd daemon on the Sensor, with the Talos community rule set loaded, and the first real alerts streaming into /var/log/snort/alert_fast.txt. Roughly 3 hours of work. Most of it is one-time setup you never repeat.</p><h4>4.1 System Preparation on the Sensor</h4><p>First, update Ubuntu and install every package Snort and libDAQ need to compile. We are going to compile from source rather than install a distro package because: (a) Ubuntu’s apt repositories ship Snort 2.9, Snort 3 is a complete rewrite and is not in the default repos at the time of writing, and (b) building from source means you control the version, the optimisation flags, and the modules.</p><p><strong>Update the OS</strong></p><blockquote>sudo apt update &amp;&amp; sudo apt upgrade -y</blockquote><p>Take care: apt upgrade may pull a new kernel, which would normally trigger a reboot prompt. If you see “*** System restart required ***”, run sudo reboot, wait one minute, and SSH back in.</p><p><strong>Install build dependencies</strong></p><p>This is one big apt install. Read the package list carefully, every name is there for a reason. The first row of packages handles the C/C++ toolchain. The libpcap, libpcre3, libdumbnet, bison and flex group are required by Snort’s rule parser and packet decoder. The libnetfilter-queue, libnfnetlink, and libmnl trio enables NFQ, needed only when we later put Snort in inline IPS mode in a future lab. libgoogle-perftools-dev gives us TCMalloc, a faster malloc that Snort uses when compiled with — enable-tcmalloc.</p><blockquote>sudo apt install -y \</blockquote><blockquote>build-essential autotools-dev cmake pkg-config git wget curl \</blockquote><blockquote>libpcap-dev libpcre3-dev libdumbnet-dev bison flex \</blockquote><blockquote>zlib1g-dev liblzma-dev openssl libssl-dev libnghttp2-dev \</blockquote><blockquote>libunwind-dev cpputest libsqlite3-dev luajit libluajit-5.1-dev \</blockquote><blockquote>libhwloc-dev tcpdump net-tools \</blockquote><blockquote>libnetfilter-queue-dev libnfnetlink-dev libmnl-dev \</blockquote><blockquote>libgoogle-perftools-dev</blockquote><p>Watch for the install pulls roughly 200 MB of additional packages and creates the directory structure under /usr/include and /usr/lib that the Snort build will look for. If any single package fails to install, fix it before moving on, Snort’s configure_cmake.sh stops at the first missing dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S5NuAF-941Cb2yENzYRXiA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*le89CnVZzqc_ORc0IZMzEg.png" /></figure><h4>4.2 Install libDAQ 3.0.17</h4><p>libDAQ (Data Acquisition library) is the abstraction layer that lets Snort read packets from many different sources, libpcap files, AF_PACKET sockets, NFQ queues, etc., through a single API. Snort 3.3.7.0 requires libDAQ 3.0.16 or newer. The original lab guide pinned 3.0.14, which produces a confusing “DAQ_PktHdr_t was not declared in this scope” error halfway through the Snort compile, we go straight to 3.0.17 to dodge it.</p><p><strong>Download, configure, build, install</strong></p><blockquote>cd /tmp</blockquote><blockquote>wget <a href="https://github.com/snort3/libdaq/archive/refs/tags/v3.0.17.tar.gz">https://github.com/snort3/libdaq/archive/refs/tags/v3.0.17.tar.gz</a></blockquote><blockquote>tar xzf v3.0.17.tar.gz &amp;&amp; cd libdaq-3.0.17</blockquote><blockquote>./bootstrap</blockquote><blockquote>./configure — enable-afpacket-module</blockquote><blockquote>make -j$(nproc)</blockquote><blockquote>sudo make install &amp;&amp; sudo ldconfig</blockquote><p>What is happening at each step: ./bootstrap regenerates the autotools scripts./configure detects your system’s capabilities and writes a Makefile, make compiles the C source into object files and links them into shared libraries, make install copies the .so files into /usr/local/lib, and ldconfig refreshes the loader cache so the system knows about the new libraries.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/994/1*W_CjAqv36kEHITkrv5W_5Q.jpeg" /></figure><p><strong>Verify libDAQ installation</strong></p><blockquote>ldconfig -p | grep daq</blockquote><blockquote>ls -la /usr/local/lib/libdaq.so*</blockquote><p>Expect to see libdaq.so.3 → libdaq.so.3.0.17 → /usr/local/lib/libdaq.so.3.0.17. The chain of three symlinks is the standard Linux SO-name versioning scheme, it lets multiple libDAQ versions coexist if you ever needed them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0dsHOzVEXVVmYwV6Dr4fpw.jpeg" /></figure><h4>4.3 Build &amp; Install Snort 3.3.7.0</h4><p>Now the main event. Snort 3 uses CMake (via a thin wrapper called configure_cmake.sh). The build takes ten to fifteen minutes on a t3.large. Use make -j$(nproc) so all available CPUs work in parallel.</p><p><strong>Download and configure</strong></p><blockquote>cd /tmp</blockquote><blockquote>wget <a href="https://github.com/snort3/snort3/archive/refs/tags/3.3.7.0.tar.gz">https://github.com/snort3/snort3/archive/refs/tags/3.3.7.0.tar.gz</a></blockquote><blockquote>tar xzf 3.3.7.0.tar.gz &amp;&amp; cd snort3–3.3.7.0</blockquote><blockquote>./configure_cmake.sh — prefix=/usr/local — enable-tcmalloc</blockquote><p>— prefix=/usr/local installs binaries to /usr/local/bin/snort and config to /usr/local/etc/snort/. — enable-tcmalloc tells Snort to link against Google’s TCMalloc allocator, measurable speed improvement on heavy rule sets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMlvIGo5-gDPONAhK4qY9Q.png" /></figure><p>At the end of configure, you should see a printed summary listing libDAQ Version: 3.0.17, OpenSSL, LuaJIT, Hyperscan, and feature flags. If it says “libDAQ &lt; 3.0.16”, you are still pointing at the old libDAQ, fix the symlinks before continuing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AWUtIQhb9VEl1gVBF-b5cA.png" /></figure><p><strong>Compile and install</strong></p><blockquote>cd build &amp;&amp; make -j$(nproc)</blockquote><blockquote>sudo make install &amp;&amp; sudo ldconfig</blockquote><p>A t3.large with 2 vCPUs takes ~12 minutes for this. You will see hundreds of “Building CXX object” lines stream past, that’s every .cc file in the project being compiled. The final progress milestone is “[100%] Built target snort2lua”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*ZIe7BU4R3Z8gwUYqfDL3_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oIu8GfIg8FNZK2I-SUCmzA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*IOTsqB36CPOYb-aDvv-UhQ.png" /></figure><p><strong>Verify Snort installation</strong></p><blockquote>snort — version</blockquote><p>Expected output below. Note the DAQ version (3.0.17, confirms libDAQ wired in correctly), libpcap (1.10.1), LuaJIT (2.1.0-beta3), OpenSSL (3.0.2), PCRE (8.39), and ZLIB (1.2.11). If snort — version says “command not found”, run hash -r in your shell to refresh PATH after the install.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*cC31xaOiXSX2doyMD6eozA.png" /></figure><blockquote><strong>✓ Stack proven</strong></blockquote><blockquote>If snort — version prints cleanly with DAQ 3.0.17, you have crossed the hardest part of Lab 1. Everything from here is configuration, not compilation.</blockquote><h4>4.4 Download Rules and Write snort.lua</h4><p>Snort without rules is just a packet sniffer. Rules are the signatures that define “what bad looks like”. The Talos team at Cisco maintains a free community rule set with several thousand signatures covering common malware, exploits, and reconnaissance patterns. We download it, then write the master snort.lua config that ties everything together.</p><p><strong>Make directories and download rules</strong></p><blockquote>sudo mkdir -p /usr/local/etc/snort/rules /var/log/snort</blockquote><blockquote>sudo chown -R ubuntu:ubuntu /var/log/snort</blockquote><blockquote>cd /tmp</blockquote><blockquote>wget <a href="https://www.snort.org/downloads/community/snort3-community-rules.tar.gz">https://www.snort.org/downloads/community/snort3-community-rules.tar.gz</a></blockquote><blockquote>tar xzf snort3-community-rules.tar.gz</blockquote><blockquote>sudo cp snort3-community-rules/snort3-community.rules /usr/local/etc/snort/rules/</blockquote><blockquote>sudo touch /usr/local/etc/snort/rules/local.rules</blockquote><p>We chown /var/log/snort to the ubuntu user so Snort (which runs as that user) can write to it without sudo. local.rules is empty for now, that’s where our custom rules will go in 4.7.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XBngu1NPK7KdtwuIcd8Kug.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bcuvyoFFOdI1LmijuxCnsg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VN_N5ZTpVKulCmHf3KVaeg.png" /></figure><p><strong>Write the master snort.lua</strong></p><p>snort.lua is the heart of every Snort 3 deployment. It declares network variables (HOME_NET, EXTERNAL_NET), the lists of which ports HTTP/SSH/FTP run on, which protocol inspectors to enable, the IPS detection engine, and the alert outputs. The original lab guide’s minimal config triggers thousands of “Undefined variable” errors because the community rules reference HTTP_PORTS, HTTP_SERVERS, SMTP_SERVERS, etc., the full config below declares all of them explicitly.</p><blockquote>sudo tee /usr/local/etc/snort/snort.lua &gt; /dev/null &lt;&lt; ‘EOF’</blockquote><blockquote>— /usr/local/etc/snort/snort.lua</blockquote><blockquote>— Network variables</blockquote><blockquote>HOME_NET = ‘192.168.10.0/24’</blockquote><blockquote>EXTERNAL_NET = ‘!$HOME_NET’</blockquote><blockquote>— Server lists (community rules reference these)</blockquote><blockquote>HTTP_SERVERS = HOME_NET</blockquote><blockquote>SMTP_SERVERS = HOME_NET</blockquote><blockquote>SQL_SERVERS = HOME_NET</blockquote><blockquote>DNS_SERVERS = HOME_NET</blockquote><blockquote>TELNET_SERVERS = HOME_NET</blockquote><blockquote>SSH_SERVERS = HOME_NET</blockquote><blockquote>FTP_SERVERS = HOME_NET</blockquote><blockquote>SIP_SERVERS = HOME_NET</blockquote><blockquote>— Port lists (community rules reference these)</blockquote><blockquote>HTTP_PORTS = ‘80,81,311,591,593,901,8080,8443,…’ — (full list in source)</blockquote><blockquote>SSH_PORTS = ‘22’</blockquote><blockquote>FTP_PORTS = ‘21,2100,3535’</blockquote><blockquote>include ‘snort_defaults.lua’</blockquote><blockquote>— Protocol inspectors</blockquote><blockquote>http_inspect = { request_depth = 0, response_depth = 0, normalize_utf = true }</blockquote><blockquote>dns = {}</blockquote><blockquote>tls = { ja3 = true }</blockquote><blockquote>ftp_server = {}</blockquote><blockquote>smtp = {}</blockquote><blockquote>— Detection engine</blockquote><blockquote>ips = {</blockquote><blockquote>enable_builtin_rules = true,</blockquote><blockquote>variables = default_variables,</blockquote><blockquote>rules = [[</blockquote><blockquote>include /usr/local/etc/snort/rules/local.rules</blockquote><blockquote>include /usr/local/etc/snort/rules/snort3-community.rules</blockquote><blockquote>]]</blockquote><blockquote>}</blockquote><blockquote>— alert_fast for human-readable plain-text log</blockquote><blockquote>alert_fast = { file = true, packet = false }</blockquote><blockquote>— alert_json for machine-parseable structured output</blockquote><blockquote>alert_json = {</blockquote><blockquote>file = true,</blockquote><blockquote>fields = ‘timestamp, msg, priority, class, src_addr, src_port, dst_addr, dst_port, proto, sid, rev, action’</blockquote><blockquote>}</blockquote><blockquote>unified2 = { }</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kW6NicwMvuuu8Csm1pFImw.png" /></figure><h4>Validate the configuration</h4><blockquote>sudo snort -c /usr/local/etc/snort/snort.lua -T</blockquote><p>The -T flag puts Snort in test/lint mode: it loads the config and rules, validates everything, prints statistics, and exits. No packet capture happens. Look for these milestones at the end:</p><p>• <strong>rule counts</strong>: roughly 4,646 total rules loaded, community + builtin</p><p>• <strong>pcap DAQ configured to passive</strong>: confirms DAQ wired correctly</p><p>• <strong>Snort successfully validated the configuration (with 0 warnings).</strong>: the line you want to see</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jOSy-uTPeCv0nOkWJSLN1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0e0jC-xiputdq6scKaN3Lg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03ZxlPzdg3PAw9K-1yT7FA.png" /></figure><blockquote><strong>⚠ If validation fails</strong></blockquote><blockquote>The error message points to a line number. Common causes: a typo in HOME_NET (must be a string literal in single quotes), missing comma in a port list, or a stray backslash. Fix and rerun snort -T until you get 0 warnings, only then move to systemd.</blockquote><h4>4.5 Configure the systemd Service</h4><p>Running snort by hand is fine for testing, but a real deployment needs auto-start at boot, auto-restart on crash, and clean logging. systemd handles all three.</p><p><strong>Write the unit file</strong></p><blockquote>sudo tee /etc/systemd/system/snort3.service &gt; /dev/null &lt;&lt; ‘EOF’</blockquote><blockquote>[Unit]</blockquote><blockquote>Description=Snort 3 IDS Daemon</blockquote><blockquote>After=network.target</blockquote><blockquote>Wants=network-online.target</blockquote><blockquote>[Service]</blockquote><blockquote>Type=simple</blockquote><blockquote>ExecStart=/usr/local/bin/snort -c /usr/local/etc/snort/snort.lua -i ens5 \</blockquote><blockquote>-A alert_fast -l /var/log/snort/ -D -q</blockquote><blockquote>ExecReload=/bin/kill -HUP $MAINPID</blockquote><blockquote>Restart=on-failure</blockquote><blockquote>RestartSec=5</blockquote><blockquote>[Install]</blockquote><blockquote>WantedBy=multi-user.target</blockquote><blockquote>EOF</blockquote><blockquote>Decoding the ExecStart flags: -c the config file, -i the interface (ens5), -A alert_fast tells Snort to write alerts in fast format, -l /var/log/snort/ is the log directory, -D daemonises, -q quiets startup banner. Restart=on-failure with RestartSec=5 means systemd will restart Snort five seconds after any crash.</blockquote><p><strong>Enable, start, verify</strong></p><blockquote>sudo systemctl daemon-reload</blockquote><blockquote>sudo systemctl enable snort3</blockquote><blockquote>sudo systemctl start snort3</blockquote><blockquote>sudo systemctl status snort3 — no-pager</blockquote><p>You want to see Loaded: loaded … enabled and Active: active (running) in green. Memory usage will hover around 50 MB while idle.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*44EDmwncOUkuJNTMsZaDHQ.png" /></figure><h4>4.6 Prepare the Attacker VM</h4><p>Switch to your second SSH window, the Attacker. We install the offensive toolkit: nmap (port scanning), hping3 (custom packet crafting), hydra (brute force), nikto (web server scanner), sqlmap (SQL injection), tcpdump (packet capture), plus the usual networking utilities.</p><blockquote>ssh -i your-key.pem ubuntu@&lt;ATTACKER_PUBLIC_IP&gt;</blockquote><blockquote>sudo apt update</blockquote><blockquote>sudo apt install -y nmap hping3 hydra nikto sqlmap tcpdump curl wget git net-tools</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*YyDIADK75pEcCr35be1Yow.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*maAE5BY-oe9uVH0D2D978A.png" /></figure><p><strong>Verify network reachability</strong></p><blockquote>ip addr show ens5 | grep inet</blockquote><blockquote>ping -c 3 xxx.xxx.xx.x</blockquote><blockquote>nmap — version | head -1</blockquote><p>You should see the Attacker’s own private IP (xxx.xxx.xx.x in our build), three successful pings to the Sensor with sub-millisecond RTTs (because they’re on the same subnet), and Nmap version 7.80.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*82solVXadluy01f7uQUn5w.png" /></figure><h4>4.7 Generate Your First Alert</h4><p>Time for the payoff. We’re going to add four custom rules to local.rules, simple ones that detect ICMP, SSH, SYN scans, and HTTP. Then we restart Snort, run a tail -f on the alert file, fire some traffic from the Attacker, and watch alerts appear within milliseconds.</p><p><strong>Write four lab rules</strong></p><blockquote>sudo tee /usr/local/etc/snort/rules/local.rules &gt; /dev/null &lt;&lt; ‘EOF’</blockquote><blockquote># Lab 1 verification rules</blockquote><blockquote>alert icmp any any -&gt; $HOME_NET any (msg:”ICMP Ping Detected”; sid:1000001; rev:1;)</blockquote><blockquote>alert tcp any any -&gt; $HOME_NET 22 (msg:”SSH Connection Attempt”; flow:to_server; sid:1000002; rev:1;)</blockquote><blockquote>alert tcp any any -&gt; $HOME_NET any (msg:”Nmap SYN Scan Detected”; flags:S; sid:1000003; rev:1;)</blockquote><blockquote>alert tcp any any -&gt; $HOME_NET 80 (msg:”HTTP Traffic Detected”; sid:1000004; rev:1;)</blockquote><blockquote>EOF</blockquote><blockquote># Validate, then restart Snort to pick up the new rules</blockquote><blockquote>sudo snort -c /usr/local/etc/snort/snort.lua -T</blockquote><blockquote>sudo systemctl restart snort3</blockquote><p>Each rule has the same shape: action protocol src_ip src_port -&gt; dst_ip dst_port (options). The sid (Signature ID) numbers start at 1000001, the convention is that custom rules use SIDs 1,000,000 and above to avoid colliding with vendor SIDs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*pUGt4mHZeYy0sS__-YfZ3g.png" /></figure><p><strong>Watch alerts appear in real time</strong></p><blockquote># On the Sensor (Window 1), leave this running:</blockquote><blockquote>sudo tail -f /var/log/snort/alert_fast.txt</blockquote><blockquote># On the Attacker (Window 2), generate traffic:</blockquote><blockquote>ping -c 30 xxx.xxx.xx.x</blockquote><blockquote>sudo nmap -sS xxx.xxx.xx.x</blockquote><p>In the Sensor window you should see new lines appear within a second of every ping reply and every SYN packet, “ICMP Ping Detected”, “SSH Connection Attempt”, “Nmap SYN Scan Detected” all interleaved. End-to-end detection latency: under 1 millisecond.</p><blockquote><strong>✅ Lab 1 Complete, Stack is Running</strong></blockquote><blockquote>✓ Snort 3.3.7.0 running as a systemd service on interface ens5</blockquote><blockquote>✓ ~4,646 rules loaded (4 custom + 4,021 community + 625 builtin)</blockquote><blockquote>✓ Alerts logged to /var/log/snort/alert_fast.txt and alert_json.txt</blockquote><blockquote>✓ First real alerts visible in real-time terminal tail</blockquote><blockquote>✓ Detection latency under 1 ms</blockquote><h4><strong>4.8 Lab 1 Recap</strong></h4><p>In the space of about three hours you have stood up a real network IDS sensor on cloud infrastructure, compiled the engine and its packet-acquisition library from source, written a complete master configuration, hooked it into systemd for production-grade lifecycle management, and proven end-to-end that it sees traffic and fires alerts. The same artefacts on disk, /usr/local/bin/snort, /usr/local/etc/snort/snort.lua, /var/log/snort/alert_fast.txt, are exactly what an enterprise SOC analyst would touch on a Linux IDS box.</p><h3>5. LAB -2 -&gt; Capturing Traffic &amp; Reading Alerts</h3><p>Goal of this lab: become fluent in the day-to-day skills of an IDS operator. Generate varied traffic, watch alerts appear in real time, capture packets to a PCAP file, replay them offline through Snort, and use grep/awk/jq to slice the alerts in every direction. Roughly 90–120 minutes of hands-on work, all spent in two side-by-side terminal windows.</p><h4>5.1 Two-Window Setup for Live Monitoring</h4><p>From here on you will work with two SSH sessions side by side. The Sensor window stays anchored on a tail -f of the alert file. The Attacker window is where you fire traffic. The split-screen below shows exactly that arrangement.</p><blockquote># WINDOW 1, Sensor, live alert monitor (leave this running)</blockquote><blockquote>sudo tail -f /var/log/snort/alert_fast.txt</blockquote><blockquote># WINDOW 2, Attacker, traffic generator</blockquote><blockquote># (we run different commands here in each block below)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4y-2z848d6sahkvxtMcAQA.png" /></figure><h4>5.2 Generating Varied Traffic (5 Blocks)</h4><p>Each block below produces a different traffic pattern and a different alert signature. Run them one at a time. After each block, glance at the Sensor window to confirm new alerts appeared.</p><p><strong>Block 1, ICMP echo flood</strong></p><blockquote># Attacker:</blockquote><blockquote>ping -c 20 xxx.xxx.xx.x</blockquote><p>Expected: 20 lines of “ICMP Ping Detected” in the Sensor tail, one per echo request. ICMP is the simplest possible test, every IP stack supports it, every Snort install ships with rules that match it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*d0aMgxb5RJk7h28j4eKOfQ.png" /></figure><p><strong>Block 2, TCP SYN port scan</strong></p><blockquote># Attacker:</blockquote><blockquote>sudo nmap -sS -T4 -p 1–1000 xxx.xxx.xx.x</blockquote><p>-sS is a half-open SYN scan, Nmap sends a SYN, watches for SYN-ACK, then resets without completing the handshake. -T4 is the aggressive timing profile (faster but noisier). Across 1000 ports that’s 1000 SYN packets in a few seconds, each of which fires our “Nmap SYN Scan Detected” rule plus several community rules like INDICATOR-SCAN Nmap and PROTOCOL-ICMP rules from the host probing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*CFrGwofq7zdt6Kl1sGgi-g.png" /></figure><p><strong>Block 3, Service version detection</strong></p><blockquote># Attacker:</blockquote><blockquote>sudo nmap -sV -p 22,80,443 xxx.xxx.xx.x</blockquote><p>-sV asks Nmap to actually connect and grab the service banner. Where -sS only knew “port 22 is open”, -sV reveals OpenSSH 8.9p1 Ubuntu 3ubuntu0.14. This kind of probe matches several extra signatures because Snort sees real TCP handshakes and protocol payloads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*eyN_i43_V9vH8vJFc2FfrA.png" /></figure><p><strong>Block 4, DNS query</strong></p><blockquote># Attacker:</blockquote><blockquote>nslookup google.com 8.8.8.8</blockquote><p>A normal recursive DNS lookup against Google’s public resolver. By default this passes through the Sensor’s subnet but doesn’t target the Sensor, yet the Snort DNS inspector still sees the egress traffic and runs DNS-class rules against it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*RPiGpz54DZ1AES2skXWp9Q.png" /></figure><p><strong>Block 5, HTTP request</strong></p><blockquote># Attacker:</blockquote><blockquote>curl <a href="http://192.168.10.9/">http://xxx.xxx.xx.x/</a> -v</blockquote><p>There’s no web server running on the Sensor, so curl gets “Connection refused”, but the SYN packet to port 80 still travels, and our rule matches the SYN. This proves Snort fires alerts based on the attempted connection, not on a successful one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/1*pf0uEZNitCb_VoZSmh3KbA.png" /></figure><p><strong>The combined alert stream</strong></p><p>Glance back at the Sensor tail window. You should now see a colourful mix of all five alert types, SSH Connection Attempt, Nmap SYN Scan Detected, HTTP Traffic Detected, ICMP Ping Detected, interleaved by timestamp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*nnKnh4SZ0foaAoU_Qs64Ag.png" /></figure><blockquote><strong>📌 What to observe</strong></blockquote><blockquote>Each rule fires for a different reason. Watch the {TCP}/{ICMP}/{UDP} protocol marker, the [Priority: N] field (0=none, 1=critical, 2=medium, 3=low), the [1:1000003:1] sid:gid:rev triple, and the source/destination IP:port pair. Reading these fields fluently is the single most valuable Snort skill.</blockquote><h4><strong>5.3 Capturing to a PCAP File</strong></h4><p>Live monitoring is great for proving the system works, but real incident response means capturing packets to disk so you can reanalyse them later with different rules or different tools. tcpdump on the Sensor handles this.</p><blockquote># WINDOW 1 (Sensor), start packet capture in background</blockquote><blockquote>sudo tcpdump -i ens5 -w /var/log/snort/lab2_capture.pcap &amp;</blockquote><blockquote># WINDOW 2 (Attacker), generate mixed traffic</blockquote><blockquote>ping -c 20 xxx.xxx.xx.x</blockquote><blockquote>sudo nmap -sS -T4 xxx.xxx.xx.x</blockquote><blockquote>curl <a href="http://192.168.10.9/">http://xxx.xxx.xx.x/</a></blockquote><blockquote># WINDOW 1 (Sensor), stop the capture</blockquote><blockquote>sudo pkill tcpdump</blockquote><blockquote>ls -lh /var/log/snort/lab2_capture.pcap</blockquote><p>The trailing &amp; runs tcpdump in the background so the shell is still usable. Each tcpdump output line means “I just saw a packet on the wire and wrote it to the file”. When you pkill tcpdump, you should see something like “211 packets captured, 211 packets received by filter, 0 packets dropped by kernel”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*uMVyxrjcgDu6KU2TKs9uzA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/593/1*uQbhLyFlSEsngkjUFrOSpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*arUN-5DPNOQjy5-63FGRNg.png" /></figure><h4><strong>5.4 Replaying the PCAP through Snort</strong></h4><p>PCAP replay is one of Snort’s most useful operational features. You take a captured file and run it back through Snort offline, same rules, same engine, no live network. This is how you test a new rule against historical traffic, or rebuild an alert log after losing it, or share traffic with another analyst who needs to see what you saw.</p><p><strong>Stop live Snort, prepare replay folder, run replay</strong></p><blockquote># Stop live Snort so live + replay alerts don’t mix :</blockquote><blockquote>sudo systemctl stop snort3</blockquote><blockquote># Replay needs a writable output dir</blockquote><blockquote>mkdir -p /tmp/replay_alerts</blockquote><blockquote># Now replay</blockquote><blockquote>sudo snort \</blockquote><blockquote>-c /usr/local/etc/snort/snort.lua \</blockquote><blockquote>-r /var/log/snort/lab2_capture.pcap \</blockquote><blockquote>-l /tmp/replay_alerts \</blockquote><blockquote>-A alert_fast</blockquote><p>Flag breakdown: -c the same config file, -r the PCAP to read (this puts Snort in read-file mode instead of live capture), -l the output log directory, -A alert_fast specifies the alert format. Snort processes every packet in the file, runs all rules against each one, then exits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*DgC59ixxHjcw8yrTgHCi0w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/765/1*iUmyr_FcHcU3tErNRmhCCg.png" /></figure><p><strong>Read the replay alerts and restart live Snort</strong></p><p>At the end of replay, Snort prints a packet statistics block (received, analyzed, dropped) and a module-level breakdown showing how many alerts each rule fired. Then it exits cleanly. Read the resulting alert_fast.txt the same way you read the live one.</p><blockquote>cat /tmp/replay_alerts/alert_fast.txt | head -20</blockquote><blockquote># Restart the live IDS</blockquote><blockquote>sudo systemctl start snort3</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*qsyDnJgnsNLF3QdyQSerVQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IDJ4RU-ZITkjGJPOxY0kpw.png" /></figure><h4>5.5 Filtering Alerts with grep, awk, and sort</h4><p>Snort can produce hundreds of thousands of alert lines a day in production. Reading them all is impossible, operators always filter. The Linux pipeline of grep | awk | sort | uniq -c | sort -rn is the universal Swiss Army knife for log triage. Below are the six most useful patterns. Run each one and watch the answer come back instantly.</p><p><strong>Filter by source IP</strong></p><blockquote>grep “xxx.xxx.xx.x” /var/log/snort/alert_fast.txt | head</blockquote><p><strong>Only ICMP alerts</strong></p><blockquote>grep “{ICMP}” /var/log/snort/alert_fast.txt | head</blockquote><p><strong>Top 10 most-fired rules</strong></p><blockquote>awk -F’”’ ‘{print $2}’ /var/log/snort/alert_fast.txt | \</blockquote><blockquote>sort | uniq -c | sort -rn | head</blockquote><p>How this works: alert_fast.txt has the rule message wrapped in double quotes. awk splits each line on “ characters and prints the second field, that’s the message. Sort groups identical messages, uniq -c counts duplicates, and the final sort -rn ranks the counts in reverse numerical order.</p><h4>Top attacker IPs by hit count</h4><blockquote>grep -oE ‘[0–9]+\.[0–9]+\.[0–9]+\.[0–9]+ -&gt;’ /var/log/snort/alert_fast.txt | \</blockquote><blockquote>sort | uniq -c | sort -rn | head</blockquote><h4>Total alerts</h4><blockquote>sudo wc -l /var/log/snort/alert_fast.txt</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*7pe8r9LJwsYcBMf_6KI1Uw.png" /></figure><blockquote><strong>Why this beats a web UI</strong></blockquote><blockquote>Older Snort guides used the Snorby Ruby-on-Rails web UI to do everything in this section. Snorby is unmaintained since 2015 and won’t build on Ubuntu 22.04. Even if it did, the grep/awk approach is faster, scriptable, scales to terabyte log files, and works over SSH without a browser.</blockquote><h4>5.6 Reading Full Alerts with alert_json + jq</h4><p>alert_fast.txt is great for at-a-glance reading, but it truncates fields and can’t be parsed reliably (because it has no field delimiters). For full structured detail, equivalent to clicking an alert in any modern SIEM, use alert_json.txt and pipe it through jq.</p><blockquote>sudo apt install -y jq</blockquote><blockquote># Pretty-print the most recent 5 alerts</blockquote><blockquote>tail -5 /var/log/snort/alert_json.txt | jq</blockquote><blockquote># Filter: only Priority 1 (critical)</blockquote><blockquote>jq ‘select(.priority == 1)’ /var/log/snort/alert_json.txt | head -50</blockquote><blockquote># Filter: alerts from a specific source IP</blockquote><blockquote>jq ‘select(.src_addr == “xxx.xxx.xx.x”)’ /var/log/snort/alert_json.txt | head -30</blockquote><blockquote># Extract just timestamp + msg + src -&gt; dst</blockquote><blockquote>jq -r ‘“\(.timestamp) \(.msg) \(.src_addr) -&gt; \(.dst_addr):\(.dst_port)”’ \</blockquote><blockquote>/var/log/snort/alert_json.txt | head</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*ELZDRnPJk8s-nCvfUGCXiA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*zgOkGK5P8ONEEEdsAzoZKQ.png" /></figure><h4>5.7 Understanding the alert_fast.txt Format</h4><p>Every line in alert_fast.txt has the same structure. Once you can parse it visually, you can triage incidents at a glance. Take this example line:</p><blockquote>04/28–12:18:24.991188 [**] [1:1000003:1] “Nmap SYN Scan Detected” \</blockquote><blockquote>[**] [Priority: 0] {TCP} xxx.xxx.xx.x:53842 -&gt; xxx.xxx.xx.x:22</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*Pb4P7GfyYcvR4ZjewKHZJg.png" /></figure><h4>5.8 Lab 2 Recap</h4><blockquote><strong>✅ Lab 2 Complete</strong></blockquote><blockquote>✓ Generated five distinct traffic types and watched each fire its own alert</blockquote><blockquote>✓ Captured 90 seconds of live traffic to a PCAP file with tcpdump</blockquote><blockquote>✓ Replayed the PCAP offline and confirmed 2,246 packets / 1,116 alerts re-fired</blockquote><blockquote>✓ Mastered six grep/awk filtering pipelines</blockquote><blockquote>✓ Pretty-printed structured JSON alerts with jq</blockquote><blockquote>✓ Memorised the alert_fast.txt line format</blockquote><p>You now have the operational fluency to run Snort like a SOC analyst, not just install it, but actually use it day to day. The next blog (Part 2) will start writing custom detection rules: SSH brute-force thresholds, SQL injection in URIs, sqlmap user-agent fingerprints, and ten more sophisticated signatures.</p><h3>6. What’s next in Part 2</h3><p>Just when everything starts making sense and every packet has meaning and every alert tells a story, you realize something uncomfortable that Snort is only reacting and telling you what happened but not why it happened or how to stop it intelligently. A deeper question then comes to mind about what will happen if the attacker changes behavior or if the payload does not match any known rule or if the attack looks completely normal but is actually malicious. This is where things become serious because in Part 2 you will not just use rules but you will start thinking like an attacker and writing like a defender while moving from simply watching alerts to designing detections, from basic signatures to context aware rules, and from known threats to identifying unknown patterns. Writing a rule is easy but writing a rule that can detect real attackers without creating noise is a completely different challenge and that is exactly what you are going to face next.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebfea7b079ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[COMPLETE THREAT INTELLIGENCE PIPELINE FROM STIX FEEDS TO LIVING DASHBOARDS]]></title>
            <link>https://medium.com/@adevani20045/complete-threat-intelligence-pipeline-from-stix-feeds-to-living-dashboards-a5c7a56bec60?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5c7a56bec60</guid>
            <category><![CDATA[ioc]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[elk]]></category>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[siem]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Sat, 25 Apr 2026 19:23:38 GMT</pubDate>
            <atom:updated>2026-04-25T19:30:52.213Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part-2</h4><p><em>MISP 2.5 · AWS EC2 · Taxonomies · Feeds · TAXII 2.1 · STIX 2.1 Export</em></p><p>Before diving into the ELK stack, here is a 16-point recap of everything completed in Part 1 on a dedicated AWS EC2 instance (c7i-flex.large · Ubuntu 24.04 · Elastic IP X.XXX.XXX.XXX).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*RXYPG4uJi6aKyJhqk-tRiw.png" /></figure><h4>Key Gotchas from Part 1</h4><blockquote><em>⚠️ Medallion is NOT a systemd service. Restart every session: nohup ~/.local/bin/medallion — host 0.0.0.0 — port 5000 ~/medallion_config.json &gt; ~/medallion.log 2&gt;&amp;1 &amp; If port 5000 in use: pkill -f medallion &amp;&amp; sleep 2 then restart.</em></blockquote><p>• IDS flag must be checked on each MISP attribute, otherwise it will not appear in STIX exports.</p><p>• MISP.live must be true or all API calls return 403 check Administration → Server Settings → MISP.</p><p>• Unpublished events are invisible to the API and STIX exports always click Publish after creating an event.</p><p>MISP Events list before integration showing existing published events (Phishing Campaign, Ransomware, LockBit 3.0) that will be exported to ELK in Part 2:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PdFQvblFfJ1evMbQMqmqdg.png" /></figure><h4>About This Part 2 Blog</h4><p><em>From a single MISP instance to a fully automated, bidirectional ELK pipeline</em></p><p>Welcome to Part 2 of the Complete Threat Intelligence Pipeline series. Part 1 laid the foundation by deploying MISP 2.5 on AWS EC2, configuring taxonomies and Galaxy clusters, enabling external feeds (CIRCL OSINT and Botvrij.eu), and standing up the Medallion TAXII 2.1 server on port 5000. At the end of Part 1 we had a single, isolated MISP node with one published event and zero downstream consumers.</p><p>This Part 2 blog turns that isolated node into a production-grade threat intelligence pipeline. Across eighteen chapters you will provision a second AWS EC2 instance (t3.xlarge, Ubuntu 22.04), install and harden the full Elasticsearch + Kibana + Logstash stack, design an ECS-aligned index for STIX 2.1 indicators, build the Python pipeline that polls MISP via TAXII and writes IOCs into Elasticsearch, construct a multi-panel Kibana dashboard visualising 347,479 indicators, and wire up the reverse pipeline that pushes ELK detections back into MISP as new events. The final chapter automates the entire bidirectional cycle with a systemd timer running every fifteen minutes.</p><p>Every command, every error, and every fix encountered during the live build is documented exactly as it happened. Screenshots are cross-referenced to the original session PDF so you can verify your output against the real lab environment as you follow along.</p><h4>Project Environment &amp; Structure</h4><p>The full pipeline runs across two AWS EC2 instances. The MISP Lab serves curated threat intelligence over TAXII; the ELK Lab indexes incoming indicators into Elasticsearch and surfaces them through Kibana. A pair of Python scripts moves data in both directions on a 15-minute systemd timer, with zero manual intervention once configured.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_F7Ivi4Br6t_l6QsNB2Wg.jpeg" /></figure><p><strong>1. Lab Infrastructure</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*mjMz3KhfpCaqDy41i_5HwQ.png" /></figure><p><strong>2. Pipeline Architecture &amp; Data Flow.</strong></p><p><em>Forward pipeline (MISP → ELK): the TAXII client polls the Medallion server every 15 minutes, parses STIX 2.1 bundles, normalises the indicators into ECS-aligned documents, and bulk-indexes them into Elasticsearch. Kibana surfaces the result.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*QM-sCOrfnS0PkNtMIryZiA.png" /></figure><p><em>Reverse pipeline (ELK → MISP): when a new IOC pattern surfaces in Kibana, elk_to_misp.py packages it and posts it to the MISP REST API, where it becomes a new auto-published event tagged tlp:green and visible to all downstream consumers.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*y_4noeuDDiALQcivx3wx7Q.png" /></figure><p><strong>3. Technology Stack</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*grT0XzN_4D43RMJFTUmqqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9bPpKzIASKeBnkAHNJ-NGA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qIKjTVm9PkwbgEFDA_H6eQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7nkLfv9jh1tWCGqcdT_9oA.jpeg" /></figure><p><strong>🛠️ What You Need Before Starting</strong></p><p>This is a hands-on lab blog not a theoretical overview. You will be running real commands on real AWS infrastructure. Here is what you need:</p><p>• An AWS account with EC2 access two instances will be used (t3.xlarge + c7i-flex.large)</p><p>• Basic Linux command line comfort we use sudo, apt, systemctl, curl throughout</p><p>• Part 1 complete MISP 2.5 installed, at least one published event with IOCs, Medallion TAXII running (Part 0 recap covers this)</p><p>• ~3–4 hours of focused time the full pipeline from blank EC2 instance to 347,479 indexed indicators</p><p>• Patience for errors this blog documents every real error encountered and exactly how it was fixed</p><h4><strong>PART 1 — ELK STACK INSTALLATION</strong></h4><p><strong>Installing Elasticsearch · Kibana · Logstash on AWS EC2</strong></p><p>This section covers the full ELK Stack installation on a fresh t3.xlarge Ubuntu 22.04 instance. Elasticsearch 8.x comes with security enabled by default TLS, authentication, and auto-generated certificates are all set up automatically. This is a significant change from older versions where security was optional.</p><h4>1. AWS Infrastructure Setup</h4><p><strong>1.1.1 EC2 Instance Overview</strong></p><p>Both instances run in ap-south-1 (Mumbai) with permanent Elastic IPs. MISP writes its base URL into the database at install time a changing IP breaks everything.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCnFKd8h8Go0ypMXQpO7Mw.jpeg" /></figure><p><strong>1.1.2 Elastic IP Addresses</strong></p><p>Both MISP (x.xxx.xxx.xxx) and ELK (x.x.xxx.xxx) have permanent Elastic IPs assigned. These never change even after instance restarts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdw7P7rudATcopmDNe_qaA.jpeg" /></figure><p><strong>1.1.3 Security Group Configuration</strong></p><p>Two separate security groups are needed. ELK Lab exposes SSH, HTTPS, and Kibana. MISP Lab additionally needs port 5000 open for Medallion TAXII server connections from ELK Lab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYjZVDfPoDgfIKmwZ8mPog.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HAF5hBnog5XMgylDvkYkhQ.jpeg" /></figure><h4><strong>1.2. Kernel Tuning and System Prerequisites</strong></h4><p><strong>1.2.1 vm.max_map_count and Swap Disable</strong></p><p>Elasticsearch checks vm.max_map_count at startup and refuses to start if it is below 262144. Swap must also be disabled.</p><blockquote>echo “vm.max_map_count=262144” | sudo tee /etc/sysctl.d/99-elasticsearch.conf</blockquote><blockquote>echo “vm.swappiness=1” | sudo tee -a /etc/sysctl.d/99-elasticsearch.conf</blockquote><blockquote>sudo sysctl — system</blockquote><blockquote>sudo swapoff -a</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0zN6eV1EW2inFjKiJ6deWQ.jpeg" /></figure><p>During apt upgrade you will see dialogs these are normal. Click OK to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xqMRqUB63A-mE4sOwuvTHw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x2I7ghIBnk6txk2oHyYTcw.jpeg" /></figure><p><strong>1.2.2 File Descriptor and Memory Lock Limits</strong></p><blockquote>cat &lt;&lt; ‘EOF’ | sudo tee /etc/security/limits.d/50-elasticsearch.conf</blockquote><blockquote>elasticsearch soft nofile 65535</blockquote><blockquote>elasticsearch hard nofile 65535</blockquote><blockquote>elasticsearch soft memlock unlimited</blockquote><blockquote>elasticsearch hard memlock unlimited</blockquote><blockquote>EOF</blockquote><blockquote>sudo mkdir -p /etc/systemd/system/elasticsearch.service.d</blockquote><blockquote>printf ‘[Service]\nLimitMEMLOCK=infinity\nLimitNOFILE=65535\n’ | sudo tee /etc/systemd/system/elasticsearch.service.d/override.conf</blockquote><blockquote>sudo systemctl daemon-reload</blockquote><h4><strong>1.3 Elastic APT Repository</strong></h4><p><strong>1.3.1 System Update and Prerequisites</strong></p><p>Update package lists and install the prerequisites required to add a signed APT repository. Elasticsearch, Kibana, and Logstash will all come from the same Elastic repo.</p><blockquote>sudo apt update &amp;&amp; sudo apt upgrade -y</blockquote><blockquote>sudo apt install -y apt-transport-https curl gnupg</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0kVmD6mts1LU0c2resEGA.jpeg" /></figure><p><strong>1.3.2 Add GPG Key and Repository</strong></p><blockquote>curl -fsSL <a href="https://artifacts.elastic.co/GPG-KEY-elasticsearch">https://artifacts.elastic.co/GPG-KEY-elasticsearch</a> | \</blockquote><blockquote>sudo gpg — dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg</blockquote><blockquote>echo “deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] \</blockquote><blockquote><a href="https://artifacts.elastic.co/packages/8.x/apt">https://artifacts.elastic.co/packages/8.x/apt</a> stable main” | \</blockquote><blockquote>sudo tee /etc/apt/sources.list.d/elastic-8.x.list</blockquote><blockquote>sudo apt update</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4a94xoBcHmhJMLfEcfAR2Q.jpeg" /></figure><h4><strong>1.4 Installing Elasticsearch 8.x</strong></h4><p><strong>1.4.1 Installation and Auto-Generated Password</strong></p><blockquote>sudo apt install -y elasticsearch</blockquote><blockquote><em>⚠️ The auto-generated elastic superuser password is highlighted in the install output. SAVE IT IMMEDIATELY — shown only once. Also written to /var/log/elasticsearch install log.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QFcqEUB9xMuEo4FXxSgGyg.jpeg" /></figure><p>When the install completes, Elasticsearch has already auto-configured TLS for both the HTTP and transport layers, created a CA certificate, and generated an enrollment token for Kibana. This is the biggest change from Elasticsearch 7.x in version 8.x you cannot skip security even for a lab. The auto-configuration handles it all.</p><p><strong>1.4.2 elasticsearch.yml Configuration</strong></p><p>Edit /etc/elasticsearch/elasticsearch.yml for single-node lab operation:</p><blockquote>cluster.name: elk-lab</blockquote><blockquote>node.name: elk-node-1</blockquote><blockquote>path.data: /var/lib/elasticsearch</blockquote><blockquote>path.logs: /var/log/elasticsearch</blockquote><blockquote>network.host: localhost</blockquote><blockquote>http.port: 9200</blockquote><blockquote>discovery.type: single-node</blockquote><blockquote>bootstrap.memory_lock: true</blockquote><blockquote>xpack.security.enabled: true # ON by default in 8.x — keep it</blockquote><p><strong>1.4.3 JVM Heap Settings</strong></p><p>Create /etc/elasticsearch/jvm.options.d/heap.options — give ES half of available RAM, capped at 31 GB:</p><blockquote>-Xms8g # For 16 GB instance</blockquote><blockquote>-Xmx8g</blockquote><p><strong>1.4.4 Enable and Start</strong></p><blockquote>sudo systemctl daemon-reload</blockquote><blockquote>sudo systemctl enable elasticsearch &amp;&amp; sudo systemctl start elasticsearch</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V6xLokNeYxXj7NsEYxym1A.jpeg" /></figure><h4><strong>1.5 Resetting Password and Verifying Cluster Health</strong></h4><p><strong>1.5.1 Resetting the Superuser Password</strong></p><p>If the install-time password was not saved (common after session restart), reset it interactively using the built-in tool:</p><blockquote>sudo /usr/share/elasticsearch/bin/elasticsearch-reset-password -u elastic -i</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoYL1oQCZdRDbTDU9-KVjg.jpeg" /></figure><p><strong>1.5.2 Verifying Cluster Health</strong></p><p>Confirm Elasticsearch is running and the cluster is healthy before proceeding to Kibana installation:</p><blockquote>curl -k -u elastic:Elastic123 <a href="https://localhost:9200/_cluster/health?pretty">https://localhost:9200/_cluster/health?pretty</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FsD0Pz8Crvk-LEDFwoNl-A.jpeg" /></figure><h4><strong>1.6. Installing Kibana</strong></h4><p><strong>1.6.1 Installation</strong></p><p>Install Kibana from the Elastic APT repository. The package fetches ~407 MB and automatically creates the kibana user, group, and keystore.</p><blockquote>sudo apt install -y kibana</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JkBRd0KjTQvV1zziRTPdw.jpeg" /></figure><p><strong>1.6.2 kibana.yml Configuration</strong></p><blockquote>sudo tee -a /etc/kibana/kibana.yml &lt;&lt; ‘EOF’</blockquote><blockquote>server.port: 5601</blockquote><blockquote>server.host: “0.0.0.0”</blockquote><blockquote>server.name: “elk-lab-kibana”</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6ZgP7AubSMQ9-ACKOe_Cw.jpeg" /></figure><blockquote>sudo /usr/share/elasticsearch/bin/elasticsearch-create-enrollment-token -s kibana</blockquote><blockquote>sudo systemctl enable kibana &amp;&amp; sudo systemctl start kibana</blockquote><blockquote><em>⚠️ Kibana enrollment tokens expire after 30 minutes. Generate the token immediately before starting Kibana for the first time.</em></blockquote><p><strong>1.6.3 First Login</strong></p><p>Navigate to <a href="http://3.6.111.162:5601,">http://3.6.111.162:5601,</a> accept self-signed cert warning, paste enrollment token, then log in with elastic and the auto-generated password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRiQOCnkplPS9SEclhRy-g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amiK7SaJZet1LLj5jDGDPA.jpeg" /></figure><h4><strong>1.7. Installing Logstash</strong></h4><p><strong>1.7.1 Installation and Configuration</strong></p><blockquote>sudo apt install -y logstash</blockquote><p>Set Logstash heap in /etc/logstash/jvm.options to prevent memory pressure alongside Elasticsearch and Kibana:</p><blockquote>-Xms1g # /etc/logstash/jvm.options</blockquote><blockquote>-Xmx1g</blockquote><p><strong>1.7.2 Enable, Start, and Verify</strong></p><blockquote>sudo systemctl enable logstash &amp;&amp; sudo systemctl start logstash</blockquote><p>Verify Logstash is running. Note: port 9600 (Logstash monitoring API) may show connection refused initially restart resolves this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBcvY104llp9W3xrSTS0oQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BPkachjzbbnGllqW7F_9OQ.jpeg" /></figure><h4><strong>1.8 Python Environment and Libraries</strong></h4><p><strong>1.8.1 Python venv Setup</strong></p><p>Install Python tooling and create an isolated virtual environment for the STIX/TAXII pipeline so its dependencies do not conflict with system packages.</p><blockquote>sudo apt install -y python3 python3-pip python3-venv</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*myFa3qvgnp8IvpwIyusDBw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5js-37AQmS32gd5H7mN6JA.jpeg" /></figure><blockquote>sudo mkdir -p /opt/ti-poller &amp;&amp; sudo chown ubuntu:ubuntu /opt/ti-poller</blockquote><blockquote>python3 -m venv /opt/ti-poller/venv</blockquote><blockquote>source /opt/ti-poller/venv/bin/activate</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*anQFt4APgyZKk5BjjiuKDQ.jpeg" /></figure><p><strong>1.8.2 Install Libraries</strong></p><p>pip install stix2 taxii2-client elasticsearch requests</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tR8v-S_jXiFR214F5eBVQ.jpeg" /></figure><h4><strong>PART 2 — STIX/TAXII PIPELINE AND KIBANA</strong></h4><p>With ELK running, this section connects it to actual threat intelligence data. The most important architectural decision here is the index mapping specifically using ECS (Elastic Common Schema) field names like threat.indicator.ip and threat.indicator.type. This is not just a naming convention: it unlocks Elastic Security’s native indicator match rules, which cross-reference live event data against your threat intel automatically.</p><p>One real gotcha is documented here: the MITRE ATT&amp;CK TAXII server connection timed out during testing this is an access restriction on their end, not a pipeline bug. The solution was to use sample data first to verify the pipeline works end-to-end, then switch to MISP as the live TAXII source.</p><h4><strong>2.1 Elasticsearch Index Design and STIX Ingestion</strong></h4><p><strong>2.1.1 ECS-Aligned Index Mapping</strong></p><p>Align with ECS threat.indicator.* fields to unlock Elastic Security’s native indicator match rules. The ip field type enables CIDR-range queries; geo_point enables Kibana Maps.</p><blockquote>PUT threat-intel-indicators</blockquote><blockquote>{</blockquote><blockquote>“mappings”: { “properties”: {</blockquote><blockquote>“@timestamp”: { “type”: “date” },</blockquote><blockquote>“threat.indicator.type”: { “type”: “keyword” },</blockquote><blockquote>“threat.indicator.ip”: { “type”: “ip” },</blockquote><blockquote>“threat.indicator.domain”: { “type”: “keyword” },</blockquote><blockquote>“threat.indicator.geo.location”: { “type”: “geo_point” },</blockquote><blockquote>“threat.indicator.confidence”: { “type”: “keyword” },</blockquote><blockquote>“threat.feed.name”: { “type”: “keyword” }</blockquote><blockquote>} }</blockquote><blockquote>}</blockquote><blockquote><em>⚠️ Map geo_point BEFORE indexing any documents. Auto-mapping creates an ‘object’ type that Kibana Maps cannot use. If documents were indexed first, delete the index, recreate with explicit mapping, and re-run the pipeline.</em></blockquote><p><strong>2.1.2 TAXII Compatibility and Version Fix</strong></p><p>Initial test used the MITRE ATT&amp;CK TAXII server connection timed out because MITRE restricts access. When switching to local sample data, an elasticsearch library version mismatch caused HTTP 400 errors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xHuiUxPT-GeuiezwJZCEUw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1uXq0harArjnzSo2BKHTdQ.jpeg" /></figure><p><strong>2.1.3 Initial Test — Indexed 3 STIX 2.1 Indicators</strong></p><p>After fixing the library version, the ingestion script ran successfully and indexed 3 sample STIX 2.1 indicators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*93xPjGEgUCy6udCeymqJTA.jpeg" /></figure><p><strong>2.1.4 GeoIP Ingest Pipeline</strong></p><p>Set up a GeoIP ingest pipeline to automatically enrich IP indicators with geolocation data. The geo_point field must already be mapped in the index before this pipeline runs.</p><blockquote>PUT _ingest/pipeline/threat-intel-geoip</blockquote><blockquote>{</blockquote><blockquote>“description”: “Enrich IP indicators with geolocation”,</blockquote><blockquote>“processors”: [{</blockquote><blockquote>“geoip”: {</blockquote><blockquote>“field”: “threat.indicator.ip”,</blockquote><blockquote>“target_field”: “threat.indicator.geo”,</blockquote><blockquote>“ignore_missing”: true,</blockquote><blockquote>“properties”: [“country_iso_code”,”country_name”,”city_name”,”location”]</blockquote><blockquote>}</blockquote><blockquote>}]</blockquote><blockquote>}</blockquote><blockquote><em>ℹ️ Elasticsearch uses bundled MaxMind GeoLite2 databases that auto-update every 3 days. The location field must be geo_point in the mapping — it cannot be auto-detected and will silently fail if the mapping is wrong.</em></blockquote><p><strong>2.1.5 systemd Timer for Automated Polling</strong></p><p>A systemd timer was set up to replace cron for pipeline scheduling better logging, dependency management, and persistent catch-up.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SXRGYDWGSrMZTJc7Og2-Cw.jpeg" /></figure><h4><strong>2.2 Kibana Data View and Dashboard Construction</strong></h4><p><strong>2.2.1 Create Data View (threat-intel-indicators*)</strong></p><p>Stack Management → Data Views → Create data view. Index pattern: threat-intel-indicators*. Time field: @timestamp. This enables Kibana’s time picker for all visualizations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dqlEFefWRRwv8WNl2pb_dA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OVAFizRa5QdG3Re-G6edbw.jpeg" /></figure><p><strong>2.2.2 Panel 1 — Total IOC Count (Metric)</strong></p><p>Security → Dashboards → Create dashboard → Create visualization → Select Metric type. Drag Records to Primary metric. This shows the live total count of all indexed indicators.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0RV5grtHWutATpVmAXzJLw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MFs6JQabNdxbxKAuz2fpPA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4WoB9qI-tQDKNoItV09flQ.jpeg" /></figure><p><strong>2.2.3 Panel 2 — IOC Type Distribution (Pie)</strong></p><p>Create visualization → Pie type. Slice by: Top 5 values of threat.indicator.type. This shows proportional split across IP, domain, hash, URL types.</p><p><em>(Pie chart panel configuration follows same Kibana Lens workflow as the bar chart shown below)</em></p><p><strong>2.2.4 Panel 3 — Timeline (Area Chart)</strong></p><p>Create visualization → Line/Area type. X-axis: @timestamp (date histogram, daily). Y-axis: Count of records. Breakdown by: threat.feed.name. Reveals feed activity spikes.</p><p><strong>2.2.5 Panel 4 — Feed Breakdown (Bar Chart)</strong></p><p>Create visualization → Bar type. Horizontal axis: Top 5 values of threat.feed.name. Vertical axis: Count of records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fmK40a1eLYJdmH_XY4z2fQ.jpeg" /></figure><p><strong>2.2.6 Explore in Discover</strong></p><p>Set time range to Last 1 year. Navigate to Discover and select the threat-intel-indicators* data view to see all indexed indicators with their ECS fields.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KjY6c6tci-2nqdActgL6xA.jpeg" /></figure><p><strong>2.2.7 Save Under Security Solution Tag</strong></p><p>When saving the dashboard, add the tag ‘Security Solution’. The dashboard then appears in Security → Dashboards alongside built-in Elastic Security dashboards.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-xCCPGvxQc-Ic4cYhi8wA.jpeg" /></figure><h4><strong>PART 3 — MISP-\ELK BIDIRECTIONAL INTEGRATION</strong></h4><p><strong>MISP 2.5 Bidirectional ELK Pipeline</strong></p><p><em>Forward · Reverse · Automation · 347,479 Indicators · MISP Events #1989–1991</em></p><h4><strong>3.1. Verify Both Systems at Session Start</strong></h4><p><strong>3.1.1 ELK Lab Elasticsearch and Kibana</strong></p><blockquote>sudo systemctl status elasticsearch kibana</blockquote><blockquote>curl -k -u elastic:Elastic123 <a href="https://localhost:9200/_cluster/health?pretty">https://localhost:9200/_cluster/health?pretty</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MCKsr0QT40ef4Lbt6M1EQA.jpeg" /></figure><p><strong>3.1.2 MISP Lab Medallion TAXII Server</strong></p><p>Medallion must be started manually every session — it is NOT a systemd service.</p><blockquote>pkill -f medallion 2&gt;/dev/null; sleep 2</blockquote><blockquote>nohup ~/.local/bin/medallion — host 0.0.0.0 — port 5000 ~/medallion_config.json &gt; ~/medallion.log 2&gt;&amp;1 &amp;</blockquote><blockquote>curl -u admin:Password0 -H ‘Accept: application/taxii+json;version=2.1’ <a href="http://localhost:5000/taxii2/">http://localhost:5000/taxii2/</a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3tBRyoOva2-lCXT6OHusg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*HARr-KmaFP3Lt1bxJK2ztg.jpeg" /></figure><h4><strong>3.2 Install Pipeline Dependencies</strong></h4><p><strong>3.2.1 Python Libraries</strong></p><p>Install the three Python libraries the forward and reverse pipelines rely on: pymisp to talk to the MISP REST API, elasticsearch for bulk indexing, and requests for raw HTTP calls.</p><blockquote>pip3 install pymisp elasticsearch requests</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a1kUwHgczOo25TQH59VZXA.jpeg" /></figure><p>If you see a media_type_header_exception (HTTP 400) when the pipeline first runs, it means the elasticsearch-py library version is too new. Fix by downgrading to match the server version:</p><blockquote>pip install elasticsearch==8.17.0</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yya19Docyc1vJFMCkn5nXQ.jpeg" /></figure><p><strong>3.2.2 Fix — elasticsearch Library Version Mismatch</strong></p><p>If the pipeline produces a BadRequestError HTTP 400 ‘media_type_header_exception’, the elasticsearch-py client version is incompatible with the server. Fix by pinning to the matching version:</p><blockquote>pip install elasticsearch==8.17.0</blockquote><blockquote><em>⚠️ This version mismatch happens because pip installs the latest elasticsearch library (9.x) which sends a different Accept header than Elasticsearch 8.x expects. Always pin to elasticsearch==8.17.0 for ES 8.x servers.</em></blockquote><p><strong>3.2.3 Credentials File (.env)</strong></p><blockquote>sudo mkdir -p /opt/ti-pipeline &amp;&amp; sudo chown ubuntu:ubuntu /opt/ti-pipeline</blockquote><blockquote>sudo tee /opt/ti-pipeline/.env &lt;&lt; ‘EOF’</blockquote><blockquote>MISP_URL=https://3.111.190.100</blockquote><blockquote>MISP_KEY=&lt;your-misp-api-key&gt;</blockquote><blockquote>TAXII_URL=http://3.111.190.100:5000</blockquote><blockquote>TAXII_USER=admin</blockquote><blockquote>TAXII_PASS=Password0</blockquote><blockquote>ES_URL=https://localhost:9200</blockquote><blockquote>ES_USER=elastic</blockquote><blockquote>ES_PASS=Elastic123</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_jn38iy8UVLJhYxVFknsbg.jpeg" /></figure><h4><strong>3.3 Forward Pipeline — MISP to Elasticsearch</strong></h4><p><strong>3.3.1 Script: misp_to_elk.py</strong></p><p>The script reads last_id.txt, queries MISP for new published events, exports each as STIX 2.1 via restSearch, maps to ECS fields, and bulk-indexes into Elasticsearch.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EkOcNJOa70FnxVn7WXiCIA.jpeg" /></figure><p>First run of misp_to_elk.py hit a BadRequestError elasticsearch library version 9.3.0 was incompatible with ES 8.x. Fix: downgrade to elasticsearch==8.17.0, then reset ES password.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yya19Docyc1vJFMCkn5nXQ.jpeg" /></figure><blockquote><em>⚠️ Critical bug in timer context: MISP API returns a dict when called by systemd but a list during manual runs. Fix: raw = r.json(); events = raw if isinstance(raw,list) else raw.get(‘response’,[])</em></blockquote><p><strong>3.3.2 First Run — 1,974 Events Processed</strong></p><blockquote>echo ‘0’ &gt; /opt/ti-pipeline/last_id.txt</blockquote><blockquote>cd /opt/ti-pipeline &amp;&amp; export $(cat .env | grep -v ^# | xargs) &amp;&amp; python3 misp_to_elk.py</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xDbHGJrVFXr3rFsQcW-cA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GIVJAJQE8RfS07T4coYrew.jpeg" /></figure><p><strong>3.3.3 Final Count — 37,442 Documents Indexed</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1X5J5yblwZBQK944NKTGMg.jpeg" /></figure><p>The pipeline processed 1,974 MISP events in a single run iterating through each one, calling the restSearch STIX 2.1 export endpoint, parsing the response, mapping each indicator to ECS fields, and bulk-indexing them. The state file (last_id.txt) means subsequent runs only process new events, not all 1,974 again.</p><blockquote>curl -k -u elastic:Elastic123 <a href="https://localhost:9200/threat-intel-indicators/_count">https://localhost:9200/threat-intel-indicators/_count</a></blockquote><h4><strong>3.4 Kibana Dashboard with MISP Data</strong></h4><p><strong>3.4.1 Discover — Live Indicator Feed</strong></p><p>Open Kibana → Discover. Set time range to Last 1 year to see all historical data. Set to Last 15 minutes during active pipeline runs to see live ingestion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Phm5jFPcI8gbMcvk_3ORhQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJ7zsTyQ9P027ct-FjPB3w.jpeg" /></figure><p><strong>3.4.2 Dashboard — 347,479 Indicators</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VoukMunk4gwr8D7xV523lg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tqXOTloUo3vgvgBjQg3kgQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kMkeC-qsbfTBYoNMgsrEXw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_wE0UaDc9ZHwYiCNzsCeIA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z1AN-aDBfIBBuiZEXbyq9w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RxKAHgAWVul3iCNeGi06UQ.jpeg" /></figure><h4><strong>3.5 Reverse Pipeline — ELK to MISP</strong></h4><p><strong>3.5.1 Script: elk_to_misp.py</strong></p><p>Queries Elasticsearch for recent indicators and pushes them back to MISP as new events tagged tlp:green. Closes the bidirectional intelligence loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9iHl80udy1aPgga5sbX3A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yowSFRz1B30Ue8uRnsf3IQ.jpeg" /></figure><blockquote>cd /opt/ti-pipeline &amp;&amp; export $(cat .env | grep -v ^# | xargs) &amp;&amp; python3 elk_to_misp.py</blockquote><p><strong>3.5.2 Auto-Created MISP Events #1989-#1991</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fQZFf7USrLPjgi9wG2P6OA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-GLSyXg1vK446lmNdl3WA.jpeg" /></figure><p>This is the moment the loop closes. Events that started in MISP got indexed in Elasticsearch then Elasticsearch pushed indicators back into MISP as new events. A threat analyst working in MISP would see #1989, #1990, and #1991 as fresh intelligence without knowing they came from their own platform via ELK.</p><blockquote><em>⚠️ Circular loop prevention: In production, add a must_not filter to exclude indicators that originated from MISP-TAXII-Pipeline. Remove the filter for initial testing otherwise 0 indicators are found.</em></blockquote><h4><strong>3.6 Full Automation with systemd Timer</strong></h4><p><strong>3.6.1 ti-pipeline.service</strong></p><p>The systemd service unit defines what runs on each invocation: both misp_to_elk.py and elk_to_misp.py execute inside the Python venv, with credentials loaded from the .env file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JJIC2FqUU8IDfXn0BcTU_g.jpeg" /></figure><p><strong>3.6.2 ti-pipeline.timer</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6OwVpNgYJ4B9NXJDuDBlpA.jpeg" /></figure><blockquote>sudo systemctl daemon-reload</blockquote><blockquote>sudo systemctl enable — now ti-pipeline.timer</blockquote><blockquote>sudo systemctl list-timers ti-pipeline.timer # Verify schedule</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZuNNoTTBjpXDQW44cBH6Q.jpeg" /></figure><p><strong>3.6.3 Bug Found and Fixed During Automation</strong></p><p>First automated timer run produced TypeError: string indices must be integers. Root cause: MISP API wraps response in a dict when called from systemd context, but returns a list during manual runs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lYIk47d4EPZpvqKmdrBNEg.jpeg" /></figure><p><strong>3.6.4 End-to-End Verification</strong></p><p>After all automation is confirmed, run a full round-trip verification. Reset last_id to 0 to re-process all MISP events, then confirm both directions work cleanly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/635/1*HPcPA4BDXskvlOHpM3-0wQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*hUHToaj94igvpyqrzgJwGw.png" /></figure><h4><strong>3.7 Hardening, Gotchas, and Troubleshooting</strong></h4><p><strong>3.7.1 Five Critical Gotchas</strong></p><p>• geo_point must be mapped BEFORE indexing. Auto-mapping creates an object type delete and recreate the index if this happens.</p><p>• The elastic superuser password is shown exactly once at install. If lost: elasticsearch-reset-password -u elastic -i</p><p>• Kibana enrollment tokens expire in 30 minutes. Generate immediately before first Kibana start.</p><p>• Medallion is NOT a systemd service must be manually restarted every session. Wrap in a service for production.</p><p>• stix2-elevator conversion (STIX 1.x to 2.x) is lossy review all conversion warnings carefully.</p><p><strong>3.7.2 Troubleshooting Reference Table</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*i_6OqzQq602bVXTD8unPTw.png" /></figure><p><strong>3.7.3 Session Startup Checklist</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*DcHwsB2zFUxB_2knATDT3g.png" /></figure><p><strong>3.8 Key Takeaways and Resources</strong></p><p><em>Architecture lessons · Final pipeline metrics · Documentation links</em></p><p>If you followed this blog end-to-end, you now have a fully operational, automated, bidirectional threat intelligence pipeline running on AWS which is something that in a production SOC would involve a team of engineers and commercial tools costing tens of thousands of dollars per year.</p><p>The most important lesson from this build is not any individual command, but rather it is the architecture decision that every component should speak STIX 2.1 JSON. Once that is the standard, MISP, Elasticsearch, Kibana, and any future tool all fit together naturally. TAXII 2.x is just the delivery protocol for that JSON.</p><p>• <strong>1. </strong>STIX 1.x cannot be served over TAXII 2.x. Convert via stix2-elevator and treat all data as STIX 2.x JSON-native.</p><p>• <strong>2. </strong>A single t3.xlarge on Ubuntu 22.04 with ES 8.x gives security-by-default, bundled JDK, and enrollment-token Kibana setup out of the box.</p><p>• <strong>3. </strong>ECS-aligned mappings (threat.indicator.*) unlock Elastic Security’s indicator match rules the bridge between passive intelligence and active detection.</p><p>• <strong>4. </strong>systemd timers beat cron: built-in journald logging, Persistent=true catch-up, and proper dependency management.</p><p>• <strong>5. </strong>347,479 indicators indexed, self-updating dashboard, MISP auto-push every 15 minutes this is a real SOC threat intelligence loop at lab scale.</p><p>• <strong>6. </strong>Next steps: Elastic Security indicator match rules for live alert generation, and OpenCTI as middleware for enrichment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*uz1TgaM1G3ffPFQtFMu2JQ.png" /></figure><p><strong>PROJECT COMPLETE</strong></p><p>MISP 2.5 — STIX 2.1 — TAXII 2.1 — Elasticsearch 8.x — Kibana</p><p><em>347,479 indicators · Fully automated · Bidirectional · Self-updating dashboard</em></p><p>#MISP #STIX #TAXII #ELK #ThreatIntelligence #AWS #BlueTeam #SOC</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5c7a56bec60" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Smart WAF Deployment and Enhancing Web security using Bunker Web on AWS]]></title>
            <link>https://medium.com/@adevani20045/smart-waf-deployment-and-enhancing-web-security-using-bunker-web-on-aws-6950c53f27bb?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/6950c53f27bb</guid>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[web-application-firewall]]></category>
            <category><![CDATA[reverse-proxy]]></category>
            <category><![CDATA[modsecurity]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Thu, 16 Apr 2026 21:00:21 GMT</pubDate>
            <atom:updated>2026-04-16T21:00:21.850Z</atom:updated>
            <content:encoded><![CDATA[<p>Most cybersecurity courses teach you <em>about</em> firewalls. This lab series taught me how to actually <strong>build one, attack it, and watch it defend itself in real time.</strong></p><p>I followed a structured curriculum using BunkerWeb, an open source, next generation Web Application Firewall (WAF) built on NGINX. What makes this different from typical labs: everything runs on live AWS infrastructure, not a local VM. The threat surface is real. The IP is publicly reachable. The attacks travel through actual network hops, making every blocked and allowed response forensically meaningful rather than loopback artifacts.</p><p><strong>What is BunkerWeb?</strong></p><p>BunkerWeb is not just a firewall. It is a full reverse proxy security stack that intercepts all traffic before it reaches your application. Key capabilities include:</p><p>• HTTPS with automated Let’s Encrypt certificate management</p><p>• ModSecurity WAF with the OWASP Core Rule Set (CRS) for attack detection</p><p>• Automatic banning of clients that generate too many error status codes</p><p>• Rate limiting and request throttling per client IP</p><p>• Antibot challenges: cookie, JavaScript, CAPTCHA, hCaptcha, Turnstile</p><p>• Country based access policies supporting whitelist or blacklist by geo</p><p>• DNSBL and IP reputation checking</p><p>• Web UI for real time attack monitoring and configuration</p><p>• Plugin system: ClamAV, Coraza, Discord/Slack alerts, VirusTotal</p><blockquote><strong>ℹ️ INFO :</strong></blockquote><blockquote><strong>Everything runs in Docker containers via Docker Compose, configured through container labels. No config files needed for most use cases. The bw-autoconf service watches Docker events and auto-reconfigures BunkerWeb when containers change.</strong></blockquote><p><strong>Lab Environment Architecture</strong></p><p>The architecture uses three isolated Docker networks for layered defense in depth:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WsmYmyVfsp6CnEoM-atSdA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*tj9e0irPJvQltCBLDeoqlw.png" /></figure><blockquote>💡<strong>GOOD TO KNOW :</strong></blockquote><blockquote>Layered defense in depth: An attacker who compromises the web application is isolated on bw-services. They cannot reach bw-db (database) or bw-universe (BunkerWeb internals). No lateral movement possible.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAGBaNJ44oAkgG30jClAGw.png" /></figure><h4>PREREQUISITES: AWS CLOUD INFRASTRUCTURE SETUP</h4><p>This entire lab series runs on a live AWS EC2 instance in the Asia Pacific (Mumbai) ap-south-1 region. Before any Docker or BunkerWeb work begins, the cloud infrastructure must be provisioned correctly: the right instance type launched with sufficient storage, a security group configured to allow all required ports, and an Elastic IP allocated to give the lab a permanent, predictable public address.</p><p>Getting these prerequisites right prevents hours of debugging later. A wrong instance type causes container out of memory kills. Missing security group rules cause silent connection timeouts that look like application bugs. A dynamic public IP invalidates every docker-compose.yml label every time the instance restarts.</p><blockquote><strong>ℹ️ INFO :</strong></blockquote><blockquote>Using a real cloud instance rather than a local VM means the threat surface is genuine. The IP is publicly reachable from any browser or curl command on the internet. Attacks travel through real network hops, making blocked and allowed responses forensically meaningful rather than loopback artifacts.</blockquote><blockquote><strong>🎯 Learning Objectives</strong></blockquote><blockquote><strong>▸ </strong>Provision a production equivalent EC2 instance with the correct size and storage for Docker workloads</blockquote><blockquote><strong>▸ </strong>Configure AWS Security Groups as the first line of network defense by controlling which ports are publicly reachable</blockquote><blockquote><strong>▸ </strong>Understand why Elastic IPs are essential when IP addresses are embedded in application configuration</blockquote><blockquote><strong>▸ </strong>Recognise how cloud firewall rules (Security Groups) interact with application layer WAF rules (BunkerWeb)</blockquote><p><strong>P.1 EC2 Instance Launch on Ubuntu 22.04 t3.large</strong></p><p>The lab instance is launched from the AWS EC2 console using the following specification:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*JACyo_MiOq6uV4-U-4gFlQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g1EoexTjSrohdrVahepHMg.png" /></figure><p><strong>P.2 Security Group Configuration for launch-wizard-16</strong></p><p>Security group controls all inbound traffic to the instance. Five inbound rules are required for the BunkerWeb lab: HTTP (port 80) and HTTPS (port 443) for web traffic, SSH (port 22) for terminal access, Custom TCP port 8080 as an additional management/testing port, and port 7000 for the BunkerWeb Web UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/714/1*JPd09mpRZLPMfqw1t7EFnQ.png" /></figure><blockquote><strong>📝 NOTE :</strong></blockquote><blockquote>Source 0.0.0.0/0 allows access from any IP address. This is acceptable for a short term lab environment. In production, restrict SSH to known IP ranges and consider restricting HTTP/HTTPS if behind a CDN or load balancer.</blockquote><p><strong>P.3 Elastic IP Allocation &amp; Association</strong></p><p>A standard EC2 public IP changes every time the instance is stopped and started. An Elastic IP provides a static public IP that persists across reboots. This is critical for a lab where the IP address is hardcoded into all docker-compose.yml labels, curl test commands, and BunkerWeb’s SERVER_NAME setting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-yhM7LJM2Um3CcZ2dHZRfw.jpeg" /></figure><blockquote>📝 <strong>NOTE :</strong></blockquote><blockquote>Once the Elastic IP is associated, update /etc/hosts on the EC2 instance and any local machine used for testing. All BunkerWeb docker-compose.yml labels use SERVER_NAME=YOUR_SERVER_IP. If the IP changes, every label must be updated and the stack restarted.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*l-hQUGtXlormrvdKRxBaxg.png" /></figure><h4>01. LAB 1 : BUILDING THE INFRASTRUCTURE</h4><p><strong>1.1 Installing Docker CE</strong></p><p>On the fresh Ubuntu 22.04 EC2 instance, Docker CE 29.4.0 and Docker Compose v5.1.1 were installed:</p><blockquote>sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin</blockquote><blockquote>sudo usermod -aG docker $USER</blockquote><blockquote>newgrp docker</blockquote><blockquote># Verify installation</blockquote><blockquote>docker — version # Docker version 29.4.0</blockquote><blockquote>docker compose version # Docker Compose version v5.1.1</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NnkTMljNMhc-aHjEqusSSA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6HucH_2l9L1C6vBoV-uaQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*mO-AkAsPQ4Y1U3fN-LsWDA.jpeg" /></figure><p><strong>1.2 Creating the Project Structure</strong></p><blockquote>mkdir -p ~/bunkerweb-lab &amp;&amp; cd ~/bunkerweb-lab</blockquote><blockquote>mkdir -p configs/modsec configs/modsec-crs configs/server-http vulnerable-app</blockquote><blockquote>ls -la</blockquote><blockquote># configs/ vulnerable-app/</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*7FOWyKpbabyzaseImcwvPQ.jpeg" /></figure><p><strong>1.3 Deploying the Vulnerable Target Application</strong></p><p>A simple nginx served HTML page with a search form (for SQLi/XSS testing) and a login form (for brute force testing) acts as the intentionally vulnerable target:</p><blockquote>cat &gt; vulnerable-app/index.html &lt;&lt; ‘EOF’</blockquote><blockquote>&lt;!DOCTYPE html&gt;</blockquote><blockquote>&lt;html&gt;&lt;head&gt;&lt;title&gt;Vulnerable Lab App&lt;/title&gt;&lt;/head&gt;</blockquote><blockquote>&lt;body&gt;</blockquote><blockquote>&lt;h1&gt;BunkerWeb Lab — Target Application&lt;/h1&gt;</blockquote><blockquote>&lt;form action=”/search” method=”GET”&gt;</blockquote><blockquote>&lt;input type=”text” name=”q” placeholder=”Search…”&gt;</blockquote><blockquote>&lt;button type=”submit”&gt;Go&lt;/button&gt;</blockquote><blockquote>&lt;/form&gt;</blockquote><blockquote>&lt;form action=”/login” method=”POST”&gt;</blockquote><blockquote>&lt;label&gt;Username:&lt;/label&gt;&lt;input type=”text” name=”user”&gt;</blockquote><blockquote>&lt;label&gt;Password:&lt;/label&gt;&lt;input type=”password” name=”pass”&gt;</blockquote><blockquote>&lt;button type=”submit”&gt;Login&lt;/button&gt;</blockquote><blockquote>&lt;/form&gt;</blockquote><blockquote>&lt;/body&gt;&lt;/html&gt;</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OwenFJx-AC8kZgSMaYHiIg.jpeg" /></figure><h4><strong>02. LAB 2 : INSTALLIING &amp; CONFIGURING BINKERWEB ON AWS EC2</strong></h4><p><strong>2.1 The Docker Compose Stack Configuration</strong></p><p>The complete BunkerWeb stack runs 6 containers. The security critical configuration for the vulnerable app uses Docker labels.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BKd_ei-Kz6kR5GTlPhhtbA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9OedyyLROWoWuVsZq2Gf4A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_1WpYYq5EB460P9uIGmGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJPUFcJXqCalWvJD1EUJYg.jpeg" /></figure><blockquote><strong>ℹ️ INFO :</strong></blockquote><blockquote><strong>Key Insight :</strong> In Docker autoconf mode, ALL BunkerWeb configuration lives as labels on YOUR application containers. It does not live on BunkerWeb itself. The bw-autoconf service watches Docker events and auto-reconfigures BunkerWeb instantly. No container restart required.</blockquote><p><strong>2.2 Launching Stack</strong></p><blockquote>cd ~/bunkerweb-lab</blockquote><blockquote>docker compose up -d</blockquote><blockquote># Wait 30–60 seconds, then watch initialization</blockquote><blockquote>docker compose logs -f bw-scheduler</blockquote><blockquote># Press Ctrl+C when you see ‘Config successfully saved to database’</blockquote><blockquote># Verify all 6 containers are running</blockquote><blockquote>docker compose ps</blockquote><blockquote># Check memory usage</blockquote><blockquote>docker stats — no-stream</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eU0a3kPeAgUg5v8KQKhhhw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*berZtwnOQ_9BnxzePCuzXg.jpeg" /></figure><p><strong>2.3 Networks &amp; Security Headers Verification</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*fbg6RyoHGJZ4Ffqmu-m6qA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*rzdctqwKpoxz6ng-Mi8z4Q.jpeg" /></figure><p><strong>2.4 Host Header Validation</strong></p><p>BunkerWeb’s default protection rejects requests with unknown Host headers. This is a critical defense against host header injection attacks :</p><blockquote># Random fake host: BLOCKED</blockquote><blockquote>curl -k -o /dev/null -w “Random Host: %{http_code}\n” \</blockquote><blockquote>-H ‘Host: randomfakehost.xyz’ <a href="https://localhost/">https://localhost</a></blockquote><blockquote># Random Host: 302</blockquote><blockquote># No host header: BLOCKED</blockquote><blockquote>curl -k -o /dev/null -w “No Host: %{http_code}\n” <a href="https://localhost/">https://localhost</a></blockquote><blockquote># No Host: 302</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/710/1*7wd4GgRiI-w_ucAFwLTIVQ.jpeg" /></figure><p><strong>2.5 Key Security Settings</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*OO7XbSwTqwlYXiUuz24vMg.png" /></figure><p><strong>2.6 BunkerWeb UI</strong></p><p>The Web UI runs on port 7000, accessible via the BunkerWeb reverse proxy. After completing the setup wizard, the dashboard provides real time visibility into blocked attacks, configured services, loaded plugins, and system resource usage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zln_YYN94m6XZdFqAqKW_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e8Gl0423taswcdR1vm4C0Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s30vUh3J9q0eHJXEBwtK_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wfK4mEoQdlM_Q0B_Xhog2Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*11FEsL5DcQPHcPZMHcGakA.png" /></figure><h4>03. LAB 3 : Simulated Attacks &amp; WAF Validation</h4><blockquote><strong>Objective : </strong>Execute all OWASP Top 10 attack patterns against the live infrastructure and observe WAF blocking.</blockquote><blockquote><strong>⚠️ ALERT</strong></blockquote><blockquote><strong>ETHICAL REMINDER </strong>: All attacks were performed exclusively against my own AWS instance in a controlled lab environment. Never perform attacks against systems you do not own or have explicit written permission to test.</blockquote><p><strong>3.1 Attack 1 : SQL Injection (SQLi)</strong></p><p>SQL injection attempts to manipulate database queries through unsanitized user input. Three variants were tested against the live infrastructure :</p><blockquote># Classic Boolean-based SQLi</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=1%27+OR+%271%27=%271&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># UNION-based , data extraction attempt</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=1+UNION+SELECT+1,2,3--&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># Time-based Blind SQLi</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=1%27+AND+SLEEP(5)--&#39;</blockquote><blockquote># HTTP: 403</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSAT6N-yUUYNoT_vAkDmHQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*G38jrkgacyJh3di3QkOziQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-46g-WE4_FPSv7c2XFwYQw.jpeg" /></figure><p><strong>3.2 Attack 2 : Cross Site Scripting (XSS)</strong></p><blockquote># Script tag vector</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=%3Cscript%3Ealert(1)%3C%2Fscript%3E&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># IMG onerror vector</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=%3Cimg+src%3Dx+onerror%3Dalert(1)%3E&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># SVG onload vector</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=%3Csvg+onload%3Dalert(1)%3E&#39;</blockquote><blockquote># HTTP: 403</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*usHGwfiP3wJK7msEfC4gsQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/753/1*qpRSjdqoK4xJzYpB8FmoSQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4qG0FFyWWhFM6bx9CI8g4A.jpeg" /></figure><p><strong>3.3 Attack 3 : Path Traversal and Local File Inclusion (LFI)</strong></p><blockquote># Classic path traversal</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=../../etc/passwd&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># URL-encoded variant</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/search?q=%2e%2e%2f%2e%2e%2fetc%2fpasswd&#39;</blockquote><blockquote># HTTP: 403</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pIXZPE0627F4rxBrh2zpdw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*s86YTptL8YoCFRY-LNcn1A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YrblAhNztz0tVr0dfjoHTQ.jpeg" /></figure><p><strong>3.4 Attack 4 : Remote Command Execution (RCE)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DGXXXwZ31N8tBZjubG0OpA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*s86YTptL8YoCFRY-LNcn1A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DmJuF7LS-vxDYClARsMDMQ.jpeg" /></figure><p><strong>3.5 Attack 5 : Sensitive File Exposure</strong></p><blockquote># Git configuration exposure</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/.git/config&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># Environment file exposure</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/.env&#39;</blockquote><blockquote># HTTP: 403</blockquote><blockquote># WordPress admin panel probe</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>‘https://YOUR_SERVER_IP/wp-admin/&#39;</blockquote><blockquote># HTTP: 404 (not a WP site , no route exists)</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IbVIhIudafeNnTkod3ePBg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tlEX8Jufv_fRgbv8Q4VKPw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1AF0dOrYa-zVM0pIaFB0tQ.jpeg" /></figure><p><strong>3.6 Attack 6 : Security Scanner Detection</strong></p><blockquote># Nikto scanner user agent</blockquote><blockquote>curl -sk -o /dev/null -w “HTTP: %{http_code}\n” \</blockquote><blockquote>-H ‘User-Agent: Nikto/2.1.6’ ‘https://YOUR_SERVER_IP/&#39;</blockquote><blockquote># HTTP: 403</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mp5kFQsu7Zm5H1g8KQyUew.jpeg" /></figure><p><strong>3.7 Attack 7 : Brute Force and Rate limiting</strong></p><blockquote># 20 rapid requests to /login</blockquote><blockquote>for i in $(seq 1 20); do</blockquote><blockquote>curl -sk -o /dev/null -w “%{http_code} “ ‘https://YOUR_SERVER_IP/login&#39;</blockquote><blockquote>done</blockquote><blockquote><strong>📝 NOTE</strong></blockquote><blockquote><strong>Pattern </strong>: First 2 requests return 404 (path doesn’t exist). From request 3 onwards, rate limiting kicks in with HTTP 429 Too Many Requests. Rate limit: 2r/s on /login, burst=3.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nVRIF3vMrrS4QKx4Vr0zyw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/471/1*3GgTeKMKNpSwF9NVTOsxrw.jpeg" /></figure><p><strong>3.8 Complete Attack Sweep &amp; Reports Dashboard</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n611QEhG9m2QIA_AiaHvuQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VwFLLJGPAG2CI9BbP5lhSw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U-mQZXJjfQLySu1OGHHxfQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kU5lEV4tWAtBxgtJbgEyMg.jpeg" /></figure><p><strong>3.9 ModSecurity Rule ID Analysis</strong></p><p>After all attacks the top triggered rule IDs sorted by frequency :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xgm8Rntvu_P1oxOtb6llyg.jpeg" /></figure><p><strong>3.10 IP Unban Procedure</strong></p><p>After repeated attacks, my test IP was automatically banned. To unban and continue testing :</p><blockquote>docker compose exec bw-scheduler bwcli unban YOUR_SERVER_IP</blockquote><blockquote># SUCCESS: IP YOUR_SERVER_IP has been unbanned globally</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zwo9aoxkBYzMvBnTXd6opA.jpeg" /></figure><p><strong>3.11 Attack Summary</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*qqdTom6iL1B5VpGM_goeWA.png" /></figure><h4><strong>04. LAB 4 : CUSTOM SECURITY RULES &amp; ADVANCED HARDENING</strong></h4><blockquote><strong>Objective: </strong>Write custom ModSecurity rules, configure BunkerWeb settings for advanced protection, and handle false positives.</blockquote><p>This moves beyond default protection. The OWASP CRS handles the major web attack categories well, but every real application has unique threat surfaces that generic rules cannot cover. It also addresses legitimate traffic patterns that generic rules may incorrectly flag. Lab 04 addresses both sides of this equation.</p><p>Five custom configuration files are written and mounted into the BunkerWeb stack via Docker volume mounts on the bw-scheduler service. This volume-mount approach is the production-recommended pattern: config files stay in your git repository, are version controlled, and are injected as read only into the container. Security rules become code</p><blockquote><strong>🎯 Learning Objectives</strong></blockquote><blockquote><strong>▸ </strong>Write custom ModSecurity SecRules for application-specific threats (scanner UAs, sensitive files, admin paths)</blockquote><blockquote><strong>▸ </strong>Implement NGINX custom rate limiting zones for specific endpoints beyond BunkerWeb’s global rate limiter</blockquote><blockquote><strong>▸ </strong>Suppress false positives surgically using CRS ctl:ruleRemoveById and ctl:ruleRemoveTargetById directives</blockquote><blockquote><strong>▸ </strong>Mount custom config files into BunkerWeb via Docker volume mounts on the bw-scheduler service</blockquote><blockquote><strong>▸ </strong>Configure antibot challenges (cookie → JavaScript) and country based geo blocking</blockquote><blockquote><strong>▸ </strong>Understand the config load order: modsec/ runs BEFORE CRS, modsec-crs/ runs AFTER CRS</blockquote><blockquote><strong>ℹ️ INFO</strong></blockquote><blockquote><strong>Custom rules are stored in three locations :</strong> configs/modsec/ (pre-CRS SecRules), configs/modsec-crs/ (CRS overrides and exclusions), and configs/server-http/ (raw NGINX server block directives). Files are mounted read-only into the scheduler at /etc/bunkerweb/configs/&lt;type&gt;/.</blockquote><p><strong>4.1 Rule 100001: Blocking Known Security Scanners</strong></p><p>Blocks requests where the User Agent header matches known security scanner tool names. Any legitimate user or browser will never identify itself as Nikto, sqlmap, nmap, dirbuster, gobuster, or wfuzz.</p><blockquote>cat &gt; ~/bunkerweb-lab/configs/modsec/block-scanners.conf &lt;&lt; ‘EOF’</blockquote><blockquote>SecRule REQUEST_HEADERS:User-Agent “@rx (?i)(nikto|sqlmap|nmap|dirbuster|gobuster|wfuzz)” \</blockquote><blockquote>“id:100001,phase:1,deny,status:403,log,\</blockquote><blockquote>msg:’Blocked known security scanner’,\</blockquote><blockquote>severity:’CRITICAL’,tag:’custom-rule/scanner-block’”</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VsaC7BAqJxFTtwy--LQgZg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hq85gJ1Z60jWWgrAYfijMw.jpeg" /></figure><p><strong>4.2 Rule 100002: Blocking Sensitive File Access</strong></p><p>Blocks direct HTTP access to sensitive files that should never be publicly accessible: .env (environment variables/secrets), .git (source control data), .svn, .htaccess, .htpasswd, and wp-config.php.</p><blockquote>cat &gt; ~/bunkerweb-lab/configs/modsec/block-sensitive-files.conf &lt;&lt; ‘EOF’</blockquote><blockquote>SecRule REQUEST_URI “@rx (?i)(\.env|\.git|\.svn|\.htaccess|\.htpasswd|wp-config\.php)” \</blockquote><blockquote>“id:100002,phase:1,deny,status:403,log,\</blockquote><blockquote>msg:’Blocked access to sensitive file’,\</blockquote><blockquote>severity:’CRITICAL’,tag:’custom-rule/sensitive-file’”</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lp9TqkrZ7ri6wwNicez3Og.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Og_1QsYqPnfPGDP4SzWiGQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QYuUZ4grW4WA4yb2ymYGg.jpeg" /></figure><p><strong>4.3 Custom NGINX Rate Limiting Zone for the Login Endpoint</strong></p><p>BunkerWeb’s built in rate limiting applies globally. To apply a stricter, endpoint specific rate limit to the /login route, we inject a raw NGINX server block via configs/server-http/ :</p><blockquote><strong>📝 NOTE</strong></blockquote><blockquote>The limit_req_zone directive defines the shared memory zone that limit_req references. Without it, NGINX will fail to start with an ‘unknown zone’ error. The zone name (login_limit) must match in both directives.</blockquote><blockquote>cat &gt; ~/bunkerweb-lab/configs/server-http/rate-limit-login.conf &lt;&lt; ‘EOF’</blockquote><blockquote># Define a rate-limiting zone: 10MB shared memory, 5 requests/second per client IP</blockquote><blockquote>limit_req_zone $binary_remote_addr zone=login_limit:10m rate=5r/s;</blockquote><blockquote>location /login {</blockquote><blockquote># Allow burst of 3 requests, reject excess immediately (nodelay)</blockquote><blockquote>limit_req zone=login_limit burst=3 nodelay;</blockquote><blockquote>proxy_pass <a href="http://vulnerable-app;/">http://vulnerable-app;</a></blockquote><blockquote>}</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S1bdTM6cGgqk2v-gBkRyUg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EOVJ7-9U4XH0CptQH4T9Ug.jpeg" /></figure><p><strong>4.4 False Positive Suppression with CRS Exclusion Rules</strong></p><p>At Paranoia Level 2, the CRS can trigger false positives on legitimate application traffic. Two common cases are: (1) API endpoints that use SQL like syntax in responses (triggers rule 942100), and (2) search forms where the description parameter might contain HTML like content (triggers rule 941100).</p><blockquote>cat &gt; ~/bunkerweb-lab/configs/modsec-crs/false-positive-fix.conf &lt;&lt; ‘EOF’</blockquote><blockquote># Disable rule 942100 for API endpoints that use SQL like syntax</blockquote><blockquote>SecRule REQUEST_URI “@beginsWith /api/data” \</blockquote><blockquote>“id:100010,phase:1,pass,nolog,ctl:ruleRemoveById=942100”</blockquote><blockquote># Exclude ARGS:description from XSS rule 941100 on /search</blockquote><blockquote>SecRule REQUEST_URI “@beginsWith /search” \</blockquote><blockquote>“id:100011,phase:1,pass,nolog,ctl:ruleRemoveTargetById=941100;ARGS:description”</blockquote><blockquote>EOF</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jJCFuEcw3iBmgxnsSjV-tA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Lp3BCd8eV2R1MTuaquRIxA.jpeg" /></figure><blockquote><strong>🔑 IMPORTANT :</strong></blockquote><blockquote>Place false positive exclusions in configs/modsec-crs/ so they load AFTER the CRS rules they reference. Putting them in configs/modsec/ (which loads before CRS) will have no effect because the rules being excluded have not been loaded yet.</blockquote><p><strong>4.5 Volume Mount Strategy for Injecting Configs via bw-scheduler</strong></p><blockquote>bw-scheduler:</blockquote><blockquote>image: bunkerity/bunkerweb-scheduler:1.6.9</blockquote><blockquote>volumes:</blockquote><blockquote>- bw-storage:/data</blockquote><blockquote>- ./configs/modsec/block-scanners.conf:/etc/bunkerweb/configs/modsec/block-scanners.conf:ro</blockquote><blockquote>- ./configs/modsec/block-sensitive-files.conf:/etc/bunkerweb/configs/modsec/block-sensitive-files.conf:ro</blockquote><blockquote>- ./configs/modsec/block-admin.conf:/etc/bunkerweb/configs/modsec/block-admin.conf:ro</blockquote><blockquote>- ./configs/modsec-crs/false-positive-fix.conf:/etc/bunkerweb/configs/modsec-crs/false-positive-fix.conf:ro</blockquote><blockquote>- ./configs/server-http/rate-limit-login.conf:/etc/bunkerweb/configs/server-http/rate-limit-login.conf:ro</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RsYJGNpI33_BScyhZ_l17Q.jpeg" /></figure><blockquote>💡 <strong>GOOD TO KNOW</strong></blockquote><blockquote>All custom config files are mounted with :ro (read-only) to prevent the container from modifying them. This follows the principle of least privilege — the container needs only read access to consume these configs.</blockquote><blockquote># Full stack restart required when adding volume mounts</blockquote><blockquote>cd ~/bunkerweb-lab &amp;&amp; docker compose down &amp;&amp; docker compose up -d</blockquote><blockquote># Verify all configs are loaded</blockquote><blockquote>find ~/bunkerweb-lab/configs/ -type f</blockquote><blockquote># Expected: false-positive-fix.conf, rate-limit-login.conf,</blockquote><blockquote># block-admin.conf, block-sensitive-files.conf, block-scanners.conf</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8QYuUZ4grW4WA4yb2ymYGg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/527/1*CCXrxO9d5z68r47Ar1bFaw.jpeg" /></figure><blockquote><strong>❗ESSENTIAL :</strong></blockquote><blockquote>The /admin rule is optional because blocking it locks out real staff who need that page. Keep it in a separate file so you can turn it on or off easily. Turn it ON if your site has no admin page — it stops hackers scanning for one. Turn it OFF if you actually use /admin, or you’ll block yourself.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1006/1*nkfJHpWmAdIUD8YReyyJ5Q.jpeg" /></figure><p><strong>4.6 Antibot Configuration with Cookie and JavaScript Challenge</strong></p><p>BunkerWeb’s antibot feature presents a challenge to HTTP clients before serving any content. Cookie antibot sets a cookie on the first request and checks if the client resends it on the next one. This simple check filters out basic bots and scripts that don’t handle cookies properly. If you want to test stronger protection, you can try it by enabling JavaScript antibot.</p><blockquote># Enable cookie-based antibot (simpler, sets cookie, checks client resends it)</blockquote><blockquote>- “bunkerweb.USE_ANTIBOT=cookie”</blockquote><blockquote># Options: cookie, javascript, captcha, hcaptcha, recaptcha, turnstile</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QZf_k0KWetkpVqo8X9yYJw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*Z13ctbY1776ErJMwrVvMYw.jpeg" /></figure><p><strong>4.7 Country blocking Verification</strong></p><p>BunkerWeb uses MaxMind GeoIP to map source IPs to countries. The BLACKLIST_COUNTRY setting blocks all traffic originating from specified country codes. In this lab, CN (China), RU (Russia), and KP (North Korea) are blocked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PZJVXBAxzCuibtW4IY_jKQ.jpeg" /></figure><p><strong>4.8 Custom Rules Summary</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*yGzZCAXQMEkym2N455rhrw.png" /></figure><h4>05. LAB 5 : SECURITY <strong>ASSESSMENT &amp; WAF EFFECTIVENESS</strong></h4><p>It is the capstone of the entire series. Rather than deploying or configuring anything new, this lab measures what has been built. A systematic before/after methodology , identical attack sweeps with all protections disabled, then repeated with full protection enabled , produces the hard numbers that justify a WAF deployment: 87.23% block rate, 0% false positive rate.</p><blockquote><strong>🎯 What You Will Learn</strong></blockquote><blockquote><strong>▸ </strong>Conduct a systematic before/after WAF effectiveness test using sed based configuration toggling</blockquote><blockquote><strong>▸ </strong>Read and interpret ModSecurity raw logs for SQLi, XSS, LFI, and RCE attack categories</blockquote><blockquote><strong>▸ </strong>Understand the impact of CRS Paranoia Level 2 including new rules triggered, attack coverage gained, and false positive risk</blockquote><blockquote><strong>▸ </strong>Validate anomaly scoring mode: why natural language queries containing SQL keywords pass the threshold</blockquote><blockquote><strong>▸ </strong>Write a professional Security Assessment Report with executive summary, infrastructure, results, and recommendations</blockquote><blockquote><strong>▸ </strong>Calculate WAF effectiveness metrics: block rate, false positive rate, and custom rule coverage</blockquote><p><strong>5.1 Phase 1: Disable All Protections to Establish Baseline</strong></p><p>Using sed to flip every security flag to ‘no’ in docker-compose.yml at once, then restart the stack. This simulates a completely unprotected deployment. the state most applications exist in before WAF is introduced.</p><blockquote># Disable ALL security features via sed in-place replacements</blockquote><blockquote>sed -i ‘s/USE_MODSECURITY=yes/USE_MODSECURITY=no/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_MODSECURITY_CRS=yes/USE_MODSECURITY_CRS=no/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_BAD_BEHAVIOR=yes/USE_BAD_BEHAVIOR=no/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_LIMIT_REQ=yes/USE_LIMIT_REQ=no/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_ANTIBOT=javascript/USE_ANTIBOT=no/’ docker-compose.yml</blockquote><blockquote># Verify all features are off</blockquote><blockquote>grep -E “USE_MODSECURITY|USE_BAD|USE_LIMIT|USE_ANTIBOT” docker-compose.yml</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/979/1*mttj2K0G6LcoISvDAtsptg.jpeg" /></figure><blockquote>echo -n “SQL Classic : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/?q=1&#39;OR’1&#39;=’1”</blockquote><blockquote>echo -n “SQL UNION : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/?q=1+UNION+SELECT+1,2,3”</blockquote><blockquote>echo -n “XSS : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/?q=&lt;script&gt;alert(1)&lt;/script&gt;”</blockquote><blockquote>echo -n “LFI : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/?q=../../etc/passwd”</blockquote><blockquote>echo -n “RCE : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/?q=;cat+/etc/passwd”</blockquote><blockquote>echo -n “Scanner Nikto: “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” -A “Nikto/2.1.6” “$T/”</blockquote><blockquote>echo -n “Sensitive .env: “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/.env”</blockquote><blockquote>echo -n “Homepage : “ &amp;&amp; curl -sk -o /dev/null -w “%{http_code}\n” “$T/”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*wWX4eIrY_JAv0PDGldK3VQ.jpeg" /></figure><p><strong>5.2 Phase 2 : Restore All Protections with Full WAF Active</strong></p><blockquote># Re-enable all WAF features</blockquote><blockquote>sed -i ‘s/USE_MODSECURITY=no/USE_MODSECURITY=yes/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_MODSECURITY_CRS=no/USE_MODSECURITY_CRS=yes/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_BAD_BEHAVIOR=no/USE_BAD_BEHAVIOR=yes/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_LIMIT_REQ=no/USE_LIMIT_REQ=yes/’ docker-compose.yml</blockquote><blockquote>sed -i ‘s/USE_ANTIBOT=no/USE_ANTIBOT=javascript/’ docker-compose.yml</blockquote><blockquote>docker compose down &amp;&amp; docker compose up -d</blockquote><blockquote>sleep 30 &amp;&amp; docker compose ps</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tQU52THZDPwJUWKZ1UvunQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2nH_FjAVjLmg5xI23_3wyA.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*-uTtvwy7eh1gQHu_pPE6zw.png" /></figure><p><strong>5.3 ModSecurity Log Analysis with Per Attack Forensics</strong></p><blockquote>echo “=== SQLi LOGS ===”</blockquote><blockquote>docker compose logs bunkerweb 2&gt;&amp;1 | grep ‘attack-sqli’ | tail -3</blockquote><blockquote>echo “=== XSS LOGS ===”</blockquote><blockquote>docker compose logs bunkerweb 2&gt;&amp;1 | grep ‘attack-xss’ | tail -3</blockquote><blockquote>echo “=== LFI LOGS ===”</blockquote><blockquote>docker compose logs bunkerweb 2&gt;&amp;1 | grep ‘attack-lfi’ | tail -3</blockquote><blockquote>echo “=== RCE LOGS ===”</blockquote><blockquote>docker compose logs bunkerweb 2&gt;&amp;1 | grep ‘attack-rce’ | tail -3</blockquote><blockquote># Check anomaly scoring (949110 = blocking evaluator)</blockquote><blockquote>docker compose logs bunkerweb 2&gt;&amp;1 | grep “Anomaly Score” | tail -10</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqM6jUPTSVWOCXVPQCAyzw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QmvFkON-gIscjOMxXv8M8Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hTxq5PbwA7hF2DvX4_r9fw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lIHFhvm-YUjF-qzYcFMP4Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uSgi4DT092a6kwH6EmHlpg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qNxSyeoS3p8LJqkrYVgnng.jpeg" /></figure><p><strong>5.4 Paranoia Level 2 Deep Dive</strong></p><p>Paranoia Level 2 activates additional CRS rules that catch more attack variants at the cost of potential false positives on complex applications. This section measures exactly which new rules fire at PL2 vs. PL1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I21scbfLDdrcM38nKhQ67Q.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YsC66iqofw_AWCx7SWi_0w.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IJciQnrdZdeTH2ypC8awTw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*456CNWIAwsNXjUqqGEiblw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*-X9Pxt5y90KcCAyYVu3pHg.png" /></figure><blockquote><strong>📝 NOTE</strong></blockquote><blockquote>Rule 920350 fires on ALL requests at PL2 because the raw IP address is used as SERVER_NAME instead of a domain name. In production with an FQDN, this false trigger is eliminated. Rule 949110 is the final blocking rule , never disable it.</blockquote><p><strong>5.5 False Positive Test and Anomaly Scoring Validation</strong></p><p>A critical test: send a natural language query containing SQL keywords (SELECT, UNION) but with no actual injection syntax. Anomaly scoring mode should pass it because no actual injection pattern is present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0a6zbueROpWQN5sQOXRQBg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/840/1*N6MrXaxKEK1O1GW8RLeYwg.jpeg" /></figure><blockquote><strong>Why Anomaly Scoring is More Powerful Than Block Mode ?</strong></blockquote><blockquote>Traditional WAFs would block any query containing ‘SELECT’ or ‘UNION’. ModSecurity’s anomaly mode scores the full request context. Only actual injection syntax accumulates enough score to trigger the threshold. A single CRITICAL rule match (score 5) hits the default threshold of 5. Multi vector attacks score higher and are caught by multiple rules simultaneously.</blockquote><p><strong>5.6 Recommendations for Production Hardening</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*H0Wul2WnEnqNsCsbT0qkXg.png" /></figure><h4><strong>06. OWASP CRS &amp; Custom Rule ID Quick Reference</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*TUhg7p6BhjYKhk3oYA5d7w.png" /></figure><h4><strong>07. KEY TAKEAWAYS</strong></h4><blockquote><strong>1. Label-Based Configuration is Security as Code</strong></blockquote><blockquote>The Docker label approach means you configure security per-application by annotating your app container. No central firewall config files. bw-autoconf propagates changes automatically. Deploy security as code and keep it version controlled in your git repository.</blockquote><blockquote><strong>2. Anomaly Scoring Prevents False Positives at Scale</strong></blockquote><blockquote>Rather than blocking on the first rule match, requests accumulate an anomaly score. A single CRITICAL match (score 5) hits the default threshold of 5. Multi vector attacks score higher and are caught by multiple rules simultaneously , which dramatically reduces false positives compared to binary block rules.</blockquote><blockquote><strong>3. Three Network Isolation Provides Real Layered Defense in Depth</strong></blockquote><blockquote>Even if the vulnerable app is fully compromised, the attacker is trapped on bw-services. They cannot reach bw-db (database) or bw-universe (BunkerWeb internal API). This is not just a checkbox , it is a real architectural barrier that limits the blast radius of a breach.</blockquote><blockquote><strong>4. OWASP CRS Out-of-the-Box is Remarkably Effective</strong></blockquote><blockquote>With just three labels (USE_MODSECURITY=yes, USE_MODSECURITY_CRS=yes, PARANOIA_LEVEL=2), the WAF blocked 100% of OWASP Top 10 attack patterns. Custom rules add another defense layer on top for application-specific threats.</blockquote><blockquote><strong>5. Visibility is as Important as Blocking</strong></blockquote><blockquote>The Web UI Reports dashboard combined with ModSecurity logs provided complete forensic evidence for every blocked request, including rule ID, attack category, anomaly score, affected endpoint, source IP, and country. In production, this feeds directly into your SIEM.</blockquote><h4><strong>08. RESOURCES &amp; FURTHER READING</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/705/1*N5pvnIzlqxpXZ5VtykUXBQ.png" /></figure><blockquote><em>Built with curiosity and a healthy paranoia about web security.</em></blockquote><blockquote><strong>Stay curious. Stay secure.</strong></blockquote><p>#cybersecurity #WAF #BunkerWeb #AWS #Docker #ModSecurity #OWASP #WebSecurity #HandsOnLab</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6950c53f27bb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Threat Intelligence Lab with MISP 2.5 on AWS]]></title>
            <link>https://medium.com/@adevani20045/building-a-threat-intelligence-lab-with-misp-2-5-on-aws-2665ff9f22de?source=rss-53635efa97f6------2</link>
            <guid isPermaLink="false">https://medium.com/p/2665ff9f22de</guid>
            <category><![CDATA[misp]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <category><![CDATA[blue-team]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Aditya Devani]]></dc:creator>
            <pubDate>Mon, 13 Apr 2026 12:21:32 GMT</pubDate>
            <atom:updated>2026-04-13T12:21:32.700Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*tx_lvha2qZ4D5ffvCCYExg.jpeg" /></figure><p><strong>WHAT IS IN PART-1</strong></p><p>1. What is MISP and why does it matter?</p><p>2. Lab architecture</p><p>3. Spinning up the EC2 instance</p><p>4. Installing MISP 2.5</p><p>5. First login and configuration</p><p>6. Taxonomies, Galaxies, and Feeds</p><p>7. Creating a real threat event</p><p>8. Adding IOCs — and watching correlation happen</p><p>9. Setting up the TAXII 2.1 server</p><p>10. Exporting to STIX 2.1</p><p>11. What Part 2 covers</p><h3>1. What is MISP and why does it matter?</h3><p>MISP (Malware Information Sharing Platform) is the open-source threat intelligence platform used by national CERTs, ISACs, Europol, NATO, and thousands of private security teams. The core idea is straightforward: when an attack happens, the indicators i.e., IP addresses, domains, file hashes, email addresses etc. get documented in MISP, tagged, categorized, and shared. Other teams pull that intel and use it for detection and blocking.</p><p>What makes MISP more than a glorified spreadsheet is <strong>automatic correlation</strong>. The moment you add an IOC, MISP checks it against other intel data in the database and performs matching. In this article we will see a concrete example later when MISP found a hash I had just added across 1,300 existing events in the feeds.</p><p>MISP also speaks STIX 2.1 natively, which means everything stored in it can be exported in a format that SIEMs, EDRs, and firewalls can consume directly. That export-to-STIX capability is the primary reason this project is important beyond just a pipeline.</p><p>MISP was originally developed by CIRCL (Computer Incident Response Centre Luxembourg) and has grown into one of the most widely deployed open-source threat intelligence platforms in the world. The MISP community spans national CERTs, financial sector ISACs, military cyber commands, and private SOC teams across more than 70 countries. That community breadth matters: it means the feeds, the galaxies, and the taxonomy libraries built into MISP reflect real adversary behaviour from real incident response, not theoretical frameworks written by vendors who have never handled a live incident.</p><h3>2. Lab Architecture</h3><p>Before getting into the steps, here is what the lab looks like end-to-end:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*C8Gpbg-7_0gc24DsRnHnfQ.png" /></figure><p>Data flows in one direction: external feeds get pulled into MISP, threat events are created with IOCs and tags, and then the STIX export makes everything available via TAXII for downstream consumption. Simple pipeline.</p><p>It is worth understanding why MISP sits at the centre rather than simply subscribing to raw TAXII feeds directly. MISP acts as a curation and enrichment layer. Every indicator that enters the platform gets cross-referenced against the full database, enriched with galaxy cluster labels, and stamped with a TLP marking before it leaves as a STIX bundle. Downstream consumers receive context, not just raw IPs and hashes.</p><h3>3. Spinning Up the EC2 Instance</h3><p>I deployed on AWS EC2 rather than a local VM for one practical reason: a real, persistent public IP. MISP writes its base URL into the database at install time. Every API call, every browser link, every TAXII connection references that URL. If the IP changes between sessions, everything breaks. Assigning an Elastic IP on AWS solves that permanently.</p><p>Instance configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/649/1*-th43o3PXDYAjjaYUrVYZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*NQLqKM1CzowivpqnbH2dSg.png" /></figure><p>I accessed the instance using EC2 Instance Connect directly from the browser and no terminal setup was needed. Once in, the Elastic IP was assigned immediately so the base URL is stable for the entire project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvP9NXQB-9VgHjoFVGxDVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWPYdyRQbSkXCRcczaJ1MA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5RV5FE1fJqnYQqIEi_XLCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0isAzeHn_DgQmM4AaIrL-A.png" /></figure><p>One practical note on the instance type choice: the c7i-flex uses Intel Emerald Rapids processors and delivers consistent CPU performance without the burstable throttling that t3 instances apply under sustained load. During a feed import or a correlation run across thousands of events, MISP will saturate a CPU core for several minutes. A t3 would throttle during exactly those moments. The c7i-flex does not, which makes the feed import step noticeably faster and the correlation results more reliable.</p><h3>4. Installing MISP 2.5</h3><p>MISP provides an unattended installer for Ubuntu 24.04. One thing worth flagging: if you copy the installer URL from a browser on Windows and paste it into the terminal, hidden Windows-style line endings get embedded in the string. The shell treats them as literal characters and the <strong>wget </strong>command fails silently or downloads garbage. Hence, I recommend to type the command directly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*aq7CmzpvE65YnLsXDu1ydA.png" /></figure><p>The install runs unattended and takes ~15–30 minutes. At the end it prints the admin credentials:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*G1DWzrSMf4wn58Dk944XpQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/643/1*DxkT3dpUM3WOdaQ1HJlz1g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*5r1iip523f48Ftpc-2TAxw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ftgF70Qf9o0Gq1qDbDD2pg.png" /></figure><h3>Verifying services</h3><p>Before touching the UI, confirm all four services are up:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*arG6H_e3q22I7L2BPewO_w.png" /></figure><p><strong>Redis</strong> is the one worth double-checking. Feeds will appear to import without it running, but nothing actually shows up in the event list as the background workers silently fail because there is no message queue to pick up from. All four need to show <strong>active (running)</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/959/1*onBgBQIBFUbM5cttOWNWjQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/963/1*XrV3qisCQAwliTHfmWyy-Q.png" /></figure><p>One thing not shown in the installer output but worth being aware of: the MISP background workers handle all the heavy tasks that would otherwise block the web UI. Feed imports, correlation runs, event publishing notifications, and STIX exports all go through Supervisor-managed worker processes running in the background. If workers go down, the UI will appear to work normally but nothing will actually process. That is why verifying Supervisor alongside Apache, MariaDB, and Redis is mandatory. It is the most common source of silent failures in a fresh MISP deployment.</p><h3>5.First Login and Configuration</h3><p>Navigate to https://&lt;BASE_URL&gt;. The browser will warn about the self-signed certificate. In Firefox: Advanced → Accept the Risk and Continue. The login page loads with an initial setup notice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EN4JyOHbHz2YN-prdICb9Q.png" /></figure><p>After changing the password, three settings need to be configured before anything else:</p><p><strong>Organisation name.</strong> Administration → Edit Organisation → set to &lt;ORG_NAME. In this blog I have set it to <strong>CyberThreatLab</strong>. This name appears on every event created and in all sharing metadata. This is the identifier to identify who produced the intel.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gk2LGMjRA8_fJ06gfuluyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9uf7HpJnlyRVj7K7Jmn4mg.png" /></figure><p><strong>Base URL and live flag.</strong> Administration → Server Settings &amp; Maintenance → MISP tab. Set <strong>MISP.baseurl</strong> to <strong>https://&lt;BASE_URL&gt;</strong> and flip<strong> MISP.live </strong>to<strong> true</strong>. The live flag is a global on/off switch, when false, every API call returns 403 and only site admins can log in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0GI4YYHyvO3VURhr2ORhMg.png" /></figure><p><strong>API key.</strong> Administration → List Users → Auth Keys. The installer generated one automatically. This key goes into the <strong>Authorization</strong> header of every API call and every <strong>PyMISP</strong> script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vzQOAHgEreZTINPHhjB3IA.png" /></figure><p>The three settings above form the minimum viable configuration for a functioning MISP instance. Without the correct <strong>baseurl</strong>, every link inside MISP points to the wrong address and API clients get confused about where to send requests. Without the live flag, the platform silently rejects all external interaction. Without a valid <strong>API key, PyMISP scripts and curl commands </strong>will receive 403 responses with no useful error message. Getting these three things right before creating any events saves significant debugging time later.</p><h3>6. Taxonomies, Galaxies, and Feeds</h3><p>Without taxonomies enabled, the tag picker is empty when creating events that makes tagging useless. The three I enabled:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*bcYBTsNTfzm5ICKBwyJE_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3CcqWzMmhEN9dHzioT7PPA.png" /></figure><p><strong>Galaxies</strong> are richer knowledge bases i.e., threat actor profiles, malware families, attack campaigns. They are what turn IoCs into actual threat intelligence, by connecting indicators to known adversaries and their behaviours. I enabled Threat Actor, MITRE ATT&amp;CK Techniques, and Tidal Campaigns clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*037gjiBlAqC21Ohu4TV_dw.png" /></figure><p>For external feeds I enabled <strong>CIRCL OSINT Feed</strong> (threat events from the team that built MISP) and <strong>Botvrij.eu</strong> (malware and botnet indicators), then triggered a background pull. You can also enable other options provided.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8h43HbWh7A1gcvJ1QkpoRQ.png" /></figure><p>A practical note on feed import timing: when you first trigger a background pull on CIRCL and Botvrij.eu, expect the process to run for 10 to 15 minutes. MISP downloads each event from the feed, deduplicates attributes, runs correlation against the existing database, and indexes everything. The feed status page will show a spinning indicator during this time. The event count in the dashboard will jump significantly once the import finishes, often from a handful of test events to several thousand and that moment is also when the correlation engine has enough data to start surfacing meaningful connections.</p><h3>7. Creating a Real Threat Event</h3><p>To create a new event, go to Event Actions → Add Event. For the blog we take the following scenario: a phishing campaign targeting the financial sector.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*8EmuoTI42MyKAnEmttV9ag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WyGieD__e72JFFUKzNM0-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4p788WSApME-Xv_DSVjtLA.png" /></figure><p>The choice of Distribution field is worth pausing on. Setting it to Your organisation only during a lab exercise keeps the event private, which is appropriate while you are still adding and verifying attributes. Once all IOCs have been confirmed and the event is tagged correctly, changing Distribution to Community or All communities before publishing makes the event visible to connected MISP instances and TAXII consumers. For this lab the event stays internal, but in a production sharing environment that distribution setting is the mechanism that controls who receives the intelligence.</p><h3>8. Adding IOCs — and Watching Correlation Happen</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*UiXaD7XoZxh9Ju915CbmMw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*FVqyidShOKGSYe-YMjViVg.png" /></figure><p>After adding the MD5 hash, something interesting happened as seen MISP flagged it immediately:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_9OE6w50vhyPk44I-w9gXA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJueYdhu0lpy_g2g2pDu5g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*YjHKI4WWONEwptvBP7sLXg.png" /></figure><p>Once all four IOCs were in, I tagged the event. <strong>tlp:green</strong> from the Taxonomy Library, meaning this data can be shared within the community. <strong>APT28,</strong> a galaxy cluster for a Russian state-sponsored group with a documented history of targeting financial and government organisations.</p><p>After tagging, the Related Events panel filled in with CIRCL feed data from 2016 through 2024 sharing the same indicators. The picture of the threat got richer without any additional work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emNXVkURVcJOzJcgBjGMZw.png" /></figure><p>An unpublished event is a draft as it does not appear in API searches and cannot be exported as STIX. Clicked <strong>Publish Event</strong> in the left sidebar to make it visible outside the UI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q6x7oAelGDy2j3tgZcUByw.png" /></figure><p>Publishing the event does two things that are not immediately obvious from the UI. First, it makes the event available in API searches, which is what PyMISP scripts and STIX export calls use to query the database. An unpublished event is invisible to the API regardless of its distribution setting. Second, it triggers notifications to any connected MISP servers that have sync configured. In a real ISAC deployment, publishing an event is the act that distributes the intelligence. In this lab it is the step that enables the STIX export in the next section.</p><h3>9. Setting Up the TAXII 2.1 Server</h3><p>STIX is the format. TAXII is how you deliver it. <strong>Medallion</strong> is the OASIS reference implementation of a TAXII 2.1 server, a lightweight Flask app designed for exactly this kind of lab use case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*kuNuH5tXP8pI1KrCIPBidA.png" /></figure><p>Configuration in <strong>medallion_config.json:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*gXgh34I8sNWOvcD4vsq6Cg.png" /></figure><p>Two things are important to note here. First, both <strong>module</strong> and<strong> module_class</strong> are required as missing <strong>module_class</strong> throws a cryptic <strong>AttributeError</strong> on startup with no useful hint.</p><p>Second, the <strong>collections</strong> array in <strong>taxii_data.json</strong> must be nested inside the <strong>trustgroup1</strong> key. Placing it at the top level makes collections return empty with no error, another silent failure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*y1d0KiwPTCC6rHNqG3_YQQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/658/1*53iAFaMCPjp6fe1AEfdRmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*lIwcSP1Z28N_fbRYqFlHZg.png" /></figure><p>Tested the discovery endpoint. Every TAXII request requires the <strong>Accept: application/taxii+json;version=2.1</strong> header as without it, Medallion returns 406:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*3NqCzqOhx3s3b-TkoxM0rg.png" /></figure><p>The discovery endpoint returns a JSON object describing the TAXII server, its title, and the API roots it exposes. Each API root contains collections, and each collection is where STIX bundles get pushed and pulled from. For this lab there is one collection defined in <strong>taxii_data.json</strong>. Medallion keeps everything in memory by default, meaning a server restart clears all pushed bundles. For persistent storage across restarts, the config supports a MongoDB backend that replacing the module and <strong>module_class</strong> values with their MongoDB equivalents is the only change required to make the storage durable.</p><h3>10. Exporting to STIX 2.1</h3><p>With Event #1968 published and the TAXII server running, the final step for Part 1 was exporting the event as a STIX 2.1 bundle. MISP’s<strong> restSearch</strong> endpoint handles this directly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*WKuYq67HmE31oSnJEQJJPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*F5EqdX52jE64YGTnmYROgA.png" /></figure><p>The output file contains all four IOCs converted to STIX 2.1 objects. The C2 IP address becomes an <strong>indicator</strong> with a detection pattern:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*pzbNTlKN3hjcPc29Jh48Ig.png" /></figure><p>Every attribute that had the IDS flag checked comes through as a typed STIX indicator. Any SIEM, EDR, or TIP that speaks STIX 2.1 can consume this directly there is no transformation needed.</p><p>It is worth examining what the STIX 2.1 bundle actually contains beyond the indicators themselves. MISP generates an Identity object representing your organisation, a Report object wrapping all the indicators, and individual Indicator objects for each IDS-flagged attribute. The confidence level, TLP marking, and kill-chain labels applied inside MISP all survive the conversion and appear as STIX 2.1 structured fields. That means a consuming SIEM does not need to strip or reinterpret any metadata that’s why the context travels with the indicators.</p><h3>11. Where Part 1 Leaves Things</h3><p>At this point the lab has: an EC2 instance with a stable IP, MISP 2.5 configured with a live organisation and API key, taxonomies and galaxy clusters active, CIRCL and Botvrij.eu feeds pulling data, a published phishing campaign event with four IOCs and automatic correlation against 1,300+ existing events, a Medallion TAXII 2.1 server running on port 5000, and a STIX 2.1 bundle exported cleanly from MISP.</p><p>Everything is running. The data is in. But nothing is connected yet as the TAXII server is sitting there with no bundles pushed to it, and the STIX export is just a file on disk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*OQ4mFB0dhVdUp3tWCoExDg.png" /></figure><p>#MISP #STIX #TAXII #ThreatIntelligence #AWS #BlueTeam #SOC</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2665ff9f22de" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>