paint-brush
When Coding Determines the Survival of The Cityby@pepitoscrespo
343 reads
343 reads

When Coding Determines the Survival of The City

by pepitoscrespoOctober 7th, 2024
Read on Terminal Reader
Read this story w/o Javascript

Too Long; Didn't Read

Can C++ outmatch Rust in real-world system control and security? Dive into a hacker’s battle to save LuxCity and explore the limits of both languages
featured image - When Coding Determines the Survival of The City
pepitoscrespo HackerNoon profile picture


We programmers often find ourselves caught up in debates — C++ vs. Rust, high-level vs. low-level programming. But the real challenge isn’t just crafting elegant systems; it’s protecting them in today’s networked world, where malicious code is always lurking. No matter how flawless your code seems, ignoring potential threats is an invitation to disaster.


It’s not enough to patch security holes or release the next update. The real battle is in mounting an effective response when — yes, when, not if — your system is breached. This means implementing proactive intrusion detection, automating defense mechanisms, and sometimes getting your hands dirty with low-level programming to tackle threats at their source.


The battlefield extends beyond high-level logic into the very core of the system, where only the most skilled developers can effectively fight back. If you’re not prepared to counteract attacks at this level, all the safety features in the world won’t save you. In cybersecurity, defense without the ability to respond isn’t sufficient.


The Dark Side of the Mighty C Family, the Rise of the Rootkits: Tiny Code, Big Power

Alright, let’s talk about the C family — C, C++, the whole crew. These languages give you ultimate freedom. You can build elegant, high-performance systems that’ll make your peers jealous. But here’s the flip side: that same freedom lets you create some of the most dangerous code out there — rootkits and their even sneakier cousins, bootkits. These aren’t just harmless lines of code lounging around — they’re the silent predators of the software world.


So, what’s the real difference between rootkits and bootkits?

  • Rootkits are designed to operate inside the operating system. They manipulate system processes, hide malicious activities, and tweak software programs. But they kick in after the OS boots up.

  • Bootkits hit you even harder. They attack the system before the OS is even running. They infect the Master Boot Record (MBR) or UEFI/BIOS firmware, gaining control before your OS can do a thing about it.


Most of the time, what people think of as a rootkit attack is actually a combo of both. Bootkits take over from the very start, while rootkits step in once the OS is up and running, letting the attack continue unnoticed. Basically, bootkits get in early, rootkits keep the show going.


Now, you’re probably thinking: “What’s the deal if the OS is coded in Rust instead of the supposedly unsafe C/C++/Assembly?


Here’s where things get interesting. Let’s be real — in today’s tech world, we’re dealing with hybrid systems, networks intertwined in complex webs where performance and precise control are absolutely essential. Think SCADA systemsHVAC controlsreal-time systemsedge computingembedded devices — you get the idea. In these environments, no matter how “safe” a language claims to be, you’re still relying heavily on C/C++/Assembly for that fine-grained control and performance.


And even if the system is built with Rust, let’s be honest — a lot of it still uses sizable chunks of unsafe Rust code to deal with performance bottlenecks, latency issues, memory constraints, and to interact directly with hardware. At the end of the day, when performance is king, you end up in the same boat. Those unsafe blocks in Rust? They open up the same vulnerabilities you'd have in C/C++/Assembly.


The reality is this: when you need fine-tuned control at the hardware level, you’re walking the same tightrope, whether your OS is coded in Rust or something else. So while Rust might offer some guardrails, those low-level unsafe operations are still vulnerable. Rootkits and bootkits don't care about your language preferences—they'll find their way in if there's a crack.


Rootkits Zone: Enter at Your Own Risk


These digital predators don’t just infect a system — they own it. And here’s the main thing: most of them are built using the classics — C, C++, and Assembly. That’s right, the same languages powering your high-performance apps are also behind some of the nastiest rootkits ever created.


Think about evolution for a second. It’s like the journey from those tiny, carnivorous dinosaurs of the Triassic period to the towering theropod monsters of the Cretaceous, like the T-Rex. Just like those early dinos evolved into apex predators, rootkits have transformed from relatively “cute” beginnings into today’s terrifying behemoths of code.


Take Hacker Defender, for example — this tiny cyber-reptile was just 3K lines of code, exploiting basic OS gaps. But like any good predator, it evolved. Today’s rootkits are monsters, split into modules with thousands of lines of code each, targeting not only operating systems but also hardware-level vulnerabilities. It’s an arms race, with each new rootkit pushing the boundaries of what’s possible.


So, in this article, we’re diving into two stories. The first one? The official version you’ll find in tech resources like Rootkits and Bootkits by Alexander Matrosov, Eugene Rodionov, and Sergey Bratus. This is pretty much the go-to guide for all the nitty-gritty details of rootkit evolution. To make things easy for you, I’ve put together a cladogram below that sums up the development of these rootkits — each branch representing a new leap in malware sophistication.


After that, you’ll find a table highlighting the unique features of each rootkit. Trust me, you’ll want to see how these bits of code transformed from tiny, opportunistic intruders into system-dominating beasts.

Here we go


Evolution of Rootkits


Rootkit Evolution: Grouping by Families

The table shows the progression of rootkits over time, highlighting their revolutionary features, the programming languages used, and their code size.


But there’s another side to this story — the view from someone who doesn’t just write rootkits but lives and breathes them. Meet our main character: a hacker who sees rootkits as extensions of himself — a symphony of code meticulously designed to disrupt and dominate. He’s not just any hacker; he’s a legend, the top-tier mastermind known only as Lizard-the-Wizard.


From his perspective, this isn’t just about tech or code — it’s about power, control, and maybe even a touch of artistry. To him, rootkits aren’t just tools; they’re masterpieces, his way of reshaping the digital world.


So, without further ado, let me introduce you to the man himself — Lizard-the-Wizard, in his own words:

Every Artist Needs a Muse: The Old Masters of Rootkits

Lizard-the-Wizard Speaks in Dreams: My Masterpieces


“Ah, you’re still here. I wondered how long it would take you, Benicio, to realize you were playing right into my hands. While you’ve been so enamored with your little Rust and its safety nets, I’ve been working on something far more… exquisite.”


“Exquisite. That’s a word you probably don’t associate with malware, but that’s because you’ve been too wrapped up in protecting your little systems to appreciate the art behind the attack. Yes, art. You think I’m just a hacker? No, no — I’m an architect, a creator. Every rootkit I’ve ever studied has been a brushstroke in the grand portrait I’m painting on the canvas of chaos.”


Here the Two Main characters of our Story: the Cplusser (Lizard-the-WizardI ) vs the Rustacean (Benicio)


Lizard-the-Wizard continues:

“You know, even the greats — Da Vinci, Van Gogh, Bach — they all learned from the masters before them. Me? I had Hacker Defender and Rustock. Hacker Defender was my Houdini, showing me how to slip code into systems, making files and processes vanish like magic. And Rustock? That was my Picasso moment — polymorphism at its finest, constantly shifting, evolving, changing form like a painting that morphs every time you look at it.”


“But those? They were just stepping stones to what I knew I could create. Then came Alureon. It didn’t just sit in the system — it was carved into the core, striking the Master Boot Record (MBR). That’s the very first sector of your hard drive, the part that tells your OS how to even begin booting up. You know what that kind of control feels like, Benicio? Divine. It’s like hearing Rachmaninoff’s Second Concerto for the first time. Pure beauty, but etched in code.”


“And still, I wasn’t satisfied. ZeroAccess was my symphony. It built an army, turning machines into a peer-to-peer botnet, every infected system playing its role in a chaotic masterpiece. It was no longer just about one infection; it was about conducting chaos across a network. That’s where you fall short, Benicio. You’re stuck chasing Rust’s harmony, while the real art lies in the dissonance — the chaos that births a masterpiece.”



Infection vectors and rootkits are best friends


“And finally came LoJax and MoonBounce. These weren’t just rootkits — they were evolutions, pushing the boundaries of what malware could be. LoJax, embedded deep into the UEFI, controlled systems at a level even your beloved Rust couldn’t touch. MoonBounce took it further, diving into SPI flash memory, hiding where no antivirus or system wipe could ever reach. It didn’t just hide in the system — it became part of the hardware, permanent and untouchable, like a Michelangelo fresco etched into silicon.”


“That’s when I understood the real truth: control isn’t in the CPU or the OS. True control lies in the hardware. And that’s where I crafted my masterpieces.”


Enter Lizard-Blue and Lizard-Red — my Sistine Chapel of rootkits. Do you know how they were born, Benicio? I’ll tell you, because you need to understand the genius that outplayed you.”


“Lizard-Blue was engineered with you in mind. You, so proud of your Rust with its safety guarantees. Lizard-Blue danced through your unsafe blocks, threw your multithreading into chaos, disrupted your I/O systems — all to distract you. It was a fool’s mate: simple and elegant. While you scrambled to chase down Lizard-Blue, my true masterpiece, Lizard-Red, had already taken root.”


But Lizard-Red didn’t care about your CPU or software. No, it went straight for the SPI flash memory, slipped into your DMA controllers, and quietly rewrote your system from the inside out. Like a hidden symphony, it played on unseen, rewriting firmware, unstoppable.”


“This is real control, Benicio. While you were busy patching software, I mastered the hardware. Tell me, why did you abandon C++ for Rust? Rust… so promising, so safe. But remember, Benicio, true power doesn’t come from safety. It comes from control. And now, you’ll never forget that.”


The first blackouts spread from the outskirts toward the center after every smart grid reset.

The stage is set. A showdown between a top-tier C++ master and an army of C++ renegades who’ve turned to Rust is about to ignite in LuxCity — or worse, plunge it into darkness. The stakes? Complete control — not just of code, but of the very infrastructure that keeps this metropolis alive.


The city, buzzing with energy, is about to become the battleground. Benicio, fortified by his Rust-powered defenses, faces a challenge he never saw coming — a challenge crafted by the master of C++ himself, Lizard-the-Wizard, determined to bring these renegade Rustaceans back into the fold. Two forces, two philosophies, on a collision course. But this isn’t just about programming languages — it’s a fight for control of systems, power, and maybe, just maybe, the future of programming, damn it!


LuxCity wasn’t just a metropolis — it was a symbol of what tomorrow could look like. Its streets hummed with autonomous vehicles, and the skies were alive with smart drones directing traffic from above. But beneath all that progress lay the city’s true lifeblood: the smart grid — a complex, intricately woven system that kept everything running smoothly.


In the control room high above the city, Alice and Bob, seasoned veterans of the grid, stared at the chaos unfolding on their monitors. The first blackout seemed like a small glitch — something they could handle. But it spread, district after district plunging into darkness. Power flickered uncontrollably, and with each reboot, things only got worse. Alarms blared, and the monitors flashed warnings of a deeper, hidden crisis they had yet to uncover.

They needed help. They needed Benicio.

Benicio: A Rust Advocate in Peril

Benicio: A Rust Advocate in Peril


When Benicio arrived, he wasn’t just armed with his laptop; oh no, he carried something far more precious: his unshakable belief in Rust — the language he had fiercely championed for the past five years. It was with Rust that he and his team of Rustacean engineers had developed the core of the LuxCity SmartGrid. Rust was his sword, his shield, the shiny new toy that promised to save him from the horrors of C++ — buffer overflows, race conditions, the ever-dreaded Use-After-Free exploits. Rust was the answer to it all, right? The future, or so he believed. After all, LuxCity’s grid was built on this supposedly unbreakable foundation.


But the irony? That unwavering confidence was about to be tested, and maybe — just maybe — C++ wasn’t as outdated as Benicio had thought.


As Benicio dove into the system’s core, he immediately knew something was wrong. With every reset of the SmartGrid’s control system, the blackout spread further — moving inward from the outskirts of the city toward the heart of LuxCity. It wasn’t random; it was deliberate, a pattern unfolding before his eyes, a well-coordinated and calculated attack. His heart sank. This wasn’t just a glitch — it was a rootkit, alive and evolving.


The signature was unmistakable.


It was Janus, aka Lizard-the-Wizard — Benicio’s old friend turned adversary. Once, they’d written code together, exploring the infinite possibilities of C++. But Janus had scoffed at Rust’s rigid safety nets and abstractions. Now, Janus wielded the raw, untamed power of C++, manipulating the city’s infrastructure like a puppet master, targeting the very brains and guts of the biggest SmartGrid — coded by Benicio in Rust.


Lizard-Red: A Ruthless Attack on the Foundations

A Ruthless Attack by Janus aka Lizard-the-Wizard


Far below LuxCity, in the dim glow of server racks humming with life, Janus watched his masterwork unfold. His fingers moved swiftly over the keyboard, eyes sharp and focused as he tracked the chaos unraveling on the flickering screens. Two of his finest creations were in play: Lizard-Red and Lizard-Blue, each attacking from different fronts yet working in perfect harmony.


Lizard-Red was already deep inside the core of the city’s smart grid — the perfect silent invader. This wasn’t some ordinary malware hitting the usual software weak points. No, Lizard-Red was a firmware rootkit, targeting the deepest foundations: DMA controllers, SPI flash memory, and interrupt handlers. It slithered through the system unnoticed, slipping beneath Rust’s meticulously crafted safety mechanisms. Why bother attacking the CPU or memory buffers? Lizard-Red bypassed them altogether, embedding itself in the firmware where Rust’s guarantees held no sway.


Janus knew the limits of Rust’s supposed safety like the back of his hand — he had spent years dissecting it. Rust, for all its brilliance, stopped short when it came to the hardware layer. That’s where Lizard-Red thrived. This wasn’t just an attack on code; it was a hostile takeover of the hardware itself.


Meanwhile, Lizard-Blue was wreaking havoc from the high-level software side. It didn’t attack directly but acted as the perfect decoy, exploiting Rust’s unsafe blocks like a maestro conducting a symphony of chaos. It targeted the multithreading services, twisted the I/O operations, and wreaked havoc by forcing race conditions that Rust had cautiously loosened for performance reasons. Those unsafe zones were like doors left ajar in Benicio’s meticulously built defenses, and Janus — being the former master of C++ — knew exactly how to pry them open. Rust’s very safety model, the thing that gave Benicio confidence, became his downfall as Lizard-Blue turned those guarantees into weaknesses.


Janus, from his hidden lair, grinned. Benicio’s faith in Rust was about to crumble. This wasn’t just a technological attack; it was a lesson in the art of control.


Benicio Strikes Back: Exposing Rust’s Flaws

Benicio Strikes Back


In the control room, Benicio fought valiantly, his fingers moving faster than his thoughts. Each keystroke felt like a heartbeat — steady but desperate — as he wrestled with Rust’s strict safety nets against the unrelenting chaos woven by Lizard-the-Wizard’s code. Benicio had mastered Rust’s safety model, confident in its protection, but Lizard-Blue tore through the CPU with surgical precision. Race conditions and I/O failures erupted across the screens. Each time Benicio thought he had the upper hand, the attack morphed — changing shape, sliding past defenses like a shadow slipping under a door.


Rust couldn’t keep up. The very thing Benicio once loved about Rust — its rigid safety net — was now strangling his ability to regain control. Every safeguard became a cage, limiting his movements, trapping him in an endless loop of defensive patches that fell short against the fluid, relentless assault.


But Benicio, seasoned in the art of warfare, knew that this was just a diversion.


The real threat wasn’t Lizard-Blue dancing across the monitors. Far below the surface, deep in the veins of LuxCity’s smart grid, Lizard-Red had already seized control. It wasn’t playing in the upper layers of Rust’s defenses anymore. It had burrowed deep, using firmware implants to infiltrate critical systems like SCADA and the HVAC systems that controlled the city’s infrastructure down to its core. These were the systems where hardware met software — where most of the maintenance and final control devices ran on custom firmware, much of it still powered by the legacy of C and Assembly.


The DMA controllers and SPI flash memory were compromised. Lizard-Red had bypassed the CPU entirely, embedding itself into the hardware beneath the OS. It was targeting the lifeblood of the infrastructure — SCADA systems controlling critical operations and HVAC systems ensuring the city’s hardware operated seamlessly. These implants weren’t just simple code — they were permanent, surgically planted into the firmware, rewriting the rules of the system from the inside out.


Rust’s memory model — built to safeguard software — meant nothing here. This was a firmware-level war, one where Rust’s protections were like a well-built castle wall, but the attackers were already inside the gates, manipulating the hardware directly.

Janus had done what few others could: he exploited the weak spots in the hardware — the very places Rust was never designed to protect. The places where only bare metal, C++, and Assembly reign supreme. Benicio was outmatched, and deep down, he knew it.


The Melodramatic Turn: Benicio’s Crisis of Faith

WTF ?


Benicio slammed his fist against the console. Rust had been his holy grail, a language he trusted to guard against the very chaos now threatening to engulf LuxCity. He had believed in its promise to erase entire classes of vulnerabilities. But now, with the city teetering on the edge of collapse, a cold realization hit him: Rust wasn’t enough.


He stared at the glowing screen, his eyes drifting to an old folder tucked away on his desktop labeled “Old C++ Tools.” Five years — it had been five years since he’d last touched anything from that folder. He had sworn he wouldn’t go back. He wouldn’t need to. Rust had been the future, his escape from the dangers and volatility of C++. But now, as the city’s lights blinked out one by one, he knew that the very rigidity of Rust — the safety that had once been his shield — had become a cage. It was too inflexible to respond to this kind of threat.


The attacks on LuxCity were relentless, and they weren’t just digital — they were hitting the very hardware, the firmware-level depths where Rust couldn’t tread. He knew the truth now: this fight wasn’t just about Rust versus C++. This was about power. And C++? C++ had the raw, untamed power to reach where Rust could not, deep into the firmware where Lizard-Red had embedded itself.


His hand hovered over the mouse, trembling. Opening that folder felt like reaching for an ancient, dangerous weapon — one capable of just as much harm as good. One wrong move, and LuxCity would be gone forever. But without it, without the chaos and brute force of C++, there was no way to fight back.


With a heavy heart, Benicio clicked the folder. The familiar sight of his old tools greeted him, and in that moment, he knew — this battle couldn’t be won with safety and caution. It would take risk.


Janus’s Unexpected Lifeline: A Twist in the Battle

As the city plunged further into chaos and the SmartGrid teetered on the brink of collapse, a notification blinked on Benicio’s screen. It was from Janus. Benicio’s heart skipped a beat — what now? But instead of more havoc, the message held a lifeline. Janus wasn’t there to destroy LuxCity entirely — not yet. He had reached out with something unexpected: a list. A detailed breakdown of every corrupted service, every compromised process, and — most importantly — the codes to track them down.


Benicio hesitated, unsure whether to trust his old friend turned adversary. But there was no time to doubt. With LuxCity’s future hanging in the balance, he had no choice but to accept the help. His hand hovered over the mouse for a moment before he clicked open the file containing his old C++ tools.

Benicio’s Redemption: The Power of C++

Old chaps again?


With trembling hands, Benicio began typing. The once-familiar syntax of C++ flowed through him like second nature, years of muscle memory kicking in. He started crafting countermeasures, weaving them into Rust’s infrastructure, threading through the firmware to patch the chaos Janus had unleashed. Rust’s rigid structure had left him powerless against the firmware-level attack, but C++ was his sword and shield now. He bypassed Rust’s safety nets, diving straight into the vulnerable hardware, patching DMA requests and SPI memory corruptions one by one.


The air in the control room was tense. Alice and Bob watched, their eyes flickering between the fading lights on the grid and the lines of code flooding Benicio’s screen. Time was running out.


With each keystroke, Benicio wielded the power of modern C++, guided by the clues Janus, the owner of the two lizard colors, had provided — codes and a roadmap of compromised services. This wasn’t the risky, chaotic C++ of old. Modern C++ had tamed many of those dangers: smart pointers, more flavors than ever, and ownership models that echoed Rust’s safety features but with more flexibility, more raw power. It was refined, evolved. But even so, every line carried weight. One misstep could still spell disaster. Yet, as he worked, Benicio could feel parts of the grid recovering, the system responding to the precision of modern C++.


Janus had lit the fuse, but now he had handed Benicio the defusal codes. Whether it was an act of redemption or an ego-driven move to prove his dominance in the endgame, it didn’t matter, Benicio thought. He was now coding for the life of the city, with the ghosts of C++ hovering over every decision.


Every function call, every block of embedded assembly, was an intricate dance on the edge of disaster. But the unsafe code was wrapped in modern C++, using constructs reminiscent of monads — something Janus had convinced Benicio to adopt, given Benicio’s unfamiliarity with Haskell. As the minutes ticked by, the chaos on the monitors began to slow.


Benicio’s mind couldn’t shake the obsessive mantra: Rust had been his safety net. Yet, in this moment, only C++ had the flexibility and raw power to pull LuxCity back from the brink. As he coded furiously, patching each service Janus had corrupted, one thing became clear — there was no perfect language, only the right tool for the right battle.


In that moment, Benicio wasn’t just coding to save LuxCity; he was walking the fine line between creation and destruction, guided by the very language he had sworn never to touch again.


The Final Lesson: Rust’s Safety vs. C++’s Mastery of Control

As Benicio wrestled with LuxCity’s fragile systems, the weight of the moment hit him repeatedly: Rust, the language he had championed, was crumbling under the pressure of the real world. Its safety guarantees — the comforting walls he had relied on — had become his cage. Janus, Lizard-the-Wizard, had exploited every rigid boundary Rust had set — every unsafe block became a doorway for chaos, every secure memory model an obstacle Benicio couldn’t surmount in time. Rust, in its attempt to guard everything, had left the city’s very infrastructure exposed to attacks that went beyond software, reaching deep into the hardware itself.


And then the truth struck Benicio like a gut punch: Rust wasn’t failing because it was weak. It was failing because it was too strong, too strict, unable to adapt to the unpredictable forces Janus had unleashed. But C++, the language he had sworn to leave behind — with all its dangerous power and chaotic flexibility — was the one weapon capable of restoring balance. C++ wasn’t just a tool; it was freedom, an invitation to dive into the unknown, to control the uncontrollable.


Through the headset, Janus’s voice broke the silence. But this time, it wasn’t mocking or hostile.


“You see it now, don’t you?” he asked, with the calm precision of a maestro who had orchestrated the entire performance. This was never about the languages, Benicio. It’s about mastering the system — every layer, every crevice — from the software to the hardware, from the logic to the math at the heart of our programming grid.


Janus hadn’t just attacked LuxCity. He had pushed Benicio to the brink to teach him a lesson only a master hacker could deliver: true power doesn’t lie in choosing the ‘safest’ language, but in mastering the architecture beneath it, in bending the rules when necessary to adapt and survive.


“I never wanted to destroy LuxCity,” Janus continued, his voice almost nostalgic. I wanted to show you that relying on safety nets like Rust only makes you predictable. You’ve seen it yourself — Rust is bound by its own rules. C++… C++ lets you create the rules. The only constraints I respect are those set with grace and elegance by abstract algebra, category theory, and the lenses of dominating-graph theory.”


With the city teetering on the edge of collapse, Benicio understood now. Janus had staged the attack not out of malice, but as a test — a lesson in control, mastery, and adaptation. The irony? To defeat Janus, Benicio had to embrace the very language he had turned his back on.


Here’s the very final list of compromised services,” Janus said, handing Benicio the last, decisive piece of the puzzle. It was time to finish this, but now they were working together — master and student, just like old times.


As Benicio dove back into the code, his old C++ instincts reignited. With Janus’s guidance, he targeted the final persistent malware codes one by one, embedding assembly where needed, bypassing Rust’s limitations, and undoing the damage at the firmware level. It wasn’t always elegant, and it wasn’t always safe, but it was working.


The air in the control room shifted. Alice and Bob, though tense, watched as the system slowly began to stabilize. Power flickered back into the outskirts of the city. The SmartGrid, the beating heart of LuxCity, was finally fighting back.


Benicio had learned the hard way that no language, no matter how ‘safe,’ could guarantee control in the face of a true challenge. In the end, it wasn’t about choosing Rust or C++; it was about mastering both, understanding that the real battle isn’t in the lines of code, but in the mind and the science of the programmer wielding them.



Want to access more articles and news related to this topic?


You can follow my work and subscribe to my newsletter for updates, insights, and exclusive content on LinkedIn.


Stay connected for more tech insights and news!