# Course #454: PoshC2 Penetration Testing

## Section 1: Introduction to PoshC2

### Overview

PoshC2 is a powerful post-exploitation framework that allows penetration testers and red teamers to control compromised machines, execute commands, and conduct various types of attacks using PowerShell. It’s particularly noteworthy for its focus on Windows environments and is ideal for simulating advanced persistent threats (APTs). This section will guide you through the installation, configuration, and practical usage of PoshC2 on Kali Linux, offering a comprehensive understanding of its capabilities and features.

### 1. Installation and Configuration on Kali Linux

#### 1.1 Prerequisites

Before installing PoshC2, ensure that you have the following prerequisites:

– **Kali Linux**: Ensure that you are running an updated version of Kali Linux. You can download it from the official Kali Linux website.
– **Python 3**: PoshC2 is written in Python, so you will need Python 3 installed on your machine.
– **Git**: Git is necessary for cloning the PoshC2 repository from GitHub.

#### 1.2 Installation Steps

1. **Update Your System**: Open a terminal and run the following command to make sure your system is up-to-date.


sudo apt update && sudo apt upgrade -y

2. **Install Required Packages**: Install Python 3 and Git if they are not already installed.


sudo apt install python3 python3-pip git -y

3. **Clone the PoshC2 Repository**: Use Git to clone the PoshC2 repository to your local machine.


git clone https://github.com/PoshC2/PoshC2.git

4. **Navigate to the PoshC2 Directory**:

5. **Install Dependencies**: PoshC2 requires various Python packages, which can be installed using pip.

6. **Initial Configuration**: Before launching PoshC2, you will need to configure it. This can be done using the built-in configuration scripts or manually editing the configuration files.


cp PoshC2/PoshC2.config.sample.json PoshC2/PoshC2.config.json
nano PoshC2/PoshC2.config.json

Update the configuration file as needed, paying attention to settings like the server port, database connections, and the domain name.

7. **Start PoshC2**: Finally, you can start the PoshC2 server.

#### 1.3 Configuration Parameters Explained

– **Server Address**: Set the IP address where PoshC2 will listen for incoming connections. Commonly, this will be your Kali machine's IP.

– **Port**: Default is usually `443`, but you can change this to any port that matches your network configuration.

– **Database**: PoshC2 can use SQLite for local testing or MongoDB for larger deployments. Configure this according to your needs.

### 2. Step-by-Step Usage of PoshC2

#### 2.1 Setting Up the Environment

Before running attacks with PoshC2, ensure your testing environment is secure and isolated. Utilize virtual machines or isolated networks to mitigate any risk to production systems.

#### 2.2 Using PoshC2: Real-World Use Cases

1. **Initial Access via Phishing**: Create a phishing email with a malicious link that points to a PoshC2 payload.

**Example Payload Generation**:

You can use the `Invoke-ReflectivePEInjection` command in PowerShell to create a payload. For example:

[/dm_code_snippet]powershell
Invoke-ReflectivePEInjection -PEPath "path_to_payload.exe"
[/dm_code_snippet]

After generating the payload, host it on a web server or cloud storage accessible to the target.

2. **Post-Exploitation**: Once the target has executed your payload, you can interact with the compromised machine using the PoshC2 interface.

– **Session Management**: Use the command interface to manage incoming sessions.

– **Command Execution**: Execute PowerShell commands on the target machine.

3. **Data Exfiltration**: Use PoshC2 to retrieve sensitive data from the compromised system.

4. **Simulating Lateral Movement**: Use built-in commands to simulate lateral movement to other machines in the network.


invoke-command -ComputerName -ScriptBlock { }

5. **Cleanup**: Always ensure that you clean up after the test by removing any traces of your activities.

### 3. Detailed Technical Explanations

#### 3.1 The PoshC2 Architecture

PoshC2 consists of a client-server architecture where the server is hosted on your Kali machine, and the clients are the payloads executed on target machines. Understanding this architecture is crucial for effective usage.

– **Server**: Manages sessions, commands, and communication between the attacker and the target.
– **Client**: The payload that runs on the target machine. It communicates back to the PoshC2 server over the specified port.

#### 3.2 Advanced Features

– **Obfuscation**: PoshC2 provides built-in capabilities for obfuscating PowerShell scripts to avoid detection by security products.

– **Task Scheduling**: You can use PoshC2 to schedule tasks on the target machine, maintaining persistence.

### 4. Code Examples in Markdown

Below are some code examples to illustrate common PoshC2 commands you might use during a penetration test. These examples can be formatted in WordPress using Markdown.

"`markdown
### Running PowerShell Commands on a Target Session

To execute a PowerShell command on a target session:

"`bash
execute-command -SessionId -Command "Get-Process"
"`
"`

"`markdown
### Uploading Files to the Target Machine

To upload files, use the following command:

"`bash
upload -SessionId -LocalFile "path_to_local_file" -RemotePath "C:\path_on_target"
"`
"`

"`markdown
### Performing Network Scans

You can initiate a network scan from the compromised machine:

"`bash
execute-command -SessionId -Command "Invoke-Nmap -Target 192.168.1.0/24"
"`
"`

### 5. External Reference Links

– [PoshC2 GitHub Repository](https://github.com/PoshC2/PoshC2)
– [Official PoshC2 Documentation](https://poshc2.readthedocs.io/en/latest/)
– [PowerShell for Pentesters](https://www.pentesteracademy.com/course?id=106)

This section provided an introduction to PoshC2, covering its installation, configuration, and practical usage with real-world applications. Mastering such tools will enhance your skills as a penetration tester, equipping you to simulate real-world attacks effectively.

Made by pablo rotem / פבלו רותם

Pablo Guides