00:00:00.167,00:00:05.172 >>Hi Defcon. That's better. Welcome to I'm in Your Cloud. And um, I'm Dirk-jan. I live in 00:00:08.175,00:00:14.915 the Netherlands, work for Fox-IT. Um, I mostly focus my research on Azure AD and um, 00:00:14.915,00:00:19.820 active directory. Um, if you do surf with active directory, you've probably heard of some of 00:00:19.820,00:00:26.727 the tools I wrote, like mitm6 or um, a Python version of BloodHound, and I also have a 00:00:26.727,00:00:31.899 blog where I write about stuff. I also wrote the PrivExchange and of course, I have a twitter 00:00:31.899,00:00:37.838 account where I uh, share my research. So, today we'll be talking about clouds and in the 00:00:37.838,00:00:43.210 cloud, as you all know, um, everything this magic and secure. You don't have to patch 00:00:43.210,00:00:48.181 and everything is automatically arranged for you. You just spend some money and everything is 00:00:48.181,00:00:53.186 good. Um, I will offer you the reality, at Fox we also have like, inside response department 00:00:55.422,00:01:00.627 and most things they see is um, the cloud being compromised because people actually didn't 00:01:00.627,00:01:06.867 secure it properly. And on the conferences, I don't see a lot of talks yet about cloud stuff. 00:01:06.867,00:01:13.006 There are some focusing on Azure and um, on Azure virtual machines and stuff and AWS, but 00:01:13.006,00:01:19.179 I didn't really see anything about Azure AD, so that's what we'll be talking about today. 00:01:19.179,00:01:24.184 And first I'll be giving an introduction into Azure AD, what it is, how we can talk to it and 00:01:26.320,00:01:31.325 how its' architecture is kinda built and about the rules, applications, service 00:01:31.325,00:01:37.064 principals. Then I'll take a short step and have look, have a look at some fun with multi 00:01:37.064,00:01:43.136 factor authentication and then we'll talk about linking up the clouds and on-premise, then 00:01:43.136,00:01:47.874 talking about Azure Research Manager and how it's connected to Azure AD and last but not 00:01:47.874,00:01:53.647 least, I'll talk about integrations and as an example, I'll take Azure DevOps. I have 00:01:53.647,00:01:58.485 to apologize in advance. Uh, if you're still tired or hung over, this is a talk which is pretty 00:01:58.485,00:02:03.423 fast paced and I've got a lot of content, so try to keep up. But first, what is Azure AD? 00:02:07.027,00:02:12.099 According to Wikipedia, Azure active directory is Microsoft's cloud-based identity and access 00:02:12.099,00:02:18.472 management service. Um, that's a whole mouthful, but basically it does the authentication for 00:02:18.472,00:02:24.711 Office 365 and Azure Resource Manager and anything you want to integrate with it. Um, I always 00:02:24.711,00:02:30.917 like to compare it's, kind of it's login with Facebook, because you can integrate that 00:02:30.917,00:02:34.488 on a third party website, and then you just log in with your Facebook account and your 00:02:34.488,00:02:40.894 registered. Only then, um, it has a Microsoft logo and it's called Azure AD. And it's 00:02:40.894,00:02:46.433 actually on the, apart from that, it's actually pretty similar. And it's called Azure 00:02:46.433,00:02:51.872 Active Directory, but if you compare it to the Windows Server Active Directory or the 00:02:51.872,00:02:56.543 on-premise Active Directory that we all know, there's actually nothing that's really similar to 00:02:56.543,00:03:02.716 it. Um, all the protocols are different, the structure is different. There are different 00:03:02.716,00:03:08.688 um, terminology and different set up, so for this talk, try to forget almost everything you 00:03:08.688,00:03:13.693 knew about active directory and we're really gonna focus on cloud. So, if you want to 00:03:16.329,00:03:19.066 interact with Azure AD, there are a couple of ways. First, there's the portal, which if you 00:03:19.066,00:03:21.068 did use Azure AD, you probably used. There are some PowerShell modules and there is also a 00:03:21.068,00:03:23.070 command line interface and lastly, there are some API's. And it's already quite a bit of 00:03:23.070,00:03:28.075 ways and there's uh, a few difference between those. Um, for example, the portal, it's 00:03:38.251,00:03:44.524 very um, nice and shiny. It's, it works nice. You can click around and configure stuff. But 00:03:44.524,00:03:49.930 if you try to understand how Azure AD works and you're looking at the portal, um, it's 00:03:49.930,00:03:54.868 not going to work out, cause I started with the portal and then I moved to trying to understand 00:03:54.868,00:03:59.806 how things work with the API and such, and I found out that the portal just made it more unclear 00:03:59.806,00:04:05.312 for me, cause um, Microsoft tries to make everything user-friendly and translates uh, 00:04:05.312,00:04:09.950 things from the complex terminology that's actually used in the back-end, and so if you 00:04:09.950,00:04:14.955 want to understand Azure AD, um, don't use the portal. There is also a PowerShell. Actually, 00:04:17.791,00:04:23.930 there are a couple of PowerShell modules and I think the oldest one is the MSOnline PowerShell 00:04:23.930,00:04:30.137 module. This one really focuses on Office 365 and as such, it has a few features that you 00:04:30.137,00:04:35.942 won't find in the other modules. Um, this is a bit old and Microsoft is deprecating this 00:04:35.942,00:04:41.181 one, so you shouldn't be using it, but it's still has some specific features that are not 00:04:41.181,00:04:47.020 available in the other modules, so sometimes you still have to use it. There is also the Azure 00:04:47.020,00:04:53.193 AD PowerShell module, which really focuses on Azure AD, but it has a different feature set 00:04:53.193,00:04:58.932 than MSOnline PowerShell Module. And lastly, there is the command line interface and yet another 00:04:58.932,00:05:03.870 PowerShell module, but this one is focusing more on Azure Resource Manager, so you can use 00:05:03.870,00:05:08.875 it manage virtual machines and V-lines and that kind of stuff. And, the most interesting ones 00:05:12.179,00:05:17.617 from my perspective are the API's. Yet again, there are some different ways here. So, you 00:05:17.617,00:05:23.223 have the Azure AD Graph, which is, as it said, is really focusing on Azure AD, but you 00:05:23.223,00:05:27.694 also have the Microsoft Graph, and Microsoft was like, okay so we have this graph for Azure AD, 00:05:27.694,00:05:32.566 but why not put all of our product in one single API and I'm like, umm, that doesn't 00:05:32.566,00:05:36.770 really make it much easier to understand. If you would like a API definition, that would take 00:05:36.770,00:05:42.943 a year reading through and I can't really find anything, so I prefer the Azure AD Graph, um, 00:05:42.943,00:05:47.948 that's, that one is already um, considered legacy, so I, in the future you probably have to use 00:05:52.152,00:05:57.190 the Microsoft Graph. Lastly, there's the Exchange Provisioning service which uses 00:05:57.190,00:06:03.230 XML, so I really to avoid that one, but once again, that's the back-end of the MSOnline 00:06:03.230,00:06:07.400 PowerShell module, so there are some features in there which are actually not in the other API's. 00:06:09.669,00:06:15.408 Now which one to use? Um, all of them have different features and some of them have unique 00:06:15.408,00:06:21.815 features, but they are um, deprecated or considered legacy, as you can see in the, in the, 00:06:21.815,00:06:26.419 in the corner below. They support different authentication methods, so some of the 00:06:26.419,00:06:31.858 PowerShell modules supports different authentication and some don't. So, if, if you want 00:06:31.858,00:06:36.029 to actually use all of the features, you're stuck with using different API's and 00:06:36.029,00:06:40.700 different PowerShell modules all over the place. And to make it even more confusing, there is 00:06:40.700,00:06:45.705 also a different terminology. Like here, I am using, um, at the top I'm using the Azure AD 00:06:47.807,00:06:53.413 PowerShell module to list the directory roles, and you see I have five directory roles, but 00:06:53.413,00:06:58.485 if I used the MSOnline PowerShell Module, I suddenly have a lot of more roles. You 00:06:58.485,00:07:03.023 also see the ObjectId for the role is somehow different between the two modules. If 00:07:03.023,00:07:08.228 that's a reason, but it doesn't really make it um, much clearer. Also, here I am looking at the 00:07:08.228,00:07:12.565 company administrator role, and if you look at the portal, that one is conveniently called 00:07:12.565,00:07:17.570 Global administrator. So, once again, uh, different terminology. And to conclude on 00:07:19.906,00:07:25.945 this, there is not really one uniform way to talk to Azure AD. I wish there was. And you're 00:07:25.945,00:07:30.784 also kind of limited to what Microsoft considers important, like on-premise active 00:07:30.784,00:07:36.222 directory, you have L-Dep and everything in active directory is kind of stored there. But, in 00:07:36.222,00:07:40.694 the, in Azure AD, you have different API's and not all features can actually be called 00:07:40.694,00:07:46.533 by API's. And most of this research comes from using both documented and undocumented 00:07:46.533,00:07:51.538 API's in Azure AD. So, let's have a look at the architecture. In Azure AD, there are um, three 00:07:57.711,00:08:03.650 major kinds of principals. First you have the users, which often are the physical users that are 00:08:03.650,00:08:09.356 in your company. These users can, of course, have devices. Uh, a device can be like a 00:08:09.356,00:08:14.427 Windows 10 laptop that can be joined to Azure AD, but it can also be an i-Phone or android 00:08:14.427,00:08:21.434 that is joined to Azure AD via a mobile device management. And lastly, you have applications, 00:08:21.434,00:08:26.439 which we'll talk about later. And your users, um, can have specific roles and this is also, 00:08:28.808,00:08:34.147 this picture is kind of important so, usually if you hear about Azure roles, they're 00:08:34.147,00:08:39.686 talking about role-based access control, Azure RBAC roles, on the left. That is what is used 00:08:39.686,00:08:45.658 for the virtual machines and stuff, and it's not actually used for Office 365. So first, 00:08:45.658,00:08:50.663 we'll uh, focus on the roles that Office 365 uses, which are defined in Azure AD. And there 00:08:53.366,00:08:58.438 are some different admin roles. The first one, or the most um, important one, is the Global 00:08:58.438,00:09:03.143 administrator, or Company administrator if you use the API's, and this administrator 00:09:03.143,00:09:07.747 can do anything. Of course, you don't want all your administrators to be able to do 00:09:07.747,00:09:12.652 anything, um, so there are also limited administrator accounts, you have the application 00:09:12.652,00:09:17.624 administrator, authentication administrator, exchange administrator, etcetera and they 00:09:17.624,00:09:24.597 all have their limited part which they can manage. Now, at the time that I made these 00:09:24.597,00:09:29.736 slides, um, the roles were fixed. You couldn't change that. Actually in the past week, um, 00:09:29.736,00:09:35.141 Microsoft started to change that, so um, you see that cloud is changing all the time, and 00:09:35.141,00:09:39.579 they are actually looking now into uh, a way that you can create your own roles, but I 00:09:39.579,00:09:44.684 haven't played with that yet, so let's assume that um, these fixed roles are all there is for 00:09:44.684,00:09:49.689 the sake of this presentation. And now we're talking about applications, and I think this 00:09:52.559,00:09:58.398 the most confusing part of Azure AD. It took me a long time before I finally understood how 00:09:58.398,00:10:05.205 these work and it's also because the documentation is not really clear on this and once again 00:10:05.205,00:10:10.543 there's a, a big terminology difference between the documentation, the API that are 00:10:10.543,00:10:16.149 available, and what you can see in the Azure portal. And these applications have a very complex 00:10:16.149,00:10:22.956 permission system. So, what is an application in Azure? Well, about everything. I mean, the 00:10:22.956,00:10:28.995 Microsoft Graph, which is an API, is an application in everyone's Azure AD. The Azure 00:10:28.995,00:10:35.535 Portal is also a registered application in the Azure AD that your using. In fact, there are 00:10:35.535,00:10:40.540 about 200 applications and associated service principals in um, every Office 365 00:10:42.542,00:10:47.847 installation. So that's a lot of stuff that is in there by default and you can do quite 00:10:47.847,00:10:52.952 some interesting things with this. So, when I say application, there are actually 00:10:52.952,00:10:58.958 two parts. And if we're looking at the simplest case, which is an application which is defined 00:10:58.958,00:11:05.498 in your own Azure AD, then there is the application definition and a service principal. And the 00:11:05.498,00:11:10.403 application definition basically defines what the application is about, you give it a name, 00:11:10.403,00:11:16.409 etcetera, and the service principal is the uh, actual principal in our directly which 00:11:16.409,00:11:22.215 gets the rights and has the uh, rights to perform actions in your directory. So, there are 00:11:22.215,00:11:28.054 two parts of an application and in this talk, I'll, if I say application, I usually mean the 00:11:28.054,00:11:33.293 definition and if I say service principal, I mean the kind of account that is present in the 00:11:33.293,00:11:39.599 Azure AD. So, because cloud is multitenant, you can have applications from another 00:11:39.599,00:11:44.504 directory in your directory. So, this is the simplest case, uh, where you have both the 00:11:44.504,00:11:48.508 application definition and the service principal in your own directory, with great 00:11:48.508,00:11:52.812 third-party applications then the definition of the application is actually in 00:11:52.812,00:11:58.084 another directory, and once you start using that application, a service principal is created in 00:11:58.084,00:12:03.022 your own directory and that's, is the presence of that application in your directory. 00:12:07.026,00:12:13.533 For Office 365, Microsoft as some internal um, tenants in which all these applications are 00:12:13.533,00:12:20.373 defined. And in your Office 365 directory, all the service principals are created. So, once 00:12:20.373,00:12:26.913 again, it's a split between definition of the application and the service principals. Now, 00:12:26.913,00:12:33.786 applications can have privileges and there are basically two kinds of privileges. In the 00:12:33.786,00:12:38.858 Portal, they are called uh, delegated permissions and application permissions. And 00:12:38.858,00:12:44.864 delegated permissions are only used when a user is actively signed in in the application. 00:12:44.864,00:12:50.370 However, application permission is something the application has statically and it can use it at 00:12:50.370,00:12:55.375 any time. So, these privileges actually assigned to the server's principal portion of 00:12:58.911,00:13:03.850 the application. Now the permission model is as follows. Um, every application defines 00:13:05.918,00:13:12.258 its own permissions which can then be granted to other applications. And, like, 00:13:12.258,00:13:18.431 commonly used uh, are the Microsoft Graph and the Azure AD Graph and they define 00:13:18.431,00:13:22.935 permissions such as directory dot reads, which gives an application or a user, 00:13:22.935,00:13:28.241 permissions to read attributes in a directory and these can then be granted to other service 00:13:28.241,00:13:33.246 principals. So, let's look at uh, how this looks in the Portal first. So, here we have the 00:13:35.682,00:13:40.887 application definition and we see there are a couple appli- permissions defined for this 00:13:40.887,00:13:47.727 application. So, first is the Directory AccessAsUsers, AccessAsUser, which is a 00:13:47.727,00:13:53.566 delegated permission. So, once a user is sign in into this application, this application 00:13:53.566,00:13:58.571 has the right to access the directory as if it was the sign in user. There is also an 00:14:01.741,00:14:05.778 application permission here, which is um, Directory.ReadWrite.All, which 00:14:05.778,00:14:12.185 gives the application permissions to read and write to the directory. If we look at the 00:14:12.185,00:14:17.190 service principal, we see these privileges again. So, the um, the application has permissions 00:14:19.792,00:14:24.797 to read and write directory data in this case, and also uh, an admin sometimes has to grant 00:14:26.866,00:14:32.505 these privileges because by default any user can create new applications, but of course, not 00:14:32.505,00:14:37.744 every user can give these applications permissions. And sometimes the high value or high 00:14:37.744,00:14:43.216 impact permissions have to be approved by an application before they can be used. Now I 00:14:43.216,00:14:48.221 created this small table to um, see how permissions actually work versus how um, the 00:14:50.690,00:14:55.962 Microsoft Portal, or the Azure Portal tells you how they work. So, on the right is the Portal 00:14:55.962,00:15:02.802 terminology and on the left is how um, they are used in the API's, which for me is um, 00:15:02.802,00:15:08.407 conical. So, every application defines will have two permissions and application 00:15:08.407,00:15:13.913 roles and these get translated to delegated permissions and application permissions in the 00:15:13.913,00:15:18.918 portal. And, an application definition then requires uh, access to certain permissions 00:15:21.220,00:15:26.759 such as OAuth permissions, or application roles, and when an administrator approves those 00:15:26.759,00:15:33.266 permissions, these are granted to the service principal. So, you would imagine that um, we 00:15:33.266,00:15:38.504 have the Microsoft Graph application, which defines permissions. Uh, we create our 00:15:38.504,00:15:43.776 own application which needs to access the Microsoft Graph, so we set some uh, definitions that 00:15:43.776,00:15:49.315 of which API calls, or which API permission this requires, and these are then granted to the 00:15:49.315,00:15:54.320 service principal associated with our application. How this is clear, a bit. Um, and as I 00:15:59.225,00:16:05.698 said, um, Azure previously an admin has to approve these applications, so that's how it 00:16:05.698,00:16:10.703 works in the Portal. That is not necessarily how it's required to work. So, normally you add 00:16:13.139,00:16:18.311 permissions in the application definition and an admin then approves the permissions. 00:16:18.311,00:16:24.884 However, if you use the API's, you can directly um, assign a role to an application on the 00:16:24.884,00:16:30.990 Microsoft Graph or the Azure AD Graph. There are some API calls for that. And then when admin 00:16:30.990,00:16:37.396 looks in the applications overview in the Portal, it says, oh, there are no permissions 00:16:37.396,00:16:43.135 required for this application. Which looks great. If you now move to the service principal, 00:16:43.135,00:16:47.206 suddenly there are some permissions that the service principal has so even though the 00:16:47.206,00:16:51.444 application definition doesn't say it has these permissions, the service principal still has 00:16:51.444,00:16:57.683 them. And also, you can see that these privileges were granted by an admin, but it doesn't say 00:16:57.683,00:17:03.189 which admin. It just says granted by an administrator. There is not really a way to 00:17:03.189,00:17:07.126 see, hey, who was this administrator that assigned these permissions without 00:17:07.126,00:17:12.131 actually putting them in the definition? It gets even more confusing when you look at 00:17:14.734,00:17:19.739 Microsoft applications. Because all the Office 365 applications are considered uh, first-party 00:17:22.208,00:17:28.814 applications in OAuth terms and as you see in the Portal, they don't actually have any 00:17:28.814,00:17:35.488 permissions that you can see. So, you, we are looking at Microsoft Teams Web Client here, 00:17:35.488,00:17:41.294 and it says, oh, there are no permissions for this um, service principal. Okay that's great, so 00:17:41.294,00:17:47.700 it doesn't have any privileges, you'd think. But when I sign in into Microsoft Teams, I get 00:17:47.700,00:17:53.606 access web token which uh, if you decode it, contains the privileges that were granted to 00:17:53.606,00:17:58.210 this application. And you suddenly see that this application does in fact have 00:17:58.210,00:18:03.416 permissions. So, in the scope variable of the access web token, um, you see this 00:18:03.416,00:18:08.387 application can actually send emails, its- it can read my information and it can write to 00:18:08.387,00:18:13.392 my calendar. And it has these privileges on the Outlook API. And as you see, this is actually 00:18:16.062,00:18:22.268 the same application that we were just looking at, the Microsoft Teams Web Client. So, 00:18:22.268,00:18:28.708 why does this all matter? There are some admin roles uh, which allow an admin to manage all the 00:18:28.708,00:18:32.378 applications in a directory. Such as the Global Administrator, of course they 00:18:32.378,00:18:36.882 can do that because they can manage anything. Or the Application Administrator or 00:18:36.882,00:18:42.121 Cloud Application Administrator. So, these administrators can assign credentials to 00:18:42.121,00:18:47.193 applications or route it to the service principal of the applications, and then they can 00:18:47.193,00:18:53.799 log in as that service principal using those credentials. So, if we compromise an admin account 00:18:53.799,00:19:00.573 in Azure AD, we can, um, assign credentials to an application, um, and then we can log in as 00:19:00.573,00:19:05.845 that application. And of course, since applications are uh, not humans, there are no 00:19:05.845,00:19:12.485 multifactoral options for service principals. Also, if there is an application that 00:19:12.485,00:19:16.655 actually has more rights than the application administrator, it is possible to escalate 00:19:16.655,00:19:22.962 privileges this way. Actually, in previously, there used to be some default Office 365 00:19:22.962,00:19:28.034 applications which had roles assigned, so it had more permissions than the application 00:19:28.034,00:19:32.338 administrator had. So, the application administrator could just assign credentials to the 00:19:32.338,00:19:36.809 application and then perform actions that he previously couldn't do. This has been fixed 00:19:36.809,00:19:43.649 by Microsoft, by the way. So just to give an example how this works, um, you can use 00:19:43.649,00:19:49.255 PowerShell to create a new certificate and then assign certificate credentials to a 00:19:49.255,00:19:55.594 service principal. Then you can log in as a service principal, in this case I'm using the Azure 00:19:55.594,00:20:02.268 AD PowerShell Module, and you see I'm signed in with a certificate on the directory. 00:20:02.268,00:20:08.407 Now if perform any action, such as adding a user to a group, then the login will show that 00:20:08.407,00:20:14.146 this was performed by the application rather than um, the admin that assigned the 00:20:14.146,00:20:19.985 credentials to the, to the application. So, if I assign credentials to an application, 00:20:19.985,00:20:25.925 and then I wait x amount of time, that the login kind of rolls over and there are no more 00:20:25.925,00:20:32.498 logs that I actually modified the application, there is no way to see which user assigned these 00:20:32.498,00:20:37.503 credentials and this actually performs these actions. Furthermore, a bit of a twist, 00:20:42.675,00:20:48.881 um, so application admins by default can't assign roles to the application that allow it to 00:20:48.881,00:20:53.819 interact with the Microsoft Graph or the Azure AD Graph. If they could, they could just 00:20:53.819,00:20:58.290 assign the permissions to the application which they don't have themselves, which would be 00:20:58.290,00:21:04.296 privilege escalation again. But this is not possible. But what they can do is assign OAuth 00:21:04.296,00:21:09.068 permissions, or delegated permissions if you use the Portal, but these are only valid 00:21:09.068,00:21:14.073 when the user is using the application. But, of course, you can exploit this. Um, if you add 00:21:16.308,00:21:20.479 the user impersonation permissions to the application and then phish a Global 00:21:20.479,00:21:25.384 Administrator to actually sign into its application, you can perform any actions that the 00:21:25.384,00:21:30.389 Global Administrator could do. And then here is a small demo. Let's hope it works. So, we sent 00:21:33.425,00:21:40.032 an email to the Global admin here and here's the link. He clicks on it and then we 00:21:40.032,00:21:45.037 captured his access token. So, this is an access token for the um, Microsoft Graph and with 00:21:47.439,00:21:53.445 this access token, I could perform all kinds of actions. And you can see here that actu ñ 00:21:53.445,00:22:00.119 this token has privileges to access directory as if it was the user. So, with this token, 00:22:00.119,00:22:05.491 um, I can perform all kinds of actions and I can um, modify my own role, I can give myself 00:22:05.491,00:22:10.496 permissions, I can add users to group and all that kind of stuff. And, um, as you saw, this 00:22:13.098,00:22:17.236 didn't require any consent from the admin, that's because the Application admin already 00:22:17.236,00:22:22.241 approved the privileges for the application. You can make this even more fun. Um, so, because 00:22:26.679,00:22:31.951 there are like 200 built-in Office 365 applications, that the Application admin can also 00:22:31.951,00:22:36.956 modify. And, if you assign a read ñ a write listed URL that this application can use to sign 00:22:40.226,00:22:46.765 users in, and you then assign your own URL, you can use the built-in permissions for the 00:22:46.765,00:22:51.770 application to actually uh, phish the admin again. And if you look at the logs, uh, this 00:22:55.140,00:23:01.247 actually doesn't show anything suspicious, because if, if an admin is using Office 365, um, 00:23:01.247,00:23:06.185 these kind of sign ins appear all the time and the login doesn't specify which URL the 00:23:06.185,00:23:12.424 admin was redirected to. So, you can just add your own redirect URL, uh, get a token, and in the 00:23:12.424,00:23:17.329 login it won't actually say anything, apart, of course, that you modified the application, 00:23:17.329,00:23:22.334 but the sign in log is kind of useless here. So, there was a bit about Azure applications. 00:23:26.805,00:23:33.479 Um, I'm gonna take a little ide-step and have a look at multifactor authentication. So 00:23:33.479,00:23:38.917 of course, um multifactor authentication is good and everyone should do it. Um, and 00:23:38.917,00:23:45.924 there are multiple options for this. So, the authenticator app is one of the options, um, it's 00:23:45.924,00:23:49.628 kind of similar to Google authenticator, when you have like a code that you dis-display 00:23:49.628,00:23:55.534 and you use that as the second factor. You can also have notification that kind of pops 00:23:55.534,00:24:00.939 up on your phone that you can approve the sign in, and then of course, the good old uh, text 00:24:00.939,00:24:06.412 message that I think has been reiterated, uh, a million times already that these can be 00:24:06.412,00:24:11.350 intercepted and are insecure and stuff. So, I didn't look at that. But there is also the 00:24:11.350,00:24:18.157 option to authenticate with a voice call. And this works as follows. Um, you have your phone 00:24:18.157,00:24:24.296 and are registered to Azure AD and then um, Microsoft calls you, and in order to approve the 00:24:24.296,00:24:29.301 sign in, you have to press the hash sign or the pound sign. Now, I thought, okay, what about 00:24:31.503,00:24:36.508 I break into someone's voicemail, and I change his welcome message to the tone of a 00:24:38.577,00:24:43.849 pound sign, because these signs are just specific sound frequencies. So, if you can 00:24:43.849,00:24:49.655 record it in your voicemail message, then, um, potentially Azure would call you and hear 00:24:49.655,00:24:55.627 that same tone. Now you make sure that the phone is occupied so when you are performing your 00:24:55.627,00:24:57.629 sign in, you call the victim and make sure their phone can't answer it and the talk, and it 00:24:57.629,00:24:59.631 will go to voicemail. You sign in using the passwords that you phished previously or you found 00:24:59.631,00:25:04.570 it in a leak somewhere, and AzuraAD will get redirected to voicemail and it will 00:25:13.779,00:25:18.784 authenticate you. And if you think um, can I actually break into someone's voicemail and how 00:25:21.053,00:25:26.558 hard is that, uh, you should see this talk from last year. Um, this guy made like a Python 00:25:26.558,00:25:32.197 script to brute force all the ping codes on voicemails, which is really cool. So, here is a 00:25:32.197,00:25:37.202 small demo. So, I changed my voicemail message, I hope you can hear this. This is the sound 00:25:46.178,00:25:51.183 of the pound sign, now I put my phone airplane mode and I enter the password for the user that I 00:25:53.552,00:25:58.557 somehow obtained and it will say okay, I sent you a text message, but you can also choose to call 00:26:02.327,00:26:07.533 the phone. And now Azure is calling the phone and hopefully getting redirected to voicemail. 00:26:07.533,00:26:12.538 And we have to wait for a little bit. And there it goes. [Applause] So, if you do 00:26:24.583,00:26:29.922 compromise someone's voicemail and you change the message, you can potentially bypass his multi 00:26:29.922,00:26:36.228 factor authentication. I reported this to Microsoft and they're saying, okay, yeah, um, 00:26:36.228,00:26:41.066 we see the issue here, but you still need to compromise someone's voicemail first and 00:26:41.066,00:26:45.437 it's kind of a post- post application technique, so we will be fixing this at some 00:26:45.437,00:26:52.144 point, but not right now. So, I haven't tested this recently, but I assume this still works. 00:26:52.144,00:26:57.983 So, if you do allow voice messages for authentication in your tenant, you may think, you 00:26:57.983,00:27:02.921 may want to think about disabling that. Okay, up next, um, linking up the cloud and 00:27:06.525,00:27:11.697 on-premise, cause um, of course, you don't have all your infrastructure in the cloud yet. 00:27:11.697,00:27:16.702 You also have a part on-prem and you would like to combine the two. And previously we talked 00:27:20.639,00:27:24.276 about the Application Administrator and how he can backdoor stuff, escalate 00:27:24.276,00:27:29.648 privileges and stuff, but let's assume that this account is protected with MFA and we can't 00:27:29.648,00:27:34.920 hack into his voicemail. So, what about the on-premise infrastructure? If you want to 00:27:34.920,00:27:40.192 synchronize Azure AD and On-premise AD, that's usually done through a utility called 00:27:40.192,00:27:45.197 Azure AD connect and you install that on-premise and you, that synchronizes at the directory 00:27:47.432,00:27:53.238 redial to Azure AD. And depending on which methods, uh, you use to authenticate your 00:27:53.238,00:27:57.876 on-premise using Azure AD, you can for example use Password Hash Synchronization, so that 00:27:57.876,00:28:02.581 they can sign in with the same passwords on-premise in Azure AD, or you can use, um, 00:28:02.581,00:28:09.421 Federation with ADFS. Both require this Azure AD connect tool. And the account for this 00:28:09.421,00:28:15.527 tool in Azure AD has quite some privileges, which is all very nicely documented, by the way. 00:28:15.527,00:28:19.665 So, if you look at the documentation, you see the directions synchronization 00:28:19.665,00:28:24.670 accounts. And we can see that it has permissions to update service principals and to assign 00:28:26.805,00:28:31.944 credentials to service principals. And these were just the applications that we abused 00:28:31.944,00:28:36.949 with the Application Administrator account. So, um, briefly some interesting things 00:28:41.019,00:28:45.891 about the sync account. If you use Password Hash Synchronization, then the sync 00:28:45.891,00:28:50.896 account will have access to all the password hashes on-premise, so that basically makes it 00:28:50.896,00:28:56.668 domain admin, cause you can use synchronized, or synchronize the password hash of the kbtt 00:28:56.668,00:29:03.175 account and then you can comprise on-premise. And, of course, in the cloud it also has 00:29:03.175,00:29:08.914 high privileges as we just saw from documentation. And, the access in the cloud may not just 00:29:08.914,00:29:14.953 be limited to the single AD domain that you're synchronizing. So, there is some 00:29:14.953,00:29:21.393 potential for privilege escalation here. Um, I wrote a tool to extract the Azure AD 00:29:21.393,00:29:26.298 connect passwords from the on-premise server. There are some, several protections for 00:29:26.298,00:29:31.603 these passwords uh, about which I presented at Troopers earlier this year, so if you are 00:29:31.603,00:29:36.308 interested in the technical stuff, uh, check out the link below. But basically, I wrote 00:29:36.308,00:29:41.947 three different tools that depending on your scenario can be used to dump the credentials 00:29:41.947,00:29:48.186 off this account and some work over the network while some others uh, can be used in 00:29:48.186,00:29:54.192 example, for a global strike through um, assembly loading and these tools get your, get the 00:29:54.192,00:29:59.031 both the on-premise passwords, any cloud password from the server where AD connect is 00:29:59.031,00:30:04.036 installed. So, once we have these credentials, there is some fun stuff we can do. We can dump 00:30:08.540,00:30:12.277 all the on-premise password hashes if the organization is using Password Hash 00:30:12.277,00:30:18.784 Synchronization. We can also use this account to log into the Azure portal, don't ask me why, 00:30:18.784,00:30:24.956 but this works. It's a user account, so you can just log in. And we can bypass conditional 00:30:24.956,00:30:29.528 access policies since there are some conditional access polices to require multifactor 00:30:29.528,00:30:35.367 authentication for admin accounts, but the sync account is of course, excluded from this 00:30:35.367,00:30:41.406 since it's not a human account and this account do multifactor. Just like the Application 00:30:41.406,00:30:46.545 Administrator, we can add credentials to service principals and backdoor stuff 00:30:46.545,00:30:51.550 and do all kinds of fun things, and we can also modify service principal properties. So, we can 00:30:54.252,00:30:59.991 change the authentication URL of a Microsoft application, phish an admin, and escalate to Global 00:30:59.991,00:31:04.930 admin privileges. And, there are some more things where service principles are used and that's 00:31:07.432,00:31:12.437 where the connection between Azure Resource manager and Azure AD comes in. So, once again 00:31:14.773,00:31:19.778 returning to this picture, um, Azure AD is the authentication and, and identification access 00:31:22.080,00:31:27.385 management for both Office 365 and for the Azure role-based access controls in Azure 00:31:27.385,00:31:32.924 Resource manager. This means that if you are a Global Administrator, you can um, by 00:31:32.924,00:31:37.929 design, also access all the um, virtual machines and network infrastructure that is stored in 00:31:40.031,00:31:45.036 Azure Resource manager. And, you can also assign privileges to manage Azure resources to 00:31:47.806,00:31:53.211 service principals. Which, can be managed by Application Administrators or by the 00:31:53.211,00:31:58.350 on-premise sync account. And if you have an application such as Terraform, which is used to 00:31:58.350,00:32:03.088 automatically provision cloud resources, then it obviously needs high privileges in order 00:32:03.088,00:32:07.659 to create and modify delete resources and this is, this can be done with service principals. 00:32:10.462,00:32:15.200 So, if you have act control over the on-premise sync account, you can assign credentials to 00:32:15.200,00:32:20.705 service principals which have rights in Azure Resource manager and you can also control all the 00:32:20.705,00:32:25.710 cloud resources. An example which actually uses this is Azure DevOps. And what is Azure 00:32:30.982,00:32:37.856 DevOps? Azure DevOps is uh, DevOps tooling and it's in some ways kind of like Git hook. You 00:32:37.856,00:32:43.762 can use source code managements, you can collaborate on projects, um, you can have automatic build 00:32:43.762,00:32:50.335 pipelines and automated deployment. It's the whole DevOps, um, toolkit. Now have a 00:32:50.335,00:32:57.242 look at Azure DevOps pipelines. Um, this is kind of cool because Microsoft makes this feature 00:32:57.242,00:33:02.080 available for free to for example, open source project and you can automatically build your 00:33:02.080,00:33:07.018 codes through, for example, Git It intergration and when you push your, a new version, it 00:33:07.018,00:33:12.023 will be automatically built on hosted resources in Azure. An example of this is my own Azure 00:33:14.259,00:33:19.464 AD connect tool. I have connected that to Azure pipelines so as soon as I create 00:33:19.464,00:33:25.170 a, put the new comment in there, um, the, the net binaries will get automatically built on Azure 00:33:25.170,00:33:30.175 and you can download this. So, there are multiple ways to change the definition of a build 00:33:35.213,00:33:40.218 pipeline. Previously, um, when I looked at this, only the uh, agree could be used to change 00:33:43.255,00:33:49.327 the, the build definition, but, um, I think earlier this year or at the end of last year, a new 00:33:49.327,00:33:55.867 feature was added which allowed pipelines as code in YAML files. So, then the pipeline definition 00:33:55.867,00:34:00.805 is part of the repository where the code is in. And it kind of looks like this. So, this is a 00:34:02.807,00:34:08.613 YAML file with the um, build definition. It's says, okay when I push a new uh, comment to 00:34:08.613,00:34:13.618 master, uh, you build it using the hosted official Studio 2017 profile. You can provide, you 00:34:15.921,00:34:20.926 can set up all build steps in order to um, do stuff with this. So, let's talk about a 00:34:24.195,00:34:30.635 hypothetical scenario. And we have a DevOps team and a team, a member of the team wants to 00:34:30.635,00:34:37.609 automatically publish the built artifacts so for example, executables, uh, to Azure using 00:34:37.609,00:34:43.815 Blob storage. Blob storage is kind of like S3 in AWS. It can store all kinds of stuff in 00:34:43.815,00:34:50.322 there. So, he links up Azure Resource manager with Azure DevOps and actually it's nice. 00:34:50.322,00:34:55.360 But, from there, which you can select your subscription and then you click authorize and 00:34:55.360,00:35:00.298 then soon the lead or two are connected. Now, there is a new user, or a new team member at 00:35:03.234,00:35:09.574 the company and this team member needs minimal privileges to uh, contribute his codes to the 00:35:09.574,00:35:15.013 repository. Because he is a newer member, there, we don't give him acc- any special 00:35:15.013,00:35:21.753 privileges to, for example, alter the build definitions. And adding a new user isn't exactly 00:35:21.753,00:35:28.059 uh, isn't exactly a nice person cause the first thing he does is actually editing that build 00:35:28.059,00:35:33.064 definition in the code and then pushing that change to, uh, to the repository. So, even though 00:35:36.067,00:35:41.272 he didn't have privileges to edit the pipelines, because the pipeline is part of the codes, 00:35:41.272,00:35:46.277 this user can still edit it. And, meanwhile, in um, a completely unrelated Azure VM, 00:35:49.481,00:35:54.486 which is not related to the source code at all, the following happens. If the video 00:35:56.888,00:36:01.826 plays. Yes. Oh, that's a Notepad. How did Notepad get there? I thought we were editing 00:36:05.230,00:36:10.235 source code? So, what happens here? Um, remember that I said that we allot um a copy to Azure 00:36:15.573,00:36:21.613 Blob storage for the artifacts? Well there's uh, a task for that which is called Azure File Copy 00:36:21.613,00:36:28.153 and I've edited this build pipeline a little so what it does its, it's gets the Azure 00:36:28.153,00:36:33.158 file copy script and it vectors that to dump some of the authentication data that is used 00:36:35.360,00:36:41.666 to link Azure Research manager to Azure DevOps and it will then put the backdoor code back in 00:36:41.666,00:36:46.671 the original PowerShell thread that is used to copy the file. So, when the file gets copied, 00:36:46.671,00:36:51.676 uh, instead my code gets run, and we can gain access to some of the credentials. So, if you 00:36:53.778,00:36:58.783 look at the logs, um, we see it dumped the tenantid, service principal id, but there all um, 00:37:00.785,00:37:06.391 there all masked in astericks, because Azure DevOps doesn't let you log sensitive stuff of 00:37:06.391,00:37:11.963 course, to the logs, but if you bay 64 and code that, um, then it's all fine. So, at the bottom 00:37:11.963,00:37:15.967 you see that I dumped the authentication data and the password for the account using 00:37:15.967,00:37:20.972 bay 60, bay 64. And we can decode that and then we see you get the tenantid that is used 00:37:25.577,00:37:31.082 for Azure subscription, the service ID of the service principal that was created and 00:37:31.082,00:37:36.087 you get the service principal key, which is the password for that service principal. Now, I 00:37:38.823,00:37:44.195 was a bit confused when all this happened cause I just remembered clicking the authorize button 00:37:44.195,00:37:49.400 and I didn't really get a warning that the service principal would basically get 00:37:49.400,00:37:55.106 contributor rights on my whole Azure subscription. So, when I clicked that little button, a 00:37:55.106,00:37:59.944 new service principal was created and he got full privileges on the whole Azure 00:37:59.944,00:38:05.517 Resource manager subscription. So, it means that he can edit any virtual machines, discs, 00:38:05.517,00:38:11.990 access files, and all that kind of stuff. And, with these credentials that we just 00:38:11.990,00:38:18.763 obtained, we can log in using the Azure uh, C-line module and that password you saw before, 00:38:18.763,00:38:24.469 even though it looks, uh, like basically for encoders, it's just a very long string. So, 00:38:24.469,00:38:30.542 here I used the credentials that I dumped from Azure DevOps to actually log in on Azure 00:38:30.542,00:38:35.547 Resource manager. Now, how about the Notepad, um, I added a little extra so it is just 00:38:39.450,00:38:44.455 inline script without a new custom extension to a virtual machine in Azure and this runs a 00:38:47.392,00:38:54.098 PowerShell script which then uh, spawns Notepad. So, that's just to prove that you can actually 00:38:54.098,00:38:59.103 access those virtual machines as the highest user there is. So, can anyone edit pipelines? Um, 00:39:02.941,00:39:09.214 normally, no. Uh, the pipeline definition uh, there's a specific role required to edit 00:39:09.214,00:39:14.519 the build section of pipeline, but since the piplines move to be part of the code, anyone who 00:39:14.519,00:39:20.091 can edit the code could actually edit the pipeline. I reported that to Microsoft and that is 00:39:20.091,00:39:25.396 fixed in the latest version of Azure DevOps, so I didn't retest this yet, but uh, this shouldn't 00:39:25.396,00:39:29.968 be possible anymore and hopefully now the edit pipeline role is actually enforced also 00:39:29.968,00:39:34.973 on the source code in the repository. A few conclusions about this. Um, be careful with 00:39:39.043,00:39:45.216 integrations. Look - have a look at which privileges to actually get on your subscription and um, 00:39:45.216,00:39:50.488 how they are used because anyone that can edit your build pipelines can access the secrets 00:39:50.488,00:39:56.327 that are exposed to the build pipeline and if you enable secrets for public repositories 00:39:56.327,00:40:02.400 and you allow, um, you allow builds on pull requests, then anyone who creates a pull 00:40:02.400,00:40:06.838 request can actually extract your secrets off any service that your integrate with Azure 00:40:06.838,00:40:11.809 DevOps. Um, though this is disabled by default and this is documented uh, pretty well, I 00:40:11.809,00:40:16.781 think. At the link at the bottom it actually say Warning, anyone who can edit your build pipeline 00:40:16.781,00:40:22.520 can access your secrets if you enable this. You don't want this. Some general conclusions. 00:40:22.520,00:40:29.160 Um, I think cloud can be beautiful. It definitely allows us to do a lot of things that we 00:40:29.160,00:40:34.165 couldn't do before, but all your stuff is on the internet and you will have to uh, secure it 00:40:36.301,00:40:43.074 yourself because not everything is secure, by design, and especially enable MFA for all 00:40:43.074,00:40:48.279 your sensitive users because uh, 99 percent of the cloud compromises are users that 00:40:48.279,00:40:53.284 didn't have MFA enabled. And if you have software Azure service, um, it does take away your need 00:40:56.020,00:41:01.559 to patch manually. You always have the latest patches, you always have the latest features, 00:41:01.559,00:41:06.097 but you also have the latest vulnerabilities that got introduced by those fancy new 00:41:06.097,00:41:11.002 features. Especially in Azure DevOps case, if you really lock down your permissions, and then 00:41:11.002,00:41:16.641 suddenly there is a new feature which uh, changes that, then you have to be uh, aware and redo 00:41:16.641,00:41:21.512 your um, risk calculation and sometimes there may be a vulnerability that makes your 00:41:21.512,00:41:28.186 security sudden ñ suddenly a bit more insecure. And of course, there is uh, a full trust 00:41:28.186,00:41:33.991 implied in the vendor from who you are renting your cloud services, so um, you do have to 00:41:33.991,00:41:38.996 trust that they are actually doing everything correctly and following best practices. So, 00:41:41.332,00:41:46.337 this was I'm In Your Cloud and thank you for attending. [Applause]