ENTERPRISE

Windows 7 : Interacting with the Built-In Security Features - ACCESSING APPLOCKER (part 2) - Reading AppLocker Entries

2/27/2014 1:50:48 AM

3. Reading AppLocker Entries

Reading the AppLocker entries means locating the entries in the registry and then parsing them. You have no way of knowing how many entries the registry will contain (if it contains any entries at all). Listing 2 parses the entries using the assumption that the registry might not contain any entries.

Example 2. Reading the AppLocker entries from a known location
private void btnList_Click(object sender, EventArgs e)
{
// Clear the previous entries.
lstEntries.Items.Clear();

// Open the AppLocker registry key.
RegistryKey AppLock =
Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Policies\Microsoft\Windows\SrpV2");

// Obtain the kinds of entries that the application can create.
String[] EntryTypes = AppLock.GetSubKeyNames();

// Process each entry in turn.
foreach (String EntryType in EntryTypes)
{
// Display the entry type.
lstEntries.Items.Add(EntryType);

// Open the associated subkey.
RegistryKey ThisType = AppLock.OpenSubKey(EntryType);

// Obtain a list of entries within the type.
String[] AppLockEntries = ThisType.GetSubKeyNames();

// Process each of the individual entries.
foreach (String AppLockEntry in AppLockEntries)
{
// Display the individual entry GUID.
lstEntries.Items.Add("\t" + AppLockEntry);

// Open the individual entry.
RegistryKey ThisEntry = ThisType.OpenSubKey(AppLockEntry);

// Obtain the XML value of the entry.
XmlDocument Entry = new XmlDocument();
Entry.LoadXml(ThisEntry.GetValue("Value").ToString());

// Obtain the root element.
XmlNode TheRule = Entry.FirstChild;

// Display the overall rule values.
lstEntries.Items.Add("\t\tName: " +
TheRule.Attributes["Name"].Value);
lstEntries.Items.Add("\t\tDescription: " +
TheRule.Attributes["Description"].Value);
lstEntries.Items.Add("\t\tGroup or User SID: " +
TheRule.Attributes["UserOrGroupSid"].Value);
lstEntries.Items.Add("\t\tAction: " +
TheRule.Attributes["Action"].Value);

// Obtain the condition element.


XmlNode Conditions = TheRule.FirstChild;

// Examine the conditions.
foreach (XmlNode Condition in Conditions)
{
// Display the attributes for each condition.
foreach (XmlAttribute Specification in Condition.Attributes)
{
// Show the attribute information.
lstEntries.Items.Add("\t\t\t" + Specification.Name +
": " + Specification.Value);
}
}

// Close the individual entry.
ThisEntry.Close();

// Add a space.
lstEntries.Items.Add("");
}

// Close the entry type.
ThisType.Close();

// Add a space.
lstEntries.Items.Add("");
}

// Close the main key.
AppLock.Close();
}


The example begins by clearing the previous list box entries. It then opens the one key that you can depend on to find AppLocker entries, assuming the target system supports AppLocker. The AppLock object contains a handle to the registry entry after the code calls OpenSubKey() using the Registry.LocalMachine property. The code calls GetSubKeyNames() to obtain a list of entries and places them in EntryTypes (the array should contain the Dll, Exe, Msi, and Script key names). Because Microsoft could decide to change the format of the registry entries, the code uses a foreach loop to parse through whatever entries appear in the EntryTypes String array.

At this point, the code opens a subkey, such as Dll, for processing by calling OpenSubKey(). The code uses the GetSubKeyNames() call to place a list of GUID entries in AppLockEntries. It uses a second foreach loop to process each of the GUID entries that appear as subkeys of EntryType.

As previously mentioned, each GUID entry contains a value named Value that contains XML describing the rule used to define an exception. The code begins by creating an XmlDocument object, Entry, and placing the XML in it by calling LoadXml(). The code processes the XML as you would any XML document. It begins by accessing the <FilePublisherRule> or other rule element, listing the attributes in this element, and then working through the <Conditions> element. The precise order of processing depends on the rule. Figure 2 shows typical output from this example.

Figure 2. The example displays any AppLocker rules configured on your system.

Other  
  •  Windows 7 : Interacting with the Built-In Security Features - WORKING WITH AUTOMATIC UPDATES (part 2)
  •  Windows 7 : Interacting with the Built-In Security Features - WORKING WITH AUTOMATIC UPDATES (part 1)
  •  Windows 8 Architecture from a Developer’s Point of View : Understanding Windows Runtime (part 5) - What’s not in Windows Runtime
  •  Windows 8 Architecture from a Developer’s Point of View : Understanding Windows Runtime (part 4) - Language Projections
  •  Windows 8 Architecture from a Developer’s Point of View : Understanding Windows Runtime (part 3) - Metadata in Windows Runtime - Namespaces
  •  Windows 8 Architecture from a Developer’s Point of View : Understanding Windows Runtime (part 2) - Metadata in Windows Runtime - Metadata Format
  •  Windows 8 Architecture from a Developer’s Point of View : Understanding Windows Runtime (part 1) - Windows Runtime Architecture Overview
  •  Windows 8 Architecture from a Developer’s Point of View : Windows 8 Development Architecture
  •  Windows 7 : Programming KMDF Hardware Driver - Mapping Resources - Code to Map Resources
  •  Windows 7 : Programming KMDF Hardware Driver - Handling Interrupts (part 2) - Deferred Processing for Interrupts
  •  
    Top 10
    Review : Sigma 24mm f/1.4 DG HSM Art
    Review : Canon EF11-24mm f/4L USM
    Review : Creative Sound Blaster Roar 2
    Review : Philips Fidelio M2L
    Review : Alienware 17 - Dell's Alienware laptops
    Review Smartwatch : Wellograph
    Review : Xiaomi Redmi 2
    Extending LINQ to Objects : Writing a Single Element Operator (part 2) - Building the RandomElement Operator
    Extending LINQ to Objects : Writing a Single Element Operator (part 1) - Building Our Own Last Operator
    3 Tips for Maintaining Your Cell Phone Battery (part 2) - Discharge Smart, Use Smart
    REVIEW
    - First look: Apple Watch

    - 3 Tips for Maintaining Your Cell Phone Battery (part 1)

    - 3 Tips for Maintaining Your Cell Phone Battery (part 2)
    VIDEO TUTORIAL
    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 1)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 2)

    - How to create your first Swimlane Diagram or Cross-Functional Flowchart Diagram by using Microsoft Visio 2010 (Part 3)
    Popular Tags
    Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8