log parser&webshell detection

36
MS-LogParser를 활용한 WebShell 탐지 파일 업로드 취약점 최일선 1 E-mail : [email protected] Writing by Ilsun Choi

Upload: ilsun-choi

Post on 08-Aug-2015

108 views

Category:

Technology


8 download

TRANSCRIPT

MS-LogParser를 활용한WebShell 탐지

파일 업로드 취약점

최일선

1E-mail : [email protected] Writing by Ilsun Choi

Index

2E-mail : [email protected] Writing by Ilsun Choi

1. Log Parser 2.2 개요1) 특징 : 다양한 용도2) LogParser 기본 사용법

2. IISW3C Log 분석 : Fields

3. IISW3C Log 분석 : Example Queries

4. 실습1) 스크립트 제작2) 분석3) Log 분석 결과4) 대응방안

부록. LogPaser GUI 버전

참고 문헌

1. Log Parser 2.2 개요

• Windows 운영 체제의 핵심 데이터 원본에 대한 범용 쿼리 액세스를 제공

• 로그 파일, XML 파일, CSV 파일 등과 같은 텍스트 기반 지원

• 이벤트 로그, 레지스트, 파일 시스템, Active Directory 지원

• 모든 것을 데이터베이스로 사용

3

MS - Log Parser 웹사이트

E-mail : [email protected] Writing by Ilsun Choi

• 광범위한 용도의 특성 때문에 전문 서적이 제작됨

4E-mail : [email protected] Writing by Ilsun Choi

1. Log Parser 2.2 개요 > 1) 특징

• 다음과 같이 –h 옵션을 사용하면 도움말이 출력된다.

5

logparser 도움말 출력

logparser Usage Help

SQL Query Help

E-mail : [email protected] Writing by Ilsun Choi

1. Log Parser 2.2 개요 > 2) 기본 사용법[1/3]

A. 기본 형식

• 우리가 사용할 구문은 다음과 같은 형식으로 간소화할 수 있다.

6

LogParser.exe –i:[입력형식] –o:[출력형식]

“SELECT [필드명]

INTO [출력파일명]

FROM ex*.log

GROUP BY [필드명]

WHERE [조건]

ORDER BY [필드명] ASC|DESC”

E-mail : [email protected] Writing by Ilsun Choi

1. Log Parser 2.2 개요 > 2) 기본 사용법[2/3]

B. 다양한 도움말

• 다양한 형식을 지원하기 때문에 여러 도움말이 존재한다.

7

logparser 입출력 형식

그림 2.2.2. logparser에 내장된 예제 출력

그림 2.2.3. IISW3C의 포맷 도움말

E-mail : [email protected] Writing by Ilsun Choi

1. Log Parser 2.2 개요 > 2) 기본 사용법[2/3]

2. IISW3C Log 분석 : Fields

Field Name Description Uses

Date (date) The date of the request. Event correlation.

Time (time) The UTC time of the request. Event correlation, determine time zone, identif

y scanning scripts.

Client IP Address (

c-ip)

The IP address of the client or

proxy that sent the request.

Identify user or proxy server.

User Name (cs-us

ername)

The user name used to authent

icate to the resource.

Identify compromised user passwords.

Service Name (s-si

tename)

The W3SVC instance number o

f the site accessed.

Can verify the site accessed if the log files ar

e later moved from the system.

Server Name (s-co

mputername)

The Windows host name assig

ned to the system that generat

ed the log entry.

Can verify the server accessed if the log files

are later moved from the system.

Server IP Address (

s-ip)

The IP address that received th

e request.

Can verify the IP address accessed if the log

files are later moved from the system or if the

server is moved to a new location.

Server Port (s-port

)

The TCP port that received the

request.

To verify the port when correlating with other t

ypes of log files.

Method (cs-metho

d)

The HTTP method used by the

client.

Can help track down abuse of scripts or exec

utables.

URI Stem (cs-uri-

stem)

The resource accessed on the

server.

Can identify attack vectors.

URI Query (cs-uri-

query)

The contents of the query strin

g portion of the URI.

Can identify injection of malicious data.

8

Field Name Description Uses

Protocol Status (s

c-status)

The result code sent to the cl

ient.

Can identify CGI scans, SQL injection and

other intrusions.

Win32 Status (sc-

win32-status)

The Win32 error code produc

ed by the request.

Can help identify script abuse.

Bytes Sent (sc-by

tes)

The number of bytes sent to

the client.

Can help identify unusual traffic from a sin

gle script.

Bytes Received (c

s-bytes)

The number of bytes receive

d from the client.

Can help identify unusual traffic to a single

script.

Time Taken (time

-taken)

The amount of server time, in

milliseconds, taken to proces

s the request.

Can identify unusual activity from a single s

cript.

Protocol Version (

cs-version)

The HTTP protocol version s

upplied by the client.

Can help identify older scripts or browsers.

Host (cs-host) The contents of the HTTP Ho

st header sent by the client.

Can determine if the user browsed to the si

te by IP address or host name.

User Agent (cs(U

ser-Agent))

The contents of the HTTP Us

er-Agent header sent by the

client.

Can help uniquely identify users or attack s

cripts.

Cookie (cs(Cooki

e))

The contents of the HTTP Co

okie header sent by the client

.

Can help uniquely identify users.

Referer (cs(Refer

er))

The contents of the HTTP Re

ferer header sent by the clien

t.

Can help identify the source of an attack or

see if an attacker is using search engines t

o find vulnerable sites.

E-mail : [email protected] Writing by Ilsun Choi

• 주요 항목은 노란색으로 강조하였다.

3. IISW3C Log 분석 > Example Queries [1/9]

9

1. Tracing Attack

Logparser

"SELECT DISTINCT

TO_LOWERCASE(cs-uri-stem)

AS URL, Count(*) AS Hits

FROM ex*.log

WHERE sc-status=200

GROUP BY URL

ORDER BY HITS"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

10

2. Last Write Time

Logparser -i:FS

"SELECT TOP 20 Path, LastWriteTime

FROM *.*

ORDER BY LastWriteTime DESC"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [2/9]

11

3. Count Number of Hits by a Client

logparser

"SELECT DISTINCT date, cs-uri-stem, c-ip,

Count(*) AS Hits

FROM ex*.log

GROUP BY date, c-ip, cs-uri-stem

HAVING Hits>100

ORDER BY Hits DESC"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [3/9]

12

4. 404 > Error Page Response

logparser

"SELECT cs-uri-query, Count(*) AS Total

FROM ex*.log

WHERE sc-status>=404

GROUP BY cs-uri-query

ORDER BY Total DESC"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [4/9]

13

5. Specific client ip order by hits

logparser

"SELECT DISTINCT TO_LOWERCASE(cs-uri-

stem) AS URL, Count(*) As HITS

FROM ex*.log

WHERE sc-status=200

and c-ip='211.34.150.3'

GROUP BY URL

ORDER BY hits"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [5/9]

14

6. Count number of urls if the file name extension is asp or exe

logparser

"SELECT cs-uri-stem, Count(*) as Hits, AVG(time-taken) AS Avg,

Max(time-taken) AS Max, Min(time-taken) AS Min,

Sum(time-taken) AS Total

FROM ex*.log

WHERE TO_LOWERCASE(cs-uri-stem)

LIKE '%.asp%'

OR TO_LOWERCASE(cs-uri-stem)

LIKE '%.exe%'

GROUP BY cs-uri-stem

ORDER BY cs-uri-stem"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [6/9]

15

7. Win32 error

logparser

"SELECT cs-uri-stem,

WIN32_ERROR_DESCRIPTION(sc-win32-status)

as Error, Count(*) AS Total

FROM ex*.log

WHERE sc-win32-status>0

AND (TO_LOWERCASE(cs-uri-stem)

LIKE '%.asp%'

OR TO_LOWERCASE(cs-uri-stem)

LIKE '%.exe%')

GROUP BY cs-uri-stem, Error

ORDER BY cs-uri-stem, Error

-rtp:-1E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [7/9]

16

8. Count numbers Classified according to the error and the url

logparser

"SELECT cs-uri-stem, sc-status, Count(*) AS Total

FROM ex*.log

WHERE TO_LOWERCASE(cs-uri-stem) LIKE '%.asp%'

OR TO_LOWERCASE(cs-uri-stem) LIKE '%.exe%'

GROUP BY cs-uri-stem, sc-status

ORDER BY cs-uri-stem, sc-status"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [8/9]

17

9. Error Report about the pages over 500 error code

logparser

"SELECT cs-uri-query, Count(*) AS Total

FROM ex*.log

WHERE sc-status>=500

GROUP BY cs-uri-query

ORDER BY Total DESC"

-rtp:-1

E-mail : [email protected] Writing by Ilsun Choi

3. IISW3C Log 분석 > Example Queries [9/9]

4. 실습

18E-mail : [email protected] Writing by Ilsun Choi

SEC 스터디에서 제공 받은 실제 웹셸 탐지 사례의 LOG를 사용하여 해당 웹의 로그를 분석(SEC 스터디: 웹 모의해킹과 시큐어코딩 가이드 – 최경철 저자 스터디 까페)

LOG만을 사용하여 분석했기 때문에 일부 오탐 및 미탐이 존재할 수 있음

4. 실습 > 1) 스크립트 제작

• 로그 분석 예제 -> Python 스크립트

19

LogParser 자동화를 위한 Python 스크립트 Python 스크립트 실행 결과

E-mail : [email protected] Writing by Ilsun Choi

• 두 가지의 의심스러운 점을 발견

I. DoS Attack?

II. Web Shell?

20E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석

• GET Flooding 공격으로 추측

• 해당 웹서버에 IPS 동작 하지 않음.

21

count_hit.csv 파일 - 1 count_hit.csv 파일 - 2

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석I. DoS Attack

• 가장 최근에 발생된 DoS 공격 시기인 2월 2일의 로그 파일이다.

22

ex080202.log 파일 211.34.150.3 첫 번째 검색 ex080202.log 파일 211.34.150.3 마지막 요청 검색

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석I. DoS Attack > ex080202.log 파일 분석[1/3]

• %를 사용한 인증 우회가 있었는지 검사.

• ‘ 와 1=1 같은 인증을 우회하려는 시도 감지.

• 3초 단위로 공격.

• 정상적인 방법으로 URL에 접근하지 않음.

23

ex080202.log 파일 : % 검색

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석I. DoS Attack > ex080202.log 파일 분석[2/3]

• https://db-ip.com/ 을 통해서 공격으로 추측되는 행위를 한 IP를 추적하였다.

24

DoS 공격으로 추측되는 IP 인젝션으로 인증 우회를 시도한 IP

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석I. DoS Attack > ex080202.log 파일 분석[3/3]

• 같은 IP 주소의 첫 공격

• 1월 4일 10시 45분 경부터 1월 5일 1시 35분

• 서버 관리자는 첫 번째 공격 의심 로그 이후에도 해당 IP를 차단하지 않음

25

첫 번째 DoS 공격

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석I. DoS Attack > ex080104.log 파일 분석

• 로그를 통한 웹셸 탐지 방법

1) 히트 수가 비정상적으로 적은 파일

2) 비정상적인 이름을 사용하는 파일

3) Upload PATH를 위치하는 파일

26E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect

• 히트 수를 오름차순으로 정렬

• dll이나 jpg, gif 등 검사에 불필요한 파일이 섞여있음

• 히트 수 50 이하의 파일이 500개가 넘기 때문에 목록 필터링이 필요하다.

27

그림 5.2.2.1. tracing_attack.cvs

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > tracing_attack.csv

• Python Script로 불필요한 파일들을 걸러내었다.

• 히트 수 50 이하 파일이 100 여 개로 줄어 분석이 용이해졌다.

• 63번, 65번 라인에서 조건에 합하는 파일을 찾았다.

28

new_tracing_attack.cvs : 50번 이하의 Hits

new_tracing_attack.cvs : laobing.asa

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > new_tracing_attack.cvs

• Google 검색을 사용하여 해당 파일에 대한 정보를 수집

• 멀웨어로 추측되어 LogParser를 사용하여 laobing.asa 파일에 접근한 IP 목록을 수집하였다.

29

laobing.asa 구글 검색 결과 laobing.asa에 접근한 IP 정보

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > laobing.asa 구글 검색[1/2]

• laobing.asa 파일에 접근한 모든 IP는 중국 IP였다.

• Laobing의 사전적 의미는 중국식 flat bread를 의미한다.

30

laobing.asa 접근한 IP laobing 검색 결과

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > laobing.asa 구글 검색[2/2]

• 이 IP 주소들이 다른 웹페이지로 접속한 이력이 있는지 확인하기 위해 접속한 웹 페이지를 LogParser로 조회했다.

• 하지만 laobing.asa 파일 외에는 다른 파일에 접근한 기록이 없다. 분석을 어렵게 하기 위해 여러 IP를 사용한 듯 보인다.

31

중국발 IP들의 페이지 요청 이력

E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > Web Shell Trace

• 파일을 올릴 때는 POST 방식으로 200 또는 300 대의 상태코드를 받는다. 400>sc-status>=200상태코드를 받은 POST요청을 검색

모든 URL, IP, Date를 조회했다.

Date 오름차순으로 정렬하였다.

laobing.asa 파일을 요청한 최초 요청(p29 오른쪽 그림 참고)

2008. 1. 5

• 1월 5일 이전을 대상으로 멀웨어가 업로드된 free와 visitor 폴더 내 wirte_module파일에 접근한 220.117.80.157이 가장 많이 의심된다.

32E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 2) 분석II. Web Shell Detect > 업로드한 IP 조회

4. 실습 > 3) 로그 분석 결과

• DoS 공격은 부천 시청, 인증 우회는 동국 대학교, WebShell 접속은 중국으로부터 들어온것으로 추측된다.

• DoS는 1월 4일, WebShell 최초 접근 날짜는 1월 5일로, 비슷한 시기에 수상한 로그가많이 발견되었다.

• 이 모든 공격을 연관 지어 생각해 볼 필요성이 있다.

33E-mail : [email protected] Writing by Ilsun Choi

• 관리자의 보안 교육

• IPS, 웹 방화벽 등 보안 솔루션 필요

• laobing.asa의 파일 업로드 경로에 업로드하는 소스 파일 검사

-> 업로드 취약점 보완

34E-mail : [email protected] Writing by Ilsun Choi

4. 실습 > 4) 대응 방안

부록. LogPaser GUI 버전

• Visual LogParser(왼쪽)은 실시간으로 도움말이 출력되어 Log Parser 작성 시 용이하다.

• Log Parser Studio(오른쪽)은 라이브러리를 통하여 원하는 쿼리를 골라서 사용할 수 있다.

• 각 장단점을 잘 활용하여 상황과 자신에게 맞는 툴을 사용하는 것이 바람직하다.

35E-mail : [email protected] Writing by Ilsun Choi

참고 문헌

36

• https://technet.microsoft.com/ko-kr/scriptcenter/dd919274.aspx• http://www.symantec.com/connect/articles/forensic-log-parsing-microsofts-logparser• http://allimter.tistory.com/

E-mail : [email protected] Writing by Ilsun Choi