Skip to content

Commit

Permalink
Fixed SOCKS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Ne0nd0g committed Mar 21, 2024
1 parent 6ef04d4 commit 51dad96
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/go_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
- name: Gosec Security Scanner
id: gosec
uses: securego/gosec@master
with:
args: ./...

- name: Go Report Card - Install
id: goreportcard_install
Expand Down
3 changes: 2 additions & 1 deletion docs/CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## 2.1.2 - 2024-XX-XX
## 2.1.2 - 2024-03-21

### Fixed

- SOCKS listener was not properly handling data and connection status
- Increased SOCKS job in/out channel size from 100 to 1,000
- Fixed a bug where multiple SOCKS go routines were created instead of one
- Updated `readSOCKSClient()` function to close the connection on any connection read error
- Updated `processMessage()` to drop SOCKS jobs when the connection was already closed
- Added `NewInfoWithID()` factory for SOCKS jobs information structures that keep the same Job ID for the connection lifetime
Expand Down
2 changes: 1 addition & 1 deletion pkg/modules/socks/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/Ne0nd0g/merlin/v2/pkg/core"
)

// listeners is a map of single TCP bound interfaces associated keyed to a specific agent ID
// listeners is a map of single TCP-bound interfaces associated keyed to a specific agent ID
var listeners = sync.Map{}

// connections is a map connections keyed to their own ID. There are multiple connections per listener
Expand Down
11 changes: 5 additions & 6 deletions pkg/services/job/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func NewJobService() *Service {
messageRepo: withMemoryClientMessageRepository(),
agentService: agent.NewAgentService(),
}
// Start the SOCKS infinite loop
go memoryService.socksJobs()
}
// Start the SOCKS infinite loop
go memoryService.socksJobs()
return memoryService
}

Expand Down Expand Up @@ -533,7 +533,6 @@ func (s *Service) buildJob(agentID uuid.UUID, job *jobs.Job, jobArgs []string) e
conn := job.Payload.(jobs.Socks)
command = fmt.Sprintf("SOCKS connection %s packet %d", conn.ID, conn.Index)
default:
fmt.Printf("DEFAULT\n")
command = fmt.Sprintf("%s %+v", job.Type, job.Payload)
}

Expand All @@ -554,7 +553,7 @@ func (s *Service) buildJob(agentID uuid.UUID, job *jobs.Job, jobArgs []string) e
job.ID = jobInfo.ID()
}

// Add job to the server side job list
// Add the job to the server side job list
s.jobRepo.Add(*job, jobInfo)

// Log the job
Expand All @@ -568,7 +567,7 @@ func (s *Service) buildJob(agentID uuid.UUID, job *jobs.Job, jobArgs []string) e
return nil
}

// checkJob verifies that the input job message contains the expected token and was not already completed
// checkJob verifies that the input job message contains the expected token and was not yet completed
func (s *Service) checkJob(job jobs.Job) error {
// Check to make sure agent UUID is in dataset
if !s.agentService.Exist(job.AgentID) {
Expand Down Expand Up @@ -802,7 +801,7 @@ func (s *Service) Handler(agentJobs []jobs.Job) error {
return fmt.Errorf("pkg/services/job.Handler(): %s", err)
}

// Verify that the job contains the correct token and that it was not already completed
// Verify that the job contains the correct token and that it was not yet completed
err = s.checkJob(job)
if err != nil {

Expand Down

0 comments on commit 51dad96

Please sign in to comment.