Red teaming, in an information security context, is an adversarial-based offensive activity against an organisation's assets, whether this is infrastructure, applications or people. Red teaming is a specialised penetration testing service offering wherein the attacker assumes the role of an advanced threat actor and attempts to compromise agreed upon components inside the target. The threat actors use Tactics, Techniques and Procedures (TTPs) in their compromise campaigns. It is designed to be stealthier than a typical penetration test and test the defences of a network against a persistent attacker. It is also goal driven to provide focus and guide the test towards what the targeted organisation sees as its most valuable assets rather than the common misconception of "get domain admin". Mitre's ATT&CK framework, provides a comprehensive breakdown of all the different tactics in a red teaming engagement and outline of all different techniques inside each tactic.
Command and Control (C2 for the remainder of this post) is a dedicated tactic in the Mitre ATT&CK framework consisting of different techniques, each describing different ways to achieve a persistent connection between the 'implants' (software agents running on exploited workstations providing the ability to run commands and retrieve results) and the command and control server.
Choosing the C2 protocol is not a trivial task as, in most cases, this governs whether a persistent connection will be established back to the attacker. Select a protocol operating on a non-standard port (trying to get an HTTPS connection out on ports 8080 or 8443), or make uneducated assumptions, (assuming there is no proxy present on the exploited organisation’s infrastructure) and, no matter the sophistication of the attack delivery or payload, you will still end up empty-handed.
Having said all that, one can - in the vast majority of cases - count on two protocols being allowed to communicate with external servers, namely HTTP(S) and DNS, so a very large part of implants use one of these protocols to reach their C2 servers.
Each of the above protocols has its strengths and weaknesses and depend on implementation. HTTP may be a bit more monitored/controlled (see site categorisation) on a customer's infrastructure while DNS may go unnoticed. On the other hand, HTTP can be used to transfer a fair amount of data at once while with DNS, you will end up making so many requests there is a good chance you will end up losing the covertness it initially provides.
Another thing one will need to consider when choosing a C2 protocol is the purpose of using the particular protocol. In any red team engagement, we try to use different tools, protocols, hosting providers and infrastructure in order to achieve operational security and resilience. For the topic at hand, in each red team exercise we are using at least two different C2 channels, sometimes, even more, depending on the geographic spread of the target organisation. Regardless of the number, they all fall conceptually into two discrete categories:
Putting all the above in practical use, in red teaming engagements we are using a mixture of domain names, protocols and tools to make sure we are executing the engagement in a timely, yet operationally secure manner.
If you couple the above with two or more domains, each one is serving a particular type of C2 protocol, then you have a pretty resilient C2 capability. In reality, the short-haul implants have a higher risk of being identified. By introducing a long-haul implant, you provide yourself with the ability to respin a short-haul implant with different IoCs, thereby bypassing any custom detection the targeted organisation put in place to detect the red team operators.
We talked about the lack of tooling regarding the implementation of a DNS-based C2 protocol. We were more or less limited to using DNS-Shell from Sensepost or writing our own implant. DNS-Shell worked well enough for a while, provided we were happy with its single-channel limitation (a server can only communicate with a single implant). While we are not spreading long haul implants on every workstation/server we hop onto, we do have 3 or 4 running in different parts of the targeted organisation's infrastructure. As a result, just spinning a few instances means we bypass DNS-Shell's limitation. The client-side utilises PowerShell; the enhanced optics Microsoft built on the recent PowerShell versions encouraged us to move forward.
Eventually, we built our implant communicating over the DNS protocol, so we introduce you to RETURNINGPATIENT.
So, we built RETURNINGPATIENT to fill the gap we had with a reliable DNS-based C2 channel. In deciding to create RETURNINGPATIENT, we had a clear vision of the purpose of this tool and, while we were often tempted to stray away and add features, we stayed true to our initial design decisions.
There will be a more detailed presentation of RETURNINGPATIENT but for the sake of this post RETURNINGPATIENT:
RETURNINGPATIENT is available here.
We will be following up with a more detailed post going over installation and a simple workflow to help you get up and running with RETURNINGPATIENT.