Latest / CyberCode Academy / Course 18 - Evading IDS Firewalls and Honeypots | Episode 6: Mastering Malware Evasion: Stealth, Obfuscation, and Anti-Analysis
Transcript
- 0:00Speaker 1: Welcome to the deep dive, the place where we cut
- 0:02Speaker 1: through the noise and get straight to the knowledge you need. Today,
- 0:06Speaker 1: we are peering deep into this continuous, high stakes game
- 0:10Speaker 1: of cyber warfare. I'm talking about the endless cat and
- 0:14Speaker 1: mouse struggle between detection systems, your firewalls, your anti virus,
- 0:18Speaker 1: and the adversaries who are constantly and I mean constantly
- 0:22Speaker 1: analyzing them looking for that one tiny flaw.
- 0:25Speaker 2: It really is an arms race, but it's happening at
- 0:28Speaker 2: the level of code. Every single time a security team
- 0:30Speaker 2: rolls out an update or a new signature, you could
- 0:33Speaker 2: bet the offensive side is already taking it apart. They're
- 0:35Speaker 2: trying to figure out, you know, how to change their
- 0:37Speaker 2: own tools just enough to stay ahead exactly.
- 0:41Speaker 1: So the mission for this deep dive is to really
- 0:42Speaker 1: unpack that playbook, the adversaries evasion playbook. We're going to
- 0:46Speaker 1: break it down into the three major phases of a
- 0:48Speaker 1: successful stealthy attack. First, how do they get their malicious
- 0:51Speaker 1: cargo pass those initial defenses. Second, once they're inside, how
- 0:54Speaker 1: do they hide? And finally, how do they defeat the
- 0:57Speaker 1: actual people the security teams trying to add their malware.
- 1:01Speaker 2: And you know, if you're someone who builds or tests
- 1:04Speaker 2: these defenses. Understanding these techniques isn't just helpful, it's absolutely essential.
- 1:08Speaker 2: The whole point of evasion is to reduce the attack's
- 1:11Speaker 2: digital fingerprint. If you can minimize those unique markers that
- 1:16Speaker 2: security software looks for, well, you force the defender to
- 1:19Speaker 2: spend way more time and resources just to find you.
- 1:22Speaker 2: We're going beyond the loud smashing grab attacks here. This
- 1:25Speaker 2: is all about the whisper quiet infiltration.
- 1:28Speaker 1: Okay, so let's unpack that first challenge. Then getting past
- 1:31Speaker 1: the front door without setting off any alarms. This almost
- 1:34Speaker 1: always starts with disguising the payload itself, right, the malicious code.
- 1:38Speaker 1: This is where obfuscation and encoding come into play.
- 1:41Speaker 2: Right obfuscation is basically a way of scrambling or wrapping
- 1:45Speaker 2: the payload so it no longer looks like itself. It
- 1:48Speaker 2: won't match any known signature of a dangerous piece of code,
- 1:51Speaker 2: and that simple trick immediately defeats the most basic kind
- 1:54Speaker 2: of signature checks that a lot of older av software
- 1:57Speaker 2: is still relies on.
- 1:58Speaker 1: When you look at popular tool like metasploit, they have
- 2:01Speaker 1: these encoders built right in. I've heard one that gets
- 2:03Speaker 1: a lot of attention. Is called chicataganai. What makes that
- 2:06Speaker 1: one so effective it's.
- 2:07Speaker 2: The principle behind it. It's iterative. So when you create
- 2:11Speaker 2: your payload, let's say you're setting up a reverse shell
- 2:14Speaker 2: back to your own IP address. You then apply the encoder.
- 2:17Speaker 2: But you don't just do it once. You can run it,
- 2:19Speaker 2: say one hundred times.
- 2:21Speaker 1: So wait, if I tell the tool to run one
- 2:23Speaker 1: hundred iterations of that encoder, I'm basically wrapping the original
- 2:27Speaker 1: very recognizable payload in one hundred unique layers of a
- 2:31Speaker 1: junk code.
- 2:32Speaker 2: Not just junk code, but one hundred layers of unique
- 2:35Speaker 2: decryption routines. The final file is completely cloaked, and because
- 2:40Speaker 2: each of those hundred iterations introduces tiny randomized changes, the
- 2:43Speaker 2: executable that comes out the other end is unique every
- 2:46Speaker 2: single time. It makes matching it to a known signature
- 2:49Speaker 2: pretty much impossible.
- 2:50Speaker 1: Hold on, if it's so deeply encoded, it still needs
- 2:52Speaker 1: to be decoded to actually run, right, which I guess
- 2:56Speaker 1: leads us to the next technique. You hear about custom packaging.
- 2:59Speaker 1: So what is a packer?
- 3:01Speaker 2: A packer is a tool that creates a compressed or
- 3:03Speaker 2: encrypted version of the malware. Think of it, Like putting
- 3:06Speaker 2: the malware inside a lock safe. The part that runs
- 3:09Speaker 2: first is the key to that safe, which we call
- 3:12Speaker 2: the stubcode. It unlocks and executes the real malware in memory.
- 3:16Speaker 1: Ah okay, So even if the malware itself is hidden
- 3:19Speaker 1: inside that safe, the outside of the safe, that stubcode
- 3:23Speaker 1: becomes the new potential fingerprint. So security researchers could spot
- 3:27Speaker 1: a whole malur campaign just by recognizing the same stubcode
- 3:30Speaker 1: over and over.
- 3:31Speaker 2: That's the vulnerability exactly, And that's what a custom packer exploits. See.
- 3:35Speaker 2: The key insight here isn't just about compression. It's about personalization.
- 3:39Speaker 2: To make the defender's job harder. Standard packers use common
- 3:42Speaker 2: recognizable stubcode. Custom packers create a unique, never before seen
- 3:47Speaker 2: stubcode for every single payload. It forces the defense to
- 3:50Speaker 2: analyze every single variant from scratch.
- 3:52Speaker 1: Wow, that just dramatically increases the cost of defense. But
- 3:55Speaker 1: let's shift gears a little. What about languages that are
- 3:57Speaker 1: harder to hide, like Python? Scripts are by their nature readable.
- 4:02Speaker 1: How do you click a script?
- 4:03Speaker 2: Yeah, that's a different challenge. This is where we see
- 4:05Speaker 2: some really clever injection techniques. You're essentially turning a completely benign,
- 4:10Speaker 2: useful script into a carrier for your malicious payload.
- 4:14Speaker 1: Okay, so let's walk through an example. Let's say an
- 4:16Speaker 1: attacker finds a genuinely useful script, maybe one that lists
- 4:19Speaker 1: all your saved Wi Fi passwords. How do they hide
- 4:23Speaker 1: a malicious shell inside that without breaking its original function?
- 4:27Speaker 2: The process is actually pretty elegant. The attacker first generates
- 4:31Speaker 2: their malicious shell code, maybe from metasplate, but then they
- 4:35Speaker 2: convert that raw code into chunks of Base sixty four characters.
- 4:39Speaker 2: To you or me, Base sixty four just looks like
- 4:41Speaker 2: a meaningless jumble of text, so it can be embedded
- 4:44Speaker 2: anywhere without raising suspicion.
- 4:45Speaker 1: So they just paste those Base sixty four chunks into
- 4:48Speaker 1: the legitimate script, along with a little bit of extra
- 4:51Speaker 1: code to glue it together.
- 4:52Speaker 2: Precisely, when the target runs the helpful WiFi script, that
- 4:57Speaker 2: little bit of extra code secretly finds all that those
- 5:00Speaker 2: Base sixty four chunks, pieces them back together into the
- 5:03Speaker 2: original payload, and runs it directly in memory. It opens
- 5:06Speaker 2: a backdoor connection, maybe on a common port like four
- 5:08Speaker 2: forty three, to blend in, and then the script just
- 5:12Speaker 2: continues on. It does its job listing the Wi Fi passwords.
- 5:15Speaker 2: The user sees exactly what they expected and has no
- 5:18Speaker 2: idea a reverse shell was just opened.
- 5:20Speaker 1: That is the perfect way to defeat static analysis. The
- 5:23Speaker 1: malicious part is masked by the legitimate part. But okay,
- 5:27Speaker 1: once the attackers in and running, the rules change. We're
- 5:30Speaker 1: not just beating a scanner anymore. We're trying to beat
- 5:32Speaker 1: a human analyst, which brings us to our second segment,
- 5:36Speaker 1: how to attack SPAE invisible once they're already inside.
- 5:39Speaker 2: Once you're inside, the number one rule is do not
- 5:41Speaker 2: touch the file system. If you write a malicious file
- 5:43Speaker 2: to the disk, an anti malware solution is almost certain
- 5:47Speaker 2: to find it eventually. This is why filess malware has
- 5:49Speaker 2: become so dominant. It runs entirely in memory without writing
- 5:52Speaker 2: anything malicious to the hard drive.
- 5:54Speaker 1: And PowerShell seems to be the tool of choice for this,
- 5:57Speaker 1: given how deeply it's baked into Windows.
- 5:59Speaker 2: It absolutely is a classic example really shows its power.
- 6:02Speaker 2: The attacker puts their payload script on a simple temporary
- 6:06Speaker 2: web server. Then on the target machine they just need
- 6:09Speaker 2: to execute a single command. It tells PowerShell to go
- 6:12Speaker 2: to that web server, say on port eighty and just
- 6:15Speaker 2: grab the script.
- 6:16Speaker 1: And the key is that it can override local security controls.
- 6:19Speaker 2: Right, that's the magic trick. They use a parameter, it's
- 6:22Speaker 2: des ep bypass, which tells PowerShell to ignore any local
- 6:26Speaker 2: security policies and just run the code. Affetches that one line,
- 6:30Speaker 2: downloads the script into a memory buffer and executes it,
- 6:33Speaker 2: opening the connection back to the attacker. The moment that
- 6:36Speaker 2: connection is made and the buffer is cleared, there is
- 6:38Speaker 2: zero forensic evidence of a malicious file on the hard drive. Nothing.
- 6:42Speaker 1: That level of stealth is genuinely scary. But what if
- 6:45Speaker 1: they need persistence? If the attacker needs to store config
- 6:49Speaker 1: files or other tools for later, they can't just drop
- 6:51Speaker 1: them in a visible folder.
- 6:53Speaker 2: No, so they have to use the operating system against itself.
- 6:56Speaker 2: They exploit these obscure but legitimate features of Wind. They
- 7:01Speaker 2: look for ways to make their own directories and files
- 7:03Speaker 2: completely invisible, even to someone who has show hidden files
- 7:07Speaker 2: turned on.
- 7:08Speaker 1: I find the technique using the desktop dot ni file
- 7:11Speaker 1: so clever. If you look at certain Windows folders, like
- 7:13Speaker 1: the history folder deep inside app dator, you often can't
- 7:16Speaker 1: see it. It's just gone right.
- 7:18Speaker 2: But if you type the exact path into the address bar.
- 7:21Speaker 2: You can navigate right into it. The folders are there,
- 7:23Speaker 2: it's accessible, but the file listings and Windows Explore itself
- 7:27Speaker 2: just pretend it doesn't exist.
- 7:28Speaker 1: And that's all because of a tiny file desktop dot
- 7:31Speaker 1: eenie sitting inside that folder. It's like a secret note
- 7:33Speaker 1: to Windows telling it how to display the folder. And
- 7:36Speaker 1: it has these specific codes, a CLSID and a UICLSID.
- 7:40Speaker 2: That essentially instruct Windows Explorer and even command line searches
- 7:44Speaker 2: to just ignore the folder's existence. So an attacker just
- 7:47Speaker 2: copies that desktop dot ni file into their own folder.
- 7:50Speaker 2: Now their folder's physically there, ready to hold tools, but
- 7:53Speaker 2: Windows itself is actively helping to hide it.
- 7:55Speaker 1: Building on that idea of hidden storage, we have to
- 7:58Speaker 1: talk about alternate data streams ADS. This exploits the very
- 8:02Speaker 1: structure of the NTFS filesystem. I think most people think
- 8:06Speaker 1: a file is just a simple string of bytes, but
- 8:07Speaker 1: it's much more complex than that.
- 8:09Speaker 2: Oh, it's way more complex. Every file on an NTFS
- 8:12Speaker 2: system has a main section the data stream that's the
- 8:14Speaker 2: content you actually see and edit, but the file structure
- 8:17Speaker 2: can support multiple other named data streams. They were originally
- 8:22Speaker 2: designed for things like compatibility with old Mac filesystems, but
- 8:25Speaker 2: attackers saw them for what they could be, a perfect
- 8:29Speaker 2: digital black hole.
- 8:29Speaker 1: A black hole because anything you store in an ADS
- 8:32Speaker 1: is completely invisible to normal file sized checks and application
- 8:36Speaker 1: reads totally.
- 8:37Speaker 2: So you have a simple text file notes dot txt
- 8:39Speaker 2: that Windows says is one hundred bytes long. You can
- 8:42Speaker 2: then use specific commands to attach an entire three megabyte
- 8:45Speaker 2: executable program to a named stream inside notes dot txt.
- 8:49Speaker 2: When you check again, Windows still reports the file size
- 8:52Speaker 2: as one hundred bytes. The three megabyte program is there,
- 8:55Speaker 2: but it's not counted.
- 8:55Speaker 1: That's just wild. So how does an analyst ever find
- 8:58Speaker 1: something that the OS is actively helping to hide?
- 9:01Speaker 2: This is where that specialized knowledge is critical. You have
- 9:04Speaker 2: to use a specific non standard command. If you just
- 9:06Speaker 2: run a normal dirt command, you'll see nothing. But if
- 9:09Speaker 2: you use that same command with the special R switch,
- 9:12Speaker 2: it suddenly exposes all those hidden name streams. It reveals
- 9:16Speaker 2: the true complex structure of the file, not just its
- 9:19Speaker 2: apparent size.
- 9:21Speaker 1: The moment you realize your file system can hide massive
- 9:24Speaker 1: executables without changing the file size, you really get the
- 9:27Speaker 1: depth of this problem.
- 9:28Speaker 2: It's a perfect example of attackers taking a feature built
- 9:31Speaker 2: for a totally benign reason like handling metadata and turning
- 9:36Speaker 2: it into a weapon.
- 9:37Speaker 1: So we've gotten pass the door we've hidden inside. The
- 9:39Speaker 1: final line of defense for the malware is to stop
- 9:41Speaker 1: security analysts from even studying it. Let's talk about anti analysis, right.
- 9:45Speaker 2: Malware authors know that security professionals use isolated environments, virtual machines,
- 9:50Speaker 2: or sandboxes to safely see what a suspicious file does.
- 9:54Speaker 2: They can't risk running it on their real network. So
- 9:56Speaker 2: the malware is now designed to ask itself a question
- 10:00Speaker 2: being watched right now? That's anti virtualization?
- 10:03Speaker 1: And how can a piece of code actually detect that
- 10:05Speaker 1: it's in a virtual environment.
- 10:07Speaker 2: It looks for telltale signs for artifacts. It might be
- 10:09Speaker 2: super technical, like checking a CPU instruction that returns the
- 10:12Speaker 2: hypervisor brand like VMware, or could be simpler. It might
- 10:16Speaker 2: just check for specific files on the disc, or certain
- 10:19Speaker 2: network adapter names or unique registry keys that only exist
- 10:22Speaker 2: when virtualization software is installed. Sometimes a VM just looks
- 10:26Speaker 2: too clean, no documents, no browser history, none of the
- 10:30Speaker 2: messiness of a real users system.
- 10:32Speaker 1: Okay, so if the malware figures out it's in a sandbox,
- 10:35Speaker 1: it has to react. What are the common evasive actions
- 10:39Speaker 1: it takes?
- 10:40Speaker 2: The goal is always to waste the analyst's time or
- 10:43Speaker 2: hide its true purpose. So it has three main tactics. One,
- 10:46Speaker 2: it can just terminate it self destructs before the analyst
- 10:49Speaker 2: sees anything malicious. Two, it can alter its behavior. It runs,
- 10:53Speaker 2: but it only does harmless things. It waits until it's
- 10:55Speaker 2: been declared clean and move to a real network before
- 10:58Speaker 2: it's malicious side activates. Three, and this one is really tricky.
- 11:01Speaker 2: It can enter a long sleep phase. It just does
- 11:03Speaker 2: nothing for hours or even days, waiting for the automated
- 11:06Speaker 2: analysis window to close before it finally wakes up and executes.
- 11:09Speaker 1: This whole deep dive just reveals the incredible depth of
- 11:13Speaker 1: this fight. We've gone from simple signature evasion all the
- 11:16Speaker 1: way to manipulating the file system and playing psychological games
- 11:20Speaker 1: with human analysts.
- 11:21Speaker 2: It means the defender has to be constantly learning. The
- 11:24Speaker 2: moment a new defense is perfected, the clock is already
- 11:28Speaker 2: ticking on the evasion technique that will beat it.
- 11:30Speaker 1: We've covered a lot of technical ground today, but it
- 11:32Speaker 1: all points to this fundamental asymmetry in cybersecurity. Understanding these
- 11:37Speaker 1: deep evasion tricks is just crucial for building better security.
- 11:40Speaker 1: Whether you're a developer, security pro or honestly just curious
- 11:44Speaker 1: about how this all works.
- 11:45Speaker 2: Absolutely, and as a final thought, maybe a little exercise
- 11:48Speaker 2: for you to think about. We talked about how alternate
- 11:50Speaker 2: data streams can hide data, making a file's actual size
- 11:54Speaker 2: different from its apparent size. So, if you were designing
- 11:57Speaker 2: the next generation file system, knowing that it's exploit this,
- 12:01Speaker 2: what's one architectural change you could make? How could you
- 12:04Speaker 2: ensure that the reported size of a file always has
- 12:06Speaker 2: to equal the total fizz of all data streams associated
- 12:09Speaker 2: with it hidden or not?
- 12:11Speaker 1: Think about that next time you see a file size
- 12:13Speaker 1: on your computer. Until next time, keep digging deeper.