[SYSTEM HACKING] Melkor ELF(Binary) Fuzzer 설치 및 사용법(Install and Usage)
예전부터 간간히 사용하던 Linux Base Fuzzer에 대한 이야기입니다. Melkor라는 이 Fuzzer는 Linux 시스템에서 EFL 파일에 대한 Fuzzing 을 위한 툴이고, 간단한 사용법에 성능도 괜찮은 편이라 공유드리네요.
Melkor 설치하기(Install Melkor)
Melkor는 github를 통해 배포되고 있습니다. git 명령으로 일단 clone을 생성합니다.
# git clone https://github.com/IOActive/Melkor_ELF_Fuzzer.git
다운로드 되면 Clone 디렉토리로 접근합니다.
# cd Melkor_ELF_Fuzzer/
# ll
합계 228
drwxr-xr-x 8 root root 4096 11월 24 18:07 .git
-rw-r--r-- 1 root root 1165 11월 24 18:07 AUTHOR.txt
-rw-r--r-- 1 root root 1334 11월 24 18:07 BUGS.txt
-rw-r--r-- 1 root root 35147 11월 24 18:07 LICENSE.txt
-rw-r--r-- 1 root root 2072 11월 24 18:07 Makefile
-rw-r--r-- 1 root root 7472 11월 24 18:07 README.txt
-rw-r--r-- 1 root root 822 11월 24 18:07 TODO.txt
drwxr-xr-x 2 root root 4096 11월 24 18:07 docs
-rwxr-xr-x 1 root root 136264 11월 24 18:28 melkor
drwxr-xr-x 2 root root 4096 11월 24 18:28 src
drwxr-xr-x 2 root root 4096 11월 24 18:28 templates
-rwxr-xr-x 1 root root 2635 11월 24 18:07 test_fuzzed.sh
-rw-r--r-- 1 root root 294 11월 24 18:07 win_test_fuzzed.bat
별도의 설정 과정은 필요없고, 바로 Make를 통해 빌드해주시면 됩니다.
# make
# make install
이렇게 간단하게 설치가 완료되었습니다. 명령 디렉토리 하단에 melkor으로 실행파일이 넘어갔기 때문에 bashrc의 alias나 별도의 명령 등록 없이 명령행에서 사용 가능합니다.
Melkor를 이용한 Fuzzing
일단 Usage를 보면 아래와 같습니다.
|
| M e l k o R v1.0 - An ELF File Format Fuzzer
| by nitr0us
|
'. ;' '; .'
;l, x, lc ;c'
,x; k; ol :o.
dk. ;0. :0. ,k:
.0k dO.,;0: .Ok
.0O. cO: c dO. cOx
.O0ocOo l .kk;xOd
.OO00O; . ;O00Ox
.cxkkkx:xkolkkkxo.
'kkkkkkxxxxxx'
.xxxxxxxxxxxxx.
.;;:xxxxxxxxxxxxo;;;.
..:dxxdo.ddddd:..
ddl:. .ldd:
ldd. .ddl
.cdlc. .ldc.
:o. .o:
; ;
___ ___ ____ __ __ __ ___ ____
||\\//|| || || || // // \\ || \\
<< || \/ || ||== || ||<< (( )) ||_// >>
|| || ||___ ||__| || \\ \\_// || \\
Usage: melkor <ELF metadata to fuzz> <ELF file template> [-n num -l likelihood -q]
<ELF metadata to fuzz>:
-a Autodetect (fuzz according to e_type except -H [the header])
-H ELF header
-S Section Header Table
-P Program Header Table
-D Dynamic section
-s Symbols Table(s)
-R Relocations Table(s)
-N Notes section
-Z Strings Tables
-A All of the above (except -a [Autodetect])
-B All of the above (except -a [Autodetect] and -H [ELF Header])
-n Number of new fuzzed ELF files (orcs) to create (default: 5000)
-l Likelihood (given in % from 1-100) of the execution of each fuzzing rule (default: 10%)
-q Quiet mode (doesn't print to STDOUT every executed fuzzing rule)
Usage: melkor <ELF metadata to fuzz> <ELF file template> [-n num -l likelihood -q]
인자값으로 ELF 파일, Template 등이 들어갑니다.
기본으로 자동으로 분석하는 -a(autodetect)부터, 각각 ELF 헤더 설정이던, Symbols Table 설정이던 옵션을 주고 대상 타겟을 인자값으로 넘겨주면 분석을 시작합니다.
테스트를 위해 간단하게 BOF 취약 코드를 작성하였습니다.
#include <stdio.h>
#include <string.h>
void main(int argc, char *argv[])
{
char buffer[256];
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
}
# melkor -a test
..-.--..
,','.-`.-.`.
:.',;' `.\.
||//----,-.--\| <<--- test
\`:|/-----`-'--||'/
\\|: <x> <X>|:'
`|| " \ |! _________________________________
|!| ;| / I'll be corrupted 5000 times ! \
!||:. -- /|! \_________________________________/
/||!||:.___.|!||\
/|!|||!| |!||!\\:.
,'//!||!||!`._.||!||,:\\\
: :: |!|||!| |!||! |!::
| |! !||!|||`---!|!|| ||!|
[+] Automatic mode
[+] ELF type detected: ET_EXEC
[+] Selecting the metadata to fuzz
[+] Detailed log for this session: 'orcs_test/Report_test.txt'
[+] The Likelihood of execution of each rule is: Aprox. 10 % (rand() % 10 < 1)
[+] Press any key to start the fuzzing process...
=================================================================================
[+] Malformed ELF 'orc_0001':
[+] Fuzzing the relocations section .rela.dyn with 1 SHT_RELA entries
[+] Fuzzing the relocations section .rela.plt with 6 SHT_RELA entries
[+] Fuzzing the Symbol Table .dynsym with 7 entries
[+] Fuzzing the Symbol Table .symtab with 68 entries
. SHT[28] SYM[0] rule [01] executed
. SHT[28] SYM[3] rule [06] executed
. SHT[28] SYM[3] rule [15] executed
. SHT[28] SYM[7] rule [04] executed
. SHT[28] SYM[9] rule [15] executed
. SHT[28] SYM[18] rule [04] executed
. SHT[28] SYM[21] rule [06] executed
. SHT[28] SYM[22] rule [06] executed
. SHT[28] SYM[22] rule [15] executed
. SHT[28] SYM[23] rule [03] executed
. SHT[28] SYM[25] rule [04] executed
. SHT[28] SYM[25] rule [05] executed
. SHT[28] SYM[25] rule [06] executed
. SHT[28] SYM[31] rule [04] executed
. SHT[28] SYM[32] rule [03] executed
. SHT[28] SYM[42] rule [10] executed
. SHT[28] SYM[42] rule [15] executed
. SHT[28] SYM[48] rule [05] executed
. SHT[28] SYM[49] rule [15] executed
. SHT[28] SYM[55] rule [15] executed
. SHT[28] SYM[57] rule [13] executed
. SHT[28] SYM[64] rule [04] executed
. SHT[28] SYM[66] rule [10] executed
[+] Fuzzing the Dynamic section .dynamic with 29 entries
[+] Fuzzing the Note section .note.ABI-tag with 32 bytes
. SHT[2] NOTE[0] rule [03] executed
[+] Fuzzing the Note section .note.gnu.build-id with 36 bytes
[+] Fuzzing the String Table .dynstr with 100 bytes
[+] Fuzzing the String Table .shstrtab with 264 bytes
[+] Fuzzing the String Table .strtab with 632 bytes