Monday, April 11, 2016

Using AppLocker

Hey everyone - Today, we are going to talk about AppLocker.  We will start with a discussion of what it is.  Then, we will talk about why you would want to use it.  Finally, we will talk about how to use it.  More after the jump...

What is AppLocker?

AppLocker is a mechanism in Windows for controlling access to applications.  It does this based on a set of rules defined by the administrator of the domain or computer.  These rules are defined on aspects of the application (usually based on its digital signature) and who is trying to use it.  On the client side, AppLocker was introduced with Windows 7.  On the server side, it was introduced in Windows Server 2008 R2.  Different versions of Windows allow you to do different things with AppLocker.  As a rule of thumb, on the client side, you need at least the Pro version of Windows (Pro, Enterprise, Ultimate).  A full chart is available here.

.exe files are not the only executables you can control with AppLocker.  You can also control scripts (PowerShell and Visual Basic scripts), packaged apps and their installers, DLLs, and Windows Installer files (.msi).  Packaged app rules in AppLocker are available in versions of Windows with apps (Windows 8 / Server 2012 and higher).  It is typically deployed through Group Policy either on a single computer or across a domain.

This feature is similar to (but not exactly the same as) other Mandatory Access Control (MAC) measures in Linux such as SELinux and AppArmor.

Why Would You Want To Use It?

AppLocker is not intended to be the only defense mechanism you employ in your organization.  As we talked about with EMET, it is meant to be one layer in a multi-layer defense.  AppLocker is good when you want relatively granular control over which applications are allowed to run in your network.  You might want to use AppLocker to only allow applications signed by trusted publishers (like your internal developers or organizations you have a relationship with).

How Do I Use It?

The examples we will work through today are in our test domain that we built a little while back.  If you have an appropriate version of Windows with AppLocker, you can implement it through Local Group Policy.  The idea is the same.

To get started, open Group Policy Management (Start > Run > gpmc.msc or hit the Windows key and start typing Group Policy).  Right click the organizational unit (OU) that you want to apply AppLocker policies to.  In this case, we will use the Workstations OU we defined previously.  Click "Create a GPO in this domain, and Link it here":

Give your GPO a name.  I will call our example "Workstations AppLocker Policy"

Right click your newly created GPO and click Edit.  AppLocker configuration is under Computer Configuration > Windows Settings > Security Settings > Application Control Policies > AppLocker.
First, we will create a default set of rules for each aspect of application configuration that is available to us.  The defaults are not sufficient to have a robust AppLocker configuration.  They are meant as a place to start, not to end.  Like any defense measure, you should always tailor the configuration to your environment.  The defaults are well known and can be bypassed.

We will start with Executable Rules.  Expand the AppLocker section by click the little arrow next to it.  Then click Executable Rules.  In that window, right click anywhere and choose Create Default Rules:

You can see that there were three rules created by default:
  1. Everyone can execute anything in Program Files
  2. Everyone can execute anything in the Windows folder
  3. Administrators can execute anything
Those are not a bad start, but we can (and should) do better.  The specific rules you will want to use will depend on your environment, but one that is particularly problematic is that second one.  Unfortunately, there are places in the Windows directory that any user can write to.  How do we find these?  We could use PowerShell (Get-Acl, look for directories with Write access), but I wanted to show another tool: AccessEnum.  AccessEnum is part of the Sysinternals Suite.  In my opinion, any security professional working with Windows should be familiar with the Sysinternals Toolkit because it contains a number of useful utilities to see what is going on on a system.

AccessEnum will enumerate all of the permissions on a given directory and its subdirectories.  We can then save the output and use a program like LibreOffice Calc or Excel to filter down to the permissions that we care about.  Essentially, we are looking for any folder that has write permissions for Users or Authenticated Users.

The picture above comes from a Windows 8.1 Enterprise machine.  We found one directory where Authenticated Users have write permissions: C:\Windows\Tasks.  With the default AppLocker rules that we created above, a user could copy an executable to this directory and run it because all executables under C:\Windows\ can run.  That includes subdirectories.  In fact, C:\Windows\Tasks is one folder that is often cited as a way to bypass default AppLocker permissions.  However, there are others.  I hit the Save button in AccessEnum and opened the resulting text file in LibreOffice.  I then filtered on the Write column for anything that had Users or Authenticated Users, and this is what I found:

Here are the paths for easier copy / paste:
  • C:\Windows\Tasks
  • C:\Windows\debug\WIA
  • C:\Windows\System32\Tasks
  • C:\Windows\SysWOW64\Tasks
  • C:\Windows\tracing
  • C:\Windows\System32\LogFiles\WUDF
  • C:\Windows\RemotePackages
  • C:\Windows\Registration\CRMLog
You might be thinking that the best course of action here would be to change the permissions on these folders to remove the write capability.  You could do that, but I think that is like using a sledgehammer to nail in a nail.  I think it would be better to allow users to write to those folder if there is some legitimate need, but not allow them to run any executables in those directories.  We can add those directories as exceptions to our AppLocker policy.

To do this, right click on the policy that says all programs in the Windows folder are allowed to run, click Edit, and then click the Exceptions tab:

For each path, click Add and type or copy / paste the paths we identified above (or ones that you identified):

When you are done, click OK.  You can use AccessEnum for other directories you are worried about.  In my environment, there were no user writable folders in either C:\Program Files or C:\Program Files (x86)

We will work through one more example.  We will only allow signed applications to be run.  This might not work for your environment, but it will stop a whole class of malware that is unsigned.  This does not stop malware completely though, because even when only signed executables can run, the following could happen:
  • If a trusted publisher's signing certificate is compromised, someone could sign malicious binaries with it (either an insider or an intruder).
  • If someone is able to install a root certificate on a box, they could sign arbitrary software with it.
  • If there is some vulnerability in a signed application, it could be exploited to run other executable code (i.e. from memory).  AppLocker does not act on executables that are solely in memory.
If you depend on some unsigned binaries, it might be worth looking into signing them yourself using an internal signing certificate.  You could even go a step further and only allow applications signed with your organization's internal signing certificate and known trusted publishers (like Microsoft).

To create the rule, right click Executable Rules then click Create New Rule. The Executable Rule Wizard will pop up:

Click Next

We are writing a rule that only allows signs executables to run.  This rule will apply to everyone.  We will keep the two options shown here because we cannot say Deny unsigned executables to run.  Rather, we have to say that only signed executables are allowed to run.  Click Next.

Since we want to work with signatures and not paths or hashes, we will click Next here.

We have to provide a signed file.  The publisher is not important because we are going to adjust it to allow any publisher.  I chose write.exe under C:\Windows.  Then, slide the slider up to Any Publisher.

If we wanted to restrict our rule to certain properties of the signature, such as Publisher or Product name we could do it here by supplying a reference file (a file signed in the way we want this rule to apply).  We are not going to do that because we are okay with all signed executables running.

When you click Next, you can define exceptions to the rule.

We do not have any, so click Next.

You can give your new rule a name.  I called it "Only allow signed executables"

Finally, click Create.  You will see your new rule in the right pane.

Now we need to enforce the rules.  There are two things we need to do.  First, we have to enable the Application Identity Service to load Automatically.  To do that, click System Services under Computer Configuration > Policies > Windows Settings > Security Settings.

Double click Application Identity, click Define This Policy Setting, then click Automatic:
Then click OK.  Now we have to set the rules to enforced.  To do that, click on AppLocker under Computer Configuration > Windows Settings > Security Settings > Application Control Policies.

Then click Configure Rule Enforcement on the right side:

Click the check box next to Configured under Executable rules.  We have not defined any other types of rules, so we will leave those alone.  You could choose to put the rules in Audit Only mode which means that only logs will be generated instead of actually blocking executables.  This is good if you want to test your rules before deploying them.  We live on the edge, so we will leave this at Enforced.  Click OK.

Before we apply the Group Policy settings on the machine, let's try to run an evil Hello World program on our domain-connected client:

Oh no! We cannot let this happen!  When we apply the group policy (restarting the computer is easiest), this is what happens when we try to run the same program:

Awesome.  We saved our network from that evil program.

There is another good rule you can set up.  Suppose a user brings in a USB from home, and without their knowledge, an executable on it is malicious.  We can use AppLocker to stop programs from running from removable media.  Here is how.  When you create a rule, make a new Deny rule, and choose Path as the condition.

In the path box, enter %HOT%.  %HOT% is the variable for removable drives.  There are other variables you can use, all listed here.  You can also use %REMOVABLE% to restrict access to executables on removable media like CDs.

Conclusions and Final Thoughts

AppLocker is another tool for your defensive toolbox.  Like just about every other network security measure, it takes configuration and maintenance to be effective.  The default rules will not cut because they can be easily bypassed as we saw with writable directories in the Windows folder.  However, if you take the time to build a comprehensive rule set, AppLocker may help mitigate some of the vulnerabilities in your network.

AppLocker Overview
AppLocker Policies Deployment Guide
Working with AppLocker Rules

1 comment:

  1. Game Boy Advance Game Boy Advance Online Release Time - ChoE
    As an add-on in the Sega Genesis/ Master System, it's available in a physical cartridge form 온라인카지노 for the Game Boy Advance on Wii 카지노사이트 Virtual Console.