applied security research
Wesley Neelen - 05 mei 2020

Office 365 – malicious applications

This blog is part of our Office 365 attack & defense series. We also maintain a Github page where we share our Office 365 tools and queries.

Many organizations are moving (partially) to the cloud. One of the main components is Azure Active Directory (AAD). This is the cloud version of the on-premise Active Directory that many organizations are using or have been using in the past years. The adoption mostly has grown because AAD is required and automatically tied to Office365. But besides basic identity and access functionality, Azure Active Directory offers a ton of functionality. Such as this interesting feature called “app registrations”. This new feature could potentially be abused by attackers. Therefore, it is important to understand the inner workings of such attacks and implement defensive measures.

The app registration feature of Azure AD is a way to grant permissions / authenticate against an Azure Active Directory tenant using an application. Within the app registration it is possible to configure the scope of the permissions that are granted to the application.

Delegated permissions

When creating an app registration, it is possible to assign delegated permissions to access specific resources in the Azure Active Directory tenant on behalf of another user. If a user authenticates through the application, access is granted to the specified resources on behalf of the user account stored in the app registration.

These kinds of features could for example be used to access someone’s email if a victim authenticates into a malicious application. Some proof of concept applications have been published to perform this attack scenario against Microsoft Azure, such as PwnAuth. Generally, an attack follows these steps:

  1. the attacker creates a malicious multi-tenant app registration with a callback to a webserver controlled by him. The application requests access to the resources he wants to obtain (e.g. reading mail through Microsoft Graph API)
  2. the victim authenticates in the application (and ignores any messages) and is redirected to the attacker’s webserver including a newly added code value
  3. the attacker uses the code to get an authorization token
  4. the attacker uses the authorization token to query the specific resources, for example the Microsoft Graph API to read the users e-mail

Monitoring for abuse

Azure Sentinel can be used to detect a user that consents to an application. The following KQL query can be used to monitor  application consent to any application:

AuditLogs
| where OperationName == 'Consent to application'
| extend applicationDetails = parse_json(TargetResources)[0]
| extend appname = parse_json(applicationDetails)['displayName']
| extend scope = parse_json(applicationDetails)['modifiedProperties'][4]["newValue"]

Complete YML

This query can be used to detect more critical consents, with admin privileges:

AuditLogs
| where OperationName == 'Consent to application'
| extend applicationDetails = parse_json(TargetResources)[0]
| extend appname = parse_json(applicationDetails)['displayName']
| extend IsAdmin = parse_json(applicationDetails)['modifiedProperties'][0]["newValue"]
| where IsAdmin == '"True"'

Complete YML

If you want to review all consents that were granted to (external) applications in a tenant, this can be done manually through the Azure portal or through PowerShell. More information on this can be found in the Microsoft documentation here.

Reviewing all the applications manually through the Azure portal or PowerShell can be a time-consuming task. Therefor the author of PwnAuth created a script to hunt for potential malicious apps on multiple characteristics. This is a nice way to identify potentially malicious scripts and perform the further investigation manually for each application through the Azure portal or PowerShell.

Mitigation

Azure AD offers a configuration setting to disable the consent to all apps by users. Disabling this prevents a user granting access to company resources or information through applications.

If you prefer using PowerShell, the following one liner could be used to look up the current value of the setting:

Get-MsolCompanyInformation | select UsersPermissionToUserConsentToAppEnabled

The following PowerShell could be used to disable consent to applications for regular users:

Set-MsolCompanySettings -UsersPermissionToUserConsentToAppEnabled:$false

Application permissions

Another possibility is to assign application permissions to an app registration. These permissions can only be consented by an administrator. After those permissions have been consented, an attacker is able to access the Azure tenant through the application. This requires an attacker to have the application ID, tenant ID and application secret.

This method could be used by an attacker to keep access to an Azure tenant, for example when the admin accounts he obtained access to got locked out. By for example granting the Directory.ReadWrite.all permission to an application, he would be able to modify the directory data such as user and groups through the application. The following steps are required to perform this attack:

  1. the attacker compromised a tenant and obtained high privileges to the Azure tenant. Using the obtained access, he creates an app registration with applications permissions on the resources he wants persistence access to.
  2. the attacker grants admin consents to the application
  3. the attacker generates a certificate / client secret
  4. whenever the attacker wants to use the obtained access, he could use the certificate or client secret to perform his malicious actions.

Monitoring for abuse

The following Sentinel rule could be used to discover any application being added for further investigation:

AuditLogs
| where (OperationName == "Add application") or (OperationName == "Update application")

Complete YML

PwnAuth describes a default call path in its documentation. It is possible to hunt in sentinel for these kinds of applications being added, using the following query. This query would detect PwnAuth applications being created within the organizations tenant, using the default documentation information:

AuditLogs
| where (OperationName == "Add application") or (OperationName == "Update application")
| extend details = parse_json(TargetResources[0])
| extend properties = parse_json(details["modifiedProperties"][0])
| where properties["newValue"] contains "/oauth/api/microsoft/callback"

Complete YML

The same, earlier mentioned query, could be also used to detect whether an administrator within the tenant consents admin to an application within the tenant:

AuditLogs
| where OperationName == 'Consent to application'
| extend applicationDetails = parse_json(TargetResources)[0]
| extend appname = parse_json(applicationDetails)['displayName']
| extend IsAdmin = parse_json(applicationDetails)['modifiedProperties'][0]["newValue"]
| where IsAdmin == '"True"'

Complete YML

Mitigation

It is possible to disable the possibility to create app registrations by regular users. This prevents non-administrative users from creating apps to access resources through an app registration. It is possible to disable this settings through the Azure portal:

If you prefer using PowerShell, the following one liner could be used to look up the current value of the setting:

Get-MsolCompanyInformation | select UsersPermissionToCreateLOBAppsEnabled

The following PowerShell could be used to disable consent to applications for regular users:

Set-MsolCompanySettings -UsersPermissionToCreateLOBAppsEnabled:$false

Conclusion

Applications are a great way for attackers to obtain access to company resources. If they successfully phish a victim, they are able to obtain access to the organizations resources on their behalf. Also, applications can be used to gain persistent access in an already compromised tenant. If compromised accounts are locked out, but the malicious application is missed, it can still be used as an entry point into the tenant. Also, if registering of applications is allowed within a tenant (which is by default), a non-admin user could create a malicious app within the tenant of an organization, to phish others.

To minimize the chance of above attacks Zolder recommends:

  • If you do not require the app functionality, disable the possibility for users to consents to application
  • disable registration of apps by non-admin users
  • monitor for users consents with suspicious characteristics
  • monitor for admin consents, make sure to review every admin consents granted
Blogs

Internetoplichters richten pijlen op Hockeyvereniging

Erik Remmelzwaal - 10 mrt 2023
De penningmeester van Hockeyclub Zevenbergen ontving een poging tot oplichting. Gelukkig werd het herkend, maar zal dat overal gebeuren, nu internetoplichters hun pijlen blijkbaar op sportverenigingen hebben gericht? Lees verder

Microsoft Digital Defense Report

Erik Remmelzwaal - 14 nov 2022
Het Digital Defense Report 2022 van Microsoft is uitgekomen. Wat zijn de highlights en key takeaways? Lees verder

TBX2022 Throwback & Masterclass

Erik Remmelzwaal - 07 nov 2022
Op 2 en 3 november vond in de Jaarbeurs Utrecht de TBX2022 beurs plaats. Zolder was net als vorig jaar aanwezig als exposant, en was op beide dagen de host van een masterclass. Ons voornaamste doel was om ons nieuwe propositie van Attic for MSPs bekend te maken. Met deze nieuwe release, stellen we andere […] Lees verder

Hacking my Helium Crypto Miner

Wesley Neelen - 05 sep 2022
Recently I came across an interesting cryptocurrency project called Helium. Its a wireless network built by people all around the world. The people that help expanding the network by adding a hotspot receive the Helium cryptocurrency coin by providing the coverage. During my research I decided to order one of those Helium miners. I ordered […] Lees verder

PEN-300 / OSEP review

Wesley Neelen - 19 jul 2022
This year I decided to start a new study, the PEN-300 course of Offensive Security. In 2012 I did the OSCP course and in 2013 OSCE. In 2016 I took the OSEE class in Vegas, unfortunately never took the exam (one of my biggest mistakes ever🥴). I liked all the courses very much at that […] Lees verder

Deze 3 misverstanden blokkeren het ontwikkelen van cyberweerbaarheid

Zolder B.V. - 04 jul 2022
Het NCTV heeft weer het jaarlijkse Cybersecuritybeeld Nederland gepubliceerd. Het CSBN-2022. Mooie aanleiding om eens op te schrijven waar ik al langer mee in mijn hoofd zit. Drie hardnekkige en foute aannames die mensen hebben bij digitale dreigingen. Drie misverstanden dus, die in mijn ervaring de belangrijkste reden zijn dat we nauwelijks vooruit komen met […] Lees verder

Cyberweerbaarheid en Operational Technology

Erik Remmelzwaal - 02 jun 2022
Onlangs nam Erik Remmelzwaal, co-owner en Managing Director van Zolder BV, deel aan een tafelgesprek van Data Value Center – Smart Industry (DVC-SI). Het thema was Cyberweerbaarheid en Operational Technology, en het gesprek werd opgenomen in de campus van Breda Robotics, waar Zolder lid van is. De opname is inmiddels beschikbaar en terug te kijken […] Lees verder

Detecting MFASweep using Azure Sentinel

Zolder B.V. - 01 nov 2021
Many companies are using cloud services such as Microsoft 365 for email, file sharing and communicating. If an attacker gains access to valid credentials that allows them to authenticate to the account, all information within the account is usually instantly accessible. Therefor, implementing multi factor authentication is one of the most important steps while securing […] Lees verder

Public SharePoint sites - the new open shares

Wesley Neelen - 16 sep 2021
During one of our engagements we were investigating a Microsoft 365 environment. My colleague Rik discovered that many SharePoint sites were publicly available within the organization. We were surprised by the amount sites that were wide open this way. A lot of sensitive information was located on those sites, for example PII-information and passwords for […] Lees verder

Decrypt passwords from Xerox Workcentre config backups

Rik van Duijn - 29 aug 2021
During a recent engagement we encountered Xerox WorkCentre printers using default credentials (admin:1111). Usually it’s just another finding, but this time we noticed the printer had SMB and e-mail credentials configured. For LDAP we usually point the printer to our own IP and get access to the plaintext creds that way. But in the case […] Lees verder

Office 365 audit logging

Rik van Duijn - 19 aug 2021
It’s important to enable audit logging for o365 even if you are not monitoring them actively. Atleast if you get hacked there’s logging to investigate :). The audit log is not always enabled by default, it seems to rely on license levels. However there are some important things to take into consideration. You can enable […] Lees verder

Ransomware, nationale crisis?

Erik Remmelzwaal - 04 aug 2021
Als er 1 digitale dreiging is die veel in het nieuws komt, dan is het ransomware. Er wordt zelfs gesproken van een nationale crisis. Lees verder

Mijlpalen en hoe het gaat

Zolder B.V. - 02 jul 2021
Vandaag gebeurden er op Zolder toch een paar dingen die blogwaardig zijn. Dus prima aanleiding om nog maar eens de laptop open te klappen en te vertellen hoe het gaat. Nieuwe collega’s Het is 1 juli 2021 en we zijn ruim een jaartje onderweg als Zolder. De belangrijkste stap die we vandaag zetten, is dat […] Lees verder

Zolder wordt hoofdsponsor HCZ

Zolder B.V. - 01 jul 2021
Vandaag is bekend geworden dat Zolder de nieuwe hoofdsponsor is van HCZ – Hockeyclub Zevenbergen. De komende drie seizoenen zal het logo van Zolder daarom voorop de shirts van alle HCZ leden prijken. We zijn heel erg trots op deze nieuwe stap voor ons jonge bedrijf, en hopen zo de relatie met onze regio te […] Lees verder

Breda Robotics

Erik Remmelzwaal - 10 mei 2021
Zolder BV is toegetreden tot het netwerk van Breda Robotics. Deze vereniging brengt organisaties bij elkaar die actief zijn rondom robotisering in de regio West-Brabant. Voor Zolder geeft Breda Robotics de mogelijkheid om samen te werken met de robotiseringsindustrie. Te begrijpen hoe die sector precies werk en op welke vlakken cybersecurity kennis kan worden ingezet […] Lees verder

27% .nl domeinen slecht beschermd tegen spoofing

Erik Remmelzwaal - 29 apr 2021
TLDR: We scanden de DNS records van 1,6 miljoen .nl domeinen en vonden uit: 9% is rechtstreeks gekoppeld aan Microsoft 365, daarmee is Microsoft veruit de grootste Google is nr2 en heeft 4% van de domeinen aan zich verbonden, nagenoeg gelijk aan een aantal andere spelers. Van alle mail-enabled domeinen heeft 27% geen SPF record […] Lees verder

Zolder biedt MKB betaalbare en eenvoudige security-app

Zolder B.V. - 12 apr 2021
“Attic voorkomt dat security een luchtbel wordt” Security is bij mkb-bedrijven vaak het ondergeschoven kindje. Ze hebben er de mensen en het budget niet voor. Dat maakt deze doelgroep een aantrekkelijk doelwit voor cybercriminelen. Voor de vier doorgewinterde cybersecurity-experts van start-up Zolder reden om Attic te introduceren. Deze eenvoudige, goedkope en toekomstbestendige app maakt mkb’ers […] Lees verder

Nieuwe Themesong voor Zoldersessions

Erik Remmelzwaal - 13 mrt 2021
Ik vond het tijd worden voor een nieuw liedje voor onze Zoldersessions. Tot nu toe hadden we er een rechtenvrij liedje onder staan, namelijk EVA_失望した, maar wilden toch iets meer 'eigens'. Daar schakelden we Bjørgen van Essen voor in met dit eindresultaat. Dit is hoe dat tot stand kwam. Lees verder

Zolder.App Open Beta

Zolder B.V. - 02 feb 2021
We launched the final beta release to the Google and Apple appstores. Any business running on Microsoft 365 is more than welcome to join. As a beta-tester you will receive a free subscription to the Zolder.App Premium Plan for the remainder of the beta phase, which is scheduled to run through April 30th 2021. Zolder.App […] Lees verder

GGD data is topje van ijsberg

Erik Remmelzwaal - 26 jan 2021
Maandag kwam RTL Nieuws, na onderzoek van Daniël Verlaan, naar buiten met het nieuws dat gestolen data van de GGD online wordt verhandeld door criminelen. Het gaat om data die onderdeel uitmaakt van het bron- en contactonderzoek dat de GGD uitvoert als onderdeel van de bestrijding van Corona/COVID-19. De data bevat gevoelige persoonsgegevens en criminelen […] Lees verder