Maintaining Access
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.
sudo apt install wireguard
wg-quick up <interface>
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.
| Command | Purpose |
|---|---|
umask 077; wg genkey | tee private.key | wg pubkey > public.key | Create a protected key pair. |
wg show interfaces | List WireGuard interfaces. |
wg show wg0 latest-handshakes | Show last peer handshakes. |
wg show wg0 transfer | Show per-peer byte counters. |
wg genkey > privatekeyGenerate a new private key and save it to a filewg pubkey < privatekey > publickeyDerive the public key from an existing private keywg genkey | tee privatekey | wg pubkey > publickeyGenerate a private key and its matching public key in one pipelinewg genpsk > presharedkeyGenerate a preshared key for extra symmetric protectionwg showShow status of all active WireGuard interfaceswg show allExplicitly show every interface's peers and statswg show wg0Show status, peers and handshakes for interface wg0wg show wg0 dumpPrint a tab-separated machine-readable dump of wg0wg show interfacesList the names of all WireGuard interfaceswg show wg0 public-keyPrint only the public key of interface wg0wg showconf wg0Print the current configuration of wg0 in config-file formatwg-quick up wg0Bring up the interface defined in /etc/wireguard/wg0.confwg-quick down wg0Tear down the wg0 interface and restore routingwg-quick save wg0Save the running config of wg0 back to its .conf filewg-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 filewg addconf wg0 peer.confAppend peers from a file without touching existing oneswg syncconf wg0 <(wg-quick strip wg0)Apply config changes to wg0 without dropping active peerswg set wg0 private-key ./privatekeySet the interface's private key from a filewg set wg0 listen-port 51820Set the UDP port the interface listens onwg 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 endpointwg set wg0 peer <PUBKEY> persistent-keepalive 25Keep a NAT mapping alive by pinging every 25 secondswg set wg0 peer <PUBKEY> removeRemove a peer from the interfaceip link add dev wg0 type wireguardCreate the wg0 interface manually without wg-quicksystemctl enable --now wg-quick@wg0Enable and start the wg0 tunnel as a persistent service at bootMaintain long-term encrypted access to compromised networks.
Route C2 traffic through encrypted WireGuard tunnels.
Access internal subnets via encrypted tunnel.
Hide C2 traffic within legitimate VPN connections.
Join a home lab and a cloud VPS into one routable private network for practice ranges.
Reach SSH and management interfaces that are never exposed to the public internet.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
A comprehensive guide to VPN technology including protocols, use cases, security considerations, and how to choose a VPN service.
Networking · BeginnerHow 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 · BeginnerLearn SSH for secure remote access including key-based authentication, configuration, tunneling, port forwarding, and security hardening.
Networking · BeginnerLearn about network ports, their numbering system, common protocols at each layer, how services use ports, and security implications.
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.
This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.