Skip to content

Commit

Permalink
Merge pull request #209 from BishopFox/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
moloch-- authored Jun 8, 2020
2 parents 5931bf8 + 71d7349 commit 3904c41
Show file tree
Hide file tree
Showing 24 changed files with 63 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 9 additions & 6 deletions client/command/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package command
*/

import (
"bytes"
"context"
"fmt"
"io/ioutil"
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions go-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,34 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.


## 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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 1 addition & 1 deletion server/c2/tcp-http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions server/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ var rootCmd = &cobra.Command{
logFile := initLogging(appDir)
defer logFile.Close()

assets.Setup(false)
certs.SetupCAs()

serverConfig := configs.GetServerConfig()
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 0 additions & 26 deletions util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ package util
*/

import (
"bytes"
"compress/gzip"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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
}
42 changes: 33 additions & 9 deletions util/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ package util
import (
"bytes"
"crypto/rand"
"fmt"
"io/ioutil"
"os"
"testing"
)

Expand All @@ -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))
}

}

0 comments on commit 3904c41

Please sign in to comment.