Open Source

webknight 웹 방화벽으로 IIS 웹 사이트 보안 - 4부(로그파싱)

Pydole 2018. 5. 12. 16:34

파이썬을 이용한 Webknight(웹 나이트) 이벤트 로그 파싱

 

 

  - 차단 이벤트 추출 : OnPreprocHeaders ', ' OnUrlMap

 

  - 각각의 필드를 이용하여 모니터링을 보다 강화할 수 있다.

     

      ex) 특정 클라이어인트IP를 모니터링하고 싶다면 'client IP'를 필드에 조건을 걸어서 Email, SMS연동하여

           모니터링이 가능하다

 


event = (' OnPreprocHeaders ',' OnUrlMap ')

def printLog():
    print(' date : ' + line[0] + '\n',
          'time : ' + line[1] + '\n',
          'siteInstance : ' + line[2] + '\n',
          'event : ' + line[3] + '\n',
          'clientIP : ' + line[4] + '\n',
          'username : ' + line[5] + '\n',
          'hostheader : ' + line[6] + '\n')

with open(path, 'r') as f:
    for x in f.readlines():
        line = x.split(';')
        if event[0] in line:
            detail = ' '.join(line[7:])
            if len(detail) > 200:
                printLog()
                print(' Text : '+'\n',
                      detail[:101]+'\n',
                      detail[101:201]+'\n',
                      '-'*100)
            else:
                printLog()
                print(' Text : ' + '\n',
                      detail[:] + '\n',
                      '-' * 100)

 ----------------------------------------------------------------------------------------------------
 date : 2018-05-10 
 time :  20:39:51 
 siteInstance :  W3SVC10 
 event :  OnPreprocHeaders 
 clientIP :  x.x.x.x 
 username :   
 hostheader :  www.xxxxx.co.kr 

 Text : 
  ****** BLOCKED: '=' not allowed in filename   HTTP/1.1   Mozilla/5.0 (Linux  A
 ndroid 6.0.1  SM-J510L Build/MMB29M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Mob