티스토리 뷰

반응형

ETW를 사용해서 합리적으로 파일/프로세스/레지스트리/네트워크를 추적하는 방법 중에는, 

네트워크는 TCPIP/UDP를 이용할 수 있을 것으로 보인다. 

 

[TCP/IP에 대한 MOF 클래스를 알아보자]

https://docs.microsoft.com/en-us/windows/win32/etw/tcpip

 

TcpIp class - Win32 apps

TcpIp class - This class is the parent class for TCP/IP events. The following syntax is simplified from MOF code.

docs.microsoft.com

 

To enable TCP/IP events in an NT Kernel logging session, specify the EVENT_TRACE_FLAG_NETWORK_TCPIP flag in the EnableFlags member of an EVENT_TRACE_PROPERTIES structure when calling the StartTrace function.

 

- NT Kernel logging session을 StartTrace(Controller)에 인가하면 TCP/IP에 대한 이벤트를 얻을 수 있다.

사실 상 TCIP/IP라 하면 여러 프로토콜에 대한 정보 http/https의 정보까지 얻어낼 수 있으므로(네트워크 레이어가

더 윗단이다, 7 layer에 의하면 더 아랫단에서 raw socket 개념에서 가져오는 것이므로 전부 측정 가능하다)

 

그렇기 때문에 굳이 http/https/ftp와 같은 프로토콜 형식으로 모니터링하지 않는다.

이것을 어떻게 세부 필터링할지는 유저의 몫으로 보인다. 

물론 더 세부화시키면 좋을 것 같지만, 애초에 그렇게까지 친절하게 하려면 API란 게 필요 없지 않을까

 

일단 이벤트 타입을 알아보면 다음과 같다. 

 

[Event typeDescription]

EVENT_TRACE_TYPE_ACCEPT(Event type value is 15) Accept event for IPv4 protocol. The TcpIp_TypeGroup2 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_CONNECT(Event type value is 12) Connect event for IPv4 protocol. The TcpIp_TypeGroup2 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_DISCONNECT(Event type value is 13) Disconnect event for IPv4 protocol. The TcpIp_TypeGroup1 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_RECEIVE(Event type value is 11) Receive event for IPv4 protocol. The TcpIp_TypeGroup1 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_RECONNECT(Event type value is 16) Reconnect event for IPv4 protocol. (A connect attempt failed and another attempt is made.) The TcpIp_TypeGroup1 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_RETRANSMIT(Event type value is 14) Retransmit event for IPv4 protocol. The TcpIp_TypeGroup1 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_SEND(Event type value is 10) Send event for IPv4 protocol. The TcpIp_SendIPV4 MOF class defines the event data for this event.
Event type value, 17 Fail event. The TcpIp_Fail MOF class defines the event data for this event.
Event type value, 18 TCP copy event for IPv4 protocol. The TcpIp_TypeGroup1 MOF class defines the event data for this event.
Event type value, 26 Send event for IPv6 protocol. The TcpIp_SendIPV6 MOF class defines the event data for this event.
Event type value, 27 Receive event for IPv6 protocol. The TcpIp_TypeGroup3 MOF class defines the event data for this event.
Event type value, 28 Connect event for IPv6 protocol. The TcpIp_TypeGroup4 MOF class defines the event data for this event.
Event type value, 29 Disconnect event for IPv6 protocol. The TcpIp_TypeGroup3 MOF class defines the event data for this event.
Event type value, 30 Retransmit event for IPv6 protocol. The TcpIp_TypeGroup3 MOF class defines the event data for this event.
Event type value, 31 Accept event for IPv6 protocol. The TcpIp_TypeGroup4 MOF class defines the event data for this event.
Event type value, 32 Reconnect event for IPv6 protocol. (A connect attempt failed and another attempt is made.) The TcpIp_TypeGroup3 MOF class defines the event data for this event.
Event type value, 34 TCP copy event for IPv6 protocol. The TcpIp_TypeGroup3 MOF class defines the event data for this event.

위에서 추려보자면, 사실 상 중요한 건 3개로 보인다.

그것에서 세부화시키면 네트워크 추적을 할 수 있을 것이다. 

 

EVENT_TRACE_TYPE_SEND(Event type value is 10) Send event for IPv4 protocol. The TcpIp_SendIPV4 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_RECEIVE(Event type value is 11) Receive event for IPv4 protocol. The TcpIp_TypeGroup1 MOF class defines the event data for this event.
EVENT_TRACE_TYPE_CONNECT(Event type value is 12) Connect event for IPv4 protocol. The TcpIp_TypeGroup2 MOF class defines the event data for this event.

생각해보면 raw socket을 구현하거나 후킹 혹은 드라이버를 쓰면 해결될거긴 한데 굳이 etw 처럼 api 형식으로 

구할 수 있는데 그런 노가다를 할 필요는 없어보이니 한번 써보도록 한다. 

 

다만 중간 매개체가 들어갔을 때 etw가 온전히 정보를 얻을 수 있을지는 추후 실험을 해봐야 한다.

당연히 커널 드라이버에서 중간에 필터링을 하면 보이지 않을 것이다. 

그러나 이정도까지 바라면 드라이버를 만드는 것이 옳으므로 이것은 예외로 둔다. 

 

EVENT_TRACE_TYPE_SEND/EVENT_TRACE_TYPE_RECEIVE/EVENT_TRACE_TYPE_CONNECT 

위의 내용들을 살펴보면 tcp api들의 내용과 프로토콜과 일치하는 수준이라는 것을 알 수 있다. 

그래서 소켓을 공부한 사람들이라면 쉽게 이해 가능하다. 

기반 지식이 없다면 이해하기 쉽지 않다. 

 

일단 각각의 구조체를 알아보면, TcpIp_SendIPV4 TcpIp_TypeGroup1 TcpIp_TypeGroup2  이다.

하나 씩 알아보자. 

 

[EventType{10}, EventTypeName{"SendIPV4"}]
class TcpIp_SendIPV4 : TcpIp
{
  uint32 PID;            // 요청에 관여된 프로세스의 ID이다. (reqeust)
  uint32 size;           // 패킷의 사이즈
  object daddr;          // 목적지 ip address 이다.
  object saddr;          // 출발지 ip address 이다. 
  object dport;          // 목적지 포트
  object sport;          // 출발지 포트
  uint32 startime;       // 요청 시작 시간
  uint32 endtime;        // 요청 종료 시간
  uint32 seqnum;         // 시퀀스 넘버로서 tcp ip 통신 프로토콜에서의 순서이다.
  uint32 connid;         // 연결 정보에 대한 유니크한 identifyer이다. (추적 가능)
};

매우 익숙한 구조체가 나오는데, msdn의 내용에서 필요한 것만 옆에 주석처럼 달아놓기로 한다.

이렇게 정리 안해놓으니까 msdn 내용이 너무 보기 불편하게 되어있어서 정리하니 좋다.

이것 데이터 타입들에 대해서 detail하게 구하는 것은 따로 알아보기로 하자.

 

이것으로 유추할 수 있는 것은 tcp ip를 통해 네트워크로 request를 날릴 때 필요한 <모든> 정보를

구할 수 있다는 것이다. 다만 address 정보를 필요한 것을 추출해야 한다는 것과, 데이터의 내용 자체는

보이지 않는 것으로 보인다. 그러나 이정도 만으로도 취약점이나 어떠한 행위를 했는지 정도는 알아낼 수 있다.

 

네트워크 패킷 모니터링을 하려면 와이어 샤크처럼 네트워크 패킷에 대해 필터링하는 드라이버가 존재하는 

api나 드라이버를 구현해야 할 것으로 보인다. 굳이 그럴 필요도 없지만 tshark 처럼 콘솔을 써도 용이하다. 

아마 최근 것만을 캐싱하다가 필요할 때 해당 패킷을 가져오는 방식을 써도 좋아보인다.

raw 소켓 구현과 연동하여 로컬의 모든 네트워크를 추적하고 이 etw와 연동하면 취약한 정보가 추출될 때에

캐싱된 패킷을 보면 될 것 같다. 

 

[EventType{11, 13, 14, 16, 18}, EventTypeName{"RecvIPV4", "DisconnectIPV4", "RetransmitIPV4", "ReconnectIPV4", "TCPCopyIPV4"}]
class TcpIp_TypeGroup1 : TcpIp
{
  uint32 PID;
  uint32 size;
  object daddr;
  object saddr;
  object dport;
  object sport;
  uint32 seqnum;
  uint32 connid;
};

 recieve에 관련된 이벤트 mof 구조체다. 

send와 마찬가지로 거의 같은데 차이점이라고는, start, end 시간이 없다. 

그래도 받는 시간이 있으면 좋긴한데, 아마도 이 이벤트가 <출력> 되는 순간 그 시간이 

행위가 일어난 시간이라고 보면 되니, 그것을 기록하라는 것 같다. (근데 이건 차이가 있을 수 있는데 애매하군)

 

[EventType{12, 15}, EventTypeName{"ConnectIPV4", "AcceptIPV4"}]
class TcpIp_TypeGroup2 : TcpIp
{
  uint32 PID;
  uint32 size;
  object daddr;
  object saddr;
  object dport;
  object sport;
  uint16 mss;
  uint16 sackopt;
  uint16 tsopt;
  uint16 wsopt;
  uint32 rcvwin;
  sint16 rcvwinscale;
  sint16 sndwinscale;
  uint32 seqnum;
  uint32 connid;
};

위는 connection 정보 관련된 내용인데, 굳이 connection은 sending, recieiving이 일어난 이전의 일이므로

별도로 추적할 필요는 없어보이긴 하다. 

그래서 거른다. 

 

UDP 방식에 대해서도 나오나, 비주류에 대해서는 나중에 아라보기로 하자.

잘 쓰이지도 않고, 별로 시간을 들일만한 가치가 없어보인다. 

사용 용도가 굉장히 한정되어 있다. 

 

 

 

 

 

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/05   »
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
글 보관함