PowerShell Bible
Study Materials for Cybersecurity Students
Table of Contents
1. Introduction to PowerShell
PowerShell is a powerful command-line shell and scripting language built on the .NET framework. Unlike traditional command-line interfaces that work with text, PowerShell works with objects, making it incredibly powerful for system administration and cybersecurity tasks.
Why PowerShell Matters in Cybersecurity
System Administration: Manage Windows systems, users, and services
Incident Response: Quickly gather system information and analyze threats
Penetration Testing: Perform reconnaissance and exploitation tasks
Automation: Automate repetitive security tasks and monitoring
Forensics: Collect and analyze digital evidence
Key Features
Object-oriented: Works with .NET objects, not just text
Cross-platform: Available on Windows, Linux, and macOS
Extensible: Thousands of built-in commands (cmdlets)
Integrated: Deep integration with Windows and .NET ecosystem
2. Getting Started
Installation and Access
Windows:
PowerShell 5.1 comes pre-installed on Windows 10/11
PowerShell 7+ can be installed via:
winget install Microsoft.PowerShell
Linux/macOS:
Launching PowerShell
Windows PowerShell:
powershell.exePowerShell Core/7+:
pwsh.exeAs Administrator: Right-click → "Run as Administrator"
Basic Interface
3. Essential PowerShell Fundamentals
Understanding Cmdlets
PowerShell commands are called "cmdlets" and follow a Verb-Noun pattern:
Common Verbs
Get: Retrieve information
Set: Modify settings
Start/Stop: Control services/processes
New: Create new objects
Remove: Delete objects
Test: Verify conditions
Getting Help
The help system is your best friend:
Discovering Commands
4. Core Commands for Cybersecurity
System Information Commands
Get-ComputerInfo - Comprehensive system information
Get-WmiObject - Windows Management Instrumentation queries
Get-CimInstance - Modern replacement for Get-WmiObject
Process and Service Management
Get-Process - List running processes
Get-Service - Manage Windows services
Network Commands
Test-NetConnection - Network connectivity testing
Get-NetTCPConnection - Active network connections
Resolve-DnsName - DNS resolution
5. Variables and Data Types
Basic Variables
Variables in PowerShell start with $:
Automatic Variables
PowerShell provides many built-in variables:
Environment Variables
Access system environment variables:
Arrays and Hash Tables
6. Working with Objects and Pipelines
The Pipeline
PowerShell's pipeline (|) passes objects between commands:
This command:
Gets all processes
Filters for high CPU usage
Sorts by CPU usage (highest first)
Object Properties and Methods
Explore object structure with Get-Member:
Selecting and Filtering
Select-Object - Choose specific properties
Where-Object - Filter objects
Sort-Object - Sort results
7. Security Policies and Bypasses
Understanding Execution Policy
PowerShell's execution policy controls script execution:
Restricted: No scripts allowed (default on Windows desktop)
RemoteSigned: Local scripts OK, remote scripts must be signed
AllSigned: All scripts must be signed
Unrestricted: All scripts allowed (default on Linux/macOS)
Bypass: No restrictions or warnings
Checking Current Policy
Bypassing Execution Policy
⚠️ Important: These techniques are for educational and legitimate testing purposes only.
Method 1: Temporary bypass for current session
Method 2: Command-line bypass
Method 3: Download and execute
Method 4: Encode and execute
Zone Identifier and Unblocking Files
Windows marks downloaded files as potentially unsafe:
8. File System Operations
Navigation and Listing
File Operations
File Properties and Permissions
Alternate Data Streams (Windows)
9. Network and System Information
Network Configuration
Network Connectivity
System Monitoring
User and Group Information
10. Practical Cybersecurity Examples
Example 1: System Reconnaissance
Example 2: Network Port Scanning
Example 3: Log Analysis
Example 4: Process Monitoring
11. Fileless Execution & In-Memory Operations
Fileless execution and in-memory operations are critical techniques in modern cybersecurity, used by both attackers and security professionals. These methods allow code execution without writing files to disk, making detection more challenging and leaving minimal forensic traces.
Understanding Fileless Execution
Fileless execution refers to running code directly in memory without creating files on the target system's hard drive. This technique:
Evades file-based detection: Traditional antivirus solutions scan files on disk
Reduces forensic footprint: No persistent artifacts left behind
Leverages legitimate tools: Uses built-in system utilities like PowerShell
Enables living-off-the-land: Utilizes existing system capabilities
Core Concepts
Memory-based execution works by:
Downloading code/binaries directly into system memory
Loading and executing the code from memory
Avoiding disk writes that could trigger security alerts
Using reflection and .NET capabilities for execution
PowerShell Commands for Memory Operations
Invoke-WebRequest (iwr)
Downloads content directly into memory:
Invoke-RestMethod (irm)
Simplified method for REST API calls:
.NET WebClient Class
Lower-level approach using .NET directly:
In-Memory Binary Execution Techniques
Reflection-Based Loading
Using .NET reflection to load assemblies in memory:
PowerShell Runspaces
Creating isolated execution environments:
Practical Examples
Example 1: Mimikatz in Memory
Educational Purpose: Understanding credential extraction techniques
Example 2: PowerShell Empire Style
Red Team Technique: Stager-based execution
Example 3: Cobalt Strike Beacon Style
Advanced Persistent Threat Simulation:
Example 4: Script Block Execution
Dynamic Code Execution:
Advanced Techniques
Process Injection
Injecting code into existing processes:
DLL Reflection
Loading DLLs without file system interaction:
Detection and Mitigation Strategies
Detection Methods
PowerShell Logging:
Behavioral Monitoring:
Monitor for suspicious network connections
Track unusual process relationships
Analyze memory usage patterns
Watch for encoded command execution
Command Line Analysis:
Mitigation Strategies
PowerShell Security Features:
Network Security:
Implement DNS filtering
Monitor outbound connections
Use proxy servers with content inspection
Deploy network segmentation
Endpoint Protection:
Enable Windows Defender Application Guard
Use behavior-based detection tools
Implement endpoint detection and response (EDR)
Deploy application whitelisting
System Hardening:
12. Common Pitfalls and Best Practices
Common Pitfalls
Not Understanding the Pipeline
Remember: PowerShell passes objects, not text
Use
Get-Memberto understand object structure
Ignoring Execution Policy
Always check execution policy in new environments
Understand the security implications of bypasses
Not Using Proper Error Handling
Forgetting About Case Sensitivity
PowerShell is generally case-insensitive
But some operators have case-sensitive variants (
-ceq,-clike)
Best Practices
Use Full Cmdlet Names in Scripts
Always Test with
-WhatIfUse Proper Parameter Names
Handle Errors Appropriately
Use Comments and Documentation
13. Quick Reference
Essential Cmdlets
Get-Help
Get help for commands
Get-Help Get-Process
Get-Command
Find commands
Get-Command *service*
Get-Member
Explore objects
Get-Process | Get-Member
Get-Process
List processes
Get-Process -Name chrome
Get-Service
List services
Get-Service -Name win*
Get-ChildItem
List files/folders
Get-ChildItem -Recurse
Test-Connection
Ping hosts
Test-Connection google.com
Invoke-WebRequest
Web requests
Invoke-WebRequest http://example.com
Common Aliases
ls, dir, gci
Get-ChildItem
List files
cd, sl
Set-Location
Change directory
pwd, gl
Get-Location
Show current directory
cat, gc, type
Get-Content
Read file content
ps, gps
Get-Process
List processes
gsv
Get-Service
List services
iwr
Invoke-WebRequest
Web request
iex
Invoke-Expression
Execute string as command
Operators
-eq
Equal
$a -eq $b
-ne
Not equal
$a -ne $b
-gt
Greater than
$a -gt 5
-lt
Less than
$a -lt 10
-like
Wildcard match
$name -like "*admin*"
-match
Regex match
$text -match "\d+"
-contains
Array contains
$array -contains "value"
-and
Logical AND
($a -gt 5) -and ($b -lt 10)
-or
Logical OR
($a -eq 1) -or ($b -eq 2)
14. Glossary
Cmdlet: A PowerShell command that follows the Verb-Noun naming convention.
Pipeline: The mechanism that passes objects from one command to another using the | operator.
Object: A data structure that contains both data (properties) and functions (methods).
Parameter: An input to a cmdlet that modifies its behavior.
Alias: A shorter name for a cmdlet (e.g., ls for Get-ChildItem).
Execution Policy: A security feature that controls which PowerShell scripts can run.
Provider: A PowerShell component that provides access to data stores (file system, registry, etc.).
Module: A package of PowerShell functionality that can be imported and used.
Script Block: A collection of PowerShell statements enclosed in braces {}.
WMI/CIM: Windows Management Instrumentation - a framework for managing Windows systems.
Splatting: A technique for passing parameters to cmdlets using hash tables.
Alternate Data Stream: A feature of NTFS that allows multiple data streams per file.
15. Additional Resources
Official Documentation: https://docs.microsoft.com/powershell/
PowerShell Gallery: https://www.powershellgallery.com/
Community Forums: https://reddit.com/r/PowerShell
Security Focus: https://github.com/PowerShellMafia/PowerSploit
Remember: With great power comes great responsibility. Use PowerShell ethically and in accordance with your organization's policies and applicable laws.
PowerShell Bible for Cybersecurity Students - Version 1.0 Created for educational purposes by TryHard3r
Last updated