Streaming Now
. The moment the held open gRPC connection disconnects, that time will update to the current UTC time. This makes it very easy to know that a connection is currently held open even if no traffic is going through it.
Below are some simplified examples of working with this gRPC. An example of this Push style C2 as part of websockets is available with the websocket
C2 profile.
Message
field instead.
Once Mythic is done processing a message, we can send the response back to the agent:
StartPushC2StreamingOneToMany()
and not StartPushC2Streaming
like in the one-to-one example. Before we even get any agent connections, we send a message to the gRPC stream with just the c2 profile name. This let’s Mythic know that we have a new one-to-many c2 profile running and the name of that connection.
At this point, everything works the same as before with the one-to-one profile. As agents send the profile messages, the c2 profile should forward them off to Mythic via the stream and read from the stream to send messages back. You’re probably wondering though - how is the multiplexing happening between the one connection to Mythic and the many agents on the other side?
This stream utilizes a TrackingID
that’s supplied by the C2 profile to track these individual streams:
TrackingID
is something generated by the C2 profile when sending messages and is echoed back as part of the responses that Mythic sends. This allows a C2 Profile to do the proper correlation with messages it gets back and which agent to send it to. This data is saved and tracked by Mythic so that it can be used even when Mythic is the one sending the initial piece of data (like a new task). Let’s look at a slightly more complete example to see how that works:
TrackingID
that’s echoed back to look up the corresponding WebSocket stream and send data that way.
There’s one additional piece here that hasn’t been covered yet though - AgentDisconnected
. Since all agents on the other side of this gRPC connection are sharing the one connection to Mythic, if that gRPC connection exits, then Mythic detects that and marks ALL agents that use that C2 profile has having lost that connection. However, what if just one agent on the other end disconnects? The main gRPC connection is still there, so we need a way to inform Mythic that one remote connection is gone. This is where the AgentDisconnected
piece comes into play: