Skip to content

Commit 23bf325

Browse files
authored
Merge pull request #2015 from BishopFox/sgn-wasm
Sgn wasm
2 parents 3f400bd + d9344a4 commit 23bf325

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+16020
-153
lines changed

.github/workflows/unit-tests.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ jobs:
3939
- name: Git Fetch Tags
4040
run: git fetch --prune --unshallow --tags -f
4141

42-
- name: Make Linux (amd64)
43-
run: make linux-amd64
44-
45-
- name: Test Linux
46-
run: ./sliver-server unpack --force && ./go-tests.sh
47-
4842
- name: Make Windows (amd64)
4943
run: make windows-amd64
5044

5145
- name: Make Linux (arm64)
5246
run: make linux-arm64
5347

48+
- name: Make Linux (amd64)
49+
run: make linux-amd64
50+
51+
- name: Test Linux
52+
run: make clean && make && ./sliver-server unpack --force && ./go-tests.sh
53+
54+
5455
macos-build-test:
5556
name: MacOS Test
5657
runs-on: macos-latest
@@ -61,9 +62,6 @@ jobs:
6162
with:
6263
go-version: "^1.25"
6364

64-
- name: Mingw
65-
run: brew install mingw-w64
66-
6765
- name: Check Out Code
6866
uses: actions/checkout@v5
6967

@@ -73,12 +71,12 @@ jobs:
7371
- name: Make MacOS (amd64)
7472
run: make macos-amd64
7573

76-
- name: Test MacOS (amd64)
77-
run: ./sliver-server unpack --force && ./go-tests.sh
78-
7974
- name: Make MacOS (arm64)
8075
run: make macos-arm64
8176

77+
- name: Test MacOS
78+
run: make clean && make && ./sliver-server unpack --force && ./go-tests.sh
79+
8280
clients-build:
8381
name: Clients Build
8482
runs-on: ubuntu-latest

go-assets.sh

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ set -e
2323
GO_VER="1.25.1"
2424
GARBLE_VER="1.25.1"
2525
ZIG_VER="0.15.1"
26-
SGN_VER="0.0.3"
26+
SGN_VER="0.0.4"
2727

2828
# Zig significantly throttles downloads from the main site, so we use
2929
# community mirrors. We fetch the list of mirrors at runtime, but
@@ -309,25 +309,6 @@ echo "curl -L --fail --output $OUTPUT_DIR/darwin/arm64/garble https://github.com
309309
curl -L --fail --output $OUTPUT_DIR/darwin/arm64/garble https://github.com/moloch--/garble/releases/download/v$GARBLE_VER/garble_macos-arm64
310310

311311

312-
echo "-----------------------------------------------------------------"
313-
echo " Shikata ga nai (ノ ゜Д゜)ノ ︵ 仕方がない"
314-
echo "-----------------------------------------------------------------"
315-
# Linux (amd64)
316-
echo "curl -L --fail --output $OUTPUT_DIR/linux/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_linux-amd64.zip"
317-
curl -L --fail --output $OUTPUT_DIR/linux/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_linux-amd64.zip
318-
# Linux (arm64)
319-
echo "curl -L --fail --output $OUTPUT_DIR/linux/arm64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_linux-arm64.zip"
320-
curl -L --fail --output $OUTPUT_DIR/linux/arm64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_linux-arm64.zip
321-
# Windows (amd64)
322-
echo "curl -L --fail --output $OUTPUT_DIR/windows/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_windows-amd64.zip"
323-
curl -L --fail --output $OUTPUT_DIR/windows/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_windows-amd64.zip
324-
# MacOS (amd64)
325-
echo "curl -L --fail --output $OUTPUT_DIR/darwin/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_macos-amd64.zip"
326-
curl -L --fail --output $OUTPUT_DIR/darwin/amd64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_macos-amd64.zip
327-
# MacOS (arm64)
328-
echo "curl -L --fail --output $OUTPUT_DIR/darwin/arm64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_macos-arm64.zip"
329-
curl -L --fail --output $OUTPUT_DIR/darwin/arm64/sgn.zip https://github.com/moloch--/sgn/releases/download/v$SGN_VER/sgn_macos-arm64.zip
330-
331312
# --- Cleanup ---
332313
echo -e "clean up: $WORK_DIR"
333314
rm -rf $WORK_DIR

go-tests.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ else
139139
exit 1
140140
fi
141141

142+
# server / sgn
143+
if go test -tags=server,$TAGS ./server/sgn ; then
144+
:
145+
else
146+
cat ~/.sliver/logs/sliver.log
147+
exit 1
148+
fi
149+
142150
# server / gogo
143151
if go test -tags=server,$TAGS ./server/gogo ; then
144152
:

go.mod

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ require (
3232
github.com/miekg/dns v1.1.68
3333
github.com/moloch--/asciicast v0.1.1
3434
github.com/moloch--/memmod v0.0.0-20230225130813-fd77d905589e
35+
github.com/moloch--/sgn v0.0.4
3536
github.com/ncruces/go-sqlite3 v0.29.1
3637
github.com/reeflective/console v0.1.25
3738
github.com/reeflective/readline v1.1.3
3839
github.com/rsteube/carapace v0.50.2
3940
github.com/sirupsen/logrus v1.9.3
4041
github.com/spf13/cobra v1.10.1
4142
github.com/spf13/pflag v1.0.10
42-
github.com/stretchr/testify v1.11.0
43+
github.com/stretchr/testify v1.11.1
4344
github.com/tetratelabs/wazero v1.9.0
4445
github.com/things-go/go-socks5 v0.1.0
4546
github.com/ulikunitz/xz v0.5.15
@@ -73,6 +74,7 @@ require (
7374
github.com/VirusTotal/vt-go v1.0.1 // indirect
7475
github.com/VividCortex/ewma v1.2.0 // indirect
7576
github.com/akutz/memconn v0.1.0 // indirect
77+
github.com/alecthomas/kong v0.8.1 // indirect
7678
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e // indirect
7779
github.com/awgh/cppgo v0.0.0-20210224085512-3d24bca8edc0 // indirect
7880
github.com/awgh/rawreader v0.0.0-20200626064944-56820a9c6da4 // indirect
@@ -90,6 +92,7 @@ require (
9092
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1 // indirect
9193
github.com/aws/aws-sdk-go-v2/service/sts v1.38.6 // indirect
9294
github.com/aws/smithy-go v1.23.0 // indirect
95+
github.com/briandowns/spinner v1.11.1 // indirect
9396
github.com/carapace-sh/carapace v1.9.0 // indirect
9497
github.com/carapace-sh/carapace-shlex v1.1.0 // indirect
9598
github.com/chromedp/sysutil v1.1.0 // indirect
@@ -141,8 +144,10 @@ require (
141144
github.com/mdlayher/socket v0.5.1 // indirect
142145
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
143146
github.com/mitchellh/go-ps v1.0.0 // indirect
147+
github.com/moloch--/go-keystone v0.0.2 // indirect
144148
github.com/ncruces/go-strftime v0.1.9 // indirect
145149
github.com/ncruces/julianday v1.0.0 // indirect
150+
github.com/olekukonko/tablewriter v0.0.5 // indirect
146151
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
147152
github.com/prometheus-community/pro-bing v0.4.0 // indirect
148153
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect

go.sum

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,14 @@ github.com/VividCortex/ewma v1.2.0/go.mod h1:nz4BbCtbLyFDeC9SUHbtcT5644juEuWfUAU
4444
github.com/akamensky/argparse v1.3.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
4545
github.com/akutz/memconn v0.1.0 h1:NawI0TORU4hcOMsMr11g7vwlCdkYeLKXBcxWu2W/P8A=
4646
github.com/akutz/memconn v0.1.0/go.mod h1:Jo8rI7m0NieZyLI5e2CDlRdRqRRB4S7Xp77ukDjH+Fw=
47+
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
48+
github.com/alecthomas/assert/v2 v2.1.0/go.mod h1:b/+1DI2Q6NckYi+3mXyH3wFb8qG37K/DuK80n7WefXA=
4749
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
4850
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
51+
github.com/alecthomas/kong v0.8.1 h1:acZdn3m4lLRobeh3Zi2S2EpnXTd1mOL6U7xVml+vfkY=
52+
github.com/alecthomas/kong v0.8.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U=
53+
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
54+
github.com/alecthomas/repr v0.1.0/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
4955
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e h1:4dAU9FXIyQktpoUAgOJK3OTFc/xug0PCXYCqU0FgDKI=
5056
github.com/alexbrainman/sspi v0.0.0-20250919150558-7d374ff0d59e/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
5157
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
@@ -83,6 +89,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.38.6/go.mod h1:WtKK+ppze5yKPkZ0XwqIV
8389
github.com/aws/smithy-go v1.23.0 h1:8n6I3gXzWJB2DxBDnfxgBaSX6oe0d/t10qGz7OKqMCE=
8490
github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
8591
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
92+
github.com/briandowns/spinner v1.11.1 h1:OixPqDEcX3juo5AjQZAnFPbeUA0jvkp2qzB5gOZJ/L0=
93+
github.com/briandowns/spinner v1.11.1/go.mod h1:QOuQk7x+EaDASo80FEXwlwiA+j/PPIcX3FScO+3/ZPQ=
8694
github.com/carapace-sh/carapace v1.9.0 h1:IuEP6YeeK4fhrH7MoOyL0I3GMhvROerkw6YGxkx8Fbw=
8795
github.com/carapace-sh/carapace v1.9.0/go.mod h1:Zs3DpsawpFm+8fEfRVYE9EzMBYH8u7S3Aw9yAAKX0JM=
8896
github.com/carapace-sh/carapace-shlex v1.1.0 h1:58QSJTUxghpa/rEn6+Z9UM/Hy0ipVHDUn9S1mp4i+ZE=
@@ -134,6 +142,7 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF
134142
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
135143
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
136144
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
145+
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
137146
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
138147
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
139148
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
@@ -212,6 +221,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
212221
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
213222
github.com/hdevalence/ed25519consensus v0.2.0 h1:37ICyZqdyj0lAZ8P4D1d1id3HqbbG1N3iBb1Tb4rdcU=
214223
github.com/hdevalence/ed25519consensus v0.2.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo=
224+
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
225+
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
215226
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
216227
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
217228
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
@@ -281,6 +292,7 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
281292
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
282293
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
283294
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
295+
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
284296
github.com/mattn/go-runewidth v0.0.19 h1:v++JhqYnZuu5jSKrk9RbgF5v4CGUjqRfBm05byFGLdw=
285297
github.com/mattn/go-runewidth v0.0.19/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
286298
github.com/mattn/go-sqlite3 v1.14.32 h1:JD12Ag3oLy1zQA+BNn74xRgaBbdhbNIDYvQUEuuErjs=
@@ -302,8 +314,12 @@ github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc
302314
github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg=
303315
github.com/moloch--/asciicast v0.1.1 h1:btwwniCK9br3ys33XZ71IG/M3ZujSSCcBzsH/sieiXg=
304316
github.com/moloch--/asciicast v0.1.1/go.mod h1:OckO16UDLgxVLclrCnbocL1ix15Br/8Xv/caBoYq98o=
317+
github.com/moloch--/go-keystone v0.0.2 h1:xThbYs45CSzoDUz5kBZxAyTPIpK3t5M7NB1x+NTTRL8=
318+
github.com/moloch--/go-keystone v0.0.2/go.mod h1:kpGRJpw9b7Eq3MluHrba+GPKZhSyDrvhLULSwH5nGGM=
305319
github.com/moloch--/memmod v0.0.0-20230225130813-fd77d905589e h1:IkFCPlAa0iTiLxck+NqAwBx8JDlnHYm4orOQBbs4BDQ=
306320
github.com/moloch--/memmod v0.0.0-20230225130813-fd77d905589e/go.mod h1:eYeI6cQ5YHhHt9i0BBW0zc1DaQnb4ZMXsSPuEV/V5Og=
321+
github.com/moloch--/sgn v0.0.4 h1:90IC5rx3TmPEfrqPnENB0yyiqcbcNk9LqezXx7uruF0=
322+
github.com/moloch--/sgn v0.0.4/go.mod h1:FyWfCtdynywgLmVR71vTJztZ3WkGSkR91Y4EOijUutE=
307323
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
308324
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
309325
github.com/ncruces/go-sqlite3 v0.29.1 h1:NIi8AISWBToRHyoz01FXiTNvU147Tqdibgj2tFzJCqM=
@@ -314,6 +330,8 @@ github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt
314330
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
315331
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
316332
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
333+
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
334+
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
317335
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
318336
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde h1:x0TT0RDC7UhAVbbWWBzr41ElhJx5tXPWkIHA2HWPRuw=
319337
github.com/orisano/pixelmatch v0.0.0-20220722002657-fb0b55479cde/go.mod h1:nZgzbfBr3hhjoZnS66nKrHmduYNpc34ny7RK4z5/HM0=
@@ -371,8 +389,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
371389
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
372390
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
373391
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
374-
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
375-
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
392+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
393+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
376394
github.com/tailscale/certstore v0.1.1-0.20231202035212-d3fa0460f47e h1:PtWT87weP5LWHEY//SWsYkSO3RWRZo4OSWagh3YD2vQ=
377395
github.com/tailscale/certstore v0.1.1-0.20231202035212-d3fa0460f47e/go.mod h1:XrBNfAFN+pwoWuksbFS9Ccxnopa15zJGgXRFN90l3K4=
378396
github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 h1:Gzfnfk2TWrk8Jj4P4c1a3CtQyMaTVCznlkLZI++hok4=

implant/sliver/handlers/handlers-wireguard.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ func wgStartPortfwdHandler(data []byte, resp RPCResponse) {
6969
RemoteAddr: fwder.RemoteAddr(),
7070
},
7171
}
72-
if err != nil {
73-
fwdResp.Response.Err = err.Error()
74-
}
7572
data, err = proto.Marshal(fwdResp)
7673
resp(data, err)
7774
}

server/generate/binaries_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ package generate
2020

2121
import (
2222
"fmt"
23+
"os"
2324
"testing"
2425

2526
"github.com/bishopfox/sliver/protobuf/clientpb"
2627
"github.com/bishopfox/sliver/server/certs"
2728
"github.com/bishopfox/sliver/server/configs"
29+
"github.com/bishopfox/sliver/server/sgn"
2830
)
2931

3032
var (
@@ -506,6 +508,52 @@ func multiLibrary(t *testing.T, goos string, goarch string, debug bool) {
506508
}
507509
}
508510

511+
func multiWindowsLibraryShellcode(t *testing.T, debug bool) {
512+
t.Logf("[multi] SHELLCODE windows/amd64 - debug: %v", debug)
513+
name := fmt.Sprintf("multilibrary_shellcode_test%d", nonce)
514+
config := &clientpb.ImplantConfig{
515+
GOOS: "windows",
516+
GOARCH: "amd64",
517+
518+
C2: []*clientpb.ImplantC2{
519+
{URL: "mtls://1.example.com"},
520+
{Priority: 2, URL: "mtls://2.example.com"},
521+
{URL: "https://3.example.com"},
522+
{URL: "dns://4.example.com", Options: "asdf"},
523+
},
524+
Debug: debug,
525+
ObfuscateSymbols: true,
526+
Format: clientpb.OutputFormat_SHELLCODE,
527+
IsSharedLib: true,
528+
Exports: []string{"FoobarW"},
529+
IncludeMTLS: true,
530+
IncludeHTTP: true,
531+
IncludeDNS: true,
532+
}
533+
httpC2Config := configs.GenerateDefaultHTTPC2Config()
534+
nonce++
535+
build, _ := GenerateConfig(name, config)
536+
binPath, err := SliverShellcode(name, build, config, httpC2Config.ImplantConfig)
537+
if err != nil {
538+
t.Fatalf("%v", err)
539+
}
540+
541+
// encode bin with sgn
542+
bin, err := os.ReadFile(binPath)
543+
if err != nil {
544+
t.Fatalf("reading generated shared lib shellcode failed: %v", err)
545+
}
546+
_, err = sgn.EncodeShellcodeWithConfig(bin, sgn.SGNConfig{
547+
Iterations: 1,
548+
PlainDecoder: false,
549+
Safe: true,
550+
MaxObfuscation: 100,
551+
})
552+
if err != nil {
553+
t.Fatalf("sgn encode failed: %v", err)
554+
}
555+
}
556+
509557
func symbolObfuscation(t *testing.T, goos string, goarch string) {
510558
t.Logf("[symbol obfuscation] %s/%s ...", goos, goarch)
511559
name := fmt.Sprintf("symbol_test%d", nonce)

server/sgn/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,41 @@ SGN (Sliver Guard Node) coordination and helpers. Implements SGN enrollment, mes
66

77
## Go Files
88

9-
- `sgn.go` – Implements SGN coordination logic and message handling.
9+
- `sgn.go` – Implements SGN coordination logic and message handling, including the Shikata Ga Nai encoder helpers.
10+
- `sgn_test.go` – Unit tests covering SGN configuration wiring and helper utilities.
11+
12+
## SGN Encoder Helpers
13+
14+
The server helper wraps the [`github.com/moloch--/sgn`](https://github.com/moloch--/sgn) encoder and exposes a simple `SGNConfig` with the following knobs:
15+
16+
- `Architecture``386`/`amd64` (case-insensitive) selection passed to `sgn.NewEncoder`.
17+
- `Iterations` – number of encode passes mapped to `Encoder.EncodingCount`.
18+
- `MaxObfuscation` – byte budget forwarded to `Encoder.ObfuscationLimit`.
19+
- `PlainDecoder` – keep the decoder stub in clear text.
20+
- `Safe` – enable register preservation via `Encoder.SaveRegisters`.
21+
- `BadChars` / `Asci` – optional post-processing filters that brute force new seeds until constraints pass.
22+
23+
These options mirror the upstream CLI flags so server-side tasks can reuse the same behavior.
24+
25+
## Test Fixtures
26+
27+
Shellcode fixtures used by the unit tests live under `testdata/` with a `.bin` extension. They are produced via `msfvenom` using a dedicated Go generator:
28+
29+
```bash
30+
go generate ./server/sgn
31+
```
32+
33+
The generator invokes `msfvenom` three times (reverse TCP/HTTP stagers and an exec payload) and writes raw shellcode into the `testdata` directory. Ensure the Metasploit framework is installed and `msfvenom` is on `$PATH` before running the generation step.
34+
35+
## Testing
36+
37+
The log subsystem expects a writable Sliver root directory. Point it to a temporary location when running tests:
38+
39+
```bash
40+
export SLIVER_ROOT_DIR=$(pwd)/.tmp-sliver
41+
export GOCACHE=$(pwd)/.tmp-gocache
42+
mkdir -p "$SLIVER_ROOT_DIR" "$GOCACHE"
43+
go test ./server/sgn
44+
```
45+
46+
The test suite focuses on option wiring and constraint helpers rather than the full stochastic encoding pipeline.

0 commit comments

Comments
 (0)