Skip to content

Commit 10e2453

Browse files
authored
Merge pull request #1890 from BishopFox/fix/v1.5.x/GHSA-fh4v-v779-4g2w
Track reverse portfwd state
2 parents ba05d0a + 0b84466 commit 10e2453

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

implant/sliver/sliver.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifdef __WIN32
44
#include <windows.h>
55

6+
void StartW();
7+
68
DWORD WINAPI Start()
79
{
810
StartW();

server/core/rtunnels/rtunnels.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
var (
99
Rtunnels map[uint64]*RTunnel = make(map[uint64]*RTunnel)
1010
mutex sync.RWMutex
11+
pending sync.Map
1112
)
1213

1314
// RTunnel - Duplex byte read/write
@@ -95,6 +96,21 @@ func RemoveRTunnel(ID uint64) {
9596
delete(Rtunnels, ID)
9697
}
9798

99+
func AddPending(sessionID string, connStr string) {
100+
pending.Store(sessionID, connStr)
101+
}
102+
103+
func DeletePending(sessionID string) {
104+
pending.Delete(sessionID)
105+
}
106+
107+
func Check(sessionID string, connStr string) bool {
108+
if val, ok := pending.Load(sessionID); ok {
109+
return val == connStr
110+
}
111+
return false
112+
}
113+
98114
// func removeAndCloseAllRTunnels() {
99115
// mutex.Lock()
100116
// defer mutex.Unlock()

server/handlers/sessions.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,14 @@ func createReverseTunnelHandler(implantConn *core.ImplantConnection, data []byte
226226
req := &sliverpb.TunnelData{}
227227
proto.Unmarshal(data, req)
228228

229-
var defaultDialer = new(net.Dialer)
230-
231229
remoteAddress := fmt.Sprintf("%s:%d", req.Rportfwd.Host, req.Rportfwd.Port)
230+
if !rtunnels.Check(session.ID, remoteAddress) {
231+
sessionHandlerLog.Errorf("Session %s attempted to create reverse tunnel to %s without being initiated by a client", session.ID, remoteAddress)
232+
return nil
233+
}
234+
defer rtunnels.DeletePending(session.ID)
235+
236+
var defaultDialer = new(net.Dialer)
232237

233238
ctx, cancelContext := context.WithCancel(context.Background())
234239

server/rpc/rpc-rportfwd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/bishopfox/sliver/protobuf/commonpb"
2525
"github.com/bishopfox/sliver/protobuf/sliverpb"
26+
"github.com/bishopfox/sliver/server/core/rtunnels"
2627
)
2728

2829
// GetRportFwdListeners - Get a list of all reverse port forwards listeners from an implant
@@ -38,6 +39,7 @@ func (rpc *Server) GetRportFwdListeners(ctx context.Context, req *sliverpb.Rport
3839
// StartRportfwdListener - Instruct the implant to start a reverse port forward
3940
func (rpc *Server) StartRportFwdListener(ctx context.Context, req *sliverpb.RportFwdStartListenerReq) (*sliverpb.RportFwdListener, error) {
4041
resp := &sliverpb.RportFwdListener{Response: &commonpb.Response{}}
42+
rtunnels.AddPending(req.Request.SessionID, req.ForwardAddress)
4143
err := rpc.GenericHandler(req, resp)
4244
if err != nil {
4345
return nil, err

0 commit comments

Comments
 (0)