From efd6dbb4655e1f43beb7a8b3b0b60798d3fc2d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Notin?= Date: Wed, 15 Mar 2023 18:25:11 +0100 Subject: [PATCH] T098: accept UserPrincipalName for the "user_principal_name" argument In Azure AD a "user principal name" can be interpreted as the "name of a principal of type user" or as the "UserPrincipalName (UPN)" user attribute! But most people will expect the second meaning. Which is confusing since this test actually expects to see the user display name in this attribute. I think there was a confusion with the sibling test which is for "service principal", so for which the argument to designate it by name is "service_principal_name". With this change, there is no regression while being compatible with people passing a UPN to this argument. --- atomics/T1098/T1098.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/atomics/T1098/T1098.yaml b/atomics/T1098/T1098.yaml index a4f6598d..1a832c77 100644 --- a/atomics/T1098/T1098.yaml +++ b/atomics/T1098/T1098.yaml @@ -151,7 +151,7 @@ atomic_tests: type: string default: p4sswd user_principal_name: - description: Name of the targeted user (user principal) + description: Display Name, or User Principal Name, of the targeted user principal type: string default: SuperUser role_name: @@ -172,7 +172,7 @@ atomic_tests: $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "#{username}", $Pword Connect-AzureAD -Credential $Credential - $user = Get-AzureADUser -Filter "DisplayName eq '#{user_principal_name}'" + $user = Get-AzureADUser -Filter "DisplayName eq '#{user_principal_name}' or UserPrincipalName eq '#{user_principal_name}'" if ($user -eq $null) { Write-Warning "User not found"; exit } $role = Get-AzureADDirectoryRole -Filter "DisplayName eq '#{role_name}'" if ($role -eq $null) { Write-Warning "Role not found"; exit } @@ -184,7 +184,7 @@ atomic_tests: $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "#{username}", $Pword Connect-AzureAD -Credential $Credential -ErrorAction Ignore - $user = Get-AzureADUser -Filter "DisplayName eq '#{user_principal_name}'" + $user = Get-AzureADUser -Filter "DisplayName eq '#{user_principal_name}' or UserPrincipalName eq '#{user_principal_name}'" if ($user -eq $null) { Write-Warning "User not found"; exit } $role = Get-AzureADDirectoryRole -Filter "DisplayName eq '#{role_name}'" if ($role -eq $null) { Write-Warning "Role not found"; exit } @@ -286,7 +286,7 @@ atomic_tests: type: string default: p4sswd user_principal_name: - description: Name of the targeted user (user principal) + description: Display Name, or User Principal Name, of the targeted user principal type: string default: SuperUser role_name: @@ -311,7 +311,7 @@ atomic_tests: $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "#{username}", $Pword Connect-AzAccount -Credential $Credential - $user = Get-AzADUser | where-object {$_.DisplayName -eq "#{user_principal_name}"} + $user = Get-AzADUser | where-object {$_.DisplayName -eq "#{user_principal_name}" -or $_.UserPrincipalName -eq "#{user_principal_name}" } if ($user -eq $null) { Write-Warning "User not found"; exit } $subscription = Get-AzSubscription | where-object {$_.Name -eq "#{subscription}"} if ($subscription -eq $null) { Write-Warning "Subscription not found"; exit } @@ -326,7 +326,7 @@ atomic_tests: $Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "#{username}", $Pword Connect-AzAccount -Credential $Credential -ErrorAction Ignore - $user = Get-AzADUser | where-object {$_.DisplayName -eq "#{user_principal_name}"} + $user = Get-AzADUser | where-object {$_.DisplayName -eq "#{user_principal_name}" -or $_.UserPrincipalName -eq "#{user_principal_name}" } if ($user -eq $null) { Write-Warning "User not found"; exit } $subscription = Get-AzSubscription | where-object {$_.Name -eq "#{subscription}"} if ($subscription -eq $null) { Write-Warning "Subscription not found"; exit }