From 51dad9601843272728dcb11edb9804b887f99e77 Mon Sep 17 00:00:00 2001 From: Russel Van Tuyl Date: Thu, 21 Mar 2024 07:56:50 -0400 Subject: [PATCH] Fixed SOCKS issues --- .github/workflows/go_dev.yml | 2 ++ docs/CHANGELOG.MD | 3 ++- pkg/modules/socks/socks.go | 2 +- pkg/services/job/job.go | 11 +++++------ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/go_dev.yml b/.github/workflows/go_dev.yml index 031d5818..6ccd7b55 100644 --- a/.github/workflows/go_dev.yml +++ b/.github/workflows/go_dev.yml @@ -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 diff --git a/docs/CHANGELOG.MD b/docs/CHANGELOG.MD index bf44c6c4..bb3063a0 100644 --- a/docs/CHANGELOG.MD +++ b/docs/CHANGELOG.MD @@ -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 diff --git a/pkg/modules/socks/socks.go b/pkg/modules/socks/socks.go index 06ab3509..5dd97d06 100644 --- a/pkg/modules/socks/socks.go +++ b/pkg/modules/socks/socks.go @@ -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 diff --git a/pkg/services/job/job.go b/pkg/services/job/job.go index ca5bd8f1..37af808b 100644 --- a/pkg/services/job/job.go +++ b/pkg/services/job/job.go @@ -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 } @@ -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) } @@ -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 @@ -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) { @@ -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 {