Compare commits

...
Author SHA1 Message Date
moloch-- de5fa3458b Allow keep alives 2026-01-23 17:05:53 -08:00
Joe a3a98858fd Merge pull request #2135 from BishopFox/fix/sqlite
Add sqlite pragmas to db config
2026-01-21 22:28:56 -07:00
7 changed files with 104 additions and 1 deletions

No files matched your search

@@ -15,6 +15,12 @@ The Sliver server has a configuration file located in the `configs` sub-director
"level": 4,
"grpc_unary_payloads": false,
"grpc_stream_payloads": false
},
"grpc": {
"keepalive": {
"min_time_seconds": 30,
"permit_without_stream": true
}
}
}
```
@@ -29,6 +35,10 @@ The Sliver server has a configuration file located in the `configs` sub-director
- `level` - The `logrus` logging level (1 - 5), by default this is set to `4`, which is the `INFO` level; increasing this value increases the verbosity of the logs e.g. `DEBUG` is `5` and `SILENT` is `1`
- `grpc_unary_payloads` - Log gRPC unary payloads
- `grpc_stream_payloads` - Log gRPC streaming payloads
- `grpc` - An object containing options for the server gRPC stack
- `keepalive` - gRPC keepalive enforcement configuration
- `min_time_seconds` - Minimum amount of time (in seconds) between client pings before the server sends a GOAWAY with `too_many_pings`
- `permit_without_stream` - Allow client pings when there are no active streams
## Database Configuration
@@ -19,6 +19,12 @@ $ cat ~/.sliver/configs/server.json
"level": 5,
"grpc_unary_payloads": false,
"grpc_stream_payloads": false
},
"grpc": {
"keepalive": {
"min_time_seconds": 30,
"permit_without_stream": true
}
}
}
```
+35 -1
View File
@@ -30,7 +30,8 @@ import (
)
const (
serverConfigFileName = "server.json"
serverConfigFileName = "server.json"
defaultGRPCKeepaliveMinTimeSeconds = int64(30)
)
var (
@@ -53,6 +54,17 @@ type LogConfig struct {
TLSKeyLogger bool `json:"tls_key_logger"`
}
// GRPCKeepaliveConfig - gRPC keepalive enforcement settings
type GRPCKeepaliveConfig struct {
MinTimeSeconds int64 `json:"min_time_seconds"`
PermitWithoutStream *bool `json:"permit_without_stream"`
}
// GRPCConfig - gRPC server settings
type GRPCConfig struct {
Keepalive *GRPCKeepaliveConfig `json:"keepalive"`
}
// DaemonConfig - Configure daemon mode
type DaemonConfig struct {
Host string `json:"host"`
@@ -135,6 +147,7 @@ type ServerConfig struct {
DaemonMode bool `json:"daemon_mode"`
DaemonConfig *DaemonConfig `json:"daemon"`
Logs *LogConfig `json:"logs"`
GRPC *GRPCConfig `json:"grpc"`
Watchtower *WatchTowerConfig `json:"watch_tower"`
GoProxy string `json:"go_proxy"`
HTTPDefaults *HttpDefaultConfig `json:"http_default"`
@@ -199,6 +212,20 @@ func GetServerConfig() *ServerConfig {
config.DonutBypass = 1
}
if config.GRPC == nil {
config.GRPC = &GRPCConfig{}
}
if config.GRPC.Keepalive == nil {
config.GRPC.Keepalive = &GRPCKeepaliveConfig{}
}
if config.GRPC.Keepalive.MinTimeSeconds <= 0 {
config.GRPC.Keepalive.MinTimeSeconds = defaultGRPCKeepaliveMinTimeSeconds
}
if config.GRPC.Keepalive.PermitWithoutStream == nil {
defaultPermit := true
config.GRPC.Keepalive.PermitWithoutStream = &defaultPermit
}
err := config.Save() // This updates the config with any missing fields
if err != nil {
serverConfigLog.Errorf("Failed to save default config %s", err)
@@ -207,6 +234,7 @@ func GetServerConfig() *ServerConfig {
}
func getDefaultServerConfig() *ServerConfig {
defaultPermitWithoutStream := true
return &ServerConfig{
DaemonMode: false,
DaemonConfig: &DaemonConfig{
@@ -218,6 +246,12 @@ func getDefaultServerConfig() *ServerConfig {
GRPCUnaryPayloads: false,
GRPCStreamPayloads: false,
},
GRPC: &GRPCConfig{
Keepalive: &GRPCKeepaliveConfig{
MinTimeSeconds: defaultGRPCKeepaliveMinTimeSeconds,
PermitWithoutStream: &defaultPermitWithoutStream,
},
},
HTTPDefaults: &HttpDefaultConfig{
Headers: []models.HttpC2Header{
models.HttpC2Header{
+50
View File
@@ -0,0 +1,50 @@
package transport
/*
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 (
"time"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)
func grpcKeepaliveOptions() []grpc.ServerOption {
if serverConfig == nil || serverConfig.GRPC == nil || serverConfig.GRPC.Keepalive == nil {
return nil
}
minTimeSeconds := serverConfig.GRPC.Keepalive.MinTimeSeconds
if minTimeSeconds <= 0 {
return nil
}
permitWithoutStream := true
if serverConfig.GRPC.Keepalive.PermitWithoutStream != nil {
permitWithoutStream = *serverConfig.GRPC.Keepalive.PermitWithoutStream
}
policy := keepalive.EnforcementPolicy{
MinTime: time.Duration(minTimeSeconds) * time.Second,
PermitWithoutStream: permitWithoutStream,
}
return []grpc.ServerOption{
grpc.KeepaliveEnforcementPolicy(policy),
}
}
+1
View File
@@ -43,6 +43,7 @@ func LocalListener() (*grpc.Server, *bufconn.Listener, error) {
grpc.MaxRecvMsgSize(ServerMaxMessageSize),
grpc.MaxSendMsgSize(ServerMaxMessageSize),
}
options = append(options, grpcKeepaliveOptions()...)
options = append(options, initMiddleware(false)...)
grpcServer := grpc.NewServer(options...)
rpcpb.RegisterSliverRPCServer(grpcServer, rpc.NewServer())
+1
View File
@@ -64,6 +64,7 @@ func StartMtlsClientListener(host string, port uint16) (*grpc.Server, net.Listen
grpc.MaxRecvMsgSize(ServerMaxMessageSize),
grpc.MaxSendMsgSize(ServerMaxMessageSize),
}
options = append(options, grpcKeepaliveOptions()...)
options = append(options, initMiddleware(true)...)
grpcServer := grpc.NewServer(options...)
rpcpb.RegisterSliverRPCServer(grpcServer, rpc.NewServer())
+1
View File
@@ -81,6 +81,7 @@ func StartTsNetClientListener(hostname string, port uint16) (*grpc.Server, net.L
grpc.MaxRecvMsgSize(ServerMaxMessageSize),
grpc.MaxSendMsgSize(ServerMaxMessageSize),
}
options = append(options, grpcKeepaliveOptions()...)
options = append(options, initMiddleware(true)...)
grpcServer := grpc.NewServer(options...)
rpcpb.RegisterSliverRPCServer(grpcServer, rpc.NewServer())