기본 콘텐츠로 건너뛰기

Sulley-1

Sulley

Sulley는 파이썬으로 개발된 퍼저로 많은 사용자를 보유한 인기있는 도구이다. Gray Hat Python이나 인터넷의 여러 블로그에서 쉽게 사용법을 찾아볼 수 있어 퍼징 입문을 위해 많이 활용되고 있으며 파이썬으로 개발된 덕분에 커스터마이징을 위한 기본 뼈대로도 사용되고 있다. Wiki 페이지를 통해서 설치방법을 제공해주고 있으나, 진행 도중 설치 에러로 막히는 경우가 많다. 이는 컴파일 관련 문제로 Microsoft Visual C++ Compiler for Python 2.7
설치 후 “Visual c++ command prompt”를 이용하여 진행하면 대부분 해결 가능하다.

튜토리얼로 사용되는 warftpd 1.65퍼징 테스트를 진행해보자.

ftp.py

퍼징 테스트를 위해서 FTP 통신 표준 데이터 정의가 필요하다. request 폴더 밑에 ftp.py 파일을 생성하고 아래 코드를 입력하자.

from sulley import *

s_initialize("user")
s_static("USER")
s_delim(" ")
s_string("justin")
s_static("\r\n")

s_initialize("pass")
s_static("PASS")
s_delim(" ")
s_string("justin")
s_static("\r\n")

s_initialize("cwd")
s_static("CWD")
s_delim(" ")
s_string("c:")
s_static("\r\n")

s_initialize("dele")
s_static("DELE")
s_delim(" ")
s_string("c:\\test.txt")
s_static("\r\n")

s_initialize("mdtm")
s_static("MDTM")
s_delim(" ")
s_string("C:\\boot.ini")
s_static("\r\n")

s_initialize("mkd")
s_static("MKD")
s_delim(" ")
s_string("C:\\TESTDIR")
s_static("\r\n")

FTP를 사용해본적이 있다면 친숙한 키워드를 확인할 수 있다. (코드에서 확인할 수 있듯이 테스트를 위해 justin/justin 계정을 생성하여 사용하고 있다.)

ftp_session.py

request/ftp.py 에 정의한 데이터를 활용하여 테스트를 수행하는 ftp_session.py 파일을 생성하자.

from sulley import *
from requests import ftp

def receive_ftp_banner(sock):
    sock.recv(1024)

sess = sessions.session(session_filename="C:\\warftpd.session")
target = sessions.target("127.0.0.1", 21)
target.netmon = pedrpc.client("127.0.0.1", 26001)
target.procmon = pedrpc.client("127.0.0.1", 26002)
target.procmon_options = {"proc_name" : "war-ftpd.exe", 
        "stop_commands" : ['wmic process where (name="war-ftpd.exe") delete'],
        "start_commands":['C:\\Program Files\\War-ftpd\\war-ftpd.exe'],}

sess.pre_send = receive_ftp_banner

sess.add_target(target)

sess.connect(s_get("user"))
sess.connect(s_get("user"), s_get("pass"))
sess.connect(s_get("pass"), s_get("cwd"))
sess.connect(s_get("pass"), s_get("dele"))

sess.connect(s_get("pass"), s_get("mdtm"))
sess.connect(s_get("pass"), s_get("mkd"))

sess.fuzz()

process_monitor.py

프로세스 모니터링을 위해서 아래 명령어를 수행하자. (포트를 26002로 지정하였으므로 -P 옵션을 사용하지 않는다. 26002로 지정하지 않은 경우 python process_monitor.py -c C:\warftpd.crash -P war-ftpd.exe로 프로세스를 지정한다.)

python process_monitor.py -c C:\warftpd.crash

network_monitor.py

네트워크 모니터링을 위해서 아래 명령어를 수행하자. 로그를 저장할 C:\pcaps 디렉터리는 network_monitor.py 실행 전 미리 생성해야 정상 구동된다.

python network_monitor.py -d 0 -f "src or dst port 21" -P C:\pcaps\

Start Fuzzing

이제 warftpd를 실행하여 FTP 서비스 시작 후 ftp_session.py 파일을 실행하여 퍼징 테스트를 시작하자. 이 때 퍼징 테스트 중 종료된 프로세스를 바로 재시작할 수 있도록 warfpd 옵션에서 배너 제거와 시작 시 서비스 시작 항목을 설정한다. 퍼징 진행은 http://127.0.0.1:26000에서 확인이 가능하다.

이 블로그의 인기 게시물

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 ...

Insecure-programming-abo1

Insecure-programming-abo1 Insecure Programming by example Advanced Buffer Overflow 1 int main ( int argv , char * * argc ) { char buf [ 256 ] ; strcpy ( buf , argc [ 1 ] ) ; } Advanced Buffer Overflow 첫 번째 문제는 사용자 인자 값 검증 없이 버퍼에 strcpy() 함수로 복사하여 발생되는 오버플로우 예이다. 먼저 objdump 를 이용하여 어셈블리어를 살펴보자. # objdump -d -M intel ./abo1 | grep -A 16 "<main>" 08048374 <main>: 8048374: 55 push ebp 8048375: 89 e5 mov ebp,esp 8048377: 81 ec 18 01 00 00 sub esp,0x118 804837d: 83 e4 f0 and esp,0xfffffff0 8048380: b8 00 00 00 00 mov eax,0x0 8048385: 29 c4 sub esp,eax 8048387: 8b 45 0c mov eax,DWORD PTR [ebp+12] 804838a: 83 c0 04 add eax,0x4 804838d: 8b 00 mov eax,DWORD PTR [eax] 804838f: 89 44 24 04 mov ...

Insecure-programming-stack5

Insecure-programming-stack5 Insecure Programming by example Stack 5 이번 문제에서는 조건절 안에 “you win!” 문구 대신 "you loose!"가 있는 것을 볼 수 있다. # include <stdio.h> int main ( ) { int cookie ; char buf [ 80 ] ; printf ( "buf: %08x cookie: %08xn" , & buf , & cookie ) ; gets ( buf ) ; if ( cookie == 0x000d0a00 ) printf ( "you loose!\n" ) ; } 따라서 이번 문제를 해결하기 위해서는 임의로 작성한 별도의 코드를 프로그램에서 호출하도록 하여 “you win!” 구문 출력을 이끌어 내야한다. "you win!"을 출력하고 종료하는 간단한 어셈블리어 코드를 작성한다. section .text global _start _start: jmp short ender starter: xor eax, eax xor ebx, ebx xor ecx, ecx xor edx, edx mov al, 4 mov dbl, 91 pop ecx mov bdl, 14 int 0x80 xor eax, eax inc eaxal dec bl int 0x80 ender: call starter db 'you win!\n' 작성이 완료되었다면 nasm 을 이용하여 오브젝트 파일을 생성한 후 ld 명령어로 실행 파일을 만들어 제대로 동작하는 지 확인해보하고 objdump 를 이용하여 코드 덤프를 만들자. # nasm -f elf -o stack54_sh_code....