Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1552: Unsecured Credentials #3043

Open
Viraj05-cr7 opened this issue Jan 28, 2025 · 1 comment
Open

T1552: Unsecured Credentials #3043

Viraj05-cr7 opened this issue Jan 28, 2025 · 1 comment

Comments

@Viraj05-cr7
Copy link

Authenticate to Azure using interactive login

Write-Host "Please log in to your Azure account...";
Connect-AzAccount;

Initialize arrays to collect results

$ExposedSecrets = @();
$KeyVaultIssues = @();
$AppSettingsIssues = @();

1. Check Service Principal Secrets

Write-Host "Checking Service Principals for Exposed Secrets...";
try {
$ServicePrincipals = Get-AzADServicePrincipal -ErrorAction Stop;
foreach ($Principal in $ServicePrincipals) {
$Secrets = Get-AzADAppCredential -ObjectId $Principal.Id -ErrorAction SilentlyContinue;
if ($Secrets -and ($Secrets | Where-Object { $.EndDate -gt (Get-Date) })) {
Write-Host "Service Principal: $($Principal.DisplayName) has active credentials.";
$ExposedSecrets += $Principal;
}
}
} catch {
Write-Host "Error checking Service Principals: $
";
}

2. Check Azure Key Vault for Exposed Secrets

Write-Host "Checking Azure Key Vault for Accessible Secrets...";
try {
$KeyVaults = Get-AzKeyVault -ErrorAction Stop;
foreach ($Vault in $KeyVaults) {
$Secrets = Get-AzKeyVaultSecret -VaultName $Vault.VaultName -ErrorAction SilentlyContinue;
if ($Secrets.Count -gt 0) {
Write-Host "Key Vault: $($Vault.VaultName) has $($Secrets.Count) secrets.";
$KeyVaultIssues += $Vault;
}
}
} catch {
Write-Host "Error checking Key Vaults: $_";
}

3. Check App Service Application Settings

Write-Host "Checking App Services for Exposed App Settings...";
try {
$AppServices = Get-AzWebApp -ErrorAction Stop;
foreach ($App in $AppServices) {
$AppSettings = Get-AzWebAppSettings -ResourceGroupName $App.ResourceGroup -Name $App.Name -ErrorAction SilentlyContinue;
if ($AppSettings) {
$CredentialsFound = $AppSettings.Properties.Keys | Where-Object { $_ -match "password|secret|key" };
if ($CredentialsFound) {
Write-Host "App Service: $($App.Name) has potentially exposed credentials in App Settings.";
$AppSettingsIssues += $App;
}
}
}
} catch {
Write-Host "Error checking App Services: $_";
}

Summary of Results

Write-Host "`n--- Simulation Complete ---";
Write-Host "Exposed Service Principal Secrets: $($ExposedSecrets.Count)";
Write-Host "Key Vaults with Accessible Secrets: $($KeyVaultIssues.Count)";
Write-Host "App Services with Exposed App Settings: $($AppSettingsIssues.Count)";

@Viraj05-cr7
Copy link
Author

Combine all the segmented snippets as one full code in PowerShell, you'll get the results...

Run this test using a low or no privilege account to find the data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant