GO KALI FREE

WireGuard

Maintaining Access

Intermediatehigh risk

WireGuard is an extremely fast, modern VPN protocol that lives inside the Linux kernel and uses state-of-the-art cryptography — Curve25519 key exchange, ChaCha20Poly1305 encryption, and the Noise protocol framework — in a core codebase of only a few thousand lines. In penetration testing and red team work it creates secure, persistent tunnels for pivoting into internal networks and maintaining encrypted access, while system administrators use the same tool for site-to-site links and road-warrior VPNs. Every peer is identified by a single public key, traffic is bound to that key by cryptokey routing (AllowedIPs), and the protocol stays completely silent toward unauthenticated packets, which makes a WireGuard port nearly invisible to scanners.

Installation

sudo apt install wireguard

Basic Syntax

wg-quick up <interface>

Quick Facts

Full Name
WireGuard VPN
License
GPL v2
Language
C / Rust
Interface
CLI
Category
VPN Tunneling
Protocol
UDP
Default Port
UDP 51820
In Linux Kernel
Since 5.6 (2020)

Tool Overview

WireGuard is a modern VPN protocol that uses state-of-the-art cryptography to create secure network tunnels. In penetration testing, it enables persistent, encrypted access to compromised networks with minimal latency.

Unlike traditional VPNs, WireGuard integrates directly into the Linux kernel, provides seamless roaming, and requires minimal configuration — making it the go-to choice for red teams requiring reliable covert channels.

The design philosophy is radical simplicity. A WireGuard interface has exactly one private key and a list of peers, each peer has exactly one public key and a set of AllowedIPs, and that is nearly the entire configuration model — a working tunnel config is often under twenty lines. There are no user accounts, no certificate authorities, no cipher negotiation, and no protocol versions to mismatch: both ends either speak the same fixed, modern cryptography or they do not connect. The core implementation is a few thousand lines of code, small enough to audit, which is a security feature in itself next to VPN stacks of a hundred thousand lines or more.

Cryptokey routing is the idea that makes it work. When a packet enters the interface, WireGuard looks at its destination, finds the peer whose AllowedIPs contain it, and encrypts the packet for that peer's public key. When a packet arrives and decrypts correctly, WireGuard checks its source address against the same peer's AllowedIPs and drops it if the address is not on the list. Identity, routing, and access control collapse into a single table — which is why a WireGuard configuration reads like a routing table and why copying someone's private key is equivalent to stealing their network identity.

In penetration testing the workflow usually looks like this: a foothold host inside the target network runs WireGuard back to the tester's server (outbound UDP is often permitted where inbound connections are not), or the tester deploys a small WireGuard server and enrolls each compromised host as a peer. The result is a stable, routable network — scanners, exploit tools, and proxies simply route subnets through wg0 instead of juggling individual port forwards. Because WireGuard is silent to unauthenticated traffic and encrypts everything with forward secrecy, the channel blends into ordinary UDP noise far better than an exposed reverse shell listener.

Quick Reference Commands

Verified quick-reference commands for WireGuard
CommandPurpose
umask 077; wg genkey | tee private.key | wg pubkey > public.keyCreate a protected key pair.
wg show interfacesList WireGuard interfaces.
wg show wg0 latest-handshakesShow last peer handshakes.
wg show wg0 transferShow per-peer byte counters.
WireGuard Quick Start

Common Commands

wg genkey > privatekeyGenerate a new private key and save it to a file
wg pubkey < privatekey > publickeyDerive the public key from an existing private key
wg genkey | tee privatekey | wg pubkey > publickeyGenerate a private key and its matching public key in one pipeline
wg genpsk > presharedkeyGenerate a preshared key for extra symmetric protection
wg showShow status of all active WireGuard interfaces
wg show allExplicitly show every interface's peers and stats
wg show wg0Show status, peers and handshakes for interface wg0
wg show wg0 dumpPrint a tab-separated machine-readable dump of wg0
wg show interfacesList the names of all WireGuard interfaces
wg show wg0 public-keyPrint only the public key of interface wg0
wg showconf wg0Print the current configuration of wg0 in config-file format
wg-quick up wg0Bring up the interface defined in /etc/wireguard/wg0.conf
wg-quick down wg0Tear down the wg0 interface and restore routing
wg-quick save wg0Save the running config of wg0 back to its .conf file
wg-quick strip wg0Print the config with wg-quick-only keys removed (for wg setconf)
wg setconf wg0 /etc/wireguard/wg0.confReplace wg0's peer configuration from a config file
wg addconf wg0 peer.confAppend peers from a file without touching existing ones
wg syncconf wg0 <(wg-quick strip wg0)Apply config changes to wg0 without dropping active peers
wg set wg0 private-key ./privatekeySet the interface's private key from a file
wg set wg0 listen-port 51820Set the UDP port the interface listens on
wg set wg0 peer <PUBKEY> allowed-ips 10.0.0.2/32 endpoint 10.10.10.10:51820Add or update a peer with its allowed IPs and endpoint
wg set wg0 peer <PUBKEY> persistent-keepalive 25Keep a NAT mapping alive by pinging every 25 seconds
wg set wg0 peer <PUBKEY> removeRemove a peer from the interface
ip link add dev wg0 type wireguardCreate the wg0 interface manually without wg-quick
systemctl enable --now wg-quick@wg0Enable and start the wg0 tunnel as a persistent service at boot

Step-by-Step Guide

  1. 1Install WireGuard on both machines: sudo apt install wireguard on Kali or Debian/Ubuntu. The package provides the wg and wg-quick tools; the kernel module is built into Linux 5.6 and later, so no DKMS build is needed on current systems.
  2. 2Set a restrictive umask and generate the server's keys: umask 077, then wg genkey > server_private.key and wg pubkey < server_private.key > server_public.key. Repeat the same two commands on the client so each side owns a unique key pair. Private keys never leave their machine — only public keys are exchanged.
  3. 3Write the server configuration at /etc/wireguard/wg0.conf: an [Interface] section with Address = 10.0.0.1/24, ListenPort = 51820, and PrivateKey set to the server's private key, followed by one [Peer] section per client holding that client's PublicKey and AllowedIPs = 10.0.0.2/32.
  4. 4Write the client configuration the same way: [Interface] with Address = 10.0.0.2/32 and the client's PrivateKey, then a [Peer] section with the server's PublicKey, Endpoint = vpn.example.org:51820, AllowedIPs = 10.0.0.0/0 if all traffic should use the tunnel (or just 10.0.0.0/24 for a split tunnel), and PersistentKeepalive = 25 if the client sits behind NAT.
  5. 5Open the path: allow UDP 51820 through any firewall in front of the server (for example sudo ufw allow 51820/udp). WireGuard is UDP-only and gives no error when packets are dropped — the tunnel simply never handshakes — so this step causes most failed first setups.
  6. 6Bring the tunnel up on the server with sudo wg-quick up wg0, then on the client. Make it permanent on a server with sudo systemctl enable --now wg-quick@wg0 so the interface returns after reboot.
  7. 7Verify the handshake with sudo wg show. A healthy tunnel shows a 'latest handshake' time within the last couple of minutes and growing transfer counters. If the field is empty, the handshake never completed — check keys, endpoint, and the UDP firewall rule before changing anything else.
  8. 8Test reachability through the tunnel: ping 10.0.0.1 from the client, then ping a host on the far subnet. If tunnel IPs answer but LAN hosts do not, the server needs IP forwarding (net.ipv4.ip_forward = 1) and, for traffic leaving the server, a NAT/MASQUERADE rule on its external interface.
  9. 9Route your tooling through the tunnel deliberately. With AllowedIPs = 0.0.0.0/0 on the client, everything — scans, shells, DNS — crosses WireGuard. Confirm with curl ifconfig.me or a DNS leak test that your traffic really exits where you think it does before running any assessment tools.
  10. 10Shut down cleanly and protect the keys: sudo wg-quick down wg0 removes the interface and restores routing. Keep the /etc/wireguard directory at mode 600, back up configurations securely, and rotate key pairs when a laptop is lost or a team member leaves — a private key is the peer's identity and cannot be revoked, only replaced.

Warnings

Use Cases

Persistent Tunnels

Maintain long-term encrypted access to compromised networks.

Covert C2

Route C2 traffic through encrypted WireGuard tunnels.

Network Pivoting

Access internal subnets via encrypted tunnel.

Traffic Obfuscation

Hide C2 traffic within legitimate VPN connections.

Site-to-Site Lab Links

Join a home lab and a cloud VPS into one routable private network for practice ranges.

Secure Remote Administration

Reach SSH and management interfaces that are never exposed to the public internet.

Key Features

People Also Ask

How do I generate WireGuard keys?

Generate a private key with wg genkey > privatekey, then derive the public key with wg pubkey < privatekey > publickey. For a one-line pipeline: wg genkey | tee privatekey | wg pubkey > publickey. Each peer needs its own unique key pair for the tunnel to establish.

What is the default WireGuard port?

WireGuard uses UDP port 51820 by default. You can change it in the configuration file with ListenPort = 51820 under the [Interface] section, or at runtime with wg set wg0 listen-port 51820. Both peers must know each other's listening port.

Can WireGuard work through NAT?

Yes, WireGuard traverses NAT naturally since it uses UDP. For peers behind NAT, set PersistentKeepalive = 25 to maintain the NAT mapping. The endpoint of the public peer is automatically updated when the NATed peer sends its first packet.

How do I configure a WireGuard peer?

Add a [Peer] section to the config file with the peer's PublicKey, AllowedIPs (the subnets routed through this peer), and optionally Endpoint (the peer's public IP:port). For example: AllowedIPs = 192.168.1.0/24 routes traffic for that subnet through the peer.

Is WireGuard faster than OpenVPN?

Yes, WireGuard is significantly faster due to its kernel-level integration and minimal codebase. WireGuard processes packets in the kernel space, while OpenVPN operates in user space. Benchmarks typically show WireGuard achieving near line-speed throughput with lower latency than OpenVPN.

How do I set up a site-to-site WireGuard tunnel?

Configure each site's router with a WireGuard interface. Each site gets a unique tunnel IP (e.g., 10.0.0.1/24 and 10.0.0.2/24). Set AllowedIPs to the remote site's LAN subnet (e.g., 192.168.2.0/24) and enable IP forwarding on both routers with sysctl net.ipv4.ip_forward=1.

Does WireGuard work on Windows and phones?

Yes. Official WireGuard apps exist for Windows, macOS, Android, and iOS, all reading the same .conf format as the Linux tools, and QR codes generated from a config let a phone enroll in seconds. The Linux kernel implementation remains the fastest, but the protocol and configuration are identical everywhere.

How is WireGuard different from a proxy like ProxyChains?

WireGuard is a real network interface: it carries every protocol (TCP, UDP, ICMP) for whole subnets at layer 3, and applications need no configuration to use it. ProxyChains pushes individual TCP connections from one application through proxy servers. Testers often combine them — WireGuard for the routable path into a network, ProxyChains for steering a specific tool through an additional hop.

Related Tools

sshuttle

Post Exploitation

sshuttle acts as a transparent proxy server that forwards traffic over an SSH connection, configuring local routing rules without requiring administrator privileges on the remote server host.

Chisel

Post Exploitation

Chisel is a fast TCP/UDP tunnel utility that encapsulates traffic over an HTTP transport channel, secured via SSH. It is useful for traversing firewall boundaries and pivoting inside network environments.

ProxyChains

Post Exploitation

ProxyChains forces TCP connections made by arbitrary applications to follow user-configured proxy networks (such as TOR or SOCKS4/5 configurations), useful for obfuscation and internal pivoting.

Ligolo-ng

Maintaining Access

Ligolo-ng is a simple, lightweight, and fast tunneling tool that uses a TUN interface. It allows penetration testers to establish tunnels from a reverse TCP/TLS connection without needing SOCKS proxies.

Socat

Maintaining Access

Socat is a command line based utility that establishes two bidirectional byte streams and transfers data between them, widely used for establishing shells, port forwarding, and encrypted connections.

pwncat

Maintaining Access

pwncat is an advanced, automated shell handler that extends the capabilities of traditional reverse or bind shells, offering built-in features for automated enumeration, persistence injection, and privilege escalation tracking.

Related Cybersecurity Guides

Networking · Beginner

VPN Guide: Understanding Virtual Private Networks for Privacy and Security

A comprehensive guide to VPN technology including protocols, use cases, security considerations, and how to choose a VPN service.

Networking · Beginner

How to Use WireGuard: Beginner's Guide to Setting Up a WireGuard VPN in Kali Linux

How to use WireGuard: install it on Kali Linux, build your first tunnel, verify it with wg show, and fix common problems — cheat sheet and 31 FAQs.

Linux · Beginner

SSH Fundamentals: Secure Remote Access and Administration

Learn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.

Networking · Beginner

Ports and Protocols: Understanding Network Communication

Learn about network ports, their numbering system, common protocols at each layer, how services use ports, and security implications.

Frequently Asked Questions

What is WireGuard used for in pentesting?

WireGuard is used to create secure, persistent VPN tunnels for maintaining access to compromised networks. It provides encrypted communication between attacking and target systems with minimal overhead.

How is WireGuard different from OpenVPN?

WireGuard is faster, simpler, and uses modern cryptography. It has a minimal codebase (~4,000 lines vs OpenVPN's ~100,000+), integrates into the Linux kernel, and establishes connections in milliseconds.

Can WireGuard bypass firewalls?

Yes, WireGuard uses UDP which can traverse NAT and firewalls. It can be configured to run on any UDP port and uses a keepalive mechanism to maintain connections through stateful firewalls.

Does WireGuard support roaming?

Yes, WireGuard fully supports client roaming. If a client changes networks, the tunnel automatically re-establishes without manual intervention, making it ideal for persistent access scenarios.

How do I know if my WireGuard tunnel is actually working?

Run sudo wg show and look at 'latest handshake'. If it shows a time within the last few minutes and the transfer counters grow as you send traffic, the tunnel is up. Then ping the far tunnel IP (for example 10.0.0.1). An empty handshake field means the tunnel has never connected — check the UDP port, endpoint, and that each side holds the other's correct public key.

Why does WireGuard show no handshake?

Almost always one of four causes: UDP 51820 (or your chosen port) is blocked by a firewall; the peer's public key was pasted incorrectly on one side; the Endpoint address or port is wrong; or the system clock on one peer is behind the last handshake timestamp, which WireGuard's replay protection rejects — common on devices without a real-time clock. WireGuard never explains the failure because it stays silent toward unauthenticated traffic by design.

What is AllowedIPs in WireGuard?

AllowedIPs does two jobs at once. As a routing rule it decides which destination addresses are sent into the tunnel. As a security rule it is the list of source addresses that peer is allowed to use — packets from the peer claiming any other address are dropped even when correctly encrypted. This binding of key to addresses is called cryptokey routing, and it replaces the user accounts and certificates other VPNs use.

What is the difference between a full tunnel and a split tunnel?

AllowedIPs on the client decides. Set AllowedIPs = 0.0.0.0/0 (and ::/0 for IPv6) and every packet, including DNS and browsing, crosses the tunnel — a full tunnel. List only the remote subnets, such as 10.0.0.0/24 and 192.168.10.0/24, and only that traffic uses WireGuard while everything else takes the normal connection — a split tunnel, which is usually right for pentest pivoting.

Which port and protocol does WireGuard use?

WireGuard uses UDP only, on port 51820 by default. You can change it with ListenPort in the [Interface] section — some testers run it on UDP 53 or 443-adjacent ports in restrictive environments, but it never becomes TCP; where only TCP is allowed, testers switch to a TCP-based tool such as Chisel or tunnel WireGuard inside another transport.

Is WireGuard safe to expose on the internet?

It is designed for exactly that. WireGuard does not respond to unauthenticated packets at all — no banner, no error, nothing for a scanner to fingerprint — and every packet is authenticated with the peer's key before any processing. Keep the system patched, protect the private keys, and it is one of the smallest attack surfaces you can expose: the core is only a few thousand lines of kernel code.

How do I add a kill switch to WireGuard?

A kill switch blocks traffic outside the tunnel if WireGuard goes down. The common pattern uses wg-quick's PostUp and PreDown hooks to add iptables rules that only allow outbound traffic on the wg0 interface (plus the UDP handshake to the endpoint), and remove them when the tunnel stops. Test it by bringing the tunnel down mid-session and confirming no traffic leaks over the normal interface.

Can I connect several clients to one WireGuard server?

Yes — add one [Peer] section per client to the server configuration, each with that client's own public key and a unique AllowedIPs tunnel address (10.0.0.2/32, 10.0.0.3/32, and so on). Never share one key pair between clients: keys are identities, so a shared key makes the clients indistinguishable and impossible to revoke individually.

Tags

#maintaining-access#vpn#tunneling#networking#persistence

Output Explanation

The wg show command is your health dashboard, and a healthy tunnel looks like this: "interface: wg0" followed by "public key", "private key: (hidden)", and "listening port: 51820", then one block per peer with "endpoint: 203.0.113.10:51820", "allowed ips: 10.0.0.2/32", "latest handshake: 1 minute, 12 seconds ago", "transfer: 3.21 MiB received, 1.04 MiB sent", and optionally "persistent keepalive: every 25 seconds". Read it in this order. First, latest handshake: WireGuard peers re-handshake every few minutes when traffic flows, so a recent timestamp proves the encrypted channel is alive right now; an empty field means no handshake has ever succeeded and the tunnel has never worked. Second, transfer counters: if received stays at 0 bytes while sent grows, your packets leave but nothing returns — the classic symptom of a wrong peer public key, a blocked UDP port, or AllowedIPs that do not cover the reply path. Third, endpoint: this is the address WireGuard last heard the peer from; because of roaming it updates automatically when a peer's network changes, and a stale or private (NAT) endpoint on the initiating side explains one-way tunnels. Finally, allowed ips is not just routing — it is the access-control list bound to that peer's key. Traffic from the peer claiming any other source address is dropped even if it decrypts correctly. For scripting, wg show wg0 dump prints the same data tab-separated, and wg showconf wg0 prints the live configuration in file format.

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.