The vulnerability, identified as GHSA-f5p9-j34q-pwcc, is a classic race condition in Go due to concurrent access to shared maps without proper and consistent synchronization. The application uses several global maps (e.g., OPERATORS, PortFwds, FTPStreams, AgentControlMap) to manage state for operator sessions, port forwards, file transfers, and connected agents.
The root cause is that multiple goroutines read from and write to these standard Go maps simultaneously. For instance, one goroutine might be iterating over the OPERATORS map to broadcast a message, while another goroutine is adding or removing an operator from the same map as they connect or disconnect. Standard Go maps are not safe for concurrent access, and such operations will cause the Go runtime to detect the conflict and trigger a fatal error: concurrent map read and map write, crashing the entire C2 server process. This results in a Denial of Service (DoS).
The patch addresses this vulnerability by replacing the usage of standard map types with sync.Map for all the affected shared resources. sync.Map is a thread-safe map implementation provided by Go's standard library, specifically designed for concurrent read and write access. By migrating to sync.Map, the application ensures that all operations on these shared maps are atomic, thus eliminating the race conditions and preventing the server from crashing under concurrent activity.