My key takeaways
-
MSBuild is a binary that is installed by default on Windows
- no whitelisting required
-
.csprojand.xmlfiles are typical to interact with MSBuild -
Custom tasks are the juicy stuff
-
Malicious code is placed in the
executefunction of the custom task and compiled into an dll -
xml will bypass detection a lot more often then compiled code
-
with MSBuild you compile the malicious dll on the target system
-
con: you need 2 files to drop
-
-
With .NET 4.0 you can use inline tasks as well
-
one file to rule them all
-
no dll needed to compile
-
con: inline malicious code easily to recognize by DFIR
-
-
With the unregister task you could host malicious dll on a UNC or Webdav path as well
-
XslTransformationtasks can be abused to- No ref to CodeTaskFactory which is required for inline tasks
-
GenerateResourcetask usingresgen.exemight not be on the system already-
input is
.resxfiles >.resourcesfiles -
payload is Base64 encoded inline
-
-
If admin access you can override pre-built native tasks (like Copy, MakeDir,…) and this way make your malicious code executed for persistence using
Copy.overridetasks -
If
.csprojfile is the only file in a dir, runningMSBuild.exewithout any argument, will execute the.csprojfile anyway- no traces in the logs for the blue team
-
Looking for
Microsoft-WebDAV-MiniRedir/{VERSION}as user agent in your network might be an IOC
Env
-
Provided by Wild West Hackin’ Fest
-
Speaker
additional links
-
https://docs.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019
-
https://docs.microsoft.com/en-us/dotnet/api/microsoft.build.framework.itask?view=msbuild-16-netcore
-
https://docs.microsoft.com/en-us/dotnet/api/microsoft.build.framework.itask?view=msbuild-16-netcore
-
https://docs.microsoft.com/en-us/visualstudio/msbuild/makedir-task?view=vs-2019
-
https://www.blackhillsinfosec.com/deploying-a-webdav-server/
-
https://docs.microsoft.com/en-us/dotnet/core/extensions/create-resource-files
-
https://docs.microsoft.com/en-us/visualstudio/msbuild/generateresource-task?view=vs-2019
-
https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-task-reference?view=vs-2019