Linux Digest

Kali Linux · Metasploit · OSCP · Pentest tutorials

Meterpreter Commands Cheatsheet: Essential Post-Exploitation for Pentesters

The Meterpreter payload, part of the Metasploit Framework, is your go-to advanced, dynamic, and extensible post-exploitation agent. It gives you an interactive shell on a compromised system, enabling a wide array of actions from file system manipulation and network pivoting to privilege escalation and credential dumping. Think of it as your Swiss Army knife once you've gained initial access – it's designed specifically for post-exploitation tasks, offering capabilities far beyond a standard shell.

For any pentester, red teamer, or OSCP candidate, mastering Meterpreter commands is non-negotiable. It's the critical link between initial compromise and achieving your engagement objectives, whether that's maintaining persistence, exfiltrating data, or pivoting deeper into a network.

Getting Started with Meterpreter: Establishing Your Foothold

Before you can use Meterpreter commands, you need a Meterpreter session. This typically involves crafting a payload with tools like Msfvenom, delivering it to a target, and setting up a Metasploit listener (usually multi/handler) to catch the incoming connection. Once the target executes your payload, you'll see that glorious "Meterpreter session X opened" message, and you're in business.

From my experience, the initial setup can sometimes be the trickiest part, especially with antivirus solutions or network firewalls in play. Always test your payloads in isolated environments first to understand their behavior.

Key Takeaway: A Meterpreter session isn't just a shell; it's a powerful agent designed for sophisticated post-exploitation, making it indispensable for advanced offensive operations.

Core Meterpreter Commands: Your First Steps on a Compromised System

Once you've got a session, knowing where to start is key. These foundational commands help you get your bearings and begin interacting with the target.

Command Description Example Use Case
help Displays all available Meterpreter commands, categorized. help or help stdapi (for specific module)
background Puts the current Meterpreter session into the background, returning you to the msfconsole prompt. background (useful for managing multiple sessions)
exit Terminates the current Meterpreter session. exit (use when you're done with a session)
sysinfo Gathers system information about the target, including OS, architecture, and uptime. sysinfo (quick overview of the machine)
getuid Shows the user that the Meterpreter session is currently running as. getuid (essential for understanding your current privileges)
getprivs Lists the privileges held by the current user context. getprivs (check for admin rights, SeDebugPrivilege, etc.)
idletime Returns the number of seconds the target system has been idle. idletime (useful for determining user activity)

Essential Meterpreter Commands for Post-Exploitation Tactics

This is where Meterpreter truly shines. These commands let you move beyond initial access and perform common post-exploitation tasks, crucial for any red team engagement or Metasploit Post Exploitation scenario.

System Information and Reconnaissance with Meterpreter

Understanding your environment is paramount. Meterpreter offers several ways to gather intelligence on the compromised host.

File System Interaction: Moving Data In and Out

One of the most frequent tasks in post-exploitation is interacting with the target's file system. Meterpreter provides intuitive commands for this.

Expert Tip: When uploading or downloading, always consider the file's permissions on the target and ensure your Meterpreter session has the necessary rights to read/write to the desired locations.

Network Pivoting and Port Forwarding with Meterpreter

Often, your initial compromise only gives you access to one machine. To move laterally or access internal services, you'll need to pivot. Meterpreter's networking commands are incredibly powerful for this.

I've used portfwd countless times to access internal web servers, databases, or even RDP sessions that are otherwise inaccessible from my attacking machine. It's a cornerstone of lateral movement.

Process Management and Privilege Escalation

Gaining higher privileges is often a primary objective. Meterpreter helps you manage processes and elevate your standing.

Credential Dumping with Meterpreter

One of the most valuable pieces of information you can get from a compromised system is credentials. Meterpreter provides modules to help with this.

For even more advanced credential extraction, especially from memory, you'll often combine Meterpreter's capabilities with external tools. Our detailed guide on Mimikatz Dump Password: Extracting Credentials in Post-Exploitation covers this extensively.

Advanced Meterpreter Techniques and Modules

Meterpreter isn't just about basic commands; it's extensible through modules and scripts, allowing for complex operations.

Achieving Persistence

Maintaining access after a system reboot or user logout is crucial for red teams. Meterpreter has modules to help establish persistence.

Screenshotting and Keylogging

Gathering visual and input data can be incredibly insightful during an engagement.

Token Impersonation and Session Hijacking

Windows tokens can be a goldmine for privilege escalation and lateral movement. Meterpreter allows you to manipulate them.

Migrating Processes for Stability and Evasion

As mentioned earlier, migrate <PID> is vital. But why exactly? If your initial exploit lands Meterpreter in a volatile process (like a browser tab that might close), migrating to a more stable process (explorer.exe, winlogon.exe, or a system service) ensures your session persists longer. It also helps evade detection, as the original process might be flagged, but a legitimate system process running Meterpreter might go unnoticed for a while.

Meterpreter Scripting and Automation

Meterpreter isn't just about individual commands; you can automate complex tasks using its run command with various post-exploitation modules or even custom scripts. These scripts often simplify common workflows, like gathering system information, extracting credentials, or setting up persistence with a single command.

Learning to use these run commands effectively can dramatically speed up your post-exploitation phase, allowing you to focus on analysis rather than repetitive manual tasks.

Meterpreter Best Practices and OSCP Prep

For anyone preparing for the OSCP exam or working in a professional pentesting environment, how you use Meterpreter matters just as much as knowing the commands.

On the OSCP exam, Meterpreter is a tool, not a solution. You'll need to know *when* and *how* to use its commands to achieve specific objectives. It's often a stepping stone to further exploitation, like using gathered hashes for lateral movement via Pass-the-Hash, or leveraging a shell to compile and run custom privilege escalation exploits. For more on preparing for the exam, consider our guide on Mastering OSCP Exam Preparation: Your Blueprint to Certification.

Troubleshooting Common Meterpreter Issues

Things don't always go smoothly in the world of pentesting. Here are some common Meterpreter hiccups and how to deal with them:

Bottom Line: Meterpreter is an incredibly powerful agent, but it's not magic. Understanding the underlying operating system and network principles will help you troubleshoot effectively.

Mastering Meterpreter commands transforms your initial shell into a full-fledged control center. It's a critical component of the post-exploitation phase, giving you the tools to explore, exfiltrate, and escalate. Keep this cheatsheet handy, but more importantly, get hands-on experience. The more you use it, the more intuitive and effective your post-exploitation efforts will become. Happy hunting!

Metasploit Meterpreter Wiki MITRE ATT&CK - Meterpreter

Frequently Asked Questions

What is Meterpreter in Metasploit?

Meterpreter is an advanced, in-memory, dynamic payload that provides an interactive shell on a compromised system. It's specifically designed for post-exploitation tasks, offering extensive capabilities for file system interaction, network pivoting, privilege escalation, and more, all within the Metasploit Framework.

How do I get a Meterpreter session?

You typically obtain a Meterpreter session by crafting a malicious payload (often with Msfvenom), delivering it to a target system, and then setting up a Metasploit listener (like multi/handler) to catch the incoming connection when the target executes the payload.

What are the most important Meterpreter commands for OSCP?

For OSCP, focus on commands for system information (sysinfo, getuid, getprivs), file system interaction (ls, cd, upload, download), process management (ps, migrate), network pivoting (ipconfig, portfwd), and credential gathering (hashdump, load incognito, impersonate_token). The ability to use getsystem and establish persistence is also crucial.

Can Meterpreter bypass antivirus?

Meterpreter payloads, especially default ones, can often be detected by antivirus (AV) software. However, various techniques like encoding payloads (e.g., with Msfvenom encoders), using different payload types (stageless), or employing custom evasion methods can help bypass AV. It's a constant cat-and-mouse game between attackers and security vendors.