Skip to content

Commit

Permalink
add ECCPublicKeyDigest to protobuf and database
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBF committed May 30, 2023
1 parent a6ba863 commit 429c520
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
7 changes: 4 additions & 3 deletions protobuf/clientpb/client.pb.go

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

13 changes: 4 additions & 9 deletions server/c2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/bishopfox/sliver/server/certs"
"github.com/bishopfox/sliver/server/configs"
"github.com/bishopfox/sliver/server/core"
"github.com/bishopfox/sliver/server/cryptography"
"github.com/bishopfox/sliver/server/db"
Expand Down Expand Up @@ -144,7 +143,7 @@ type SliverHTTPC2 struct {
SliverStage []byte // Sliver shellcode to serve during staging process
Cleanup func()

c2Config *configs.HTTPC2Config // C2 config (from config file)
c2Config *clientpb.HTTPC2Config // C2 config (from config file)
}

func (s *SliverHTTPC2) getServerHeader() string {
Expand All @@ -160,15 +159,11 @@ func (s *SliverHTTPC2) getServerHeader() string {
}

func (s *SliverHTTPC2) getCookieName() string {
cookies := s.getHTTPC2Config().ServerConfig.Cookies
cookies := s.c2Config.ServerConfig.Cookies
index := insecureRand.Intn(len(cookies))
return cookies[index].Name
}

func (s *SliverHTTPC2) getHTTPC2Config() *clientpb.HTTPC2Config {
return nil
}

// StartHTTPListener - Start an HTTP(S) listener, this can be used to start both
//
// HTTP/HTTPS depending on the caller's conf
Expand Down Expand Up @@ -359,6 +354,7 @@ func (s *SliverHTTPC2) loadServerHTTPC2Configs() []*models.HttpC2Config {
func (s *SliverHTTPC2) router() *mux.Router {
router := mux.NewRouter()
c2Configs := s.loadServerHTTPC2Configs()
s.c2Config = c2Configs[0].ToProtobuf()
if s.ServerConf.MaxRequestLength < 1024 {
s.ServerConf.MaxRequestLength = DefaultMaxBodyLength
}
Expand All @@ -371,7 +367,6 @@ func (s *SliverHTTPC2) router() *mux.Router {

httpLog.Debugf("HTTP C2 Implant Config = %v", c2Config.ImplantConfig)
httpLog.Debugf("HTTP C2 Server Config = %v", c2Config.ServerConfig)
fmt.Println(c2Config.Name)
// Start Session Handler
router.HandleFunc(
fmt.Sprintf("/{rpath:.*\\.%s$}", c2Config.ImplantConfig.StartSessionFileExtension),
Expand Down Expand Up @@ -521,7 +516,7 @@ func (s *SliverHTTPC2) DefaultRespHeaders(next http.Handler) http.Handler {
for _, header := range s.c2Config.ServerConfig.Headers {
if 0 < header.Probability && header.Probability < 100 {
roll := insecureRand.Intn(99) + 1
if header.Probability < roll {
if header.Probability < int32(roll) {
continue
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/db/models/implant.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func (ic *ImplantConfig) ToProtobuf() *clientpb.ImplantConfig {
ECCServerPublicKey: ic.ECCServerPublicKey,
ECCPublicKey: ic.ECCPublicKey,
ECCPrivateKey: ic.ECCPrivateKey,
ECCPublicKeyDigest: ic.ECCPublicKeyDigest,
MtlsCACert: ic.MtlsCACert,
MtlsCert: ic.MtlsCert,
MtlsKey: ic.MtlsKey,
Expand Down Expand Up @@ -340,6 +341,7 @@ func ImplantConfigFromProtobuf(pbConfig *clientpb.ImplantConfig) *ImplantConfig
cfg.ECCServerPublicKey = pbConfig.ECCServerPublicKey
cfg.ECCPrivateKey = pbConfig.ECCPrivateKey
cfg.ECCPublicKey = pbConfig.ECCPublicKey
cfg.ECCPublicKeyDigest = pbConfig.ECCPublicKeyDigest

cfg.GOOS = pbConfig.GOOS
cfg.GOARCH = pbConfig.GOARCH
Expand Down
6 changes: 4 additions & 2 deletions server/generate/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ package generate

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"fmt"
"io/fs"
insecureRand "math/rand"
Expand Down Expand Up @@ -678,9 +680,9 @@ func GenerateConfig(implantConfig *clientpb.ImplantConfig, save bool) (*clientpb
return nil, err
}
serverKeyPair := cryptography.ECCServerKeyPair()
// digest := sha256.Sum256((*implantKeyPair.Public)[:])
digest := sha256.Sum256((*implantKeyPair.Public)[:])
implantConfig.ECCPublicKey = implantKeyPair.PublicBase64()
// config.ECCPublicKeyDigest = hex.EncodeToString(digest[:])
implantConfig.ECCPublicKeyDigest = hex.EncodeToString(digest[:])
implantConfig.ECCPrivateKey = implantKeyPair.PrivateBase64()
implantConfig.ECCPublicKeySignature = cryptography.MinisignServerSign(implantKeyPair.Public[:])
implantConfig.ECCServerPublicKey = serverKeyPair.PublicBase64()
Expand Down

0 comments on commit 429c520

Please sign in to comment.