Note for anyone interested; Don't take this as a representation of my skills in Go, I simply followed Faan Rossouw's lead in his workshop Let’s Build a Simple C2 in Golang and Vue.js. While I do plan to explore developing more tools with Go in the future. This is here to show off my understanding of how a C2 framework and network applications in general function - and to give others a deeper understanding of how Command and Control frameworks function to further their own understanding. All credit for the code written should go to Faan Rossouw's and anyone interested should 100% check out his workshop.
Small overview of the project...
It requires a basic server to be setup. Starting with a listener, an element of the program that sits and waits for incoming connections. In this case, a listener is listening on the attackers server on a specific port for a victim machine to call back to it.
A router will look at requests given to it by the listener and directs different types of traffic to different handlers, so that it can be processed correctly. For example, If you want requests to "/" to return "Welcome to the root directory" but you want requests to "/Monday" to return "Happy Monday"... then you would use a router to point the different requests to their respective handers.
A Handler processes the incoming traffic and decides how to read the requrest, what processing to do to it, and what response to send back.
Now that a basic server is setup, the agent needs to be configured. ...
How do we regognise our agent? Faan mentions that connection ID's and IP's can change and you want something that's static so regardless of any changes, you always know where your agent is.
The solution to this is UUID's
- Chi
- I am no expert in Go's standard or 3rd party libraries but Faan Ross used the Chi library as the router for this project as it offers fine-grained control over middleware implementation. (Middleware is code that sits between the listener accepting the connection and the handler actually processing the request - Like an extra step that can handle authentication, encrypting/decrypting communication, checking or modifying something about the request or response; Things like that)
- Gorilla
- Web Socket