Skip to content

Commit df8e5f0

Browse files
committed
fix Windows arm64 WireGuard reconnects
1 parent 7b11483 commit df8e5f0

8 files changed

Lines changed: 73 additions & 4 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build (windows && !arm64) || darwin || linux
2+
3+
package wireguard
4+
5+
import "golang.zx2c4.com/wireguard/conn"
6+
7+
func newWGUDPBind() conn.Bind {
8+
return conn.NewDefaultBind()
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build windows && arm64
2+
3+
package wireguard
4+
5+
import "golang.zx2c4.com/wireguard/conn"
6+
7+
// WinRingBind can stop exchanging handshakes after rapid userspace-device
8+
// recreation on Windows ARM64. Beacon callbacks recreate their device at each
9+
// interval, so use wireguard-go's portable socket bind on this target.
10+
func newWGUDPBind() conn.Bind {
11+
return conn.NewStdNetBind()
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build windows && arm64
2+
3+
package wireguard
4+
5+
import (
6+
"testing"
7+
8+
"golang.zx2c4.com/wireguard/conn"
9+
)
10+
11+
func TestWindowsARM64WGUDPBindUsesStandardSockets(t *testing.T) {
12+
if _, ok := newWGUDPBind().(*conn.StdNetBind); !ok {
13+
t.Fatal("Windows ARM64 WireGuard bind did not use standard sockets")
14+
}
15+
}

implant/sliver/transports/wireguard/wireguard.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import (
4848

4949
"github.com/bishopfox/sliver/implant/sliver/netstack"
5050
"golang.org/x/crypto/blake2b"
51-
"golang.zx2c4.com/wireguard/conn"
5251
"golang.zx2c4.com/wireguard/device"
5352
"golang.zx2c4.com/wireguard/tun"
5453
"google.golang.org/protobuf/proto"
@@ -375,7 +374,7 @@ func bringUpWGInterface(address string, port uint16, implantPrivKey string, serv
375374
wgLogLevel = device.LogLevelVerbose
376375
// {{end}}
377376

378-
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(wgLogLevel, "[c2/wg] "))
377+
dev := device.NewDevice(tun, newWGUDPBind(), device.NewLogger(wgLogLevel, "[c2/wg] "))
379378
wgConf := bytes.NewBuffer(nil)
380379
fmt.Fprintf(wgConf, "private_key=%s\n", implantPrivKey)
381380
fmt.Fprintf(wgConf, "public_key=%s\n", serverPubKey)

server/c2/wireguard.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import (
4141
"github.com/bishopfox/sliver/server/netstack"
4242
"github.com/bishopfox/sliver/util/minisign"
4343
"github.com/hashicorp/yamux"
44-
"golang.zx2c4.com/wireguard/conn"
4544
"golang.zx2c4.com/wireguard/device"
4645
"google.golang.org/protobuf/proto"
4746
)
@@ -108,7 +107,7 @@ func StartWGListener(port uint16, netstackPort uint16, keyExchangeListenPort uin
108107
// Set this to device.LogLevelVerbose when debugging for verbose logs
109108
// We should probably set this to LogLevelError and figure out how to
110109
// redirect the logs from stdout
111-
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelSilent, "[c2/wg] "))
110+
dev := device.NewDevice(tun, newWGUDPBind(), device.NewLogger(device.LogLevelSilent, "[c2/wg] "))
112111

113112
wgConf := bytes.NewBuffer(nil)
114113
fmt.Fprintf(wgConf, "private_key=%s\n", privateKey)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !windows || !arm64
2+
3+
package c2
4+
5+
import "golang.zx2c4.com/wireguard/conn"
6+
7+
func newWGUDPBind() conn.Bind {
8+
return conn.NewDefaultBind()
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//go:build windows && arm64
2+
3+
package c2
4+
5+
import "golang.zx2c4.com/wireguard/conn"
6+
7+
// Use the portable socket bind on Windows ARM64 so the listener continues to
8+
// accept handshakes when short-lived beacon devices change their UDP endpoint.
9+
func newWGUDPBind() conn.Bind {
10+
return conn.NewStdNetBind()
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//go:build windows && arm64
2+
3+
package c2
4+
5+
import (
6+
"testing"
7+
8+
"golang.zx2c4.com/wireguard/conn"
9+
)
10+
11+
func TestWindowsARM64WGUDPBindUsesStandardSockets(t *testing.T) {
12+
if _, ok := newWGUDPBind().(*conn.StdNetBind); !ok {
13+
t.Fatal("Windows ARM64 WireGuard bind did not use standard sockets")
14+
}
15+
}

0 commit comments

Comments
 (0)