Skip to content

Commit 3702c8b

Browse files
committed
AppControl Manager has reduced permissions for Intune
Using reduced permissions for Intune deployment to adhere to the least privilege principle. The policyID will be properly reflected to the Intune portal. Version bump. Dependency version update. Document update.
1 parent 02db48c commit 3702c8b

7 files changed

+42
-22
lines changed

AppControl Manager/AppControl Manager.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
<AssemblyName>AppControlManager</AssemblyName>
9292
<PublishAot>False</PublishAot>
9393
<ErrorReport>send</ErrorReport>
94-
<FileVersion>1.8.4.0</FileVersion>
94+
<FileVersion>1.8.5.0</FileVersion>
9595
<AssemblyVersion>$(FileVersion)</AssemblyVersion>
9696
<NeutralLanguage>en-US</NeutralLanguage>
9797
<PackageLicenseFile>LICENSE</PackageLicenseFile>
@@ -145,7 +145,7 @@
145145
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.DataGrid" Version="7.1.2" />
146146
<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.3.1" />
147147
<PackageReference Include="Microsoft.Identity.Client" Version="4.67.2" />
148-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
148+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.162">
149149
<PrivateAssets>all</PrivateAssets>
150150
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
151151
</PackageReference>

AppControl Manager/Others/Intune.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,9 @@ internal static class Intune
2222
// https://learn.microsoft.com/en-us/graph/permissions-reference
2323
private static readonly string[] Scopes = [
2424
"Group.Read.All", // For Groups enumeration
25-
"Group.ReadWrite.All", // For Groups enumeration
26-
"DeviceManagementConfiguration.ReadWrite.All",
27-
"DeviceManagementConfiguration.Read.All" ,
28-
"DeviceManagementManagedDevices.ReadWrite.All",
29-
"DeviceManagementApps.ReadWrite.All"
25+
"DeviceManagementConfiguration.ReadWrite.All" // For uploading policy
3026
];
3127

32-
3328
private const string DeviceConfigurationsURL = "https://graph.microsoft.com/v1.0/deviceManagement/deviceConfigurations";
3429

3530
private static readonly JsonSerializerOptions JsonOpt = new()
@@ -218,7 +213,7 @@ internal static async Task SignOut()
218213
/// <param name="policyName"></param>
219214
/// <returns></returns>
220215
/// <exception cref="InvalidOperationException"></exception>
221-
internal static async Task UploadPolicyToIntune(string policyPath, string? groupName, string? policyName)
216+
internal static async Task UploadPolicyToIntune(string policyPath, string? groupName, string? policyName, string policyID)
222217
{
223218

224219
DirectoryInfo stagingArea = StagingArea.NewStagingArea("IntuneCIPUpload");
@@ -236,7 +231,7 @@ internal static async Task UploadPolicyToIntune(string policyPath, string? group
236231
}
237232

238233
// Call Microsoft Graph API to create the custom policy
239-
string? policyId = await CreateCustomPolicy(authenticationResult.AccessToken, base64String, policyName);
234+
string? policyId = await CreateCustomPolicy(authenticationResult.AccessToken, base64String, policyName, policyID);
240235

241236
Logger.Write($"{policyId} is the ID of the policy that was created");
242237

@@ -317,13 +312,17 @@ private static async Task AssignPolicyToGroup(string policyId, string accessToke
317312
/// <param name="accessToken"></param>
318313
/// <param name="policyData"></param>
319314
/// <returns></returns>
320-
private static async Task<string?> CreateCustomPolicy(string accessToken, string policyData, string? policyName)
315+
private static async Task<string?> CreateCustomPolicy(string accessToken, string policyData, string? policyName, string policyID)
321316
{
322317

323318
string descriptionText = $"Application Control Policy Uploaded from AppControl Manager on {DateTime.UtcNow:yyyy-MM-dd HH:mm:ss 'UTC'}";
324319

325320
string displayNameText = !string.IsNullOrWhiteSpace(policyName) ? $"{policyName} App Control Policy" : "App Control Policy";
326321

322+
// Making sure the policy ID doesn't have the curly brackets
323+
// https://learn.microsoft.com/en-us/windows/security/application-security/application-control/app-control-for-business/deployment/deploy-appcontrol-policies-using-intune#deploy-custom-app-control-policies-on-windows-10-1903
324+
policyID = policyID.Trim('{', '}');
325+
327326
// Create the policy object
328327
Windows10CustomConfiguration customPolicy = new()
329328
{
@@ -337,7 +336,7 @@ private static async Task AssignPolicyToGroup(string policyId, string accessToke
337336
ODataType = "microsoft.graph.omaSettingBase64",
338337
DisplayName = displayNameText,
339338
Description = descriptionText,
340-
OmaUri = "./Vendor/MSFT/ApplicationControl/Policies/d41d8cd9-8f00-b204-e980-0998ecf8427e/Policy",
339+
OmaUri = $"./Vendor/MSFT/ApplicationControl/Policies/{policyID}/Policy",
341340
FileName = "Policy.bin",
342341
Value = policyData
343342
}

AppControl Manager/Package.appxmanifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Identity
1212
Name="AppControlManager"
1313
Publisher="CN=SelfSignedCertForAppControlManager"
14-
Version="1.8.4.0" />
14+
Version="1.8.5.0" />
1515

1616
<mp:PhoneIdentity PhoneProductId="199a23ec-7cb6-4ab5-ab50-8baca348bc79" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
1717

AppControl Manager/Pages/Deployment.xaml.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ await Task.Run(async () =>
181181

182182
if (deployToIntune)
183183
{
184-
await DeployToIntunePrivate(CIPFilePath, file);
184+
await DeployToIntunePrivate(CIPFilePath, policyObject.PolicyID, file);
185185

186186
// Delete the CIP file after deployment
187187
File.Delete(CIPFilePath);
@@ -353,7 +353,7 @@ await Task.Run(async () =>
353353

354354
if (deployToIntune)
355355
{
356-
await DeployToIntunePrivate(CIPFilePath, file);
356+
await DeployToIntunePrivate(CIPFilePath, policyObject.PolicyID, file);
357357
}
358358
else
359359
{
@@ -474,10 +474,11 @@ await Task.Run(async () =>
474474
StatusInfoBar.Message = $"Currently Deploying CIP file: '{file}'";
475475
});
476476

477+
string randomPolicyID = Guid.CreateVersion7().ToString().ToUpperInvariant();
477478

478479
if (deployToIntune)
479480
{
480-
await DeployToIntunePrivate(file);
481+
await DeployToIntunePrivate(file, randomPolicyID, null);
481482
}
482483
else
483484
{
@@ -777,7 +778,7 @@ private async void RefreshIntuneGroupsButton_Click(object sender, RoutedEventArg
777778

778779

779780

780-
private async Task DeployToIntunePrivate(string file, string? xmlFile = null)
781+
private async Task DeployToIntunePrivate(string file, string policyID, string? xmlFile = null)
781782
{
782783
string? groupID = null;
783784

@@ -811,7 +812,7 @@ await Task.Run(() =>
811812
});
812813

813814

814-
await Intune.UploadPolicyToIntune(file, groupID, policyName);
815+
await Intune.UploadPolicyToIntune(file, groupID, policyName, policyID);
815816
}
816817

817818

AppControl Manager/app.manifest

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!-- INFO: https://learn.microsoft.com/en-us/windows/win32/sbscs/application-manifests -->
33
<!-- INFO (for legacy UWP but its info can be used for better understanding): https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/root-elements -->
44
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
5-
<assemblyIdentity version="1.8.4.0" name="AppControlManager"/>
5+
<assemblyIdentity version="1.8.5.0" name="AppControlManager"/>
66

77
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
88
<application>

Wiki posts/App Control for Business/How To Create and Maintain Strict Kernel-Mode App Control Policy.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,27 @@ Navigate to the [Create App Control policy](https://github.com/HotCakeX/Harden-W
2727

2828
## Creating the Supplemental Policy
2929

30-
After restarting the system and relaunching the AppControl Manager, navigate to the [Create Supplemental Policy](https://github.com/HotCakeX/Harden-Windows-Security/wiki/Create-Supplemental-App-Control-Policy#create-kernel-mode-supplemental-policy) page. Scroll down to the `Kernel-mode policy` section.
30+
After restarting the system and relaunching the AppControl Manager, navigate to the [System Information](https://github.com/HotCakeX/Harden-Windows-Security/wiki/System-Information) page. Press the `Retrieve Policies` button, locate the Strict kernel-mode base policy, and remove it from the system.
31+
32+
<br>
33+
34+
<img src="https://raw.githubusercontent.com/HotCakeX/.github/8a4f06e919efc7ddd5b833203445ac9ea64b184c/Pictures/PNG%20and%20JPG/How%20To%20Create%20and%20Maintain%20Strict%20Kernel-Mode%20App%20Control%20Policy/Remove%20base%20policy.png" alt="Removing app control policy using AppControl Manager">
35+
36+
<br>
37+
38+
<br>
39+
40+
Once removed, redeploy the same base policy using the [Create App Control policy](https://github.com/HotCakeX/Harden-Windows-Security/wiki/Create-App-Control-Policy) page, but this time ensure that Audit Mode is disabled.
41+
42+
<br>
43+
44+
<img src="https://raw.githubusercontent.com/HotCakeX/.github/d14d7437685416117edda8a56496180a2047984f/Pictures/PNG%20and%20JPG/How%20To%20Create%20and%20Maintain%20Strict%20Kernel-Mode%20App%20Control%20Policy/redeploy%20base%20policy%20in%20enforced%20mode.png" alt="redeploy strict kernel mode base policy in enforced mode">
45+
46+
<br>
47+
48+
<br>
49+
50+
Now navigate to the [Create Supplemental Policy](https://github.com/HotCakeX/Harden-Windows-Security/wiki/Create-Supplemental-App-Control-Policy#create-kernel-mode-supplemental-policy) page. Scroll down to the `Kernel-mode policy` section.
3151

3252
<br>
3353

Wiki posts/App Control for Business/How To Upload App Control Policies To Intune Using AppControl Manager.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ By ensuring these permissions are in place, you can seamlessly deploy App Contro
4646

4747
## Select Policies To Deploy
4848

49-
Select one or more XML files to deploy to Intune. You have the option to deploy them as-is (unsigned) or cryptographically sign them before deployment. Each XML file will be deployed as a separate Intune configuration policy, as Intune does not allow two OMA-URI custom policies to exist within the same configuration policy.
49+
Select one or more XML files to deploy to Intune. You have the option to deploy them as-is (unsigned) or cryptographically sign them before deployment. Each XML file will be deployed as a separate Intune configuration policy for better management of policies.
5050

51-
The name defined in the XML file will become the name of the corresponding Intune configuration policy visible in the Intune portal.
51+
The name specified in the XML file will appear as the name of the corresponding Intune configuration policy in the Intune portal. Similarly, the policy ID from the XML file will be used as the uploaded policy's ID, enabling easy identification of policies on workstations after deployment.
5252

5353
You can optionally use the `Refresh` button and select a group to assign to the policies you upload to Intune.
5454

0 commit comments

Comments
 (0)