Skip to content

Commit

Permalink
create vendor dir for implants and script to update it
Browse files Browse the repository at this point in the history
  • Loading branch information
capnspacehook committed Jul 23, 2022
1 parent d94c596 commit 8c8dd28
Show file tree
Hide file tree
Showing 1,519 changed files with 454,342 additions and 44 deletions.
3 changes: 3 additions & 0 deletions implant/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package implant

//go:generate ./scripts/update-vendor.sh
53 changes: 35 additions & 18 deletions implant/go-mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@ module github.com/bishopfox/sliver
go 1.17

require (
github.com/Binject/universal v0.0.0-20210304094126-daefaa886313
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 // indirect
github.com/gofrs/uuid v4.0.0+incompatible
github.com/kbinani/screenshot v0.0.0-20191211154542-3a185f1ce18f
github.com/lesnuages/go-winio v0.4.19
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/pquerna/otp v1.3.0
github.com/stretchr/testify v1.7.0
golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22
golang.zx2c4.com/wireguard v0.0.0-20220316235147-5aff28b14c24
golang.zx2c4.com/wireguard/windows v0.5.1
gvisor.dev/gvisor v0.0.0-20211020211948-f76a604701b6
google.golang.org/protobuf v1.23.0
github.com/things-go/go-socks5 v0.0.3-0.20210722055343-24af464efe43
github.com/Binject/universal v0.0.0-20210304094126-daefaa886313
github.com/gofrs/uuid v4.0.0+incompatible
github.com/kbinani/screenshot v0.0.0-20191211154542-3a185f1ce18f
github.com/lesnuages/go-winio v0.4.19
github.com/miekg/dns v1.1.50
github.com/moloch--/memmod v0.0.0-20211120144554-8b37cc654945
github.com/pquerna/otp v1.3.0
github.com/stretchr/testify v1.7.0
github.com/things-go/go-socks5 v0.0.3-0.20210722055343-24af464efe43
golang.org/x/crypto v0.0.0-20220315160706-3147a52a75dd
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
golang.org/x/sys v0.0.0-20220315194320-039c03cc5b86
golang.zx2c4.com/wireguard v0.0.0-20220316235147-5aff28b14c24
google.golang.org/protobuf v1.26.0
gvisor.dev/gvisor v0.0.0-20211020211948-f76a604701b6
)

require (
github.com/Binject/debug v0.0.0-20210225042342-c9b8b45728d2 // indirect
github.com/BurntSushi/xgb v0.0.0-20210121224620-deaf085860bc // indirect
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/awgh/cppgo v0.0.0-20210224085512-3d24bca8edc0 // indirect
github.com/awgh/rawreader v0.0.0-20200626064944-56820a9c6da4 // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gen2brain/shm v0.0.0-20200228170931-49f9650110c5 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/lxn/win v0.0.0-20210218163916-a377121e959e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
golang.org/x/tools v0.1.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
977 changes: 958 additions & 19 deletions implant/go-sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions implant/implant.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ var (
// GoSum - Templated go.sum module file for implant builds
//go:embed go-sum
GoSum string

// Vendor - Embedded FS access to vendored sliver implant dependencies
//go:embed vendor/**
Vendor embed.FS
)
95 changes: 95 additions & 0 deletions implant/scripts/update-vendor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package main

import (
"bytes"
"fmt"
"go/parser"
"go/token"
"io/fs"
"os"
"path/filepath"
"strings"
)

// These are the directories imports will be taken from. If the implant
// needs files outside of these dirs in the future, add the dirs to this
// slice.
var srcDirs = []string{
"../sliver",
"../../protobuf/commonpb",
"../../protobuf/dnspb",
"../../protobuf/sliverpb",
}

func fatalf(format string, a ...interface{}) {
panic(fmt.Sprintf(format, a...))
}

func getImports(imports map[string]struct{}, dir string) error {
fset := token.NewFileSet()
return filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}

if d.IsDir() {
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}

file, err := parser.ParseFile(fset, path, nil, parser.ImportsOnly)
if err != nil {
return err
}

for _, imp := range file.Imports {
impPath := strings.ToLower(imp.Path.Value)
// skip local packages, those shouldn't be vendored
if strings.HasPrefix(impPath, `"github.com/bishopfox/sliver`) {
continue
}

imports[imp.Path.Value] = struct{}{}
}

return nil
})
}

func main() {
if len(os.Args) < 2 {
fatalf("expected temporary directory argument")
}

dir := os.Args[1]
imports := make(map[string]struct{})

// Parse Go files and build a unique list of all their 3rd party
// imports so we can build a vendor dir from them. Stdlib packages
// will be included as well but 'go mod vendor' will ignore them.
for _, srcDir := range srcDirs {
err := getImports(imports, srcDir)
if err != nil {
fatalf("error walking directory: %v", err)
}
}

// Create a Go source file containing only import statements of all
// the packages an implant might need, no matter what OS, transport,
// etc is configured.
var buf bytes.Buffer
buf.WriteString("package sliver\n\nimport (\n")
for imp := range imports {
buf.WriteString("\t _ ")
buf.WriteString(imp)
buf.WriteByte('\n')
}
buf.WriteString(")\n")

err := os.WriteFile(filepath.Join(dir, "imports.go"), buf.Bytes(), 0660)
if err != nil {
fatalf("error creating file: %v", err)
}
}
27 changes: 27 additions & 0 deletions implant/scripts/update-vendor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

set -e

# we are expecting from run from sliver/implant via 'go generate'
cd scripts

# copy Go module related files
pwd="$(pwd)"
tempDir="$(mktemp -d -p $pwd)"
cp ../go-mod "${tempDir}/go.mod"
cp ../go-sum "${tempDir}/go.sum"
mv ../vendor "${tempDir}/vendor"

# build Go file with all imported packages
go run update-vendor.go "$tempDir"
cd "$tempDir"
# update vendor dir
go mod tidy -compat=1.17
go mod vendor

# move updated files back
mv "${tempDir}/vendor" ../../vendor
mv "${tempDir}/go.mod" ../../go-mod
mv "${tempDir}/go.sum" ../../go-sum
cd ..
rm -rf "$tempDir"
27 changes: 27 additions & 0 deletions implant/vendor/github.com/Binject/debug/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8c8dd28

Please sign in to comment.