Skip to content

Commit

Permalink
Add option to log TLS info so packets can be decoded with wireshark
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgol committed Sep 14, 2022
1 parent 70b0667 commit a2673f7
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/c2/http.go
Expand Up @@ -245,9 +245,13 @@ func getHTTPTLSConfig(conf *HTTPServerConfig) *tls.Config {
httpLog.Errorf("Failed to parse tls cert/key pair %s", err)
return nil
}
return &tls.Config{
tlsConfig := &tls.Config{
Certificates: []tls.Certificate{cert},
}
if certs.TLSKeyLogger != nil {
tlsConfig.KeyLogWriter = certs.TLSKeyLogger
}
return tlsConfig
}

func (s *SliverHTTPC2) router() *mux.Router {
Expand Down
3 changes: 3 additions & 0 deletions server/c2/jobs.go
Expand Up @@ -429,6 +429,9 @@ func listenAndServeTLS(srv *http.Server, certPEMBlock, keyPEMBlock []byte) error
if srv.TLSConfig != nil {
*config = *srv.TLSConfig
}
if certs.TLSKeyLogger != nil {
config.KeyLogWriter = certs.TLSKeyLogger
}
if config.NextProtos == nil {
config.NextProtos = []string{"http/1.1"}
}
Expand Down
3 changes: 3 additions & 0 deletions server/c2/mtls.go
Expand Up @@ -220,5 +220,8 @@ func getServerTLSConfig(host string) *tls.Config {
Certificates: []tls.Certificate{cert},
MinVersion: tls.VersionTLS13, // Force TLS v1.3
}
if certs.TLSKeyLogger != nil {
tlsConfig.KeyLogWriter = certs.TLSKeyLogger
}
return tlsConfig
}
50 changes: 50 additions & 0 deletions server/certs/tlskeys.go
@@ -0,0 +1,50 @@
package certs

/*
Sliver Implant Framework
Copyright (C) 2019 Bishop Fox
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"fmt"
"os"
"path/filepath"
"github.com/bishopfox/sliver/server/configs"
"github.com/bishopfox/sliver/server/log"
)

const (
keyFileName = "tls.keys"
)

var (
// TLSKeyLogger - File descriptor for logging TLS keys
TLSKeyLogger = newKeyLogger()
)

func newKeyLogger() *os.File {
serverConfig := configs.GetServerConfig()
if serverConfig.Logs.TLSKeyLogger {
keyFilePath := filepath.Join(log.GetLogDir(), keyFileName)
keyFile, err := os.OpenFile(keyFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
certsLog.Errorf(fmt.Sprintf("Failed to open TLS key file %v", err))
return nil
}
return keyFile
}
return nil
}
1 change: 1 addition & 0 deletions server/configs/server.go
Expand Up @@ -53,6 +53,7 @@ type LogConfig struct {
Level int `json:"level"`
GRPCUnaryPayloads bool `json:"grpc_unary_payloads"`
GRPCStreamPayloads bool `json:"grpc_stream_payloads"`
TLSKeyLogger bool `json:"tls_key_logger"`
}

// DaemonConfig - Configure daemon mode
Expand Down
4 changes: 4 additions & 0 deletions server/transport/mtls.go
Expand Up @@ -116,6 +116,10 @@ func getOperatorServerTLSConfig(host string) *tls.Config {
PreferServerCipherSuites: true,
MinVersion: tls.VersionTLS13,
}
if certs.TLSKeyLogger != nil {
tlsConfig.KeyLogWriter = certs.TLSKeyLogger
}

tlsConfig.BuildNameToCertificate()
return tlsConfig
}

0 comments on commit a2673f7

Please sign in to comment.