Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Jun 20, 2023
1 parent 4da5dea commit dd98134
Show file tree
Hide file tree
Showing 15 changed files with 1,366 additions and 1,365 deletions.
8 changes: 4 additions & 4 deletions implant/sliver/cryptography/implant.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (

var (
// PeerAgePublicKey - The implant's age public key
PeerAgePublicKey = "{{.Config.ECCPublicKey}}"
PeerAgePublicKey = "{{.Config.PeerPublicKey}}"
// peerPrivateKey - The implant's age private key
peerAgePrivateKey = "{{.Config.ECCPrivateKey}}"
peerAgePrivateKey = "{{.Config.PeerPrivateKey}}"
// PublicKeySignature - The implant's age public key minisigned'd
PeerAgePublicKeySignature = `{{.Config.ECCPublicKeySignature}}`
PeerAgePublicKeySignature = `{{.Config.PeerPublicKeySignature}}`
// serverPublicKey - Server's ECC public key
serverAgePublicKey = "{{.Config.ECCServerPublicKey}}"
serverAgePublicKey = "{{.Config.AgeServerPublicKey}}"
// serverMinisignPublicKey - The server's minisign public key
serverMinisignPublicKey = `{{.Config.MinisignServerPublicKey}}`

Expand Down
2,649 changes: 1,325 additions & 1,324 deletions protobuf/clientpb/client.pb.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions protobuf/clientpb/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ message ImplantConfig {
string MtlsCert = 21;
string MtlsKey = 22;

string ECCServerPublicKey = 23;
string ECCPublicKey = 24;
string ECCPrivateKey = 25;
string ECCPublicKeySignature = 26;
string AgeServerPublicKey = 23;
string PeerPublicKey = 24;
string PeerPrivateKey = 25;
string PeerPublicKeySignature = 26;
string MinisignServerPublicKey = 27;

string WGImplantPrivKey = 30;
Expand Down
4 changes: 2 additions & 2 deletions protobuf/commonpb/common.pb.go

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

4 changes: 2 additions & 2 deletions protobuf/dnspb/dns.pb.go

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

4 changes: 2 additions & 2 deletions protobuf/rpcpb/services.pb.go

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

2 changes: 1 addition & 1 deletion protobuf/rpcpb/services_grpc.pb.go

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

4 changes: 2 additions & 2 deletions protobuf/sliverpb/sliver.pb.go

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

8 changes: 4 additions & 4 deletions server/c2/c2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ func setup() *models.ImplantConfig {
publicKeyDigest := hex.EncodeToString(digest.Sum(nil))

implantConfig := &models.ImplantConfig{
ECCPublicKey: peerAgeKeyPair.Public,
ECCPublicKeyDigest: publicKeyDigest,
ECCPrivateKey: peerAgeKeyPair.Private,
PeerPublicKey: peerAgeKeyPair.Public,
PeerPublicKeyDigest: publicKeyDigest,
PeerPrivateKey: peerAgeKeyPair.Private,

ECCServerPublicKey: serverAgeKeyPair.Public,
AgeServerPublicKey: serverAgeKeyPair.Public,
}
err = db.Session().Create(implantConfig).Error
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/c2/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func (s *SliverDNSServer) handleDNSSessionInit(domain string, msg *dnspb.DNSMess
}

serverKeyPair := cryptography.AgeServerKeyPair()
sessionInit, err := cryptography.AgeKeyExFromImplant(serverKeyPair.Private, implantConfig.ECCPrivateKey, msg.Data[32:])
sessionInit, err := cryptography.AgeKeyExFromImplant(serverKeyPair.Private, implantConfig.PeerPrivateKey, msg.Data[32:])
if err != nil {
dnsLog.Errorf("[session init] error decrypting session init data: %s", err)
return s.refusedErrorResp(req)
Expand Down
2 changes: 1 addition & 1 deletion server/c2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (s *SliverHTTPC2) startSessionHandler(resp http.ResponseWriter, req *http.R
}

serverKeyPair := cryptography.AgeServerKeyPair()
sessionInitData, err := cryptography.AgeKeyExFromImplant(serverKeyPair.Private, implantConfig.ECCPrivateKey, data[32:])
sessionInitData, err := cryptography.AgeKeyExFromImplant(serverKeyPair.Private, implantConfig.PeerPrivateKey, data[32:])
if err != nil {
httpLog.Error("age key exchange decryption failed")
s.defaultHandler(resp, req)
Expand Down
2 changes: 1 addition & 1 deletion server/db/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func ImplantConfigWithC2sByID(id string) (*models.ImplantConfig, error) {
func ImplantConfigByECCPublicKeyDigest(publicKeyDigest [32]byte) (*models.ImplantConfig, error) {
config := models.ImplantConfig{}
err := Session().Where(&models.ImplantConfig{
ECCPublicKeyDigest: hex.EncodeToString(publicKeyDigest[:]),
PeerPublicKeyDigest: hex.EncodeToString(publicKeyDigest[:]),
}).First(&config).Error
if err != nil {
return nil, err
Expand Down
16 changes: 8 additions & 8 deletions server/db/models/implant.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ type ImplantConfig struct {
BeaconJitter int64

// ECC
ECCPublicKey string
ECCPublicKeyDigest string
ECCPrivateKey string
ECCPublicKeySignature string
ECCServerPublicKey string
PeerPublicKey string
PeerPublicKeyDigest string
PeerPrivateKey string
PeerPublicKeySignature string
AgeServerPublicKey string
MinisignServerPublicKey string

// MTLS
Expand Down Expand Up @@ -159,9 +159,9 @@ func (ic *ImplantConfig) ToProtobuf() *clientpb.ImplantConfig {

GOOS: ic.GOOS,
GOARCH: ic.GOARCH,
ECCServerPublicKey: ic.ECCServerPublicKey,
ECCPublicKey: ic.ECCPublicKey,
ECCPrivateKey: ic.ECCPrivateKey,
AgeServerPublicKey: ic.AgeServerPublicKey,
PeerPublicKey: ic.PeerPublicKey,
PeerPrivateKey: ic.PeerPrivateKey,
MtlsCACert: ic.MtlsCACert,
MtlsCert: ic.MtlsCert,
MtlsKey: ic.MtlsKey,
Expand Down
16 changes: 8 additions & 8 deletions server/generate/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func ImplantConfigFromProtobuf(pbConfig *clientpb.ImplantConfig) (string, *model
cfg.BeaconInterval = pbConfig.BeaconInterval
cfg.BeaconJitter = pbConfig.BeaconJitter

cfg.ECCServerPublicKey = pbConfig.ECCServerPublicKey
cfg.ECCPrivateKey = pbConfig.ECCPrivateKey
cfg.ECCPublicKey = pbConfig.ECCPublicKey
cfg.AgeServerPublicKey = pbConfig.AgeServerPublicKey
cfg.PeerPrivateKey = pbConfig.PeerPrivateKey
cfg.PeerPublicKey = pbConfig.PeerPublicKey

cfg.GOOS = pbConfig.GOOS
cfg.GOARCH = pbConfig.GOARCH
Expand Down Expand Up @@ -777,11 +777,11 @@ func GenerateConfig(name string, config *models.ImplantConfig, save bool) error
}
serverKeyPair := cryptography.AgeServerKeyPair()
digest := sha256.Sum256([]byte(implantKeyPair.Public))
config.ECCPublicKey = implantKeyPair.Public
config.ECCPublicKeyDigest = hex.EncodeToString(digest[:])
config.ECCPrivateKey = implantKeyPair.Private
config.ECCPublicKeySignature = cryptography.MinisignServerSign([]byte(implantKeyPair.Public))
config.ECCServerPublicKey = serverKeyPair.Public
config.PeerPublicKey = implantKeyPair.Public
config.PeerPublicKeyDigest = hex.EncodeToString(digest[:])
config.PeerPrivateKey = implantKeyPair.Private
config.PeerPublicKeySignature = cryptography.MinisignServerSign([]byte(implantKeyPair.Public))
config.AgeServerPublicKey = serverKeyPair.Public
config.MinisignServerPublicKey = cryptography.MinisignServerPublicKey()

// MTLS keys
Expand Down
2 changes: 1 addition & 1 deletion server/handlers/pivot.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func serverKeyExchange(implantConn *core.ImplantConnection, peerEnvelope *sliver
pivotLog.Warn("Unknown public key digest")
return nil
}
publicKey, err := base64.RawStdEncoding.DecodeString(implantConfig.ECCPublicKey)
publicKey, err := base64.RawStdEncoding.DecodeString(implantConfig.PeerPublicKey)
if err != nil || len(publicKey) != 32 {
pivotLog.Warn("Failed to decode public key")
return nil
Expand Down

0 comments on commit dd98134

Please sign in to comment.