githubEdit

RunAs - Executing Commands with Different Privileges

The runas command in Windows allows users to execute programs with different permissions than the current user. This capability is essential for privilege escalation when you've discovered credentials for a more privileged account during penetration testing or red team exercises.

Basic Syntax and Usage

runas /user:<domain\username> "<command>"

Common Parameters

Parameter
Description

/user

Specifies the user account to run the command as

/savecred

Uses saved credentials (if previously saved)

/netonly

Indicates the credentials are for remote access only

/noprofile

Specifies that the user's profile should not be loaded

/env

Use the current environment instead of the user's

Basic Examples

# Run Command Prompt as Administrator
runas /user:Administrator cmd.exe

# Run Command Prompt as a domain user
runas /user:DOMAIN\admin cmd.exe

# Open notepad to edit a protected file
runas /user:Administrator "notepad.exe C:\Windows\System32\drivers\etc\hosts"

# Run PowerShell with elevated privileges
runas /user:Administrator "powershell.exe -ExecutionPolicy Bypass"

Privilege Escalation with RunAs

When you discover credentials during a pentest, runas can be used for privilege escalation:

1. Creating a New Admin User

2. Opening a Backdoor Connection

3. Accessing Protected Files

Limitations of RunAs

  1. Password Entry: runas will prompt for a password interactively; it doesn't accept pre-supplied passwords in the command line.

  2. SaveCred Option: The /savecred parameter only works if:

    • The user has previously saved credentials using this option

    • The system policy allows credential saving

  3. UAC Limitations: User Account Control may still block certain administrative actions.

  4. New Session: Creates a new logon session that doesn't inherit the current session's mapped drives or network connections.

Bypassing Password Prompt Limitation

Since runas requires interactive password entry, here are alternatives for automation:

1. Using PowerShell Start-Process

2. Using the SaveCred Option

First, save credentials interactively:

Then use in scripts without password prompt:

3. Using Alternative Tools

Finding Saved RunAs Credentials

During penetration testing, you might find saved credentials from previous runas /savecred usage:

Real-World Example: Accessing Protected Service Manager

Detection and Prevention

System administrators should implement these measures to prevent runas abuse:

  1. Disable Credential Saving: Prevent /savecred functionality via Group Policy

  2. Implement Credential Guard: Protect against credential theft

  3. Audit Usage: Enable logging of runas command execution

  4. Restrict Administrative Access: Limit who has administrator credentials

  5. Application Control: Use AppLocker or similar to restrict which programs can be run with runas

OSCP Exam Notes

For the OSCP exam:

  1. runas is especially useful when credentials are discovered through:

    • Credential hunting in files

    • Registry searches

    • Memory dumping

    • Clear-text password storage

  2. The /savecred option might be available in misconfigurated environments

  3. When runas doesn't work, try alternative methods:

    • PowerShell's Start-Process -Credential

    • PsExec

    • Windows Management Instrumentation (WMI)

  4. Document all attempts with runas during the exam, as this demonstrates methodology even if unsuccessful

Remember: Always obtain proper authorization before using these techniques in real environments.

Last updated