Latest / CyberCode Academy / Course 16 - Red Team Ethical Hacking Beginner Course | Episode 6: Windows Persistence Strategies: Registry, Scheduled Tasks, Services, WMI
Transcript
- 0:00Speaker 1: When we talk about cybersecurity, you know, we always seem
- 0:02Speaker 1: to focus on that first moment, the breach, the exploit
- 0:06Speaker 1: that gets.
- 0:06Speaker 2: An attacker in right kicking the door in exactly.
- 0:09Speaker 1: But what happens after that is, well, it's arguably the
- 0:12Speaker 1: most critical part of the whole operation. It's not enough
- 0:15Speaker 1: to get in. You have to find a way to
- 0:17Speaker 1: stay in.
- 0:17Speaker 2: That's the whole game. An initial foothold can be so fragile.
- 0:21Speaker 2: I mean, it can vanish if an admin logs out
- 0:24Speaker 2: or you know, a server just reboots and all.
- 0:26Speaker 1: That effort is just gone. Yeah, you're back to square one.
- 0:29Speaker 1: So that's our mission for this deep dive. We are
- 0:32Speaker 1: talking all about persistence. We're going to break down five
- 0:35Speaker 1: specific ways attackers ensure they keep their access to a
- 0:38Speaker 1: Windows system.
- 0:39Speaker 2: And we're going to move up the ladder, so to speak,
- 0:41Speaker 2: from local user tricks right up to techniques that give
- 0:44Speaker 2: you the keys to the entire domain.
- 0:46Speaker 1: What I find fascinating is that these aren't some exotic,
- 0:51Speaker 1: custom written malware tools.
- 0:53Speaker 2: No, not at all. That's the key takeaway here. Adversaries
- 0:56Speaker 2: are leveraging the operating system's own features. They're using the
- 1:00Speaker 2: same administrative tools that it managers use every single day, so.
- 1:04Speaker 1: If you don't know exactly where to look.
- 1:06Speaker 2: These backdoors are almost impossible to spot. They just blend in.
- 1:08Speaker 1: Okay, so let's start at the beginning. The most fundamental technique.
- 1:12Speaker 1: Let's talk about registry key persistence.
- 1:15Speaker 2: This is persistence one oh one really, but it's still
- 1:18Speaker 2: so common because it's just it's incredibly reliable. The goal
- 1:22Speaker 2: is simple. You want your payload, let's call it test
- 1:24Speaker 2: dot ex, to run automatically every time a user logs in.
- 1:28Speaker 1: And the way you do that is by adding it
- 1:30Speaker 1: to one of the startup locations in the Windows registry exactly.
- 1:34Speaker 2: And you have a choice here. If you only care
- 1:36Speaker 2: about one specific user, say an account named Jason Bourne,
- 1:40Speaker 2: you can target the registry key that's just for him.
- 1:43Speaker 1: But if you want to be more effective, you'd want
- 1:45Speaker 1: your code to run no matter who logs into that computer, right,
- 1:48Speaker 1: Jason Bourne, Gendo whoever.
- 1:50Speaker 2: That's the next level for that kind of persistence. You
- 1:52Speaker 2: target a different spot, a system wide key under HP
- 1:55Speaker 2: local machine. That makes it global for that machine, anyone
- 1:59Speaker 2: who logs in your payload runs.
- 2:01Speaker 1: And when you're doing this from a remote shell, you
- 2:04Speaker 1: can't have Windows popping up a confirmation box. Can you no?
- 2:07Speaker 2: That would kill your whole session. I mean, if you
- 2:09Speaker 2: try to add a key that already exists, the shell
- 2:11Speaker 2: might pause and ask are you sure, which can answer
- 2:14Speaker 2: remotely precisely. So the command they use includes a special
- 2:18Speaker 2: flag vowel, which just means force. It tells the system yes,
- 2:22Speaker 2: I'm sure, just do it, don't ask.
- 2:24Speaker 1: So they're hiding right next to legitimate startup programs, things
- 2:29Speaker 1: like one drive or other apps that are supposed to
- 2:31Speaker 1: be there.
- 2:31Speaker 2: It's the perfect camouflage, all right.
- 2:33Speaker 1: Moving on from login triggers, the second method uses, well,
- 2:36Speaker 1: it uses time itself as the trigger. Scheduled task persistence.
- 2:40Speaker 2: Right, if the registry is about running on login, scheduled
- 2:43Speaker 2: tasks are about running on a calendar. So you can
- 2:46Speaker 2: set your payload to execute, say every ten minutes or
- 2:49Speaker 2: maybe just once a day at three am.
- 2:52Speaker 1: And this is done using a built in Windows tool tasks,
- 2:55Speaker 1: again using the system against itself.
- 2:58Speaker 2: You just need the right privileges, like being a domain admin.
- 3:01Speaker 2: Then you create a new.
- 3:02Speaker 1: Task and you define what three main things.
- 3:04Speaker 2: Yeah, pretty much. You give the task a name, you
- 3:07Speaker 2: tell it what command to run your payload, and then
- 3:10Speaker 2: you define the schedule, is it daily, weekly, every minute?
- 3:13Speaker 1: And once it's created, the system just treats it like
- 3:16Speaker 1: any other legitimate job, like a backupscript or a maintenance task.
- 3:20Speaker 2: Exactly, and the attacker can even query the task to
- 3:23Speaker 2: see when it's scheduled to run next. It's completely transparent
- 3:26Speaker 2: to the operating.
- 3:26Speaker 1: System, which from a defender's point of view, is also
- 3:29Speaker 1: a place you should be looking. A new suspicious task
- 3:32Speaker 1: running every ten minutes. That's a huge flag.
- 3:35Speaker 2: A huge flag.
- 3:36Speaker 1: Yes, okay, now things get a lot more powerful. We're
- 3:39Speaker 1: moving beyond things that rely on a user logging in
- 3:42Speaker 1: and into persistence that takes hold when the system itself
- 3:46Speaker 1: boots up.
- 3:46Speaker 2: This brings us to method number three, Service control Manager
- 3:50Speaker 2: persistence or SCM. The goal here is to get system
- 3:54Speaker 2: level access.
- 3:54Speaker 1: Before anyone even types a password.
- 3:56Speaker 2: Right when a Windows machine boots up, way before the
- 3:59Speaker 2: logins appears. The service control manager is already busy starting
- 4:03Speaker 2: all the background processes. We want to sneak our payload
- 4:06Speaker 2: in there. As a service.
- 4:07Speaker 1: That's a massive jump in privilege. You get code execution automatically,
- 4:11Speaker 1: and it's running as system, the highest level of privilege
- 4:15Speaker 1: on the machine.
- 4:15Speaker 2: It is, but there's a technical trick to making it
- 4:18Speaker 2: work reliably. What's that Well, if you just tell the
- 4:21Speaker 2: new service to run your test dot ex payload directly,
- 4:24Speaker 2: the program might run do its thing and then immediately close,
- 4:27Speaker 2: and when it closes, your remote shell connection dies with it. Ah,
- 4:31Speaker 2: so it's not stable exactly. So the trick is to
- 4:34Speaker 2: set the services path not to your payload, but to
- 4:37Speaker 2: the command prompt itself cmd dot ex okay, And you
- 4:41Speaker 2: add a little switch K which tells the command prompt
- 4:44Speaker 2: execute this payload for me, but stay open. Afterwards, it
- 4:48Speaker 2: wraps your payload in a stable, persistent shell.
- 4:51Speaker 1: He forces the connection to stay alive. That's clear erry.
- 4:53Speaker 2: And of course you set the service to start auto,
- 4:55Speaker 2: so it launches every single time the computer boots. We've
- 4:58Speaker 2: seen this in action. You can reboot the target machine,
- 5:01Speaker 2: lose your shell, and then a few moments later, a
- 5:03Speaker 2: brand new system level shell just pops right back up.
- 5:06Speaker 1: That's incredibly powerful. Now, if SEM is about booting, our
- 5:11Speaker 1: fourth technique is about well, pretty much any other event.
- 5:15Speaker 1: You can imagine WMI event subscriptions.
- 5:18Speaker 2: Uh huh, WMI or Windows Management Instrumentation is. It's just
- 5:23Speaker 2: this massive framework Microsoft uses for managing everything in an enterprise, security, settings, hardware, processes,
- 5:31Speaker 2: you name it.
- 5:32Speaker 1: It's the management backbone of Windows.
- 5:34Speaker 2: It really is. And WMI event subscriptions are these permanent
- 5:38Speaker 2: little objects you can create that just sit there and
- 5:40Speaker 2: watch for things to happen. They're triggers and they don't
- 5:43Speaker 2: go away until you manually delete them.
- 5:45Speaker 1: So you're basically programming the operating system to be a
- 5:48Speaker 1: spy for you. When X happens, run my code.
- 5:50Speaker 2: That's a perfect way to put it. To create one,
- 5:53Speaker 2: you need admin rights and you have to set up
- 5:54Speaker 2: three components. We sometimes call them the three pillars.
- 5:57Speaker 1: What's the first pillar?
- 5:58Speaker 2: The first is the filter. This is your if statement.
- 6:01Speaker 2: It defines the specific event you're waiting for. It could
- 6:03Speaker 2: be a time of day or something much more obscure.
- 6:06Speaker 1: Okay, so you have the filter. What's next.
- 6:08Speaker 2: The second pillar is the consumer. This is the then
- 6:11Speaker 2: part of the statement. It's the action to take for
- 6:13Speaker 2: our purposes. That action is usually to run a command,
- 6:17Speaker 2: but it could be anything WMI can do. In the
- 6:20Speaker 2: third pillar, the binding, It just connects the two. It
- 6:22Speaker 2: tells WMI, when this filter is triggered, execute that consumer.
- 6:27Speaker 1: What's so interesting is how creative you can get with
- 6:30Speaker 1: the filters. You mentioned an example of triggering a payload
- 6:34Speaker 1: when CHALC dot ex the calculator app isn't closed. Why
- 6:38Speaker 1: on earth would you do that?
- 6:39Speaker 2: It seems random, right, And that's the point. Defenders are
- 6:42Speaker 2: looking for things that run at boot or on a schedule.
- 6:45Speaker 2: They are probably not looking for a back door that's
- 6:48Speaker 2: triggered by someone closing the calculator. It's a way to
- 6:51Speaker 2: create a self healing backdoor. If your main shell dies,
- 6:54Speaker 2: you just find a way to kill the calculator process
- 6:56Speaker 2: and boom, a brand new system level shell connects back
- 6:59Speaker 2: to you.
- 7:00Speaker 1: Is incredibly subtle. You can also turn the system clock
- 7:02Speaker 1: into a trigger, right.
- 7:04Speaker 2: Yeah, set a filter to fire on a time change.
- 7:07Speaker 2: For instance, you could make it trigger precisely at the
- 7:10Speaker 2: thirty second mark of every minute. It's a recurring schedule
- 7:13Speaker 2: that doesn't use the scheduled tasks feature at all, so
- 7:15Speaker 2: it's much harder to.
- 7:16Speaker 1: Find and getting rid of these requires deleting all three
- 7:19Speaker 1: parts the filter, the consumer, and the binding individually.
- 7:23Speaker 2: It's a real pain to clean up if you don't
- 7:25Speaker 2: know what you're looking for.
- 7:26Speaker 1: Okay, we've gone from local users to the system boot process.
- 7:30Speaker 1: Now for the final leap from owning one machine to
- 7:34Speaker 1: owning the entire network domain level persistence.
- 7:38Speaker 2: Now we're talking about the Golden ticket. This is the
- 7:40Speaker 2: absolute keys to the kingdom. It's a self generated Carbero's ticket,
- 7:44Speaker 2: a TGT that essentially lets you impersonate anyone and access
- 7:48Speaker 2: anything on the network.
- 7:49Speaker 1: So even if your original admin account gets deleted or
- 7:52Speaker 1: the password has changed, this ticket.
- 7:54Speaker 2: Still works indefinitely. It is the ultimate insurance policy. But
- 7:58Speaker 2: to create it, you need four key pieces of information
- 8:01Speaker 2: that you have to grab while you still have that
- 8:04Speaker 2: initial domain admin access.
- 8:05Speaker 1: Okay, what real You need?
- 8:06Speaker 2: The domain name, a user account you want to impersonate
- 8:10Speaker 2: the domain's SID, it's unique identifier, and the most important
- 8:14Speaker 2: part the NTLM hash of a special account called the KRBTGT.
- 8:18Speaker 1: The krbtgt hash. Can you break that down? What is that?
- 8:21Speaker 1: In simple terms, think of.
- 8:23Speaker 2: The krbtgt account as the master key maker for the
- 8:26Speaker 2: entire domain. Its hash is the secret key it uses
- 8:30Speaker 2: to sign every single legitimate access ticket. If you steal
- 8:33Speaker 2: that hash, you can sign your own tickets. You can
- 8:36Speaker 2: forge a perfect valid master ticket for yourself. You become
- 8:39Speaker 2: your own master key maker.
- 8:41Speaker 1: And gathering this data is done with tools like mimicats,
- 8:44Speaker 1: which can pull that secret hash right from the domain
- 8:47Speaker 1: controller correct.
- 8:48Speaker 2: And the real proof of its power is when you
- 8:50Speaker 2: use it. You can inject this golden ticket into a
- 8:53Speaker 2: session for a regular low privileged domain user, someone who
- 8:56Speaker 2: can't access anything sensitive, and suddenly suddenly that use has
- 9:00Speaker 2: full domain admin rights. They can browse the files on
- 9:03Speaker 2: the domain controller, access anything they want. They have achieved
- 9:06Speaker 2: total persistent domain dominance.
- 9:09Speaker 1: Wow.
- 9:09Speaker 2: It really is the ultimate goal for long term control.
- 9:12Speaker 1: So to recap we've really covered the whole spectrum here,
- 9:15Speaker 1: from simple registry keys to the timing of scheduled tasks,
- 9:19Speaker 1: the system level power of SEM services, the nuanced triggers
- 9:23Speaker 1: of WMI, and finally the total domain control of a
- 9:27Speaker 1: Golden ticket.
- 9:28Speaker 2: And the common thread through almost all of them is
- 9:30Speaker 2: abusing native features the registry, SCM, WMI. These are essential
- 9:35Speaker 2: for it to manage their networks, and that makes them
- 9:38Speaker 2: the perfect place for an attacker to hide.
- 9:40Speaker 1: So understanding how they're created is the first step to
- 9:43Speaker 1: defending against them.
- 9:44Speaker 2: It's the foundation if you know where an attacker is
- 9:47Speaker 2: going to set start auto or compile a dot mof
- 9:49Speaker 2: file for WMI, you know exactly where to point your
- 9:52Speaker 2: monitoring tools.
- 9:53Speaker 1: Which brings us to a final thought for you to
- 9:55Speaker 1: take away. We covered four Windows specific methods here, the Registry,
- 9:59Speaker 1: Scheduled Task, SEM, and WMI. If you could only monitor
- 10:03Speaker 1: one type of system activity to get the fastest possible
- 10:06Speaker 1: warning about the creation of any of these four where
- 10:09Speaker 1: would you look. Would you watch the file system, system, memory,
- 10:12Speaker 1: network traffic, or would you focus on changes happening inside
- 10:15Speaker 1: the Windows registry and the WMI repository itself?
- 10:18Speaker 2: Think about where the definitions for these persistence objects actually live.
- 10:23Speaker 2: The answer to that is the key to a faster defense.
- 10:26Speaker 1: Until next time, stay curious and keep diving deep.