Git Product home page Git Product logo

silketw's Introduction

SilkETW & SilkService

SilkETW & SilkService are flexible C# wrappers for ETW, they are meant to abstract away the complexities of ETW and give people a simple interface to perform research and introspection. While both projects have obvious defensive (and offensive) applications they should primarily be considered as research tools.

For easy consumption, output data is serialized to JSON. The JSON data can either be written to file and analyzed locally using PowerShell, stored in the Windows eventlog or shipped off to 3rd party infrastructure such as Elasticsearch.

For more information on the future of SilkETW & SilkService, see the Roadmap section.

Media

For more background on SilkETW and SilkService please consult the following resources.

  • SilkETW: Because Free Telemetry is … Free! - here
  • SilkETW & SilkService BlackHat Arsenal 2019 - here
  • Threat Hunting with ETW events and HELK — Part 1: Installing SilkETW (by @Cyb3rWard0g) - here
  • Threat Hunting with ETW events and HELK — Part 2: Shipping ETW events to HELK (by @Cyb3rWard0g) - here
  • Events from all manifest-based and mof-based ETW providers across Windows 10 versions (by @jdu2600) - here
  • Hunting for Suspicious LDAP Activity with SilkETW and Yara - here

Implementation Details

Libraries

SilkETW is buit on .Net v4.5 and uses a number of 3rd party libraries, as shown below. Please see LICENSE-3RD-PARTY for further details.

ModuleId                                 Version LicenseUrl                                                   
--------                                 ------- ----------                                                   
McMaster.Extensions.CommandLineUtils     2.3.2   https://licenses.nuget.org/Apache-2.0                        
Microsoft.Diagnostics.Tracing.TraceEvent 2.0.36  https://github.com/Microsoft/perfview/blob/master/LICENSE.TXT
Newtonsoft.Json                          12.0.1  https://licenses.nuget.org/MIT                               
System.ValueTuple                        4.4.0   https://github.com/dotnet/corefx/blob/master/LICENSE.TXT     
YaraSharp                                1.3.1   https://github.com/stellarbear/YaraSharp/blob/master/LICENSE

SilkETW

Command Line Options

Command line usage is fairly straight forward and user input is validated in the execution prologue. See the image below for further details.

Help

SilkService

Caveat

SilkService was created because a large number of people wanted to run SilkETW headless and perform ETW collection for multiple sources at the same time. While there is obvious appeal to this, the following points should be kept in mind.

  • SilkETW & SilkService were created by a one-man engineering army, (@FuzzySec), they are not backed by a department of developers and as such may contain bugs. If you do encounter bugs or see ways to improve these projects you are strongly encouraged to file tickets and/or submit pull requests.
  • ETW collection can be resource intensive. Do not roll out SilkService across a wide range of hosts without thorough performance testing. Ensure that the configuration can run stably on your least powerful machines.

Setup

After compiling or downloading the release package you can install the service by issuing the following command from an elevated prompt.

sc create SillkService binPath= "C:\Path\To\SilkService.exe" start= demand

Configuration

SilkService ingests an XML configuration file, "SilkServiceConfig.xml", which should be placed in the same directory as the service binary. An example configuration file can be seen below.

<SilkServiceConfig>
	<!--
		This is a user collector
		-> Microsoft-Windows-DotNETRuntime
		-> GUID or string based name
	-->
	<ETWCollector>
		<Guid>45c82358-c52d-4892-8237-ba001d396fb4</Guid>
		<CollectorType>user</CollectorType>
		<ProviderName>e13c0d23-ccbc-4e12-931b-d9cc2eee27e4</ProviderName>
		<UserKeywords>0x2038</UserKeywords>
		<OutputType>url</OutputType>
		<Path>https://some.elk:9200/NetETW/_doc/</Path>
	</ETWCollector>
	<!--
		This is a user collector
	-->
	<ETWCollector>
		<Guid>6720babc-dedc-4906-86b9-d0bc0089ec50</Guid>
		<CollectorType>user</CollectorType>
		<ProviderName>Microsoft-Windows-DNS-Client</ProviderName>
		<OutputType>eventlog</OutputType>
		<YaraScan>C:\Some\Path\RuleFolder</YaraScan>
		<YaraOptions>Matches</YaraOptions>
	</ETWCollector>
	<!--
		This is a kernel collector
	-->
	<ETWCollector>
		<Guid>21ac2393-3bbb-4702-a01c-b593e21913dc</Guid>
		<CollectorType>kernel</CollectorType>
		<KernelKeywords>Process</KernelKeywords>
		<OutputType>file</OutputType>
		<Path>C:\Users\b33f\Desktop\kproc.json</Path>
	</ETWCollector>
</SilkServiceConfig>

Note that each ETWCollector element should have a random GUID, this is used for internal tracking and logging purposes. You can generate GUID's in PowerShell using the following command:

PS C:\> [guid]::NewGuid()

Guid
----
eee52b87-3f32-4651-b0c3-e7bb9af334aa

Auditing

At runtime SilkService will create a "Logs" subfolder to record service runtime information. This is an invaluable resource to poll the service state, verify service parameter validation and review error information. SilkService has a preference to shut down gracefully if it encounters any type of error, even if such an error does not strictly require termination. This design decision was made purposely as it is not a sound strategy to have dangling collectors or partial operability.

Always consult the service log if the service shuts itself down!

Something went wrong?

It is always possible that something goes wrong. Consult the service log for further details. While SilkService is configured to terminate and clean up ETW collectors or error it is possible that a stale collector remains registered after process termination. To list running collectors you can use the following command.

logman -ets

If any stale collectors are identified they can be removed by issuing the following commands from an elevated prompt.

Get-EtwTraceProvider |Where-Object {$.SessionName -like "SilkService*"} |ForEach-Object {Stop-EtwTraceSession -Name $.SessionName}
Get-EtwTraceProvider |Where-Object {$_.SessionName -like "SilkService*"} |Remove-EtwTraceProvider

Output Format

JSON Output Structure

The JSON output, prior to serialization, is formatted according to the following C# struct.

public struct EventRecordStruct
{
    public Guid ProviderGuid;
    public List<String> YaraMatch;
    public string ProviderName;
    public string EventName;
    public TraceEventOpcode Opcode;
    public string OpcodeName;
    public DateTime TimeStamp;
    public int ThreadID;
    public int ProcessID;
    public string ProcessName;
    public int PointerSize;
    public int EventDataLength;
    public Hashtable XmlEventData;
}

Note that, depending on the provider and the event type, you will have variable data in the XmlEventData hash table. Sample JSON output can be seen below for "Microsoft-Windows-Kernel-Process" -> "ThreadStop/Stop".

{
   "ProviderGuid":"22fb2cd6-0e7b-422b-a0c7-2fad1fd0e716",
   "YaraMatch":[

   ],
   "ProviderName":"Microsoft-Windows-Kernel-Process",
   "EventName":"ThreadStop/Stop",
   "Opcode":2,
   "OpcodeName":"Stop",
   "TimeStamp":"2019-03-03T17:58:14.2862348+00:00",
   "ThreadID":11996,
   "ProcessID":8416,
   "ProcessName":"N/A",
   "PointerSize":8,
   "EventDataLength":76,
   "XmlEventData":{
      "FormattedMessage":"Thread 11,996 (in Process 8,416) stopped. ",
      "StartAddr":"0x7fffe299a110",
      "ThreadID":"11,996",
      "UserStackLimit":"0x3d632000",
      "StackLimit":"0xfffff38632d39000",
      "MSec":"560.5709",
      "TebBase":"0x91c000",
      "CycleTime":"4,266,270",
      "ProcessID":"8,416",
      "PID":"8416",
      "StackBase":"0xfffff38632d40000",
      "SubProcessTag":"0",
      "TID":"11996",
      "ProviderName":"Microsoft-Windows-Kernel-Process",
      "PName":"",
      "UserStackBase":"0x3d640000",
      "EventName":"ThreadStop/Stop",
      "Win32StartAddr":"0x7fffe299a110"
   }
}

Post-Collection

Filter data in PowerShell

You can import JSON output from SilkETW in PowerShell using the following simple function.

function Get-SilkData {
	param($Path)
	$JSONObject = @()
	Get-Content $Path | ForEach-Object {
		$JSONObject += $_ | ConvertFrom-Json
	}
	$JSONObject
}

In the example below we will collect process event data from the Kernel provider and use image loads to identify Mimikatz execution. We can collect the required data with the following command.

SilkETW.exe -t kernel -kk ImageLoad -ot file -p C:\Users\b33f\Desktop\mimikatz.json

With data in hand it is easy to sort, grep and filter for the properties we are interested in.

Mimikatz

Yara

SilkETW includes Yara functionality to filter or tag event data. Again, this has obvious defensive capabilities but it can just as easily be used to augment your ETW research.

In this example we will use the following Yara rule to detect Seatbelt execution in memory through Cobalt Strike's execute-assembly.

rule Seatbelt_GetTokenInformation
{
	strings:
		$s1 = "ManagedInteropMethodName=GetTokenInformation" ascii wide nocase
		$s2 = "TOKEN_INFORMATION_CLASS" ascii wide nocase
		$s3 = /bool\(native int,valuetype \w+\.\w+\/\w+,native int,int32,int32&/
		$s4 = "locals (int32,int64,int64,int64,int64,int32& pinned,bool,int32)" ascii wide nocase
	
	condition:
		all of ($s*)
}

We can start collecting .Net ETW data with the following command. The "-yo" option here indicates that we should only write Yara matches to disk!

SilkETW.exe -t user -pn Microsoft-Windows-DotNETRuntime -uk 0x2038 -l verbose -y C:\Users\b33f\Desktop\yara -yo matches -ot file -p C:\Users\b33f\Desktop\yara.json

We can see at runtime that our Yara rule was hit.

Seatbelt

Note also that we are only capturing a subset of the "Microsoft-Windows-DotNETRuntime" events (0x2038), specifically: JitKeyword, InteropKeyword, LoaderKeyword and NGenKeyword.

How to get SilkETW & SilkService?

You can either download the source and compile it in Visual Studio. Please note that you can get the community edition of Visual Studio free of charge. Or you can grab the latest pre-built version from releases.

Future Work

Changelog

For details on version specific changes, please refer to the Changelog.

RoadMap

  • Offer users the option to write trace data to disk as *.etl files.
  • Offer users the option to write trace data to the Windows event log. (v0.5+)
  • Offer users pre-compiled releases. (v0.6+)
  • Create a separate instance (SilkService) which can be deployed as a service with a configuration file. (v0.7+)
  • Suggestions welcome!

silketw's People

Contributors

fuzzysecurity avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

silketw's Issues

SilkService unable for load YaraSharp.dll

I'm trying to setup SilkService 0.8 in a Eval MS Edge VM (Windows10 1809). When starting the service throws the following error:

Service cannot be started. System.IO.FileNotFoundException: Could not load file or assembly 'YaraSharp.dll' or one of its dependencies. The specified module could not be found.
File name: 'YaraSharp.dll'
   at SilkService.SilkParameters.ValidateCollectorParameters(List`1 Collectors)
   at SilkService.SilkService.OnStart(String[] args) in C:\Users\b33f\Desktop\SilkService\SilkService.cs:line 30
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

I'm using the pre build 0.8 package from releases.

Any suggestion on what might be causing this?
Thanks in advance!
RD

Pre-build binary crashing

I am using prebuild binary on windows 7 32 bit and 64 bit Virutal Box images, but it crash on both OS.

Feature Request: Pass Yara Meta info to fieldnames/json

I'd like to be able to Tag Yara signatures with MITRE ATT&CK information, it would be awesome to be able to pass for instance the description field and meta tags to the json so I can add comma separated key value pairs to pass on to our SIEM for further enrichment/reporting and alerting.

Kernel Keyword

The kernel keyword doesnt appear to be working. When i specify 'All', i only get a subset of all the categories. When I specify tcpipnetwork i dont get any network events back. mostly thread/dcstart.

How to capture memory mapped I/O events?

Hi

I am trying to capture the read/write from notepad.exe which turns out to be using memory mapped I/O. For that I started the SilkETW as follows:

SilkETW.exe -t kernel -kk VAMap -ot file -p c:\temp\sample\output.json

For a 120 second session, in which notepad.exe is opened with a text file, I received not a single read/write event for the notepad.exe.

Please suggest what is the right way to do that. Thanks.

Opcodes can be larger than 9

Hi there,
When filtering by opcode, e.g. -f Opcode -fv 2, you limit the possible opcode to filter on to be 0-9, in this code:

SilkUtility.FilterValueObject = byte.Parse(FilterValue);
if ((byte)SilkUtility.FilterValueObject > 9)
{
    SilkUtility.ReturnStatusMessage("[!] Opcode outside valid range (0-9)", ConsoleColor.Red);
    return;
}

However in the underlying ETW API, an Opcode is an UCHAR, so it can be 0-255

Output to Syslog/Gelf

Very nice tool, already using a built version of this. I would love to see an additional output for Syslog/Gelf output for SIEM's like Graylog or other logging platforms.

Feature Request: Write to Eventlog with Eventlog format

Json is nice, however there is nested json that is hard to parse and requires select json and advanced parsing. If possible can you log to the eventlog format so eventlog loggers like Winlogbeat parse the fields automatically.

Request: Ship Example configuration files

Please ship an example config file with IOC's and common use cases, new users will have to go through your youtube video demo's to learn the parsing and structure. I did this myself, but to get people started quicker some working examples would be nice.

EventCode and PacketCode are not properly parsed out of DNS Analytical etl logs

A couple of issues when this is pointed to the DNS Analytical log (Microsoft-Windows-DNS-Server/Analytical).
First it appears the incorrect EventCode (EventID) is selected. Below is what I receive in Splunk:

11/14/2020 02:27:04 PM
LogName=SilkService-Log
SourceName=SilkService Collector
EventCode=3
EventType=4
Type=Information
ComputerName=TitansTower.titans.local
TaskCategory=None
OpCode=Info
RecordNumber=354488
Keywords=Classic
Message={"ProviderGuid":"eb79061a-a566-4698-9119-3ed2807060e7","YaraMatch":[],"ProviderName":"Microsoft-Windows-DNSServer","EventName":"RECURSE_QUERY","Opcode":0,"OpcodeName":"Info","TimeStamp":"2020-11-14T14:27:02.9641148-08:00","ThreadID":4284,"ProcessID":2772,"ProcessName":"dns","PointerSize":8,"EventDataLength":236,"XmlEventData":{"FormattedMessage":"RECURSE_RESPONSE_IN: TCP=0; Source=8.8.8.8; InterfaceIP=0.0.0.0; AA=0; AD=0; QNAME=www.shadowtrackers.net.; QTYPE=1; XID=16,962; RemoteQueriesSent=1; Port=0; Flags=33,152; RecursionScope=.; CacheScope=Default; PacketData=42428180000100010000000103777777...; AdditionalInfo = VirtualizationInstance: .; GUID={9A8C1E76-A5AF-4590-8DDD-62C3FA22D45F} ","RecursionScope":".","PacketData":"42428180000100010000000103777777...","TCP":"0","GUID":"{9A8C1E76-A5AF-4590-8DDD-62C3FA22D45F}","Flags":"33,152","AD":"0","QNAME":"www.shadowtrackers.net.","CacheScope":"Default","XID":"16,962","MSec":"414994050.4369","Source":"8.8.8.8","AA":"0","Port":"0","QTYPE":"1","PID":"2772","AdditionalInfo":".","RecursionDepth":"1","TID":"4284","ProviderName":"Microsoft-Windows-DNSServer","PName":"","InterfaceIP":"0.0.0.0","EventName":"RECURSE_QUERY"}}

Please note that the EventCode is set to 3. But the above event (seen in the attached png file) is correctly 261:

DNS_Analytical_RECOURSE_RESPONSE_IN

Secondly, (and I'm not sure if this is deliberate or not), but the PacketData field is abbreviated. This field is needed in full so that we can decode the data. Is there a way the entire value can be captured and sent?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.