The idea of 鈥persistence鈥 in a cloud environment is not a well-studied topic. At most, you hear instances of the attacker creating backup logins to maintain their long-term presence in a cloud environment.
To continue our series exposing the tradecraft around business email compromise (BEC), this blog will dive into how 杏吧传媒 identified a threat actor using a novel form of persistence (M365 applications) in order to try to stay under the radar and avoid detection. We discovered a compromised user account with the ability to add apps during the beta phase of our newest product, 杏吧传媒 Managed Identity Threat Detection and Response.
This is another unfortunate case of compromised credentials without additional security controls.聽
There was a failed login from a US IP, and then shortly thereafter, a successful login via a US IP. However, it was clear quite quickly that this wasn鈥檛 a normal IP鈥攊t was a proxy/VPN IP. Here鈥檚 an overall screenshot of the timeline of events that will be explained in more detail below:
Click to enlarge
The events you saw above are where it started to get more interesting. We saw an application added with several events in Azure around it:
鈥淎dd service principal.鈥澛
鈥淎dd delegated permission grant.鈥
鈥淎dd app role assignment grant to user.鈥
鈥淐onsent to application.鈥
Adding just one app was apparently not enough for this threat actor鈥攐r perhaps, the app didn鈥檛 allow them to do everything they wanted to do, which seems to be sending and receiving emails on behalf of the user. But before adding another app, the threat actor again showed some more sophistication in their attack.聽
When there鈥檚 a risk that something you鈥檙e doing as a threat actor can generate emails to the user, the obvious solution is to prevent the user from seeing said emails. How? Well, of course, with our favorite Microsoft 365 threat actor tradecraft of using email inbox rules. 馃聽
The rules added were pretty much as expected. They set up a rule that matched 鈥淍鈥. Yes, it would have matched any email. Then, messages were marked as read and moved to Deleted Items. 馃
Once that was in place, the threat actor went through the step of adding another app to manage email. This time it was , another legitimate app that鈥檚 great for sending mass amounts of emails in a short period of time. This app had some slightly different permissions in addition to 鈥渙ffline_access鈥:
The permissions paired with the app name seem to indicate that the intent is to send emails to all the contacts of the user that look like they are coming from the user. Perhaps follow-on phishing emails so the threat actor can gain access to more valuable user accounts?聽
Setting the probability of the app sending a welcome email aside, another reason the threat actor would not want the user to see any emails arriving in their inbox is simple: the legitimate user would be alerted faster to the compromise if any contacts reply asking 鈥渨hat in the world is this email you just sent me?鈥
Let鈥檚 go back to the meaning of the 鈥渙ffline_access鈥 permission. Any app with this access permission can continue to get new authentication tokens from Microsoft, even after the threat actor no longer controls the compromised account. So, the threat actor would have continued happily reading and sending emails all on behalf of this user account until the application access was revoked; thus maintaining persistent access to the compromised account.聽
Imagine someone stole your car keys including your key fob, then cloned the key fob. Even if you got back your original set of keys, they can use that cloned key fob to keep unlocking your car because that code is authorized to control the car alarm. That鈥檚 essentially what the threat actor was doing.
So what鈥檚 the best way to prevent this kind of attack?
As always, we hope this helps those of you hunting sneaky threat actors in the Microsoft Cloud. If ever you decide you need someone to provide some Managed Identity Threat Detection and Response, so you don鈥檛 have to make your eyes bleed reviewing arcane logging events, you know who to call. 馃槈
Catch up on the other BEC tradecraft we exposed in part one, part two, part three, and part four.
Get insider access to 杏吧传媒 tradecraft, killer events, and the freshest blog updates.