Tag: network segmentation

  • Patronus: a time limit on one device, and the browser tab that stayed stuck

    Patronus: a time limit on one device, and the browser tab that stayed stuck

    Full disclosure: I make Patronus, a router and firewall OS built on Gentoo. It’s young. Version 0.2.0 came out on October 30.

    Most of what I write about it comes out of CI logs, and a green netlab run tells you very little about what a feature is like to use. So on November 8 I took one 0.2.0 feature, per-device time limits, and used it the way a parent would. I set a policy, pushed traffic through the router from a pretend tablet, watched the tablet get cut off, and pressed the buttons.

    What this setup is

    It’s a lab, not my house. One container with four network namespaces: the router (the real patronus-web and patronus apply built from main, commit 9f5b2361), a LAN client I called kids-tablet, a fake ISP, and a fake internet that uses documentation addresses and *.example.test names. The browser on the “tablet” runs inside the client namespace, so every page it loads really crosses the router.

    The clock is the one fake part. I moved the router’s time with PATRONUS_FAKE_TIME_FILE, the knob the tests use, so an evening took half a minute. Bytes, conntrack counters, nft sets and the pages are real. The passing of time isn’t, so this covers one quota day and a few next-day checks, not a month of living with it. That’s also why the screenshots say 2026-11-09.

    The policy

    120 minutes a day, only between 16:00 and 20:00, a warning 5 minutes before the cut, the day resetting at 06:00, attached to a group called kids. kids-tablet is the only device in that group.

    Time limits page: kids-tablet has used 45 of 120 minutes, with buttons to add 30 minutes or pause the internet, above a policy of 120 minutes a day between 16:00 and 20:00 applied to the kids group
    The Time limits page under Segmentation. The policy table is at the bottom.

    A minute only counts if the device moved more than a byte threshold in it (20000 bytes by default, taken from conntrack counters). The docs say the point is that a tablet sitting idle doesn’t use up the day. Minutes spent blocked don’t count either: the tablet sat at 120 of 120 while I reloaded the blocked page over and over.

    Green usage bar at 46 of 120 minutes, state online ok
    46 of 120, after real traffic through the router.
    Amber usage bar at 115 of 120 minutes, state ending soon
    115 of 120. This is where the warning fires.

    At 115 the tablet’s next plain http page was replaced by a “5 minutes left” notice. That’s a one-shot redirect that lasts two minutes.

    Warning page on the tablet: 5 minutes left
    What the tablet shows.

    The clip

    This is the tablet’s browser on the left and the router’s admin page on the right, recorded in one take with no cuts and no speed changes. I added the labels and captions afterwards. The 118 minutes of usage before the clip came from real traffic, not from editing the database.

    The quota runs out and the tablet gets “Time’s up”. Then +30 minutes, pause, resume. 32 seconds, real time apart from the simulated clock.

    Quota runs out and the tablet gets “Time’s up”. I press +30 min today and access comes back. I press Pause internet now and it’s blocked again 97 ms after the click. Resume and it works again. After each restore I open a different site in the tablet instead of reloading the old tab, and there’s a reason for that further down.

    Time's up page on the tablet saying the internet is switched off and when it comes back
    The other way to get cut off: the 16:00 to 20:00 window closed.

    What it does in the kernel

    Enforcement is its own nft table, inet patronus_time, hooked at priority -11 so it runs ahead of the isolation table at -10. The docs say each change is one atomic nft -f, so other devices don’t see a blip when one device is toggled. A blocked tablet is three set elements: its IPv4 address in blocked_v4, its MAC in blocked_mac for IPv6, and the warning set for the two minutes after a warning.

    nft ruleset of the patronus_time table with the tablet address in the blocked set
    nft list table inet patronus_time while the tablet was blocked. The text is the real output. I added the colouring.

    The router keeps answering ICMP and DNS for a blocked device and serves the page on :8081. I checked that ping and name lookups work, that the admin port times out, and that outbound TCP gets a reset. I did not test DHCP or SSH while blocked. After a simulated reboot (fresh namespaces plus patronus apply, no web UI yet) the tablet was already blocked and its usage was unchanged.

    Timings from the lab: with a new TCP connection per probe, pause to first “Time’s up” response took 7 to 20 ms over 8 cycles, and resume to first real page 8 to 14 ms. Parent buttons act immediately. Window and quota changes are picked up by a ticker that runs every 5 seconds by default, so with the real default the page changed 4 to 5 seconds after a window edge.

    Tests: 15 firewall unit tests and 2 captive-portal tests cover this code and they pass. The web crate has no time-limit unit tests of its own. There’s also a netlab scenario, lane-s-time.sh, which I did not run this time. No commit has touched the time-limit code since October 30.

    What doesn’t work (yet)

    The one that annoyed me most is the stuck tab. A tab that was redirected to the time’s-up page keeps its connection to the router’s page server. After +30 min or Resume the old tab reloads, but it lands on the router’s own “You’re all set” page and stays there. In the runs where I kept reloading it, it took anywhere from 16 seconds to over two minutes to recover, and in one run it hadn’t recovered after 80 seconds. A new browser context or a different site works at once. Force-quitting the browser recovers faster than pressing reload. That’s why the clip opens a different site after each restore. I haven’t fixed it.

    https gets nothing useful. Only port 80 is redirected, so on an https site the browser shows its own connection error and apps just say there’s no internet. The “Time’s up” page only shows up for plain http.

    Identity is the device’s IPv4 address, plus its MAC for IPv6. With the tablet paused I gave the same client another address and the internet worked, because only the old address was in the blocked set. A device that isn’t enrolled isn’t limited at all. The docs admit a phone that rotates its MAC on every connection can’t be bound.

    IPv6 is cut but not counted. I got an IPv6 path working and the pause did stop it, but three simulated minutes of IPv6-only downloads left the usage at 4 minutes before and 4 after. The “Time’s up” redirect is IPv4 only too.

    Accounting is a byte threshold per whole minute, so it isn’t a screen-time meter. One 47 KB response costs a full minute. Fifteen tiny connections in a minute cost nothing, thirty cost one. If you give a group a policy you get one quota per device, not a shared family pool, and bonus minutes are per device as well.

    The enforcer lives in the web process. The ticker runs inside patronus-web. With it stopped and the clock moved 30 minutes past the end of the window, the tablet stayed online for the 10 seconds I watched. With it stopped and an already-blocked tablet, the tablet got connection refused instead of a page, since nothing was serving :8081. It catches up within a fraction of a second when the web process starts again.

    A transfer already running when I paused did not fail fast. A 10 second stream delivered about 16 KB before the pause and 20 KB shortly after, then stalled until the client’s own 14 second timeout.

    Minor things: in the policy form the seven day checkboxes stack in one tall column, the “who it applies to” form doesn’t preselect the current policy, and the usage table refreshes on a 15 second timer, so the admin page lags the tablet by a few seconds.

    Things I haven’t tried at all: a real DoH client or VPN app, the stricter mode that also cuts DNS, a per-device policy overriding a group one, captive-portal probes from a real Android or iPhone, DST or NTP steps, and anything over more than a day of real clock time. DNS stays open while blocked by default, and I didn’t look for anything that stops someone tunnelling through it.

    Where it stands

    It does the basic job in the lab: a device with a policy gets cut when its quota or window runs out, a parent can add time, pause or resume, and the block survives a reboot. It’s less finished than the changelog suggests. I’d fix the stuck tab first, since parents will think the button failed. I have no fixes for any of the items above yet.

    Next: a few days on a real clock with a real phone.

    Patronus lives at patronus.errant.solutions.

  • Segmentation and limiting lateral movement

    Segmentation and limiting lateral movement

    Part 2 of 3 in the Surviving ransomware series. Part 1: Backups an attacker can’t delete.

    When NotPetya hit in June 2017, it didn’t need anyone to click anything after the first infection. It spread across networks on its own, using the EternalBlue exploit for SMBv1 (MS17-010) and credentials harvested from memory on machines it had already reached, then running itself remotely with legitimate Windows tools. Maersk lost tens of thousands of machines in a few hours. The White House later put the total global damage at more than $10 billion.

    What made it so destructive wasn’t novel malware engineering. It was flat networks and shared credentials. Every compromised machine could reach thousands of others, and many of them would accept the same admin password.

    Part 1 of this series covered backups an attacker can’t delete. This part is about making the attacker’s path to those backups, and to everything else, as short and noisy as possible.

    Two kinds of segmentation

    Flat network compared with a segmented network of zones and allowlisted flows

    Most people think of segmentation as VLANs and firewalls. That’s half of it. The other half is identity segmentation: which credentials exist on which machines. An attacker moves laterally by combining reachability (can I connect to that host?) with authority (do I have a credential it accepts?). Take away either one and the move fails.

    Network segmentation limits reachability. Identity segmentation limits the value of whatever credentials an attacker steals. You need both, and the identity half is usually cheaper.

    Workstations shouldn’t talk to each other

    In most offices there’s no business reason for one laptop to open an SMB, RDP or WinRM connection to another laptop. Yet in a default Windows domain with file sharing enabled, that’s exactly what’s allowed, and it’s how a single phished laptop becomes fifty.

    Block it. Inbound SMB (445), RDP (3389) and WinRM (5985 and 5986) on workstations should only be accepted from a small management subnet where your admin jump hosts and management tools live. In Group Policy you’d scope the inbound firewall rules to that subnet. The PowerShell equivalent on a single machine shows the idea:

    # Allow inbound SMB, RDP and WinRM only from the management subnet
    $mgmt = "10.20.0.0/24"
    Get-NetFirewallRule -DisplayGroup "File and Printer Sharing",
                                      "Remote Desktop",
                                      "Windows Remote Management" |
      Where-Object { $_.Direction -eq "Inbound" -and $_.Enabled -eq "True" } |
      Set-NetFirewallRule -RemoteAddress $mgmt

    Then check it from an ordinary workstation, not from the admin network:

    Test-NetConnection -ComputerName ws-0142 -Port 445
    # TcpTestSucceeded : False   <- what you want to see

    I’ve watched this single change turn a domain-wide incident into a handful of machines. It’s dull, cheap, and it breaks almost nothing.

    Servers get allowlists, not blocklists

    Servers are harder because they do need to talk to each other, just not to everything. Start from observed flows. VPC flow logs, NetFlow from your switches, or a few weeks of host firewall logging will show you what actually connects to what. Then write rules that permit those flows and drop the rest.

    On a Linux database server, the host firewall alone can enforce most of it:

    # /etc/nftables.conf (excerpt)
    table inet filter {
      chain input {
        type filter hook input priority 0; policy drop;
        ct state established,related accept
        iif "lo" accept
        ip saddr 10.20.0.0/24 tcp dport 22 accept     # admin jump hosts only
        ip saddr 10.30.1.0/24 tcp dport 5432 accept   # application tier only
        icmp type echo-request limit rate 5/second accept
      }
    }

    Host firewalls and network firewalls complement each other. The network layer protects you when a host is misconfigured, and the host layer protects you from the neighbour in the same VLAN. Microsegmentation products automate this at scale, but the principle doesn’t need a product.

    Tier your admin accounts

    Microsoft’s tiering guidance, now folded into its enterprise access model, comes down to one rule: a credential that controls a high-value system must never be typed into, or cached on, a lower-value system. Domain admin accounts don’t log on to workstations. Server admin accounts don’t log on to workstations either. Help desk accounts that do manage workstations have no rights on servers.

    When an attacker dumps credentials from a compromised laptop, tiering decides what they find. With it, they get the laptop user and maybe a workstation-admin account. Without it, they often get domain admin, because someone remoted in to fix a printer driver last month.

    The supporting controls are well documented and mostly free:

    • Windows LAPS, built into Windows since the April 2023 updates, gives every machine a unique, rotated local administrator password, which kills the “same local admin password everywhere” path NotPetya-style tools rely on.
    • The Protected Users group stops its members’ credentials from being cached in ways that are easy to steal, and blocks NTLM authentication for them.
    • Credential Guard isolates secrets in virtualisation-based security so that memory scraping on the endpoint returns far less.
    • Restricting or auditing NTLM reduces relay and pass-the-hash opportunities. Start in audit mode, because something old in your environment will depend on it.

    Admins work from dedicated privileged access workstations or jump hosts in the management subnet. That’s what makes the firewall scoping above workable.

    Put the crown jewels behind their own door

    Some systems deserve their own zone with its own entry controls: domain controllers, backup infrastructure, hypervisor management, PKI, and identity providers. As covered in part 1, the backup server in particular shouldn’t be reachable from general server networks, and shouldn’t trust the production domain.

    The test I use is simple. Pick a random workstation and a random application server, assume both are fully compromised, and ask how many hops it takes to reach a domain controller or the backup console. If the answer is “one” or “it’s in the same VLAN”, that’s your next project.

    See the east-west traffic

    Segmentation also makes detection easier, because it creates boundaries where unusual traffic stands out. A workstation attempting SMB connections to forty other workstations in five minutes should alert. So should a service account authenticating to hosts it has never touched before, or remote service creation (Windows event 7045) on machines where nobody deploys software that way. Firewall drop logs between zones are useful here: once the rules are tight, almost every drop is worth a look.

    Expect it to be incremental

    Nobody segments a flat network in a quarter. Start with the workstation peer-to-peer block and LAPS, which together cover a huge share of real-world spread. Then tier the admin accounts, then wall off the crown jewels, then work through server allowlists one application at a time.

    Even perfect segmentation won’t stop every incident. It buys time and turns a company-wide outage into a contained one, which matters a lot when you get to part 3: actually restoring what was hit, and finding out how long that really takes.

    Other parts: Part 1: Backups an attacker can’t delete. Part 3: Restore testing and your real recovery time.