티스토리 뷰

코딩 공부방/보안&해킹

ETW - Python

TheShield 2022. 3. 17. 22:38
반응형

ETW 는 Event Tracing For Windows로

커널 단위, 응용 단위에서 윈도우즈 시스템의 전반적인 I/O를 뽑아낼 수 있는 

실시간/정적 모니터링 시스템 라이브러리이다.

 

파이썬에서 쓸 수 있게 불꽃 눈에서 github에 공개한 바 있다.

나는 이것을 잘 써볼 생각이다. 

 

아마 win32 api를 ctypes로 포맷팅한 것 같은데 etw와 함께 아라보자.

[원래 ETW]

https://docs.microsoft.com/en-us/windows/win32/etw/about-event-tracing

 

About Event Tracing - Win32 apps

Event Tracing for Windows (ETW) is an efficient kernel-level tracing facility that lets you log kernel or application-defined events to a log file.

docs.microsoft.com

 

[불꽃눈의 파이썬 ETW 라이브러리 - pywintrace]

https://github.com/fireeye/pywintrace

 

GitHub - fireeye/pywintrace: ETW Python Library

ETW Python Library. Contribute to fireeye/pywintrace development by creating an account on GitHub.

github.com

 

아름다운 불꽃 눈의 pywintrace

 

pip install pywintrace
pip install etw

를 해줘야 한다.

레파지토리 구성은 위와 같은데 

 

etw - 코어 라이브러리 

docs - 필요 없음

examples - 음. 별로

tests - 이게 실제 test code 들임, 어차피 실행할 때 

windows의 etw를 맞춰봐야 함

 

tests 코드로 윤곽을 보면서 etw를 파헤치면 되는데,

잘 동작은 하는 것 같은데 아무도 안쓰니까 내가 써본다.

잘 만든거 같은데 왜 안쓰지? 파이썬으로 래퍼 만들려면 엄청 귀찮은데 

 

난 이미 etw에 대한 사전 지식이 있지만 그래도 

열심히 다시 공부해보기로 한다.

 

https://docs.microsoft.com/en-us/windows/win32/etw/about-event-tracing

 

About Event Tracing - Win32 apps

Event Tracing for Windows (ETW) is an efficient kernel-level tracing facility that lets you log kernel or application-defined events to a log file.

docs.microsoft.com

 

[기본적인 코드]

https://github.com/fireeye/pywintrace/blob/master/examples/simple.py

이 코드인데, 나는 raw가 무서우므로 라이센스를 첨부한다

 

 

GitHub - fireeye/pywintrace: ETW Python Library

ETW Python Library. Contribute to fireeye/pywintrace development by creating an account on GitHub.

github.com

########################################################################
# Copyright 2017 FireEye Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
########################################################################

import etw


def some_func():
    # define capture provider info
    providers = [etw.ProviderInfo('Some Provider', etw.GUID("{11111111-1111-1111-1111-111111111111}"))]

    # create instance of ETW and start capture
    with etw.ETW(providers=providers, event_callback=etw.on_event_callback):
        # run capture
        etw.run('etw')


if __name__ == '__main__':
    some_func()

하지만 위의 코드는 내가 원하는 코드가 아니다. 

너무 단순하고 딱히 쓰고 싶은 게 없다.

 

그럼 이제 여기에 추가해서 프로세스나 파일, 레지스트리, 네트워크를 한번

뽑아내보자.

 

반응형
댓글