fireeye / pywintrace Goto Github PK
View Code? Open in Web Editor NEWETW Python Library
License: Apache License 2.0
ETW Python Library
License: Apache License 2.0
When logging nt kernel logger or windows kernel trace providers, there are no results. Any tips?
Hello,
Im working on USB4 device event tracing by using ETW logging and pywintrace.
but except USB4 I have captured and successfully traced by pywintrace.
Here I will provide for USB4 provider name and guid.
Microsoft-Windows-USB-USB4DeviceRouter-EventLogs {D07E8C3F-78FB-4C22-B77C-2203D00BFDF3}
how to update this issue in source code.
Hey,
First of all, it's a great library. It's helped me a lot.
I ported the library to python 2.7, and maybe this is part of the problem (but it does not look like this is the problem).
The library is working good when its standalone code, but when I try to use it within an exists project there is problems.
In some cases there is an exception on:
if tdh.ERROR_SUCCESS != et.ProcessTrace(ct.byref(trace_handle), 1, None, None):
within _run function inside etw.py
according to MSDN this function not supposed to raise exceptions so I think it's from ctypes.
The exception is not constant but the most common exceptions are "access violation writing 0xE09269EA" (or another address) or "access violation reading 0x00000000."
Hi this is a really nifty tool and I was wondering how to output the Stack Trace of the Event logged as to know what function calls generated the current event? TIA.
hello,
trying to use multiple providers using add_provider, second provider added does not seem to work as no events from second provider
using:
providers = [etw.ProviderInfo('Some Provider', etw.GUID("{11111111-1111-1111-1111-111111111111}"))]
provider2 = [etw.ProviderInfo('Some Provider2', etw.GUID("{11111111-1111-1111-1111-111111111112}"))]
job = etw.ETW(providers=providers, event_callback=something)
job.add_provider(provider2)
thanks!
Thanks for you for your wonderful project!
According to "The OpenTrace / ProcessTrace / CloseTrace
functions allow developers to consume events from either a real-time trace session or from an ETL log file", I try to call the consumer to parse a
windows .etl
log file (e.g. ShutdownCKCL.etl
). But I encountered a trouble when I try to call the consumer, because I haven't find an right way about using class EventConsumer
in details.
Could you provide a demo as a reference for me?
On a Win10 x64 box, in an Admin cmd window I am running the python script from the article https://www.countercept.com/blog/detecting-malicious-use-of-net-part-1/ (https://gist.github.com/countercept/7765ba05ad00255bcf6a4a26d7647f6e). I am running it with the --high-risk-only flag. It gets a lot of "Failed to get data field for AssemblyFlags, incrementing by reported size" error messages.
What would cause this? Is this normal or a bug? How can I fix it or suppress these messages?
I want to run:
c:\> pywintrace --type=CreateProcess --path=whatever
And get an infinite output of all the events that match my criteria.
When I run the code below to trace the GC keyword from the CLR Runtime provider (https://docs.microsoft.com/en-us/dotnet/framework/performance/clr-etw-providers), I see a large slowdown in all managed code on my machine - eg. running a build of a C# project in VS goes from 1m30s to >6 minutes. However, when I run perfview /GCCollectOnly
, which based on its source code appears to enable a larger set of keywords on this and other providers, and uses the same level (Informational), I don't see this slowdown.
I guess it might be because perfview is tracing direct to a file rather than using a callback, but I'm surprised that would make such a huge difference to the instrumented code. I thought the whole point of ETW was to be minimally intrusive. I don't see any additional filtering available on this provider besides the keywords and level.
import etw
providers = [
etw.ProviderInfo('CLR', etw.GUID('{E13C0D23-CCBC-4E12-931B-D9CC2EEE27E4}'), any_keywords=[1]),
]
with etw.ETW(providers=providers, event_callback=lambda evt: ()):
etw.run('etw')
Perfview has
if (GCCollectOnly)
{
// TODO this logic is cloned. We need it in only one place. If you update it do the other location as well
// The process events are so we get process names. The ImageLoad events are so that we get version information about the DLLs
KernelEvents = KernelTraceEventParser.Keywords.Process | KernelTraceEventParser.Keywords.ImageLoad;
ClrEvents = ClrTraceEventParser.Keywords.GC | ClrTraceEventParser.Keywords.Exception;
ClrEventLevel = TraceEventLevel.Informational;
TplEvents = TplEtwProviderTraceEventParser.Keywords.None;
NoRundown = true;
CommandProcessor.s_UserModeSessionName = "PerfViewGCSession";
DataFile = "PerfViewGCCollectOnly.etl";
}
I don't know how to get the information of the field "File".
Do you have any good Suggestions?
The 3dsmax
process did not officially display a progress bar when loading the large model.
So I needed to implement an external progress bar myself.
To implement the progress bar.
Can use EWT implement it?
Are there any plans to put this project on PyPI? I love the project and it would be awesome to be able to run
pip install pywintrace
It seems like most of the work has been done already (i.e. setup.py exists) but it is just a matter of building and pushing to PyPI. I am willing to help out in whatever way possible!
In case the main thread crash because of bad coding from the user (or something unforeseen happens) , the interpreter is not stopped because the consumer thread is still running.
To avoid that, one could make the consumer thread a daemon thread which wouldn't block the program from exiting in case of an error :
in etw.py (line 302):
self.process_thread = threading.Thread(target=self._run, args=(self.trace_handle, self.end_capture))
self.process_thread.daemon = True
self.process_thread.start()
thanks:
I am new to the etw with 3 questions.
When parsing events from Microsoft-Windows-Kernel-Process ({22FB2CD6-0E7B-422B-A0C7-2FAD1FD0E716}) on Windows 10 it looks like PROCESSSTART events lead to the exception below.
I believe it's process start events causing this because just adding a 'try catch pass' block around the exception lets me view process start events, whereas without that error handling I do not see any start events.
Python 3.6.
ValueError: invalid literal for int() with base 10: b''
Traceback (most recent call last):
File "_ctypes/callbacks.c", line 234, in 'calling callback function'
File "C:\Users\Colin\Documents\win_events\pywinevent\etw\etw.py", line 662, in _processEvent
out.update(self._unpackSimpleType(record, info, property_array[i]))
File "C:\Users\Colin\Documents\win_events\pywinevent\etw\etw.py", line 549, in _unpackSimpleType
data = tdh.TDH_CONVERTER_LOOKUPout_type
This is the code I used to trigger the bug:
import time
import etw
def handle_res(res):
n, event = res
if event['Task Name'] == 'PROCESSSTART':
print(res)
if event['Task Name'] == 'PROCESSSTOP':
print(res)
if __name__ == '__main__':
guid = {'Microsoft-Windows-Kernel-Process': etw.GUID("{22FB2CD6-0E7B-422B-A0C7-2FAD1FD0E716}")}
job = etw.ETW(guid)
job.start(handle_res)
time.sleep(15)
job.stop()
hello,author. I have a question. I have installed the package and Run successfully, but there are so many warnings in the pycharm console.like this.
I have saved the information of the event_callback to the .txt, but there are still warnings in the pycharm console.
Do you know how to close this? Thanks in advance.
I'm using Provider Windows Kernel Trace {9E814AAD-3204-11D2-9A82-006008A86939} to capture the behavior of a PE, whose function is search some files and move them to other directory. But not all events can be captured. Is it because of the value of ring_buf_size? I have tried to increase the ring_buf_size to 10240, but the problem is still unsolved.
This library does not follow best practices for ETW sessions, resulting in excessive memory usage. In addition, this library can cause substantial problems for the target system but does not appear to have any warnings that would alert users to the possible problems that might be caused by this library.
References:
Issues:
Users of this library need to be made aware of these issues and given guidance on how to minimize their impact on the target system.
In addition, it would be very helpful to improve the defaults to use less memory, and to provide additional ways for users to avoid using too much memory.
EVENT_TRACE_NO_PER_PROCESSOR_BUFFERING
flag. This flag is appropriate for low-event-rate sessions (less than a few hundred events per second) and significantly reduces the memory usage (you don't need separate buffers for each CPU).EVENT_TRACE_USE_PAGED_MEMORY
flag. By default, ETW sessions use non-paged memory so that they can receive events from the kernel. Non-paged memory means you're reserving the memory even if it is never used. If the session user knows they won't receive any events from the kernel, they should set EVENT_TRACE_USE_PAGED_MEMORY
so that the memory can be paged-out.EVENT_TRACE_INDEPENDENT_SESSION_MODE
. This just opts-in to a better ETW behavior that should have been the default.I am using the 0.2.0 package from PyPi.
When I 'import etw' logging is configured (in common.py), this caused a problem because my own call to logging.basicConfig happened later and most of my logging disappears.
I have modified this issue based on my later findings, as basicConfig is called when the first log call is made I suggest removing the call to logging.basicConfig in etw/common.py but am happy to hear alternative suggestions.
The provider below was returning stuff a few hours ago when I was testing it. But it stopped returing anything after I rerun it a few hours later, any thoughts?
def some_func():
providers = [etw.ProviderInfo('Microsoft-Windows-Win32k', etw.GUID("{8C416C79-D49B-4F01-A467-E56D3AA8234C}"))]
job = etw.ETW( providers=providers, event_callback=lambda x: print(x))
job.start()
time.sleep(10)
job.stop()
I am using this module to capture the info of the dns server.At the beginning,everything is ok and I can capture the log,but when I stop the process once,I can't capture the info of this provider unless I reboot the windows,but the other provider can capture as usual.When I use it in product,I can't reboot system at any time,so how could I solve the problem?The following is my code.Thanks!
import json
def some_func(name, guid):
# define capture provider info "{11111111-1111-1111-1111-111111111111}"
providers = [etw.ProviderInfo(name, etw.GUID("{"+guid+"}"))]
# create instance of ETW class
job = etw.ETW(providers=providers, event_callback=lambda x: print(str(x).replace("'","\"")))
# start capture
job.start()
# wait some time
#time.sleep(5)
while True:
url = "http://127.0.0.1:8093/query"
d = [
{
"Provider": guid
}
]
try:
r = requests.post(url, json.dumps(d))
response = r.text
if response == "no":
# stop capture
job.stop()
break
time.sleep(10)
except Exception as e:
print("dead")
job.stop()
break
if __name__ == '__main__':
name = sys.argv[1]
guid = sys.argv[2]
some_func(name, guid)
I've try to capture provider Active Directory Domain Service: Core
's events. The UserData is bad formatted like below:
"Description": "닼ᲃ쁏ᇑﲊ쀀쉏ᐙ瀪맔檘ᇒႷ쀀륏ꊘ"
I've also use tracerpt
tool to process the events and save it into a CSV file, and it convert properly.
Event Name, Type, Event ID, Version, Channel, Level, Opcode, Task, Keyword, PID, TID, Processor Number, Instance ID, Parent Instance ID, Activity ID, Related Activity ID, Clock-Time, Kernel(ms), User(ms), User Data
DsDirSearch, Start, 0, 4, 0, 0, 1, 0, 0x0000000000000000, 0x000001D8, 0x000004EC, 0, , , {00000000-0000-0000-0000-000000000000}, , 131644278080567528, 0, 0, "DS", 4, 6, 1141178432, 27086592, "127.0.0.1:54449", "base", "CN=***CommonName***,CN=***CommonName*** ,CN=***CommonName*** ,CN=***CommonName*** ,CN=***CommonName*** ,CN=***CommonName*** ,DC=***CommonName*** ,DC=***CommonName*** ", " (objectClass=*) ", "options", "", "", "", 0x0000160000000000
The System is Windows 2008 R2 Server
, Active Directory Domain Server is enabled.
The issue also occour on windows 10
with provider Active Directory Domain Service: SAM
When I ran the example code, it returns an attribute error:
providers = [etw.ProviderInfo('Some Provider', etw.GUID("{94335EB3-79EA-44D5-8EA9-306F49B3A041}"))] AttributeError: module 'etw' has no attribute 'ProviderInfo'.
What's going on?
Hi guys,
I'm trying to add providers on the fly after the session is started. I tried different ways but I can't do it.
The next code is a part about what I'm trying to do but It doesn't work
providers = [etw.ProviderInfo('Microsoft-Windows-Kernel-Process', etw.GUID("{22FB2CD6-0E7B-422B-A0C7-2FAD1FD0E716}"))]
job = etw.ETW(providers=providers, event_callback=lambda x: print(x))
job.start()
job.add_provider(etw.ProviderInfo('Microsoft-Windows-Kernel-File', etw.GUID("{EDD08927-9CC4-4E65-B970-C2560FB5C289}")))
However, if I add the provider before starting the job, it is added.
providers = [etw.ProviderInfo('Microsoft-Windows-Kernel-Process', etw.GUID("{22FB2CD6-0E7B-422B-A0C7-2FAD1FD0E716}"))]
job = etw.ETW(providers=providers, event_callback=lambda x: print(x))
job.add_provider(etw.ProviderInfo('Microsoft-Windows-Kernel-File', etw.GUID("{EDD08927-9CC4-4E65-B970-C2560FB5C289}")))
job.start()
Am I doing something wrong?
Thanks in advance :)
PS: I've tried also with job.query()
and job.update()
methods without success.
Hi,
Never mind, it was my mistake.
I'm pretty new to ETW and trying to log network traffic from a specific process.
I was able to get the network activity using the "Microsoft-Windows-Winsock-AFD" provider. however, I'm having trouble getting additional data such as remote address and the number of bytes sent/received.
Any help would be appreciated. I know that this is not technically an issue, but the official email didn't work.
Thanks.
I'm trying to run a Python script based on your Pywintrace code (firstly, thank you so much for creating this awesome solution!)
Initially I was able to run the script ~5 times without a problem, but since then I keep getting the following error:
OSError: [WinError 1450] Insufficient system resources exist to complete the requested service.
I don't know why it stopped working because nothing obvious changed about my environment. Also, I've tried to run the script on two separate machines (Windows 10) as well as on a Windows 7 VM, but I always get the same error.
I found a potential solution for the 1450 error on two separate questions on StackOverflow, followed the steps for all machines, however, the problem persisted. Those steps included changing the registry entries "PoolUsageMax" and "PagedPoolSize" under memory management.
(The steps followed are from the answers on the following two questions:
https://stackoverflow.com/questions/53752487/oserror-winerror-1450-insufficient-system-resources-exist-to-complete-the-req
I realise this question is not specific to your product, but I can't find much else out there so I was wondering if you might have had a similar experience in the past and/or have any clues as to how I can fix this?
Thank you in advance.
Best,
Ana
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.