Dev.to Security 🔐 Cybersecurity 👁 0 📖 5 min read

My Bash network tool was lying to me, so I rewrote it in Rust

For years I had a Bash script called netRo.sh. It was a 733-line interactive dashboard I used to check servers: CPU, memory, network, a few "security" checks. It felt useful until the day I actually read it carefully. I

For years I had a Bash script called netRo.sh. It was a 733-line interactive dashboard I used to check servers: CPU, memory, network, a few "security" checks. It felt useful until the day I actually read it carefully.

I sat down and wrote an audit of my own script, line by line, and it hurt. A function called update_system_info() did nothing but sleep 2 to look busy. The rootkit check always printed "skipped", forever. The unauthorized-users check flagged every account with UID under 1000, which on Linux is every system account, so it cried wolf on a clean machine. My "suspicious process" detector grepped for nmap, wireshark and tcpdump, which is to say it accused every network engineer of being a hacker. And the worst one: a "block device" feature ran iptables and then wrote the rules permanently to disk, with sudo, with no confirmation and no rollback.

No tests. No CI. No machine-readable output. Linux only. I had trusted this thing.

So I kept the idea and deleted the code. netRo 5.0 is a full rewrite in Rust, and this post is about the one rule that shaped every decision in it.

The rule: no fake data

Every result netRo prints comes from a real check. Anything a platform cannot do is reported as UNSUPPORTED, DEPENDENCY_MISSING or PERMISSION_DENIED, with a hint. This sounds obvious until you look at how many tools quietly guess. My old script guessed constantly.

The rule has teeth because of the error model. Every failure returns a structured error with a stable code (PERMISSION_DENIED, TIMEOUT, UNAUTHORIZED_SCAN, and so on), a message, and a hint, mapped to specific exit codes. A missing tool degrades one check instead of killing the whole run, which is what set -e did to the old script every time a dependency was missing.

Architecture that enforces the rule

The code is layered: a clap CLI and a ratatui TUI both sit on top of a commands layer, which calls a portable core, which talks to the OS only through provider traits.

SystemProvider, NetworkProvider, ProcessProvider, SecurityProvider, FirewallControl: adding a platform means implementing those traits, nothing in core/ changes. Linux providers parse /proc and /sys and drive ufw, firewalld, nftables and iptables. Windows providers call PowerShell and CIM. macOS uses netstat, lsof, scutil, socketfilterfw and system_profiler. I can verify the layering with one grep: there is not a single OS command string in src/core/.

The TUI is a second presentation layer over the same engine. It contains zero diagnostics of its own and never builds a command line. If the CLI and the TUI ever disagreed, that would be a bug in exactly one place.

The no-shell policy

There is no sh -c, bash -c or cmd /c anywhere in the codebase. Every external program runs with an explicit argument vector, resolved to an absolute path first so a poisoned PATH cannot swap in a different binary during a privileged call.

Windows was the interesting one. The PowerShell bridge passes fixed scripts through -EncodedCommand (UTF-16LE base64). User input is never concatenated into script text; the only user data that crosses the boundary is validated IP literals for firewall rules. Targets are validated for length, characters and a leading dash even though no shell ever re-parses them, because defense in depth is cheap.

Things that were harder than they look

DNS. I wanted real queries without depending on nslookup, so netRo has a built-in DNS client: UDP with TCP fallback, A/AAAA/CNAME/MX/TXT/NS/SOA/PTR/SRV records, RTT measurement, custom servers, reverse lookups. Parsing DNS is a rite of passage: compression pointers, loops, bounds checks. The tests include NXDOMAIN handling and pointer-loop attacks.

TLS. Port scanning is a TCP connect scan (SYN scanning is explicitly not implemented and the docs say so), but on open ports netRo grabs the service banner and probes TLS certificates with rustls to tell you what is actually listening and when its certificate expires. The TLS dependency is feature-gated so you can cross-compile without a C toolchain for the target.

Privileges. netRo never runs sudo on its own. Firewall changes check elevation first and fail with PERMISSION_DENIED plus the exact hint for your platform. There is a --dry-run that prints the exact commands and rollback without root, and applying a change requires confirmation or --yes, shows every command, and records rollback state so unblock only removes rules netRo itself created. My old script's silent iptables-save is the reason this exists.

The doctor command. One command runs every check and produces a score. The score is transparent: every deduction is listed by category with evidence, impact and a recommendation, and informational findings never lower it. A score you cannot explain is just a number that makes people anxious.

Numbers

On Linux x86_64 with the release build: startup is about 12 ms. A 10,000-port localhost scan with 512 workers takes about 370 ms. The full doctor run is about 4.7 s at 22 MB RSS. Steady-state monitoring costs about 16 ms per sample. The binary is a single static executable (thin LTO, stripped), and CI builds and tests it on Ubuntu, Windows, macOS Intel and Apple Silicon. There are 239 tests, including end-to-end CLI contract tests and snapshot-rendered TUI tests that inject hostile ANSI payloads into remote-derived strings to prove they cannot reach your terminal.

What I would tell past me

Writing the audit document was the most valuable hour of the whole project. Reading your own old code as if you were an auditor, and writing down every finding with a disposition, turns "my script is probably fine" into a concrete list you can fix one by one. The audit of the old script is still in the repo (docs/AUDIT.md), next to the engineering audit of the rewrite, because I want the receipts public.

netRo is MIT licensed: https://github.com/ALSRKAL/netRo. Linux is the primary, fully tested platform; Windows and macOS pass compile and CI runtime tests but I would genuinely love bug reports from real machines there. If you try the doctor command on something weird, I want to hear about it.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.