<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Modbus on Londopy</title><link>https://londo.me/blog/tags/modbus/</link><description>Recent content in Modbus on Londopy</description><image><title>Londopy</title><url>https://londo.me/blog/og-image.png</url><link>https://londo.me/blog/og-image.png</link></image><generator>Hugo</generator><language>en-us</language><copyright>2026 Londopy · Posts CC BY 4.0 · Code MIT</copyright><lastBuildDate>Sun, 15 Nov 2026 00:22:37 -0800</lastBuildDate><atom:link href="https://londo.me/blog/tags/modbus/index.xml" rel="self" type="application/rss+xml"/><item><title>I Built an ICS Attack Lab, and My IDS Lied to Me</title><link>https://londo.me/blog/posts/ics-attack-lab/</link><pubDate>Thu, 19 Nov 2026 09:00:00 -0800</pubDate><guid>https://londo.me/blog/posts/ics-attack-lab/</guid><description>In my last post I said the way to learn OT security is to build a PLC simulator and watch the traffic. So I did. I stood up OpenPLC as a deliberately-attackable PLC, wrote a Modbus attacker, and put Suricata in front of it to catch me. Then my detection rules confidently reported an attack that never happened while staying silent about the one that did. Here&amp;#39;s the build, the two traps that ate an afternoon, and why detection you can&amp;#39;t trust is worse than none.</description><content:encoded><![CDATA[<p>A few weeks ago I wrote <a href="../ot-ics-security/">a beginner&rsquo;s map of OT and ICS security</a>, and it ended with a piece of advice I hadn&rsquo;t actually followed yet: the fastest way to learn this field is to build a little plant you can break and fix safely. Run a PLC simulator, speak its protocol, watch the traffic.</p>
<p>So I built one. A real PLC runtime, a real industrial protocol, and an intrusion detector standing between them to catch me attacking it. The target is a PLC I control, on a network that touches nothing real.</p>
<p>The build was the easy part. The part worth writing about is the moment my own detector lied to me: it fired <strong>twelve alarms for an attack I never sent</strong>, and stayed completely silent about the one I did. That failure turned out to be the most educational thing in the whole lab.</p>
<h2 id="the-plant">The plant</h2>
<p>The whole thing is three roles, which is exactly how a real plant security problem is shaped:</p>
<ul>
<li><strong>The target</strong> is <a href="https://openplcproject.com/">OpenPLC</a>, a free, open-source PLC runtime. It runs in a small Linux VM, serves a web HMI, and exposes a <strong>Modbus/TCP</strong> server on port 502, behaving like a cheap industrial controller.</li>
<li><strong>The attacker</strong> is the lab host. No fancy tooling: <code>nmap</code> for discovery and a small script that speaks raw Modbus.</li>
<li><strong>The defender</strong> is <a href="https://suricata.io/">Suricata</a>, an open-source IDS, sniffing the wire with rules I wrote to flag industrial traffic.</li>
</ul>
<p>Everything lives on an isolated host-only network, <code>192.168.57.0/24</code>, with no route to the internet. The attacker is <code>192.168.57.1</code>; the PLC is <code>192.168.57.10</code>. The PLC reaches out through NAT once, to download packages, and is otherwise sealed off. Rule zero of this hobby: <strong>never point any of this at something real.</strong> Touching the wrong device on a live industrial network can stop a physical process, and it&rsquo;s illegal. A VM on an isolated subnet can&rsquo;t hurt anyone.</p>
<pre tabindex="0"><code>      host-only net  192.168.57.0/24  (isolated, no internet)
 ┌─────────────────────────┐            ┌──────────────────────────────┐
 │ attacker  192.168.57.1  │   Modbus   │ OpenPLC   192.168.57.10      │
 │  - nmap                 │ ──502────▶ │  - web HMI : 8080            │
 │  - raw Modbus script    │            │  - Modbus  : 502             │
 └─────────────────────────┘            │  - Suricata watches the NIC  │
                                        └──────────────────────────────┘
</code></pre><p>Before any of that worked, though, I lost an afternoon to two failures that had nothing to do with security and everything to do with how real this stuff gets the moment you leave the tutorial.</p>
<h2 id="trap-one-the-compile-that-ran-out-of-floor">Trap one: the compile that ran out of floor</h2>
<p>OpenPLC&rsquo;s installer isn&rsquo;t a package download. It builds a chunk of its runtime from source, including <a href="https://github.com/dnp3/opendnp3">OpenDNP3</a>, a C++ library for another industrial protocol. On a fresh cloud image of the OS, the install got about three-quarters of the way through that compile and died:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">[ 75%] Building CXX object .../IOutstationApplication.cpp.o
</span></span><span class="line"><span class="cl">fatal error: closing dependency file ...: No space left on device
</span></span><span class="line"><span class="cl">OpenPLC was NOT installed!
</span></span></code></pre></div><p>No space left on device. The generic cloud image I&rsquo;d started from ships a <strong>3 GB</strong> root disk, and a from-source C++ build of an entire protocol stack fills it. The fix is boring and worth knowing: grow the virtual disk, then let the guest grow the filesystem to match. On this VM the disk resize needed the machine powered off, and the cloud image&rsquo;s own first-boot tooling expanded the partition automatically on the next start. Ten gigabytes of headroom later, the compile finished.</p>
<p>The lesson isn&rsquo;t &ldquo;disks fill up.&rdquo; It&rsquo;s that <strong>industrial software assumes it owns the machine.</strong> OpenPLC wants to compile protocol stacks, drop a systemd service, and bind privileged ports. Treat it like an appliance, not an app, and give it room.</p>
<h2 id="trap-two-the-clone-that-couldnt">Trap two: the clone that couldn&rsquo;t</h2>
<p>With disk to spare, I re-ran the install and it failed again, differently. Every attempt to re-clone OpenPLC&rsquo;s source landed in a directory that was supposed to be empty but wasn&rsquo;t, and <code>git</code> refused.</p>
<p>The culprit was a single leftover folder: a Python virtual environment the <em>first</em>, failed install had created <strong>as root</strong>. My cleanup step deleted the source tree as my normal user, which silently skipped the root-owned folder it wasn&rsquo;t allowed to touch. So every re-clone found a non-empty directory and bailed, and every log I read was from a half-built tree.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">$ rm -rf OpenPLC_v3        # runs as me, can&#39;t remove root&#39;s files
</span></span><span class="line"><span class="cl">$ git clone ... OpenPLC_v3
</span></span><span class="line"><span class="cl">fatal: destination path &#39;OpenPLC_v3&#39; already exists and is not an empty directory
</span></span></code></pre></div><p>One <code>sudo rm -rf</code> and the loop broke. It&rsquo;s a dumb bug, but it&rsquo;s the exact flavor of dumb bug that eats an hour, because the error (<code>git</code> complaining about a directory) points nowhere near the cause (a permissions mismatch from a crash two steps earlier). Worth internalizing: when a &ldquo;clean&rdquo; step runs as one user and the mess was made by another, the clean is a no-op and nothing tells you.</p>
<h2 id="attacking-the-plc">Attacking the PLC</h2>
<p>With OpenPLC installed, I logged into its web HMI, loaded a program, and hit <strong>Start PLC</strong>. Port 502 opened, and the lab had a live Modbus target.</p>
<p>Here&rsquo;s the thing about Modbus that makes it such a clean teaching tool: <strong>it has no authentication.</strong> None. If you can reach port 502, you can read and write the controller&rsquo;s memory. No login, no token, no handshake. The protocol was designed in 1979 for a trusted serial loop, and the TCP version just wrapped it in a header.</p>
<p>My attacker is a short script that builds Modbus frames by hand. First, read some coils (Modbus&rsquo;s name for single-bit outputs):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">[enumerate] reading the PLC&#39;s memory map
</span></span><span class="line"><span class="cl">  coils[0..15]        -&gt; 00 00
</span></span><span class="line"><span class="cl">  holding_regs[0..7]  -&gt; 00 00 00 00 00 00 00 00
</span></span></code></pre></div><p>Then the part that matters. One function code, <code>0x05</code>, &ldquo;write single coil,&rdquo; and the PLC&rsquo;s state is mine:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">[write] unauthorized state change
</span></span><span class="line"><span class="cl">  before: coil 0 = 0
</span></span><span class="line"><span class="cl">  write coil 0 = ON   -&gt; ack
</span></span><span class="line"><span class="cl">  after:  coil 0 = 1
</span></span></code></pre></div><p>That <code>0 -&gt; 1</code> is the whole point of OT security in one line. On a real controller, coil 0 isn&rsquo;t an abstraction; it&rsquo;s wired to something. A relay, a pump, a valve, a breaker. I didn&rsquo;t exploit a bug or crack a password. I asked, politely, over the network, and the PLC did it, because asking is the entire protocol. This is why the field treats the network boundary as the security boundary: the devices behind it have no other defense.</p>
<h2 id="putting-a-detector-in-front-of-it">Putting a detector in front of it</h2>
<p>If you can&rsquo;t authenticate the protocol, you watch it. That&rsquo;s the job Suricata does here: sit on the wire, parse what goes by, and alert on things that shouldn&rsquo;t happen, like a write to a controller from somewhere it shouldn&rsquo;t come from.</p>
<p>My first pass at rules was the obvious one. A Modbus function code sits at a fixed spot in the packet, seven bytes in, so I wrote content rules that match that byte:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">alert tcp any any -&gt; any 502 (msg:&#34;Modbus Write Single Coil (FC05)&#34;;
</span></span><span class="line"><span class="cl">    flow:to_server,established; content:&#34;|05|&#34;; offset:7; depth:8; sid:1000005;)
</span></span></code></pre></div><p>One rule per write function code, plus one for the connection itself. I ran the full attack, tailed the alert log, and it lit up. Writes detected, connection detected. Looked great.</p>
<p>It was not great.</p>
<h2 id="the-lie">The lie</h2>
<p>I counted the alerts by type, and two numbers were wrong in opposite directions.</p>
<table>
	<thead>
			<tr>
					<th>Alert type</th>
					<th>What my rules reported</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Modbus connection</td>
					<td>33</td>
			</tr>
			<tr>
					<td>Write Single Coil (FC05)</td>
					<td>44</td>
			</tr>
			<tr>
					<td><strong>Write Multiple Registers (FC16)</strong></td>
					<td><strong>12</strong></td>
			</tr>
			<tr>
					<td><strong>Read requests (recon)</strong></td>
					<td><strong>0</strong></td>
			</tr>
	</tbody>
</table>
<p>Start with the 12. My attacker <strong>never sends</strong> a &ldquo;write multiple registers&rdquo; command. That function code, <code>0x10</code>, appears nowhere in my attack. So where did twelve alarms come from?</p>
<p>From a <em>read</em>. One of my attack steps is a quiet reconnaissance sweep that reads registers starting at <strong>address 16</strong> — and 16 is <code>0x10</code> in hex, the same byte as the write-multiple-registers function code. My crude rule matched that byte wherever it fell in the packet, so a harmless read of address 16 tripped a &ldquo;someone is rewriting the controller&rsquo;s registers&rdquo; alarm, twelve times.</p>
<p>Now the zero. That same recon sweep, all reads, produced <strong>no read alerts at all</strong>, because I hadn&rsquo;t written a rule for reads. An attacker mapping out my PLC&rsquo;s entire memory, the exact quiet step that precedes a real attack, was invisible. The only trace it left was buried under twelve false alarms about a write that never happened.</p>
<p>So my detector did both failure modes at once. It <strong>cried wolf</strong> about an attack I didn&rsquo;t launch, and it <strong>slept through</strong> the reconnaissance I did. In an office-IT setting that&rsquo;s an annoying tuning problem. In OT, where an operator might have seconds to decide whether a &ldquo;controller rewrite&rdquo; alert is real while a process runs away from them, a detector that fabricates that exact alert from a routine read is worse than no detector at all. It spends the one thing you can&rsquo;t buy back during an incident: trust in the alarm.</p>
<h2 id="the-fix-stop-poking-at-bytes">The fix: stop poking at bytes</h2>
<p>The problem was that I was pattern-matching raw bytes without understanding them. The byte <code>0x10</code> means &ldquo;write multiple registers&rdquo; <strong>only</strong> when it&rsquo;s the function code, not when it&rsquo;s an address, or a value, or a byte count that happens to equal sixteen. Telling those apart requires actually parsing Modbus, not grepping for a number.</p>
<p>Suricata can do that. It ships a real Modbus protocol parser; it just wasn&rsquo;t turned on. Once enabled, I could throw away the byte-poking and write rules against the <em>decoded</em> protocol:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl"># before: match byte 7 and hope
</span></span><span class="line"><span class="cl">content:&#34;|05|&#34;; offset:7; depth:8;
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"># after: match the actual, parsed function code
</span></span><span class="line"><span class="cl">modbus: function 5;
</span></span></code></pre></div><p>And, finally, a rule for the thing I&rsquo;d missed entirely:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">alert tcp any any -&gt; any 502 (msg:&#34;Modbus READ request (recon/monitor)&#34;;
</span></span><span class="line"><span class="cl">    modbus: access read; sid:1000100;)
</span></span></code></pre></div><p>Same attack, same wire, new rules:</p>
<table>
	<thead>
			<tr>
					<th>Alert type</th>
					<th style="text-align: right">Byte rules</th>
					<th style="text-align: right">Protocol parser</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Connection</td>
					<td style="text-align: right">33</td>
					<td style="text-align: right">33</td>
			</tr>
			<tr>
					<td><strong>Read requests (recon)</strong></td>
					<td style="text-align: right"><strong>0</strong></td>
					<td style="text-align: right"><strong>11</strong></td>
			</tr>
			<tr>
					<td>Write Single Coil (FC05)</td>
					<td style="text-align: right">44</td>
					<td style="text-align: right"><strong>21</strong></td>
			</tr>
			<tr>
					<td>Write Single Register (FC06)</td>
					<td style="text-align: right">6</td>
					<td style="text-align: right"><strong>1</strong></td>
			</tr>
			<tr>
					<td><strong>Write Multiple Registers (FC16)</strong></td>
					<td style="text-align: right"><strong>12</strong></td>
					<td style="text-align: right"><strong>0</strong></td>
			</tr>
	</tbody>
</table>
<p>Every number got honest. The twelve phantom write alarms went to zero, because the parser knows address 16 isn&rsquo;t function 16. The invisible reconnaissance went from zero to eleven, because now there&rsquo;s a rule that understands &ldquo;read.&rdquo; And the write counts dropped to exactly what I actually sent, one register write, twenty-one coil writes, no more double-counting a retransmitted packet as two attacks.</p>
<h2 id="what-the-lab-actually-taught-me">What the lab actually taught me</h2>
<p>I set out to learn how to attack and defend a PLC. I did, and the attack half was almost anticlimactic: Modbus has no authentication, so &ldquo;attacking&rdquo; it is just using it. The defense half was where the real lesson hid, and it wasn&rsquo;t the one I expected.</p>
<p><strong>Detection quality is a thing you can measure, and bad detection has two failure modes that look nothing alike.</strong> Mine over-fired and under-fired at the same time, from the same lazy shortcut. A false positive isn&rsquo;t just noise; during an incident it&rsquo;s an active lie that competes with the real signal for an operator&rsquo;s attention. A false negative is a quiet hole an attacker walks through. The only fix was to make the detector actually understand the protocol it was watching instead of squinting at its bytes.</p>
<p>There&rsquo;s a caveat I&rsquo;ll be honest about: in my lab the IDS sniffs the PLC&rsquo;s own network interface, which is a convenient shortcut, not how a real plant does it. In the field the sensor sits on a tap or a span port, watching the segment from the side, so a compromised controller can&rsquo;t blind its own watcher. That&rsquo;s the next thing I want to rebuild properly.</p>
<p>None of this took special hardware. A VM, a free PLC runtime, a free IDS, and a hundred lines of script. If my <a href="../ot-ics-security/">last post</a> made you curious about OT security, this is the afternoon I promised would teach you more than a week of reading. The protocol really does just do what you tell it. The interesting question is who&rsquo;s watching when you do, and whether you can believe what they tell you.</p>
]]></content:encoded></item></channel></rss>