Latest / CyberCode Academy / Course 16 - Red Team Ethical Hacking Beginner Course | Episode 4: Windows Post-Exploitation: Remote File Management and System Control
Transcript
- 0:00Speaker 1: Okay, let's let's unpack this. Yeah, specifically, how to manage
- 0:04Speaker 1: files and processes, and you know, seize full system control
- 0:09Speaker 1: when you are the guest of the host. Definitely didn't
- 0:11Speaker 1: invite this deep dive is purely about the mechanics of control.
- 0:15Speaker 2: That's where the real work begins. I mean, once you've
- 0:17Speaker 2: established access to a remote machine, whether you're performing a
- 0:21Speaker 2: penetration test or doing some deep system administration, you need
- 0:24Speaker 2: to execute. We're moving beyond just getting in. We're focusing
- 0:28Speaker 2: on the essential techniques how to move data, run programs,
- 0:32Speaker 2: kill lingering processes, and ultimately control the machine's basic.
- 0:37Speaker 1: State like rebooting or logging someone off exactly.
- 0:40Speaker 2: And these commands, they are just foundational to how the
- 0:43Speaker 2: system functions.
- 0:44Speaker 1: We know that modern you know, high end automated toolkits,
- 0:47Speaker 1: So what we call C two frameworks are commanding control frameworks.
- 0:49Speaker 1: They have these incredibly sleek built in commands. Oh yeah,
- 0:52Speaker 1: one click, you hit upload and the job is done.
- 0:55Speaker 1: It's seamless, they're fast, they're efficient. But what happens when
- 0:58Speaker 1: that automated toolkit fails or maybe you're operating in an
- 1:01Speaker 1: environment where I don't know, network restrictions force you back
- 1:04Speaker 1: to basics.
- 1:05Speaker 2: That's when manual command line methods become absolutely crucial. Okay,
- 1:09Speaker 2: exactly relying solely on automation is while it's unreliable, redundancy.
- 1:15Speaker 1: Is key in this game. You need a backup play always.
- 1:18Speaker 2: So we shift quickly to leveraging native Windows capabilities, specifically
- 1:22Speaker 2: the commands that are guaranteed to exist on almost every
- 1:25Speaker 2: machine you'll encounter. Right, and we start with file management.
- 1:28Speaker 2: That means working with the server Message Block Protocol or SMB.
- 1:33Speaker 1: So the goal is to get data on or off
- 1:36Speaker 1: the system. But without that easy C to upload button,
- 1:39Speaker 1: how do we turn our attacking machine into a source
- 1:42Speaker 1: that target system trusts enough to use the basic Windows
- 1:45Speaker 1: copy command?
- 1:46Speaker 2: Yeah, because just trying to copy something across networks usually
- 1:49Speaker 2: just ends in a permissions error. Right, it requires setting
- 1:52Speaker 2: up a temporary digital bridge. You're essentially turning your attacking
- 1:57Speaker 2: machine into a small network attached sworded.
- 2:00Speaker 1: A NAS drive Okay, a temporary NASS right.
- 2:03Speaker 2: On your control system, say a Collie machine. You set
- 2:07Speaker 2: up an SMB share, maybe you name it test using
- 2:10Speaker 2: a tool like Impact. And the crucial thing here is
- 2:13Speaker 2: that this setup uses a protocol SMB overport four forty
- 2:17Speaker 2: five that firewalls often allow for internal traffic.
- 2:21Speaker 1: Which makes it a really reliable channel.
- 2:23Speaker 2: A highly reliable channel, especially when those external C two
- 2:26Speaker 2: protocols might be blocked.
- 2:28Speaker 1: So you've set up this bridge. Walk us through retrieving
- 2:31Speaker 1: some intelligence. I've found a user file, maybe a spreadsheet
- 2:34Speaker 1: or a text document named hello dot txt on the
- 2:38Speaker 1: remote target system.
- 2:39Speaker 2: Okay, so from the remote target shell you execute a
- 2:42Speaker 2: simple copy command, but you direct the destination back to
- 2:45Speaker 2: your share.
- 2:46Speaker 1: You're telling the remote target to do the.
- 2:47Speaker 2: Work you are. You're telling it to pull the file
- 2:49Speaker 2: from its local directory and place it onto your SMB
- 2:52Speaker 2: share on your attacking IP. It's the target system initiating
- 2:55Speaker 2: the transfer, that's key.
- 2:56Speaker 1: And just like that, you have the intelligence file.
- 2:58Speaker 2: Securely transferred using only native commands.
- 3:01Speaker 1: And I'm guessing delivering a payload, Yeah, a new executable
- 3:06Speaker 1: let's call it evil dot ex dot to the remote
- 3:09Speaker 1: system is just the reverse.
- 3:11Speaker 2: Precisely, you use the copy command on the target system
- 3:14Speaker 2: to pull the file from your remote SMB share and
- 3:17Speaker 2: deposit it into a local directory on the target machine.
- 3:21Speaker 1: Simple enough.
- 3:21Speaker 2: And on top of that, this foundation allows for a
- 3:24Speaker 2: really powerful capability multi hot file transfers.
- 3:29Speaker 1: What do you mean by that?
- 3:30Speaker 2: You can pivot and use this technique to copy files
- 3:33Speaker 2: directly between two separate remote target systems without those files
- 3:37Speaker 2: ever needing to pass back through your own setup.
- 3:39Speaker 1: Wow, so that's a pure, really stealthy form of lateral
- 3:42Speaker 1: data movement, it is. That's a fantastic demonstration of U
- 3:45Speaker 1: native reliability. Now, once we've secured the intelligence and delivered
- 3:49Speaker 1: the payload, we shift our focus from data delivery to
- 3:51Speaker 1: process control. We need to execute the file we just uploaded,
- 3:55Speaker 1: but we also need to be able to term any application.
- 3:57Speaker 1: Sometimes a running program, you know, it locks the file,
- 3:59Speaker 1: preventing cleanup.
- 4:00Speaker 2: That's right, and on Windows, the simplest and most common
- 4:03Speaker 2: tool for process control is task kill task kill. To
- 4:06Speaker 2: use it effectively, you first have to know the process's
- 4:09Speaker 2: unique identifier, the process ID or PID, and.
- 4:13Speaker 1: We get that PID using the task lists command just
- 4:16Speaker 1: viewing the list of running applications and their corresponding IDs. Correct.
- 4:20Speaker 2: For instance, if you run task list you find that
- 4:23Speaker 2: kelc dot ex has PID twenty seven three six, you'd
- 4:27Speaker 2: use tas kill pid twenty seven three six to terminate
- 4:30Speaker 2: it locally.
- 4:31Speaker 1: Simple.
- 4:32Speaker 2: Now to your point, we need to upgrade that for
- 4:34Speaker 2: remote systems, you can use the S parameter within taskkill
- 4:38Speaker 2: to specify a remote computer's IP address, so you.
- 4:40Speaker 1: Can reach out and kill a process on a totally
- 4:42Speaker 1: different machine with that same command that one native command. Wait,
- 4:46Speaker 1: if I'm trying to kill a process remotely using cast
- 4:48Speaker 1: kills versus using a more sophisticated scripting tool, is that
- 4:52Speaker 1: termination recorded differently in the target machines event logs? Does
- 4:56Speaker 1: one offer better stealth?
- 4:57Speaker 2: That's a crucial question about tradecraft. But while taskkell s works,
- 5:01Speaker 2: it can sometimes be blocked or leave a really predictable signature,
- 5:05Speaker 2: And this brings us to redundancy tool number two. W
- 5:09Speaker 2: MIIK w MIIK. WMI stands for Windows Management Instrumentation. You
- 5:15Speaker 2: should think of WMI as the core management layer of
- 5:18Speaker 2: the Windows operating system. It's the built in scripting engine
- 5:21Speaker 2: that lets you manage nearly every component.
- 5:24Speaker 1: So WMIK is just the command line interface to that
- 5:27Speaker 1: powerful layer exactly.
- 5:29Speaker 2: Instead of relying on the S parameter of taskkill, you
- 5:32Speaker 2: use w MIIK to target a remote node explicitly and
- 5:35Speaker 2: tell that node to terminate the process itself.
- 5:37Speaker 1: Okay, so it's more direct.
- 5:39Speaker 2: It is. The syntax is a bit heavier. You specify
- 5:42Speaker 2: the remote node the process class where the process id
- 5:44Speaker 2: equals your target, and then you invoke the call terminate action.
- 5:48Speaker 2: But this method often offers way more flexibility and it
- 5:50Speaker 2: can bypass limitations placed on simpler network tools.
- 5:54Speaker 1: So we've cleared the field of old processes. Now for execution,
- 5:57Speaker 1: we've uploaded our payload. How do we launch it remotely
- 6:00Speaker 1: and ideally with maximum privilege instability?
- 6:03Speaker 2: We have three primary command line methods, each with different
- 6:07Speaker 2: implications for persistence and detection. The first leveraging our redundancy
- 6:11Speaker 2: is w MIIK direct creation.
- 6:13Speaker 1: W MIIK again, this time for creation instead of destruction.
- 6:18Speaker 2: You got it. We use the process called create action
- 6:21Speaker 2: on the remote node, specifying the path to our.
- 6:23Speaker 1: Executable Okay, but what's the catch?
- 6:25Speaker 2: The critical note here is context. This method usually runs
- 6:29Speaker 2: the process in the background under the security context of
- 6:32Speaker 2: the user currently logged into the session, you know, like
- 6:35Speaker 2: Peter Pan.
- 6:36Speaker 1: So it's great for quick execution, but it dies if
- 6:39Speaker 1: Peter Pan logs off.
- 6:40Speaker 2: Right that instability is an ideal for long term control?
- 6:43Speaker 1: Definitely not? So what if we need true stability and
- 6:47Speaker 1: elevated privilege regardless of who is logged.
- 6:49Speaker 2: In That brings us to method two, creating a service
- 6:53Speaker 2: using the stute command the Service Control manager. Services services
- 6:57Speaker 2: are designed to run in the background, often before user
- 6:59Speaker 2: even law bugs in, and they can be created, started,
- 7:02Speaker 2: and stopped remotely. But the real power is that, by default,
- 7:06Speaker 2: the service control Manager lets you define the service's binary
- 7:09Speaker 2: path and start it running with high privilege, often as
- 7:12Speaker 2: system authority.
- 7:13Speaker 1: That's the ultimate privilege, running as the operating system itself.
- 7:17Speaker 1: You define the service, start it, and bam you have
- 7:20Speaker 1: a highly privileged, stable process running persistently. But what's the
- 7:24Speaker 1: trade off. Wouldn't creating a new, unknown service leave a
- 7:28Speaker 1: huge forensic artifact?
- 7:29Speaker 2: Absolutely? The trade off is detection services are incredibly stable,
- 7:34Speaker 2: but they create clear, undeniable forensic artifacts. We're talking new
- 7:38Speaker 2: registry entries, new service files, specific event log IDs.
- 7:43Speaker 1: So they're relatively easy for defenders to spot.
- 7:45Speaker 2: Very easy. As a countermeasure, responsible operators must use st
- 7:49Speaker 2: delete afterward to clean up that service entry, but the
- 7:51Speaker 2: fact that it was created is recorded.
- 7:53Speaker 1: Which leads us to method three. A persistence favorite scheduled
- 7:57Speaker 1: tasks using the tasks command. This seems like an mid ground.
- 8:00Speaker 2: It is versatile and often viewed as stealthier than a
- 8:03Speaker 2: full service. Use the S parameter to target the remote
- 8:06Speaker 2: system and define the task name.
- 8:08Speaker 1: And crucially, like services, you can specify the user the
- 8:11Speaker 1: task runs as.
- 8:12Speaker 2: Right, you can often set the RU that's the run
- 8:15Speaker 2: as user parameter to system. This gives you that same
- 8:18Speaker 2: high privilege without the heavy footprint of a new service
- 8:22Speaker 2: registry key.
- 8:22Speaker 1: And we can immediately trigger it with the run parameter
- 8:25Speaker 1: right after creation.
- 8:26Speaker 2: Yes for immediate launch. And here's some expert advice. Persistence
- 8:31Speaker 2: and stealth are two sides of the same coin. Okay,
- 8:34Speaker 2: always use query and delete immediately after use to ensure
- 8:37Speaker 2: the task is gone. A forgotten scheduled task is a
- 8:41Speaker 2: massive giveaway of your activity.
- 8:43Speaker 1: This deep understanding of execution leads us to the final
- 8:46Speaker 1: and most impactful category of control, interrupting availability. We're moving
- 8:52Speaker 1: into the realm of the minor att and CK frameworks
- 8:54Speaker 1: impact tactic.
- 8:56Speaker 2: Right, specifically systems shut down or reboot. The goal here
- 8:59Speaker 2: is complete.
- 9:00Speaker 1: Disruption, and the primary tool for that.
- 9:02Speaker 2: The standard yet surprisingly powerful tool is the shut down command.
- 9:06Speaker 2: It's local, but it accepts a remote target.
- 9:09Speaker 1: What are the essential parameters we need to know for this?
- 9:12Speaker 2: You need f to force all applications to close instantly,
- 9:16Speaker 2: T to set the time delay, often set to zero
- 9:18Speaker 2: for an instantaneous effect, and R if you want to
- 9:21Speaker 2: reboot instead of just shutting down.
- 9:24Speaker 1: And the magic, of course is the remote parameter.
- 9:26Speaker 2: That's the M parameter. It allows you to target a
- 9:29Speaker 2: remote IP address, effectively rebooting a system you might not
- 9:32Speaker 2: even be directly logged into.
- 9:35Speaker 1: And beyond forcing the entire machine to restart, we can
- 9:38Speaker 1: also target specific logged in users and kick them off remotely.
- 9:42Speaker 2: That's the remote log off capability. This is a two
- 9:45Speaker 2: step process using some of the older session management tools. First,
- 9:49Speaker 2: you need to identify the user's session ID. How you
- 9:52Speaker 2: do that You run quin's to S with the IP
- 9:54Speaker 2: address to query the active user sessions. You might find
- 9:57Speaker 2: that Peter can is logged in with session ID one.
- 10:00Speaker 1: The execution command for the logoff.
- 10:01Speaker 2: That would be our wins to S with the IP
- 10:04Speaker 2: and the session ID. You'd replace the ID with the
- 10:06Speaker 2: number you found in this case one to force a
- 10:09Speaker 2: remote log off just for that user.
- 10:10Speaker 1: But you have to be careful here you do.
- 10:13Speaker 2: It's worth noting that these winds to commands aren't always
- 10:15Speaker 2: available on the most recent Windows versions, which again highlights
- 10:18Speaker 2: the necessity of redundancy, which brings us.
- 10:20Speaker 1: Back to w MIIK. What if we want to be
- 10:23Speaker 1: more surgical or use wmi's deep knowledge of the system environment.
- 10:28Speaker 2: W MIIK allows for conditional targeting. You can, for instance,
- 10:33Speaker 2: query a remote system for its specific OS build number,
- 10:37Speaker 2: say build one four three nine three okay, and then
- 10:41Speaker 2: tell w MIIK to execute the restart action only if
- 10:44Speaker 2: the build number matches. This ensures your disruption command is
- 10:47Speaker 2: only running on the exact target environment you expected.
- 10:50Speaker 1: Which is critical in a large network. Absolutely or the
- 10:53Speaker 1: aggressive move. I heard about that creative rolling reboot that
- 10:57Speaker 1: sounds like a denial of service attack using purely native commands.
- 11:00Speaker 2: It is a seriously aggressive move. It's the cyber equivalent
- 11:03Speaker 2: of pulling the plug and then wiring the power button
- 11:05Speaker 2: to a timer.
- 11:06Speaker 1: So how does it work?
- 11:07Speaker 2: You combine scheduled tasks with the immediate shutdown command. You
- 11:10Speaker 2: create a scheduled task using tasks create, and you set
- 11:14Speaker 2: the schedule parameter down it two on start.
- 11:16Speaker 1: Meaning the task runs every single time the system boots.
- 11:19Speaker 2: Up precisely, and the command you define for that task
- 11:22Speaker 2: is the instantaneous forced reboot command cmd dot EXCC shut
- 11:27Speaker 2: down rt zero f.
- 11:30Speaker 1: So the result is a cycle.
- 11:31Speaker 2: A vicious cycle. The system reboots, it starts up, the
- 11:35Speaker 2: task immediately executes. The command forces another reboot, and the
- 11:38Speaker 2: cycle continues indefinitely until that task is manually removed.
- 11:42Speaker 1: That's a guaranteed availability interact. Guaranteed. That sounds devastating. I mean,
- 11:47Speaker 1: before deploying such a disruptive effect, there's a serious responsibility
- 11:50Speaker 1: point here. If that command were to fail its cleanup step,
- 11:55Speaker 1: the victim system is permanently bricked in a reboot loop.
- 11:57Speaker 2: Absolutely, when deploying any disrupt of effect, especially one that
- 12:01Speaker 2: relies on network connectivity for cleanup, you must have a tested,
- 12:04Speaker 2: reliable cleanup procedure, in this case, tasks delete. If that
- 12:08Speaker 2: cleanup fails, you've rendered the system non functional.
- 12:10Speaker 1: Which is an immediate operational feeling, a huge failure. And finally,
- 12:13Speaker 1: let's wrap up this section with the ultimate modern redundancy,
- 12:17Speaker 1: PowerShell and the GWMI Cmdlet.
- 12:20Speaker 2: Right GWMI or get WMI object access is the same
- 12:24Speaker 2: underlying Wi mechanism, but through PowerShell scripting. This is often
- 12:28Speaker 2: the preferred modern method.
- 12:30Speaker 1: So how does the syntax work.
- 12:31Speaker 2: It involves calling the win thirty two operating system class
- 12:34Speaker 2: on the remote computer and then invoking the WIN thirty
- 12:37Speaker 2: two shut down method using a numerical parameter.
- 12:40Speaker 1: And those numbers are the key to control.
- 12:42Speaker 2: They define the action precisely for the listener. Here are
- 12:46Speaker 2: the key control codes. Zero is a graceful log off,
- 12:50Speaker 2: one is a graceful shutdown. Then you have the forced options.
- 12:54Speaker 2: Four is a force log off, five is a force shutdown,
- 12:56Speaker 2: and six is a forced reboot.
- 12:58Speaker 1: Full scriptable control exactly, and we can leverage that PowerShell
- 13:02Speaker 1: capability to create a persistent attack ensuring the user can
- 13:05Speaker 1: never remain logged in for long you can.
- 13:08Speaker 2: You can wrap the GWMI logoff command in a simple
- 13:10Speaker 2: PowerShell while true loop with a short sleep functions, say
- 13:13Speaker 2: twenty seconds. This creates a persistent cyclical log off attack.
- 13:17Speaker 1: The moment of user signs back.
- 13:19Speaker 2: In, the loop runs and the GWMI command logs them
- 13:21Speaker 2: right back out. It's reliable and it just uses native
- 13:24Speaker 2: scripting features.
- 13:25Speaker 1: So what does this all mean. It means control over
- 13:27Speaker 1: a remote system isn't about finding one single magic tool.
- 13:31Speaker 1: It's about a deep, comprehensive understanding of standard system commands copy, taskkill,
- 13:37Speaker 1: see tasks, shut.
- 13:39Speaker 2: Down and their advanced scriptable parameters like w MIIK and PowerShell.
- 13:44Speaker 1: Exactly, we've covered the full spectrum, from the quiet act
- 13:47Speaker 1: of moving a single text file to the loud disruption
- 13:51Speaker 1: of a forced rolling reboot.
- 13:53Speaker 2: And I think the most important lesson we hammered home
- 13:55Speaker 2: today's redundancy. Never rely on just one method. If taskill
- 13:59Speaker 2: is blocked, you have w MIIK. If service creation is
- 14:02Speaker 2: flagged by a monitor, you use scheduled tasks. Understanding all
- 14:06Speaker 2: these native alternatives ensures your operations can continue even when
- 14:09Speaker 2: automated tools fail. It makes you a far more reliable operator.
- 14:13Speaker 1: That is the ultimate goal. So for our final thought,
- 14:16Speaker 1: we spend time contrasting two high privileged execution methods, creating
- 14:20Speaker 1: a new service that runs a system and creating a
- 14:23Speaker 1: scheduled task set to run as system. For a sophisticated operator,
- 14:26Speaker 1: why would they choose the simpler scheduled task over the service.
- 14:29Speaker 2: It's a great question. You should think specifically about detection
- 14:33Speaker 2: and the kind of artifacts each method leaves behind.
- 14:35Speaker 1: Now go explore the deep documentation for those commands. That's
- 14:39Speaker 1: where true mastery lies.