티스토리 뷰
ETW를 쓰기 전에 일단, 파악을 좀 해야 하므로
정리를 해보도록 한다.
[관련 영상]
https://www.youtube.com/watch?v=ZNdpLM4uIpw
10줄 요약
- 존나 좋은데 왜 안씀?
- 윈도우 시스템 프로그래머는 꼭 써볼만해
- 모든 I/O 정보를 구할 수 있어! 만 개도 넘는 클래스! 너를 위해 준비했찌!!
- 기존 고전 프로파일러들은 존나 느려, 그리고 비싸, 그러니 써라 너와 나의 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
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. You can consume the events in real time or from a log file and use them to debug an application or to determine where performance issues are occurring in the application.
ETW lets you enable or disable event tracing dynamically, allowing you to perform detailed tracing in a production environment without requiring computer or application restarts.
- ETW 는 효율적인 <커널 레벨 추적기>이다. {커널 레벨!, 내부에서 드라이버를 쓴다는 걸 알 수 있다,
그러므로 우린 쓸데 없이 드라이버를 만들 필요도 없이 MS의 고오급 드라이버를 활용할 수 있다는 것이다.
물론 커스터마이징한 갱장한 기능을 추가할 필요가 있지 않을까 하는 것은 당신의 능력을 과대평가하는 것이다.
MS의 WINAPI로 거의 모든 것이 레고조립처럼 커버 가능한 것처럼, ETW로 거의 모든 I/O 크롤링이 가능할 것이다.
(무려 내부 클래스만 만개라고, 만카이!)
대략 만 개의 클래스에서 네가 찾는 IO가 없을 확률은 없을 것이다.
[구조] - ETW는 3가지의 기능으로 나눠진다
컨트롤러 | 이벤트 추적 <세션>을 키고 끄며 프로바이더를 설정한다. |
프로바이더 | 일종의 제공자로서 어떤 이벤트 그룹을 제공할지 세분화한다. |
컨슈머 | 소모하는 녀석이다 |
- 참고로 굳이 나누긴 했지만 컨트롤러와 프로바이더는 같은 어플리케이션에 넣을 수 있다.
DOCS의 내용이 참으로 이해하기에 좋치 않아서 따로 만들어본다.
그러므로 우리가 알아볼 것은,
깐츄롤러를 생성하고, 프로바이더와 세션에 대한 옵션을 넣어주고
깐츄롤러를 실행시키면, 실시간 이면 콜백으로 이벤트 프로퍼티들이 전달될 것이요,
수동으로 저장하게 했으면 로그 파일로 저장될 것이므로 컨슈머를 통해서 긁어오면 된다.
이 모든 것 이벤트의 수집은 마치 스레드 큐와 같이 [세션]에서 관리/ 저장된다.
[세션] 개념에 대해서
- Global Logger Session
- NT Kernel Logger Session
글로벌 로거는 os가 부팅되는 얼리 모드부터 수집된다. 드라이버까지 혼내줄 수 있따는 의미다
아주 조쿤. 이것은 procmon의 부팅 모드를 대체할 수도 있을 거시다.
커널 로거는 os의 이벤트들을 의미한다. 그냥 io라고 생각하면 된다.
disk io, page fault event 등등..
자세한 건 이녀석을 보자
뭐 어차피 거의 커널 로거를 주로 쓸테니, (다른 특이한 케이스 제외하고)
한번 보자.
Configuring and Starting the NT Kernel Logger Session - Win32 apps
The NT Kernel Logger session is an event tracing session that records a predefined set of kernel events.
docs.microsoft.com
#define INITGUID // Include this #define to use SystemTraceControlGuid in Evntrace.h.
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <strsafe.h>
#include <wmistr.h>
#include <evntrace.h>
#define LOGFILE_PATH L"<FULLPATHTOTHELOGFILE.etl>"
void wmain(void)
{
ULONG status = ERROR_SUCCESS;
TRACEHANDLE SessionHandle = 0;
EVENT_TRACE_PROPERTIES* pSessionProperties = NULL;
ULONG BufferSize = 0;
// Allocate memory for the session properties. The memory must
// be large enough to include the log file name and session name,
// which get appended to the end of the session properties structure.
BufferSize = sizeof(EVENT_TRACE_PROPERTIES) + sizeof(LOGFILE_PATH) + sizeof(KERNEL_LOGGER_NAME);
pSessionProperties = (EVENT_TRACE_PROPERTIES*) malloc(BufferSize);
if (NULL == pSessionProperties)
{
wprintf(L"Unable to allocate %d bytes for properties structure.\n", BufferSize);
goto cleanup;
}
// Set the session properties. You only append the log file name
// to the properties structure; the StartTrace function appends
// the session name for you.
ZeroMemory(pSessionProperties, BufferSize);
pSessionProperties->Wnode.BufferSize = BufferSize;
pSessionProperties->Wnode.Flags = WNODE_FLAG_TRACED_GUID;
pSessionProperties->Wnode.ClientContext = 1; //QPC clock resolution
pSessionProperties->Wnode.Guid = SystemTraceControlGuid;
pSessionProperties->EnableFlags = EVENT_TRACE_FLAG_NETWORK_TCPIP;
pSessionProperties->LogFileMode = EVENT_TRACE_FILE_MODE_CIRCULAR;
pSessionProperties->MaximumFileSize = 5; // 5 MB
pSessionProperties->LoggerNameOffset = sizeof(EVENT_TRACE_PROPERTIES);
pSessionProperties->LogFileNameOffset = sizeof(EVENT_TRACE_PROPERTIES) + sizeof(KERNEL_LOGGER_NAME);
StringCbCopy((LPWSTR)((char*)pSessionProperties + pSessionProperties->LogFileNameOffset), sizeof(LOGFILE_PATH), LOGFILE_PATH);
// Create the trace session.
status = StartTrace((PTRACEHANDLE)&SessionHandle, KERNEL_LOGGER_NAME, pSessionProperties);
if (ERROR_SUCCESS != status)
{
if (ERROR_ALREADY_EXISTS == status)
{
wprintf(L"The NT Kernel Logger session is already in use.\n");
}
else
{
wprintf(L"EnableTrace() failed with %lu\n", status);
}
goto cleanup;
}
wprintf(L"Press any key to end trace session ");
_getch();
cleanup:
if (SessionHandle)
{
status = ControlTrace(SessionHandle, KERNEL_LOGGER_NAME, pSessionProperties, EVENT_TRACE_CONTROL_STOP);
if (ERROR_SUCCESS != status)
{
wprintf(L"ControlTrace(stop) failed with %lu\n", status);
}
}
if (pSessionProperties)
free(pSessionProperties);
}
위의 내용은, TCP/IP 커널 이벤트를 캡춰링 하는 예제이다. 쉽게 생각하면 -
이걸로 덤핑이나 패킷 내용에 대한 개괄 필터링도 가능하단 소리다.
근데 너무 지저분하므로 클래스로 변신시켜보자. 지금 말고 다음 시간에
자야하니까
'코딩 공부방 > 보안&해킹' 카테고리의 다른 글
악성코드 자동 분석 시스템 (0) | 2022.03.26 |
---|---|
ETW - 네트워크 추적방식에 대한 스터디 (0) | 2022.03.20 |
ETW - 기반지식(3) : 난해함 (0) | 2022.03.18 |
ETW - 기반 지식(2) : EVENT_TRACE_PROPERTIES (0) | 2022.03.17 |
ETW - Python (0) | 2022.03.17 |
- Total
- Today
- Yesterday
- 구조체 #클래스
- 세대주분리
- 파이썬 #이벤트로그 #크롤링
- 가점제
- 세대원
- procmoninjection
- 추첨제
- 망할비주얼스튜디오코드파이썬쓸때는좋더니만
- 이럴거야?
- procmon활용
- 와이어샤크
- 비주얼스튜디오코드C/C++
- 미즈노남보쿠
- procmon
- Injection
- 청약방법
- 세대주
- 왜다운로드안되게해놨어
- 절제의성공학
- 무료라메
- 필터링
- 청약
- 주택청약
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |