diff --git a/Makefile b/Makefile index d92ad60e9b..18644ac0e0 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ endif # # Version Information # -VERSION = 1.0.2 +VERSION = 1.0.3 COMPILED_AT = $(shell date +%s) RELEASES_URL = https://api.github.com/repos/BishopFox/sliver/releases PKG = github.com/bishopfox/sliver/client/version diff --git a/client/command/filesystem.go b/client/command/filesystem.go index c9321c718e..f97b37b1fb 100644 --- a/client/command/filesystem.go +++ b/client/command/filesystem.go @@ -19,7 +19,6 @@ package command */ import ( - "bytes" "context" "fmt" "io/ioutil" @@ -33,6 +32,7 @@ import ( "github.com/bishopfox/sliver/protobuf/rpcpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + "github.com/bishopfox/sliver/util/encoders" "gopkg.in/AlecAivazis/survey.v1" "github.com/desertbit/grumble" @@ -176,7 +176,7 @@ func cat(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) { return } if download.Encoder == "gzip" { - download.Data, err = new(util.Gzip).Decode(download.Data) + download.Data, err = new(encoders.Gzip).Decode(download.Data) if err != nil { fmt.Printf(Warn+"%s\n", err) return @@ -234,7 +234,11 @@ func download(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) { } if download.Encoder == "gzip" { - download.Data, _ = new(util.Gzip).Decode(download.Data) + download.Data, err = new(encoders.Gzip).Decode(download.Data) + if err != nil { + fmt.Printf(Warn+"Decoding failed %s", err) + return + } } dstFile, err := os.Create(dst) if err != nil { @@ -275,15 +279,14 @@ func upload(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) { dst := ctx.Args[1] fileBuf, err := ioutil.ReadFile(src) - uploadGzip := bytes.NewBuffer([]byte{}) - new(util.Gzip).Encode(uploadGzip, fileBuf) + uploadGzip := new(encoders.Gzip).Encode(fileBuf) ctrl := make(chan bool) go spin.Until(fmt.Sprintf("%s -> %s", src, dst), ctrl) upload, err := rpc.Upload(context.Background(), &sliverpb.UploadReq{ Request: ActiveSession.Request(ctx), Path: dst, - Data: uploadGzip.Bytes(), + Data: uploadGzip, Encoder: "gzip", }) ctrl <- true diff --git a/go-tests.sh b/go-tests.sh index 2686062f87..9860720e07 100755 --- a/go-tests.sh +++ b/go-tests.sh @@ -18,25 +18,34 @@ # along with this program. If not, see . -## Server -# server / db -if go test ./server/db ; then +## Util + +# util +if go test ./util ; then : else - cat ~/.sliver/logs/sliver.log exit 1 fi -# server / certs -if go test ./server/certs ; then +# util / encoders +if go test ./util/encoders ; then + : +else + exit 1 +fi + +## Server + +# server / db +if go test ./server/db ; then : else cat ~/.sliver/logs/sliver.log exit 1 fi -# server / encoders -if go test ./server/encoders ; then +# server / certs +if go test ./server/certs ; then : else cat ~/.sliver/logs/sliver.log diff --git a/go.sum b/go.sum index 517bc33937..4140365689 100644 --- a/go.sum +++ b/go.sum @@ -120,6 +120,7 @@ github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174 h1:WlZsjVhE8Af9IcZDG github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c h1:kp3AxgXgDOmIJFR7bIwqFhwJ2qWar8tEQSE5XXhCfVk= github.com/hinshun/vt10x v0.0.0-20180809195222-d55458df857c/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A= +github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc= github.com/jmespath/go-jmespath v0.3.0/go.mod h1:9QtRXoHjLGCJ5IBSaohpXITPlowMeeYCZ7fLUTSywik= diff --git a/server/c2/tcp-http.go b/server/c2/tcp-http.go index 5bec534a6f..5eb96664a2 100644 --- a/server/c2/tcp-http.go +++ b/server/c2/tcp-http.go @@ -41,10 +41,10 @@ import ( "github.com/bishopfox/sliver/server/certs" "github.com/bishopfox/sliver/server/core" "github.com/bishopfox/sliver/server/cryptography" - "github.com/bishopfox/sliver/server/encoders" sliverHandlers "github.com/bishopfox/sliver/server/handlers" "github.com/bishopfox/sliver/server/log" "github.com/bishopfox/sliver/server/website" + "github.com/bishopfox/sliver/util/encoders" "github.com/golang/protobuf/proto" "github.com/gorilla/mux" diff --git a/server/cli/cli.go b/server/cli/cli.go index 8c005a756c..70e196c584 100644 --- a/server/cli/cli.go +++ b/server/cli/cli.go @@ -108,6 +108,7 @@ var rootCmd = &cobra.Command{ logFile := initLogging(appDir) defer logFile.Close() + assets.Setup(false) certs.SetupCAs() serverConfig := configs.GetServerConfig() diff --git a/server/encoders/README.md b/util/encoders/README.md similarity index 100% rename from server/encoders/README.md rename to util/encoders/README.md diff --git a/server/encoders/base64.go b/util/encoders/base64.go similarity index 100% rename from server/encoders/base64.go rename to util/encoders/base64.go diff --git a/server/encoders/base64_test.go b/util/encoders/base64_test.go similarity index 100% rename from server/encoders/base64_test.go rename to util/encoders/base64_test.go diff --git a/server/encoders/combos.go b/util/encoders/combos.go similarity index 100% rename from server/encoders/combos.go rename to util/encoders/combos.go diff --git a/server/encoders/combos_test.go b/util/encoders/combos_test.go similarity index 100% rename from server/encoders/combos_test.go rename to util/encoders/combos_test.go diff --git a/server/encoders/encoders.go b/util/encoders/encoders.go similarity index 100% rename from server/encoders/encoders.go rename to util/encoders/encoders.go diff --git a/server/encoders/encoders_test.go b/util/encoders/encoders_test.go similarity index 100% rename from server/encoders/encoders_test.go rename to util/encoders/encoders_test.go diff --git a/server/encoders/english-words.go b/util/encoders/english-words.go similarity index 100% rename from server/encoders/english-words.go rename to util/encoders/english-words.go diff --git a/server/encoders/english.go b/util/encoders/english.go similarity index 100% rename from server/encoders/english.go rename to util/encoders/english.go diff --git a/server/encoders/english_test.go b/util/encoders/english_test.go similarity index 100% rename from server/encoders/english_test.go rename to util/encoders/english_test.go diff --git a/server/encoders/gzip.go b/util/encoders/gzip.go similarity index 100% rename from server/encoders/gzip.go rename to util/encoders/gzip.go diff --git a/server/encoders/gzip_test.go b/util/encoders/gzip_test.go similarity index 100% rename from server/encoders/gzip_test.go rename to util/encoders/gzip_test.go diff --git a/server/encoders/hex.go b/util/encoders/hex.go similarity index 100% rename from server/encoders/hex.go rename to util/encoders/hex.go diff --git a/server/encoders/hex_test.go b/util/encoders/hex_test.go similarity index 100% rename from server/encoders/hex_test.go rename to util/encoders/hex_test.go diff --git a/server/encoders/images.go b/util/encoders/images.go similarity index 100% rename from server/encoders/images.go rename to util/encoders/images.go diff --git a/server/encoders/images_test.go b/util/encoders/images_test.go similarity index 100% rename from server/encoders/images_test.go rename to util/encoders/images_test.go diff --git a/util/files.go b/util/files.go index d0d7014da1..3603c47b45 100644 --- a/util/files.go +++ b/util/files.go @@ -19,10 +19,7 @@ package util */ import ( - "bytes" - "compress/gzip" "fmt" - "io" "io/ioutil" "os" "path/filepath" @@ -74,26 +71,3 @@ func ByteCountBinary(b int64) string { } return fmt.Sprintf("%.1f %ciB", float64(b)/float64(div), "KMGTPE"[exp]) } - -// Gzip - Gzip compression encoder -type Gzip struct{} - -// Encode - Compress data with gzip -func (g Gzip) Encode(w io.Writer, data []byte) error { - gw, _ := gzip.NewWriterLevel(w, gzip.BestSpeed) - defer gw.Close() - _, err := gw.Write(data) - return err -} - -// Decode - Uncompressed data with gzip -func (g Gzip) Decode(data []byte) ([]byte, error) { - bytes.NewReader(data) - reader, _ := gzip.NewReader(bytes.NewReader(data)) - var buf bytes.Buffer - _, err := buf.ReadFrom(reader) - if err != nil { - return nil, err - } - return buf.Bytes(), nil -} diff --git a/util/files_test.go b/util/files_test.go index 99f41d09a9..f54d62a8e9 100644 --- a/util/files_test.go +++ b/util/files_test.go @@ -21,6 +21,9 @@ package util import ( "bytes" "crypto/rand" + "fmt" + "io/ioutil" + "os" "testing" ) @@ -30,17 +33,38 @@ func randomData() []byte { return buf } -func TestGzip(t *testing.T) { +func TestCopyFileContents(t *testing.T) { sample := randomData() - gzipData := bytes.NewBuffer([]byte{}) - gz := new(Gzip) - gz.Encode(gzipData, sample) - data, err := gz.Decode(gzipData.Bytes()) + tmpfile, err := ioutil.TempFile("", "sliver-unit-test") if err != nil { - t.Errorf("gzip decode returned an error %v", err) - return + t.Error(err) } - if !bytes.Equal(sample, data) { - t.Errorf("sample does not match returned\n%#v != %#v", sample, data) + defer os.Remove(tmpfile.Name()) // clean up + if _, err := tmpfile.Write(sample); err != nil { + t.Error(err) } + err = tmpfile.Close() + if err != nil { + t.Error(err) + } + + dst := fmt.Sprintf("%s.2", tmpfile.Name()) + CopyFileContents(tmpfile.Name(), dst) + + srcData, err := ioutil.ReadFile(tmpfile.Name()) + if err != nil { + t.Error(err) + } + dstData, err := ioutil.ReadFile(dst) + if err != nil { + t.Error(err) + } + + if !bytes.Equal(sample, srcData) { + t.Error(fmt.Errorf("Sample and src do not match:\nsample: %v\n src: %v", sample, srcData)) + } + if !bytes.Equal(dstData, srcData) { + t.Error(fmt.Errorf("dst and src do not match:\ndst: %v\nsrc: %v", dstData, srcData)) + } + }